public override void Cross(ref ChromosomeBase x) { // cut point and lenght int cut, cut_l; cut = Globals.rnd.Next( TPChromosome.chromosome_size ); cut_l = Globals.rnd.Next( TPChromosome.chromosome_size - cut ); // preparing for the cross TPChromosome xx = (TPChromosome)x; ArrayList sec1, sec2; sec1 = (ArrayList)this.genes.GetRange( cut, cut_l ).Clone(); sec2 = (ArrayList)xx.genes.GetRange( cut, cut_l ).Clone(); // crossing for ( int i=0; i < this.genes.Count; i++ ) if ( sec2.Contains( this.genes[i] ) ) { this.genes.Remove( this.genes[i] ); i--; }; this.genes.InsertRange( cut, sec2 ); for ( int i=0; i < xx.genes.Count; i++ ) if ( sec1.Contains( xx.genes[i] ) ) { xx.genes.Remove( xx.genes[i] ); i--; } xx.genes.InsertRange( cut, sec1 ); #if DEBUG System.Diagnostics.Trace.WriteLine( "\n" + cut.ToString() + " " + cut_l.ToString() ); System.Diagnostics.Trace.WriteLine( this.GetRepresentation() ); System.Diagnostics.Trace.WriteLine( xx.GetRepresentation() ); #endif }