public static Individual[] Combine(Individual mum, Individual dad) { Individual babyA; Individual babyB; Genom genomA; Genom genomB; genomA = new Genom(mum.Genom); genomB = new Genom(dad.Genom); if (mum != dad) { int genDistance = r.Next(mum.Genom.Gens.Count); for (int genIndex = genDistance; genIndex < mum.Genom.Gens.Count; genIndex++) { double genA = genomA.Gens[genIndex]; genomA.Gens[genIndex] = genomB.Gens[genIndex]; genomB.Gens[genIndex] = genA; } } babyA = new Individual(genomA); babyB = new Individual(genomB); return(new Individual[] { babyA, babyB }); }
public static Genom Mutate(Genom genom, double rate, double strength) { Genom mutatedGenom = new Genom(genom); for (int genIndex = 0; genIndex < mutatedGenom.Gens.Count; genIndex++) { if (r.NextDouble() < rate) { mutatedGenom.Gens [genIndex] += (r.NextDouble() - r.NextDouble()) * strength; } } return(mutatedGenom); }
public Individual(Genom genom) { Fitness = 0; Genom = genom; }
public Individual(int genomSize) { Fitness = 0; Genom = new Genom(genomSize, 3); }
public Genom(Genom g) { Gens = new List <double>(g.Gens); }