Commit 35b0aa2b authored by Joseph Pallamidessi's avatar Joseph Pallamidessi

Retabbing, and other minor aesthetic change

parent 541b0b9d
This diff is collapsed.
This diff is collapsed.
...@@ -56,9 +56,9 @@ void * CComUDPServer::UDP_server_thread(void *parm) { ...@@ -56,9 +56,9 @@ void * CComUDPServer::UDP_server_thread(void *parm) {
/*process received data */ /*process received data */
memmove(p->data[(*p->nb_data)].data,buffer,sizeof(char)*MAXINDSIZE); memmove(p->data[(*p->nb_data)].data,buffer,sizeof(char)*MAXINDSIZE);
(*p->nb_data)++; (*p->nb_data)++;
// printf("address %p\n",(p->data)); // printf("address %p\n",(p->data));
p->data = (RECV_DATA*)realloc(p->data,sizeof(RECV_DATA)*((*p->nb_data)+1)); p->data = (RECV_DATA*)realloc(p->data,sizeof(RECV_DATA)*((*p->nb_data)+1));
// printf("address %p\n",(p->data)); // printf("address %p\n",(p->data));
pthread_mutex_unlock(&server_mutex); pthread_mutex_unlock(&server_mutex);
/*reset receiving buffer*/ /*reset receiving buffer*/
memset(buffer,0,MAXINDSIZE); memset(buffer,0,MAXINDSIZE);
......
This diff is collapsed.
...@@ -151,8 +151,8 @@ GPNode* selectNode( GPNode* root, int* childId, int* depth){ ...@@ -151,8 +151,8 @@ GPNode* selectNode( GPNode* root, int* childId, int* depth){
@return : pointer to the root node of the resulting sub tree @return : pointer to the root node of the resulting sub tree
*/ */
GPNode* construction_method( const int constLen, const int totalLen , const int currentDepth, GPNode* construction_method( const int constLen, const int totalLen , const int currentDepth,
const int maxDepth, const bool full, const int maxDepth, const bool full,
const unsigned* opArity, const int OP_ERC){ const unsigned* opArity, const int OP_ERC){
GPNode* node = new GPNode(); GPNode* node = new GPNode();
// first select the opCode for the current Node. // first select the opCode for the current Node.
if( full ){ if( full ){
...@@ -185,7 +185,7 @@ GPNode* construction_method( const int constLen, const int totalLen , const int ...@@ -185,7 +185,7 @@ GPNode* construction_method( const int constLen, const int totalLen , const int
} }
GPNode* RAMPED_H_H(unsigned INIT_TREE_DEPTH_MIN, unsigned INIT_TREE_DEPTH_MAX, unsigned actualParentPopulationSize, unsigned parentPopulationSize, GPNode* RAMPED_H_H(unsigned INIT_TREE_DEPTH_MIN, unsigned INIT_TREE_DEPTH_MAX, unsigned actualParentPopulationSize, unsigned parentPopulationSize,
float GROW_FULL_RATIO, unsigned VAR_LEN, unsigned OPCODE_SIZE, const unsigned* opArity, const int OP_ERC){ float GROW_FULL_RATIO, unsigned VAR_LEN, unsigned OPCODE_SIZE, const unsigned* opArity, const int OP_ERC){
/** /**
This is the standard ramped half-and-half method This is the standard ramped half-and-half method
for creation of trees. for creation of trees.
...@@ -219,10 +219,10 @@ void toString_r(std::ostringstream* oss, GPNode* root, const unsigned* opArity , ...@@ -219,10 +219,10 @@ void toString_r(std::ostringstream* oss, GPNode* root, const unsigned* opArity ,
} }
for (unsigned i = 0; i < opArity[(int)root->opCode]; ++i) { for (unsigned i = 0; i < opArity[(int)root->opCode]; ++i) {
if (root->children[i]) { if (root->children[i]) {
toString_r(oss,root->children[i],opArity,opCodeName,OP_ERC); toString_r(oss,root->children[i],opArity,opCodeName,OP_ERC);
if (i < opArity[(int)root->opCode] - 1) { if (i < opArity[(int)root->opCode] - 1) {
(*oss) << ' '; (*oss) << ' ';
} }
} }
} }
} }
...@@ -252,7 +252,7 @@ std::string toString(GPNode* root, const unsigned* opArity , const char** opCode ...@@ -252,7 +252,7 @@ std::string toString(GPNode* root, const unsigned* opArity , const char** opCode
void toDotFile_r(GPNode* root, FILE* outputFile, const unsigned* opArity , const char** opCodeName, int OP_ERC){ void toDotFile_r(GPNode* root, FILE* outputFile, const unsigned* opArity , const char** opCodeName, int OP_ERC){
if( root->opCode==OP_ERC ) if( root->opCode==OP_ERC )
fprintf(outputFile," %ld [label=\"%s : %f\"];\n", (long int)root, opCodeName[(int)root->opCode], fprintf(outputFile," %ld [label=\"%s : %f\"];\n", (long int)root, opCodeName[(int)root->opCode],
root->erc_value); root->erc_value);
else else
fprintf(outputFile," %ld [label=\"%s\"];\n", (long int)root, opCodeName[(int)root->opCode]); fprintf(outputFile," %ld [label=\"%s\"];\n", (long int)root, opCodeName[(int)root->opCode]);
......
...@@ -11,36 +11,36 @@ this->valid=0; ...@@ -11,36 +11,36 @@ this->valid=0;
#endif #endif
#ifndef WIN32 #ifndef WIN32
int toFils[2]; int toFils[2];
int toPere[2]; int toPere[2];
int sonPid; int sonPid;
this->valid=1; this->valid=1;
if(pipe(toFils)<0){ if(pipe(toFils)<0){
perror("PipeComOpen: Creating pipes"); perror("PipeComOpen: Creating pipes");
this->valid=0; this->valid=0;
return; return;
} }
if(pipe(toPere)<0){ if(pipe(toPere)<0){
perror("PipeComOpen: Creating pipes"); perror("PipeComOpen: Creating pipes");
this->valid=0; this->valid=0;
return; return;
} }
switch((sonPid=vfork())){ switch((sonPid=vfork())){
case -1: case -1:
perror("PipeComOpen: fork failed"); perror("PipeComOpen: fork failed");
this->valid=0; this->valid=0;
break; break;
case 0: case 0:
/* --- here's the son --- */ /* --- here's the son --- */
if(dup2(toFils[0], fileno(stdin))<0){ if(dup2(toFils[0], fileno(stdin))<0){
perror("PipeComOpen(son): could not connect\n"); perror("PipeComOpen(son): could not connect\n");
this->valid=0; this->valid=0;
abort(); abort();
} }
if(dup2(toPere[1], fileno(stdout))<0){ if(dup2(toPere[1], fileno(stdout))<0){
perror("PipeComOpen(son): could not connect\n"); perror("PipeComOpen(son): could not connect\n");
this->valid=0; this->valid=0;
abort(); abort();
} }
char* pPath; char* pPath;
...@@ -59,19 +59,19 @@ this->valid=0; ...@@ -59,19 +59,19 @@ this->valid=0;
if(execvp("java",arg)<0){ if(execvp("java",arg)<0){
perror("java not installed, please change plotStats parameter\n"); perror("java not installed, please change plotStats parameter\n");
abort(); abort();
this->valid=0; this->valid=0;
} }
break; break;
default : default :
if(this->valid){ if(this->valid){
this->fWrit = (FILE *)fdopen(toFils[1],"w"); this->fWrit = (FILE *)fdopen(toFils[1],"w");
this->fRead = (FILE *)fdopen(toPere[0],"r"); this->fRead = (FILE *)fdopen(toPere[0],"r");
this->pid = sonPid; this->pid = sonPid;
/*fprintf(this->fWrit,"set term wxt persist\n"); /*fprintf(this->fWrit,"set term wxt persist\n");
fprintf(this->fWrit,"set grid\n"); fprintf(this->fWrit,"set grid\n");
fprintf(this->fWrit,"set xrange[0:%d]\n",nbEval); fprintf(this->fWrit,"set xrange[0:%d]\n",nbEval);
fprintf(this->fWrit,"set xlabel \"Number of Evaluations\"\n"); fprintf(this->fWrit,"set xlabel \"Number of Evaluations\"\n");
fprintf(this->fWrit,"set ylabel \"Fitness\"\n");*/ fprintf(this->fWrit,"set ylabel \"Fitness\"\n");*/
int nbEval = param->offspringPopulationSize*param->nbGen + param->parentPopulationSize; int nbEval = param->offspringPopulationSize*param->nbGen + param->parentPopulationSize;
fprintf(this->fWrit,"set max eval:%d\n",nbEval); fprintf(this->fWrit,"set max eval:%d\n",nbEval);
fprintf(this->fWrit,"set title:%s\n",title); fprintf(this->fWrit,"set title:%s\n",title);
...@@ -79,16 +79,16 @@ this->valid=0; ...@@ -79,16 +79,16 @@ this->valid=0;
fprintf(this->fWrit,"set island model\n"); fprintf(this->fWrit,"set island model\n");
fprintf(this->fWrit,"set max generation:%d\n",param->nbGen); fprintf(this->fWrit,"set max generation:%d\n",param->nbGen);
} }
fflush(this->fWrit); fflush(this->fWrit);
} }
} }
#endif #endif
} }
CGrapher::~CGrapher(){ CGrapher::~CGrapher(){
#ifndef WIN32 #ifndef WIN32
//fprintf(this->fWrit,"quit\n"); //fprintf(this->fWrit,"quit\n");
fclose(this->fRead); fclose(this->fRead);
fclose(this->fWrit); fclose(this->fWrit);
#endif #endif
} }
...@@ -8,12 +8,12 @@ ...@@ -8,12 +8,12 @@
#include "include/CIndividual.h" #include "include/CIndividual.h"
CIndividual::CIndividual() { CIndividual::CIndividual() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
CIndividual::~CIndividual() { CIndividual::~CIndividual() {
// TODO Auto-generated destructor stub // TODO Auto-generated destructor stub
} }
...@@ -84,8 +84,8 @@ int loadParametersFile(const string& filename, char*** outputContainer){ ...@@ -84,8 +84,8 @@ int loadParametersFile(const string& filename, char*** outputContainer){
while( fgets(buffer,512,paramFile)){ while( fgets(buffer,512,paramFile)){
for( size_t i=0 ; i<512 ; i++ ) for( size_t i=0 ; i<512 ; i++ )
if( buffer[i] == '#' || buffer[i] == '\n' || buffer[i] == '\0' || buffer[i]==' '){ if( buffer[i] == '#' || buffer[i] == '\n' || buffer[i] == '\0' || buffer[i]==' '){
buffer[i] = '\0'; buffer[i] = '\0';
break; break;
} }
int str_len; int str_len;
if( (str_len = strlen(buffer)) ){ if( (str_len = strlen(buffer)) ){
...@@ -107,7 +107,7 @@ int loadParametersFile(const string& filename, char*** outputContainer){ ...@@ -107,7 +107,7 @@ int loadParametersFile(const string& filename, char*** outputContainer){
void parseArguments(const char* parametersFileName, int ac, char** av, void parseArguments(const char* parametersFileName, int ac, char** av,
po::variables_map& vm, po::variables_map& vm_file){ po::variables_map& vm, po::variables_map& vm_file){
char** argv; char** argv;
int argc; int argc;
...@@ -119,51 +119,51 @@ void parseArguments(const char* parametersFileName, int ac, char** av, ...@@ -119,51 +119,51 @@ void parseArguments(const char* parametersFileName, int ac, char** av,
} }
po::options_description desc("Allowed options "); po::options_description desc("Allowed options ");
desc.add_options() desc.add_options()
("help", "produce help message") ("help", "produce help message")
("compression", po::value<int>(), "set compression level") ("compression", po::value<int>(), "set compression level")
("seed", po::value<int>(), "set the global seed of the pseudo random generator") ("seed", po::value<int>(), "set the global seed of the pseudo random generator")
("popSize",po::value<int>(),"set the population size") ("popSize",po::value<int>(),"set the population size")
("nbOffspring",po::value<int>(),"set the offspring population size") ("nbOffspring",po::value<int>(),"set the offspring population size")
("survivingParents",po::value<float>(),"set the reduction size for parent population") ("survivingParents",po::value<float>(),"set the reduction size for parent population")
("survivingOffspring",po::value<float>(),"set the reduction size for offspring population") ("survivingOffspring",po::value<float>(),"set the reduction size for offspring population")
("elite",po::value<int>(),"Nb of elite parents (absolute), 0 for no elite") ("elite",po::value<int>(),"Nb of elite parents (absolute), 0 for no elite")
("eliteType",po::value<int>(),"Strong (1) or weak (0)") ("eliteType",po::value<int>(),"Strong (1) or weak (0)")
("nbGen",po::value<int>(),"Set the number of generation") ("nbGen",po::value<int>(),"Set the number of generation")
("timeLimit",po::value<int>(),"Set the timeLimit, (0) to deactivate") ("timeLimit",po::value<int>(),"Set the timeLimit, (0) to deactivate")
("selectionOperator",po::value<string>(),"Set the Selection Operator (default : Tournament)") ("selectionOperator",po::value<string>(),"Set the Selection Operator (default : Tournament)")
("selectionPressure",po::value<float>(),"Set the Selection Pressure (default : 2.0)") ("selectionPressure",po::value<float>(),"Set the Selection Pressure (default : 2.0)")
("reduceParentsOperator",po::value<string>(),"Set the Parents Reducing Operator (default : Tournament)") ("reduceParentsOperator",po::value<string>(),"Set the Parents Reducing Operator (default : Tournament)")
("reduceParentsPressure",po::value<float>(),"Set the Parents Reducing Pressure (default : 2.0)") ("reduceParentsPressure",po::value<float>(),"Set the Parents Reducing Pressure (default : 2.0)")
("reduceOffspringOperator",po::value<string>(),"Set the Offspring Reducing Operator (default : Tournament)") ("reduceOffspringOperator",po::value<string>(),"Set the Offspring Reducing Operator (default : Tournament)")
("reduceOffspringPressure",po::value<float>(),"Set the Offspring Reducing Pressure (default : 2.0)") ("reduceOffspringPressure",po::value<float>(),"Set the Offspring Reducing Pressure (default : 2.0)")
("reduceFinalOperator",po::value<string>(),"Set the Final Reducing Operator (default : Tournament)") ("reduceFinalOperator",po::value<string>(),"Set the Final Reducing Operator (default : Tournament)")
("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)") ("remoteIslandModel",po::value<int>(),"Boolean to activate the individual exachange with remote islands (default : 0)")
("ipFile",po::value<string>(),"File containing all the IPs of the remote islands)") ("ipFile",po::value<string>(),"File containing all the IPs of the remote islands)")
("migrationProbability", po::value<float>(),"Probability to send an individual each generation") ("migrationProbability", po::value<float>(),"Probability to send an individual each generation")
("serverPort", po::value<int>(),"Port of the Server") ("serverPort", po::value<int>(),"Port of the Server")
("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)")
("plotStats",po::value<int>(),"Plot the Stats (default : 0)") ("plotStats",po::value<int>(),"Plot the Stats (default : 0)")
("generateCSVFile",po::value<int>(),"Print the Stats to a CSV File (Filename: ProjectName.dat) (default : 0)") ("generateCSVFile",po::value<int>(),"Print the Stats to a CSV File (Filename: ProjectName.dat) (default : 0)")
("generatePlotScript",po::value<int>(),"Generates a Gnuplot script to plat the Stats (Filename: ProjectName.plot) (default : 0)") ("generatePlotScript",po::value<int>(),"Generates a Gnuplot script to plat the Stats (Filename: ProjectName.plot) (default : 0)")
("generateRScript",po::value<int>(),"Generates a R script to plat the Stats (Filename: ProjectName.r) (default : 0)") ("generateRScript",po::value<int>(),"Generates a R script to plat the Stats (Filename: ProjectName.r) (default : 0)")
// ("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)") ("savePopulation",po::value<int>(),"Saves population at the end (default : 0)")
("startFromFile",po::value<int>(),"Loads the population from a .pop file (default : 0") ("startFromFile",po::value<int>(),"Loads the population from a .pop file (default : 0")
("fstgpu",po::value<int>(),"The number of the first GPU used for computation") ("fstgpu",po::value<int>(),"The number of the first GPU used for computation")
("lstgpu",po::value<int>(),"The number of the fisrt GPU NOT used for computation") ("lstgpu",po::value<int>(),"The number of the fisrt GPU NOT used for computation")
("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")
("u4",po::value<int>(),"User defined parameter 4") ("u4",po::value<int>(),"User defined parameter 4")
("u5",po::value<int>(),"User defined parameter 5") ("u5",po::value<int>(),"User defined parameter 5")
; ;
try{ try{
po::store(po::parse_command_line(ac, av, desc,0), vm); po::store(po::parse_command_line(ac, av, desc,0), vm);
......
This diff is collapsed.
...@@ -12,18 +12,18 @@ ...@@ -12,18 +12,18 @@
#include <math.h> #include <math.h>
CRandomGenerator::CRandomGenerator(unsigned int seed){ CRandomGenerator::CRandomGenerator(unsigned int seed){
this->seed = seed; this->seed = seed;
this->mt_rnd = new MTRand(seed); this->mt_rnd = new MTRand(seed);
//srand(seed); //srand(seed);
} }
CRandomGenerator::~CRandomGenerator(){ CRandomGenerator::~CRandomGenerator(){
delete this->mt_rnd; delete this->mt_rnd;
} }
int CRandomGenerator::randInt(){ int CRandomGenerator::randInt(){
//return rand(); //return rand();
return mt_rnd->randInt(); return mt_rnd->randInt();
} }
bool CRandomGenerator::tossCoin(){ bool CRandomGenerator::tossCoin(){
...@@ -40,8 +40,8 @@ bool CRandomGenerator::tossCoin(float bias){ ...@@ -40,8 +40,8 @@ bool CRandomGenerator::tossCoin(float bias){
} }
int CRandomGenerator::randInt(int min, int max){ int CRandomGenerator::randInt(int min, int max){
max--; // exclude upper bound max--; // exclude upper bound
return min+mt_rnd->randInt(max-min); return min+mt_rnd->randInt(max-min);
} }
int CRandomGenerator::random(int min, int max){ int CRandomGenerator::random(int min, int max){
...@@ -49,7 +49,7 @@ int CRandomGenerator::random(int min, int max){ ...@@ -49,7 +49,7 @@ int CRandomGenerator::random(int min, int max){
} }
float CRandomGenerator::randFloat(float min, float max){ float CRandomGenerator::randFloat(float min, float max){
return min+mt_rnd->randExc(max-min); return min+mt_rnd->randExc(max-min);
} }
float CRandomGenerator::random(float min, float max){ float CRandomGenerator::random(float min, float max){
...@@ -97,6 +97,6 @@ float CRandomGenerator::random_gauss(float mean, float std_dev){ ...@@ -97,6 +97,6 @@ float CRandomGenerator::random_gauss(float mean, float std_dev){
std::ostream & operator << (std::ostream & os, const CRandomGenerator& rg) { std::ostream & operator << (std::ostream & os, const CRandomGenerator& rg) {
os<< "s : " << rg.seed << std::endl; os<< "s : " << rg.seed << std::endl;
return os; return os;
} }
...@@ -25,30 +25,30 @@ float getSelectionPressure(std::string selectop){ ...@@ -25,30 +25,30 @@ float getSelectionPressure(std::string selectop){
CSelectionOperator* getSelectionOperator(std::string selectop, int minimizing, CRandomGenerator* globalRandomGenerator){ CSelectionOperator* getSelectionOperator(std::string selectop, int minimizing, CRandomGenerator* globalRandomGenerator){
if(minimizing){ if(minimizing){
if(selectop.compare("Tournament")==0) if(selectop.compare("Tournament")==0)
return (new MinTournament(globalRandomGenerator)); return (new MinTournament(globalRandomGenerator));
else if (selectop.compare("Random")==0) else if (selectop.compare("Random")==0)
return (new MinRandom(globalRandomGenerator)); return (new MinRandom(globalRandomGenerator));
else if (selectop.compare("Deterministic")==0) else if (selectop.compare("Deterministic")==0)
return (new MinDeterministic()); return (new MinDeterministic());
else{ else{
std::cout << "Operateur n\'existe pas pour minimisation, utilise Tournament par defaut" << std::endl; std::cout << "Operateur n\'existe pas pour minimisation, utilise Tournament par defaut" << std::endl;
return (new MinTournament(globalRandomGenerator)); return (new MinTournament(globalRandomGenerator));
} }
} }
else{ else{
if(selectop.compare("Tournament")==0) if(selectop.compare("Tournament")==0)
return (new MaxTournament(globalRandomGenerator)); return (new MaxTournament(globalRandomGenerator));
else if (selectop.compare("Random")==0) else if (selectop.compare("Random")==0)
return (new MaxRandom(globalRandomGenerator)); return (new MaxRandom(globalRandomGenerator));
else if (selectop.compare("Deterministic")==0) else if (selectop.compare("Deterministic")==0)
return (new MaxDeterministic()); return (new MaxDeterministic());
else if (selectop.compare("Roulette")==0) else if (selectop.compare("Roulette")==0)
return (new MaxRoulette(globalRandomGenerator)); return (new MaxRoulette(globalRandomGenerator));
else{ else{
std::cout << "Operateur n\'existe pas pour maximisation, utilise Tournament par defaut" << std::endl; std::cout << "Operateur n\'existe pas pour maximisation, utilise Tournament par defaut" << std::endl;
return (new MaxTournament(globalRandomGenerator)); return (new MaxTournament(globalRandomGenerator));
} }
} }
} }
...@@ -159,8 +159,8 @@ size_t MinTournament::selectNext(size_t populationSize){ ...@@ -159,8 +159,8 @@ size_t MinTournament::selectNext(size_t populationSize){
float currentFitness = population[selectedIndex]->getFitness(); float currentFitness = population[selectedIndex]->getFitness();
if( bestFitness > currentFitness ){ if( bestFitness > currentFitness ){
bestIndex = selectedIndex; bestIndex = selectedIndex;
bestFitness = currentFitness; bestFitness = currentFitness;
} }
} }
...@@ -171,18 +171,18 @@ size_t MinTournament::selectNext(size_t populationSize){ ...@@ -171,18 +171,18 @@ size_t MinTournament::selectNext(size_t populationSize){
if( rg->tossCoin(currentSelectionPressure) ){ if( rg->tossCoin(currentSelectionPressure) ){
if( population[i1]->getFitness() < population[i2]->getFitness() ){ if( population[i1]->getFitness() < population[i2]->getFitness() ){
bestIndex = i1; bestIndex = i1;
} }
} }
else{ else{
if( population[i1]->getFitness() < population[i2]->getFitness() ){ if( population[i1]->getFitness() < population[i2]->getFitness() ){
bestIndex = i2; bestIndex = i2;
} }
} }
} }
else{ else{
std::cerr << " MinTournament selection operator doesn't handle selection pressure : " std::cerr << " MinTournament selection operator doesn't handle selection pressure : "
<< currentSelectionPressure << std::endl; << currentSelectionPressure << std::endl;
} }
//std::cout << std::endl; //std::cout << std::endl;
...@@ -213,8 +213,8 @@ size_t MaxTournament::selectNext(size_t populationSize){ ...@@ -213,8 +213,8 @@ size_t MaxTournament::selectNext(size_t populationSize){
float currentFitness = population[selectedIndex]->getFitness(); float currentFitness = population[selectedIndex]->getFitness();
if( bestFitness < currentFitness ){ if( bestFitness < currentFitness ){
bestIndex = selectedIndex; bestIndex = selectedIndex;
bestFitness = currentFitness; bestFitness = currentFitness;
} }
} }
...@@ -225,18 +225,18 @@ size_t MaxTournament::selectNext(size_t populationSize){ ...@@ -225,18 +225,18 @@ size_t MaxTournament::selectNext(size_t populationSize){
if( rg->tossCoin(currentSelectionPressure) ){ if( rg->tossCoin(currentSelectionPressure) ){
if( population[i1]->getFitness() > population[i2]->getFitness() ){ if( population[i1]->getFitness() > population[i2]->getFitness() ){
bestIndex = i1; bestIndex = i1;
} }
} }
else{ else{
if( population[i1]->getFitness() > population[i2]->getFitness() ){ if( population[i1]->getFitness() > population[i2]->getFitness() ){
bestIndex = i2; bestIndex = i2;
} }
} }
} }
else{ else{
std::cerr << " MinTournament selection operator doesn't handle selection pressure : " std::cerr << " MinTournament selection operator doesn't handle selection pressure : "
<< currentSelectionPressure << std::endl; << currentSelectionPressure << std::endl;
} }
//std::cout << std::endl; //std::cout << std::endl;
...@@ -274,7 +274,7 @@ size_t MaxRoulette::selectNext(size_t populationSize){ ...@@ -274,7 +274,7 @@ size_t MaxRoulette::selectNext(size_t populationSize){
break; break;
} }
} }
free(poids); free(poids);
return bestIndex; return bestIndex;
} }
......
...@@ -19,7 +19,7 @@ CGenerationalCriterion::CGenerationalCriterion(unsigned generationalLimit){ ...@@ -19,7 +19,7 @@ CGenerationalCriterion::CGenerationalCriterion(unsigned generationalLimit){
} }
void CGenerationalCriterion::setCounterEa(unsigned* ea_counter){ void CGenerationalCriterion::setCounterEa(unsigned* ea_counter){
this->currentGenerationPtr = ea_counter; this->currentGenerationPtr = ea_counter;
} }
bool CGenerationalCriterion::reached(){ bool CGenerationalCriterion::reached(){
...@@ -32,7 +32,7 @@ bool CGenerationalCriterion::reached(){ ...@@ -32,7 +32,7 @@ bool CGenerationalCriterion::reached(){
} }
unsigned* CGenerationalCriterion::getGenerationalLimit(){ unsigned* CGenerationalCriterion::getGenerationalLimit(){
return &(this->generationalLimit); return &(this->generationalLimit);
} }
/* **************************************** /* ****************************************
...@@ -45,25 +45,25 @@ CTimeCriterion::CTimeCriterion(unsigned timeLimit){ ...@@ -45,25 +45,25 @@ CTimeCriterion::CTimeCriterion(unsigned timeLimit){
bool CTimeCriterion::reached(){ bool CTimeCriterion::reached(){
if(timeLimit>0){ if(timeLimit>0){
//gettimeofday(&(this->end),0); //gettimeofday(&(this->end),0);
//timersub(&(this->end),&(this->begin), &(this->res)); //timersub(&(this->end),&(this->begin), &(this->res));
//if((unsigned)res.tv_sec>timeLimit-1){ //if((unsigned)res.tv_sec>timeLimit-1){
if((unsigned)elapsedTime>timeLimit-1){ if((unsigned)elapsedTime>timeLimit-1){
std::cout << "Time Over" << std::endl; std::cout << "Time Over" << std::endl;
std::cout << "Time Limit was " << timeLimit << " seconds" << std::endl; std::cout << "Time Limit was " << timeLimit << " seconds" << std::endl;
return true; return true;
} }
else return false; else return false;
} }
else return false; else return false;
} }
void CTimeCriterion::setElapsedTime(double elapsedTime){ void CTimeCriterion::setElapsedTime(double elapsedTime){
this->elapsedTime = elapsedTime; this->elapsedTime = elapsedTime;
} }
double CTimeCriterion::getElapsedTime(){ double CTimeCriterion::getElapsedTime(){
return this->elapsedTime; return this->elapsedTime;
} }
/* **************************************** /* ****************************************
...@@ -83,7 +83,7 @@ CControlCStopingCriterion::CControlCStopingCriterion(){ ...@@ -83,7 +83,7 @@ CControlCStopingCriterion::CControlCStopingCriterion(){
bool CControlCStopingCriterion::reached(){ bool CControlCStopingCriterion::reached(){
if(ARRET_DEMANDE) if(ARRET_DEMANDE)
std::cout << "Algorithm stopped on user demand" << std::endl; std::cout << "Algorithm stopped on user demand" << std::endl;
return ARRET_DEMANDE; return ARRET_DEMANDE;
} }
......
...@@ -21,8 +21,8 @@ int Parameters::setReductionSizes(int popSize, float popReducSize){ ...@@ -21,8 +21,8 @@ int Parameters::setReductionSizes(int popSize, float popReducSize){
return (int)(popReducSize*popSize); return (int)(popReducSize*popSize);
if(popReducSize<0.0) if(popReducSize<0.0)
return 0; return 0;
if(popReducSize == 1.0) if(popReducSize == 1.0)
return popSize; return popSize;
if((int)popReducSize>popSize){ if((int)popReducSize>popSize){
printf("*WARNING* ReductionSize greater than PopulationSize !!!\n"); printf("*WARNING* ReductionSize greater than PopulationSize !!!\n");
printf("*WARNING* ReductionSize will be PopulationSize\n"); printf("*WARNING* ReductionSize will be PopulationSize\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment