/// <summary> /// /// </summary> public void Mutate() { for (int i = 0; i < Dna.Length; i++) { if (MutationRnd.NextDouble() < MutationChance) { Dna[i] = MutateByPercentage(Dna[i]); } // if (MutationRnd.NextDouble() < MutationChance) // Dna[i] = MutateBySign(Dna[i]); } }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public double MutateByNumber(double value) { return(value + MutationRnd.NextDouble() * MutationRnd.Next(0, 1) == 0 ? -1 : 1); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public double MutateByPercentage(double value) { //Plus ou moins de 5 a 15 pourcent de la valeur du nombre value += value * (0.05 + (MutationRnd.NextDouble() / 10)) * MutationRnd.Next(0, 1) == 0 ? -1 : 1; return(value); }