当前位置: 首页>>代码示例>>C++>>正文


C++ Population::GetAdults方法代码示例

本文整理汇总了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 );
}
开发者ID:khskrede,项目名称:AI,代码行数:29,代码来源:strategies.cpp

示例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));
      }
   }
}
开发者ID:khskrede,项目名称:AI,代码行数:10,代码来源:strategies.cpp

示例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();
}
开发者ID:khskrede,项目名称:AI,代码行数:16,代码来源:strategies.cpp


注:本文中的Population::GetAdults方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。