📄 eliteoperation.cpp
字号:
// EliteOperation.cpp: implementation of the EliteOperation class.
//
//////////////////////////////////////////////////////////////////////
#include <stdafx.h> // Added 980901 by Aleksander 踙rn.
#include "../copyright.h" // Added 000323 by Aleksander 豩rn.
#include "EliteOperation.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
EliteOperation::EliteOperation() : elite(NULL)
{
}
EliteOperation::~EliteOperation()
{
}
Population & EliteOperation::apply(Population & p, int /*generation*/)
{
if(p.size() == 0)
return p;
Individual * max = p.population[p.fittest];
if(elite == NULL || (getFitness(elite) <= getFitness(max))){ // first time
if(elite == NULL)
elite = max->clone();
else
*elite = *max;
return p;
}
if(getFitness(elite) > getFitness(max)){ // lost elite, reinsert
*p.population[p.worst] = *elite;
p.population[p.worst]->age = 0;
return stats.apply(p);
}
return p;
}
double EliteOperation::getFitness(Individual * i, bool scaled)
{
return scaled ? i->sfitness : i->fitness;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -