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
%start COPY_EO_INITIALISER
%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_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
%name CEASEALexer {
......@@ -72,7 +72,7 @@ Centre de Math
bool bWaitingForSemiColon,bFinishNB_GEN,bFinishMINIMISE,bFinishMINIMIZE,bGenerationFunction;
bool bCatchNextSemiColon,bWaitingToClosePopulation, bMethodsInGenome, bFinalizationFunction;
bool bWithinCUDA_Initializer, bWithinMAKEFILEOPTION, bWithinCUDA_Evaluator, bBoundCheckingFunction;
bool bIsParentReduce, bIsOffspringReduce, bEndGeneration, bBeginGeneration;
bool bIsParentReduce, bIsOffspringReduce, bEndGeneration, bBeginGeneration, bEndGenerationFunction, bBeginGenerationFunction;
CSymbol *pASymbol;
public:
......@@ -89,7 +89,7 @@ Centre de Math
bCatchNextSemiColon,bWaitingToClosePopulation=bMethodsInGenome=0;
bBoundCheckingFunction = bWithinCUDA_Initializer=bWithinMAKEFILEOPTION =bWithinCUDA_Evaluator=0;
bIsParentReduce = bIsOffspringReduce = false;
bEndGeneration = bBeginGeneration = false;
bEndGeneration = bBeginGeneration = bEndGenerationFunction = bBeginGenerationFunction = false;
}
// macros
......@@ -159,20 +159,24 @@ exponent ([Ee][+-]?[0-9]+)
<TEMPLATE_ANALYSIS>"\\INSERT_BEGIN_GENERATION_FUNCTION" {
DEBUG_PRT("insert beg");
if (bVERBOSE) printf ("Inserting at the begining of each generation function.\n");
yyreset();
yyin = fpGenomeFile;
BEGIN COPY_GENERATION_FUNCTION;
bBeginGeneration = true;
bEndGeneration = false;
BEGIN COPY_BEG_GENERATION_FUNCTION;
}
<TEMPLATE_ANALYSIS>"\\INSERT_END_GENERATION_FUNCTION" {
DEBUG_PRT("insert end");
if (bVERBOSE) printf ("Inserting at the end of each generation function.\n");
yyreset();
yyin = fpGenomeFile;
bEndGeneration = true;
bBeginGeneration = false;
BEGIN COPY_GENERATION_FUNCTION;
BEGIN COPY_END_GENERATION_FUNCTION;
}
......@@ -589,9 +593,9 @@ exponent ([Ee][+-]?[0-9]+)
BEGIN PARAMETERS_ANALYSIS;
}
<TEMPLATE_ANALYSIS>"\\INSERT_GEN_FCT_CALL" {
DEBUG_PRT("Generational function call %d",bGenerationFunction);
if (bGenerationFunction) {
if( bVERBOSE ) fprintf(stdout,"Inserting generation function call\n");
if( TARGET==CUDA || TARGET==STD ){
fprintf(fpOutputFile,"\n\tEASEAGenerationFunction(this);");
}
......@@ -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" {
if (bBoundCheckingFunction) {
if( TARGET==CUDA || TARGET==STD ){
......@@ -1138,35 +1161,86 @@ exponent ([Ee][+-]?[0-9]+)
<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");
bFunction=1; bGenerationFunction=1;
bEndGeneration = 0;
bFunction=1;
bEndGenerationFunction = 1;
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]*":" {
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," const GAPopulation *pPopulation;\n",sPROJECT_NAME);
fprintf(fpOutputFile," pPopulation=&(g.population()); // to circumvent a bug in GALib\n",sPROJECT_NAME);
bFunction=1; bGenerationFunction=1;
BEGIN COPY_USER_GENERATION;
}
else if(TARGET==CUDA || TARGET==STD){
fprintf (fpOutputFile,"// Function called at each new generation\nvoid EASEAGenerationFunction(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n");
bFunction=1; bGenerationFunction=1;
if( !bEndGeneration && !bBeginGeneration )
else if((TARGET==CUDA || TARGET==STD) && !bBeginGeneration && !bEndGeneration ){
fprintf (fpOutputFile,"// Function called at each new generation\nvoid EASEAGenerationFunction(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n");
bFunction=1; bGenerationFunction=1;
BEGIN COPY_USER_GENERATION;
}
}
<COPY_GENERATION_FUNCTION><<EOF>> {
bGenerationFunction=0; // No Generation function was found in the .ez file
if (bVERBOSE) printf("*** No generation function was found. ***\n");
fprintf(fpOutputFile,"\n// No generation function.\n");
if( bBeginGeneration ){
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);
yyin = fpTemplateFile;
BEGIN TEMPLATE_ANALYSIS;
......
......@@ -227,20 +227,6 @@ return NbMut;
CPPFLAGS+=
\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
......
......@@ -273,14 +273,13 @@ void EvolutionaryAlgorithm::runEvolutionaryLoop(){
gettimeofday(&begin,NULL);
while( this->allCriteria() == false ){
\INSERT_BEGINNING_GEN_FCT_CALL
population->produceOffspringPopulation();
\INSERT_BOUND_CHECKING_FCT_CALL
population->evaluateOffspringPopulation();
\INSERT_GEN_FCT_CALL
\INSERT_END_GEN_FCT_CALL
#if \IS_PARENT_REDUCTION
population->reduceParentPopulation(\SURV_PAR_SIZE);
......@@ -292,7 +291,8 @@ void EvolutionaryAlgorithm::runEvolutionaryLoop(){
#endif
population->reduceTotalPopulation();
\INSERT_GEN_FCT_CALL
showPopulationStats(begin);
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