Commit 4fa0f124 authored by maitre's avatar maitre

Almost finished TGP version.

parent 9cc29417
......@@ -26,7 +26,7 @@ Centre de Math
bool genomeSizeValidity=false;
int lineCounter = 0;
// local functions
// local functions
char* selectorDetermination(int nMINIMISE, char* sSELECTOR){
char selectorName[50];
......@@ -75,7 +75,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_BEFORE_REPLACEMENT GET_METHODS COPY_MAKEFILE_OPTION COPY_BOUND_CHECKING_FUNCTION COPY_BEG_GENERATION_FUNCTION COPY_END_GENERATION_FUNCTION
%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
// lexical analyser name and class definition
%name CEASEALexer {
......@@ -187,6 +187,15 @@ exponent ([Ee][+-]?[0-9]+)
}
<TEMPLATE_ANALYSIS>"\\INSTEAD_EVAL_FUNCTION" {
//DEBUG_PRT_PRT("insert beg");
yyreset();
yyin = fpGenomeFile;
if (bVERBOSE) printf ("Evaluation population in a single function!!.\n");
BEGIN COPY_INSTEAD_EVAL;
}
<TEMPLATE_ANALYSIS>"\\INSERT_END_GENERATION_FUNCTION" {
//DEBUG_PRT_PRT("insert end");
if (bVERBOSE) printf ("Inserting at the end of each generation function.\n");
......@@ -497,7 +506,7 @@ exponent ([Ee][+-]?[0-9]+)
if (bVERBOSE) printf ("Inserting user functions.\n");
yyreset();
yyin = fpGenomeFile;
lineCounter=1; // switch to .ez file and analyser
lineCounter=2; // switch to .ez file and analyser
BEGIN COPY_USER_FUNCTIONS;
}
<TEMPLATE_ANALYSIS>"\\INSERT_EO_INITIALISER" {
......@@ -531,11 +540,13 @@ exponent ([Ee][+-]?[0-9]+)
<TEMPLATE_ANALYSIS>"\\INSERT_MUTATOR" {
yyreset();
yyin = fpGenomeFile; // switch to .ez file and analyser
lineCounter=1;
BEGIN COPY_MUTATOR;
}
<TEMPLATE_ANALYSIS>"\\INSERT_EVALUATOR" {
yyreset();
yyin = fpGenomeFile; // switch to .ez file and analyser
lineCounter=1;
BEGIN COPY_EVALUATOR;
}
......@@ -543,6 +554,7 @@ exponent ([Ee][+-]?[0-9]+)
yyreset();
yyin = fpGenomeFile; // switch to .ez file and analyser
bWithinCUDA_Evaluator = 1;
lineCounter=1;
BEGIN COPY_EVALUATOR;
}
......@@ -960,6 +972,29 @@ if(OPERATING_SYSTEM=WINDOWS)
}
}
<COPY_INSTEAD_EVAL>"\\Instead"[ \t\n]+"evaluation"[ \t\n]+"function:" {
//DEBUG_PRT_PRT("at each beg");
if( (TARGET==CUDA || TARGET==STD)){
fprintf (fpOutputFile,"{\n");
bFunction=1;
BEGIN COPY_USER_GENERATION;
}
}
<COPY_INSTEAD_EVAL>.|\n {}
<COPY_INSTEAD_EVAL><<EOF>> {
bBeginGenerationFunction=0; // No Generation function was found in the .ez file
if (bVERBOSE) printf("*** No Instead evaluation step function was found. ***\n");
fprintf(fpOutputFile,"\n// No Instead evaluation step function.\n");
rewind(fpGenomeFile);
yyin = fpTemplateFile;
BEGIN TEMPLATE_ANALYSIS;
bNotFinishedYet=1;
}
<COPY_BEG_GENERATION_FUNCTION><<EOF>> {
bBeginGenerationFunction=0; // No Generation function was found in the .ez file
if (bVERBOSE) printf("*** No beginning generation function was found. ***\n");
......@@ -1301,16 +1336,23 @@ if(OPERATING_SYSTEM=WINDOWS)
<COPY_CROSSOVER>\n {lineCounter++;}
<COPY_MUTATOR>"\\GenomeClass::mutator"[ \t\n]*":" {
bWithinMutator=1;
if( bLINE_NUM_EZ_FILE )
fprintf(fpOutputFile,"#line %d \"%s.ez\"\n",lineCounter, sRAW_PROJECT_NAME);
BEGIN COPY_USER_FUNCTION;
return USER_MUTATOR;
}
<COPY_MUTATOR>.|\n {}
<COPY_MUTATOR>. {}
<COPY_MUTATOR>\n {lineCounter++;}
<COPY_EVALUATOR>"\\GenomeClass::evaluator"[ \t\n]*":" {
BEGIN COPY_USER_FUNCTION;
bWithinEvaluator=1;
if( bLINE_NUM_EZ_FILE )
fprintf(fpOutputFile,"#line %d \"%s.ez\"\n",lineCounter, sRAW_PROJECT_NAME);
return USER_EVALUATOR;
}
<COPY_EVALUATOR>.|\n {}
<COPY_EVALUATOR>. {}
<COPY_EVALUATOR>\n {lineCounter++;}
//****************************************
// Basic copy to .cpp file with major changes
......
This diff is collapsed.
......@@ -31,6 +31,9 @@ extern CEvolutionaryAlgorithm* EA;
void EASEABeginningGenerationFunction(CEvolutionaryAlgorithm* evolutionaryAlgorithm);
void EASEAEndGenerationFunction(CEvolutionaryAlgorithm* evolutionaryAlgorithm);
void EASEAGenerationFunctionBeforeReplacement(CEvolutionaryAlgorithm* evolutionaryAlgorithm);
extern void evale_pop_chunk(CIndividual** pop, int popSize);
extern bool INSTEAD_EVAL_STEP;
/**
* @DEPRECATED the next contructor has to be used instead of this one.
*/
......@@ -112,7 +115,11 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
std::cout << "Parent's population initializing "<< std::endl;
this->initializeParentPopulation();
this->population->evaluateParentPopulation();
if(!INSTEAD_EVAL_STEP)
this->population->evaluateParentPopulation();
else
evale_pop_chunk(population->parents, population->parentPopulationSize);
this->population->currentEvaluationNb += this->params->parentPopulationSize;
if(this->params->printInitialPopulation){
std::cout << *population << std::endl;
......@@ -131,9 +138,10 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
EASEABeginningGenerationFunction(this);
population->produceOffspringPopulation();
population->evaluateOffspringPopulation();
if(!INSTEAD_EVAL_STEP)
population->evaluateOffspringPopulation();
else
evale_pop_chunk(population->offsprings, population->offspringPopulationSize);
population->currentEvaluationNb += this->params->offspringPopulationSize;
EASEAGenerationFunctionBeforeReplacement(this);
......@@ -160,8 +168,9 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
population->reduceTotalPopulation(elitistPopulation);
population->sortParentPopulation();
showPopulationStats(begin);
bBest = population->Best;
EASEAEndGenerationFunction(this);
currentGeneration += 1;
......
......@@ -8,6 +8,7 @@
#include "include/CStoppingCriterion.h"
#include <iostream>
#include <signal.h>
#include "include/global.h"
#include "include/CEvolutionaryAlgorithm.h"
/* ****************************************
......@@ -92,3 +93,19 @@ void signal_handler(int sig){
}
/* ****************************************
Goal stopping criterion class
****************************************/
CGoalCriterion::CGoalCriterion( double goal, bool minimize ){
this->goal = goal;
this->minimize = minimize;
}
bool CGoalCriterion::reached(){
if( minimize ){
//printf("bf : %f\n",bBest->fitness);
return bBest->fitness <= goal;
}
else
return bBest->fitness >= goal;
}
......@@ -58,6 +58,19 @@ class CTimeCriterion : public CStoppingCriterion {
void setElapsedTime(size_t elapsedTime);
};
/* ****************************************
Goal stopping criterion class
****************************************/
class CGoalCriterion : public CStoppingCriterion {
private:
double goal;
bool minimize;
public:
virtual bool reached();
CGoalCriterion( double goal, bool minimize );
};
/* ****************************************
ControlCStopingCriterion class
****************************************/
......
......@@ -14,7 +14,7 @@
//#define true 1;
//#define false 0;
class CIndividual;
class CRandomGenerator;
extern CIndividual** pPopulation;
extern CIndividual* bBest;
extern float* pEZ_MUT_PROB;
......
......@@ -7,7 +7,7 @@ LDFLAGS =
$(EXEC):EaseaSym.o EaseaParse.o EaseaLex.o alexyacc/libalex.a EaseaYTools.o libeasea/libeasea.a
$(CPPC) $(CPPFLAGS) $(LDFLAGS) $^ -o $@
echo "export EZ_PATH=$(PWD)/">>$(HOME)/.bashrc
@if [ $(EZ_PATH) != "$(PWD)/" ] ; then echo "export EZ_PATH=$(PWD)/">>$(HOME)/.bashrc ; fi
#
# Congratulations ! It looks like you compiled EASEA successfully.
#
......
......@@ -81,7 +81,7 @@ int main(int argc, char** argv){
using namespace std;
#include "EASEAIndividual.hpp"
bool INSTEAD_EVAL_STEP = false;
CRandomGenerator* globalRandomGenerator;
extern CEvolutionaryAlgorithm* EA;
......@@ -99,6 +99,11 @@ extern CEvolutionaryAlgorithm* EA;
\INSERT_BOUND_CHECKING
void evale_pop_chunk(CIndividual** population, int popSize){
printf("evalPopChunk\n");
\INSTEAD_EVAL_FUNCTION
}
void EASEAInit(int argc, char** argv){
\INSERT_INIT_FCT_CALL
}
......
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