Logo Search packages:      
Sourcecode: gaffitter version File versions  Download package

void GeneticAlgorithm::Reproduction ( int  dad,
int  mom,
int  child1,
int  child2 
) const [protected]

Promotes the crossover among two individuals, generating two children.

Definition at line 401 of file GeneticAlgorithm.cc.

References CopyMutate(), m_genomes, m_prob_crossover, and Random::Probability().

Referenced by Generation().

{
   if (Random::Probability(m_prob_crossover))
   {
      // mask uniform crossover
      for(int i=0; i<m_genomes[dad]->Length(); ++i)
      {
         if (Random::Probability(0.5))
         {
            m_genomes[child1]->Gene(i, CopyMutate(m_genomes[dad]->Gene(i)));
            m_genomes[child2]->Gene(i, CopyMutate(m_genomes[mom]->Gene(i)));
         }
         else
         {
            m_genomes[child1]->Gene(i, CopyMutate(m_genomes[mom]->Gene(i)));
            m_genomes[child2]->Gene(i, CopyMutate(m_genomes[dad]->Gene(i)));
         }
      }

   }
   else // just duplicate (with mutation)
   {
      for(int i=0; i<m_genomes[dad]->Length(); ++i)
      {
         // [no] switch mom/dad group for more diversity
         m_genomes[child1]->Gene(i, CopyMutate(m_genomes[dad]->Gene(i)));
         m_genomes[child2]->Gene(i, CopyMutate(m_genomes[mom]->Gene(i)));
      }
   }
}


Generated by  Doxygen 1.6.0   Back to index