GA/Assets/Scripts/Chromosome.cs
/// <summary>
/// Mutates each city in the DNA by swapping two random cities
/// (probability is specified by the <paramref name="mutationRate"/>).
/// </summary>
Mutates each city in the DNA by swapping two random cities
(probability is specified by the ).
Mutates each city in the DNA by swapping two random cities ( probability is specified by the ) .
public void Mutate(float mutationRate) {
        for (int i = 0; i < dna.Count; i++) {
            if (Random.value < mutationRate) {
                var city2Index = Random.Range(0, dna.Count);
                int numTries = world.itersToFindNewCity;
                while (city2Index == i && numTries > 0) {
                    city2Index = Random.Range(0, dna.Count);
                    numTries--;
                }
                var temp = dna[i];
                dna[i] = dna[city2Index];
                dna[city2Index] = temp;
            }
        }
    }
public void Mutate ( float mutationRate ) { for ( int i = 0 ; i < dna . Count ; i ++ ) { if ( Random . value < mutationRate ) { var city2Index = Random . Range ( 0 , dna . Count ) ; int numTries = world . itersToFindNewCity ; while ( city2Index == i && numTries > 0 ) { city2Index = Random . Range ( 0 , dna . Count ) ; numTries -- ; } var temp = dna [ i ] ; dna [ i ] = dna [ city2Index ] ; dna [ city2Index ] = temp ; } } }
Mutates each city in the DNA by swapping two random cities
(probability is specified by the ).
Mutates each city in the DNA by swapping two random cities ( probability is specified by the ) .
// cities are the same // swap cities
mutationRate
float