GA/Assets/Scripts/Chromosome.cs
/// <summary>
/// Returns a list of all neighboring cities of a specific city
/// in the DNAs of both parents.
/// </summary>
Returns a list of all neighboring cities of a specific city
in the DNAs of both parents.
Returns a list of all neighboring cities of a specific city in the DNAs of both parents .
private List<City> FindEdges(int city, Chromosome partner) {
        var cityEdges = new List<City>();
        for (int i = 0; i < 2; i++) {
            var parentDNA = i == 0 ? this.dna : partner.dna;
            for (int j = 0; j < parentDNA.Count; j++) {
                if ((j == 0 && (parentDNA[parentDNA.Count - 1].index == city || parentDNA[j + 1].index == city)) ||
                    (j == parentDNA.Count - 1 && (parentDNA[j - 1].index == city || parentDNA[0].index == city)) ||
                    (j > 0 && j < parentDNA.Count - 1 && (parentDNA[j - 1].index == city || parentDNA[j + 1].index == city))) {
                    if (!cityEdges.Contains(parentDNA[j]) && parentDNA[j].index != city) {
                        cityEdges.Add(parentDNA[j]);
                    }
                }
            }
        }
        return cityEdges;
    }
private List < City > FindEdges ( int city , Chromosome partner ) { var cityEdges = new List < City > ( ) ; for ( int i = 0 ; i < 2 ; i ++ ) { var parentDNA = i == 0 ? this . dna : partner . dna ; for ( int j = 0 ; j < parentDNA . Count ; j ++ ) { if ( ( j == 0 && ( parentDNA [ parentDNA . Count - 1 ] . index == city || parentDNA [ j + 1 ] . index == city ) ) || ( j == parentDNA . Count - 1 && ( parentDNA [ j - 1 ] . index == city || parentDNA [ 0 ] . index == city ) ) || ( j > 0 && j < parentDNA . Count - 1 && ( parentDNA [ j - 1 ] . index == city || parentDNA [ j + 1 ] . index == city ) ) ) { if ( ! cityEdges . Contains ( parentDNA [ j ] ) && parentDNA [ j ] . index != city ) { cityEdges . Add ( parentDNA [ j ] ) ; } } } } return cityEdges ; }
Returns a list of all neighboring cities of a specific city
in the DNAs of both parents.
Returns a list of all neighboring cities of a specific city in the DNAs of both parents .
city
int
partner
Chromosome