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

GeneticAlgorithm::GeneticAlgorithm ( vector< SizeName > &  sn,
Params p 
)

Automatically adjust population size and num. of generations. Also sets Random::Seed. These parameters are static (its adjustment) over the iterations, however, Initialize() is called before each iteration.

Definition at line 33 of file GeneticAlgorithm.cc.

References SizeName::CmpSizeRev(), Optimizer::m_files, Params::m_ga_cross_prob, Params::m_ga_num_gens, Params::m_ga_pop_size, Params::m_ga_seed, Params::m_ga_sel_pressure, m_genomes, m_num_gen, Optimizer::m_params, m_pop_size, m_prob_crossover, m_tournament_size, Random::Seed(), Tournament, Tournament2(), and TournamentN().

                                                                 : 
                  Optimizer(sn, p) 
{
   // This constructor is called just once. Thus, these parameters
   // remain "static" over all iterations. On the other hand,
   // Initialize() is called for each iteration.

   // sort files by size (reverse order), needed by the genetic operators
   sort(m_files.begin(), m_files.end(), SizeName::CmpSizeRev);

   // auto adjust if not explicitly declared

   // Selection pressure [default = 2]
   if (m_params.m_ga_sel_pressure <= 2) 
   {
      m_tournament_size = 2;
      Tournament = &GeneticAlgorithm::Tournament2;
   }
   else // maximum = pop size
   {
      m_tournament_size = m_params.m_ga_sel_pressure;
      Tournament = &GeneticAlgorithm::TournamentN;
   }

   // Population size and generations are proportionally to ln (natural
   // logarithmic) of input size (number of files).
   if (m_params.m_ga_pop_size <= m_tournament_size) m_params.m_ga_pop_size = 
       max(m_tournament_size+1, 
       static_cast<unsigned>(20*log((float) m_files.size()+1)));
    
   if (m_params.m_ga_num_gens <= 0) m_params.m_ga_num_gens = 
      static_cast<int>(50*log((float) m_files.size()+1));

   // ------ set params
   // resize population to m_ga_pop_size
   m_pop_size = m_params.m_ga_pop_size;
   m_num_gen  = m_params.m_ga_num_gens;
   m_prob_crossover = m_params.m_ga_cross_prob;
    

   // --- Population and Genetic Algorithm

   // reserve the correct size
   m_genomes.reserve(m_params.m_ga_pop_size);

   m_params.m_ga_seed = Random::Seed(m_params.m_ga_seed); 
}


Generated by  Doxygen 1.6.0   Back to index