Commit 3ca1ba93 authored by Frederic's avatar Frederic
Browse files
parents 3185e50a fef1bee4
...@@ -1163,9 +1163,6 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1163,9 +1163,6 @@ exponent ([Ee][+-]?[0-9]+)
<COPY_FINALIZATION_FUNCTION>.|\n {} <COPY_FINALIZATION_FUNCTION>.|\n {}
<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]*":" { <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"); DEBUG_PRT("at each end");
if( (TARGET==CUDA || TARGET==STD) ){ if( (TARGET==CUDA || TARGET==STD) ){
...@@ -1294,11 +1291,24 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1294,11 +1291,24 @@ exponent ([Ee][+-]?[0-9]+)
<COPY>"POP_SIZE"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"POP_SIZE"); <COPY>"POP_SIZE"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"POP_SIZE");
else fprintf(fpOutputFile,"EZ_POP_SIZE");} // local genome name else fprintf(fpOutputFile,"EZ_POP_SIZE");} // local genome name
<COPY>"MUT_PROB" | <COPY>"MUT_PROB" |
<COPY>"MUT_PROB"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"MUT_PROB"); <COPY>"MUT_PROB"/[ \t\n]*"==" {
else fprintf(fpOutputFile,"EZ_MUT_PROB");} // local genome name if (bDoubleQuotes)
fprintf(fpOutputFile,"MUT_PROB");
else
if( TARGET==STD || TARGET==CUDA){
fprintf(fpOutputFile,"(*pEZ_MUT_PROB)");
}
else fprintf(fpOutputFile,"EZ_MUT_PROB");
} // local genome name
<COPY>"XOVER_PROB" | <COPY>"XOVER_PROB" |
<COPY>"XOVER_PROB"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"XOVER_PROB"); <COPY>"XOVER_PROB"/[ \t\n]*"==" {
else fprintf(fpOutputFile,"EZ_XOVER_PROB");} // local genome name if (bDoubleQuotes)
fprintf(fpOutputFile,"XOVER_PROB");
else if( TARGET==CUDA || TARGET==STD )
fprintf(fpOutputFile,"(*pEZ_XOVER_PROB)");
else fprintf(fpOutputFile,"EZ_XOVER_PROB");
} // local genome name
<COPY>"REPL_PERC" | <COPY>"REPL_PERC" |
<COPY>"REPL_PERC"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"REPL_PERC"); <COPY>"REPL_PERC"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"REPL_PERC");
else fprintf(fpOutputFile,"EZ_REPL_PERC");} // local genome name else fprintf(fpOutputFile,"EZ_REPL_PERC");} // local genome name
...@@ -1325,7 +1335,11 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1325,7 +1335,11 @@ exponent ([Ee][+-]?[0-9]+)
<COPY>"currentGeneration"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The current generation number cannot be changed (not an l-value).\n",sEZ_FILE_NAME,yylineno); exit(1);} <COPY>"currentGeneration"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The current generation number cannot be changed (not an l-value).\n",sEZ_FILE_NAME,yylineno); exit(1);}
<COPY>"NB_GEN"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The number of generations can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);} <COPY>"NB_GEN"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The number of generations can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
<COPY>"POP_SIZE"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The size of the population can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);} <COPY>"POP_SIZE"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The size of the population can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
<COPY>"MUT_PROB"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The mutation probability can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);} <COPY>"MUT_PROB"[ \t\n]*"=" {
fprintf(stderr,"\n%s - Error line %d: The mutation probability can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno);
exit (1);
}
<COPY>"XOVER_PROB"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The crossover proability can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);} <COPY>"XOVER_PROB"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The crossover proability can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
<COPY>"REPL_PERC"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The replacement percentage can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);} <COPY>"REPL_PERC"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The replacement percentage can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
<COPY>"MINIMISE"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The evaluation goal can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);} <COPY>"MINIMISE"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The evaluation goal can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
...@@ -1601,17 +1615,27 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1601,17 +1615,27 @@ exponent ([Ee][+-]?[0-9]+)
case EO : fprintf(fpOutputFile,"EZ_POP_SIZE"); case EO : fprintf(fpOutputFile,"EZ_POP_SIZE");
}} // local genome name }} // local genome name
<COPY_USER_GENERATION>"MUT_PROB" | <COPY_USER_GENERATION>"MUT_PROB" |
<COPY_USER_GENERATION>"MUT_PROB"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"MUT_PROB"); <COPY_USER_GENERATION>"MUT_PROB"/[ \t\n]*"==" {
if (bDoubleQuotes) fprintf(fpOutputFile,"MUT_PROB");
else switch (TARGET) { else switch (TARGET) {
case GALIB : fprintf(fpOutputFile,"g.pMutation()"); break; case GALIB : fprintf(fpOutputFile,"g.pMutation()"); break;
case EO : fprintf(fpOutputFile,"EZ_MUT_PROB"); case EO : fprintf(fpOutputFile,"EZ_MUT_PROB"); break;
}} // local genome name case STD:
case CUDA:
fprintf(fpOutputFile,"(*pEZ_MUT_PROB)");
}
} // local genome name
<COPY_USER_GENERATION>"XOVER_PROB" | <COPY_USER_GENERATION>"XOVER_PROB" |
<COPY_USER_GENERATION>"XOVER_PROB"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"XOVER_PROB"); <COPY_USER_GENERATION>"XOVER_PROB"/[ \t\n]*"==" {
if (bDoubleQuotes) fprintf(fpOutputFile,"XOVER_PROB");
else switch (TARGET) { else switch (TARGET) {
case GALIB : fprintf(fpOutputFile,"g.pCrossover()"); break; case GALIB : fprintf(fpOutputFile,"g.pCrossover()"); break;
case EO : fprintf(fpOutputFile,"EZ_XOVER_PROB"); case EO : fprintf(fpOutputFile,"EZ_XOVER_PROB"); break;
}} // local genome name case STD:
case CUDA:
fprintf(fpOutputFile,"(*pEZ_XOVER_PROB)");
}
} // local genome name
<COPY_USER_GENERATION>"REPL_PERC" | <COPY_USER_GENERATION>"REPL_PERC" |
<COPY_USER_GENERATION>"REPL_PERC"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"REPL_PERC"); <COPY_USER_GENERATION>"REPL_PERC"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"REPL_PERC");
else switch (TARGET) { else switch (TARGET) {
...@@ -1673,14 +1697,23 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1673,14 +1697,23 @@ exponent ([Ee][+-]?[0-9]+)
else switch (TARGET) { else switch (TARGET) {
case GALIB : fprintf(fpOutputFile,"g.pMutation((EZ_MUT_PROB="); case GALIB : fprintf(fpOutputFile,"g.pMutation((EZ_MUT_PROB=");
bWaitingForSemiColon=1; break; bWaitingForSemiColon=1; break;
case EO : fprintf(fpOutputFile,"EZ_MUT_PROB="); case EO : fprintf(fpOutputFile,"EZ_MUT_PROB="); break;
}} // local genome name case CUDA:
case STD:
fprintf(fpOutputFile,"(*pEZ_MUT_PROB)=");
break;
}
} // local genome name
<COPY_USER_GENERATION>"XOVER_PROB"[ \t\n]*"=" {if (bDoubleQuotes) fprintf(fpOutputFile,"%s",yytext); <COPY_USER_GENERATION>"XOVER_PROB"[ \t\n]*"=" {if (bDoubleQuotes) fprintf(fpOutputFile,"%s",yytext);
else switch (TARGET) { else switch (TARGET) {
case GALIB :fprintf(fpOutputFile,"g.pCrossover((EZ_XOVER_PROB="); case GALIB :fprintf(fpOutputFile,"g.pCrossover((EZ_XOVER_PROB=");
bWaitingForSemiColon=1; break; bWaitingForSemiColon=1; break;
case EO : fprintf(fpOutputFile,"EZ_MUT_PROB="); case EO : fprintf(fpOutputFile,"EZ_XOVER_PROB="); break;
}} // local genome name case CUDA:
case STD:
fprintf(fpOutputFile,"(*pEZ_XOVER_PROB)=");
}
} // local genome name
<COPY_USER_GENERATION>"REPL_PERC"[ \t\n]*"=" {if (bDoubleQuotes) fprintf(fpOutputFile,"%s",yytext); <COPY_USER_GENERATION>"REPL_PERC"[ \t\n]*"=" {if (bDoubleQuotes) fprintf(fpOutputFile,"%s",yytext);
else switch (TARGET) { else switch (TARGET) {
case GALIB :fprintf(fpOutputFile,"g.pReplacement((1/100)*(EZ_REPL_PERC="); case GALIB :fprintf(fpOutputFile,"g.pReplacement((1/100)*(EZ_REPL_PERC=");
...@@ -1827,10 +1860,18 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1827,10 +1860,18 @@ exponent ([Ee][+-]?[0-9]+)
<COPY_USER_FUNCTION>"POP_SIZE"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"POP_SIZE"); <COPY_USER_FUNCTION>"POP_SIZE"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"POP_SIZE");
else fprintf(fpOutputFile,"EZ_POP_SIZE");} // local genome name else fprintf(fpOutputFile,"EZ_POP_SIZE");} // local genome name
<COPY_USER_FUNCTION>"MUT_PROB" | <COPY_USER_FUNCTION>"MUT_PROB" |
<COPY_USER_FUNCTION>"MUT_PROB"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"MUT_PROB"); <COPY_USER_FUNCTION>"MUT_PROB"/[ \t\n]*"==" {
else fprintf(fpOutputFile,"EZ_MUT_PROB");} // local genome name if (bDoubleQuotes) fprintf(fpOutputFile,"MUT_PROB");
else if( TARGET==CUDA || TARGET==STD)
fprintf(fpOutputFile,"(*pEZ_MUT_PROB)");
else fprintf(fpOutputFile,"EZ_MUT_PROB");
} // local genome name
<COPY_USER_FUNCTION>"XOVER_PROB" | <COPY_USER_FUNCTION>"XOVER_PROB" |
<COPY_USER_FUNCTION>"XOVER_PROB"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"XOVER_PROB"); <COPY_USER_FUNCTION>"XOVER_PROB"/[ \t\n]*"==" {
if (bDoubleQuotes)
fprintf(fpOutputFile,"XOVER_PROB");
else if( TARGET==CUDA || TARGET==STD )
fprintf(fpOutputFile,"(*pEZ_XOVER_PROB)");
else fprintf(fpOutputFile,"EZ_XOVER_PROB");} // local genome name else fprintf(fpOutputFile,"EZ_XOVER_PROB");} // local genome name
<COPY_USER_FUNCTION>"REPL_PERC" | <COPY_USER_FUNCTION>"REPL_PERC" |
<COPY_USER_FUNCTION>"REPL_PERC"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"REPL_PERC"); <COPY_USER_FUNCTION>"REPL_PERC"/[ \t\n]*"==" {if (bDoubleQuotes) fprintf(fpOutputFile,"REPL_PERC");
...@@ -1839,7 +1880,11 @@ exponent ([Ee][+-]?[0-9]+) ...@@ -1839,7 +1880,11 @@ exponent ([Ee][+-]?[0-9]+)
<COPY_USER_FUNCTION>"currentGeneration"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The current generation number cannot be changed (not an l-value).\n",sEZ_FILE_NAME,yylineno); exit(1);} <COPY_USER_FUNCTION>"currentGeneration"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The current generation number cannot be changed (not an l-value).\n",sEZ_FILE_NAME,yylineno); exit(1);}
<COPY_USER_FUNCTION>"NB_GEN"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The number of generations can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);} <COPY_USER_FUNCTION>"NB_GEN"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The number of generations can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
<COPY_USER_FUNCTION>"POP_SIZE"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The size of the population can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);} <COPY_USER_FUNCTION>"POP_SIZE"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The size of the population can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
<COPY_USER_FUNCTION>"MUT_PROB"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The mutation probability can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);} <COPY_USER_FUNCTION>"MUT_PROB"[ \t\n]*"=" {
fprintf(stderr,"\n%s - Error line %d: The mutation probability can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno);
exit (1);
}
<COPY_USER_FUNCTION>"XOVER_PROB"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The crossover proability can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);} <COPY_USER_FUNCTION>"XOVER_PROB"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The crossover proability can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
<COPY_USER_FUNCTION>"REPL_PERC"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The replacement percentage can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);} <COPY_USER_FUNCTION>"REPL_PERC"[ \t\n]*"=" {fprintf(stderr,"\n%s - Error line %d: The replacement percentage can only be changed within the generation function.\n",sEZ_FILE_NAME,yylineno); exit (1);}
<COPY_USER_FUNCTION>"false" {if (TARGET==GALIB) fprintf(fpOutputFile,"gaFalse"); <COPY_USER_FUNCTION>"false" {if (TARGET==GALIB) fprintf(fpOutputFile,"gaFalse");
......
...@@ -167,11 +167,12 @@ float gauss() ...@@ -167,11 +167,12 @@ float gauss()
printf("%.02f:%.02f|",Genome.x[i],Genome.sigma[i]); printf("%.02f:%.02f|",Genome.x[i],Genome.sigma[i]);
} }
\end \end
\Initialisation function: \before everything else function:
std::cout<<"************* n: "<<n<<std::endl; std::cout<<"************* n: "<<n<<std::endl;
\end \end
\Finalization function: \after everything else function:
cout << "xover prob is " << XOVER_PROB << endl;
cout << "finalization function called" << endl; cout << "finalization function called" << endl;
\end \end
...@@ -198,6 +199,12 @@ GenomeClass { ...@@ -198,6 +199,12 @@ GenomeClass {
} }
\end \end
\At the end of each generation function:
if( currentGeneration==98 ) XOVER_PROB = 0.5;
\end
\GenomeClass::mutator : // Must return the number of mutations \GenomeClass::mutator : // Must return the number of mutations
int NbMut=0; int NbMut=0;
float pond = 1./sqrt((float)n); float pond = 1./sqrt((float)n);
...@@ -218,6 +225,7 @@ return NbMut; ...@@ -218,6 +225,7 @@ return NbMut;
\GenomeClass::evaluator : // Returns the score \GenomeClass::evaluator : // Returns the score
float Score= 0.0; float Score= 0.0;
float Point[SIZE]; float Point[SIZE];
if(0) return 0;
for (int i=0; i<N_LIM; i++) Point[i] = Genome.x[i]; for (int i=0; i<N_LIM; i++) Point[i] = Genome.x[i];
Score= Weierstrass(Point, N_LIM); Score= Weierstrass(Point, N_LIM);
return Score; return Score;
...@@ -232,7 +240,7 @@ CPPFLAGS+= ...@@ -232,7 +240,7 @@ 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
Mutation probability : 1 // MUT_PROB Mutation probability : 1 // MUT_PROB
Crossover probability : 1 // XOVER_PROB Crossover probability : 0.8 // XOVER_PROB
Population size : 20 // POP_SIZE Population size : 20 // POP_SIZE
Offspring size : 20 // 40% Offspring size : 20 // 40%
Genitors selector: Tournament 2 Genitors selector: Tournament 2
......
...@@ -4,11 +4,19 @@ ...@@ -4,11 +4,19 @@
*/ */
\ANALYSE_PARAMETERS \ANALYSE_PARAMETERS
using namespace std; using namespace std;
#include <stdlib.h>
/** Global variables for the whole algorithm */
float* pEZ_MUT_PROB = NULL;
float* pEZ_XOVER_PROB = NULL;
#include <iostream> #include <iostream>
#include "EASEATools.hpp" #include "EASEATools.hpp"
#include "EASEAIndividual.hpp" #include "EASEAIndividual.hpp"
#include <time.h> #include <time.h>
RandomGenerator* globalRandomGenerator; RandomGenerator* globalRandomGenerator;
size_t *EZ_NB_GEN; size_t *EZ_NB_GEN;
...@@ -23,6 +31,9 @@ int main(int argc, char** argv){ ...@@ -23,6 +31,9 @@ int main(int argc, char** argv){
float pMutation = \MUT_PROB; float pMutation = \MUT_PROB;
float pMutationPerGene = 0.05; float pMutationPerGene = 0.05;
pEZ_MUT_PROB = &pMutationPerGene;
pEZ_XOVER_PROB = &pCrossover;
time_t seed = setVariable("seed",time(0)); time_t seed = setVariable("seed",time(0));
globalRandomGenerator = new RandomGenerator(seed); globalRandomGenerator = new RandomGenerator(seed);
...@@ -77,7 +88,6 @@ int main(int argc, char** argv){ ...@@ -77,7 +88,6 @@ int main(int argc, char** argv){
#include <sys/time.h> #include <sys/time.h>
#define STD_TPL #define STD_TPL
extern RandomGenerator* globalRandomGenerator; extern RandomGenerator* globalRandomGenerator;
\INSERT_USER_DECLARATIONS \INSERT_USER_DECLARATIONS
...@@ -281,8 +291,7 @@ void EvolutionaryAlgorithm::runEvolutionaryLoop(){ ...@@ -281,8 +291,7 @@ void EvolutionaryAlgorithm::runEvolutionaryLoop(){
\INSERT_BOUND_CHECKING_FCT_CALL \INSERT_BOUND_CHECKING_FCT_CALL
population->evaluateOffspringPopulation(); population->evaluateOffspringPopulation();
\INSERT_END_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);
...@@ -709,6 +718,8 @@ Population::Population(size_t parentPopulationSize, size_t offspringPopulationSi ...@@ -709,6 +718,8 @@ Population::Population(size_t parentPopulationSize, size_t offspringPopulationSi
this->pCrossover = pCrossover; this->pCrossover = pCrossover;
this->pMutation = pMutation; this->pMutation = pMutation;
pEZ_MUT_PROB = &this->pMutation;
pEZ_XOVER_PROB = &this->pCrossover;
this->pMutationPerGene = pMutationPerGene; this->pMutationPerGene = pMutationPerGene;
this->rg = rg; this->rg = rg;
...@@ -1261,6 +1272,9 @@ string setVariable(const string optionName, string defaultValue){ ...@@ -1261,6 +1272,9 @@ string setVariable(const string optionName, string defaultValue){
#include <boost/archive/text_iarchive.hpp> //for serialization (loading) #include <boost/archive/text_iarchive.hpp> //for serialization (loading)
#include <boost/serialization/vector.hpp> #include <boost/serialization/vector.hpp>
extern float* pEZ_MUT_PROB;
extern float* pEZ_XOVER_PROB;
class EvolutionaryAlgorithm; class EvolutionaryAlgorithm;
class Individual; class Individual;
class Population; class Population;
......
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