Esempio n. 1
0
 private void CreateStartPopulation()
 {
     for (int count = 0; count < PopulationSize; ++count)
     {
         DesertGenome genome = new DesertGenome(ChromosomeLength);
         mGenomes.Add(genome);
     }
 }
Esempio n. 2
0
 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));
         }
     }
 }
Esempio n. 3
0
    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;
    }