Commit 3b98f4a4 authored by Ogier Maitre's avatar Ogier Maitre

Merge branch 'master' of atia.u-strasbg.fr:easea

parents f68bfdae d74e0ce0
......@@ -20,16 +20,14 @@ Centre de Math
#define CUDA 4
#define STD 5
#define CMAES 6
#define MEMETIC 7
#define STD_FLAVOR_SO 0
#define STD_FLAVOR_MO 1
#define STD_FLAVOR_CMAES 2
#define STD_FLAVOR_MEMETIC 3
#define CUDA_FLAVOR_SO 0
#define CUDA_FLAVOR_MO 1
#define CUDA_FLAVOR_CMAES 2
#define CUDA_FLAVOR_GP 3
#define CUDA_FLAVOR_MEMETIC 4
#define CUDA_FLAVOR_GP 2
#define UNIX 1
......@@ -44,20 +42,23 @@ extern int nClasses_nb;
extern FILE *fpOutputFile, *fpTemplateFile, *fpGenomeFile, *fpExplodedGenomeFile;
extern char sRAW_PROJECT_NAME[], sPROJECT_NAME[], sEO_DIR[], sEZ_PATH[1000], sTPL_DIR[1000], sEZ_FILE_NAME[];
extern char sLOWER_CASE_PROJECT_NAME[];
extern float fSELECT_PRM, fRED_PAR_PRM, fRED_FINAL_PRM, fRED_OFF_PRM;
extern char sSELECTOR[], sSELECTOR_OPERATOR[], sRED_PAR[], sRED_PAR_OPERATOR[], sRED_FINAL[], sRED_FINAL_OPERATOR[], sRED_OFF[], sRED_OFF_OPERATOR[];
extern int nMINIMISE,nELITE;
extern char sIP_FILE[];
extern bool bELITISM, bVERBOSE;
extern bool bBALDWINISM;
extern bool bPRINT_STATS, bPLOT_STATS, bGENERATE_CSV_FILE, bGENERATE_GNUPLOT_SCRIPT, bGENERATE_R_SCRIPT;
extern bool bSAVE_POPULATION, bSTART_FROM_FILE;
extern bool bREMOTE_ISLAND_MODEL;
extern bool bLINE_NUM_EZ_FILE;
extern char* nGENOME_NAME;
extern int nPOP_SIZE, nNB_GEN, nNB_OPT_IT, nOFF_SIZE, nPROBLEM_DIM, nTIME_LIMIT;
extern float fMUT_PROB, fXOVER_PROB, fSURV_PAR_SIZE, fSURV_OFF_SIZE;
extern int nWARNINGS, nERRORS;
extern int TARGET, OPERATING_SYSTEM;
extern int TARGET_FLAVOR;
extern bool bLINE_NUM_EZ_FILE;
extern int nMINIMISE,nELITE;
extern float fMUT_PROB, fXOVER_PROB, fSURV_PAR_SIZE, fSURV_OFF_SIZE;
extern float fSELECT_PRM, fRED_PAR_PRM, fRED_FINAL_PRM, fRED_OFF_PRM;
extern unsigned iMAX_INIT_TREE_D,iMIN_INIT_TREE_D,iMAX_TREE_D,iNB_GPU,iPRG_BUF_SIZE,iMAX_TREE_DEPTH,iNO_FITNESS_CASES;
// Prototypes
......
This diff is collapsed.
......@@ -686,15 +686,6 @@ exponent ([Ee][+-]?[0-9]+)
<TEMPLATE_ANALYSIS>"\\GENOME_SERIAL" {
CListItem<CSymbol*> *pSym;
if (bVERBOSE) printf ("Inserting default genome serializer.\n");
pGENOME->pSymbolList->reset();
while (pSym=pGENOME->pSymbolList->walkToNextItem()){
//DEBUG_PRT_PRT("found new symbol %s",pSym->Object->sName);
fprintf(fpOutputFile," ar & %s;\n",pSym->Object->sName);
}
}
<TEMPLATE_ANALYSIS>"\\INSERT_GENOME" {
if (pGENOME->sString) {
......@@ -767,6 +758,23 @@ exponent ([Ee][+-]?[0-9]+)
}
}
<TEMPLATE_ANALYSIS>"\\GENOME_SERIAL" {
CListItem<CSymbol*> *pSym;
if (bVERBOSE) printf ("Inserting default genome serializer.\n");
fprintf (fpOutputFile,"// Memberwise serialization\n");
pGENOME->pSymbolList->reset();
pGENOME->serializeIndividual(fpOutputFile, "this");
//fprintf(fpOutputFile,"\tEASEA_Line << endl;\n");
}
<TEMPLATE_ANALYSIS>"\\GENOME_DESERIAL" {
CListItem<CSymbol*> *pSym;
if (bVERBOSE) printf ("Inserting default genome deserializer.\n");
fprintf (fpOutputFile,"// Memberwise deserialization\n");
pGENOME->pSymbolList->reset();
pGENOME->deserializeIndividual(fpOutputFile, "this");
}
<TEMPLATE_ANALYSIS>"\\COPY_CUDA_CTOR" {
CListItem<CSymbol*> *pSym;
if (bVERBOSE) printf ("Creating default copy constructor.\n");
......@@ -1102,15 +1110,22 @@ if(OPERATING_SYSTEM=WINDOWS)
<TEMPLATE_ANALYSIS>"\\XOVER_PROB" {fprintf(fpOutputFile,"%f",fXOVER_PROB);}
<TEMPLATE_ANALYSIS>"\\MINIMAXI" {fprintf(fpOutputFile,"%s",(nMINIMISE? "true" : "false")); }
<TEMPLATE_ANALYSIS>"\\ELITISM" {fprintf(fpOutputFile,"%d",bELITISM);}
<TEMPLATE_ANALYSIS>"\\NB_OPT_IT" {fprintf(fpOutputFile,"%d",nNB_OPT_IT);}
<TEMPLATE_ANALYSIS>"\\BALDWINISM" {fprintf(fpOutputFile,"%d",bBALDWINISM);}
<TEMPLATE_ANALYSIS>"\\REMOTE_ISLAND_MODEL" {fprintf(fpOutputFile,"%d",bREMOTE_ISLAND_MODEL);}
<TEMPLATE_ANALYSIS>"\\IP_FILE" {if(strlen(sIP_FILE)>0)fprintf(fpOutputFile,"%s",sIP_FILE); else fprintf(fpOutputFile,"NULL");}
<TEMPLATE_ANALYSIS>"\\PRINT_STATS" {fprintf(fpOutputFile,"%d",bPRINT_STATS);}
<TEMPLATE_ANALYSIS>"\\PLOT_STATS" {fprintf(fpOutputFile,"%d",bPLOT_STATS);}
<TEMPLATE_ANALYSIS>"\\GENERATE_CSV_FILE" {fprintf(fpOutputFile,"%d",bGENERATE_CSV_FILE);}
<TEMPLATE_ANALYSIS>"\\GENERATE_GNUPLOT_SCRIPT" {fprintf(fpOutputFile,"%d",bGENERATE_GNUPLOT_SCRIPT);}
<TEMPLATE_ANALYSIS>"\\GENERATE_R_SCRIPT" {fprintf(fpOutputFile,"%d",bGENERATE_R_SCRIPT);}
<TEMPLATE_ANALYSIS>"\\SAVE_POPULATION" {fprintf(fpOutputFile,"%d",bSAVE_POPULATION);}
<TEMPLATE_ANALYSIS>"\\START_FROM_FILE" {fprintf(fpOutputFile,"%d",bSTART_FROM_FILE);}
<TEMPLATE_ANALYSIS>"\\START_CUDA_GENOME_H_TPL" {
char sFileName[1000];
fclose(fpOutputFile);
......@@ -1551,7 +1566,7 @@ if(OPERATING_SYSTEM=WINDOWS)
fprintf(fpOutputFile,"template <class fitT> %s %sGenome<fitT>::",yytext,sPROJECT_NAME);}
<COPY>"GenomeClass::" {fprintf(fpOutputFile,"template <class fitT> %sGenome<fitT>::",sPROJECT_NAME);}
<COPY>"GenomeClass" {
if( TARGET==CUDA || TARGET==STD) fprintf(fpOutputFile,"Individual");
if( TARGET==CUDA || TARGET==STD) fprintf(fpOutputFile,"IndividualImpl");
else fprintf(fpOutputFile,"%sGenome",sPROJECT_NAME);} // local name
<COPY>"pPopulation[" {
if(bFinalizationFunction){
......@@ -1625,7 +1640,7 @@ if(OPERATING_SYSTEM=WINDOWS)
// keywords
<GENOME_ANALYSIS>"bool" {
yylval.pSymbol = pSymbolTable->find("boolean");
yylval.pSymbol = pSymbolTable->find("bool");
return BOOL;}
<GENOME_ANALYSIS>"boolean" {
yylval.pSymbol = new CSymbol(yytext);
......@@ -2076,12 +2091,15 @@ if(OPERATING_SYSTEM=WINDOWS)
<GET_PARAMETERS>"Crossover"[ \t\n]+"probability"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tXov Prob...\n");return XOVER_PROB;}
<GET_PARAMETERS>"Offspring"[ \t\n]+"size"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tOff Size...\n");return OFFSPRING;}
<GET_PARAMETERS>"Print"[ \t\n]+"stats"[ \t\n]*":"[\t\n]* {if (bVERBOSE) printf("\tPrint Stats...\n");return PRINT_STATS;}
<GET_PARAMETERS>"Plot"[ \t\n]+"stats"[ \t\n]*":"[\t\n]* {if (bVERBOSE) printf("\tPlot Stats with gnuplot...\n");return PLOT_STATS;}
<GET_PARAMETERS>"Print"[ \t\n]+"stats"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tPrint Stats...\n");return PRINT_STATS;}
<GET_PARAMETERS>"Plot"[ \t\n]+"stats"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tPlot Stats with gnuplot...\n");return PLOT_STATS;}
<GET_PARAMETERS>"Generate"[ \t\n]+"csv"[ \t\n]+"stats"[ \t\n]+"file"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tPrint Stats to csv File...\n");return GENERATE_CSV_FILE;}
<GET_PARAMETERS>"Generate"[ \t\n]+"gnuplot"[ \t\n]+"script"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tGenerate Gnuplot Script...\n");return GENERATE_GNUPLOT_SCRIPT;}
<GET_PARAMETERS>"Generate"[ \t\n]+"R"[ \t\n]+"script"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tGenerate R Script...\n");return GENERATE_R_SCRIPT;}
<GET_PARAMETERS>"Save"[ \t\n]+"population"[ \t\n]*":"[ \t\n]* {if(bVERBOSE) printf("\tSave population...\n"); return SAVE_POPULATION;}
<GET_PARAMETERS>"Start"[ \t\n]+"from"[ \t\n]+"file"[ \t\n]*":"[ \t\n]* {if(bVERBOSE) printf("\tStart from file...\n"); return START_FROM_FILE;}
<GET_PARAMETERS>"Reduce"[ \t\n]+"parents"[ \t\n]+"operator"[ \t\n]*":"[ \t\n]* {
if (bVERBOSE) printf ("\tReduce Parents Operator...\n");
bIsParentReduce = true;
......@@ -2102,6 +2120,10 @@ if(OPERATING_SYSTEM=WINDOWS)
<GET_PARAMETERS>"Evaluator"[ \t\n]+"goal"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tMinMax...\n");return MINIMAXI;}
<GET_PARAMETERS>"Number"[ \t\n]+"of"[ \t\n]+"optimisation"[ \t\n]+"iterations"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tNb of Optimisation It...\n");return NB_OPT_IT;}
<GET_PARAMETERS>"Baldwinism"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf ("\tBaldwinism...\n");return BALDWINISM;}
<GET_PARAMETERS>"Remote"[ \t\n]+"island"[ \t\n]+"model"[ \t\n]*":"[ \t\n]* {if(bVERBOSE) printf ("\tRemote Island Model...\n"); return REMOTE_ISLAND_MODEL;}
<GET_PARAMETERS>"IP"[ \t\n]+"file"[ \t\n]*":"[ \t\n]* {if(bVERBOSE) printf("\tIP File...\n"); return IP_FILE;}
// number
<GET_PARAMETERS>[0-9]+"."[0-9]*{exponent}? |
......@@ -2254,11 +2276,11 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable)
if (TARGET==CUDA){
if(TARGET_FLAVOR == CUDA_FLAVOR_SO )
strcat(sTemp,"CUDA.tpl");
else if(TARGET_FLAVOR == CUDA_FLAVOR_CMAES )
else if(TARGET_FLAVOR == CMAES )
strcat(sTemp,"CMAES_CUDA.tpl");
else if( TARGET_FLAVOR == CUDA_FLAVOR_GP )
strcat(sTemp,"CUDA_GP.tpl");
else if(TARGET_FLAVOR == CUDA_FLAVOR_MEMETIC )
else if(TARGET_FLAVOR == MEMETIC )
strcat(sTemp,"CUDA_MEM.tpl");
else
strcat(sTemp,"CUDA_MO.tpl");
......@@ -2272,9 +2294,9 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable)
if (TARGET==STD){
if(TARGET_FLAVOR == STD_FLAVOR_SO)
strcat(sTemp,"STD.tpl");
else if (TARGET_FLAVOR == STD_FLAVOR_CMAES)
else if (TARGET_FLAVOR == CMAES)
strcat(sTemp,"CMAES.tpl");
else if (TARGET_FLAVOR == STD_FLAVOR_MEMETIC )
else if (TARGET_FLAVOR == MEMETIC )
strcat(sTemp,"STD_MEM.tpl");
else
strcat(sTemp,"STD_MO.tpl");
......
This diff is collapsed.
......@@ -3,7 +3,7 @@
#include <cyacc.h>
#line 65 "EaseaParse.y"
#line 68 "EaseaParse.y"
// forward references
class CSymbol;
......@@ -11,7 +11,7 @@ class CSymbol;
#line 12 "EaseaParse.h"
#ifndef YYSTYPE
union tagYYSTYPE {
#line 71 "EaseaParse.y"
#line 74 "EaseaParse.y"
CSymbol* pSymbol;
double dValue;
......@@ -65,26 +65,30 @@ union tagYYSTYPE {
#define MINIMAXI 294
#define ELITISM 295
#define ELITE 296
#define PRINT_STATS 297
#define PLOT_STATS 298
#define GENERATE_CSV_FILE 299
#define GENERATE_GNUPLOT_SCRIPT 300
#define GENERATE_R_SCRIPT 301
#define TIME_LIMIT 302
#define MAX_INIT_TREE_D 303
#define MIN_INIT_TREE_D 304
#define MAX_XOVER_DEPTH 305
#define MAX_MUTAT_DEPTH 306
#define MAX_TREE_D 307
#define NB_GPU 308
#define PRG_BUF_SIZE 309
#define NO_FITNESS_CASES 310
#line 150 "EaseaParse.y"
#define REMOTE_ISLAND_MODEL 297
#define IP_FILE 298
#define PRINT_STATS 299
#define PLOT_STATS 300
#define GENERATE_CSV_FILE 301
#define GENERATE_GNUPLOT_SCRIPT 302
#define GENERATE_R_SCRIPT 303
#define SAVE_POPULATION 304
#define START_FROM_FILE 305
#define TIME_LIMIT 306
#define MAX_INIT_TREE_D 307
#define MIN_INIT_TREE_D 308
#define MAX_XOVER_DEPTH 309
#define MAX_MUTAT_DEPTH 310
#define MAX_TREE_D 311
#define NB_GPU 312
#define PRG_BUF_SIZE 313
#define NO_FITNESS_CASES 314
#line 157 "EaseaParse.y"
#include "EaseaSym.h"
#include "EaseaLex.h"
#line 88 "EaseaParse.h"
#line 92 "EaseaParse.h"
/////////////////////////////////////////////////////////////////////////////
// CEASEAParser
......@@ -105,7 +109,7 @@ protected:
#endif
public:
#line 157 "EaseaParse.y"
#line 164 "EaseaParse.y"
protected:
CEASEALexer EASEALexer; // the lexical analyser
......@@ -119,7 +123,7 @@ public:
double divide(double dDividend, double dDivisor);
CSymbol* insert() const;
#line 123 "EaseaParse.h"
#line 127 "EaseaParse.h"
};
#ifndef YYPARSENAME
......
......@@ -46,7 +46,10 @@ bool bLINE_NUM_EZ_FILE=1;
bool bPRINT_STATS=1;
bool bPLOT_STATS=0;
bool bGENERATE_CSV_FILE=0, bGENERATE_R_SCRIPT=0, bGENERATE_GNUPLOT_SCRIPT=0;
bool bBALDWINISM=0;
bool bSAVE_POPULATION=0, bSTART_FROM_FILE=0;
bool bBALDWINISM=0; //memetic
bool bREMOTE_ISLAND_MODEL=0; //remote island model
char sIP_FILE[128]; //remote island model
int nPOP_SIZE, nOFF_SIZE;
float fSURV_PAR_SIZE=-1.0, fSURV_OFF_SIZE=-1.0;
char *nGENOME_NAME;
......@@ -132,16 +135,20 @@ class CSymbol;
%token MINIMAXI
%token ELITISM
%token ELITE
%token REMOTE_ISLAND_MODEL //island model
%token IP_FILE //island model
%token PRINT_STATS
%token PLOT_STATS
%token GENERATE_CSV_FILE
%token GENERATE_GNUPLOT_SCRIPT
%token GENERATE_R_SCRIPT
%token SAVE_POPULATION
%token START_FROM_FILE
%token TIME_LIMIT
%token MAX_INIT_TREE_D
%token MIN_INIT_TREE_D
%token MAX_XOVER_DEPTH
%token MAX_MUTAT_DEPTH
%token MAX_MUTAT_DEPTH
%token MAX_TREE_D
%token NB_GPU
%token PRG_BUF_SIZE
......@@ -361,7 +368,7 @@ Object
}
| Symbol '[' Expr ']' {
if((TARGET_FLAVOR==STD_FLAVOR_CMAES || TARGET_FLAVOR==CUDA_FLAVOR_CMAES) && nPROBLEM_DIM==0 && strcmp(pCURRENT_CLASS->sName,"Genome")==0) { nGENOME_NAME=$1->sName; nPROBLEM_DIM=(int)$3;}
if((TARGET_FLAVOR==CMAES) && nPROBLEM_DIM==0 && strcmp(pCURRENT_CLASS->sName,"Genome")==0) { nGENOME_NAME=$1->sName; nPROBLEM_DIM=(int)$3;}
printf("DEBUG : size of $3 %d nSize %d\n",(int)$3,pCURRENT_TYPE->nSize);
......@@ -377,7 +384,7 @@ Object
| '*' Symbol '[' Expr ']' {
// this is for support of pointer array. This should be done in a more generic way in a later version
if((TARGET_FLAVOR==STD_FLAVOR_CMAES || TARGET_FLAVOR==CUDA_FLAVOR_CMAES) && nPROBLEM_DIM==0 && strcmp(pCURRENT_CLASS->sName,"Genome")==0) {
if((TARGET_FLAVOR==CMAES) && nPROBLEM_DIM==0 && strcmp(pCURRENT_CLASS->sName,"Genome")==0) {
nGENOME_NAME=$2->sName; nPROBLEM_DIM=(int)$4;
}
......@@ -610,6 +617,19 @@ Parameter
fprintf(stderr,"\n%s - Warning line %d: Baldwinism must be \"True\" or \"False\".\nDefault value \"True\" inserted.\n.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
bBALDWINISM=1;
}}
| REMOTE_ISLAND_MODEL IDENTIFIER2{
if (!mystricmp($2->sName,"False")) bREMOTE_ISLAND_MODEL=0;
else if (!mystricmp($2->sName,"True")) bREMOTE_ISLAND_MODEL=1;
else {
fprintf(stderr,"\n%s - Warning line %d: remote island model must be \"True\" or \"False\".\nDefault value \"False\" inserted.\n",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
bREMOTE_ISLAND_MODEL=0;
}}
| IP_FILE IDENTIFIER2'.'IDENTIFIER2{
sprintf(sIP_FILE, $2->sName);
strcat(sIP_FILE,".");
strcat(sIP_FILE,$4->sName);
}
| PRINT_STATS NUMBER2{
if((int)$2>=1)
......@@ -641,6 +661,20 @@ Parameter
else
bGENERATE_R_SCRIPT=0;
}
| SAVE_POPULATION IDENTIFIER2{
if (!mystricmp($2->sName,"False")) bSAVE_POPULATION=0;
else if (!mystricmp($2->sName,"True")) bSAVE_POPULATION=1;
else {
fprintf(stderr,"\n%s - Warning line %d: SavePopulation must be \"True\" or \"False\".\nDefault value \"False\" inserted.\n.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
bSAVE_POPULATION=0;
}}
| START_FROM_FILE IDENTIFIER2{
if (!mystricmp($2->sName,"False")) bSTART_FROM_FILE=0;
else if (!mystricmp($2->sName,"True")) bSTART_FROM_FILE=1;
else {
fprintf(stderr,"\n%s - Warning line %d: StartFromFile must be \"True\" or \"False\".\nDefault value \"False\" inserted.\n.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
bSTART_FROM_FILE=0;
}}
| MAX_INIT_TREE_D NUMBER2 {iMAX_INIT_TREE_D = (unsigned)$2;}
| MIN_INIT_TREE_D NUMBER2 {iMIN_INIT_TREE_D = (unsigned)$2;}
| MAX_TREE_D NUMBER2 {iMAX_TREE_D = (unsigned)$2;}
......@@ -686,7 +720,8 @@ int main(int argc, char *argv[]){
char *sTemp;
int i=0;
TARGET=bVERBOSE=0;
TARGET=STD;
bVERBOSE=0;
sRAW_PROJECT_NAME[0]=0; // used to ask for a filename if no filename is found on the command line.
while ((++nParamNb) < argc) {
......@@ -714,20 +749,10 @@ int main(int argc, char *argv[]){
TARGET_FLAVOR = STD_FLAVOR_MO;
}
else if (!mystricmp(sTemp,"cmaes")) {
TARGET=STD;
TARGET_FLAVOR = STD_FLAVOR_CMAES;
}
else if (!mystricmp(sTemp,"cmaes_cuda")) {
TARGET=CUDA;
TARGET_FLAVOR = CUDA_FLAVOR_CMAES;
TARGET_FLAVOR = CMAES;
}
else if (!mystricmp(sTemp,"memetic")) {
TARGET=STD;
TARGET_FLAVOR = STD_FLAVOR_MEMETIC;
}
else if (!mystricmp(sTemp,"memetic_cuda")) {
TARGET=CUDA;
TARGET_FLAVOR = CUDA_FLAVOR_MEMETIC;
TARGET_FLAVOR = MEMETIC;
}
else if (!mystricmp(sTemp,"v")) bVERBOSE=true;
......
......@@ -185,9 +185,59 @@ void CSymbol::print(FILE *fp){
fprintf(fp," if( %s[EASEA_Ndx] ) delete %s[EASEA_Ndx];\n",pSym->Object->sName,pSym->Object->sName);
}
}
fprintf(fp," }\n"); // destructor
fprintf(fp," string serializer() { // serialize\n"); // serializer
fprintf(fp," \tostringstream EASEA_Line(ios_base::app);\n");
pSymbolList->reset();
while (pSym=pSymbolList->walkToNextItem()){
if((pSym->Object->pType->ObjectType==oUserClass)){
fprintf(fpOutputFile,"\tif(this->%s != NULL){\n",pSym->Object->sName);
fprintf(fpOutputFile,"\t\tEASEA_Line << \"\\a \";\n");
fprintf(fpOutputFile,"\t\tEASEA_Line << this->%s->serializer() << \" \";\n",pSym->Object->sName);
fprintf(fpOutputFile,"}\n");
fprintf(fpOutputFile,"\telse\n");
fprintf(fpOutputFile,"\t\tEASEA_Line << \"NULL\" << \" \";\n");
}
else{
if (pSym->Object->ObjectType==oObject){
fprintf(fpOutputFile,"\tEASEA_Line << this->%s << \" \";\n",pSym->Object->sName);
}
if(pSym->Object->ObjectType==oArray){
fprintf(fpOutputFile,"\tfor(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
fprintf(fpOutputFile,"\t\tEASEA_Line << this->%s[EASEA_Ndx] <<\" \";\n", pSym->Object->sName);
}
}
}
fprintf(fp," \treturn EASEA_Line.str();\n");
fprintf(fp," }\n"); // serializer
fprintf(fp," void deserializer(istringstream* EASEA_Line) { // deserialize\n"); // deserializer
fprintf(fp," \tstring line;\n");
pSymbolList->reset();
while (pSym=pSymbolList->walkToNextItem()){
if((pSym->Object->pType->ObjectType==oUserClass)){
fprintf(fpOutputFile,"\t(*EASEA_Line) >> line;\n");
fprintf(fpOutputFile,"\tif(strcmp(line.c_str(),\"NULL\")==0)\n");
fprintf(fpOutputFile,"\t\tthis->%s = NULL;\n",pSym->Object->sName);
fprintf(fpOutputFile,"\telse{\n");
fprintf(fpOutputFile,"\t\tthis->%s = new %s;\n",pSym->Object->sName, sName);
fprintf(fpOutputFile,"\t\tthis->%s->deserializer(EASEA_Line);\n",pSym->Object->sName);
fprintf(fpOutputFile,"\t}");
}
else{
if (pSym->Object->ObjectType==oObject){
fprintf(fpOutputFile,"\t(*EASEA_Line) >> this->%s;\n",pSym->Object->sName);
}
if(pSym->Object->ObjectType==oArray){
fprintf(fpOutputFile,"\tfor(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
fprintf(fpOutputFile,"\t\t(*EASEA_Line) >> this->%s[EASEA_Ndx];\n", pSym->Object->sName);
}
}
}
fprintf(fp," }\n"); // deserializer
fprintf(fp," %s& operator=(const %s &EASEA_Var) { // Operator=\n",sName,sName); // operator=
fprintf(fp," if (&EASEA_Var == this) return *this;\n");
pSymbolList->reset();
......@@ -325,6 +375,57 @@ void CSymbol::printUserClasses(FILE *fp){
}
}
void CSymbol::serializeIndividual(FILE *fp, char* sCompleteName){
CListItem<CSymbol*> *pSym;
pSymbolList->reset();
char sNewCompleteName[1000];
strcpy(sNewCompleteName, sCompleteName);
while(pSym=pSymbolList->walkToNextItem()){
if((pSym->Object->pType->ObjectType==oUserClass)){
fprintf(fpOutputFile,"\tif(this->%s != NULL){\n",pSym->Object->sName);
fprintf(fpOutputFile,"\t\tEASEA_Line << \"\\a \";\n");
fprintf(fpOutputFile,"\t\tEASEA_Line << this->%s->serializer() << \" \";\n",pSym->Object->sName);
fprintf(fpOutputFile,"\t}\n");
fprintf(fpOutputFile,"\telse\n");
fprintf(fpOutputFile,"\t\tEASEA_Line << \"NULL\" << \" \";\n");
}
else{
if (pSym->Object->ObjectType==oObject){
fprintf(fpOutputFile,"\tEASEA_Line << this->%s << \" \";\n",pSym->Object->sName);
}
if(pSym->Object->ObjectType==oArray){
fprintf(fpOutputFile,"\tfor(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
fprintf(fpOutputFile,"\t\tEASEA_Line << this->%s[EASEA_Ndx] <<\" \";\n", pSym->Object->sName);
}
}
}
}
void CSymbol::deserializeIndividual(FILE *fp, char* sCompleteName){
CListItem<CSymbol*> *pSym;
pSymbolList->reset();
while (pSym=pSymbolList->walkToNextItem()){
if((pSym->Object->pType->ObjectType==oUserClass)){
fprintf(fpOutputFile,"\tEASEA_Line >> line;\n");
fprintf(fpOutputFile,"\tif(strcmp(line.c_str(),\"NULL\")==0)\n");
fprintf(fpOutputFile,"\t\tthis->%s = NULL;\n",pSym->Object->sName);
fprintf(fpOutputFile,"\telse{\n");
fprintf(fpOutputFile,"\t\tthis->%s = new %s;\n",pSym->Object->sName, pSym->Object->pType->sName);
fprintf(fpOutputFile,"\t\tthis->%s->deserializer(&EASEA_Line);\n",pSym->Object->sName);
fprintf(fpOutputFile,"\t}");
}
else{
if (pSym->Object->ObjectType==oObject){
fprintf(fpOutputFile,"\tEASEA_Line >> this->%s;\n",pSym->Object->sName);
}
if(pSym->Object->ObjectType==oArray){
fprintf(fpOutputFile,"\tfor(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
fprintf(fpOutputFile,"\t\tEASEA_Line >> this->%s[EASEA_Ndx];\n", pSym->Object->sName);
}
}
}
}
void CSymbol::printAllSymbols(FILE *fp, char *sCompleteName, EObjectType FatherType, CListItem<CSymbol *> *pSym){
char sNewCompleteName[1000], s[20];
......
......@@ -91,6 +91,8 @@ public:
void printAllSymbols(FILE *f, char *, EObjectType, CListItem<CSymbol *> *pSym);
void printUserClasses(FILE* fp);
void printUC(FILE* fp);
void serializeIndividual(FILE *fp, char* sCompleteName);
void deserializeIndividual(FILE *fp, char* sCompleteName);
};
......
......@@ -12,7 +12,7 @@ libboost: to install it on ubuntu:
2. EASEA source code:
The source code can be obtained either from sourceforge or, for
programmers invoved in the EASEA development, from its GIT repository.
programmers involved in the EASEA development, from its GIT repository.
2.1 Downloading it from sourceforge:
......
......@@ -632,17 +632,19 @@
// Evolution Engine:
Evaluator goal: minimize
Number of generations: 100
Population size: 100
Elite: 4
Number of generations: 5
Population size: 10
Elite: 5
Selection operator: Tournament 7
Offspring size: 50%
Offspring size: 100%
Reduce parents operator: Tournament 4
Surviving parents: 50
Surviving parents: 50%
Reduce offspring operator: Tournament 2
Surviving offspring: 96
Surviving offspring: 96%
Final reduce operator: Tournament 2
Elitism: Weak
Save population:true
\end
/*_________________________________________________________
This file was automatically created by GUIDE v0.1c
User: collet
Date: Tue May 06 10:02:37 CEST 2003
File name: D:\travail\easea\listsort.ez
Target library: EO
Operating System: Windows XP
_________________________________________________________*/
\User declarations:
int SIZE=10;
double pMutPerGene=0.4;
inline void swap(int& a,int& b) {int c=a; a=b; b=c;}
\end
\User functions:
void cross(GenomeClass *pChild, GenomeClass *pParent, int locus){
Element *p, *pChildList, *pParentList;
pChildList=pChild->pList; pParentList=pParent->pList;
for (int i=0;i<SIZE;i++){
if (i>=locus){
for(p=pChild->pList;pParentList->Value!=p->Value;p=p->pNext);
swap(p->Value, pChildList->Value);
}
pChildList=pChildList->pNext;
pParentList=pParentList->pNext;
}
}
\end
\Before everything else function:
if ((argc>1)&&(!strcmp(argv[1],"size"))) SIZE=atoi(argv[2]);
\end
\User classes:
Element { int Value;
Element *pNext; }
GenomeClass { Element *pList;
int Size; }
\end
\After everything else function:
std::cout << (*population) ;
\end
\GenomeClass::initialiser:
Element *pElt;
Genome.Size=0;
Genome.pList=NULL;
for (int i=0;i<SIZE;i++){ // creation of a linked list of SIZE elements
pElt=new Element; // with the decreasing values:
pElt->Value=i+1; // (SIZE, SIZE-1, ... , 3, 2, 1)
pElt->pNext=Genome.pList;
Genome.pList=pElt;
Genome.Size++;
}
\end
\GenomeClass::crossover:
int locus=random(0,SIZE-1);
cross(&child, &parent2, locus);
\end
\GenomeClass::mutator:
int NbMut=0;
Element *p=Genome.pList;
while (p->pNext){
if (tossCoin(pMutPerGene)){ //We swap the current value with the next
swap(p->Value,p->pNext->Value);
NbMut++;
}
p=p->pNext;
}
return NbMut;
\end
\GenomeClass::evaluator:
int i=0,eval=0;
Element *p=Genome.pList;