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


C++ ControllerPtr::GetFitness方法代码示例

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


在下文中一共展示了ControllerPtr::GetFitness方法的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;
	}
}
开发者ID:ci-group,项目名称:monee,代码行数:66,代码来源:PopulationControlArchitecture.cpp


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