private void layout_rects_from_genes() { for (int i = 0; i < this.original_rects.Count; i++) { this.layout_rects[i] = (RECT)this.original_rects[i]; } for (int i = 0; i < genes.Count; i++) { MyGene g = (MyGene)this.genes[i]; this.layout_rects[i + 1] = RECTTOOLS.relative_reposition(this.layout_rects[i], this.layout_rects[i + 1], g.side, g.q); } RECT bb = RECTTOOLS.get_bounding_box(this.layout_rects); for (int i = 0; i < this.layout_rects.Length; i++) { RECT r = this.layout_rects[i]; r.x0 = r.x0 - bb.x0; r.y0 = r.y0 - bb.y0; System.Diagnostics.Debug.Assert(r.x0 >= 0.0); System.Diagnostics.Debug.Assert(r.y0 >= 0.0); } }
public void SwapGenesBetween(int first_index, int last_index, geneticfx.IChromosome other_chromosome) { MyChromosome ocs = (MyChromosome)other_chromosome; for (int i = first_index; i <= last_index; i++) { MyGene swap = (MyGene)this.genes[i]; this.genes[i] = ocs.genes[i]; ocs.genes[i] = swap; } }
public void RandomizeGenes() { for (int i = 0; i < genes.Count; i++) { MyGene g = (MyGene)this.genes[i]; int new_side = r.Next(0, 4); double new_q = (r.NextDouble() * 2.0) - 1.0; MyGene new_g; new_g.side = new_side; new_g.q = new_q; this.genes[i] = new_g; } }
public void MutateGene(int index) { double rate = 0.5; MyGene g = (MyGene)this.genes[index]; if (r.NextDouble() > rate) { g.side = MyChromosome.get_random_side(); } else { g.q = MyChromosome.get_random_q(); } this.genes[index] = g; }