Commit 7baaa751 authored by kruger's avatar kruger

Version Memetic STD

parent 9d46eb94
...@@ -24,6 +24,7 @@ Centre de Math ...@@ -24,6 +24,7 @@ Centre de Math
#define STD_FLAVOR_SO 0 #define STD_FLAVOR_SO 0
#define STD_FLAVOR_MO 1 #define STD_FLAVOR_MO 1
#define STD_FLAVOR_CMAES 2 #define STD_FLAVOR_CMAES 2
#define STD_FLAVOR_MEMETIC 3
#define CUDA_FLAVOR_SO 0 #define CUDA_FLAVOR_SO 0
#define CUDA_FLAVOR_MO 1 #define CUDA_FLAVOR_MO 1
#define CUDA_FLAVOR_CMAES 2 #define CUDA_FLAVOR_CMAES 2
...@@ -46,9 +47,10 @@ extern float fSELECT_PRM, fRED_PAR_PRM, fRED_FINAL_PRM, fRED_OFF_PRM; ...@@ -46,9 +47,10 @@ extern float fSELECT_PRM, fRED_PAR_PRM, fRED_FINAL_PRM, fRED_OFF_PRM;
extern char sSELECTOR[], sSELECTOR_OPERATOR[], sRED_PAR[], sRED_PAR_OPERATOR[], sRED_FINAL[], sRED_FINAL_OPERATOR[], sRED_OFF[], sRED_OFF_OPERATOR[]; extern char sSELECTOR[], sSELECTOR_OPERATOR[], sRED_PAR[], sRED_PAR_OPERATOR[], sRED_FINAL[], sRED_FINAL_OPERATOR[], sRED_OFF[], sRED_OFF_OPERATOR[];
extern int nMINIMISE,nELITE; extern int nMINIMISE,nELITE;
extern bool bELITISM, bVERBOSE; extern bool bELITISM, bVERBOSE;
extern bool bPRINT_STATS, bPLOT_STATS, bGENERATE_CVS_FILE, bGENERATE_GNUPLOT_SCRIPT, bGENERATE_R_SCRIPT; extern bool bBALDWINISM;
extern bool bPRINT_STATS, bPLOT_STATS, bGENERATE_CSV_FILE, bGENERATE_GNUPLOT_SCRIPT, bGENERATE_R_SCRIPT;
extern char* nGENOME_NAME; extern char* nGENOME_NAME;
extern int nPOP_SIZE, nNB_GEN, nOFF_SIZE, nPROBLEM_DIM, nTIME_LIMIT; extern int nPOP_SIZE, nNB_GEN, nNB_OPT_IT, nOFF_SIZE, nPROBLEM_DIM, nTIME_LIMIT;
extern float fMUT_PROB, fXOVER_PROB, fSURV_PAR_SIZE, fSURV_OFF_SIZE; extern float fMUT_PROB, fXOVER_PROB, fSURV_PAR_SIZE, fSURV_OFF_SIZE;
extern int nWARNINGS, nERRORS; extern int nWARNINGS, nERRORS;
......
...@@ -73,7 +73,7 @@ Centre de Math ...@@ -73,7 +73,7 @@ Centre de Math
%start GENOME_ANALYSIS TEMPLATE_ANALYSIS MACRO_IDENTIFIER MACRO_DEFINITION %start GENOME_ANALYSIS TEMPLATE_ANALYSIS MACRO_IDENTIFIER MACRO_DEFINITION
%start COPY_USER_DECLARATIONS COPY_INITIALISATION_FUNCTION ANALYSE_USER_CLASSES %start COPY_USER_DECLARATIONS COPY_INITIALISATION_FUNCTION ANALYSE_USER_CLASSES
%start COPY_EO_INITIALISER %start COPY_EO_INITIALISER
%start COPY COPY_INITIALISER COPY_CROSSOVER COPY_MUTATOR COPY_EVALUATOR COPY_FINALIZATION_FUNCTION %start COPY COPY_INITIALISER COPY_CROSSOVER COPY_MUTATOR COPY_EVALUATOR COPY_FINALIZATION_FUNCTION COPY_OPTIMISER
%start COPY_DISPLAY COPY_USER_FUNCTION COPY_USER_GENERATION PARAMETERS_ANALYSIS GET_PARAMETERS %start COPY_DISPLAY COPY_USER_FUNCTION COPY_USER_GENERATION PARAMETERS_ANALYSIS GET_PARAMETERS
%start COPY_USER_FUNCTIONS COPY_GENERATION_FUNCTION_BEFORE_REPLACEMENT GET_METHODS COPY_MAKEFILE_OPTION COPY_BOUND_CHECKING_FUNCTION COPY_BEG_GENERATION_FUNCTION COPY_END_GENERATION_FUNCTION COPY_INSTEAD_EVAL %start COPY_USER_FUNCTIONS COPY_GENERATION_FUNCTION_BEFORE_REPLACEMENT GET_METHODS COPY_MAKEFILE_OPTION COPY_BOUND_CHECKING_FUNCTION COPY_BEG_GENERATION_FUNCTION COPY_END_GENERATION_FUNCTION COPY_INSTEAD_EVAL
...@@ -81,7 +81,7 @@ Centre de Math ...@@ -81,7 +81,7 @@ Centre de Math
%name CEASEALexer { %name CEASEALexer {
protected: protected:
CSymbolTable *pSymbolTable; // the symbol table CSymbolTable *pSymbolTable; // the symbol table
bool bSymbolInserted,bWithinEvaluator; // used to change evalutor type from double to float bool bSymbolInserted,bWithinEvaluator, bWithinOptimiser; // used to change evalutor type from double to float
bool bInitFunction,bDisplayFunction,bFunction, bNotFinishedYet, bWithinEO_Function; bool bInitFunction,bDisplayFunction,bFunction, bNotFinishedYet, bWithinEO_Function;
bool bDoubleQuotes,bWithinDisplayFunction,bWithinInitialiser,bWithinMutator,bWithinXover; bool bDoubleQuotes,bWithinDisplayFunction,bWithinInitialiser,bWithinMutator,bWithinXover;
bool bWaitingForSemiColon,bFinishNB_GEN,bFinishMINIMISE,bFinishMINIMIZE,bGenerationReplacementFunction; bool bWaitingForSemiColon,bFinishNB_GEN,bFinishMINIMISE,bFinishMINIMIZE,bGenerationReplacementFunction;
...@@ -98,7 +98,7 @@ Centre de Math ...@@ -98,7 +98,7 @@ Centre de Math
// constructor // constructor
{ {
bFunction=bWithinEvaluator=bDisplayFunction=bInitFunction=bNotFinishedYet=0; bFunction=bWithinEvaluator=bWithinOptimiser=bDisplayFunction=bInitFunction=bNotFinishedYet=0;
bSymbolInserted=bDoubleQuotes=bWithinDisplayFunction=bWithinInitialiser=bWithinMutator=bWithinXover=0; bSymbolInserted=bDoubleQuotes=bWithinDisplayFunction=bWithinInitialiser=bWithinMutator=bWithinXover=0;
bWaitingForSemiColon=bFinishNB_GEN=bFinishMINIMISE=bFinishMINIMIZE=bGenerationReplacementFunction=0; bWaitingForSemiColon=bFinishNB_GEN=bFinishMINIMISE=bFinishMINIMIZE=bGenerationReplacementFunction=0;
bCatchNextSemiColon,bWaitingToClosePopulation=bMethodsInGenome=0; bCatchNextSemiColon,bWaitingToClosePopulation=bMethodsInGenome=0;
...@@ -549,6 +549,11 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -549,6 +549,11 @@ exponent ([Ee][+-]?[0-9]+)
lineCounter=1; lineCounter=1;
BEGIN COPY_EVALUATOR; BEGIN COPY_EVALUATOR;
} }
<TEMPLATE_ANALYSIS>"\\INSERT_OPTIMISER" {
yyreset();
yyin = fpGenomeFile; // switch to .ez file and analyser
BEGIN COPY_OPTIMISER;
}
<TEMPLATE_ANALYSIS>"\\INSERT_CUDA_EVALUATOR" { <TEMPLATE_ANALYSIS>"\\INSERT_CUDA_EVALUATOR" {
yyreset(); yyreset();
...@@ -711,10 +716,12 @@ if(OPERATING_SYSTEM=WINDOWS) ...@@ -711,10 +716,12 @@ if(OPERATING_SYSTEM=WINDOWS)
case STD: case STD:
case CUDA: fprintf(fpOutputFile,"%d",bELITISM); case CUDA: fprintf(fpOutputFile,"%d",bELITISM);
} } } }
<TEMPLATE_ANALYSIS>"\\NB_OPT_IT" {fprintf(fpOutputFile,"%d",nNB_OPT_IT);}
<TEMPLATE_ANALYSIS>"\\BALDWINISM" {fprintf(fpOutputFile,"%d",bBALDWINISM);}
<TEMPLATE_ANALYSIS>"\\PRINT_STATS" {fprintf(fpOutputFile,"%d",bPRINT_STATS);} <TEMPLATE_ANALYSIS>"\\PRINT_STATS" {fprintf(fpOutputFile,"%d",bPRINT_STATS);}
<TEMPLATE_ANALYSIS>"\\PLOT_STATS" {fprintf(fpOutputFile,"%d",bPLOT_STATS);} <TEMPLATE_ANALYSIS>"\\PLOT_STATS" {fprintf(fpOutputFile,"%d",bPLOT_STATS);}
<TEMPLATE_ANALYSIS>"\\GENERATE_CVS_FILE" {fprintf(fpOutputFile,"%d",bGENERATE_CVS_FILE);} <TEMPLATE_ANALYSIS>"\\GENERATE_CSV_FILE" {fprintf(fpOutputFile,"%d",bGENERATE_CSV_FILE);}
<TEMPLATE_ANALYSIS>"\\GENERATE_GNUPLOT_SCRIPT" {fprintf(fpOutputFile,"%d",bGENERATE_GNUPLOT_SCRIPT);} <TEMPLATE_ANALYSIS>"\\GENERATE_GNUPLOT_SCRIPT" {fprintf(fpOutputFile,"%d",bGENERATE_GNUPLOT_SCRIPT);}
<TEMPLATE_ANALYSIS>"\\GENERATE_R_SCRIPT" {fprintf(fpOutputFile,"%d",bGENERATE_R_SCRIPT);} <TEMPLATE_ANALYSIS>"\\GENERATE_R_SCRIPT" {fprintf(fpOutputFile,"%d",bGENERATE_R_SCRIPT);}
...@@ -1354,6 +1361,15 @@ if(OPERATING_SYSTEM=WINDOWS) ...@@ -1354,6 +1361,15 @@ if(OPERATING_SYSTEM=WINDOWS)
<COPY_EVALUATOR>. {} <COPY_EVALUATOR>. {}
<COPY_EVALUATOR>\n {lineCounter++;} <COPY_EVALUATOR>\n {lineCounter++;}
<COPY_OPTIMISER>"\\GenomeClass::optimiser"[ \t\n]*":" {
BEGIN COPY_USER_FUNCTION;
bWithinOptimiser=1;
if( bLINE_NUM_EZ_FILE )
fprintf(fpOutputFile,"#line %d \"%s.ez\"\n",lineCounter, sRAW_PROJECT_NAME);
return USER_OPTIMISER;
}
<COPY_OPTIMISER>.|\n {lineCounter++;}
//**************************************** //****************************************
// Basic copy to .cpp file with major changes // Basic copy to .cpp file with major changes
//**************************************** //****************************************
...@@ -1549,7 +1565,7 @@ if(OPERATING_SYSTEM=WINDOWS) ...@@ -1549,7 +1565,7 @@ if(OPERATING_SYSTEM=WINDOWS)
<COPY_USER_FUNCTION>"Genome" { <COPY_USER_FUNCTION>"Genome" {
if(bWithinEvaluator || bWithinMutator || bWithinDisplayFunction){ if(bWithinOptimiser || bWithinEvaluator || bWithinMutator || bWithinDisplayFunction){
if( bWithinCUDA_Evaluator) if( bWithinCUDA_Evaluator)
fprintf(fpOutputFile, "(*INDIVIDUAL_ACCESS(devBuffer,id))"); fprintf(fpOutputFile, "(*INDIVIDUAL_ACCESS(devBuffer,id))");
else fprintf(fpOutputFile, "(*this)"); else fprintf(fpOutputFile, "(*this)");
...@@ -1641,7 +1657,7 @@ if(OPERATING_SYSTEM=WINDOWS) ...@@ -1641,7 +1657,7 @@ if(OPERATING_SYSTEM=WINDOWS)
<COPY_USER_FUNCTION>"\\end" {rewind(fpGenomeFile); <COPY_USER_FUNCTION>"\\end" {rewind(fpGenomeFile);
yyin = fpTemplateFile; yyin = fpTemplateFile;
BEGIN TEMPLATE_ANALYSIS; BEGIN TEMPLATE_ANALYSIS;
bWithinInitialiser=bWithinXover=bWithinMutator=bWithinEvaluator=bWithinCUDA_Evaluator=0; bWithinInitialiser=bWithinXover=bWithinMutator=bWithinEvaluator=bWithinOptimiser=bWithinCUDA_Evaluator=0;
if (bWithinDisplayFunction){ if (bWithinDisplayFunction){
bWithinDisplayFunction=0; // display function bWithinDisplayFunction=0; // display function
} }
...@@ -1680,7 +1696,7 @@ if(OPERATING_SYSTEM=WINDOWS) ...@@ -1680,7 +1696,7 @@ if(OPERATING_SYSTEM=WINDOWS)
<GET_PARAMETERS>"Print"[ \t\n]+"stats"[ \t\n]*":"[\t\n]* {if (bVERBOSE) printf("\tPrint Stats...\n");return PRINT_STATS;} <GET_PARAMETERS>"Print"[ \t\n]+"stats"[ \t\n]*":"[\t\n]* {if (bVERBOSE) printf("\tPrint Stats...\n");return PRINT_STATS;}
<GET_PARAMETERS>"Plot"[ \t\n]+"stats"[ \t\n]*":"[\t\n]* {if (bVERBOSE) printf("\tPlot Stats with gnuplot...\n");return PLOT_STATS;} <GET_PARAMETERS>"Plot"[ \t\n]+"stats"[ \t\n]*":"[\t\n]* {if (bVERBOSE) printf("\tPlot Stats with gnuplot...\n");return PLOT_STATS;}
<GET_PARAMETERS>"Generate"[ \t\n]+"cvs"[ \t\n]+"stats"[ \t\n]+"file"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tPrint Stats to cvs File...\n");return GENERATE_CVS_FILE;} <GET_PARAMETERS>"Generate"[ \t\n]+"csv"[ \t\n]+"stats"[ \t\n]+"file"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tPrint Stats to csv File...\n");return GENERATE_CSV_FILE;}
<GET_PARAMETERS>"Generate"[ \t\n]+"gnuplot"[ \t\n]+"script"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tGenerate Gnuplot Script...\n");return GENERATE_GNUPLOT_SCRIPT;} <GET_PARAMETERS>"Generate"[ \t\n]+"gnuplot"[ \t\n]+"script"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tGenerate Gnuplot Script...\n");return GENERATE_GNUPLOT_SCRIPT;}
<GET_PARAMETERS>"Generate"[ \t\n]+"R"[ \t\n]+"script"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tGenerate R Script...\n");return GENERATE_R_SCRIPT;} <GET_PARAMETERS>"Generate"[ \t\n]+"R"[ \t\n]+"script"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tGenerate R Script...\n");return GENERATE_R_SCRIPT;}
...@@ -1702,6 +1718,8 @@ if(OPERATING_SYSTEM=WINDOWS) ...@@ -1702,6 +1718,8 @@ if(OPERATING_SYSTEM=WINDOWS)
<GET_PARAMETERS>"Final"[ \t\n]+"reduce"[ \t\n]+"operator"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tFinal Reduce Operator...\n");return RED_FINAL;}// DISCARD;} <GET_PARAMETERS>"Final"[ \t\n]+"reduce"[ \t\n]+"operator"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tFinal Reduce Operator...\n");return RED_FINAL;}// DISCARD;}
<GET_PARAMETERS>"Elitism"[ \t\n]*":" {if (bVERBOSE) printf ("\tElitism...\n");return ELITISM;} <GET_PARAMETERS>"Elitism"[ \t\n]*":" {if (bVERBOSE) printf ("\tElitism...\n");return ELITISM;}
<GET_PARAMETERS>"Evaluator"[ \t\n]+"goal"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tMinMax...\n");return MINIMAXI;} <GET_PARAMETERS>"Evaluator"[ \t\n]+"goal"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tMinMax...\n");return MINIMAXI;}
<GET_PARAMETERS>"Number"[ \t\n]+"of"[ \t\n]+"optimisation"[ \t\n]+"iterations"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tNb of Optimisation It...\n");return NB_OPT_IT;}
<GET_PARAMETERS>"Baldwinism"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tBaldwinism...\n");return BALDWINISM;}
// number // number
<GET_PARAMETERS>[0-9]+"."[0-9]*{exponent}? | <GET_PARAMETERS>[0-9]+"."[0-9]*{exponent}? |
...@@ -1840,6 +1858,8 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable) ...@@ -1840,6 +1858,8 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable)
strcat(sTemp,"STD.tpl"); strcat(sTemp,"STD.tpl");
else if (TARGET_FLAVOR == STD_FLAVOR_CMAES) else if (TARGET_FLAVOR == STD_FLAVOR_CMAES)
strcat(sTemp,"CMAES.tpl"); strcat(sTemp,"CMAES.tpl");
else if (TARGET_FLAVOR == STD_FLAVOR_MEMETIC )
strcat(sTemp,"STD_MEM.tpl");
else else
strcat(sTemp,"STD_MO.tpl"); strcat(sTemp,"STD_MO.tpl");
if (!(yyin = fpTemplateFile = fopen(sTemp, "r"))){ if (!(yyin = fpTemplateFile = fopen(sTemp, "r"))){
......
...@@ -39,18 +39,20 @@ float fRED_OFF_PRM;//[50] = {0}; ...@@ -39,18 +39,20 @@ float fRED_OFF_PRM;//[50] = {0};
char sRED_FINAL[50], sRED_FINAL_OPERATOR[50]; char sRED_FINAL[50], sRED_FINAL_OPERATOR[50];
float fRED_FINAL_PRM=0.0;//[50]; float fRED_FINAL_PRM=0.0;//[50];
int nMINIMISE=2; int nMINIMISE=2;
int nELITE; int nELITE=0;
bool bELITISM=0; bool bELITISM=0;
bool bVERBOSE=0; bool bVERBOSE=0;
bool bLINE_NUM_EZ_FILE=1; bool bLINE_NUM_EZ_FILE=1;
bool bPRINT_STATS=1; bool bPRINT_STATS=1;
bool bPLOT_STATS=0; bool bPLOT_STATS=0;
bool bGENERATE_CVS_FILE=0, bGENERATE_R_SCRIPT=0, bGENERATE_GNUPLOT_SCRIPT=0; bool bGENERATE_CSV_FILE=0, bGENERATE_R_SCRIPT=0, bGENERATE_GNUPLOT_SCRIPT=0;
bool bBALDWINISM=0;
int nPOP_SIZE, nOFF_SIZE; int nPOP_SIZE, nOFF_SIZE;
float fSURV_PAR_SIZE=-1.0, fSURV_OFF_SIZE=-1.0; float fSURV_PAR_SIZE=-1.0, fSURV_OFF_SIZE=-1.0;
char *nGENOME_NAME; char *nGENOME_NAME;
int nPROBLEM_DIM; int nPROBLEM_DIM;
int nNB_GEN; int nNB_GEN=0;
int nNB_OPT_IT=0;
int nTIME_LIMIT=0; int nTIME_LIMIT=0;
float fMUT_PROB; float fMUT_PROB;
float fXOVER_PROB; float fXOVER_PROB;
...@@ -94,6 +96,7 @@ class CSymbol; ...@@ -94,6 +96,7 @@ class CSymbol;
%token USER_XOVER %token USER_XOVER
%token USER_MUTATOR %token USER_MUTATOR
%token USER_EVALUATOR %token USER_EVALUATOR
%token USER_OPTIMISER
%token MAKEFILE_OPTION %token MAKEFILE_OPTION
%token END_OF_FUNCTION %token END_OF_FUNCTION
//%token DELETE //%token DELETE
...@@ -111,6 +114,8 @@ class CSymbol; ...@@ -111,6 +114,8 @@ class CSymbol;
%token METHODS %token METHODS
%token STATIC %token STATIC
%token NB_GEN %token NB_GEN
%token NB_OPT_IT //Memetic
%token BALDWINISM //Memetic
%token MUT_PROB %token MUT_PROB
%token XOVER_PROB %token XOVER_PROB
%token POP_SIZE %token POP_SIZE
...@@ -126,7 +131,7 @@ class CSymbol; ...@@ -126,7 +131,7 @@ class CSymbol;
%token ELITE %token ELITE
%token PRINT_STATS %token PRINT_STATS
%token PLOT_STATS %token PLOT_STATS
%token GENERATE_CVS_FILE %token GENERATE_CSV_FILE
%token GENERATE_GNUPLOT_SCRIPT %token GENERATE_GNUPLOT_SCRIPT
%token GENERATE_R_SCRIPT %token GENERATE_R_SCRIPT
%token TIME_LIMIT %token TIME_LIMIT
...@@ -446,6 +451,12 @@ StandardFunctionAnalysis ...@@ -446,6 +451,12 @@ StandardFunctionAnalysis
END_OF_FUNCTION { END_OF_FUNCTION {
if (TARGET!=CUDA && TARGET!=STD) fprintf(fpOutputFile,"}\n"); if (TARGET!=CUDA && TARGET!=STD) fprintf(fpOutputFile,"}\n");
} }
| USER_OPTIMISER {
if (bVERBOSE) printf("Inserting user genome optimiser (taken from .ez file).\n");
}
END_OF_FUNCTION {
if (TARGET!=CUDA && TARGET!=STD) fprintf(fpOutputFile,"}\n");
}
| MAKEFILE_OPTION END_OF_FUNCTION { | MAKEFILE_OPTION END_OF_FUNCTION {
//DEBUG_PRT("User makefile options have been reduced"); //DEBUG_PRT("User makefile options have been reduced");
} }
...@@ -460,6 +471,8 @@ RunParameters ...@@ -460,6 +471,8 @@ RunParameters
Parameter Parameter
: NB_GEN NUMBER2 : NB_GEN NUMBER2
{nNB_GEN=(int)$2;} {nNB_GEN=(int)$2;}
| NB_OPT_IT NUMBER2
{nNB_OPT_IT=(int)$2;}
| TIME_LIMIT NUMBER2 | TIME_LIMIT NUMBER2
{nTIME_LIMIT=(int)$2;} {nTIME_LIMIT=(int)$2;}
| MUT_PROB NUMBER2 | MUT_PROB NUMBER2
...@@ -576,6 +589,14 @@ Parameter ...@@ -576,6 +589,14 @@ Parameter
fprintf(stderr,"\n%s - Warning line %d: Elitism must be \"Strong\" or \"Weak\".\nDefault value \"Strong\" inserted.\n.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++; fprintf(stderr,"\n%s - Warning line %d: Elitism must be \"Strong\" or \"Weak\".\nDefault value \"Strong\" inserted.\n.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
bELITISM=1; bELITISM=1;
}} }}
| BALDWINISM IDENTIFIER2{
if (!mystricmp($2->sName,"False")) bELITISM=0;
else if (!mystricmp($2->sName,"True")) bELITISM=1;
else {
fprintf(stderr,"\n%s - Warning line %d: Lamarckism must be \"True\" or \"False\".\nDefault value \"True\" inserted.\n.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
bELITISM=1;
}}
| PRINT_STATS NUMBER2{ | PRINT_STATS NUMBER2{
if((int)$2>=1) if((int)$2>=1)
bPRINT_STATS=1; bPRINT_STATS=1;
...@@ -588,11 +609,11 @@ Parameter ...@@ -588,11 +609,11 @@ Parameter
else else
bPLOT_STATS=0; bPLOT_STATS=0;
} }
| GENERATE_CVS_FILE NUMBER2{ | GENERATE_CSV_FILE NUMBER2{
if((int)$2>=1) if((int)$2>=1)
bGENERATE_CVS_FILE=1; bGENERATE_CSV_FILE=1;
else else
bGENERATE_CVS_FILE=0; bGENERATE_CSV_FILE=0;
} }
| GENERATE_GNUPLOT_SCRIPT NUMBER2{ | GENERATE_GNUPLOT_SCRIPT NUMBER2{
if((int)$2>=1) if((int)$2>=1)
...@@ -678,11 +699,14 @@ int main(int argc, char *argv[]){ ...@@ -678,11 +699,14 @@ int main(int argc, char *argv[]){
TARGET=CUDA; TARGET=CUDA;
TARGET_FLAVOR = CUDA_FLAVOR_CMAES; TARGET_FLAVOR = CUDA_FLAVOR_CMAES;
} }
else if (!mystricmp(sTemp,"memetic")) {
TARGET=STD;
TARGET_FLAVOR = STD_FLAVOR_MEMETIC;
}
else if (!mystricmp(sTemp,"v")) bVERBOSE=true; else if (!mystricmp(sTemp,"v")) bVERBOSE=true;
else if (!mystricmp(sTemp,"tl")){ else if (!mystricmp(sTemp,"tl")){
printf("yopyop true line\n");
bLINE_NUM_EZ_FILE=false; bLINE_NUM_EZ_FILE=false;
} }
else if (!mystricmp(sTemp,"path")) { else if (!mystricmp(sTemp,"path")) {
......
...@@ -152,8 +152,8 @@ CPPFLAGS+= ...@@ -152,8 +152,8 @@ CPPFLAGS+=
\Default run parameters : // Please let the parameters appear in this order \Default run parameters : // Please let the parameters appear in this order
Number of generations : 100 // NB_GEN Number of generations : 100 // NB_GEN
Time limit: 0 // In seconds, 0 to deactivate Time limit: 0 // In seconds, 0 to deactivate
Population size : 3840 //POP_SIZE Population size : 10 //POP_SIZE
Offspring size : 3840 // 40% Offspring size : 10 // 40%
Mutation probability : 1 // MUT_PROB Mutation probability : 1 // MUT_PROB
Crossover probability : 1 // XOVER_PROB Crossover probability : 1 // XOVER_PROB
Evaluator goal : minimise // Maximise Evaluator goal : minimise // Maximise
......
...@@ -87,9 +87,9 @@ CEvolutionaryAlgorithm::CEvolutionaryAlgorithm(Parameters* params){ ...@@ -87,9 +87,9 @@ CEvolutionaryAlgorithm::CEvolutionaryAlgorithm(Parameters* params){
fichier.append(".plot"); fichier.append(".plot");
remove(fichier.c_str()); remove(fichier.c_str());
} }
if(params->generateRScript || params->generateCVSFile){ if(params->generateRScript || params->generateCSVFile){
string fichier = params->outputFilename; string fichier = params->outputFilename;
fichier.append(".cvs"); fichier.append(".csv");
remove(fichier.c_str()); remove(fichier.c_str());
} }
if(params->generateRScript){ if(params->generateRScript){
...@@ -113,6 +113,13 @@ void CEvolutionaryAlgorithm::addStoppingCriterion(CStoppingCriterion* sc){ ...@@ -113,6 +113,13 @@ void CEvolutionaryAlgorithm::addStoppingCriterion(CStoppingCriterion* sc){
void CEvolutionaryAlgorithm::runEvolutionaryLoop(){ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
CIndividual** elitistPopulation; CIndividual** elitistPopulation;
#ifdef WIN32
clock_t begin(clock());
#else
struct timeval begin;
gettimeofday(&begin,NULL);
#endif
std::cout << "Parent's population initializing "<< std::endl; std::cout << "Parent's population initializing "<< std::endl;
this->initializeParentPopulation(); this->initializeParentPopulation();
if(!INSTEAD_EVAL_STEP) if(!INSTEAD_EVAL_STEP)
...@@ -120,14 +127,17 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){ ...@@ -120,14 +127,17 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
else else
evale_pop_chunk(population->parents, population->parentPopulationSize); evale_pop_chunk(population->parents, population->parentPopulationSize);
if(this->params->optimise){
population->optimiseParentPopulation();
}
this->population->currentEvaluationNb += this->params->parentPopulationSize; this->population->currentEvaluationNb += this->params->parentPopulationSize;
if(this->params->printInitialPopulation){ if(this->params->printInitialPopulation){
std::cout << *population << std::endl; std::cout << *population << std::endl;
} }
showPopulationStats(begin);
struct timeval begin; currentGeneration += 1;
gettimeofday(&begin,NULL);
//Initialize elitPopulation //Initialize elitPopulation
if(params->elitSize) if(params->elitSize)
...@@ -144,6 +154,10 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){ ...@@ -144,6 +154,10 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
evale_pop_chunk(population->offsprings, population->offspringPopulationSize); evale_pop_chunk(population->offsprings, population->offspringPopulationSize);
population->currentEvaluationNb += this->params->offspringPopulationSize; population->currentEvaluationNb += this->params->offspringPopulationSize;
if(this->params->optimise){
population->optimiseOffspringPopulation();
}
EASEAGenerationFunctionBeforeReplacement(this); EASEAGenerationFunctionBeforeReplacement(this);
/* ELITISM */ /* ELITISM */
...@@ -169,7 +183,7 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){ ...@@ -169,7 +183,7 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
population->reduceTotalPopulation(elitistPopulation); population->reduceTotalPopulation(elitistPopulation);
population->sortParentPopulation(); population->sortParentPopulation();
if( this->params->printStats || this->params->generateCVSFile ) if( this->params->printStats || this->params->generateCSVFile )
showPopulationStats(begin); showPopulationStats(begin);
bBest = population->Best; bBest = population->Best;
EASEAEndGenerationFunction(this); EASEAEndGenerationFunction(this);
...@@ -246,11 +260,11 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){ ...@@ -246,11 +260,11 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){
fclose(f); fclose(f);
} }
} }
if(params->generateCVSFile || params->generateRScript){ //Generation du fichier CVS; if(params->generateCSVFile || params->generateRScript){ //Generation du fichier CSV;
FILE *f; FILE *f;
string fichier = params->outputFilename; string fichier = params->outputFilename;
fichier.append(".cvs"); fichier.append(".csv");
f = fopen(fichier.c_str(),"a"); //ajouter .cvs f = fopen(fichier.c_str(),"a"); //ajouter .csv
if(f!=NULL){ if(f!=NULL){
if(currentGeneration==0) if(currentGeneration==0)
fprintf(f,"GEN,TIME,EVAL,BEST,AVG,STDEV\n"); fprintf(f,"GEN,TIME,EVAL,BEST,AVG,STDEV\n");
...@@ -304,7 +318,7 @@ void CEvolutionaryAlgorithm::generateRScript(){ ...@@ -304,7 +318,7 @@ void CEvolutionaryAlgorithm::generateRScript(){
f=fopen(fichier.c_str(),"a"); f=fopen(fichier.c_str(),"a");
fprintf(f,"#Plotting for R\n"), fprintf(f,"#Plotting for R\n"),
fprintf(f,"png(\"%s\")\n",params->plotOutputFilename); fprintf(f,"png(\"%s\")\n",params->plotOutputFilename);
fprintf(f,"data <- read.table(\"./%s.cvs\",sep=\",\")\n",params->outputFilename); fprintf(f,"data <- read.table(\"./%s.csv\",sep=\",\")\n",params->outputFilename);
fprintf(f,"plot(0, type = \"n\", main = \"Plot Title\", xlab = \"Number of Evaluations\", ylab = \"Fitness\", xlim = c(0,%d) )\n",population->currentEvaluationNb); fprintf(f,"plot(0, type = \"n\", main = \"Plot Title\", xlab = \"Number of Evaluations\", ylab = \"Fitness\", xlim = c(0,%d) )\n",population->currentEvaluationNb);
fprintf(f,"grid() # add grid\n"); fprintf(f,"grid() # add grid\n");
fprintf(f,"lines(data[,3], data[,4], lty = 1) #draw first dataset\n"); fprintf(f,"lines(data[,3], data[,4], lty = 1) #draw first dataset\n");
......
...@@ -132,6 +132,8 @@ void parseArguments(const char* parametersFileName, int ac, char** av, ...@@ -132,6 +132,8 @@ void parseArguments(const char* parametersFileName, int ac, char** av,
("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)")
("baldwinism",po::value<int>(),"Only keep fitness (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)")
......
...@@ -106,19 +106,27 @@ void CPopulation::initPopulation(CSelectionOperator* selectionOperator, ...@@ -106,19 +106,27 @@ void CPopulation::initPopulation(CSelectionOperator* selectionOperator,
void CPopulation::evaluatePopulation(CIndividual** population, size_t populationSize){ void CPopulation::evaluatePopulation(CIndividual** population, size_t populationSize){
for( size_t i=0 ; i < populationSize ; i++ ) for( size_t i=0 ; i < populationSize ; i++ )
population[i]->evaluate(); population[i]->evaluate();
//currentEvaluationNb += populationSize;
} }
void CPopulation::optimisePopulation(CIndividual** population, size_t populationSize){
}
void CPopulation::evaluateParentPopulation(){ void CPopulation::evaluateParentPopulation(){
evaluatePopulation(parents,parentPopulationSize); evaluatePopulation(parents,parentPopulationSize);
} }
void CPopulation::optimiseParentPopulation(){
optimisePopulation(parents,parentPopulationSize);
}
void CPopulation::evaluateOffspringPopulation(){ void CPopulation::evaluateOffspringPopulation(){
evaluatePopulation(offsprings,offspringPopulationSize); evaluatePopulation(offsprings,offspringPopulationSize);
} }
void CPopulation::optimiseOffspringPopulation(){
optimisePopulation(offsprings,offspringPopulationSize);
}
/** /**
Reduit la population population de taille populationSize Reduit la population population de taille populationSize
......
...@@ -65,12 +65,15 @@ public: ...@@ -65,12 +65,15 @@ public:
//virtual void initializeParentPopulation() = 0; //virtual void initializeParentPopulation() = 0;
void addIndividualParentPopulation(CIndividual* indiv); void addIndividualParentPopulation(CIndividual* indiv);
void evaluatePopulation(CIndividual** population, size_t populationSize); void evaluatePopulation(CIndividual** population, size_t populationSize);
virtual void optimisePopulation(CIndividual** population, size_t populationSize);
virtual void evaluateParentPopulation(); virtual void evaluateParentPopulation();
void optimiseParentPopulation();
void strongElitism(size_t elitismSize, CIndividual** population, size_t populationSize, CIndividual** outPopulation, size_t outPopulationSize); void strongElitism(size_t elitismSize, CIndividual** population, size_t populationSize, CIndividual** outPopulation, size_t outPopulationSize);
void weakElitism(size_t elitismSize, CIndividual** parentsPopulation, CIndividual** offspringPopulation, size_t* parentPopSize, size_t* offPopSize, CIndividual** outPopulation, size_t outPopulationSize); void weakElitism(size_t elitismSize, CIndividual** parentsPopulation, CIndividual** offspringPopulation, size_t* parentPopSize, size_t* offPopSize, CIndividual** outPopulation, size_t outPopulationSize);
virtual void evaluateOffspringPopulation(); virtual void evaluateOffspringPopulation();
void optimiseOffspringPopulation();
CIndividual** reducePopulations(CIndividual** population, size_t populationSize, CIndividual** reducePopulations(CIndividual** population, size_t populationSize,
CIndividual** reducedPopulation, size_t obSize); CIndividual** reducedPopulation, size_t obSize);
CIndividual** reduceParentPopulation(size_t obSize); CIndividual** reduceParentPopulation(size_t obSize);
......
...@@ -50,8 +50,12 @@ public: ...@@ -50,8 +50,12 @@ public:
bool strongElitism; bool strongElitism;
unsigned int elitSize; unsigned int elitSize;
bool optimise;
int optimiseIterations;
bool baldwinism;
int printStats; int printStats;
int generateCVSFile; int generateCSVFile;
int generateGnuplotScript; int generateGnuplotScript;
int generateRScript; int generateRScript;
int plotStats; int plotStats;
......
...@@ -84,7 +84,7 @@ int main(int argc, char** argv){ ...@@ -84,7 +84,7 @@ int main(int argc, char** argv){
using namespace std; using namespace std;
#include "EASEAIndividual.hpp" #include "EASEAIndividual.hpp"
bool INSTEAD_EVAL_STEP = false;
CRandomGenerator* globalRandomGenerator; CRandomGenerator* globalRandomGenerator;
extern CEvolutionaryAlgorithm* EA; extern CEvolutionaryAlgorithm* EA;
...@@ -102,6 +102,9 @@ extern CEvolutionaryAlgorithm* EA; ...@@ -102,6 +102,9 @@ extern CEvolutionaryAlgorithm* EA;
\INSERT_BOUND_CHECKING \INSERT_BOUND_CHECKING
void evale_pop_chunk(CIndividual** population, int popSize){
\INSTEAD_EVAL_FUNCTION
}
void EASEAInit(int argc, char** argv){ void EASEAInit(int argc, char** argv){
\INSERT_INIT_FCT_CALL \INSERT_INIT_FCT_CALL
...@@ -276,20 +279,21 @@ void ParametersImpl::setDefaultParameters(int argc, char** argv){ ...@@ -276,20 +279,21 @@ void ParametersImpl::setDefaultParameters(int argc, char** argv){
controlCStopingCriterion = new CControlCStopingCriterion(); controlCStopingCriterion = new CControlCStopingCriterion();
timeCriterion = new CTimeCriterion(setVariable("timeLimit",\TIME_LIMIT)); timeCriterion = new CTimeCriterion(setVariable("timeLimit",\TIME_LIMIT));
this->optimise = 0;
seed = setVariable("seed",(int)time(0)); seed = setVariable("seed",(int)time(0));
globalRandomGenerator = new CRandomGenerator(seed); globalRandomGenerator = new CRandomGenerator(seed);
this->randomGenerator = globalRandomGenerator; this->randomGenerator = globalRandomGenerator;
this->printStats = setVariable("printStats",\PRINT_STATS); this->printStats = setVariable("printStats",\PRINT_STATS);
this->generateCVSFile = setVariable("generateCSVFile",\GENERATE_CVS_FILE); this->generateCSVFile = setVariable("generateCSVFile",\GENERATE_CSV_FILE);
this->generateGnuplotScript = setVariable("generateGnuplotScript",\GENERATE_GNUPLOT_SCRIPT); this->generateGnuplotScript = setVariable("generateGnuplotScript",\GENERATE_GNUPLOT_SCRIPT);