Commit 4110cd42 authored by maitre's avatar maitre

Handle Makefile options from the ez file

parent 6a088d6d
...@@ -22,6 +22,7 @@ Centre de Math ...@@ -22,6 +22,7 @@ Centre de Math
#define EO 2 #define EO 2
#define DREAM 3 #define DREAM 3
#define CUDA 4 #define CUDA 4
#define STD 5
#define UNIX 1 #define UNIX 1
#define WINDOWS 2 #define WINDOWS 2
#define UNKNOWN_OS 3 #define UNKNOWN_OS 3
......
...@@ -29,6 +29,11 @@ Centre de Math ...@@ -29,6 +29,11 @@ Centre de Math
strcat(selectorName,"Tournament(globalRandomGenerator)"); strcat(selectorName,"Tournament(globalRandomGenerator)");
else if( mystricmp("dettour",sSELECTOR)==0 ) else if( mystricmp("dettour",sSELECTOR)==0 )
strcat(selectorName,"Tournament(globalRandomGenerator)"); strcat(selectorName,"Tournament(globalRandomGenerator)");
else if( mystricmp("Sequential",sSELECTOR)==0 )
strcat(selectorName,"Deterministic()");
else if( mystricmp("Random",sSELECTOR)==0 )
strcat(selectorName,"Random(globalRandomGenerator)");
else return NULL; else return NULL;
char* ret = (char*)malloc((strlen(selectorName)+1)*sizeof(char)); char* ret = (char*)malloc((strlen(selectorName)+1)*sizeof(char));
...@@ -51,7 +56,7 @@ Centre de Math ...@@ -51,7 +56,7 @@ Centre de Math
%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
%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 GET_METHODS %start COPY_USER_FUNCTIONS COPY_GENERATION_FUNCTION GET_METHODS COPY_MAKEFILE_OPTION
// lexical analyser name and class definition // lexical analyser name and class definition
%name CEASEALexer { %name CEASEALexer {
...@@ -62,7 +67,7 @@ Centre de Math ...@@ -62,7 +67,7 @@ Centre de Math
bool bDoubleQuotes,bWithinDisplayFunction,bWithinInitialiser,bWithinMutator,bWithinXover; bool bDoubleQuotes,bWithinDisplayFunction,bWithinInitialiser,bWithinMutator,bWithinXover;
bool bWaitingForSemiColon,bFinishNB_GEN,bFinishMINIMISE,bFinishMINIMIZE,bGenerationFunction; bool bWaitingForSemiColon,bFinishNB_GEN,bFinishMINIMISE,bFinishMINIMIZE,bGenerationFunction;
bool bCatchNextSemiColon,bWaitingToClosePopulation, bMethodsInGenome, bFinalizationFunction; bool bCatchNextSemiColon,bWaitingToClosePopulation, bMethodsInGenome, bFinalizationFunction;
bool bWithinCUDA_Initializer; bool bWithinCUDA_Initializer, bWithinMAKEFILEOPTION;
CSymbol *pASymbol; CSymbol *pASymbol;
public: public:
...@@ -77,7 +82,7 @@ Centre de Math ...@@ -77,7 +82,7 @@ Centre de Math
bSymbolInserted=bDoubleQuotes=bWithinDisplayFunction=bWithinInitialiser=bWithinMutator=bWithinXover=0; bSymbolInserted=bDoubleQuotes=bWithinDisplayFunction=bWithinInitialiser=bWithinMutator=bWithinXover=0;
bWaitingForSemiColon=bFinishNB_GEN=bFinishMINIMISE=bFinishMINIMIZE=bGenerationFunction=0; bWaitingForSemiColon=bFinishNB_GEN=bFinishMINIMISE=bFinishMINIMIZE=bGenerationFunction=0;
bCatchNextSemiColon,bWaitingToClosePopulation=bMethodsInGenome=0; bCatchNextSemiColon,bWaitingToClosePopulation=bMethodsInGenome=0;
bWithinCUDA_Initializer=0; bWithinCUDA_Initializer=0, bWithinMAKEFILEOPTION;
} }
// macros // macros
...@@ -109,6 +114,7 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -109,6 +114,7 @@ exponent ([Ee][+-]?[0-9]+)
strcpy(sFileName, sRAW_PROJECT_NAME); strcpy(sFileName, sRAW_PROJECT_NAME);
switch (TARGET) { switch (TARGET) {
case DREAM : strcat(sFileName,".java"); break; case DREAM : strcat(sFileName,".java"); break;
case STD :
case CUDA : strcat(sFileName,".cpp"); break; case CUDA : strcat(sFileName,".cpp"); break;
default : strcat(sFileName,".cpp"); default : strcat(sFileName,".cpp");
} }
...@@ -337,6 +343,15 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -337,6 +343,15 @@ exponent ([Ee][+-]?[0-9]+)
yyin = fpGenomeFile; // switch to .ez file and analyser yyin = fpGenomeFile; // switch to .ez file and analyser
BEGIN COPY_DISPLAY; BEGIN COPY_DISPLAY;
} }
<TEMPLATE_ANALYSIS>"\\INSERT_MAKEFILE_OPTION" {
if( bVERBOSE ) printf("Inserting user LDFLAGS.\n");
yyreset();
yyin = fpGenomeFile;
BEGIN COPY_MAKEFILE_OPTION;
}
<TEMPLATE_ANALYSIS>"\\WRITE" { <TEMPLATE_ANALYSIS>"\\WRITE" {
CListItem<CSymbol*> *pSym; CListItem<CSymbol*> *pSym;
if (!bDisplayFunction){ if (!bDisplayFunction){
...@@ -402,7 +417,7 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -402,7 +417,7 @@ exponent ([Ee][+-]?[0-9]+)
<TEMPLATE_ANALYSIS>"\\INSERT_EO_INITIALISER" { <TEMPLATE_ANALYSIS>"\\INSERT_EO_INITIALISER" {
yyreset(); yyreset();
bWithinEO_Function=1; bWithinEO_Function=1;
if( TARGET==CUDA ) bWithinCUDA_Initializer = 1; if( TARGET==CUDA || TARGET==STD) bWithinCUDA_Initializer = 1;
yyin = fpGenomeFile; // switch to .ez file and analyser yyin = fpGenomeFile; // switch to .ez file and analyser
BEGIN COPY_EO_INITIALISER; // not implemented as a function ! BEGIN COPY_EO_INITIALISER; // not implemented as a function !
} }
...@@ -441,7 +456,12 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -441,7 +456,12 @@ exponent ([Ee][+-]?[0-9]+)
BEGIN PARAMETERS_ANALYSIS; BEGIN PARAMETERS_ANALYSIS;
} }
<TEMPLATE_ANALYSIS>"\\INSERT_GEN_FCT_CALL" { <TEMPLATE_ANALYSIS>"\\INSERT_GEN_FCT_CALL" {
if (bGenerationFunction) fprintf(fpOutputFile,"\n EASEAGenerationFunction(ga);\n"); if (bGenerationFunction) {
if( TARGET==CUDA || TARGET==STD ){
fprintf(fpOutputFile,"\n\tEASEAGenerationFunction(this);");
}
else fprintf(fpOutputFile,"\n EASEAGenerationFunction(ga);\n");
}
} }
<TEMPLATE_ANALYSIS>"\\INSERT_INIT_FCT_CALL" { <TEMPLATE_ANALYSIS>"\\INSERT_INIT_FCT_CALL" {
if (bInitFunction) fprintf(fpOutputFile,"\n EASEAInitFunction(argc, argv);\n"); if (bInitFunction) fprintf(fpOutputFile,"\n EASEAInitFunction(argc, argv);\n");
...@@ -457,11 +477,11 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -457,11 +477,11 @@ exponent ([Ee][+-]?[0-9]+)
} }
<TEMPLATE_ANALYSIS>"\\SELECTOR" { <TEMPLATE_ANALYSIS>"\\SELECTOR" {
if( TARGET==CUDA ){ if( TARGET==CUDA || TARGET==STD){
DEBUG_PRT("Selector is \"%s\" | Goal is %s",sSELECTOR,(nMINIMISE?"Minimize":"Maximize")); DEBUG_PRT("Selector is \"%s\" | Goal is %s",sSELECTOR,(nMINIMISE?"Minimize":"Maximize"));
char* selectorClass = selectorDetermination(nMINIMISE,sSELECTOR); char* selectorClass = selectorDetermination(nMINIMISE,sSELECTOR);
if( !selectorClass ){ if( !selectorClass ){
fprintf(stderr,"Error %d : selection operator %s doesn't exist in CUDA template\n",yylineno,sSELECTOR); fprintf(stderr,"Error %d : selection operator %s doesn't exist in CUDA/STD template\n",yylineno,sSELECTOR);
return -1; return -1;
} }
DEBUG_PRT("Created class is %s",selectorClass); DEBUG_PRT("Created class is %s",selectorClass);
...@@ -475,7 +495,7 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -475,7 +495,7 @@ exponent ([Ee][+-]?[0-9]+)
<TEMPLATE_ANALYSIS>"\\OFF_SIZE" {fprintf(fpOutputFile,"%d",nOFF_SIZE);} <TEMPLATE_ANALYSIS>"\\OFF_SIZE" {fprintf(fpOutputFile,"%d",nOFF_SIZE);}
<TEMPLATE_ANALYSIS>"\\ELITE_SIZE" { <TEMPLATE_ANALYSIS>"\\ELITE_SIZE" {
fprintf(fpOutputFile,"%d",nELITE); fprintf(fpOutputFile,"%d",nELITE);
DEBUG_PRT("elitism is %d, elite size is %d",bELITISM, nELITE); //DEBUG_PRT("elitism is %d, elite size is %d",bELITISM, nELITE);
} }
<TEMPLATE_ANALYSIS>"\\RED_PAR" {fprintf(fpOutputFile,"%s",sRED_PAR);} <TEMPLATE_ANALYSIS>"\\RED_PAR" {fprintf(fpOutputFile,"%s",sRED_PAR);}
...@@ -483,11 +503,11 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -483,11 +503,11 @@ exponent ([Ee][+-]?[0-9]+)
<TEMPLATE_ANALYSIS>"\\RED_OFF" {fprintf(fpOutputFile,"%s",sRED_OFF);} <TEMPLATE_ANALYSIS>"\\RED_OFF" {fprintf(fpOutputFile,"%s",sRED_OFF);}
<TEMPLATE_ANALYSIS>"\\RED_OFF_PRM" {fprintf(fpOutputFile,"%s",sRED_OFF_PRM);} <TEMPLATE_ANALYSIS>"\\RED_OFF_PRM" {fprintf(fpOutputFile,"%s",sRED_OFF_PRM);}
<TEMPLATE_ANALYSIS>"\\RED_FINAL" { <TEMPLATE_ANALYSIS>"\\RED_FINAL" {
if( TARGET==CUDA ){ if( TARGET==CUDA || TARGET==STD){
DEBUG_PRT("Replacement selector is \"%s\" | Goal is %s",sRED_FINAL,(nMINIMISE?"Minimize":"Maximize")); DEBUG_PRT("Replacement selector is \"%s\" | Goal is %s",sRED_FINAL,(nMINIMISE?"Minimize":"Maximize"));
char* selectorClass = selectorDetermination(nMINIMISE,sRED_FINAL); char* selectorClass = selectorDetermination(nMINIMISE,sRED_FINAL);
if( !selectorClass ){ if( !selectorClass ){
fprintf(stderr,"Error %d : replacement operator %s doesn't exist in CUDA template\n",yylineno,sRED_FINAL); fprintf(stderr,"Error %d : replacement operator %s doesn't exist in CUDA/TPL template\n",yylineno,sRED_FINAL);
return -1; return -1;
} }
DEBUG_PRT("Created class is %s",selectorClass); DEBUG_PRT("Created class is %s",selectorClass);
...@@ -524,6 +544,8 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -524,6 +544,8 @@ exponent ([Ee][+-]?[0-9]+)
else fprintf(fpOutputFile," ga.elitist(gaFalse);\n"); else fprintf(fpOutputFile," ga.elitist(gaFalse);\n");
break; break;
case EO : fprintf(fpOutputFile,"%d",bELITISM); case EO : fprintf(fpOutputFile,"%d",bELITISM);
break;
case STD:
case CUDA: fprintf(fpOutputFile,"%d",bELITISM); case CUDA: fprintf(fpOutputFile,"%d",bELITISM);
} } } }
<TEMPLATE_ANALYSIS>"\\IMMIG_SEL" {fprintf(fpOutputFile,"%s",sIMMIG_SEL);} <TEMPLATE_ANALYSIS>"\\IMMIG_SEL" {fprintf(fpOutputFile,"%s",sIMMIG_SEL);}
...@@ -567,7 +589,10 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -567,7 +589,10 @@ exponent ([Ee][+-]?[0-9]+)
char sFileName[1000]; char sFileName[1000];
fclose(fpOutputFile); fclose(fpOutputFile);
strcpy(sFileName, sRAW_PROJECT_NAME); strcpy(sFileName, sRAW_PROJECT_NAME);
strcat(sFileName,"Individual.cu"); if( TARGET==CUDA )
strcat(sFileName,"Individual.cu");
else if( TARGET==STD )
strcat(sFileName,"Individual.cpp");
fpOutputFile=fopen(sFileName,"w"); fpOutputFile=fopen(sFileName,"w");
if (bVERBOSE) printf("Creating %s...\n",sFileName); if (bVERBOSE) printf("Creating %s...\n",sFileName);
} }
...@@ -808,7 +833,7 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -808,7 +833,7 @@ exponent ([Ee][+-]?[0-9]+)
printf ("%s @%s.prm\n\n",sPROJECT_NAME,sPROJECT_NAME); printf ("%s @%s.prm\n\n",sPROJECT_NAME,sPROJECT_NAME);
} } } }
printf ("Have a nice compile time.\n"); printf ("Have a nice compile time.\n");
if (TARGET==EO || TARGET==CUDA) fprintf(fpOutputFile,"\n# That's all folks ! \n"); if (TARGET==EO || TARGET==CUDA || TARGET==STD) fprintf(fpOutputFile,"\n# That's all folks ! \n");
else fprintf(fpOutputFile,"\n// That's all folks ! \n"); else fprintf(fpOutputFile,"\n// That's all folks ! \n");
fflush(fpOutputFile); fflush(fpOutputFile);
fclose(fpOutputFile); fclose(fpOutputFile);
...@@ -890,8 +915,9 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -890,8 +915,9 @@ exponent ([Ee][+-]?[0-9]+)
case EO: case EO:
fprintf (fpOutputFile,"// Finalization function\n\nvoid EASEAFinalFunction(eoPop<Indi>& population){"); fprintf (fpOutputFile,"// Finalization function\n\nvoid EASEAFinalFunction(eoPop<Indi>& population){");
break; break;
case STD:
case CUDA: case CUDA:
fprintf (fpOutputFile,"// Finalization function\n\nvoid EASEAFinalization(Population* population){"); fprintf (fpOutputFile,"// Finalization function\nvoid EASEAFinalization(Population* population){");
break; break;
default: default:
fprintf (stderr," Warning this template doesn't support finalization function "); fprintf (stderr," Warning this template doesn't support finalization function ");
...@@ -914,9 +940,14 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -914,9 +940,14 @@ exponent ([Ee][+-]?[0-9]+)
<COPY_GENERATION_FUNCTION>"\\At"[ \t\n]+"each"[ \t\n]+"new"[ \t\n]+"generation"[ \t\n]*":" { <COPY_GENERATION_FUNCTION>"\\At"[ \t\n]+"each"[ \t\n]+"new"[ \t\n]+"generation"[ \t\n]*":" {
if( TARGET==GALIB){
fprintf (fpOutputFile,"// Function called at each new generation\n\nvoid EASEAGenerationFunction(GAGeneticAlgorithm & g){\n"); fprintf (fpOutputFile,"// Function called at each new generation\n\nvoid EASEAGenerationFunction(GAGeneticAlgorithm & g){\n");
fprintf(fpOutputFile," const GAPopulation *pPopulation;\n",sPROJECT_NAME); fprintf(fpOutputFile," const GAPopulation *pPopulation;\n",sPROJECT_NAME);
fprintf(fpOutputFile," pPopulation=&(g.population()); // to circumvent a bug in GALib\n",sPROJECT_NAME); fprintf(fpOutputFile," pPopulation=&(g.population()); // to circumvent a bug in GALib\n",sPROJECT_NAME);
}
else if(TARGET==CUDA || TARGET==STD){
fprintf (fpOutputFile,"// Function called at each new generation\nvoid EASEAGenerationFunction(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n");
}
bFunction=1; bGenerationFunction=1; bFunction=1; bGenerationFunction=1;
BEGIN COPY_USER_GENERATION; BEGIN COPY_USER_GENERATION;
} }
...@@ -989,10 +1020,10 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -989,10 +1020,10 @@ exponent ([Ee][+-]?[0-9]+)
} // local random name } // local random name
<COPY>"random" { <COPY>"random" {
if (TARGET==DREAM) fprintf(fpOutputFile,"%s.random",sPROJECT_NAME); if (TARGET==DREAM) fprintf(fpOutputFile,"%s.random",sPROJECT_NAME);
else if( TARGET==CUDA ) fprintf(fpOutputFile,"globalRandomGenerator->random"); else if( TARGET==CUDA || TARGET==STD) fprintf(fpOutputFile,"globalRandomGenerator->random");
else fprintf(fpOutputFile,"random");} else fprintf(fpOutputFile,"random");}
<COPY>"Genome" { <COPY>"Genome" {
if (bWithinEO_Function && TARGET!=CUDA) fprintf(fpOutputFile,"_genotype"); if (bWithinEO_Function && TARGET!=CUDA && TARGET!=STD) fprintf(fpOutputFile,"_genotype");
else if(bWithinEO_Function && bWithinCUDA_Initializer )fprintf(fpOutputFile,"(*this)"); else if(bWithinEO_Function && bWithinCUDA_Initializer )fprintf(fpOutputFile,"(*this)");
else fprintf(fpOutputFile,"Genome");} // local genome name else fprintf(fpOutputFile,"Genome");} // local genome name
<COPY>"identicalGenome" {fprintf(fpOutputFile,"genome._evaluated");} // local name <COPY>"identicalGenome" {fprintf(fpOutputFile,"genome._evaluated");} // local name
...@@ -1005,22 +1036,24 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1005,22 +1036,24 @@ exponent ([Ee][+-]?[0-9]+)
<COPY>"GenomeClass::" {fprintf(fpOutputFile,"template <class fitT> %sGenome<fitT>::",sPROJECT_NAME);} <COPY>"GenomeClass::" {fprintf(fpOutputFile,"template <class fitT> %sGenome<fitT>::",sPROJECT_NAME);}
<COPY>"GenomeClass" { <COPY>"GenomeClass" {
if (TARGET==EO) fprintf(fpOutputFile,"Indi"); if (TARGET==EO) fprintf(fpOutputFile,"Indi");
else if( TARGET==CUDA ) fprintf(fpOutputFile,"Individual"); else if( TARGET==CUDA || TARGET==STD) fprintf(fpOutputFile,"Individual");
else fprintf(fpOutputFile,"%sGenome",sPROJECT_NAME);} // local name else fprintf(fpOutputFile,"%sGenome",sPROJECT_NAME);} // local name
<COPY>"population" { <COPY>"population" {
if( TARGET == CUDA && bFinalizationFunction ){ if( (TARGET == CUDA || TARGET==STD) && bFinalizationFunction ){
fprintf(fpOutputFile,"(*population)"); fprintf(fpOutputFile,"(*population)");
} }
else fprintf(fpOutputFile,"population"); else fprintf(fpOutputFile,"population");
} }
<COPY>"\\end" { <COPY>"\\end" {
if (bFunction==1) { if (bFunction==1 && bWithinCUDA_Initializer==0) {
fprintf (fpOutputFile,"}\n"); fprintf (fpOutputFile,"}\n");
bFunction=0; bFunction=0;
bWithinCUDA_Initializer=0;
} }
bWithinEO_Function=0; bWithinEO_Function=0;
rewind(fpGenomeFile); rewind(fpGenomeFile);
yyin = fpTemplateFile; BEGIN TEMPLATE_ANALYSIS;} // Back to the template file yyin = fpTemplateFile;
BEGIN TEMPLATE_ANALYSIS;} // Back to the template file
<COPY>.|\n {putc(yytext[0],fpOutputFile);} <COPY>.|\n {putc(yytext[0],fpOutputFile);}
// Looking for an identifier // Looking for an identifier
...@@ -1115,13 +1148,54 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1115,13 +1148,54 @@ exponent ([Ee][+-]?[0-9]+)
} }
<COPY_DISPLAY>.|\n {} <COPY_DISPLAY>.|\n {}
<COPY_MAKEFILE_OPTION>"\\User"[ \t\n]+[Mm]"akefile"[ \t\n]+"options"[ \t\n]*":" {
DEBUG_PRT("LDFLAGS is beg: %s",yytext);
bWithinMAKEFILEOPTION=1;
return MAKEFILE_OPTION;
}
//**************************************** //****************************************
// Looks for standard and user functions in the .ez file // Looks for Makefile options (like
// LDFLAGS+= or CPPFLAGS...)
//**************************************** //****************************************
<COPY_MAKEFILE_OPTION>"\\end" {
if( bWithinMAKEFILEOPTION ){
DEBUG_PRT("end of makefile options");
yyin = fpTemplateFile;
bWithinMAKEFILEOPTION = 0;
BEGIN TEMPLATE_ANALYSIS;
return END_OF_FUNCTION;
}
}
<COPY_MAKEFILE_OPTION>.|\n {
if( bWithinMAKEFILEOPTION ){
putc(yytext[0],fpOutputFile);
}
}
<COPY_MAKEFILE_OPTION>\n {
if( bWithinMAKEFILEOPTION );
}
<COPY_MAKEFILE_OPTION><<EOF>> {
DEBUG_PRT("No makefile options defined.");
yyin = fpTemplateFile;
bWithinMAKEFILEOPTION = 0;
BEGIN TEMPLATE_ANALYSIS;
return MAKEFILE_OPTION;
}
//****************************************
// Looks for standard and user functions in the .ez file
//****************************************
<COPY_INITIALISER>"\\GenomeClass::initiali"[sz]"er"[ \t\n]*":" { <COPY_INITIALISER>"\\GenomeClass::initiali"[sz]"er"[ \t\n]*":" {
bWithinInitialiser=1; bWithinInitialiser=1;
BEGIN COPY_USER_FUNCTION; BEGIN COPY_USER_FUNCTION;
BEGIN TEMPLATE_ANALYSIS;
return USER_CTOR; return USER_CTOR;
} }
<COPY_INITIALISER>.|\n {} <COPY_INITIALISER>.|\n {}
...@@ -1159,17 +1233,28 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1159,17 +1233,28 @@ exponent ([Ee][+-]?[0-9]+)
<COPY_USER_GENERATION>"pPopulation"[ \t\n]*"[" {bWaitingToClosePopulation=true; <COPY_USER_GENERATION>"pPopulation"[ \t\n]*"[" {bWaitingToClosePopulation=true;
switch (TARGET) { switch (TARGET) {
case EO: fprintf(fpOutputFile,"pPopulation ["); break; case EO: fprintf(fpOutputFile,"pPopulation ["); break;
case GALIB: fprintf(fpOutputFile,"((%sGenome *)&(pPopulation->individual(",sPROJECT_NAME); case GALIB:
fprintf(fpOutputFile,"((%sGenome *)&(pPopulation->individual(",sPROJECT_NAME);
break;
case CUDA:
case STD:
fprintf(fpOutputFile,"(*evolutionaryAlgorithm->getPopulation())");
} }
} }
<COPY_USER_GENERATION>"]" {if (!bWaitingToClosePopulation) fprintf(fpOutputFile,"]"); <COPY_USER_GENERATION>"]" {if (!bWaitingToClosePopulation) fprintf(fpOutputFile,"]");
else {fprintf(fpOutputFile,")))"); bWaitingToClosePopulation=false;}} else {fprintf(fpOutputFile,")))"); bWaitingToClosePopulation=false;}}
<COPY_USER_GENERATION>"currentGeneration" | <COPY_USER_GENERATION>"currentGeneration" |
<COPY_USER_GENERATION>"currentGeneration"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"currentGeneration"); <COPY_USER_GENERATION>"currentGeneration"/[ \t\n]*"==" {
if (bDoubleQuotes) fprintf(fpOutputFile,"currentGeneration");
else switch (TARGET) { else switch (TARGET) {
case GALIB : fprintf(fpOutputFile,"g.generation()"); break; case GALIB : fprintf(fpOutputFile,"g.generation()"); break;
case EO : fprintf(fpOutputFile,"generationCounter.value()"); case EO :
fprintf(fpOutputFile,"generationCounter.value()"); break;
case CUDA:
case STD:
fprintf(fpOutputFile,"(evolutionaryAlgorithm->getCurrentGeneration())");
break;
}} // local genome name }} // local genome name
<COPY_USER_GENERATION>"NB_GEN" | <COPY_USER_GENERATION>"NB_GEN" |
<COPY_USER_GENERATION>"NB_GEN"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"NB_GEN"); <COPY_USER_GENERATION>"NB_GEN"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"NB_GEN");
...@@ -1295,7 +1380,10 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1295,7 +1380,10 @@ exponent ([Ee][+-]?[0-9]+)
else fprintf(fpOutputFile,"));"); else fprintf(fpOutputFile,"));");
} }
else fprintf(fpOutputFile,";");} else fprintf(fpOutputFile,";");}
<COPY_USER_GENERATION>"evoluationaryAlgorithm." |
<COPY_USER_GENERATION>"ea." {
fprintf(fpOutputFile,"(*evoluationaryAlgorithm).");
}
<COPY_USER_GENERATION>.|\n {putc(yytext[0],fpOutputFile);} <COPY_USER_GENERATION>.|\n {putc(yytext[0],fpOutputFile);}
//**************************************** //****************************************
...@@ -1315,7 +1403,7 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1315,7 +1403,7 @@ exponent ([Ee][+-]?[0-9]+)
if (bWithinDisplayFunction) fprintf(fpOutputFile,"(*this)"); if (bWithinDisplayFunction) fprintf(fpOutputFile,"(*this)");
else if ((TARGET==EO)&&(bWithinInitialiser)) fprintf(fpOutputFile, "(*genome)"); else if ((TARGET==EO)&&(bWithinInitialiser)) fprintf(fpOutputFile, "(*genome)");
else if ((TARGET==CUDA) && ((bWithinEvaluator) || bWithinMutator)) fprintf(fpOutputFile, "(*this)"); else if ((TARGET==CUDA || TARGET==STD) && ((bWithinEvaluator) || bWithinMutator)) fprintf(fpOutputFile, "(*this)");
else if ((TARGET==EO)&&(bWithinMutator)) fprintf(fpOutputFile, "_genotype"); else if ((TARGET==EO)&&(bWithinMutator)) fprintf(fpOutputFile, "_genotype");
else fprintf(fpOutputFile,"genome");} // local genome name else fprintf(fpOutputFile,"genome");} // local genome name
...@@ -1371,7 +1459,7 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1371,7 +1459,7 @@ exponent ([Ee][+-]?[0-9]+)
if (TARGET==DREAM) fprintf(fpOutputFile,"Math.random()<");} // local random name if (TARGET==DREAM) fprintf(fpOutputFile,"Math.random()<");} // local random name
<COPY_USER_FUNCTION>"random" { <COPY_USER_FUNCTION>"random" {
if (TARGET==DREAM) fprintf(fpOutputFile,"%s.random",sPROJECT_NAME); if (TARGET==DREAM) fprintf(fpOutputFile,"%s.random",sPROJECT_NAME);
else if( TARGET==CUDA ) fprintf(fpOutputFile,"rg->random"); else if( TARGET==CUDA || TARGET==STD) fprintf(fpOutputFile,"rg->random");
else fprintf(fpOutputFile,"random");} else fprintf(fpOutputFile,"random");}
<COPY_USER_FUNCTION>"child1" {if ((bWithinXover)&&(TARGET==GALIB)) fprintf(fpOutputFile, "(*pBro)"); <COPY_USER_FUNCTION>"child1" {if ((bWithinXover)&&(TARGET==GALIB)) fprintf(fpOutputFile, "(*pBro)");
else fprintf(fpOutputFile,"child1"); else fprintf(fpOutputFile,"child1");
...@@ -1390,7 +1478,7 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1390,7 +1478,7 @@ exponent ([Ee][+-]?[0-9]+)
if (TARGET==GALIB) fprintf(fpOutputFile,"EZ_EVAL+=(double)(clock()-EZ_t1);\n return (float)"); if (TARGET==GALIB) fprintf(fpOutputFile,"EZ_EVAL+=(double)(clock()-EZ_t1);\n return (float)");
else if (TARGET==EO) {fprintf(fpOutputFile,"genome.fitness(");bCatchNextSemiColon=true;}// changes function type// changes function type else if (TARGET==EO) {fprintf(fpOutputFile,"genome.fitness(");bCatchNextSemiColon=true;}// changes function type// changes function type
else if (TARGET==DREAM) {fprintf(fpOutputFile,"infoHabitant.setFitness(new Double(");bCatchNextSemiColon=true;}// changes function type else if (TARGET==DREAM) {fprintf(fpOutputFile,"infoHabitant.setFitness(new Double(");bCatchNextSemiColon=true;}// changes function type
else if( TARGET==CUDA ) { else if( TARGET==CUDA || TARGET==STD) {
fprintf(fpOutputFile,"return fitness = "); fprintf(fpOutputFile,"return fitness = ");
bCatchNextSemiColon=false; bCatchNextSemiColon=false;
} }
...@@ -1548,15 +1636,18 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable) ...@@ -1548,15 +1636,18 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable)
if (bVERBOSE) printf("\n"); if (bVERBOSE) printf("\n");
if (TARGET==0) { if (TARGET==0) {
printf("\nPlease select a target library (DREAM, EO, GALib or CUDA): "); /* printf("\nPlease select a target library (DREAM, EO, GALib STD or CUDA): "); */
scanf("%s",sTemp); /* scanf("%s",sTemp); */
if (!mystricmp(sTemp,"eo")) TARGET=EO; /* if (!mystricmp(sTemp,"eo")) TARGET=EO; */
else if (!mystricmp(sTemp,"galib")) TARGET=GALIB; /* else if (!mystricmp(sTemp,"galib")) TARGET=GALIB; */
else if (!mystricmp(sTemp,"dream")) TARGET=DREAM; /* else if (!mystricmp(sTemp,"dream")) TARGET=DREAM; */
else if (!mystricmp(sTemp,"cuda")) TARGET=CUDA; /* else if (!mystricmp(sTemp,"cuda")) TARGET=CUDA; */
else return 0; /* else if (!mystricmp(sTemp,"std")) TARGET=STD; */
/* else return 0; */
TARGET = STD;
} }
char* sEZ_PATH = "./tpl/";
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
//strcpy(sTemp,"e:\\lutton\\easea\\debug");pour tester sous windows //strcpy(sTemp,"e:\\lutton\\easea\\debug");pour tester sous windows
if ((sEZ_PATH==NULL)||(sEZ_PATH[0]==0)) { if ((sEZ_PATH==NULL)||(sEZ_PATH[0]==0)) {
...@@ -1564,14 +1655,14 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable) ...@@ -1564,14 +1655,14 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable)
printf("\n\nHmmm, it looks like you are running EASEA without GUIDE for the first time.\n"); printf("\n\nHmmm, it looks like you are running EASEA without GUIDE for the first time.\n");
printf("Please, add the path of the installation directory to the PATH variable and\n"); printf("Please, add the path of the installation directory to the PATH variable and\n");
printf("into the \"EZ_PATH\" environment variable, so that EASEA knows where to look for\n"); printf("into the \"EZ_PATH\" environment variable, so that EASEA knows where to look for\n");
printf("its template files.\n"); printf("its template files.\n");
exit(1); exit(1);
} }
strcpy(sEZ_PATH,getenv("EZ_PATH")); strcpy(sEZ_PATH,getenv("EZ_PATH"));
} }
switch (OPERATING_SYSTEM) { switch (OPERATING_SYSTEM) {
case UNIX : if (sEZ_PATH[strlen(sEZ_PATH)-1] != '/') strcat (sEZ_PATH,"/"); break; case UNIX : if (sEZ_PATH[strlen(sEZ_PATH)-1] != '/') strcat (sEZ_PATH,"./"); break;
case WINDOWS : if (sEZ_PATH[strlen(sEZ_PATH)-1] != '\\') strcat (sEZ_PATH,"\\"); break; case WINDOWS : if (sEZ_PATH[strlen(sEZ_PATH)-1] != '\\') strcat (sEZ_PATH,"\\"); break;
case UNKNOWN_OS : fprintf(fpOutputFile,"UNKNOWN_OS"); break; case UNKNOWN_OS : fprintf(fpOutputFile,"UNKNOWN_OS"); break;
} }
...@@ -1606,6 +1697,13 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable) ...@@ -1606,6 +1697,13 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable)
exit(1); exit(1);
} } } }
if (TARGET==STD){
strcat(sTemp,"STD.tpl");
if (!(yyin = fpTemplateFile = fopen(sTemp, "r"))){
fprintf(stderr,"\n*** Could not open %s.\n",sTemp);
fprintf(stderr,"*** Please modify the EZ_PATH environment variable.\n");
exit(1);
} }
if (TARGET==EO){ if (TARGET==EO){
if ((sEO_DIR==NULL)||(sEO_DIR[0]==0)) { if ((sEO_DIR==NULL)||(sEO_DIR[0]==0)) {
......
...@@ -92,6 +92,7 @@ class CSymbol; ...@@ -92,6 +92,7 @@ class CSymbol;
%token USER_XOVER %token USER_XOVER
%token USER_MUTATOR %token USER_MUTATOR
%token USER_EVALUATOR %token USER_EVALUATOR
%token MAKEFILE_OPTION
%token END_OF_FUNCTION %token END_OF_FUNCTION
//%token DELETE //%token DELETE
%token <szString> END_METHODS %token <szString> END_METHODS
...@@ -467,7 +468,7 @@ StandardFunctionAnalysis ...@@ -467,7 +468,7 @@ StandardFunctionAnalysis
} } } }
END_OF_FUNCTION { END_OF_FUNCTION {
if (TARGET==DREAM) fprintf(fpOutputFile," }\n"); if (TARGET==DREAM) fprintf(fpOutputFile," }\n");
if( TARGET!=CUDA ) fprintf(fpOutputFile,"}"); if( TARGET!=CUDA && TARGET!=STD) fprintf(fpOutputFile,"}");
} }
| USER_EVALUATOR { | USER_EVALUATOR {
if (bVERBOSE) printf("Inserting user genome evaluator (taken from .ez file).\n"); if (bVERBOSE) printf("Inserting user genome evaluator (taken from .ez file).\n");
...@@ -485,8 +486,12 @@ StandardFunctionAnalysis ...@@ -485,8 +486,12 @@ StandardFunctionAnalysis
fprintf(fpOutputFile," EZ_NB_EVALUATIONS++;\n",sPROJECT_NAME); fprintf(fpOutputFile," EZ_NB_EVALUATIONS++;\n",sPROJECT_NAME);
} } } }
END_OF_FUNCTION { END_OF_FUNCTION {
if (TARGET!=EO && TARGET!=CUDA ) fprintf(fpOutputFile,"}\n"); if (TARGET!=EO && TARGET!=CUDA && TARGET!=STD) fprintf(fpOutputFile,"}\n");
} }
| MAKEFILE_OPTION END_OF_FUNCTION {
DEBUG_PRT("User makefile options have been reduced");
}
| MAKEFILE_OPTION {}
; ;
RunParameters RunParameters
...@@ -547,18 +552,28 @@ Parameter ...@@ -547,18 +552,28 @@ Parameter
exit(1); exit(1);
} }
break; break;
case EO : if (!mystricmp(sSELECTOR,"RouletteWheel")){ case CUDA:
if (nMINIMISE==1) { case STD:
fprintf(stderr,"\n%s - Error line %d: The RouletteWheel selection scheme cannot be\n selected when \"minimising the fitness\" is the evaluator goal.\n",sEZ_FILE_NAME,EASEALexer.yylineno); case EO : if (!mystricmp(sSELECTOR,"RouletteWheel")){
exit(1); if (nMINIMISE==1) {
} fprintf(stderr,"\n%s - Error line %d: The RouletteWheel selection scheme cannot be\n selected when \"minimising the fitness\" is the evaluator goal.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
else sprintf(sSELECTOR,"Roulette"); exit(1);
} }
else if (!mystricmp(sSELECTOR,"Tournament")) sprintf(sSELECTOR,"DetTour"); else sprintf(sSELECTOR,"Roulette");
else if (!mystricmp(sSELECTOR,"StochTrn")) sprintf(sSELECTOR,"StochTour"); }
else if (!mystricmp(sSELECTOR,"Random")) sprintf(sSELECTOR,"Random"); else if (!mystricmp(sSELECTOR,"Tournament")) sprintf(sSELECTOR,"DetTour");
else if (!mystricmp(sSELECTOR,"Ranking")) sprintf(sSELECTOR,"Ranking"); else if (!mystricmp(sSELECTOR,"StochTrn")) sprintf(sSELECTOR,"StochTour");
else if (!mystricmp(sSELECTOR,"Sequential")) sprintf(sSELECTOR,"Sequential"); else if (!mystricmp(sSELECTOR,"Random")){
sprintf(sSELECTOR,"Random");
if( TARGET==CUDA || TARGET==STD )
sprintf(sSELECT_PRM,"(0)");
}
else if (!mystricmp(sSELECTOR,"Ranking")) sprintf(sSELECTOR,"Ranking");
else if (!mystricmp(sSELECTOR,"Sequential")){
sprintf(sSELECTOR,"Sequential");
if( TARGET==CUDA || TARGET==STD) sprintf(sSELECT_PRM,"(0)");
}
else { else {
fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist in EO.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sSELECTOR); fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist in EO.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sSELECTOR);
exit(1); exit(1);
...@@ -606,6 +621,7 @@ Parameter ...@@ -606,6 +621,7 @@ Parameter
} }
break; break;
case CUDA: case CUDA:
case STD:
case EO : if (!mystricmp(sSELECTOR,"Tournament")||!mystricmp(sSELECTOR,"StochTrn")) { case EO : if (!mystricmp(sSELECTOR,"Tournament")||!mystricmp(sSELECTOR,"StochTrn")) {
if ($3>=2) {sprintf(sSELECTOR,"DetTour");sprintf(sSELECT_PRM,"(%d)",(int) $3);} if ($3>=2) {sprintf(sSELECTOR,"DetTour");sprintf(sSELECT_PRM,"(%d)",(int) $3);}
else if (($3>.5)&&($3<=1.0)) {sprintf(sSELECTOR,"StochTour");sprintf(sSELECT_PRM,"(%f)",(float) $3);} else if (($3>.5)&&($3<=1.0)) {sprintf(sSELECTOR,"StochTour");sprintf(sSELECT_PRM,"(%f)",(float) $3);}
...@@ -630,7 +646,12 @@ Parameter ...@@ -630,7 +646,12 @@ Parameter
} }
else if (!mystricmp(sSELECTOR,"Sequential")) { else if (!mystricmp(sSELECTOR,"Sequential")) {
sprintf(sSELECTOR,"Sequential"); sprintf(sSELECTOR,"Sequential");
if ($3==0) sprintf(sSELECT_PRM,"(unordered)"); if ($3==0)
if( TARGET==CUDA || TARGET==STD )
sprintf(sSELECT_PRM,"(0)");
else
sprintf(sSELECT_PRM,"(unordered)");
else if ($3==1) sprintf(sSELECT_PRM,"(ordered)"); else if ($3==1) sprintf(sSELECT_PRM,"(ordered)");
else { else {
fprintf(stderr,"\n%s - Warning line %d: The parameter of Sequential must be either 0 (unordered) or 1 (ordered).\nThe parameter will default to 1.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++; fprintf(stderr,"\n%s - Warning line %d: The parameter of Sequential must be either 0 (unordered) or 1 (ordered).\nThe parameter will default to 1.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
...@@ -708,6 +729,7 @@ Parameter ...@@ -708,6 +729,7 @@ Parameter
} }
break; break;
case CUDA : case CUDA :
case STD:
case EO : if (!mystricmp(sRED_PAR,"Tournament")||!mystricmp(sRED_PAR,"StochTrn")) { case EO : if (!mystricmp(sRED_PAR,"Tournament")||!mystricmp(sRED_PAR,"StochTrn")) {
if ($3>=2) {sprintf(sRED_PAR,"DetTour");sprintf(sRED_PAR_PRM,"(%d)",(int) $3);}