Commit a7c7d447 authored by kruger's avatar kruger
Browse files

Mises a jour

parent a4156440
...@@ -632,15 +632,15 @@ ...@@ -632,15 +632,15 @@
// Evolution Engine: // Evolution Engine:
Evaluator goal: minimize Evaluator goal: minimize
Number of generations: 100 Number of generations: 5
Population size: 100 Population size: 10
Elite: 4 Elite: 5
Selection operator: Tournament 7 Selection operator: Tournament 7
Offspring size: 50% Offspring size: 100%
Reduce parents operator: Tournament 4 Reduce parents operator: Tournament 4
Surviving parents: 50 Surviving parents: 50%
Reduce offspring operator: Tournament 2 Reduce offspring operator: Tournament 2
Surviving offspring: 96 Surviving offspring: 96%
Final reduce operator: Tournament 2 Final reduce operator: Tournament 2
Elitism: Weak Elitism: Weak
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
*/ */
#include "include/CEvolutionaryAlgorithm.h" #include "include/CEvolutionaryAlgorithm.h"
#include <string>
#ifndef WIN32 #ifndef WIN32
#include <sys/time.h> #include <sys/time.h>
#endif #endif
...@@ -18,12 +17,16 @@ ...@@ -18,12 +17,16 @@
#endif #endif
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
#include <string> #include <string.h>
#include "include/CIndividual.h" #include "include/CIndividual.h"
#include "include/Parameters.h" #include "include/Parameters.h"
#include "include/CGnuplot.h" #include "include/CGnuplot.h"
#include "include/global.h" #include "include/global.h"
#include "include/CComUDPLayer.h"
#include "include/CRandomGenerator.h"
#include <stdio.h> #include <stdio.h>
#include <sstream>
#include <fstream>
using namespace std; using namespace std;
...@@ -35,10 +38,11 @@ void EASEAGenerationFunctionBeforeReplacement(CEvolutionaryAlgorithm* evolutiona ...@@ -35,10 +38,11 @@ void EASEAGenerationFunctionBeforeReplacement(CEvolutionaryAlgorithm* evolutiona
extern void evale_pop_chunk(CIndividual** pop, int popSize); extern void evale_pop_chunk(CIndividual** pop, int popSize);
extern bool INSTEAD_EVAL_STEP; extern bool INSTEAD_EVAL_STEP;
/** /**
* @DEPRECATED the next contructor has to be used instead of this one. * @DEPRECATED the next contructor has to be used instead of this one.
*/ */
CEvolutionaryAlgorithm::CEvolutionaryAlgorithm( size_t parentPopulationSize, /*CEvolutionaryAlgorithm::CEvolutionaryAlgorithm( size_t parentPopulationSize,
size_t offspringPopulationSize, size_t offspringPopulationSize,
float selectionPressure, float replacementPressure, float parentReductionPressure, float offspringReductionPressure, float selectionPressure, float replacementPressure, float parentReductionPressure, float offspringReductionPressure,
CSelectionOperator* selectionOperator, CSelectionOperator* replacementOperator, CSelectionOperator* selectionOperator, CSelectionOperator* replacementOperator,
...@@ -62,8 +66,19 @@ CEvolutionaryAlgorithm::CEvolutionaryAlgorithm( size_t parentPopulationSize, ...@@ -62,8 +66,19 @@ CEvolutionaryAlgorithm::CEvolutionaryAlgorithm( size_t parentPopulationSize,
this->reduceParents = 0; this->reduceParents = 0;
this->reduceOffsprings = 0; this->reduceOffsprings = 0;
} // INITIALIZE SERVER OBJECT ISLAND MODEL
if(params->remoteIslandModel){
this->server = new CComUDPServer(2909,0);
this->treatedIndividuals = 0;
this->numberOfClients = 0;
this->initializeClients();
}
}*/
/*****
* REAL CONSTRUCTOR
*/
CEvolutionaryAlgorithm::CEvolutionaryAlgorithm(Parameters* params){ CEvolutionaryAlgorithm::CEvolutionaryAlgorithm(Parameters* params){
this->params = params; this->params = params;
...@@ -103,17 +118,35 @@ CEvolutionaryAlgorithm::CEvolutionaryAlgorithm(Parameters* params){ ...@@ -103,17 +118,35 @@ CEvolutionaryAlgorithm::CEvolutionaryAlgorithm(Parameters* params){
this->gnuplot = new CGnuplot((this->params->offspringPopulationSize*this->params->nbGen)+this->params->parentPopulationSize); this->gnuplot = new CGnuplot((this->params->offspringPopulationSize*this->params->nbGen)+this->params->parentPopulationSize);
} }
#endif #endif
// INITIALIZE SERVER OBJECT ISLAND MODEL
if(params->remoteIslandModel){
server = new CComUDPServer(2909,0); //1 if debug
this->treatedIndividuals = 0;
this->numberOfClients = 0;
this->initializeClients();
}
} }
/* DESTRUCTOR */
CEvolutionaryAlgorithm::~CEvolutionaryAlgorithm(){ CEvolutionaryAlgorithm::~CEvolutionaryAlgorithm(){
delete population; delete population;
if(this->params->remoteIslandModel){
delete this->server;
if(this->numberOfClients>1){
for(int i=0; (unsigned)i<this->numberOfClients; i++)
delete this->Clients[i];
delete this->Clients;
}
}
} }
void CEvolutionaryAlgorithm::addStoppingCriterion(CStoppingCriterion* sc){ void CEvolutionaryAlgorithm::addStoppingCriterion(CStoppingCriterion* sc){
this->stoppingCriteria.push_back(sc); this->stoppingCriteria.push_back(sc);
} }
/* MAIN FUNCTION TO RUN THE EVOLUTIONARY LOOP */
void CEvolutionaryAlgorithm::runEvolutionaryLoop(){ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
CIndividual** elitistPopulation; CIndividual** elitistPopulation;
...@@ -148,10 +181,15 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){ ...@@ -148,10 +181,15 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
if(params->elitSize) if(params->elitSize)
elitistPopulation = (CIndividual**)malloc(params->elitSize*sizeof(CIndividual*)); elitistPopulation = (CIndividual**)malloc(params->elitSize*sizeof(CIndividual*));
// EVOLUTIONARY LOOP
while( this->allCriteria() == false){ while( this->allCriteria() == false){
EASEABeginningGenerationFunction(this); EASEABeginningGenerationFunction(this);
// Sending individuals if remote island model
if(params->remoteIslandModel && this->numberOfClients>0)
this->sendIndividual();
population->produceOffspringPopulation(); population->produceOffspringPopulation();
if(!INSTEAD_EVAL_STEP) if(!INSTEAD_EVAL_STEP)
...@@ -194,6 +232,11 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){ ...@@ -194,6 +232,11 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
bBest = population->Best; bBest = population->Best;
EASEAEndGenerationFunction(this); EASEAEndGenerationFunction(this);
//Receiving individuals if cluster island model
if(params->remoteIslandModel){
this->receiveIndividuals();
}
currentGeneration += 1; currentGeneration += 1;
} }
#ifdef __linux__ #ifdef __linux__
...@@ -208,6 +251,15 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){ ...@@ -208,6 +251,15 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
std::cout << *population << std::endl; std::cout << *population << std::endl;
} }
//IF SAVING THE POPULATION, ERASE THE OLD FILE
if(params->savePopulation){
string fichier = params->outputFilename;
fichier.append(".pop");
remove(fichier.c_str());
population->serializePopulation();
}
if(this->params->generateGnuplotScript || !this->params->plotStats) if(this->params->generateGnuplotScript || !this->params->plotStats)
generateGnuplotScript(); generateGnuplotScript();
...@@ -297,7 +349,7 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){ ...@@ -297,7 +349,7 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){
#ifdef WIN32 #ifdef WIN32
fprintf(f,"%lu,%2.6f,%lu,%.15e,%.15e,%.15e\n",currentGeneration,duration,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV); fprintf(f,"%lu,%2.6f,%lu,%.15e,%.15e,%.15e\n",currentGeneration,duration,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV);
#else #else
fprintf(f,"%d,%ld.%06ld,%d,%f,%f,%f\n",currentGeneration,res.tv_sec,res.tv_usec,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV); fprintf(f,"%d,%ld.%06ld,%d,%.15e,%.15e,%.15e\n",currentGeneration,res.tv_sec,res.tv_usec,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV);
#endif #endif
fclose(f); fclose(f);
} }
...@@ -317,6 +369,76 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){ ...@@ -317,6 +369,76 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){
params->timeCriterion->setElapsedTime(res.tv_sec); params->timeCriterion->setElapsedTime(res.tv_sec);
} }
//REMOTE ISLAND MODEL FUNCTIONS
void CEvolutionaryAlgorithm::initializeClients(){
char (*clients)[16] = (char(*)[16])calloc(1,sizeof(char)*16);
// string clients[256];
cout << "Reading IP address file" << endl;
ifstream IP_File("ip.txt");
string line;
while(getline(IP_File, line)){
if(!isLocalMachine(line.c_str())){
memmove(clients[this->numberOfClients],line.c_str(),sizeof(char)*16);
//clients[this->numberOfClients] = line;
this->numberOfClients++;
clients = (char(*)[16])realloc(clients,sizeof(char)*16*(this->numberOfClients*16));
}
}
this->Clients = (CComUDPClient**)malloc(this->numberOfClients*sizeof(CComUDPClient*));
for(int i=0; i<(signed)this->numberOfClients; i++){
//this->Clients[i] = new CComUDPClient(2909,clients[i].c_str(),0);
this->Clients[i] = new CComUDPClient(2909,(const char*)clients[i],0);
// cout << "Client " << i << " IP is " << this->Clients[i]->getIP() << endl;
}
free(clients);
}
void CEvolutionaryAlgorithm::sendIndividual(){
//Sending an individual every n generations
if(this->currentGeneration%10==0){
//cout << "I'm going to send an Individual now" << endl;
this->population->selectionOperator->initialize(this->population->parents, 7, this->population->actualParentPopulationSize);
size_t index = this->population->selectionOperator->selectNext(this->population->actualParentPopulationSize);
//cout << "Going to send individual " << index << " with fitness " << this->population->parents[index]->fitness << endl;
//selecting a client randomly
int client = globalRandomGenerator->getRandomIntMax(this->numberOfClients);
cout << "Going to send and individual to client " << client << endl;
cout << "His IP is " << this->Clients[client]->getIP() << endl;
//cout << "Sending individual " << index << " to client " << client << " nomw" << endl;
//cout << this->population->parents[index]->serialize() << endl;
this->Clients[client]->CComUDP_client_send((char*)this->population->parents[index]->serialize().c_str());
}
}
void CEvolutionaryAlgorithm::receiveIndividuals(){
//Checking every generation for received individuals
if(this->treatedIndividuals<(unsigned)this->server->nb_data){
//cout << "number of received individuals :" << this->server->nb_data << endl;
//cout << "number of treated individuals :" << this->treatedIndividuals << endl;
//Treating all the individuals before continuing
while(this->treatedIndividuals < (unsigned)this->server->nb_data){
//selecting the individual to erase
CSelectionOperator *antiTournament = getSelectionOperator("Tournament",!this->params->minimizing, globalRandomGenerator);
antiTournament->initialize(this->population->parents, 7, this->population->actualParentPopulationSize);
size_t index = antiTournament->selectNext(this->population->actualParentPopulationSize);
//cout << "old individual fitness :" << this->population->parents[index]->fitness << endl;
//cout << "old Individual :" << this->population->parents[index]->serialize() << endl;
this->server->read_data_lock();
string line = this->server->parm->data[this->treatedIndividuals].data;
this->population->parents[index]->deserialize(line);
this->server->read_data_unlock();
//cout << "new Individual :" << this->population->parents[index]->serialize() << endl;
this->treatedIndividuals++;
}
}
}
void CEvolutionaryAlgorithm::outputGraph(){ void CEvolutionaryAlgorithm::outputGraph(){
fprintf(this->gnuplot->fWrit,"set term png\n"); fprintf(this->gnuplot->fWrit,"set term png\n");
fprintf(this->gnuplot->fWrit,"set output \"%s\"\n",params->plotOutputFilename); fprintf(this->gnuplot->fWrit,"set output \"%s\"\n",params->plotOutputFilename);
...@@ -372,7 +494,7 @@ bool CEvolutionaryAlgorithm::allCriteria(){ ...@@ -372,7 +494,7 @@ bool CEvolutionaryAlgorithm::allCriteria(){
#ifdef WIN32 #ifdef WIN32
int gettimeofday int gettimeofday
(struct timeval* tp, void* tzp) { (struct timeval* tp, void* tzp) {
DWORD t; DWORD t;
t = timeGetTime(); t = timeGetTime();
tp->tv_sec = t / 1000; tp->tv_sec = t / 1000;
......
...@@ -140,6 +140,7 @@ void parseArguments(const char* parametersFileName, int ac, char** av, ...@@ -140,6 +140,7 @@ void parseArguments(const char* parametersFileName, int ac, char** av,
("reduceFinalPressure",po::value<float>(),"Set the Final Reducing Pressure (default : 2.0)") ("reduceFinalPressure",po::value<float>(),"Set the Final Reducing Pressure (default : 2.0)")
("optimiseIterations",po::value<int>(),"Set the number of optimisation iterations (default : 100)") ("optimiseIterations",po::value<int>(),"Set the number of optimisation iterations (default : 100)")
("baldwinism",po::value<int>(),"Only keep fitness (default : 0)") ("baldwinism",po::value<int>(),"Only keep fitness (default : 0)")
("remoteIslandModel",po::value<int>(),"Boolean to activate the individual exachange with remote islands (default : 0)")
("outputfile",po::value<string>(),"Set an output file for the final population (default : none)") ("outputfile",po::value<string>(),"Set an output file for the final population (default : none)")
("inputfile",po::value<string>(),"Set an input file for the initial population (default : none)") ("inputfile",po::value<string>(),"Set an input file for the initial population (default : none)")
("printStats",po::value<int>(),"Print the Stats (default : 1)") ("printStats",po::value<int>(),"Print the Stats (default : 1)")
...@@ -150,6 +151,8 @@ void parseArguments(const char* parametersFileName, int ac, char** av, ...@@ -150,6 +151,8 @@ void parseArguments(const char* parametersFileName, int ac, char** av,
// ("printStatsFile",po::value<int>(),"Print the Stats to a File (Filename: ProjectName.dat) (default : 0)") // ("printStatsFile",po::value<int>(),"Print the Stats to a File (Filename: ProjectName.dat) (default : 0)")
("printInitialPopulation",po::value<int>(),"Prints the initial population (default : 0)") ("printInitialPopulation",po::value<int>(),"Prints the initial population (default : 0)")
("printFinalPopulation",po::value<int>(),"Prints the final population (default : 0)") ("printFinalPopulation",po::value<int>(),"Prints the final population (default : 0)")
("savePopulation",po::value<int>(),"Saves population at the end (default : 0)")
("startFromFile",po::value<int>(),"Loads the population from a .pop file (default : 0")
("u1",po::value<string>(),"User defined parameter 1") ("u1",po::value<string>(),"User defined parameter 1")
("u2",po::value<string>(),"User defined parameter 2") ("u2",po::value<string>(),"User defined parameter 2")
("u3",po::value<int>(),"User defined parameter 3") ("u3",po::value<int>(),"User defined parameter 3")
......
...@@ -6,11 +6,15 @@ ...@@ -6,11 +6,15 @@
*/ */
#include "include/CPopulation.h" #include "include/CPopulation.h"
#include <iostream>
#include <fstream>
#include <string.h> #include <string.h>
#include "include/CRandomGenerator.h" #include "include/CRandomGenerator.h"
#include "include/CIndividual.h" #include "include/CIndividual.h"
#include "include/Parameters.h" #include "include/Parameters.h"
using namespace std;
CSelectionOperator* CPopulation::selectionOperator; CSelectionOperator* CPopulation::selectionOperator;
CSelectionOperator* CPopulation::replacementOperator; CSelectionOperator* CPopulation::replacementOperator;
CSelectionOperator* CPopulation::parentReductionOperator; CSelectionOperator* CPopulation::parentReductionOperator;
...@@ -234,6 +238,19 @@ void CPopulation::sortRPopulation(CIndividual** population, size_t populationSiz ...@@ -234,6 +238,19 @@ void CPopulation::sortRPopulation(CIndividual** population, size_t populationSiz
qsort(population,populationSize,sizeof(CIndividual*),CIndividualRCompare); qsort(population,populationSize,sizeof(CIndividual*),CIndividualRCompare);
} }
/* Fonction qui va serializer la population */
void CPopulation::serializePopulation(){
ofstream EASEA_File;
std::string fichier = params->outputFilename;
fichier.append(".pop");
EASEA_File.open(fichier.c_str(), ios::app);
for(int i=0; (unsigned)i<parentPopulationSize; i++){
EASEA_File << parents[i]->serialize() << endl;
}
EASEA_File.close();
}
/** /**
Reduit les populations en faisant l'operation de remplacement. Reduit les populations en faisant l'operation de remplacement.
...@@ -381,11 +398,12 @@ void CPopulation::weakElitism(size_t elitismSize, CIndividual** parentsPopulatio ...@@ -381,11 +398,12 @@ void CPopulation::weakElitism(size_t elitismSize, CIndividual** parentsPopulatio
} }
for(int i = 0 ; (unsigned)i<elitismSize ; i++ ){ for(int i = 0 ; (unsigned)i<elitismSize ; i++ ){
if((!params->minimizing && bestParentFitness > bestOffspringFitness) || (params->minimizing && bestParentFitness<bestOffspringFitness)){ if(((!params->minimizing && bestParentFitness > bestOffspringFitness) || (params->minimizing && bestParentFitness<bestOffspringFitness) || (*offPopSize)==0) && (*parentPopSize)>0){
outPopulation[i] = parentsPopulation[bestParentIndiv]; outPopulation[i] = parentsPopulation[bestParentIndiv];
parentsPopulation[bestParentIndiv] = parentsPopulation[(*parentPopSize)-1]; parentsPopulation[bestParentIndiv] = parentsPopulation[(*parentPopSize)-1];
parentsPopulation[(*parentPopSize)-1] = NULL; parentsPopulation[(*parentPopSize)-1] = NULL;
(*parentPopSize)-=1; (*parentPopSize)-=1;
if((*parentPopSize)>0){
bestParentFitness = parentsPopulation[0]->getFitness(); bestParentFitness = parentsPopulation[0]->getFitness();
bestParentIndiv=0; bestParentIndiv=0;
for(int j=1; (unsigned)j<(*parentPopSize); j++){ for(int j=1; (unsigned)j<(*parentPopSize); j++){
...@@ -396,11 +414,13 @@ void CPopulation::weakElitism(size_t elitismSize, CIndividual** parentsPopulatio ...@@ -396,11 +414,13 @@ void CPopulation::weakElitism(size_t elitismSize, CIndividual** parentsPopulatio
} }
} }
} }
}
else{ else{
outPopulation[i] = offspringPopulation[bestOffspringIndiv]; outPopulation[i] = offspringPopulation[bestOffspringIndiv];
offspringPopulation[bestOffspringIndiv] = offspringPopulation[(*offPopSize)-1]; offspringPopulation[bestOffspringIndiv] = offspringPopulation[(*offPopSize)-1];
offspringPopulation[(*offPopSize)-1] = NULL; offspringPopulation[(*offPopSize)-1] = NULL;
(*offPopSize)-=1; (*offPopSize)-=1;
if((*offPopSize)>0){
bestOffspringFitness = offspringPopulation[0]->getFitness(); bestOffspringFitness = offspringPopulation[0]->getFitness();
bestOffspringIndiv = 0; bestOffspringIndiv = 0;
for(int j=1; (unsigned)j<(*offPopSize); j++){ for(int j=1; (unsigned)j<(*offPopSize); j++){
...@@ -412,6 +432,7 @@ void CPopulation::weakElitism(size_t elitismSize, CIndividual** parentsPopulatio ...@@ -412,6 +432,7 @@ void CPopulation::weakElitism(size_t elitismSize, CIndividual** parentsPopulatio
} }
} }
} }
}
} }
......
...@@ -52,6 +52,7 @@ CSelectionOperator* getSelectionOperator(std::string selectop, int minimizing, C ...@@ -52,6 +52,7 @@ CSelectionOperator* getSelectionOperator(std::string selectop, int minimizing, C
} }
} }
/* **************************************** /* ****************************************
SelectionOperator class SelectionOperator class
****************************************/ ****************************************/
...@@ -62,13 +63,15 @@ void CSelectionOperator::initialize(CIndividual** population, float selectionPre ...@@ -62,13 +63,15 @@ void CSelectionOperator::initialize(CIndividual** population, float selectionPre
size_t CSelectionOperator::selectNext(size_t populationSize){ return 0; } size_t CSelectionOperator::selectNext(size_t populationSize){ return 0; }
/* ****************************************
MaxDeterministic class
****************************************/
void MaxDeterministic::initialize(CIndividual** population, float selectionPressure,size_t populationSize){ void MaxDeterministic::initialize(CIndividual** population, float selectionPressure,size_t populationSize){
CSelectionOperator::initialize(population,selectionPressure,populationSize); CSelectionOperator::initialize(population,selectionPressure,populationSize);
CPopulation::sortPopulation(population,populationSize); CPopulation::sortPopulation(population,populationSize);
populationSize = populationSize; populationSize = populationSize;
} }
size_t MaxDeterministic::selectNext(size_t populationSize){ size_t MaxDeterministic::selectNext(size_t populationSize){
return populationSize-1; return populationSize-1;
} }
...@@ -77,14 +80,15 @@ float MaxDeterministic::getExtremum(){ ...@@ -77,14 +80,15 @@ float MaxDeterministic::getExtremum(){
return -FLT_MAX; return -FLT_MAX;
} }
/* ****************************************
MinDeterministic class
****************************************/
void MinDeterministic::initialize(CIndividual** population, float selectionPressure,size_t populationSize){ void MinDeterministic::initialize(CIndividual** population, float selectionPressure,size_t populationSize){
CSelectionOperator::initialize(population,selectionPressure,populationSize); CSelectionOperator::initialize(population,selectionPressure,populationSize);
CPopulation::sortRPopulation(population,populationSize); CPopulation::sortRPopulation(population,populationSize);
populationSize = populationSize; populationSize = populationSize;
} }
size_t MinDeterministic::selectNext(size_t populationSize){ size_t MinDeterministic::selectNext(size_t populationSize){
return populationSize-1; return populationSize-1;
} }
...@@ -93,6 +97,9 @@ float MinDeterministic::getExtremum(){ ...@@ -93,6 +97,9 @@ float MinDeterministic::getExtremum(){
return FLT_MAX; return FLT_MAX;
} }
/* ****************************************
MaxRandom class
****************************************/
MaxRandom::MaxRandom(CRandomGenerator* globalRandomGenerator){ MaxRandom::MaxRandom(CRandomGenerator* globalRandomGenerator){
rg = globalRandomGenerator; rg = globalRandomGenerator;
} }
...@@ -109,6 +116,9 @@ float MaxRandom::getExtremum(){ ...@@ -109,6 +116,9 @@ float MaxRandom::getExtremum(){
return -FLT_MAX; return -FLT_MAX;
} }
/* ****************************************
MinRandom class
****************************************/
MinRandom::MinRandom(CRandomGenerator* globalRandomGenerator){ MinRandom::MinRandom(CRandomGenerator* globalRandomGenerator){
rg = globalRandomGenerator; rg = globalRandomGenerator;
} }
...@@ -126,7 +136,9 @@ float MinRandom::getExtremum(){ ...@@ -126,7 +136,9 @@ float MinRandom::getExtremum(){
} }
/* ****************************************
MinTournament class
****************************************/
void MinTournament::initialize(CIndividual** population, float selectionPressure, size_t populationSize) { void MinTournament::initialize(CIndividual** population, float selectionPressure, size_t populationSize) {
CSelectionOperator::initialize(population,selectionPressure,populationSize); CSelectionOperator::initialize(population,selectionPressure,populationSize);
} }
...@@ -135,7 +147,6 @@ float MinTournament::getExtremum(){ ...@@ -135,7 +147,6 @@ float MinTournament::getExtremum(){
return FLT_MAX; return FLT_MAX;
} }
size_t MinTournament::selectNext(size_t populationSize){ size_t MinTournament::selectNext(size_t populationSize){
size_t bestIndex = 0; size_t bestIndex = 0;
float bestFitness = FLT_MAX; float bestFitness = FLT_MAX;
...@@ -178,6 +189,10 @@ size_t MinTournament::selectNext(size_t populationSize){ ...@@ -178,6 +189,10 @@ size_t MinTournament::selectNext(size_t populationSize){
return bestIndex; return bestIndex;
} }
/* ****************************************
MaxTournament class
****************************************/
void MaxTournament::initialize(CIndividual** population, float selectionPressure, size_t populationSize) { void MaxTournament::initialize(CIndividual** population, float selectionPressure, size_t populationSize) {
CSelectionOperator::initialize(population,selectionPressure,populationSize); CSelectionOperator::initialize(population,selectionPressure,populationSize);
} }
...@@ -186,10 +201,9 @@ float MaxTournament::getExtremum(){ ...@@ -186,10 +201,9 @@ float MaxTournament::getExtremum(){
return -FLT_MAX; return -FLT_MAX;
} }
size_t MaxTournament::selectNext(size_t populationSize){ size_t MaxTournament::selectNext(size_t populationSize){