GA/Assets/Scripts/Chromosome.cs
/// <summary>
/// Combines the DNAs of two parents and returns a child
/// (using Ordered Crossover).
/// </summary>
Combines the DNAs of two parents and returns a child
(using Ordered Crossover).
Combines the DNAs of two parents and returns a child ( using Ordered Crossover ) .
private Chromosome CrossoverOX(Chromosome partner) {
        var size = this.dna.Count;
        Chromosome child = new Chromosome(world);
        child.dna.Clear();
        var startCut = Random.Range(0, size);
        var endCut = Random.Range(startCut + 1, size);
        var slice = this.dna.Skip(startCut).Take(endCut - startCut).ToList();
        for (int k = 0; k < size; k++) {
            if (!slice.Contains(partner.dna[k])) {
                slice.Add(partner.dna[k]);
            }
        }
        child.dna = slice;
        return child;
    }
private Chromosome CrossoverOX ( Chromosome partner ) { var size = this . dna . Count ; Chromosome child = new Chromosome ( world ) ; child . dna . Clear ( ) ; var startCut = Random . Range ( 0 , size ) ; var endCut = Random . Range ( startCut + 1 , size ) ; var slice = this . dna . Skip ( startCut ) . Take ( endCut - startCut ) . ToList ( ) ; for ( int k = 0 ; k < size ; k ++ ) { if ( ! slice . Contains ( partner . dna [ k ] ) ) { slice . Add ( partner . dna [ k ] ) ; } } child . dna = slice ; return child ; }
Combines the DNAs of two parents and returns a child
(using Ordered Crossover).
Combines the DNAs of two parents and returns a child ( using Ordered Crossover ) .
partner
Chromosome