本文整理汇总了C++中ControllerPtr::SetFitness方法的典型用法代码示例。如果您正苦于以下问题:C++ ControllerPtr::SetFitness方法的具体用法?C++ ControllerPtr::SetFitness怎么用?C++ ControllerPtr::SetFitness使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ControllerPtr
的用法示例。
在下文中一共展示了ControllerPtr::SetFitness方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setCandidateFitness
void PopulationControlArchitecture::setCandidateFitness(ControllerPtr candidate, double scoredFitness) {
// running evaluation has completed. Decide if the candidate will become the active solution.
if (candidate->GetFitness() > -1) {
// this is a re-evaluation, average out the previous and the new score
if (debug) {
cout << "This was a re-evaluation, not adding a new candidate" << endl;
}
candidate->SetFitness((candidate->GetFitness() + scoredFitness) / 2);
if (debug || verbose) {
cout << "Finished re-evaluating " << candidate->ToShortString() << " - fitness: " << scoredFitness << ", avg: " << candidate->GetFitness() << endl;
}
} else {
candidate->SetFitness(scoredFitness);
// this is a first evaluation and will need to be considered for placement as an active solution
if (activeSolutions.size() < mu) {
// there is no full set of active solutions yet, just add this solution
activeSolutions.push_back(candidate);
// send out a news item about the new active solution
population->setNews(candidate->Clone(), activeSolutions.size() - 1, currentTime);
} else {
// there is a full list of active solutions, compete with the active solutions
int worstIndex = -1;
ControllerPtr worst = candidate;
// find the worst controller in the (unsorted) list
for (unsigned int i = 0; i < activeSolutions.size(); i++) {
if (worst->GetFitness() > activeSolutions[i]->GetFitness()) {
worst = activeSolutions[i];
worstIndex = i;
}
}
// if the candidate is better than the worst controller in the list, have it take that controller's place
if (scoredFitness > worst->GetFitness()) {
if (debug) {
cout << "This was first evaluation, candidate became active solution" << endl;
}
activeSolutions[worstIndex] = candidate;
// send out a news item about the new active solution
population->setNews(candidate->Clone(), worstIndex, currentTime);
} else {
if (debug) {
cout << "This was first evaluation, candidate failed" << endl;
}
// the candidate has lost the competition; have it deleted
// done automatically by smart pointer
}
}
// Don't print if candidate was deleted
if (candidate && (debug || verbose)) {
cout << "Finished evaluating " << candidate->ToShortString() << " - fitness: " << scoredFitness << endl;
}
}
if (!debug && !verbose) {
// there has been no output on the fitness yet, do that now
cout << scoredFitness << endl;
}
}