本文整理汇总了C++中Population::addFitnessFunction方法的典型用法代码示例。如果您正苦于以下问题:C++ Population::addFitnessFunction方法的具体用法?C++ Population::addFitnessFunction怎么用?C++ Population::addFitnessFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population
的用法示例。
在下文中一共展示了Population::addFitnessFunction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildEvolutionSystem
bool JanEvolution::buildEvolutionSystem() {
World *world = new World("Main");
Population *population = new Population("HumanoidControllers");
world->addPopulation(population);
IdentityGenotypePhenotypeMapper *mapper = new IdentityGenotypePhenotypeMapper();
population->setGenotypePhenotypeMapper(mapper);
new ENS3EvolutionAlgorithm(world);
world->setEvaluationMethod(new LocalNetworkInSimulationEvaluationMethod());
Evolution::getEvolutionManager()->addEvolutionWorld(world);
//Add statistics calculator.
Statistics::getStatisticsManager()->addGenerationStatistics(
new BasicNeuralNetworkStatistics(*population));
FitnessFunction *fitness = 0;
CommandLineArgument *fitnessFunctionArg = new CommandLineArgument(
"fitness", "fit", "<prototypeName> <fitnessFunctionName>",
"Creates a copy of <prototypeName> and uses it for the population"
" with the given <fitnessFunctionName>.", 2, 0, true);
QList<QString> fitArguments = fitnessFunctionArg->getEntryParameters(0);
if(fitArguments.size() > 1) {
fitness = Fitness::getFitnessManager()
->createFitnessFunctionFromPrototype(fitArguments.at(0), fitArguments.at(1));
if(fitness == 0) {
cerr << "Failed to create FitnessFunction prototype ["
<< fitArguments.at(0).toStdString().c_str() << endl;
}
}
if(fitness == 0) {
fitness = Fitness::getFitnessManager()
->createFitnessFunctionFromPrototype("Script", "Script");
}
population->addFitnessFunction(fitness);
TournamentSelectionMethod *tournament = new TournamentSelectionMethod(5);
PoissonDistributionRanking *poissonDistribution = new PoissonDistributionRanking();
population->addSelectionMethod(tournament);
population->addSelectionMethod(poissonDistribution);
tournament->setResponsibleFitnessFunction(fitness);
poissonDistribution->setResponsibleFitnessFunction(fitness);
poissonDistribution->getPopulationProportion()->set(0.0);
//add individual statistics
StandardIndividualStatistics indStatistics(population);
NeuralNetworkIndividualStatistics neuroStatistics(population);
return true;
}
示例2: evo
/**
* Constructs a new NeuroEvolutionSelector.
*/
NeuroEvolutionSelector::NeuroEvolutionSelector(EvaluationMethod *evaluationMethod)
{
//TODO Currently only a single world with a single population is supported.
//Select evolution algorithm
CommandLineArgument *evoAlgorithmArg = new CommandLineArgument(
"evolutionAlgorithm", "evo", "<algorithmName> <controlledAgent> <populationName>",
"Uses the evolution algorithm with the given <algorithmName> "
"to evolve controllers for agent <controlledAgent> (optional). "
"Optionally the population name can be set with <populationName>.", 1, 2, true);
CommandLineArgument *fitnessFunctionArg = new CommandLineArgument(
"fitness", "fit", "<prototypeName> <fitnessFunctionName> <population>",
"Creates a copy of <prototypeName> and uses it "
" with the given <fitnessFunctionName>. The <population>"
" is a number and specifies the population in which the fitness function is used.",
2, 1, true);
//ensure that there is at least on world, even if not specified via command line.
bool createDefaultWorld = false;
if(evoAlgorithmArg->getNumberOfEntries() == 0) {
createDefaultWorld = true;
}
int scriptFitnessCounter = 0;
QList<QString> evoWorldNames;
for(int evoCount = 0; evoCount < evoAlgorithmArg->getNumberOfEntries() || createDefaultWorld; ++evoCount) {
QString worldName = "Main";
QString popName = "Controllers";
if(evoCount > 0) {
worldName = "Pop" + QString::number(evoCount);
}
if(evoCount > 0) {
popName = "Controllers" + QString::number(evoCount);
}
QList<QString> evoArguments = evoAlgorithmArg->getEntryParameters(evoCount);
if(evoArguments.size() >= 3) {
worldName = evoArguments[2];
QString name = worldName;
int counter = 1;
while(evoWorldNames.contains(worldName)) {
worldName = name + QString::number(counter);
counter++;
}
evoWorldNames.append(worldName);
}
World *world = new World(worldName);
Population *population = new Population(popName, world);
world->addPopulation(population);
if(evoCount == 0) {
world->setEvaluationMethod(evaluationMethod);
}
else {
world->setEvaluationMethod(0);
}
Evolution::getEvolutionManager()->addEvolutionWorld(world);
//Install Fitness
FitnessFunction *fitness = 0;
for(int i = 0; i < fitnessFunctionArg->getNumberOfEntries(); ++i) {
QList<QString> fitArguments = fitnessFunctionArg->getEntryParameters(i);
if((evoCount == 0 && fitArguments.size() <= 2)
|| (fitArguments.size() > 2
&& fitArguments.at(2).toInt() == evoCount))
{
if(fitArguments.size() > 1) {
fitness = Fitness::getFitnessManager()
->createFitnessFunctionFromPrototype(fitArguments.at(0), fitArguments.at(1));
if(fitness == 0) {
cerr << "Failed to create FitnessFunction prototype ["
<< fitArguments.at(0).toStdString().c_str() << endl;
}
}
if(fitness != 0) {
population->addFitnessFunction(fitness);
}
}
}
if(fitness == 0) {
QString scriptName = "Script";
if(scriptFitnessCounter > 0) {
scriptName += QString::number(scriptFitnessCounter);
//.........这里部分代码省略.........