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

bool GeneticAlgorithm::Generation (  )  [protected]

Runs the GA for one generation. Returns true if a perfect fit was found; false otherwise.

Definition at line 330 of file GeneticAlgorithm.cc.

References Optimizer::Diff(), DirectedMutation(), LocalOptimizer(), m_genomes, Reproduction(), Score(), and Tournament.

Referenced by Evolve().

{
   for(unsigned int i=0; i<m_genomes.size(); i+=2)
   {
      // select daddy and mommy and the losers (will be replaced by children)
      pair<int,int> dad = (this->*Tournament)(0, m_genomes.size()/2 - 1);
      pair<int,int> mom = 
           (this->*Tournament)(m_genomes.size()/2, m_genomes.size() - 1);

      // Reproduction (crossover and mutation)
      Reproduction(dad.first, mom.first, dad.second, mom.second);

      // Calculate the sum (evaluation)
      m_genomes[dad.second]->Diff(Diff(m_genomes[dad.second]->m_chrom));
      m_genomes[mom.second]->Diff(Diff(m_genomes[mom.second]->m_chrom));

      // ------  other genetic operators
      // Directed mutation
      DirectedMutation(*m_genomes[dad.second]);
      DirectedMutation(*m_genomes[mom.second]);

      // local optimizer and makes the individual feasible if needed
      LocalOptimizer(*m_genomes[dad.second]);
      LocalOptimizer(*m_genomes[mom.second]);

      // test if was found the perfect fit
      if (Score(dad.second) <= 0.0 || Score(mom.second) <= 0.0) return true;
   }

   // yet not found the perfect fit
   return false;
}


Generated by  Doxygen 1.6.0   Back to index