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


C++ Problem::fitness方法代码示例

本文整理汇总了C++中Problem::fitness方法的典型用法代码示例。如果您正苦于以下问题:C++ Problem::fitness方法的具体用法?C++ Problem::fitness怎么用?C++ Problem::fitness使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Problem的用法示例。


在下文中一共展示了Problem::fitness方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: crossover

const population TwoPoint::crossover(const population & mates, const Problem & problem) const {
  // two-point crossover
  population children = mates;
  int_dist percent(0, 100);
  if (chance || percent(rg.engine) < int(100 * chance)) {
    int_dist gene_dist(0, children[0].size() - 1);
    int start = gene_dist(rg.engine);
    int length = gene_dist(rg.engine);
    for (Individual & child : children)
      std::rotate(child.begin(), child.begin() + start, child.end());
    for (int i = 0; i < length; i++)
      std::swap(children[0][i], children[1][i]);
  }
  // update fitnesses
  for (Individual & child : children) child.fitness = problem.fitness(child);
  return children;
}
开发者ID:andschwa,项目名称:uidaho-cs472-project1,代码行数:17,代码来源:recombinator_two_point.cpp

示例2: mutate

const Individual Creep::mutate(const Problem & problem, const Individual & subject) const {
  // basic mutation by delta distribution and chance
  Individual mutant = subject; // non-const copy to mutate
  int_dist percent(0, 100);
  // distribution of real delta values, scaled for problem domain
  real_dist delta_dist(-problem.delta * (std::abs(problem.domain_min) +
					 std::abs(problem.domain_max)) / 2,
		       problem.delta * (std::abs(problem.domain_min) +
					std::abs(problem.domain_max)) / 2);
  for (parameter & gene : mutant)
    // short circuit for problem.chance == 1
    if (problem.chance || percent(rg.engine) < int(100 * problem.chance))
      mutant.mutate(gene, gene + delta_dist(rg.engine));
  // update fitness
  mutant.fitness = problem.fitness(mutant);
  return mutant;
}
开发者ID:andschwa,项目名称:uidaho-cs472-project1,代码行数:17,代码来源:mutator_creep.cpp


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