本文整理汇总了C++中Chromosome::evaluate方法的典型用法代码示例。如果您正苦于以下问题:C++ Chromosome::evaluate方法的具体用法?C++ Chromosome::evaluate怎么用?C++ Chromosome::evaluate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chromosome
的用法示例。
在下文中一共展示了Chromosome::evaluate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void genitor<Chromosome,Encoding>::run_one_generation()
{
mtrandom mt;
m_sel_scheme->set_population(&this->m_population);
// select two parents
Chromosome<Encoding> p1 = m_sel_scheme->select_parent();
Chromosome<Encoding> p2 = m_sel_scheme->select_parent();
// perform crossover with some probability
Chromosome<Encoding> c1 = p1;
Chromosome<Encoding> c2 = p2;
if(mt.random() < m_cross_rate)
{
m_cross_op->crossover(p1, p2, c1, c2);
}
Chromosome<Encoding> offspring;
if(mt.random() < 0.5)
{
offspring = c1;
}
else
{
offspring = c2;
}
// mutate the offspring
m_mut_op->mutate(offspring);
// evaluate the offspring
offspring.evaluate(this->m_fitfunc);
chromosome_evaluated(offspring);
// put the offspring into the population in place of the
// worst individual
m_rep_scheme->merge_individual(offspring, this->m_population, this->m_population);
}