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) {
/*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);
......
This diff is collapsed.
......@@ -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();
}
bool CRandomGenerator::tossCoin(){
......@@ -40,8 +40,8 @@ bool CRandomGenerator::tossCoin(float bias){
}
int CRandomGenerator::randInt(int min, int max){
max--; // exclude upper bound
return min+mt_rnd->randInt(max-min);
max--; // exclude upper bound
return min+mt_rnd->randInt(max-min);
}
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){
return min+mt_rnd->randExc(max-min);
return min+mt_rnd->randExc(max-min);
}
float CRandomGenerator::random(float min, float max){
......@@ -97,6 +97,6 @@ float CRandomGenerator::random_gauss(float mean, float std_dev){
std::ostream & operator << (std::ostream & os, const CRandomGenerator& rg) {
os<< "s : " << rg.seed << std::endl;
return os;
os<< "s : " << rg.seed << std::endl;
return os;
}
......@@ -25,30 +25,30 @@ float getSelectionPressure(std::string selectop){
CSelectionOperator* getSelectionOperator(std::string selectop, int minimizing, CRandomGenerator* globalRandomGenerator){
if(minimizing){
if(selectop.compare("Tournament")==0)
return (new MinTournament(globalRandomGenerator));
else if (selectop.compare("Random")==0)
return (new MinRandom(globalRandomGenerator));
else if (selectop.compare("Deterministic")==0)
return (new MinDeterministic());
else{
std::cout << "Operateur n\'existe pas pour minimisation, utilise Tournament par defaut" << std::endl;
return (new MinTournament(globalRandomGenerator));
}
if(selectop.compare("Tournament")==0)
return (new MinTournament(globalRandomGenerator));
else if (selectop.compare("Random")==0)
return (new MinRandom(globalRandomGenerator));
else if (selectop.compare("Deterministic")==0)
return (new MinDeterministic());
else{
std::cout << "Operateur n\'existe pas pour minimisation, utilise Tournament par defaut" << std::endl;
return (new MinTournament(globalRandomGenerator));
}
}
else{
if(selectop.compare("Tournament")==0)
return (new MaxTournament(globalRandomGenerator));
else if (selectop.compare("Random")==0)
return (new MaxRandom(globalRandomGenerator));
else if (selectop.compare("Deterministic")==0)
return (new MaxDeterministic());
else if (selectop.compare("Roulette")==0)
return (new MaxRoulette(globalRandomGenerator));
else{
std::cout << "Operateur n\'existe pas pour maximisation, utilise Tournament par defaut" << std::endl;
return (new MaxTournament(globalRandomGenerator));
}
if(selectop.compare("Tournament")==0)
return (new MaxTournament(globalRandomGenerator));
else if (selectop.compare("Random")==0)
return (new MaxRandom(globalRandomGenerator));
else if (selectop.compare("Deterministic")==0)
return (new MaxDeterministic());
else if (selectop.compare("Roulette")==0)
return (new MaxRoulette(globalRandomGenerator));
else{
std::cout << "Operateur n\'existe pas pour maximisation, utilise Tournament par defaut" << std::endl;
return (new MaxTournament(globalRandomGenerator));
}
}
}
......@@ -159,8 +159,8 @@ size_t MinTournament::selectNext(size_t populationSize){
float currentFitness = population[selectedIndex]->getFitness();
if( bestFitness > currentFitness ){
bestIndex = selectedIndex;
bestFitness = currentFitness;
bestIndex = selectedIndex;
bestFitness = currentFitness;
}
}
......@@ -171,18 +171,18 @@ size_t MinTournament::selectNext(size_t populationSize){
if( rg->tossCoin(currentSelectionPressure) ){
if( population[i1]->getFitness() < population[i2]->getFitness() ){
bestIndex = i1;
bestIndex = i1;
}
}
else{
if( population[i1]->getFitness() < population[i2]->getFitness() ){
bestIndex = i2;
bestIndex = i2;
}
}
}
else{
std::cerr << " MinTournament selection operator doesn't handle selection pressure : "
<< currentSelectionPressure << std::endl;
<< currentSelectionPressure << std::endl;
}
//std::cout << std::endl;
......@@ -213,8 +213,8 @@ size_t MaxTournament::selectNext(size_t populationSize){
float currentFitness = population[selectedIndex]->getFitness();
if( bestFitness < currentFitness ){
bestIndex = selectedIndex;
bestFitness = currentFitness;
bestIndex = selectedIndex;
bestFitness = currentFitness;
}
}
......@@ -225,18 +225,18 @@ size_t MaxTournament::selectNext(size_t populationSize){
if( rg->tossCoin(currentSelectionPressure) ){
if( population[i1]->getFitness() > population[i2]->getFitness() ){
bestIndex = i1;
bestIndex = i1;
}
}
else{
if( population[i1]->getFitness() > population[i2]->getFitness() ){
bestIndex = i2;
bestIndex = i2;
}
}
}
else{
std::cerr << " MinTournament selection operator doesn't handle selection pressure : "
<< currentSelectionPressure << std::endl;
<< currentSelectionPressure << std::endl;
}
//std::cout << std::endl;
......@@ -274,7 +274,7 @@ size_t MaxRoulette::selectNext(size_t populationSize){
break;
}
}
free(poids);
free(poids);
return bestIndex;
}
......
......@@ -19,7 +19,7 @@ CGenerationalCriterion::CGenerationalCriterion(unsigned generationalLimit){
}
void CGenerationalCriterion::setCounterEa(unsigned* ea_counter){
this->currentGenerationPtr = ea_counter;
this->currentGenerationPtr = ea_counter;
}
bool CGenerationalCriterion::reached(){
......@@ -32,7 +32,7 @@ bool CGenerationalCriterion::reached(){
}
unsigned* CGenerationalCriterion::getGenerationalLimit(){
return &(this->generationalLimit);
return &(this->generationalLimit);
}
/* ****************************************
......@@ -45,25 +45,25 @@ CTimeCriterion::CTimeCriterion(unsigned timeLimit){
bool CTimeCriterion::reached(){
if(timeLimit>0){
//gettimeofday(&(this->end),0);
//timersub(&(this->end),&(this->begin), &(this->res));
//if((unsigned)res.tv_sec>timeLimit-1){
if((unsigned)elapsedTime>timeLimit-1){
std::cout << "Time Over" << std::endl;
std::cout << "Time Limit was " << timeLimit << " seconds" << std::endl;
return true;
}
else return false;
//gettimeofday(&(this->end),0);
//timersub(&(this->end),&(this->begin), &(this->res));
//if((unsigned)res.tv_sec>timeLimit-1){
if((unsigned)elapsedTime>timeLimit-1){
std::cout << "Time Over" << std::endl;
std::cout << "Time Limit was " << timeLimit << " seconds" << std::endl;
return true;
}
else return false;
}
else return false;
}
void CTimeCriterion::setElapsedTime(double elapsedTime){
this->elapsedTime = elapsedTime;
this->elapsedTime = elapsedTime;
}
double CTimeCriterion::getElapsedTime(){
return this->elapsedTime;
return this->elapsedTime;
}
/* ****************************************
......@@ -83,7 +83,7 @@ CControlCStopingCriterion::CControlCStopingCriterion(){
bool CControlCStopingCriterion::reached(){
if(ARRET_DEMANDE)
std::cout << "Algorithm stopped on user demand" << std::endl;
std::cout << "Algorithm stopped on user demand" << std::endl;
return ARRET_DEMANDE;
}
......
......@@ -21,8 +21,8 @@ int Parameters::setReductionSizes(int popSize, float popReducSize){
return (int)(popReducSize*popSize);
if(popReducSize<0.0)
return 0;
if(popReducSize == 1.0)
return popSize;
if(popReducSize == 1.0)
return popSize;
if((int)popReducSize>popSize){
printf("*WARNING* ReductionSize greater than 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