Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

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

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) {
/*process received data */
memmove(p->data[(*p->nb_data)].data,buffer,sizeof(char)*MAXINDSIZE);
(*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));
// printf("address %p\n",(p->data));
// printf("address %p\n",(p->data));
pthread_mutex_unlock(&server_mutex);
/*reset receiving buffer*/
memset(buffer,0,MAXINDSIZE);
......
This diff is collapsed.
......@@ -151,8 +151,8 @@ GPNode* selectNode( GPNode* root, int* childId, int* depth){
@return : pointer to the root node of the resulting sub tree
*/
GPNode* construction_method( const int constLen, const int totalLen , const int currentDepth,
const int maxDepth, const bool full,
const unsigned* opArity, const int OP_ERC){
const int maxDepth, const bool full,
const unsigned* opArity, const int OP_ERC){
GPNode* node = new GPNode();
// first select the opCode for the current Node.
if( full ){
......@@ -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,
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
for creation of trees.
......@@ -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) {
if (root->children[i]) {
toString_r(oss,root->children[i],opArity,opCodeName,OP_ERC);
if (i < opArity[(int)root->opCode] - 1) {
(*oss) << ' ';
}
toString_r(oss,root->children[i],opArity,opCodeName,OP_ERC);
if (i < opArity[(int)root->opCode] - 1) {
(*oss) << ' ';
}
}
}
}
......@@ -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){
if( root->opCode==OP_ERC )
fprintf(outputFile," %ld [label=\"%s : %f\"];\n", (long int)root, opCodeName[(int)root->opCode],
root->erc_value);
root->erc_value);
else
fprintf(outputFile," %ld [label=\"%s\"];\n", (long int)root, opCodeName[(int)root->opCode]);
......
......@@ -11,36 +11,36 @@ this->valid=0;
#endif
#ifndef WIN32
int toFils[2];
int toFils[2];
int toPere[2];
int sonPid;
this->valid=1;
this->valid=1;
if(pipe(toFils)<0){
perror("PipeComOpen: Creating pipes");
this->valid=0;
return;
this->valid=0;
return;
}
if(pipe(toPere)<0){
perror("PipeComOpen: Creating pipes");
this->valid=0;
return;
return;
}
switch((sonPid=vfork())){
case -1:
perror("PipeComOpen: fork failed");
this->valid=0;
this->valid=0;
break;
case 0:
/* --- here's the son --- */
if(dup2(toFils[0], fileno(stdin))<0){
perror("PipeComOpen(son): could not connect\n");
this->valid=0;
this->valid=0;
abort();
}
}
if(dup2(toPere[1], fileno(stdout))<0){
perror("PipeComOpen(son): could not connect\n");
this->valid=0;
this->valid=0;
abort();
}
char* pPath;
......@@ -59,19 +59,19 @@ this->valid=0;
if(execvp("java",arg)<0){
perror("java not installed, please change plotStats parameter\n");
abort();
this->valid=0;
this->valid=0;
}
break;
default :
if(this->valid){
this->fWrit = (FILE *)fdopen(toFils[1],"w");
this->fRead = (FILE *)fdopen(toPere[0],"r");
this->pid = sonPid;
/*fprintf(this->fWrit,"set term wxt persist\n");
fprintf(this->fWrit,"set grid\n");
fprintf(this->fWrit,"set xrange[0:%d]\n",nbEval);
fprintf(this->fWrit,"set xlabel \"Number of Evaluations\"\n");
fprintf(this->fWrit,"set ylabel \"Fitness\"\n");*/
default :
if(this->valid){
this->fWrit = (FILE *)fdopen(toFils[1],"w");
this->fRead = (FILE *)fdopen(toPere[0],"r");
this->pid = sonPid;
/*fprintf(this->fWrit,"set term wxt persist\n");
fprintf(this->fWrit,"set grid\n");
fprintf(this->fWrit,"set xrange[0:%d]\n",nbEval);
fprintf(this->fWrit,"set xlabel \"Number of Evaluations\"\n");
fprintf(this->fWrit,"set ylabel \"Fitness\"\n");*/
int nbEval = param->offspringPopulationSize*param->nbGen + param->parentPopulationSize;
fprintf(this->fWrit,"set max eval:%d\n",nbEval);
fprintf(this->fWrit,"set title:%s\n",title);
......@@ -79,16 +79,16 @@ this->valid=0;
fprintf(this->fWrit,"set island model\n");
fprintf(this->fWrit,"set max generation:%d\n",param->nbGen);
}
fflush(this->fWrit);
}
fflush(this->fWrit);
}
}
#endif
}
CGrapher::~CGrapher(){
#ifndef WIN32
//fprintf(this->fWrit,"quit\n");
fclose(this->fRead);
fclose(this->fWrit);
//fprintf(this->fWrit,"quit\n");
fclose(this->fRead);
fclose(this->fWrit);
#endif
}
......@@ -8,12 +8,12 @@
#include "include/CIndividual.h"
CIndividual::CIndividual() {
// TODO Auto-generated constructor stub
// TODO Auto-generated constructor stub
}
CIndividual::~CIndividual() {
// TODO Auto-generated destructor stub
// TODO Auto-generated destructor stub
}
......@@ -84,8 +84,8 @@ int loadParametersFile(const string& filename, char*** outputContainer){
while( fgets(buffer,512,paramFile)){
for( size_t i=0 ; i<512 ; i++ )
if( buffer[i] == '#' || buffer[i] == '\n' || buffer[i] == '\0' || buffer[i]==' '){
buffer[i] = '\0';
break;
buffer[i] = '\0';
break;
}
int str_len;
if( (str_len = strlen(buffer)) ){
......@@ -107,7 +107,7 @@ int loadParametersFile(const string& filename, char*** outputContainer){
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;
int argc;
......@@ -119,51 +119,51 @@ void parseArguments(const char* parametersFileName, int ac, char** av,
}
po::options_description desc("Allowed options ");
desc.add_options()
("help", "produce help message")
("compression", po::value<int>(), "set compression level")
("seed", po::value<int>(), "set the global seed of the pseudo random generator")
("popSize",po::value<int>(),"set the population size")
("nbOffspring",po::value<int>(),"set the offspring population size")
("survivingParents",po::value<float>(),"set the reduction size for parent 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")
("eliteType",po::value<int>(),"Strong (1) or weak (0)")
("nbGen",po::value<int>(),"Set the number of generation")
("timeLimit",po::value<int>(),"Set the timeLimit, (0) to deactivate")
("selectionOperator",po::value<string>(),"Set the Selection Operator (default : Tournament)")
("selectionPressure",po::value<float>(),"Set the Selection Pressure (default : 2.0)")
("reduceParentsOperator",po::value<string>(),"Set the Parents Reducing Operator (default : Tournament)")
("reduceParentsPressure",po::value<float>(),"Set the Parents Reducing Pressure (default : 2.0)")
("reduceOffspringOperator",po::value<string>(),"Set the Offspring Reducing Operator (default : Tournament)")
("reduceOffspringPressure",po::value<float>(),"Set the Offspring Reducing Pressure (default : 2.0)")
("reduceFinalOperator",po::value<string>(),"Set the Final Reducing Operator (default : Tournament)")
("reduceFinalPressure",po::value<float>(),"Set the Final Reducing Pressure (default : 2.0)")
("optimiseIterations",po::value<int>(),"Set the number of optimisation iterations (default : 100)")
("baldwinism",po::value<int>(),"Only keep fitness (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)")
("migrationProbability", po::value<float>(),"Probability to send an individual each generation")
("help", "produce help message")
("compression", po::value<int>(), "set compression level")
("seed", po::value<int>(), "set the global seed of the pseudo random generator")
("popSize",po::value<int>(),"set the population size")
("nbOffspring",po::value<int>(),"set the offspring population size")
("survivingParents",po::value<float>(),"set the reduction size for parent 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")
("eliteType",po::value<int>(),"Strong (1) or weak (0)")
("nbGen",po::value<int>(),"Set the number of generation")
("timeLimit",po::value<int>(),"Set the timeLimit, (0) to deactivate")
("selectionOperator",po::value<string>(),"Set the Selection Operator (default : Tournament)")
("selectionPressure",po::value<float>(),"Set the Selection Pressure (default : 2.0)")
("reduceParentsOperator",po::value<string>(),"Set the Parents Reducing Operator (default : Tournament)")
("reduceParentsPressure",po::value<float>(),"Set the Parents Reducing Pressure (default : 2.0)")
("reduceOffspringOperator",po::value<string>(),"Set the Offspring Reducing Operator (default : Tournament)")
("reduceOffspringPressure",po::value<float>(),"Set the Offspring Reducing Pressure (default : 2.0)")
("reduceFinalOperator",po::value<string>(),"Set the Final Reducing Operator (default : Tournament)")
("reduceFinalPressure",po::value<float>(),"Set the Final Reducing Pressure (default : 2.0)")
("optimiseIterations",po::value<int>(),"Set the number of optimisation iterations (default : 100)")
("baldwinism",po::value<int>(),"Only keep fitness (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)")
("migrationProbability", po::value<float>(),"Probability to send an individual each generation")
("serverPort", po::value<int>(),"Port of the Server")
("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)")
("printStats",po::value<int>(),"Print the Stats (default : 1)")
("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)")
("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)")
// ("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)")
("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")
("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")
("u1",po::value<string>(),"User defined parameter 1")
("u2",po::value<string>(),"User defined parameter 2")
("u3",po::value<int>(),"User defined parameter 3")
("u4",po::value<int>(),"User defined parameter 4")
("u5",po::value<int>(),"User defined parameter 5")
;
("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)")
("printStats",po::value<int>(),"Print the Stats (default : 1)")
("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)")
("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)")
// ("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)")
("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")
("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")
("u1",po::value<string>(),"User defined parameter 1")
("u2",po::value<string>(),"User defined parameter 2")
("u3",po::value<int>(),"User defined parameter 3")
("u4",po::value<int>(),"User defined parameter 4")
("u5",po::value<int>(),"User defined parameter 5")
;
try{
po::store(po::parse_command_line(ac, av, desc,0), vm);
......
......@@ -37,8 +37,8 @@ CPopulation::CPopulation(){
}
CPopulation::CPopulation(unsigned parentPopulationSize, unsigned offspringPopulationSize,
float pCrossover, float pMutation, float pMutationPerGene,
CRandomGenerator* rg, Parameters* params, CStats* cstats){
float pCrossover, float pMutation, float pMutationPerGene,
CRandomGenerator* rg, Parameters* params, CStats* cstats){
this->parents = new CIndividual*[parentPopulationSize];
this->offsprings = new CIndividual*[offspringPopulationSize];
......@@ -89,11 +89,11 @@ CPopulation::~CPopulation(){
}
void CPopulation::initPopulation(CSelectionOperator* selectionOperator,
CSelectionOperator* replacementOperator,
CSelectionOperator* parentReductionOperator,
CSelectionOperator* offspringReductionOperator,
float selectionPressure, float replacementPressure,
float parentReductionPressure, float offspringReductionPressure){
CSelectionOperator* replacementOperator,
CSelectionOperator* parentReductionOperator,
CSelectionOperator* offspringReductionOperator,
float selectionPressure, float replacementPressure,
float parentReductionPressure, float offspringReductionPressure){
CPopulation::selectionOperator = selectionOperator;
CPopulation::replacementOperator = replacementOperator;
CPopulation::parentReductionOperator = parentReductionOperator;
......@@ -144,8 +144,8 @@ void CPopulation::optimiseOffspringPopulation(){
*/
void CPopulation::reducePopulation(CIndividual** population, unsigned populationSize,
CIndividual** reducedPopulation, unsigned obSize,
CSelectionOperator* replacementOperator,int pressure){
CIndividual** reducedPopulation, unsigned obSize,
CSelectionOperator* replacementOperator,int pressure){
replacementOperator->initialize(population,pressure,populationSize);
......@@ -155,7 +155,7 @@ void CPopulation::reducePopulation(CIndividual** population, unsigned population
// select an CIndividual and add it to the reduced population
unsigned selectedIndex = replacementOperator->selectNext(populationSize - i);
// std::cout << "Selected " << selectedIndex << "/" << populationSize
// << " replaced by : " << populationSize-(i+1)<< std::endl;
// << " replaced by : " << populationSize-(i+1)<< std::endl;
reducedPopulation[i] = population[selectedIndex];
//printf("TEST REMPLACEMENT %d %d %f %f\n", i, selectedIndex, reducedPopulation[i]->fitness, population[selectedIndex]->fitness);
......@@ -171,13 +171,13 @@ void CPopulation::reducePopulation(CIndividual** population, unsigned population
CIndividual** CPopulation::reduceParentPopulation(unsigned obSize){
CIndividual** nextGeneration;
if(obSize==0){
nextGeneration = new CIndividual*[1];
nextGeneration = new CIndividual*[1];
}
else
nextGeneration = new CIndividual*[obSize];
nextGeneration = new CIndividual*[obSize];
reducePopulation(parents,actualParentPopulationSize,nextGeneration,obSize,
CPopulation::parentReductionOperator,parentReductionPressure);
CPopulation::parentReductionOperator,parentReductionPressure);
// free no longer needed CIndividuals
for( unsigned i=0 ; i<actualParentPopulationSize-obSize ; i++ )
......@@ -199,7 +199,7 @@ CIndividual** CPopulation::reduceOffspringPopulation(unsigned obSize){
CIndividual** nextGeneration = new CIndividual*[offspringPopulationSize];
reducePopulation(offsprings,actualOffspringPopulationSize,nextGeneration,obSize,
CPopulation::offspringReductionOperator,offspringReductionPressure);
CPopulation::offspringReductionOperator,offspringReductionPressure);
//printf("POPULATION SIZE %d\n",actualOffspringPopulationSize-obSize);
// free no longer needed CIndividuals
......@@ -208,7 +208,7 @@ CIndividual** CPopulation::reduceOffspringPopulation(unsigned obSize){
delete[](offsprings);
//printf("DANS LA FONCTION DE REMPLACEMENT\n");
/*for(int i=0; i<parentPopulationSize; i++)
printf("Indiv %d %f | ",i, parents[i]->fitness);
printf("Indiv %d %f | ",i, parents[i]->fitness);
printf("\n");*/
this->actualOffspringPopulationSize = obSize;
......@@ -247,19 +247,19 @@ void CPopulation::serializePopulation(){
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 << parents[i]->serialize() << endl;
}
EASEA_File.close();
}
int CPopulation::getWorstIndividualIndex(CIndividual** population){
int index=0;
for(int i=1; i<(signed)this->parentPopulationSize; i++){
if((params->minimizing && (population[i]->fitness > population[index]->fitness)) || (!params->minimizing && (population[i]->fitness < population[index]->fitness)))
index=i;
}
return index;
int index=0;
for(int i=1; i<(signed)this->parentPopulationSize; i++){
if((params->minimizing && (population[i]->fitness > population[index]->fitness)) || (!params->minimizing && (population[i]->fitness < population[index]->fitness)))
index=i;
}
return index;
}
......@@ -275,20 +275,20 @@ void CPopulation::reduceTotalPopulation(CIndividual** elitPop){
CIndividual** nextGeneration = new CIndividual*[parentPopulationSize];
if(params->elitSize)
memcpy(nextGeneration,elitPop, sizeof(CIndividual*)*params->elitSize);
memcpy(nextGeneration,elitPop, sizeof(CIndividual*)*params->elitSize);
unsigned actualGlobalSize = actualParentPopulationSize+actualOffspringPopulationSize;
CIndividual** globalPopulation = new CIndividual*[actualGlobalSize]();
if(actualParentPopulationSize==0){
memcpy(globalPopulation,offsprings,sizeof(CIndividual*)*actualOffspringPopulationSize);
memcpy(globalPopulation,offsprings,sizeof(CIndividual*)*actualOffspringPopulationSize);
}
else if(actualOffspringPopulationSize==0){
memcpy(globalPopulation,parents,sizeof(CIndividual*)*actualParentPopulationSize);
memcpy(globalPopulation,parents,sizeof(CIndividual*)*actualParentPopulationSize);
}
else{
memcpy(globalPopulation,parents,sizeof(CIndividual*)*actualParentPopulationSize);
memcpy(globalPopulation,parents,sizeof(CIndividual*)*actualParentPopulationSize);
memcpy(globalPopulation+actualParentPopulationSize,offsprings,sizeof(CIndividual*)*actualOffspringPopulationSize);
}
......@@ -296,7 +296,7 @@ void CPopulation::reduceTotalPopulation(CIndividual** elitPop){
replacementOperator->initialize(globalPopulation, replacementPressure,actualGlobalSize);
CPopulation::reducePopulation(globalPopulation,actualGlobalSize,params->elitSize+nextGeneration,
parentPopulationSize-params->elitSize,replacementOperator,replacementPressure);
parentPopulationSize-params->elitSize,replacementOperator,replacementPressure);
for( unsigned int i=0 ; i<((int)actualGlobalSize+params->elitSize)-(int)parentPopulationSize ; i++ )
......@@ -332,8 +332,8 @@ void CPopulation::produceOffspringPopulation(){
if( rg->tossCoin(pCrossover) ){
for( unsigned j=0 ; j<crossoverArrity-1 ; j++ ){
index = selectionOperator->selectNext(parentPopulationSize);
ps[j] = parents[index];
index = selectionOperator->selectNext(parentPopulationSize);
ps[j] = parents[index];
if( this->params->remoteIslandModel && parents[index]->isImmigrant ){
this->cstats->currentNumberOfImmigrantReproductions++;
}
......@@ -367,7 +367,7 @@ void CPopulation::produceOffspringPopulation(){
*/
void CPopulation::strongElitism(unsigned elitismSize, CIndividual** population, unsigned populationSize,
CIndividual** outPopulation, unsigned outPopulationSize){
CIndividual** outPopulation, unsigned outPopulationSize){
float bestFitness = population[0]->getFitness();
unsigned bestCIndividual = 0;
......@@ -383,11 +383,11 @@ void CPopulation::strongElitism(unsigned elitismSize, CIndividual** population,
bestCIndividual = 0;
for( unsigned j=0 ; j<populationSize-i ; j++ ){
if( (params->minimizing && bestFitness > population[j]->getFitness() ) ||
( !params->minimizing && bestFitness < population[j]->getFitness() )){
bestFitness = population[j]->getFitness();
bestCIndividual = j;
}
if( (params->minimizing && bestFitness > population[j]->getFitness() ) ||
( !params->minimizing && bestFitness < population[j]->getFitness() )){
bestFitness = population[j]->getFitness();
bestCIndividual = j;
}
}
outPopulation[i] = population[bestCIndividual];
population[bestCIndividual] = population[populationSize-(i+1)];
......@@ -419,49 +419,49 @@ void CPopulation::weakElitism(unsigned elitismSize, CIndividual** parentsPopulat
}
for(int i = 0 ; (unsigned)i<elitismSize ; i++ ){
if(((!params->minimizing && bestParentFitness > bestOffspringFitness) || (params->minimizing && bestParentFitness<bestOffspringFitness) || (*offPopSize)==0) && (*parentPopSize)>0){
outPopulation[i] = parentsPopulation[bestParentIndiv];
parentsPopulation[bestParentIndiv] = parentsPopulation[(*parentPopSize)-1];
parentsPopulation[(*parentPopSize)-1] = NULL;
(*parentPopSize)-=1;
if((*parentPopSize)>0){
bestParentFitness = parentsPopulation[0]->getFitness();
bestParentIndiv=0;
for(int j=1; (unsigned)j<(*parentPopSize); j++){
if( (params->minimizing && bestParentFitness > parentsPopulation[j]->getFitness() ) ||
( !params->minimizing && bestParentFitness < parentsPopulation[j]->getFitness() )){
bestParentFitness = parentsPopulation[j]->getFitness();
bestParentIndiv = j;
}
}
}
}
else{
outPopulation[i] = offspringPopulation[bestOffspringIndiv];
offspringPopulation[bestOffspringIndiv] = offspringPopulation[(*offPopSize)-1];
offspringPopulation[(*offPopSize)-1] = NULL;
(*offPopSize)-=1;
if((*offPopSize)>0){
bestOffspringFitness = offspringPopulation[0]->getFitness();
bestOffspringIndiv = 0;
for(int j=1; (unsigned)j<(*offPopSize); j++){
if( (params->minimizing && bestOffspringFitness > offspringPopulation[j]->getFitness() ) ||
( !params->minimizing && bestOffspringFitness < offspringPopulation[j]->getFitness() )){
bestOffspringFitness = offspringPopulation[j]->getFitness();
bestOffspringIndiv = j;
}
}
}
}
if(((!params->minimizing && bestParentFitness > bestOffspringFitness) || (params->minimizing && bestParentFitness<bestOffspringFitness) || (*offPopSize)==0) && (*parentPopSize)>0){
outPopulation[i] = parentsPopulation[bestParentIndiv];
parentsPopulation[bestParentIndiv] = parentsPopulation[(*parentPopSize)-1];
parentsPopulation[(*parentPopSize)-1] = NULL;
(*parentPopSize)-=1;
if((*parentPopSize)>0){
bestParentFitness = parentsPopulation[0]->getFitness();
bestParentIndiv=0;
for(int j=1; (unsigned)j<(*parentPopSize); j++){
if( (params->minimizing && bestParentFitness > parentsPopulation[j]->getFitness() ) ||
( !params->minimizing && bestParentFitness < parentsPopulation[j]->getFitness() )){
bestParentFitness = parentsPopulation[j]->getFitness();
bestParentIndiv = j;
}
}
}
}
else{
outPopulation[i] = offspringPopulation[bestOffspringIndiv];
offspringPopulation[bestOffspringIndiv] = offspringPopulation[(*offPopSize)-1];
offspringPopulation[(*offPopSize)-1] = NULL;
(*offPopSize)-=1;
if((*offPopSize)>0){
bestOffspringFitness = offspringPopulation[0]->getFitness();
bestOffspringIndiv = 0;
for(int j=1; (unsigned)j<(*offPopSize); j++){
if( (params->minimizing && bestOffspringFitness > offspringPopulation[j]->getFitness() ) ||
( !params->minimizing && bestOffspringFitness < offspringPopulation[j]->getFitness() )){
bestOffspringFitness = offspringPopulation[j]->getFitness();
bestOffspringIndiv = j;
}
}
}
}
}
}
void CPopulation::addIndividualParentPopulation(CIndividual* indiv, unsigned id){
parents[id] = indiv;
parents[id] = indiv;
}
void CPopulation::addIndividualParentPopulation(CIndividual* indiv){
parents[actualParentPopulationSize++] = indiv;
parents[actualParentPopulationSize++] = indiv;
}
std::ostream& operator << (std::ostream& O, const CPopulation& B)
......@@ -481,8 +481,8 @@ std::ostream& operator << (std::ostream& O, const CPopulation& B)
O << "\t Offspring size : "<< realOffspringPopulationSize << "/" <<
offspringPopulationSize << std::endl;
for( unsigned i=0 ; i<realParentPopulationSize ; i++){
B.parents[i]->printOn(O);
O << "\n";
B.parents[i]->printOn(O);
O << "\n";
}
return O;
......
......@@ -12,18 +12,18 @@
#include <math.h>
CRandomGenerator::CRandomGenerator(unsigned int seed){
this->seed = seed;
this->mt_rnd = new MTRand(seed);
//srand(seed);
this->seed = seed;
this->mt_rnd = new MTRand(seed);
//srand(seed);
}
CRandomGenerator::~CRandomGenerator(){
delete this->mt_rnd;
delete this->mt_rnd;
}
int CRandomGenerator::randInt(){
//return rand();
return mt_rnd->randInt();
return mt_rnd->randInt();