private void CreateStartPopulation() { for (int count = 0; count < PopulationSize; ++count) { DesertGenome genome = new DesertGenome(ChromosomeLength); mGenomes.Add(genome); } }
private void Crossover(DesertGenome mum, DesertGenome dad, DesertGenome baby1, DesertGenome baby2) { if (UnityEngine.Random.value > CrossoverRate || mum == dad) { baby1.Bits = mum.Bits; baby2.Bits = dad.Bits; } else { int point = UnityEngine.Random.Range(0, ChromosomeLength - 1); for (int count = 0; count < ChromosomeLength; ++count) { baby1.Bits.Set(count, count < point ? mum.Bits.Get(count) : dad.Bits.Get(count)); baby2.Bits.Set(count, count < point ? dad.Bits.Get(count) : mum.Bits.Get(count)); } } }
private IEnumerator Epoch() { yield return(UpdateFitnessScores()); List <DesertGenome> babyGenomes = new List <DesertGenome>(); while (babyGenomes.Count < PopulationSize) { DesertGenome mum = RouletteWheelSelection(); DesertGenome dad = RouletteWheelSelection(); DesertGenome baby1 = new DesertGenome(ChromosomeLength); DesertGenome baby2 = new DesertGenome(ChromosomeLength); Crossover(mum, dad, baby1, baby2); Mutate(baby1.Bits); Mutate(baby2.Bits); babyGenomes.Add(baby1); babyGenomes.Add(baby2); } mGenomes = babyGenomes; ++mGeneration; }