本文整理汇总了C++中Population::GetAdults方法的典型用法代码示例。如果您正苦于以下问题:C++ Population::GetAdults方法的具体用法?C++ Population::GetAdults怎么用?C++ Population::GetAdults使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population
的用法示例。
在下文中一共展示了Population::GetAdults方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Elitism
void
Strategies::RankSelection( Population &pop ) {
/* Take care of elitism first */
Elitism( pop );
/* Create roullette wheel */
float max = 0;
float min = 999999999999999999;
float sum = 0;
float roulette[pop.GetAdults().size()];
/* Find min and max */
for ( unsigned int i = 0 ; i < pop.GetAdults().size() ; i++ ) {
if ( max < pop.GetAdults().at(i).GetFitness() ) max = pop.GetAdults().at(i).GetFitness();
if ( min > pop.GetAdults().at(i).GetFitness() ) min = pop.GetAdults().at(i).GetFitness();
}
max = pop.GetAdults().back().GetFitness();
min = pop.GetAdults().at(0).GetFitness();
roulette[0]=0;
for ( unsigned int i = 1 ; i < pop.GetAdults().size() ; i++ ) {
roulette[i] = roulette[i-1] + min+(max-min)*(i - 1) / (pop.GetAdults().size() - 1);
}
sum = roulette[pop.GetAdults().size()-1] + max;
Select( pop, roulette, pop.GetAdults().size(), sum );
}
示例2: sort
void
Strategies::Elitism( Population &pop ) {
unsigned int elitism = pop.GetElitism();
if (elitism > 0) {
sort(pop.GetAdults().begin(), pop.GetAdults().end(), IndividualSort);
for (unsigned int i = 0; i<elitism; i++) {
pop.GetChildren().push_back(pop.GetAdults().at(i));
}
}
}
示例3: while
void
Strategies::OverProduction( Population &pop ) {
/* All adults die, children fight to become adults */
pop.GetAdults().clear();
int num;
while ( pop.GetAdults().size() < pop.GetAdultsSize() ) {
num = rand() % pop.GetChildren().size();
pop.GetAdults().push_back( pop.GetChildren().at( num ) );
pop.GetChildren().erase( pop.GetChildren().begin()+num );
}
/* Clear children */
pop.GetChildren().clear();
}