Commit ff5dc5d5 authored by maitre's avatar maitre

Commit from Fred, Og

parent 8630340f
......@@ -18,9 +18,6 @@ Centre de Math
#define true 1
#define false 0
#define GALIB 1
#define EO 2
#define DREAM 3
#define CUDA 4
#define STD 5
......@@ -43,15 +40,14 @@ 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 char sREPLACEMENT[], sSELECTOR[], sSELECT_PRM[], sRED_PAR[], sRED_PAR_PRM[], sRED_FINAL[], sRED_FINAL_PRM[], sRED_OFF[], sRED_OFF_PRM[], sDISCARD[], sDISCARD_PRM[];
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 bool bELITISM, bVERBOSE;
extern bool bPROP_SEQ;
extern bool bPRINT_STATS, bPLOT_STATS, bGENERATE_CVS_FILE, bGENERATE_GNUPLOT_SCRIPT, bGENERATE_R_SCRIPT;
extern char* nGENOME_NAME;
extern int nPOP_SIZE, nNB_GEN, nNB_ISLANDS, nOFF_SIZE, nSURV_PAR_SIZE, nSURV_OFF_SIZE, nPROBLEM_DIM;
extern float fMUT_PROB, fXOVER_PROB, fREPL_PERC, fMIG_FREQ;
extern int nMIG_CLONE, nNB_MIG, nIMMIG_REPL;
extern char sMIG_SEL[], sMIGRATOR[], sIMMIG_SEL[],sMIG_TARGET_SELECTOR[];
extern int nPOP_SIZE, nNB_GEN, 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;
......
This diff is collapsed.
This diff is collapsed.
......@@ -80,11 +80,11 @@ void CSymbol::print(FILE *fp){
CListItem<CSymbol*> *pSym;
int i;
if (strcmp(sName,"Genome")&&(TARGET!=DREAM)){ // If we are printing a user class other than the genome
if (strcmp(sName,"Genome")){ // If we are printing a user class other than the genome
fprintf(fp,"\nclass %s {\npublic:\n// Default methods for class %s\n",sName,sName); // class header
fprintf(fp,"// Class members \n"); // Now, we must print the class members
/*fprintf(fp,"// Class members \n"); // Now, we must print the class members
pSymbolList->reset();
while (pSym=pSymbolList->walkToNextItem()){
if (pSym->Object->ObjectType==oObject)
......@@ -93,7 +93,7 @@ void CSymbol::print(FILE *fp){
fprintf(fp," %s *%s;\n",pSym->Object->pType->sName,pSym->Object->sName);
if (pSym->Object->ObjectType==oArray)
fprintf(fp," %s %s[%d];\n",pSym->Object->pType->sName,pSym->Object->sName,pSym->Object->nSize/pSym->Object->pType->nSize);
}
}*/
if( TARGET==CUDA ){ // here we we are generating function to copy objects from host memory to gpu's.
......@@ -193,19 +193,7 @@ void CSymbol::print(FILE *fp){
fprintf(fp," bool operator==(%s &EASEA_Var) const { // Operator==\n",sName); // operator==
pSymbolList->reset();
while (pSym=pSymbolList->walkToNextItem()){
if (TARGET==GALIB){
if (pSym->Object->ObjectType==oObject)
fprintf(fp," if (%s!=EASEA_Var.%s) return gaFalse;\n",pSym->Object->sName,pSym->Object->sName);
if (pSym->Object->ObjectType==oArray){
fprintf(fp," {for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
fprintf(fp," if (%s[EASEA_Ndx]!=EASEA_Var.%s[EASEA_Ndx]) return gaFalse;}\n",pSym->Object->sName,pSym->Object->sName);
}
if (pSym->Object->ObjectType==oPointer){
fprintf(fp," if (((%s) && (!EASEA_Var.%s)) || ((!%s) && (EASEA_Var.%s))) return gaFalse;\n",pSym->Object->sName,pSym->Object->sName, pSym->Object->sName,pSym->Object->sName,pSym->Object->sName);
fprintf(fp," if ((%s)&&(%s!=EASEA_Var.%s)) return gaFalse;\n",pSym->Object->sName,pSym->Object->sName,pSym->Object->sName, pSym->Object->pType->sName,pSym->Object->sName,pSym->Object->sName);
}
}
if (TARGET==EO || TARGET==CUDA || TARGET==STD){
if (TARGET==CUDA || TARGET==STD){
if (pSym->Object->ObjectType==oObject)
fprintf(fp," if (%s!=EASEA_Var.%s) return false;\n",pSym->Object->sName,pSym->Object->sName);
if (pSym->Object->ObjectType==oArray){
......@@ -218,8 +206,7 @@ void CSymbol::print(FILE *fp){
}
}
}
if (TARGET==GALIB) fprintf(fp," return gaTrue;\n }\n\n"); // operator==
if (TARGET==EO || TARGET==CUDA || TARGET==STD) fprintf(fp," return true;\n }\n\n"); // operator==
if (TARGET==CUDA || TARGET==STD) fprintf(fp," return true;\n }\n\n"); // operator==
fprintf(fp," bool operator!=(%s &EASEA_Var) const {return !(*this==EASEA_Var);} // operator!=\n\n",sName); // operator!=
......@@ -256,93 +243,6 @@ void CSymbol::print(FILE *fp){
fprintf(fpOutputFile,"%s\n",sString);
}
}
else if (strcmp(sName,"Genome")&&(TARGET==DREAM)){ // If we are printing a user class other than the genome AND we are producing code for DREAM
// We must first create a new file called Class.java
char sFileName[1000];
strcpy(sFileName, sRAW_PROJECT_NAME);
for (i=strlen(sFileName);(sFileName[i]!='/')&&(sFileName[i]!='\\')&&(i!=0);i--);
sFileName[i]=0;
if (i!=0) {sFileName[i]='/';sFileName[i+1]=0;}
if ((i!=0)&&(OPERATING_SYSTEM==WINDOWS)) {sFileName[i]='\\';sFileName[i+1]=0;}
strcat(sFileName,sName); strcat(sFileName,".java");
if (bVERBOSE) printf("Creating %s...\n",sFileName);
fp=fopen(sFileName,"w");
fprintf(fp,"//********************************************\n//\n// %s.java\n//\n// Java file generated by EASEA-DREAM v0.7patch17\n",sName);
fprintf(fp,"//\n//********************************************\n\n");
fprintf(fp,"\nimport drm.agentbase.Logger;\n");
fprintf(fp,"import java.util.Arrays;\nimport java.util.Vector;\nimport java.util.Collection;\nimport java.util.Iterator;\nimport java.io.*;\n\n");
fprintf(fp,"public class %s implements java.io.Serializable { \n",sName); // Now, we must print the class members
fprintf(fp,"// Class members \n"); // Now, we must print the class members
pSymbolList->reset();
while (pSym=pSymbolList->walkToNextItem()){
if ((pSym->Object->ObjectType==oObject)||(pSym->Object->ObjectType==oPointer))
fprintf(fp," %s %s;\n",pSym->Object->pType->sName,pSym->Object->sName);
if (pSym->Object->ObjectType==oArray)
fprintf(fp," public %s[] %s = new %s[%d];\n",pSym->Object->pType->sName,pSym->Object->sName,pSym->Object->pType->sName,pSym->Object->nSize/pSym->Object->pType->nSize);
}
fprintf(fp,"\n %s(){ // Constructor\n",sName); // constructor
pSymbolList->reset(); // in which we initialise all pointers to NULL
while (pSym=pSymbolList->walkToNextItem())
if (pSym->Object->ObjectType==oPointer)
fprintf(fp," %s=null;\n",pSym->Object->sName);
fprintf(fp," }\n\n"); // constructor
fprintf(fp," public %s (%s EZ_%s) { \n// Memberwise Cloning\n",sName,sName,sName); // copy constructor
pSymbolList->reset();
while (pSym=pSymbolList->walkToNextItem()){
if (pSym->Object->ObjectType==oObject)
fprintf(fp," %s=EZ_%s.%s;\n",pSym->Object->sName,sName,pSym->Object->sName);
if (pSym->Object->ObjectType==oArray){
fprintf(fp," {for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
if (pSym->Object->pType->ObjectType==oUserClass) fprintf(fp," %s[EASEA_Ndx]=new %s(EZ_%s.%s[EASEA_Ndx]);}\n",pSym->Object->sName,pSym->Object->pType->sName,sName,pSym->Object->sName);
else fprintf(fp," %s[EASEA_Ndx]=EZ_%s.%s[EASEA_Ndx];}\n",pSym->Object->sName,sName,pSym->Object->sName);
}
if (pSym->Object->ObjectType==oPointer){
fprintf(fp," %s=(EZ_%s.%s!=null ? new %s(EZ_%s.%s) : null);\n",pSym->Object->sName,sName,pSym->Object->sName,pSym->Object->pType->sName,sName,pSym->Object->sName);
}
}
fprintf(fp," }\n\n"); // copy constructor
fprintf(fp," public Object copy() throws CloneNotSupportedException {\n");
fprintf(fp," %s EZ_%s = new %s();\n",sName,sName,sName);
fprintf(fp," // Memberwise copy\n");
pSymbolList->reset();
while (pSym=pSymbolList->walkToNextItem()){
if (pSym->Object->ObjectType==oObject)
fprintf(fp," EZ_%s.%s = %s;\n",sName,pSym->Object->sName,pSym->Object->sName);
if (pSym->Object->ObjectType==oArray){
fprintf(fp," {for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
if (pSym->Object->pType->ObjectType==oUserClass) fprintf(fp," EZ_%s.%s[EASEA_Ndx] = new %s(%s[EASEA_Ndx]);}\n",sName,pSym->Object->sName,pSym->Object->pType->sName,pSym->Object->sName);
else fprintf(fp," EZ_%s.%s[EASEA_Ndx] = %s[EASEA_Ndx];}\n",sName,pSym->Object->sName,pSym->Object->sName);
}
if (pSym->Object->ObjectType==oPointer){
fprintf(fp," EZ_%s.%s = (%s != null ? new %s(%s) : null);\n",sName,pSym->Object->sName,pSym->Object->sName,pSym->Object->pType->sName,pSym->Object->sName);
}
}
fprintf(fp," return EZ_%s;\n }\n\n",sName); // operator<=
fprintf(fp," public String toString() {\n");
fprintf(fp," String EASEA_S = new String();\n");
fprintf(fp," //Default display function\n");
pSymbolList->reset();
while (pSym=pSymbolList->walkToNextItem()){
if (pSym->Object->ObjectType==oObject)
fprintf(fp," EASEA_S = EASEA_S + \"%s:\" + %s + \"\\n\";\n",pSym->Object->sName,pSym->Object->sName);
if (pSym->Object->ObjectType==oArray){
fprintf(fp," {EASEA_S = EASEA_S + \"Array %s : \";\n",pSym->Object->sName);
fprintf(fp," for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)\n",pSym->Object->nSize/pSym->Object->pType->nSize);
fprintf(fp," EASEA_S = EASEA_S + \"[\" + EASEA_Ndx + \"]:\" + %s[EASEA_Ndx] + \"\\t\";}\n EASEA_S = EASEA_S + \"\\n\";\n",pSym->Object->sName);
}
if (pSym->Object->ObjectType==oPointer)
fprintf(fp," if (%s!=null) EASEA_S = EASEA_S + \"%s:\" + %s + \"\\n\";\n",pSym->Object->sName,pSym->Object->sName,pSym->Object->sName);
}
fprintf(fp," return EASEA_S;\n }\n}\n\n"); // Output stream insertion operator
fclose(fp);
}
else {
fprintf(fp,"// Class members \n"); // Now, we must print the class members
pSymbolList->reset();
while (pSym=pSymbolList->walkToNextItem()){
......@@ -350,16 +250,11 @@ void CSymbol::print(FILE *fp){
fprintf(fp," static");
if (pSym->Object->ObjectType==oObject)
fprintf(fp," %s %s;\n",pSym->Object->pType->sName,pSym->Object->sName);
if ((pSym->Object->ObjectType==oPointer)&&(TARGET==DREAM))
fprintf(fp," %s %s;\n",pSym->Object->pType->sName,pSym->Object->sName);
if ((pSym->Object->ObjectType==oPointer)&&(TARGET!=DREAM))
if ((pSym->Object->ObjectType==oPointer))
fprintf(fp," %s *%s;\n",pSym->Object->pType->sName,pSym->Object->sName);
if ((pSym->Object->ObjectType==oArray)&&(TARGET==DREAM))
fprintf(fp," public %s[] %s = new %s[%d];\n",pSym->Object->pType->sName,pSym->Object->sName,pSym->Object->pType->sName,pSym->Object->nSize/pSym->Object->pType->nSize);
if ((pSym->Object->ObjectType==oArray)&&(TARGET!=DREAM))
if ((pSym->Object->ObjectType==oArray))
fprintf(fp," %s %s[%d];\n",pSym->Object->pType->sName,pSym->Object->sName,pSym->Object->nSize/pSym->Object->pType->nSize);
}
}
if (strcmp(sName,"Genome"))
fprintf(fp,"};\n",sName);
......
......@@ -6,32 +6,31 @@
#include "debug.h"
void pickupSTDSelector(char* sSELECTOR, char* sSELECT_PRM, char* sEZ_FILE_NAME, CEASEALexer* EASEALexer){
void pickupSTDSelector(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME, CEASEALexer* EASEALexer){
//DEBUG_PRT("Picking up selector without argument %s",sSELECTOR);
if (!mystricmp(sSELECTOR,"RouletteWheel")){
if (!mystricmp(sSELECTOR,"Roulette")){
if (nMINIMISE==1) {
fprintf(stderr,"\n%s - Error line %d: The RouletteWheel selection scheme cannot be\n selected when \"minimising the fitness\" is the evaluator goal.\n",
fprintf(stderr,"\n%s - Error line %d: The Roulette selection scheme cannot be\n selected when \"minimising the fitness\" is the evaluator goal.\n",
sEZ_FILE_NAME,EASEALexer->yylineno);
exit(1);
}
else sprintf(sSELECTOR,"Roulette");
}
else if (!mystricmp(sSELECTOR,"Tournament")){
sprintf(sSELECTOR,"DetTour");
sprintf(sSELECTOR,"Tournament");
// as there is no selection pressure, we put 2
sprintf(sSELECT_PRM,"(2)");
*fSELECT_PRM=(float)2.0;
}
else if (!mystricmp(sSELECTOR,"StochTrn")) sprintf(sSELECTOR,"StochTour");
else if (!mystricmp(sSELECTOR,"Random")){
sprintf(sSELECTOR,"Random");
if( TARGET==CUDA || TARGET==STD )
sprintf(sSELECT_PRM,"(0)");
*fSELECT_PRM = 0.0;
}
else if (!mystricmp(sSELECTOR,"Ranking")) sprintf(sSELECTOR,"Ranking");
else if (!mystricmp(sSELECTOR,"Sequential")){
sprintf(sSELECTOR,"Sequential");
if( TARGET==CUDA || TARGET==STD) sprintf(sSELECT_PRM,"(0)");
else if (!mystricmp(sSELECTOR,"Deterministic")){
sprintf(sSELECTOR,"Deterministic");
if( TARGET==CUDA || TARGET==STD) *fSELECT_PRM = 0.0;
}
else {
fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist in CUDA/STD.\n",sEZ_FILE_NAME,EASEALexer->yylineno, sSELECTOR);
......@@ -40,14 +39,14 @@ void pickupSTDSelector(char* sSELECTOR, char* sSELECT_PRM, char* sEZ_FILE_NAME,
}
void pickupSTDSelectorArgument(char* sSELECTOR, char* sSELECTOR_PRM, char* sEZ_FILE_NAME, float thirdParam, CEASEALexer* EASEALexer){
void pickupSTDSelectorArgument(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME, float thirdParam, CEASEALexer* EASEALexer){
//DEBUG_PRT("Picking up selector with argument %s %d",sSELECTOR,(int) thirdParam);
if (!mystricmp(sSELECTOR,"Tournament")||!mystricmp(sSELECTOR,"StochTrn")) {
if (thirdParam>=2) {sprintf(sSELECTOR,"DetTour");
sprintf(sSELECTOR_PRM,"(%d)",(int) thirdParam);}
if (thirdParam>=2) {sprintf(sSELECTOR,"Tournament");
*fSELECT_PRM = (float) thirdParam;}
else if ((thirdParam>.5)&&(thirdParam<=1.0)) {
sprintf(sSELECTOR,"StochTour");
sprintf(sSELECTOR_PRM,"(%f)",(float) thirdParam);
*fSELECT_PRM = (float) thirdParam;
}
else {
fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",
......@@ -55,14 +54,13 @@ void pickupSTDSelectorArgument(char* sSELECTOR, char* sSELECTOR_PRM, char* sEZ_F
exit(1);
}
}
else if (!mystricmp(sSELECTOR,"RouletteWheel")) {
else if (!mystricmp(sSELECTOR,"Roulette")) {
sprintf(sSELECTOR,"Roulette");
if (thirdParam<1) {fprintf(stderr,"\n%s - Warning line %d: The parameter of RouletteWheel must be greater than one.\nThe parameter will therefore be ignored.",
if (thirdParam<1) {fprintf(stderr,"\n%s - Warning line %d: The parameter of Roulette must be greater than one.\nThe parameter will therefore be ignored.",
sEZ_FILE_NAME,EASEALexer->yylineno);
nWARNINGS++;
}
else sprintf(sSELECTOR_PRM,"(%f)",(float) thirdParam);
}
else *fSELECT_PRM = (float) thirdParam; }
else if (!mystricmp(sSELECTOR,"Random")) {
sprintf(sSELECTOR,"Random");
fprintf(stderr,"\n%s - Warning line %d: The Uniform selector does not (yet) take any parameter in CUDA/STD.\nThe parameter will therefore be ignored.",
......@@ -74,25 +72,16 @@ void pickupSTDSelectorArgument(char* sSELECTOR, char* sSELECTOR_PRM, char* sEZ_F
if ((thirdParam<=1)||(thirdParam>2)) {
fprintf(stderr,"\n%s - Warning line %d: The parameter of Ranking must be in (1,2].\nThe parameter will default to 2.",sEZ_FILE_NAME,EASEALexer->yylineno);
nWARNINGS++;
sprintf(sSELECTOR_PRM,"(2)");
*fSELECT_PRM = 2.0;
}
else sprintf(sSELECTOR_PRM,"(%f)",(float) thirdParam);
else *fSELECT_PRM = (float) thirdParam;
}
else if (!mystricmp(sSELECTOR,"Sequential")) {
sprintf(sSELECTOR,"Sequential");
else if (!mystricmp(sSELECTOR,"Deterministic")) {
sprintf(sSELECTOR,"Deterministic");
if (thirdParam==0)
if( TARGET==CUDA || TARGET==STD )
sprintf(sSELECT_PRM,"(0)");
else
sprintf(sSELECT_PRM,"(unordered)");
else if (thirdParam==1) sprintf(sSELECTOR_PRM,"(ordered)");
else {
fprintf(stderr,"\n%s - Warning line %d: The parameter of Sequential must be either 0 (unordered) or 1 (ordered).\nThe parameter will default to 1.",
sEZ_FILE_NAME,EASEALexer->yylineno);
nWARNINGS++;
sprintf(sSELECTOR_PRM,"(ordered)");
}
*fSELECT_PRM = 0.0;
}
else {
fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist in CUDA/STD.\n",sEZ_FILE_NAME,EASEALexer->yylineno, sSELECTOR);
......
#include "EaseaLex.h"
void pickupSTDSelector(char* sSELECTOR, char* sSELECT_PRM, char* sEZ_FILE_NAME, CEASEALexer* EASEALexer);
void pickupSTDSelectorArgument(char* sSELECTOR, char* sSELECTOR_PRM, char* sEZ_FILE_NAME, float thirdParam, CEASEALexer* EASEALexer);
void pickupSTDSelector(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME, CEASEALexer* EASEALexer);
void pickupSTDSelectorArgument(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME, float thirdParam, CEASEALexer* EASEALexer);
/*_________________________________________________________
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
\Initialisation 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
\Finalization 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(&child1, &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;
while(p->pNext){
if (p->Value==++i) eval+=10;
if (p->Value<p->pNext->Value) eval+=4;
else eval-=2;
p=p->pNext;
}
if (p->Value==SIZE) eval+=10;
return (eval<0 ? 0 : eval);
\end
\GenomeClass::display:
os << "Size:" << Genome.Size << "\n";
os << "pList:" << *(Genome.pList) << "\n";
os << "This was MY display function !\n";
\end
\At each new generation:
if (NB_GEN-currentGeneration==10) pMutPerGene=0.1;
\end
\Default run parameters:
// Variation operators:
Operators are called: Sequentially
Mutation probability: 1.0
Crossover probability: 0.9
// Evolution Engine:
Evaluator goal: maximize
Number of generations: 34
Evolutionary engine: Custom
Population size: 5
Elite: 5
Fertility: 75
Genitors selector: Tournament 2
Selected genitors: 50
Offspring size: 100%
Reduce parents: Ranking
Surviving parents: 50
Reduce offspring: RouletteWheel
Surviving offspring: 96
Final reduce: Tournament 2
Elitism: Weak
\end
/*_________________________________________________________
Test functions
log normal adaptive mutation
Selection operator: Tournament
__________________________________________________________*/
\User declarations :
#define SIZE 10
#define X_MIN -1.
#define X_MAX 1.
#define ITER 50
#define Abs(x) ((x) < 0 ? -(x) : (x))
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define SIGMA 1. /* mutation parameter */
#define PI 3.141592654
float pMutPerGene=0.1;
#define N_LIM 10
int n = N_LIM;
EvalCounter* d_counter;
struct gpuOptions{
EvalCounter* counter;
};
\end
\User functions:
//fitness function
#include <math.h>
__device__ __host__ inline float Weierstrass(float x[SIZE], int n) // Weierstrass multimidmensionnel h = 0.25
{
float res = 0.;
float val[SIZE];
float b=2.;
float h = 0.25;
for (int i = 0;i<n; i++) {
val[i] = 0.;
for (int k=0;k<ITER;k++)
val[i] += pow(b,-(float)k*h) * sin(pow(b,(float)k)*x[i]);
res += Abs(val[i]);
}
return (res);
}
float gauss()
/* Generates a normally distributed random value with variance 1 and 0 mean.
Algorithm based on "gasdev" from Numerical recipes' pg. 203. */
{
int iset = 0;
float gset = 0.0;
float v1 = 0.0, v2 = 0.0, r = 0.0;
float factor = 0.0;
if (iset) {
iset = 0;
return gset;
}
else {
do {
v1 = (float)random(0.,1.) * 2.0 - 1.0;
v2 = (float)random(0.,1.) * 2.0 - 1.0;
r = v1 * v1 + v2 * v2;
}
while (r > 1.0);
factor = sqrt (-2.0 * log (r) / r);
gset = v1 * factor;
iset = 1;
return (v2 * factor);
}
}
\end
\GenomeClass::display:
/* for( size_t i=0 ; i<SIZE ; i++){ */
/* // cout << Genome.x[i] << ":" << Genome.sigma[i] << "|"; */
/* printf("%.02f:%.02f|",Genome.x[i],Genome.sigma[i]); */
/* } */
\end
\Initialisation function:
std::cout<<"************* n: "<<n<<std::endl;
/* EvalCounter counter; */
/* counter.a = 0; */
/* d_counter = counter.cudaSendToGpuEvalCounter(); */
/* initOpts.counter=d_counter; */
\end
\Finalization function:
{
cout << "finalization function called" << endl;
/* EvalCounter counter; */
/* counter.cudaGetFromGpuEvalCounter(d_counter); */
/* cout << counter << endl; */
}
\end
\User classes :
EvalCounter {
int a;
}
GenomeClass {
float x[SIZE];
float sigma[SIZE]; // auto-adaptative mutation parameter
}
\end
\GenomeClass::initialiser : // "initializer" is also accepted
for(int i=0; i<n; i++ ) {
Genome.x[i] = (float)random(X_MIN,X_MAX);
Genome.sigma[i]=(float)random(0.,0.5);
}
\end
\GenomeClass::crossover :
for (int i=0; i<n; i++)
{
float alpha = (float)random(0.,1.); // barycentric crossover
child1.x[i] = alpha*parent1.x[i] + (1.-alpha)*parent2.x[i];
}
\end
\GenomeClass::mutator : // Must return the number of mutations
int NbMut=0;
float pond = 1./sqrt((float)n);
for (int i=0; i<n; i++)
if (tossCoin(pMutPerGene)){
NbMut++;
Genome.sigma[i] = Genome.sigma[i] * exp(SIGMA*pond*(float)gauss());
Genome.sigma[i] = MIN(0.5,Genome.sigma[0]);
Genome.sigma[i] = MAX(0.,Genome.sigma[0]);
Genome.x[i] += Genome.sigma[i]*(float)gauss();
Genome.x[i] = MIN(X_MAX,Genome.x[i]); // pour eviter les depassements
Genome.x[i] = MAX(X_MIN,Genome.x[i]);
}
return NbMut;