internal static void CalculateFitness(char[] target, StringDna parStringDna) { var targetlen = target.Length; var fitness = targetlen; var fitnessMother = targetlen; var fitnessFather = targetlen; //var minlen = Math.Min(target.Length, GeneA.Length); // Aufhoeren wenn klar ist, dass kein besserer erreicht werden kann ??? for (var i = 0; i < targetlen; i++) { if (target[i] != parStringDna.GeneA[i]) { continue; } fitness--; if (i > targetlen / 2) { fitnessFather--; } else { fitnessMother--; } } parStringDna.Fitness = fitness; parStringDna.FitnessMother = fitnessMother; parStringDna.FitnessFather = fitnessFather; }
public static StringDna[] DnaInitialize(int size, int targetlen, string startstring = "") { var dnaarray = new StringDna[size]; for (var i = 0; i < size; i++) { var tempdna = new StringDna(startstring); if (string.IsNullOrWhiteSpace(startstring)) { tempdna.Initialize(targetlen); } dnaarray[i] = tempdna; } return(dnaarray); }
internal StringDna CrossOver(StringDna father, int targetlen) { var temp = new char[targetlen]; for (var i = 0; i < targetlen; i += 1) { if (i < targetlen / 2) { temp[i] = GeneA[i]; } else { temp[i] = father.GeneA[i]; } } var child = new StringDna(temp); //child.Mutate(Rng.Next(0,AlphabetLength - 1)); child.Mutate(1); return(child); }