本文整理汇总了C++中Population::best_solution方法的典型用法代码示例。如果您正苦于以下问题:C++ Population::best_solution方法的具体用法?C++ Population::best_solution怎么用?C++ Population::best_solution使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population
的用法示例。
在下文中一共展示了Population::best_solution方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: solve
Solution Solver::solve(const Instance& tsp, Population& init_pop)
{
//set_phase(1);
bool stop = false;
Population& training_population = init_pop;
Solution best_sol = init_pop.best_solution();
int max_no_imp = tsp.nodes_card*2;
while (!stop && iterations < max_tot_iterations) {
Population next_gen = advance_generation(best_sol, training_population, tsp);
// cout << "### "<< iterations << "-th population ###" << endl;
// next_gen.print();
Solution local_best_sol = next_gen.best_solution();
// cout << "best sol:\t\t";
// best_sol.print();
// cout << "current best sol:\t";
// local_best_sol.print();
if (local_best_sol.evaluate() < best_sol.evaluate()) {
best_sol = local_best_sol;
set_phase(1);
iterations_without_improvement = 0;
}
else {
iterations_without_improvement++;
}
iterations++;
training_population = next_gen;
if (iterations_without_improvement > max_no_imp)
stop = true;
if (iterations_without_improvement > max_no_imp-1)
set_phase(0);
}
// cout << "### "<< iterations << "-th population ###" << endl;
return best_sol;
}