private float FitnessFunction(int index) { float score = 0; Andre.AI.DNA <float> dna = ga.Population[index]; score = SpeedyGeneration[index].DistanceTraveled; score = (Mathf.Pow(2, score) - 1) / (2 - 1); return(score); }
private float FitnessFunction(int index) { float score = 0; Andre.AI.DNA <char> dna = ga.Population[index]; for (int i = 0; i < dna.Genes.Length; i++) { if (dna.Genes[i] == targetString[i]) { score += 1; } } score /= targetString.Length; score = (Mathf.Pow(2, score) - 1) / (2 - 1); return(score); }
private bool Mutate(Andre.AI.DNA <float> child, float MutationRate) { double PositiveOrNegative = random.NextDouble(); for (int i = 0; i < 3; i++) { if (random.NextDouble() < mutationRate) { child.Genes[i] += (float)random.NextDouble() * (PositiveOrNegative >= 0.5 ? 1 : -1); switch (i) { case 0: if (child.Genes[i] <= 0) { child.Genes[i] = 0.01f; } break; case 1: if (child.Genes[i] <= 0.5f) { child.Genes[i] = 0.5f; } break; case 2: if (child.Genes[i] <= 0.5f) { child.Genes[i] = 0.5f; } break; default: break; } } } return(true); }