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

void GeneticAlgorithm::Evolve (  )  [virtual]

Genetic Algorithm search.

GA searches for optimal (not guaranteed) solutions by means of darwinian evolution.

Implements Optimizer.

Definition at line 89 of file GeneticAlgorithm.cc.

References Generation(), Initialize(), InitPopulation(), Optimizer::m_best, m_cur_gen, m_genomes, m_num_gen, Optimizer::m_params, Params::m_verbose, Reset(), and Score().

{
   // Reset variables
   Reset();

   // Initialize the GeneticAlgorithm Optimizer
   Initialize();

   // ---- Evolving...
   // Initialize the GA population
   InitPopulation();

   if (m_params.m_verbose) cout << "> ";

   while (m_cur_gen++ < m_num_gen)
   { 
      if (m_params.m_verbose) cout << "." << flush;
      if (Generation()) break;
   }

   if (m_params.m_verbose) cout << " <" << endl << flush;

   // pick the best
   Params::Size_t best_score = numeric_limits<Params::Size_t>::max();

   for(unsigned int i=0; i<m_genomes.size(); ++i)
   {
      Params::Size_t tmp_score = Score(i);

      if (tmp_score < best_score) 
      { 
         m_best = &m_genomes[i]->m_chrom;
         best_score = tmp_score;
      }
   }
}


Generated by  Doxygen 1.6.0   Back to index