Commit 97534812 authored by maitre's avatar maitre

At beginning/end of each generation function ok

parent 607e733f
...@@ -60,7 +60,7 @@ Centre de Math ...@@ -60,7 +60,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 COPY_MAKEFILE_OPTION COPY_BOUND_CHECKING_FUNCTION %start COPY_USER_FUNCTIONS COPY_GENERATION_FUNCTION GET_METHODS COPY_MAKEFILE_OPTION COPY_BOUND_CHECKING_FUNCTION COPY_BEG_GENERATION_FUNCTION COPY_END_GENERATION_FUNCTION
// lexical analyser name and class definition // lexical analyser name and class definition
%name CEASEALexer { %name CEASEALexer {
...@@ -72,7 +72,7 @@ Centre de Math ...@@ -72,7 +72,7 @@ Centre de Math
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, bWithinMAKEFILEOPTION, bWithinCUDA_Evaluator, bBoundCheckingFunction; bool bWithinCUDA_Initializer, bWithinMAKEFILEOPTION, bWithinCUDA_Evaluator, bBoundCheckingFunction;
bool bIsParentReduce, bIsOffspringReduce, bEndGeneration, bBeginGeneration; bool bIsParentReduce, bIsOffspringReduce, bEndGeneration, bBeginGeneration, bEndGenerationFunction, bBeginGenerationFunction;
CSymbol *pASymbol; CSymbol *pASymbol;
public: public:
...@@ -89,7 +89,7 @@ Centre de Math ...@@ -89,7 +89,7 @@ Centre de Math
bCatchNextSemiColon,bWaitingToClosePopulation=bMethodsInGenome=0; bCatchNextSemiColon,bWaitingToClosePopulation=bMethodsInGenome=0;
bBoundCheckingFunction = bWithinCUDA_Initializer=bWithinMAKEFILEOPTION =bWithinCUDA_Evaluator=0; bBoundCheckingFunction = bWithinCUDA_Initializer=bWithinMAKEFILEOPTION =bWithinCUDA_Evaluator=0;
bIsParentReduce = bIsOffspringReduce = false; bIsParentReduce = bIsOffspringReduce = false;
bEndGeneration = bBeginGeneration = false; bEndGeneration = bBeginGeneration = bEndGenerationFunction = bBeginGenerationFunction = false;
} }
// macros // macros
...@@ -159,20 +159,24 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -159,20 +159,24 @@ exponent ([Ee][+-]?[0-9]+)
<TEMPLATE_ANALYSIS>"\\INSERT_BEGIN_GENERATION_FUNCTION" { <TEMPLATE_ANALYSIS>"\\INSERT_BEGIN_GENERATION_FUNCTION" {
DEBUG_PRT("insert beg");
if (bVERBOSE) printf ("Inserting at the begining of each generation function.\n"); if (bVERBOSE) printf ("Inserting at the begining of each generation function.\n");
yyreset(); yyreset();
yyin = fpGenomeFile; yyin = fpGenomeFile;
BEGIN COPY_GENERATION_FUNCTION; bBeginGeneration = true;
bEndGeneration = false;
BEGIN COPY_BEG_GENERATION_FUNCTION;
} }
<TEMPLATE_ANALYSIS>"\\INSERT_END_GENERATION_FUNCTION" { <TEMPLATE_ANALYSIS>"\\INSERT_END_GENERATION_FUNCTION" {
DEBUG_PRT("insert end");
if (bVERBOSE) printf ("Inserting at the end of each generation function.\n"); if (bVERBOSE) printf ("Inserting at the end of each generation function.\n");
yyreset(); yyreset();
yyin = fpGenomeFile; yyin = fpGenomeFile;
bEndGeneration = true; bEndGeneration = true;
bBeginGeneration = false; bBeginGeneration = false;
BEGIN COPY_GENERATION_FUNCTION; BEGIN COPY_END_GENERATION_FUNCTION;
} }
...@@ -589,9 +593,9 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -589,9 +593,9 @@ exponent ([Ee][+-]?[0-9]+)
BEGIN PARAMETERS_ANALYSIS; BEGIN PARAMETERS_ANALYSIS;
} }
<TEMPLATE_ANALYSIS>"\\INSERT_GEN_FCT_CALL" { <TEMPLATE_ANALYSIS>"\\INSERT_GEN_FCT_CALL" {
DEBUG_PRT("Generational function call %d",bGenerationFunction);
if (bGenerationFunction) { if (bGenerationFunction) {
if( bVERBOSE ) fprintf(stdout,"Inserting generation function call\n"); if( bVERBOSE ) fprintf(stdout,"Inserting generation function call\n");
if( TARGET==CUDA || TARGET==STD ){ if( TARGET==CUDA || TARGET==STD ){
fprintf(fpOutputFile,"\n\tEASEAGenerationFunction(this);"); fprintf(fpOutputFile,"\n\tEASEAGenerationFunction(this);");
} }
...@@ -599,6 +603,25 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -599,6 +603,25 @@ exponent ([Ee][+-]?[0-9]+)
} }
} }
<TEMPLATE_ANALYSIS>"\\INSERT_END_GEN_FCT_CALL" {
if( bEndGenerationFunction ) {
if( bVERBOSE ) fprintf(stdout,"Inserting end generation function call\n");
if( TARGET==CUDA || TARGET==STD ){
fprintf(fpOutputFile,"\n\tEASEAEndGenerationFunction(this);");
}
}
}
<TEMPLATE_ANALYSIS>"\\INSERT_BEGINNING_GEN_FCT_CALL" {
if( bBeginGenerationFunction ) {
if( bVERBOSE ) fprintf(stdout,"Inserting beginning generation function call\n");
if( TARGET==CUDA || TARGET==STD ){
fprintf(fpOutputFile,"\n\tEASEABeginningGenerationFunction(this);");
}
}
}
<TEMPLATE_ANALYSIS>"\\INSERT_BOUND_CHECKING_FCT_CALL" { <TEMPLATE_ANALYSIS>"\\INSERT_BOUND_CHECKING_FCT_CALL" {
if (bBoundCheckingFunction) { if (bBoundCheckingFunction) {
if( TARGET==CUDA || TARGET==STD ){ if( TARGET==CUDA || TARGET==STD ){
...@@ -1138,35 +1161,86 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1138,35 +1161,86 @@ exponent ([Ee][+-]?[0-9]+)
<COPY_FINALIZATION_FUNCTION>.|\n {} <COPY_FINALIZATION_FUNCTION>.|\n {}
<COPY_GENERATION_FUNCTION>"\\At"[ \t\n]+"the"[ \t\n]+"end"[ \t\n]+"of"[ \t\n]+"each"[ \t\n]+"generation"[ \t\n]+"function"[ \t\n]*":" {
if( (TARGET==CUDA || TARGET==STD)&& bEndGeneration ){
<COPY_END_GENERATION_FUNCTION>"\\At"[ \t\n]+"the"[ \t\n]+"end"[ \t\n]+"of"[ \t\n]+"each"[ \t\n]+"generation"[ \t\n]+"function"[ \t\n]*":" {
DEBUG_PRT("at each end");
if( (TARGET==CUDA || TARGET==STD) ){
fprintf (fpOutputFile,"// Function called at each new generation\nvoid EASEAEndGenerationFunction(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n"); fprintf (fpOutputFile,"// Function called at each new generation\nvoid EASEAEndGenerationFunction(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n");
bFunction=1; bGenerationFunction=1; bFunction=1;
bEndGeneration = 0; bEndGenerationFunction = 1;
BEGIN COPY_USER_GENERATION; BEGIN COPY_USER_GENERATION;
} }
} }
<COPY_END_GENERATION_FUNCTION><<EOF>> {
bEndGenerationFunction=0; // No Generation function was found in the .ez file
printf("*** No end generation function was found. ***\n");
fprintf(fpOutputFile,"\n// No at end of generation function.\n");
rewind(fpGenomeFile);
yyin = fpTemplateFile;
BEGIN TEMPLATE_ANALYSIS;
bNotFinishedYet=1;
}
<COPY_END_GENERATION_FUNCTION>.|\n {}
<COPY_BEG_GENERATION_FUNCTION>"\\At"[ \t\n]+"the"[ \t\n]+"beginning"[ \t\n]+"of"[ \t\n]+"each"[ \t\n]+"generation"[ \t\n]+"function"[ \t\n]*":" {
DEBUG_PRT("at each beg");
if( (TARGET==CUDA || TARGET==STD)){
fprintf (fpOutputFile,"// Function called at each new generation\nvoid EASEABeginningGenerationFunction(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n");
bFunction=1;
bBeginGeneration = 0;
bBeginGenerationFunction = 1;
BEGIN COPY_USER_GENERATION;
}
}
<COPY_BEG_GENERATION_FUNCTION><<EOF>> {
bBeginGenerationFunction=0; // No Generation function was found in the .ez file
printf("*** No beginning generation function was found. ***\n");
fprintf(fpOutputFile,"\n// No at beginning of generation function.\n");
rewind(fpGenomeFile);
yyin = fpTemplateFile;
BEGIN TEMPLATE_ANALYSIS;
bNotFinishedYet=1;
}
<COPY_BEG_GENERATION_FUNCTION>.|\n {}
<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){ DEBUG_PRT("at each");
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);
bFunction=1; bGenerationFunction=1; bFunction=1; bGenerationFunction=1;
BEGIN COPY_USER_GENERATION; BEGIN COPY_USER_GENERATION;
} }
else if(TARGET==CUDA || TARGET==STD){ else if((TARGET==CUDA || TARGET==STD) && !bBeginGeneration && !bEndGeneration ){
fprintf (fpOutputFile,"// Function called at each new generation\nvoid EASEAGenerationFunction(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n"); fprintf (fpOutputFile,"// Function called at each new generation\nvoid EASEAGenerationFunction(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n");
bFunction=1; bGenerationFunction=1; bFunction=1; bGenerationFunction=1;
if( !bEndGeneration && !bBeginGeneration )
BEGIN COPY_USER_GENERATION; BEGIN COPY_USER_GENERATION;
} }
} }
<COPY_GENERATION_FUNCTION><<EOF>> { <COPY_GENERATION_FUNCTION><<EOF>> {
bGenerationFunction=0; // No Generation function was found in the .ez file bGenerationFunction=0; // No Generation function was found in the .ez file
if (bVERBOSE) printf("*** No generation function was found. ***\n"); if( bBeginGeneration ){
fprintf(fpOutputFile,"\n// No generation function.\n"); if( bVERBOSE ) printf("*** No generation function was found. ***\n");
fprintf(fpOutputFile,"\n// No at begining of generation function.\n");
}
else if ( bEndGeneration ){
printf("*** No generation function was found. ***\n");
fprintf(fpOutputFile,"\n// No at end of generation function.\n");
}
else{
printf("*** No generation function was found. ***\n");
fprintf(fpOutputFile,"\n// No generation function.\n");
}
rewind(fpGenomeFile); rewind(fpGenomeFile);
yyin = fpTemplateFile; yyin = fpTemplateFile;
BEGIN TEMPLATE_ANALYSIS; BEGIN TEMPLATE_ANALYSIS;
......
...@@ -227,20 +227,6 @@ return NbMut; ...@@ -227,20 +227,6 @@ return NbMut;
CPPFLAGS+= CPPFLAGS+=
\end \end
\At the beginning of each generation function:
if (NB_GEN-currentGeneration==10) pMutPerGene=0.1;
\end
\At the end of each generation function:
if (NB_GEN-currentGeneration==10) pMutPerGene=0.1;
\end
\At each new generation :
cout << "A new generation is born" << endl;
\end
\Default run parameters : // Please let the parameters appear in this order \Default run parameters : // Please let the parameters appear in this order
......
...@@ -273,14 +273,13 @@ void EvolutionaryAlgorithm::runEvolutionaryLoop(){ ...@@ -273,14 +273,13 @@ void EvolutionaryAlgorithm::runEvolutionaryLoop(){
gettimeofday(&begin,NULL); gettimeofday(&begin,NULL);
while( this->allCriteria() == false ){ while( this->allCriteria() == false ){
\INSERT_BEGINNING_GEN_FCT_CALL
population->produceOffspringPopulation(); population->produceOffspringPopulation();
\INSERT_BOUND_CHECKING_FCT_CALL \INSERT_BOUND_CHECKING_FCT_CALL
population->evaluateOffspringPopulation(); population->evaluateOffspringPopulation();
\INSERT_GEN_FCT_CALL \INSERT_END_GEN_FCT_CALL
#if \IS_PARENT_REDUCTION #if \IS_PARENT_REDUCTION
population->reduceParentPopulation(\SURV_PAR_SIZE); population->reduceParentPopulation(\SURV_PAR_SIZE);
...@@ -292,7 +291,8 @@ void EvolutionaryAlgorithm::runEvolutionaryLoop(){ ...@@ -292,7 +291,8 @@ void EvolutionaryAlgorithm::runEvolutionaryLoop(){
#endif #endif
population->reduceTotalPopulation(); population->reduceTotalPopulation();
\INSERT_GEN_FCT_CALL
showPopulationStats(begin); showPopulationStats(begin);
currentGeneration += 1; currentGeneration += 1;
......
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