Ejemplo n.º 1
0
        public GA(IGAFunctions functions)
        {
            m_Functions = functions;
              Chromosomes = new List<Chromosome>();

              for (int i = 0; i < functions.PopulationSize; i++)
              {
            Chromosome chromosome = new Chromosome(functions.ChromosoneLength);
            chromosome.Fitness = m_Functions.CalculateFitness(chromosome.Data);
            Chromosomes.Add(chromosome);
              }
        }
Ejemplo n.º 2
0
 private void Mutate(Chromosome c)
 {
     for (int i = 0; i < c.Data.Length; i++)
       {
     if (TossTheDice(m_Functions.MutationRate))
       c.Data.Set(i, !c.Data[i]);
       }
 }
Ejemplo n.º 3
0
 private void UpdateBestFit(Chromosome c)
 {
     if (c.Fitness > BestFit)
       {
     BestFit = c.Fitness;
     Best = c;
     if (OnBestFitChanged != null)
       OnBestFitChanged(this, EventArgs.Empty);
       }
 }
Ejemplo n.º 4
0
 private Chromosome CrossOver(Chromosome p1, Chromosome p2)
 {
     Chromosome c = new Chromosome();
       c.Data = p1.Data.Clone() as BitArray;
       int index = m_Rand.Next(c.Data.Length);
       for (int i = 0; i < index; i++)
     c.Data.Set(i, p2.Data[i]);
       return c;
 }