?? 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 + -