EaseaParse.y 71.1 KB
Newer Older
moh_lo's avatar
moh_lo committed
1 2 3 4 5 6 7 8 9 10 11 12
%{
/****************************************************************************
EaseaLex.y
Parser for the EASEA language (EAsy Specification for Evolutionary Algorithms)

Pierre COLLET (Pierre.Collet@polytechnique.fr)
Ecole Polytechnique
Centre de Mathmatiques Appliques
91128 Palaiseau cedex
****************************************************************************/

#include "Easea.h"
moh_lo's avatar
moh_lo committed
13
#include "debug.h"
maitre's avatar
maitre committed
14
#include "EaseaYTools.h"
moh_lo's avatar
moh_lo committed
15 16 17 18 19

// Globals     
CSymbol *pCURRENT_CLASS;
CSymbol *pCURRENT_TYPE;
CSymbol *pGENOME;
maitre's avatar
maitre committed
20
CSymbol* pCLASSES[128];
moh_lo's avatar
moh_lo committed
21
char sRAW_PROJECT_NAME[1000];
maitre's avatar
maitre committed
22
int nClasses_nb = 0;
moh_lo's avatar
moh_lo committed
23 24 25 26 27
char sPROJECT_NAME[1000];
char sLOWER_CASE_PROJECT_NAME[1000];
char sEZ_FILE_NAME[1000];
char sEO_DIR[1000];
char sEZ_PATH[1000];
28
int TARGET,TARGET_FLAVOR;
moh_lo's avatar
moh_lo committed
29 30 31 32 33 34 35
int OPERATING_SYSTEM;
int nWARNINGS=0;
int nERRORS=0;
char sREPLACEMENT[50];
char sSELECTOR[50];
char sSELECT_PRM[50];
char sRED_PAR[50];
maitre's avatar
maitre committed
36
char sRED_PAR_PRM[50] = {0};
moh_lo's avatar
moh_lo committed
37
char sRED_OFF[50];
maitre's avatar
maitre committed
38
 char sRED_OFF_PRM[50] = {0};
moh_lo's avatar
moh_lo committed
39 40 41 42 43 44 45
char sRED_FINAL[50];
char sRED_FINAL_PRM[50];
char sDISCARD[50];
char sDISCARD_PRM[50];
int nMINIMISE=2;
int nELITE;
bool bELITISM=0;
maitre's avatar
maitre committed
46
bool bVERBOSE=0;
moh_lo's avatar
moh_lo committed
47
int nPOP_SIZE, nOFF_SIZE, nSURV_PAR_SIZE, nSURV_OFF_SIZE;
Frederic's avatar
Frederic committed
48 49
char *nGENOME_NAME;
int nPROBLEM_DIM;
moh_lo's avatar
moh_lo committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
int nNB_GEN;
int nNB_ISLANDS;
bool bPROP_SEQ;
float fMUT_PROB;
float fXOVER_PROB;
float fREPL_PERC=100;
FILE *fpOutputFile, *fpTemplateFile, *fpGenomeFile;//, *fpExplodedGenomeFile;
int nMIG_CLONE, nNB_MIG, nIMMIG_REPL;
char sMIG_SEL[50], sMIGRATOR[50], sIMMIG_SEL[50], sMIG_TARGET_SELECTOR[50];
float fMIG_FREQ;

%}

// include file
%include {
// forward references
class CSymbol;
}

// attribute type
%union {
  CSymbol* pSymbol;
  double dValue;
  int ObjectQualifier;
  int nValue;
  char *szString;
}

// nonterminals
%type <dValue> Expr
%type <ObjectQualifier> Qualifier
%type <pSymbol> BaseType
%type <pSymbol> UserType
%type <pSymbol> Symbol

// tokens
%right '='
%left '+', '-'
%left '*', '/'
%right UMINUS

// keywords

// .ez file tokens
%token CLASSES
%token GENOME
%token USER_CTOR
%token USER_XOVER
%token USER_MUTATOR
%token USER_EVALUATOR                   
100
%token MAKEFILE_OPTION
moh_lo's avatar
moh_lo committed
101 102
%token END_OF_FUNCTION                   
//%token DELETE
maitre's avatar
maitre committed
103
%token <szString> END_METHODS
moh_lo's avatar
moh_lo committed
104 105 106 107 108 109 110 111 112 113
%token <pSymbol> IDENTIFIER
%token <pSymbol> IDENTIFIER2
%token <pSymbol> BOOL
%token <pSymbol> INT
%token <pSymbol> DOUBLE
%token <pSymbol> FLOAT
%token <pSymbol> CHAR
%token <pSymbol> POINTER
%token <dValue> NUMBER
%token <dValue> NUMBER2
maitre's avatar
maitre committed
114
%token METHODS
moh_lo's avatar
moh_lo committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
%token STATIC       
%token NB_GEN       
%token NB_ISLANDS
%token PROP_SEQ
%token MUT_PROB
%token XOVER_PROB                       
%token POP_SIZE
%token SELECTOR
%token RED_PAR
%token RED_OFF
%token RED_FINAL
%token OFFSPRING
%token SURVPAR
%token SURVOFF
%token REPLACEMENT
%token DISCARD
%token MINIMAXI
%token ELITISM
%token ELITE
%token MIG_CLONE
%token MIG_SEL
%token MIGRATOR
%token MIG_FREQ
%token NB_MIG
%token IMMIG_SEL
%token IMMIG_REPL

// include file
%include {
#include "EaseaSym.h"
#include "EaseaLex.h"
}

// parser name and class definition
%name CEASEAParser
{
protected:
  CEASEALexer EASEALexer;       // the lexical analyser
  
public:
  CSymbolTable SymbolTable;    // the symbol table

  int create();
  
  double assign(CSymbol* pIdentifier, double dValue);
  double divide(double dDividend, double dDivisor);
  CSymbol* insert() const;
}

// constructor
{
      CSymbol *pNewBaseType;

      if (TARGET!=DREAM) pNewBaseType=new CSymbol("bool");
      else pNewBaseType=new CSymbol("boolean");
      pNewBaseType->nSize=sizeof(bool);   
      pNewBaseType->ObjectType=oBaseClass;
      SymbolTable.insert(pNewBaseType);

      pNewBaseType=new CSymbol("int");
      pNewBaseType->nSize=sizeof(int);   
      pNewBaseType->ObjectType=oBaseClass;
      SymbolTable.insert(pNewBaseType);

      pNewBaseType=new CSymbol("double");
      pNewBaseType->nSize=sizeof(double);   
      pNewBaseType->ObjectType=oBaseClass;
      SymbolTable.insert(pNewBaseType);

      pNewBaseType=new CSymbol("float");
      pNewBaseType->nSize=sizeof(float);   
      pNewBaseType->ObjectType=oBaseClass;
      SymbolTable.insert(pNewBaseType);

      pNewBaseType=new CSymbol("char");
      pNewBaseType->nSize=sizeof(char);   
      pNewBaseType->ObjectType=oBaseClass;
      SymbolTable.insert(pNewBaseType);

      pNewBaseType=new CSymbol("pointer");
      pNewBaseType->nSize=sizeof(char *);   
      pNewBaseType->ObjectType=oBaseClass;
      SymbolTable.insert(pNewBaseType);
}

%start EASEA
%%

EASEA :  RunParameters GenomeAnalysis;

GenomeAnalysis
    : ClassDeclarationsSection GenomeDeclarationSection {
        if (bVERBOSE) printf("                    _______________________________________\n");
maitre's avatar
maitre committed
208 209
        if ((TARGET==DREAM)&& bVERBOSE) printf ("\nGeneration of the JAVA source files for %s.\n\n",sPROJECT_NAME);
        if ((TARGET!=DREAM)&& bVERBOSE) printf ("\nGeneration of the C++ source file for %s.\n\n",sPROJECT_NAME);
moh_lo's avatar
moh_lo committed
210 211 212 213
      }
      StandardFunctionsAnalysis
    | GenomeDeclarationSection {
        if (bVERBOSE) printf("                    _______________________________________\n");
maitre's avatar
maitre committed
214 215
        if ((TARGET==DREAM)&& bVERBOSE) printf ("\nGeneration of the JAVA source files for %s.\n\n",sPROJECT_NAME);
        if ((TARGET!=DREAM)&& bVERBOSE) printf ("\nGeneration of the C++ source file for %s.\n\n",sPROJECT_NAME);
moh_lo's avatar
moh_lo committed
216 217 218 219 220 221
      }
      StandardFunctionsAnalysis
  ;

ClassDeclarationsSection
  : CLASSES {
maitre's avatar
maitre committed
222
    if (bVERBOSE) printf("Declaration of user classes :\n\n");} 
moh_lo's avatar
moh_lo committed
223 224 225 226 227 228
    ClassDeclarations
  | CLASSES {
      if (bVERBOSE) printf("No user class declaration found other than GenomeClass.\n");} 
  ;
  
ClassDeclarations
maitre's avatar
maitre committed
229 230
: ClassDeclaration 
| ClassDeclarations ClassDeclaration
moh_lo's avatar
moh_lo committed
231 232 233 234 235 236 237
  ;
  
ClassDeclaration
  : Symbol {
      pCURRENT_CLASS=SymbolTable.insert($1);  
      pCURRENT_CLASS->pSymbolList=new CLList<CSymbol *>();
      $1->ObjectType=oUserClass;
maitre's avatar
maitre committed
238 239
      DEBUG_PRT("Yacc Symbol declaration %s %d",$1->sName,$1->nSize);
      pCLASSES[nClasses_nb++] = $1;
moh_lo's avatar
moh_lo committed
240 241 242
    }
  '{' VariablesDeclarations '}' {
      if (bVERBOSE) printf("Class %s declared for %d bytes.\n\n",$1->sName,$1->nSize);
maitre's avatar
maitre committed
243
      DEBUG_PRT("Yacc variable declaration %s %d",$1->sName,$1->nSize);
moh_lo's avatar
moh_lo committed
244 245 246 247 248 249 250 251 252 253 254 255
    }                       
  ;

VariablesDeclarations
  : VariablesDeclaration    
  | VariablesDeclarations VariablesDeclaration    
  ;                             
  
// TypeSize initialisation in a separate rule to avoid reduce/reduce conflict
VariablesDeclaration
  : Qualifier BaseType {pCURRENT_TYPE=$2; pCURRENT_TYPE->ObjectQualifier=$1;} BaseObjects {}
  | Qualifier UserType {pCURRENT_TYPE=$2; pCURRENT_TYPE->ObjectQualifier=$1;} UserObjects {}
maitre's avatar
maitre committed
256 257 258 259 260 261 262 263 264
  | MethodsDeclaration
  ;

MethodsDeclaration
  : METHODS END_METHODS{
    pCURRENT_CLASS->sString = new char[strlen($2) + 1];
    strcpy(pCURRENT_CLASS->sString, $2);      
    if (bVERBOSE) printf("\n    The following methods have been declared:\n\n%s\n\n",pCURRENT_CLASS->sString);
    }
moh_lo's avatar
moh_lo committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
  ;

Qualifier
  : STATIC {$$=1;}  // 1=Static
  | {$$=0;} // 0=Normal
  ;
  
BaseObjects
  : Objects ';'
  | Objects ':' BaseConstructorParameters ';' {}
  ;

UserObjects
  : Objects ';' {}
  | Objects ':' UserConstructorParameters ';' {}
  ;
  
BaseType
  : BOOL
  | INT
  | DOUBLE
  | FLOAT
  | CHAR
  | POINTER
  ;
  
UserType
  : Symbol {  
      CSymbol *pSym=SymbolTable.find($1->sName);
      if (pSym==NULL) {
        fprintf(stderr,"\n%s - Error line %d: Class \"%s\" was not defined.\n",sEZ_FILE_NAME,EASEALexer.yylineno,$1->sName);
        fprintf(stderr,"Only base types (bool, int, float, double, char) or new user classes defined\nwithin the \"User classes\" sections are allowed.\n");
        exit(1);
      }       
      else $$=pSym;
    }
  ;

Objects
  : Object
  | Objects ',' Object
  ;

// Attention : il reste  grer correctement les tableaux de pointeurs
// les indirections multiples et les tableaux  plusieurs dimensions.
// Je sais, il faudrait aussi utiliser un peu de polymorphisme pour les symboles
  
Object
  : Symbol {
//      CSymbol *pSym;
//      pSym=$1;
      if (TARGET==DREAM){                             
        if (pCURRENT_TYPE->ObjectType==oBaseClass){
          $1->nSize=pCURRENT_TYPE->nSize;
          $1->pClass=pCURRENT_CLASS;
          $1->pType=pCURRENT_TYPE;
          $1->ObjectType=oObject;
          $1->ObjectQualifier=pCURRENT_TYPE->ObjectQualifier;
          pCURRENT_CLASS->nSize+=$1->nSize;
          pCURRENT_CLASS->pSymbolList->addFirst((CSymbol *)($1));
          if (bVERBOSE) printf("    %s variable declared (%d bytes)\n",$1->sName,$1->nSize);
        }
        else {
          $1->nSize=sizeof (char *);
          $1->pClass=pCURRENT_CLASS;
          $1->pType=pCURRENT_TYPE;
          $1->ObjectType=oPointer;
          $1->ObjectQualifier=pCURRENT_TYPE->ObjectQualifier;
          pCURRENT_CLASS->nSize+=$1->nSize;
          pCURRENT_CLASS->pSymbolList->addFirst((CSymbol *)($1));
          if (bVERBOSE) printf("    %s pointer declared (%d bytes)\n",$1->sName,$1->nSize);
      } }
      else {
        $1->nSize=pCURRENT_TYPE->nSize;
        $1->pClass=pCURRENT_CLASS;
        $1->pType=pCURRENT_TYPE;
        $1->ObjectType=oObject;
        $1->ObjectQualifier=pCURRENT_TYPE->ObjectQualifier;
        pCURRENT_CLASS->nSize+=$1->nSize;
        pCURRENT_CLASS->pSymbolList->addFirst((CSymbol *)($1));
        if (bVERBOSE) printf("    %s variable declared (%d bytes)\n",$1->sName,$1->nSize);
    } }
  | '*' Symbol {
      $2->nSize=sizeof (char *);
      $2->pClass=pCURRENT_CLASS;
      $2->pType=pCURRENT_TYPE;
      $2->ObjectType=oPointer;
      $2->ObjectQualifier=pCURRENT_TYPE->ObjectQualifier;
      pCURRENT_CLASS->nSize+=$2->nSize;
      pCURRENT_CLASS->pSymbolList->addFirst((CSymbol *)($2));
      if (bVERBOSE) printf("    %s pointer declared (%d bytes)\n",$2->sName,$2->nSize);
    }
  | Symbol  '[' Expr ']' {
358
      if((TARGET_FLAVOR==STD_FLAVOR_CMAES) && nPROBLEM_DIM==0 && strcmp(pCURRENT_CLASS->sName,"Genome")==0) { nGENOME_NAME=$1->sName; nPROBLEM_DIM=(int)$3;}
moh_lo's avatar
moh_lo committed
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
      $1->nSize=pCURRENT_TYPE->nSize*(int)$3;
      $1->pClass=pCURRENT_CLASS;
      $1->pType=pCURRENT_TYPE;
      $1->ObjectType=oArray;
      $1->ObjectQualifier=pCURRENT_TYPE->ObjectQualifier;
      pCURRENT_CLASS->nSize+=$1->nSize;
      pCURRENT_CLASS->pSymbolList->addFirst((CSymbol *)($1));
      if (bVERBOSE) printf("    %s array declared (%d bytes)\n",$1->sName,$1->nSize);
    }
  ;  

BaseConstructorParameters                           
  : BaseConstructorParameter
  | BaseConstructorParameters BaseConstructorParameter
  ;                                                   

BaseConstructorParameter 
  : NUMBER {}
  ;
  
maitre's avatar
maitre committed
379 380 381 382
//Methods
//  : Method
//  | Methods Method
//  ;
moh_lo's avatar
moh_lo committed
383

maitre's avatar
maitre committed
384 385 386
//Method
//  : NUMBER {}
//  ;
moh_lo's avatar
moh_lo committed
387 388 389
  
GenomeDeclarationSection
  : GENOME {
390
    //DEBUG_PRT("Yacc genome decl %s",$1.pSymbol->sName);
moh_lo's avatar
moh_lo committed
391 392 393 394 395 396
      if (bVERBOSE) printf ("\nGenome declaration analysis :\n\n");
      pGENOME=new CSymbol("Genome");
      pCURRENT_CLASS=SymbolTable.insert(pGENOME);  
      pGENOME->pSymbolList=new CLList<CSymbol *>();
      pGENOME->ObjectType=oUserClass;
      pGENOME->ObjectQualifier=0;
maitre's avatar
maitre committed
397
      pGENOME->sString=NULL;
moh_lo's avatar
moh_lo committed
398
    }
maitre's avatar
maitre committed
399
'{' VariablesDeclarations '}' {}
moh_lo's avatar
moh_lo committed
400
  ;
maitre's avatar
maitre committed
401 402 403 404 405 406 407 408 409

//GenomeMethodsDeclaration
//  : GENOME_METHODS GENOME_END_METHODS{
//    pCURRENT_CLASS->sString = new char[strlen($2) + 1];
//    strcpy(pCURRENT_CLASS->sString, $2);      
//    }
//  |
//  ;

moh_lo's avatar
moh_lo committed
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
UserConstructorParameters
  : UserConstructorParameter
  | UserConstructorParameters UserConstructorParameter
  ;

UserConstructorParameter
  : Symbol {}
  ;
                         
Symbol                                        
  : IDENTIFIER {$$=$1;}
  ;                                             
  
StandardFunctionsAnalysis
  : StandardFunctionAnalysis
  | StandardFunctionsAnalysis StandardFunctionAnalysis
  ;
  
StandardFunctionAnalysis
  : USER_CTOR {         
      if (bVERBOSE) printf("Inserting genome initialiser (taken from .ez file).\n");
      switch (TARGET) {
        case GALIB : 
          fprintf(fpOutputFile,"void %sGenome::Initializer(GAGenome& g) {\n",sPROJECT_NAME);
          fprintf(fpOutputFile,"  %sGenome & genome = (%sGenome &)g;\n",sPROJECT_NAME,sPROJECT_NAME);
          break;
        case EO :
          fprintf(fpOutputFile,"%sGenome InitialiserFunction() {\n",sPROJECT_NAME);
          fprintf(fpOutputFile,"  %sGenome *genome = new %sGenome;\n",sPROJECT_NAME,sPROJECT_NAME);
    } }
    END_OF_FUNCTION {                                    
      switch (TARGET) {
        case GALIB : fprintf(fpOutputFile,"genome._evaluated=gaFalse;\n}\n\n");break;
        case EO : fprintf(fpOutputFile,"return *genome;\n}");
    } }
  | USER_XOVER {
      if (bVERBOSE) printf("Inserting user genome crossover (taken from .ez file).\n");
      switch (TARGET) {
        case GALIB : 
          fprintf(fpOutputFile,"int %sGenome::Crossover(const GAGenome& EZ_a, const GAGenome& EZ_b, GAGenome* pEZ_c, GAGenome* pEZ_d) {\n",sPROJECT_NAME);
          fprintf(fpOutputFile,"  %sGenome *pMom = (%sGenome *) &EZ_a;\n",sPROJECT_NAME,sPROJECT_NAME);
          fprintf(fpOutputFile,"  %sGenome *pDad = (%sGenome *) &EZ_b;\n",sPROJECT_NAME,sPROJECT_NAME);
          fprintf(fpOutputFile,"  %sGenome *pSis = (%sGenome *) pEZ_c;\n",sPROJECT_NAME,sPROJECT_NAME);
          fprintf(fpOutputFile,"  %sGenome *pBro = (%sGenome *) pEZ_d;\n",sPROJECT_NAME,sPROJECT_NAME);
          fprintf(fpOutputFile,"  if (pBro) pBro->_evaluated=gaFalse;\n  if (pSis) pSis->_evaluated=gaFalse;\n");
          fprintf(fpOutputFile,"  int EZ_GeneratedChildren=2;\n");
          fprintf(fpOutputFile,"  if (pBro) *pBro=*pDad;\n");
          fprintf(fpOutputFile,"  if (pSis) *pSis=*pMom;\n");
          fprintf(fpOutputFile,"  if (!pBro) {pBro = new %sGenome(*pMom);pBro->_evaluated=pSis->_evaluated=gaFalse;EZ_GeneratedChildren=3;}\n",sPROJECT_NAME);
          fprintf(fpOutputFile,"  if (!pSis) {pSis = new %sGenome(*pDad);pBro->_evaluated=pSis->_evaluated=gaFalse;EZ_GeneratedChildren=4;}\n",sPROJECT_NAME);
          break;
    } }
    END_OF_FUNCTION {
      switch (TARGET) {
        case GALIB : 
          fprintf(fpOutputFile,"  if(EZ_GeneratedChildren==3) {delete pBro; EZ_GeneratedChildren=1;}\n");
          fprintf(fpOutputFile,"  if(EZ_GeneratedChildren==4) {delete pSis; EZ_GeneratedChildren=1;}\n");
          fprintf(fpOutputFile,"return EZ_GeneratedChildren;\n}\n\n");break;
    } }
  | USER_MUTATOR {
      if (bVERBOSE) printf("Inserting user genome mutator (taken from .ez file).\n");
      switch (TARGET) {
        case GALIB : 
          fprintf(fpOutputFile,"int %sGenome::Mutator(GAGenome& g, float PMut) {\n",sPROJECT_NAME);
          fprintf(fpOutputFile,"  if (!GAFlipCoin((float)EZ_MUT_PROB)) return 0;\n");
          fprintf(fpOutputFile,"  %sGenome & genome = (%sGenome &)g;\n",sPROJECT_NAME,sPROJECT_NAME);
          fprintf(fpOutputFile,"  genome._evaluated=gaFalse;\n");
          break;
    } }
    END_OF_FUNCTION {   
      if (TARGET==DREAM) fprintf(fpOutputFile,"  }\n");
481
      if( TARGET!=CUDA && TARGET!=STD) fprintf(fpOutputFile,"}");
moh_lo's avatar
moh_lo committed
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
    }
  | USER_EVALUATOR { 
      if (bVERBOSE) printf("Inserting user genome evaluator (taken from .ez file).\n");
      switch (TARGET) {
        case GALIB : 
          fprintf(fpOutputFile,"float %sGenome::Evaluator(GAGenome & g) {\n",sPROJECT_NAME);
          fprintf(fpOutputFile,"  clock_t EZ_t1;\n",sPROJECT_NAME);
          fprintf(fpOutputFile,"  %sGenome & genome = (%sGenome &)g;\n",sPROJECT_NAME,sPROJECT_NAME);
          fprintf(fpOutputFile,"  EZ_NB_EVALUATIONS++;\n",sPROJECT_NAME);
          fprintf(fpOutputFile,"  const GAPopulation *pPopulation;\n",sPROJECT_NAME);
          fprintf(fpOutputFile,"  if (g.geneticAlgorithm()!=NULL) pPopulation=&(g.geneticAlgorithm()->population());  // to circumvent a bug in GALib\n",sPROJECT_NAME);
          fprintf(fpOutputFile,"  EZ_t1=clock();\n",sPROJECT_NAME);
          break;
        case EO : 
          fprintf(fpOutputFile,"  EZ_NB_EVALUATIONS++;\n",sPROJECT_NAME);
    } }
    END_OF_FUNCTION {
499
      if (TARGET!=EO && TARGET!=CUDA && TARGET!=STD) fprintf(fpOutputFile,"}\n");
moh_lo's avatar
moh_lo committed
500
    }
501 502 503 504
   | MAKEFILE_OPTION END_OF_FUNCTION {
     DEBUG_PRT("User makefile options have been reduced");
     }
   | MAKEFILE_OPTION {}
moh_lo's avatar
moh_lo committed
505 506 507
  ;

RunParameters
maitre's avatar
maitre committed
508 509 510
  : Parameter
  | RunParameters Parameter
  ;           
moh_lo's avatar
moh_lo committed
511 512
  
Parameter
maitre's avatar
maitre committed
513 514 515 516 517 518 519
  :  NB_GEN NUMBER2
      {nNB_GEN=(int)$2;}
  |  NB_ISLANDS NUMBER2
      {nNB_ISLANDS=(int)$2;}
  |  PROP_SEQ IDENTIFIER2{
      if (!mystricmp($2->sName,"proportionally")) bPROP_SEQ=true;
      else if (!mystricmp($2->sName,"sequentially")) bPROP_SEQ=false;
moh_lo's avatar
moh_lo committed
520
      else {
maitre's avatar
maitre committed
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
         fprintf(stderr,"\n%s - Error line %d: Looking for \"Proportionally\" or \"Sequentially\".\n",sEZ_FILE_NAME,EASEALexer.yylineno);
         exit(1);
     } }
  |  MUT_PROB NUMBER2
      {fMUT_PROB=(float)$2;}
  |  XOVER_PROB NUMBER2
      {fXOVER_PROB=(float)$2;}
  |  POP_SIZE NUMBER2
      {nPOP_SIZE=(int)$2;}
  |  SELECTOR IDENTIFIER2{
      strcpy(sSELECTOR, $2->sName);
      switch (TARGET) {
        case DREAM : if (!mystricmp(sSELECTOR,"EPTrn")){
            fprintf(stderr,"\n%s - Error line %d: The EP-Tournament selector is not implemented in DREAM.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
            exit(1);
          }
          else if (!mystricmp(sSELECTOR,"Tournament")) sprintf(sSELECTOR,"TournamentSelector(MAX, 1, 2)");
          else if (!mystricmp(sSELECTOR,"StochTrn")) {
            fprintf(stderr,"\n%s - Warning line %d: The Stochatic Tournament selector needs a parameter in [0.5,1].\nDefault value 1 inserted",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
            sprintf(sSELECTOR,"TournamentSelector(MAX, 1, 2)");
          }
          else if (!mystricmp(sSELECTOR,"RouletteWheel")) sprintf(sSELECTOR,"RouletteWheelSelector(MAX)");
          else if (!mystricmp(sSELECTOR,"Random")) sprintf(sSELECTOR,"RandomSelector()");
          else if (!mystricmp(sSELECTOR,"Sequential")) sprintf(sSELECTOR,"BestNSelector(MAX,%d)",nPOP_SIZE);
          else if (!mystricmp(sSELECTOR,"Ranking")) sprintf(sSELECTOR,"RankingSelector(MAX)");
          else {
            fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sSELECTOR);
            exit(1);
          }
          break;
        case GALIB : if (!mystricmp(sSELECTOR,"Ranking")){
                                  fprintf(stderr,"\n%s - Error line %d: The Ranking selector is not implemented in GALib.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
                                  exit(1);
                                }
                                else if (!mystricmp(sSELECTOR,"Tournament")) sprintf(sSELECTOR,"Tournament");
                                else if (!mystricmp(sSELECTOR,"StochTrn")) sprintf(sSELECTOR,"TournamentSelector(true, 1, 2)");
                                else if (!mystricmp(sSELECTOR,"RouletteWheel")) sprintf(sSELECTOR,"RouletteWheel");
                                else if (!mystricmp(sSELECTOR,"Random")) sprintf(sSELECTOR,"Uniform");
                                else if (!mystricmp(sSELECTOR,"Sequential")) sprintf(sSELECTOR,"Rank");
                                else {
                                  fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sSELECTOR);
                                  exit(1);
                                }
                                break;
565 566
      case CUDA:
      case STD:
maitre's avatar
maitre committed
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
	pickupSTDSelector(sSELECTOR,sSELECT_PRM,sEZ_FILE_NAME,&EASEALexer);
	break;
      case EO : 

	if (!mystricmp(sSELECTOR,"RouletteWheel")){
	  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",sEZ_FILE_NAME,EASEALexer.yylineno);
	    exit(1);
	  }
	  else sprintf(sSELECTOR,"Roulette");
	}
	else if (!mystricmp(sSELECTOR,"Tournament")) sprintf(sSELECTOR,"DetTour");
	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)");
	}
	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 {
	  fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist in EO.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sSELECTOR);
	  exit(1);
	}
moh_lo's avatar
moh_lo committed
595
      }
maitre's avatar
maitre committed
596
    }
maitre's avatar
maitre committed
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
  |  SELECTOR IDENTIFIER2 NUMBER2 {
      sprintf(sSELECTOR, $2->sName);   
      switch (TARGET) {
        case DREAM : if (!mystricmp(sSELECTOR,"EPTrn")){
                                  fprintf(stderr,"\n%s - Error line %d: The EP-Tournament selector is not implemented in DREAM.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
                                  exit(1);
                                }
                                else if (!mystricmp(sSELECTOR,"Tournament")) {
                                  if ($3>=2) sprintf(sSELECTOR,"TournamentSelector(MAX, 1, %d)",(int)$3);
                                  else if (($3>.5)&&($3<=1.0)) sprintf(sSELECTOR,"TournamentSelector(MAX, %f, 2)",(float)$3);
                                  else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
                                }
                                else if (!mystricmp(sSELECTOR,"StochTrn")) {
                                  if (($3>.5)&&($3<=1.0)) sprintf(sSELECTOR,"TournamentSelector(MAX, %f, 2)",(float)$3);
                                  else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
                                }
                                else if (!mystricmp(sSELECTOR,"RouletteWheel")) sprintf(sSELECTOR,"RouletteWheelSelector(MAX)");
                                else if (!mystricmp(sSELECTOR,"Random")) sprintf(sSELECTOR,"RandomSelector()");
                                else if (!mystricmp(sSELECTOR,"Sequential")) sprintf(sSELECTOR,"BestNSelector(MAX,%d)",nPOP_SIZE);
                                else if (!mystricmp(sSELECTOR,"Ranking")) sprintf(sSELECTOR,"RankingSelector(MAX)");
                                else {
                                  fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sSELECTOR);
                                  exit(1);
                                }
                                break;
        case GALIB : fprintf(stderr,"\n%s - Warning line %d: No GALib selector takes parameters yet. The parameter will be ignored.\n",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
                                if (!mystricmp(sSELECTOR,"Ranking")) sprintf(sSELECTOR,"Rank");
                                else if (!mystricmp(sSELECTOR,"Tournament")) sprintf(sSELECTOR,"Tournament");
                                else if (!mystricmp(sSELECTOR,"StochTrn")) sprintf(sSELECTOR,"TournamentSelector(true, 1, 2)");
                                else if (!mystricmp(sSELECTOR,"RouletteWheel")) sprintf(sSELECTOR,"RouletteWheel");
                                else if (!mystricmp(sSELECTOR,"Random")) sprintf(sSELECTOR,"Uniform");
                                else if (!mystricmp(sSELECTOR,"Sequential")){
                                          fprintf(stderr,"\n%s - Error line %d: The Sequential selector does not exist under GALib.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
                                          exit(1);
                                        }
                                else {
                                  fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sSELECTOR);
                                  exit(1);
                                }
                                break;
      case CUDA:
638
      case STD:
maitre's avatar
maitre committed
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
	pickupSTDSelectorArgument(sSELECTOR,sSELECT_PRM,sEZ_FILE_NAME,(float)$3,&EASEALexer);
	break;
      case EO :  

	if (!mystricmp(sSELECTOR,"Tournament")||!mystricmp(sSELECTOR,"StochTrn")) {
	  if ($3>=2) {sprintf(sSELECTOR,"DetTour");sprintf(sSELECT_PRM,"(%d)",(int) $3);}
	  else if (($3>.5)&&($3<=1.0)) {sprintf(sSELECTOR,"StochTour");sprintf(sSELECT_PRM,"(%f)",(float) $3);}
	  else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
	}
	else if (!mystricmp(sSELECTOR,"RouletteWheel")) {
	  sprintf(sSELECTOR,"Roulette");
	  if ($3<1) {fprintf(stderr,"\n%s - Warning line %d: The parameter of RouletteWheel must be greater than one.\nThe parameter will therefore be ignored.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;}
	  else sprintf(sSELECT_PRM,"(%f)",(float) $3);
	}
	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 EO.\nThe parameter will therefore be ignored.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
	}
	else if (!mystricmp(sSELECTOR,"Ranking")) {
	  sprintf(sSELECTOR,"Ranking");
	  if (($3<=1)||($3>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(sSELECT_PRM,"(2)");
	  }
	  else sprintf(sSELECT_PRM,"(%f)",(float) $3);
	}
	else if (!mystricmp(sSELECTOR,"Sequential")) {
	  sprintf(sSELECTOR,"Sequential");
	  if ($3==0)
	    if( TARGET==CUDA || TARGET==STD )
	      sprintf(sSELECT_PRM,"(0)");
	    else
	      sprintf(sSELECT_PRM,"(unordered)");
	  
	  else if ($3==1) sprintf(sSELECT_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(sSELECT_PRM,"(ordered)");
	  }
	}
	else {
	  fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sSELECTOR);
	  exit(1);
	}
      }
    }
maitre's avatar
maitre committed
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
  |  RED_PAR IDENTIFIER2{
        sprintf(sRED_PAR, $2->sName);
        switch (TARGET) {
          case DREAM :
            if (!mystricmp(sRED_PAR,"EPTrn")){
              fprintf(stderr,"\n%s - Error line %d: The EP-Tournament selector is not implemented in DREAM.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
              exit(1);
            }
            else if (!mystricmp(sRED_PAR,"Tournament")) sprintf(sRED_PAR,"TournamentSelector(MAX, 1, 2)");
            else if (!mystricmp(sRED_PAR,"StochTrn")) {
              fprintf(stderr,"\n%s - Warning line %d: The Stochatic Tournament selector needs a parameter in [0.5,1].\nDefault value 1 inserted",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
              sprintf(sRED_PAR,"TournamentSelector(MAX, 1, 2)");
            }
            else if (!mystricmp(sRED_PAR,"RouletteWheel")) sprintf(sRED_PAR,"RouletteWheelSelector(MAX)");
            else if (!mystricmp(sRED_PAR,"Random")) sprintf(sRED_PAR,"RandomSelector()");
            else if (!mystricmp(sRED_PAR,"Sequential")) sprintf(sRED_PAR,"BestNSelector(MAX,%d)",nPOP_SIZE);
            else if (!mystricmp(sRED_PAR,"Ranking")) sprintf(sRED_PAR,"RankingSelector(MAX)");
            else {
              fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_PAR);
              exit(1);
            }
          break;
maitre's avatar
maitre committed
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
	case CUDA:
	case STD:
	  pickupSTDSelector(sRED_PAR,sRED_PAR_PRM,sEZ_FILE_NAME,&EASEALexer);
	  break;
	case EO : if (!mystricmp(sRED_PAR,"RouletteWheel")){
	    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",sEZ_FILE_NAME,EASEALexer.yylineno);
	      exit(1);
	    }
	    else sprintf(sRED_PAR,"Roulette");
	  }
	  else if (!mystricmp(sRED_PAR,"Tournament")) sprintf(sRED_PAR,"DetTour");
	  else if (!mystricmp(sRED_PAR,"StochTrn")) sprintf(sRED_PAR,"StochTour");
	  else if (!mystricmp(sRED_PAR,"Random")) sprintf(sRED_PAR,"Random");
	  else if (!mystricmp(sRED_PAR,"Ranking")) sprintf(sRED_PAR,"Ranking");
	  else if (!mystricmp(sRED_PAR,"Sequential")) sprintf(sRED_PAR,"Sequential");
	  else {
	    fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist in EO.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_PAR);
	    exit(1);
	  }
	}
    }
|  RED_PAR IDENTIFIER2 NUMBER2 {
maitre's avatar
maitre committed
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
        sprintf(sRED_PAR, $2->sName);
        switch (TARGET) {
          case DREAM : if (!mystricmp(sRED_PAR,"EPTrn")){
                                        fprintf(stderr,"\n%s - Error line %d: The EP-Tournament selector is not implemented in DREAM.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
                                        exit(1);
                                      }
                                      else if (!mystricmp(sRED_PAR,"Tournament")) {
                                        if ($3>=2) sprintf(sRED_PAR,"TournamentSelector(MAX, 1, %d)",(int)$3);
                                        else if (($3>.5)&&($3<=1.0)) sprintf(sRED_PAR,"TournamentSelector(MAX, %f, 2)",(float)$3);
                                        else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
                                      }
                                      else if (!mystricmp(sRED_PAR,"StochTrn")) {
                                        if (($3>.5)&&($3<=1.0)) sprintf(sRED_PAR,"TournamentSelector(MAX, %f, 2)",(float)$3);
                                        else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
                                      }
                                      else if (!mystricmp(sRED_PAR,"RouletteWheel")) sprintf(sRED_PAR,"RouletteWheelSelector(MAX)");
                                      else if (!mystricmp(sRED_PAR,"Random")) sprintf(sRED_PAR,"RandomSelector()");
                                      else if (!mystricmp(sRED_PAR,"Sequential")) sprintf(sRED_PAR,"BestNSelector(MAX,%d)",nPOP_SIZE);
                                      else if (!mystricmp(sRED_PAR,"Ranking")) sprintf(sRED_PAR,"RankingSelector(MAX)");
                                      else {
                                        fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_PAR);
                                        exit(1);
                                      }
          break;
	case CUDA :
755
	case STD:
maitre's avatar
maitre committed
756 757 758 759
	  pickupSTDSelectorArgument(sRED_PAR,sRED_PAR_PRM,sEZ_FILE_NAME,(float)$3,&EASEALexer);
	  break;
        case EO :
	  if (!mystricmp(sRED_PAR,"Tournament")||!mystricmp(sRED_PAR,"StochTrn")) {
maitre's avatar
maitre committed
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
                             if ($3>=2) {sprintf(sRED_PAR,"DetTour");sprintf(sRED_PAR_PRM,"(%d)",(int) $3);}
                             else if (($3>.5)&&($3<=1.0)) {sprintf(sRED_PAR,"StochTour");sprintf(sRED_PAR_PRM,"(%f)",(float) $3);}
                             else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
                          }
                          else if (!mystricmp(sRED_PAR,"RouletteWheel")) {
                            sprintf(sRED_PAR,"Roulette");
                            if ($3<1) {fprintf(stderr,"\n%s - Warning line %d: The parameter of RouletteWheel must be greater than one.\nThe parameter will therefore be ignored.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;}
                            else sprintf(sRED_PAR_PRM,"(%f)",(float) $3);
                          }
                          else if (!mystricmp(sRED_PAR,"Random")) {
                            sprintf(sRED_PAR,"Random");
                            fprintf(stderr,"\n%s - Warning line %d: The Uniform selector does not (yet) take any parameter in EO.\nThe parameter will therefore be ignored.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
                          }
                          else if (!mystricmp(sRED_PAR,"Ranking")) {
                            sprintf(sRED_PAR,"Ranking");
                            if (($3<=1)||($3>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(sRED_PAR_PRM,"(2)");
                            }
                            else sprintf(sRED_PAR_PRM,"(%f)",(float) $3);
                          }
                          else if (!mystricmp(sRED_PAR,"Sequential")) {
                            sprintf(sRED_PAR,"Sequential");
783 784 785 786 787 788 789
			    
                            if ($3==0)
			      if( TARGET==CUDA || TARGET==STD )
				sprintf(sSELECT_PRM,"(0)");
			      else
				sprintf(sSELECT_PRM,"(unordered)");
			    else if ($3==1) sprintf(sRED_PAR_PRM,"(ordered)");
maitre's avatar
maitre committed
790 791 792 793 794 795 796 797 798
                            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(sRED_PAR_PRM,"(ordered)");
                            }
                          }
                          else {
                            fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_PAR);
                            exit(1);
                          }
maitre's avatar
maitre committed
799 800
	}
    }
maitre's avatar
maitre committed
801 802 803
  |  RED_OFF IDENTIFIER2{
      sprintf(sRED_OFF, $2->sName);
      switch (TARGET) {
maitre's avatar
maitre committed
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
      case DREAM : if (!mystricmp(sRED_OFF,"EPTrn")){
	  fprintf(stderr,"\n%s - Error line %d: The EP-Tournament selector is not implemented in DREAM.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
	  exit(1);
	}
	else if (!mystricmp(sRED_OFF,"Tournament")) sprintf(sRED_OFF,"TournamentSelector(MAX, 1, 2)");
	else if (!mystricmp(sRED_OFF,"StochTrn")) {
	  fprintf(stderr,"\n%s - Warning line %d: The Stochatic Tournament selector needs a parameter in [0.5,1].\nDefault value 1 inserted",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
	  sprintf(sRED_OFF,"TournamentSelector(MAX, 1, 2)");
	}
	else if (!mystricmp(sRED_OFF,"RouletteWheel")) sprintf(sRED_OFF,"RouletteWheelSelector(MAX)");
	else if (!mystricmp(sRED_OFF,"Random")) sprintf(sRED_OFF,"RandomSelector()");
	else if (!mystricmp(sRED_OFF,"Sequential")) sprintf(sRED_OFF,"BestNSelector(MAX,%d)",nPOP_SIZE);
	else if (!mystricmp(sRED_OFF,"Ranking")) sprintf(sRED_OFF,"RankingSelector(MAX)");
	else {
	  fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_OFF);
	  exit(1);
	}
	break;
      case EO : if (!mystricmp(sRED_OFF,"RouletteWheel")){
	  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",sEZ_FILE_NAME,EASEALexer.yylineno);
	    exit(1);
	  }
	  else sprintf(sRED_OFF,"Roulette");
	}
	else if (!mystricmp(sRED_OFF,"Tournament")) sprintf(sRED_OFF,"DetTour");
	else if (!mystricmp(sRED_OFF,"StochTrn")) sprintf(sRED_OFF,"StochTour");
	else if (!mystricmp(sRED_OFF,"Random")) sprintf(sRED_OFF,"Random");
	else if (!mystricmp(sRED_OFF,"Ranking")) sprintf(sRED_OFF,"Ranking");
	else if (!mystricmp(sRED_OFF,"Sequential")) sprintf(sRED_OFF,"Sequential");
	else {
	  fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist in EO.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_OFF);
	  exit(1);
	}
	break;
      case STD:
      case CUDA:
	pickupSTDSelector(sRED_OFF,sRED_OFF_PRM,sEZ_FILE_NAME,&EASEALexer);
	break;
      }
    }
maitre's avatar
maitre committed
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
  |  RED_OFF IDENTIFIER2 NUMBER2 {
        strcpy(sRED_OFF, $2->sName);
        switch (TARGET) {
          case DREAM : if (!mystricmp(sRED_OFF,"EPTrn")){
                                        fprintf(stderr,"\n%s - Error line %d: The EP-Tournament selector is not implemented in DREAM.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
                                        exit(1);
                                      }
                                      else if (!mystricmp(sRED_OFF,"Tournament")) {
                                        if ($3>=2) sprintf(sRED_OFF,"TournamentSelector(MAX, 1, %d)",(int)$3);
                                        else if (($3>.5)&&($3<=1.0)) sprintf(sRED_OFF,"TournamentSelector(MAX, %f, 2)",(float)$3);
                                        else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
                                      }
                                      else if (!mystricmp(sRED_OFF,"StochTrn")) {
                                        if (($3>.5)&&($3<=1.0)) sprintf(sRED_OFF,"TournamentSelector(MAX, %f, 2)",(float)$3);
                                        else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
                                      }
moh_lo's avatar
moh_lo committed
861 862 863 864 865 866 867 868
                                      else if (!mystricmp(sRED_OFF,"RouletteWheel")) sprintf(sRED_OFF,"RouletteWheelSelector(MAX)");
                                      else if (!mystricmp(sRED_OFF,"Random")) sprintf(sRED_OFF,"RandomSelector()");
                                      else if (!mystricmp(sRED_OFF,"Sequential")) sprintf(sRED_OFF,"BestNSelector(MAX,%d)",nPOP_SIZE);
                                      else if (!mystricmp(sRED_OFF,"Ranking")) sprintf(sRED_OFF,"RankingSelector(MAX)");
                                      else {
                                        fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_OFF);
                                        exit(1);
                                      }
maitre's avatar
maitre committed
869
	    break;
moh_lo's avatar
moh_lo committed
870
        case EO :  if (!mystricmp(sRED_OFF,"Tournament")||!mystricmp(sRED_OFF,"StochTrn")) {
maitre's avatar
maitre committed
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912
	      if ($3>=2) {sprintf(sRED_OFF,"DetTour");sprintf(sRED_OFF_PRM,"(%d)",(int) $3);}
	      else if (($3>.5)&&($3<=1.0)) {sprintf(sRED_OFF,"StochTour");sprintf(sRED_OFF_PRM,"(%f)",(float) $3);}
	      else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
	    }
	    else if (!mystricmp(sRED_OFF,"RouletteWheel")) {
	      sprintf(sRED_OFF,"Roulette");
	      if ($3<1) {fprintf(stderr,"\n%s - Warning line %d: The parameter of RouletteWheel must be greater than one.\nThe parameter will therefore be ignored.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;}
	      else sprintf(sRED_OFF_PRM,"(%f)",(float) $3);
	    }
	    else if (!mystricmp(sRED_OFF,"Random")) {
	      sprintf(sRED_OFF,"Random");
	      fprintf(stderr,"\n%s - Warning line %d: The Uniform selector does not (yet) take any parameter in EO.\nThe parameter will therefore be ignored.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
	    }
	    else if (!mystricmp(sRED_OFF,"Ranking")) {
	      sprintf(sRED_OFF,"Ranking");
	      if (($3<=1)||($3>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(sRED_OFF_PRM,"(2)");
	      }
	      else sprintf(sRED_OFF_PRM,"(%f)",(float) $3);
	    }
	    else if (!mystricmp(sRED_OFF,"Sequential")) {
	      sprintf(sRED_OFF,"Sequential");
	      
	      if ($3==0) if( TARGET==CUDA || TARGET==STD )
			   sprintf(sSELECT_PRM,"(0)");
		else
		  sprintf(sRED_OFF_PRM,"(unordered)");
	      else if ($3==1) sprintf(sRED_OFF_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(sRED_OFF_PRM,"(ordered)");
	      }
	    }
	    else {
	      fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_OFF);
	      exit(1);
	    }
	  break;
	case STD:
	case CUDA:
	  pickupSTDSelectorArgument(sRED_OFF,sRED_OFF_PRM,sEZ_FILE_NAME,$3,&EASEALexer);
moh_lo's avatar
moh_lo committed
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
       }}
  |  RED_FINAL IDENTIFIER2{
        strcpy(sRED_FINAL, $2->sName);
        switch (TARGET) {
          case DREAM : if (!mystricmp(sRED_FINAL,"EPTrn")){
                                        fprintf(stderr,"\n%s - Error line %d: The EP-Tournament selector is not implemented in DREAM.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
                                        exit(1);
                                      }
                                      else if (!mystricmp(sRED_FINAL,"Tournament")) sprintf(sRED_FINAL,"TournamentSelector(false, 1, 2)");
                                      else if (!mystricmp(sRED_FINAL,"StochTrn")) {
                                        fprintf(stderr,"\n%s - Warning line %d: The Stochatic Tournament selector needs a parameter in [0.5,1].\nDefault value 1 inserted",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
                                        sprintf(sRED_FINAL,"TournamentSelector(false, 1, 2)");
                                      }
                                      else if (!mystricmp(sRED_FINAL,"RouletteWheel")) sprintf(sRED_FINAL,"RouletteWheelSelector(%s)",nMINIMISE?"true":"false");
                                      else if (!mystricmp(sRED_FINAL,"Random")) sprintf(sRED_FINAL,"RandomSelector()");
                                      else if (!mystricmp(sRED_FINAL,"Sequential")) sprintf(sRED_FINAL,"BestNSelector(%s,%d)",nMINIMISE?"true":"false",nPOP_SIZE);
                                      else if (!mystricmp(sRED_FINAL,"Ranking")) sprintf(sRED_FINAL,"RankingSelector(%s)",nMINIMISE?"true":"false");
                                      else {
                                        fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_FINAL);
                                        exit(1);
                                      }
            break;
935 936
	case CUDA:
	case STD:
maitre's avatar
maitre committed
937 938 939
	  pickupSTDSelector(sRED_FINAL,sRED_FINAL_PRM,sEZ_FILE_NAME,&EASEALexer);
	  break;
	case EO : if (!mystricmp(sRED_FINAL,"RouletteWheel")){
moh_lo's avatar
moh_lo committed
940 941 942 943 944 945 946 947
                              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",sEZ_FILE_NAME,EASEALexer.yylineno);
                                exit(1);
                              }
                              else sprintf(sRED_FINAL,"Roulette");
                            }
                            else if (!mystricmp(sRED_FINAL,"Tournament")) sprintf(sRED_FINAL,"DetTour");
                            else if (!mystricmp(sRED_FINAL,"StochTrn")) sprintf(sRED_FINAL,"StochTour");
948 949 950 951 952
                            else if (!mystricmp(sRED_FINAL,"Random")){
			      sprintf(sRED_FINAL,"Random");
			      if( TARGET==CUDA || TARGET==STD ) 			     
				sprintf(sRED_FINAL_PRM,"(0)");      
			    }	    
moh_lo's avatar
moh_lo committed
953
                            else if (!mystricmp(sRED_FINAL,"Ranking")) sprintf(sRED_FINAL,"Ranking");
954 955 956 957
                            else if (!mystricmp(sRED_FINAL,"Sequential")) {
			      sprintf(sRED_FINAL,"Sequential");
			      sprintf(sRED_FINAL_PRM,"(2)");      
			    }
moh_lo's avatar
moh_lo committed
958 959 960 961 962
                            else {
                              fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist in EO.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_FINAL);
                              exit(1);
                            }
       }}
maitre's avatar
maitre committed
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988
  |  RED_FINAL IDENTIFIER2 NUMBER2 {
        strcpy(sRED_FINAL, $2->sName);
        switch (TARGET) {
          case DREAM : if (!mystricmp(sRED_FINAL,"EPTrn")){
                                        fprintf(stderr,"\n%s - Error line %d: The EP-Tournament selector is not implemented in DREAM.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
                                        exit(1);
                                      }
                                      else if (!mystricmp(sRED_FINAL,"Tournament")) {
                                        if ($3>=2) sprintf(sRED_FINAL,"TournamentSelector(%s, 1, %d)",(nMINIMISE?"true":"false"),(int)$3);
                                        else if (($3>.5)&&($3<=1.0)) sprintf(sRED_FINAL,"TournamentSelector(%s, %f, 2)",(nMINIMISE?"true":"false"),(float)$3);
                                        else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
                                      }
                                      else if (!mystricmp(sRED_FINAL,"StochTrn")) {
                                        if (($3>.5)&&($3<=1.0)) sprintf(sRED_FINAL,"TournamentSelector(%s, %f, 2)",(nMINIMISE?"true":"false"),(float)$3);
                                        else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
                                      }
                                      else if (!mystricmp(sRED_FINAL,"RouletteWheel")) sprintf(sRED_FINAL,"RouletteWheelSelector(%s)",nMINIMISE?"true":"false");
                                      else if (!mystricmp(sRED_FINAL,"Random")) sprintf(sRED_FINAL,"RandomSelector()");
                                      else if (!mystricmp(sRED_FINAL,"Sequential")) sprintf(sRED_FINAL,"BestNSelector(%s,%d)",nMINIMISE?"true":"false",nPOP_SIZE);
                                      else if (!mystricmp(sRED_FINAL,"Ranking")) sprintf(sRED_FINAL,"RankingSelector(%s)",nMINIMISE?"true":"false");
                                      else {
                                        fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_OFF);
                                        exit(1);
                                      }
          break;
	case CUDA :
989
	case STD:
maitre's avatar
maitre committed
990 991
	  pickupSTDSelectorArgument(sRED_FINAL,sRED_FINAL_PRM,sEZ_FILE_NAME,$3,&EASEALexer);
	  break;
maitre's avatar
maitre committed
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
        case EO :  
 	  if (!mystricmp(sRED_FINAL,"Tournament")||!mystricmp(sRED_FINAL,"StochTrn")) {
	    if ($3>=2) {
	      sprintf(sRED_FINAL,"DetTour");sprintf(sRED_FINAL_PRM,"(%d)",(int) $3);
	      DEBUG_PRT("tournament parameter is %s",sRED_FINAL_PRM);
	    }
	    else if (($3>.5)&&($3<=1.0)) {sprintf(sRED_FINAL,"StochTour");sprintf(sRED_FINAL_PRM,"(%f)",(float) $3);}
	    else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
	  }
	  else if (!mystricmp(sRED_FINAL,"RouletteWheel")) {
	    sprintf(sRED_FINAL,"Roulette");
	    if ($3<1) {fprintf(stderr,"\n%s - Warning line %d: The parameter of RouletteWheel must be greater than one.\nThe parameter will therefore be ignored.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;}
	    else sprintf(sRED_FINAL_PRM,"(%f)",(float) $3);
	  }
	  else if (!mystricmp(sRED_FINAL,"Random")) {
	    sprintf(sRED_FINAL,"Random");
	    fprintf(stderr,"\n%s - Warning line %d: The Uniform selector does not (yet) take any parameter in EO.\nThe parameter will therefore be ignored.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
	  }
	  else if (!mystricmp(sRED_FINAL,"Ranking")) {
	    sprintf(sRED_FINAL,"Ranking");
	    if (($3<=1)||($3>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(sRED_FINAL_PRM,"(2)");
	    }
	    else sprintf(sRED_FINAL_PRM,"(%f)",(float) $3);
	  }
	  else if (!mystricmp(sRED_FINAL,"Sequential")) {
	    sprintf(sRED_FINAL,"Sequential");
1020 1021 1022 1023 1024
	    if ($3==0) 
	      if( TARGET==CUDA || TARGET==STD )
		sprintf(sRED_FINAL_PRM,"(0)");
	      else
		sprintf(sRED_FINAL_PRM,"(unordered)");
maitre's avatar
maitre committed
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
	    else if ($3==1) sprintf(sRED_FINAL_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(sRED_FINAL_PRM,"(ordered)");
	    }
	  }
	  else {
	    fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_FINAL);
	    exit(1);
	  }
	}}
  |  OFFSPRING NUMBER2 {nOFF_SIZE=(int)$2;}
  |  OFFSPRING NUMBER2 '%' {nOFF_SIZE=(int)($2*nPOP_SIZE/100);}
  |  SURVPAR NUMBER2 {nSURV_PAR_SIZE=(int)$2;}
  |  SURVPAR NUMBER2 '%' {nSURV_PAR_SIZE=(int)($2*nPOP_SIZE/100);}
  |  SURVOFF NUMBER2 {nSURV_OFF_SIZE=(int)$2;}
  |  SURVOFF NUMBER2 '%' {nSURV_OFF_SIZE=(int)($2*nPOP_SIZE/100);}
  |  REPLACEMENT IDENTIFIER2 {                                       
moh_lo's avatar
moh_lo committed
1043
  // Generational
maitre's avatar
maitre committed
1044
      if (!mystricmp($2->sName,"Generational")){
moh_lo's avatar
moh_lo committed
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
        if ((nOFF_SIZE+fREPL_PERC) && ((nOFF_SIZE!=nPOP_SIZE)||(fREPL_PERC!=100))){
          fprintf(stderr,"\n%s - Warning line %d: The \"Generational\" replacement strategy\nreplaces the whole population.\n",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
          fprintf(stderr,"COMPILATION WILL THEREFORE CONTINUE WITH AN OFFSPRING POPULATION SIZE OF %d !\n",nPOP_SIZE);
          if (TARGET==GALIB) fREPL_PERC=0; else fREPL_PERC=100;
        }
        switch (TARGET) {
          case GALIB : strcpy(sREPLACEMENT, "Simple"); break;
          case EO : strcpy(sREPLACEMENT, "Generational");
      }}
// Steadystate
      else if (!mystricmp($2->sName,"SteadyState"))
        switch (TARGET) {
          case GALIB : strcpy(sREPLACEMENT, "Incremental");
                                  fREPL_PERC=0;
                                  break;
          case EO : strcpy(sREPLACEMENT, "SSGA");
        }
// Plus
      else if (!mystricmp($2->sName,"ESPlus"))
        switch (TARGET) {
          case GALIB : strcpy(sREPLACEMENT, "SteadyState"); break;
          case EO : strcpy(sREPLACEMENT, "Plus");
        }
// Comma
      else if (!mystricmp($2->sName,"ESComma"))
        switch (TARGET) {
          case GALIB : fprintf(stderr,"\n%s - Error line %d: The Comma replacement strategie is not yet available in EASEA-GALib.\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);
          case EO : strcpy(sREPLACEMENT, "Comma");
        }  
      else if (!mystricmp($2->sName,"Custom"))
        switch (TARGET) {
          case GALIB : fprintf(stderr,"\n%s - Error line %d: The Custom replacement strategie is not yet available in EASEA-GALib.\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);
          case EO : strcpy(sREPLACEMENT, "Custom");
        }  
      else {
         fprintf(stderr,"\n%s - Error line %d: The %s replacement strategy does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, $2->sName);
         exit(1);
     }}
  |  DISCARD IDENTIFIER2 {
      strcpy(sDISCARD, $2->sName);
      switch (TARGET) {
        case GALIB : if (!mystricmp(sDISCARD,"Worst")) {
                                  strcpy(sDISCARD,"WORST"); break;
                                }
                                else if (!mystricmp(sDISCARD,"Parent")) {
                                  if (mystricmp(sREPLACEMENT,"Incremental")){  
                                    fprintf(stderr,"\n%s - Warning line %d: GALib only takes \"%s\" with a steady-state replacement strategy. Default operator \"Worst\" is selected.\n",sEZ_FILE_NAME,EASEALexer.yylineno,sDISCARD);nWARNINGS++;
                                    strcpy(sDISCARD,"WORST"); break;
                                  }
                                  strcpy(sDISCARD,"PARENT");
                                  break;
                                }
                                else if (!mystricmp(sDISCARD,"Random")) {
                                  if (mystricmp(sREPLACEMENT,"Incremental")){  
                                    fprintf(stderr,"\n%s - Warning line %d: GALib only takes \"%s\" with a steady-state replacement strategy. Default operator \"Worst\" is selected.\n",sEZ_FILE_NAME,EASEALexer.yylineno,sDISCARD);nWARNINGS++;
                                    strcpy(sDISCARD,"WORST"); break;
                                  }
                                  strcpy(sDISCARD,"RANDOM"); break;
                                }
                                else if (!mystricmp(sDISCARD,"Best")) {
                                  if (mystricmp(sREPLACEMENT,"Incremental")){  
                                    fprintf(stderr,"\n%s - Warning line %d: GALib only takes \"%s\" with a steady-state replacement strategy. Default operator \"Worst\" is selected.\n",sEZ_FILE_NAME,EASEALexer.yylineno,sDISCARD);nWARNINGS++;
                                    strcpy(sDISCARD,"WORST"); break;
                                  }
                                  strcpy(sDISCARD,"BEST"); break;
                                }
                                else {
                                  fprintf(stderr,"\n%s - Warning line %d: GALib does not take \"%s\" as a discarding\noperator. Default operator \"Worst\" is selected.\n",sEZ_FILE_NAME,EASEALexer.yylineno,sDISCARD);nWARNINGS++;
                                  strcpy(sDISCARD,"WORST"); break;
                                }
          break;
        case EO : if (!mystricmp(sREPLACEMENT,"SSGA")){
                           if (!mystricmp(sDISCARD,"Tournament")) {
                              strcat(sREPLACEMENT,"DetTournament");
                              strcpy(sDISCARD_PRM,"(2)");
                            }
                           else if (!mystricmp(sDISCARD,"Worst")) {
                              strcat(sREPLACEMENT,"Worse");
                            }
                           else {
                              fprintf(stderr,"\n%s - Warning line %d: EO does not take \"%s\" as a discarding\noperator. Default operator \"Worst\" is selected.\n",sEZ_FILE_NAME,EASEALexer.yylineno,sDISCARD);nWARNINGS++;
                              strcat(sREPLACEMENT,"Worse"); break;
                            }
       }}}
  |  DISCARD IDENTIFIER2 '(' NUMBER2 ')' {
      strcpy(sDISCARD, $2->sName);
      switch (TARGET) {
        case GALIB : fprintf(stderr,"\n%s - Warning line %d: No GALib selector takes parameters yet. The parameter will be ignored.\n",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
                                if (!mystricmp(sDISCARD,"Worst")) {
                                  strcpy(sDISCARD,"WORST"); break;
                                }
                                else if (!mystricmp(sDISCARD,"Parent")) {
                                  if (mystricmp(sREPLACEMENT,"Incremental")){  
                                    fprintf(stderr,"\n%s - Warning line %d: GALib only takes \"%s\" with a steady-state replacement strategy. Default operator \"Worst\" is selected.\n",sEZ_FILE_NAME,EASEALexer.yylineno,sDISCARD);nWARNINGS++;
                                    strcpy(sDISCARD,"WORST"); break;
                                  }
                                  strcpy(sDISCARD,"PARENT");
                                  break;
                                }
                                else if (!mystricmp(sDISCARD,"Random")) {
                                  if (mystricmp(sREPLACEMENT,"Incremental")){  
                                    fprintf(stderr,"\n%s - Warning line %d: GALib only takes \"%s\" with a steady-state replacement strategy. Default operator \"Worst\" is selected.\n",sEZ_FILE_NAME,EASEALexer.yylineno,sDISCARD);nWARNINGS++;
                                    strcpy(sDISCARD,"WORST"); break;
                                  }
                                  strcpy(sDISCARD,"RANDOM"); break;
                                }
                                else if (!mystricmp(sDISCARD,"Best")) {
                                  if (mystricmp(sREPLACEMENT,"Incremental")){  
                                    fprintf(stderr,"\n%s - Warning line %d: GALib only takes \"%s\" with a steady-state replacement strategy. Default operator \"Worst\" is selected.\n",sEZ_FILE_NAME,EASEALexer.yylineno,sDISCARD);nWARNINGS++;
                                    strcpy(sDISCARD,"WORST"); break;
                                  }
                                  strcpy(sDISCARD,"BEST"); break;
                                }
                                else {
                                  fprintf(stderr,"\n%s - Warning line %d: GALib does not take \"%s\" as a discarding\noperator. Default operator \"Worst\" is selected.\n",sEZ_FILE_NAME,EASEALexer.yylineno,sDISCARD);nWARNINGS++;
                                  strcpy(sDISCARD,"WORST"); break;
                                }
          break;
        case EO : if (!mystricmp(sDISCARD,"Tournament")) {
                             if ($4>=2) {strcpy(sDISCARD,"DetTournament");sprintf(sDISCARD_PRM,"(%d)",(int) $4);}
                             else if (($4>.5)&&($4<=1.0)) {strcpy(sDISCARD,"StochTournament");sprintf(sDISCARD_PRM,"(%f)",(float) $4);}
                             else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
                          }
                          else if (!mystricmp(sDISCARD,"Worst")) {
                             strcpy(sDISCARD,"Worse");
                             fprintf(stderr,"\n%s - Warning line %d: The Worst discarding operator does not take parameters. The parameter will be ignored.\n",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
                          }
      }}
  |  MINIMAXI IDENTIFIER2 {
      if ((!mystricmp($2->sName,"maximise")) || (!mystricmp($2->sName,"maximize"))) nMINIMISE=0;
      else if ((!mystricmp($2->sName,"minimise")) || (!mystricmp($2->sName,"minimize"))) nMINIMISE=1;
      else {
         fprintf(stderr,"\n%s - Error line %d: The evaluator goal default parameter can only take\n",sEZ_FILE_NAME,EASEALexer.yylineno);
         fprintf(stderr,"two values : maximi[sz]e or minimi[sz]e.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
         exit(1);
       }
      }
  |  ELITE NUMBER2 {
        if ($2!=0) bELITISM=1;
        else bELITISM=0;
        nELITE=(int)$2;
        }
  |  ELITE NUMBER2 '%' {
        if ($2!=0) bELITISM=1;
        else bELITISM=0;
        nELITE=(int)$2*nPOP_SIZE/100;
        }
  |  ELITISM IDENTIFIER2{
      if (!mystricmp($2->sName,"weak")) bELITISM=0;
      else if (!mystricmp($2->sName,"strong")) bELITISM=1;
      else {
maitre's avatar
maitre committed
1196
         fprintf(stderr,"\n%s - Warning line %d: Elitism must be \"Strong\" or \"Weak\".\nDefault value \"Strong\" inserted.\n.",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
moh_lo's avatar
moh_lo committed
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
         bELITISM=1;
       }}
  |  MIG_CLONE IDENTIFIER2{
       if (!mystricmp($2->sName,"clone")) nMIG_CLONE=1;
      else if (!mystricmp($2->sName,"move")) nMIG_CLONE=0;
      else {
         fprintf(stderr,"\n%s - Error line %d: Looking for \"Move\" or \"Clone\".\n",sEZ_FILE_NAME,EASEALexer.yylineno);
         exit(1);
     } }
  |  MIG_SEL IDENTIFIER2{
        strcpy(sMIG_SEL, $2->sName);
        if (!mystricmp(sMIG_SEL,"EPTrn")){
          fprintf(stderr,"\n%s - Error line %d: The EP-Tournament selector is not implemented in DREAM.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
          exit(1);
        }
        else if (!mystricmp(sMIG_SEL,"Tournament")) sprintf(sMIG_SEL,"TournamentSelector(false, 1, 2)");
        else if (!mystricmp(sMIG_SEL,"StochTrn")) {
maitre's avatar
maitre committed
1214
          fprintf(stderr,"\n%s - Warning line %d: The Stochatic Tournament selector needs a parameter in [0.5,1].\nDefault value 1 inserted.\n",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
moh_lo's avatar
moh_lo committed
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234
          sprintf(sMIG_SEL,"TournamentSelector(false, 1, 2)");
        }
        else if (!mystricmp(sMIG_SEL,"RouletteWheel")) sprintf(sMIG_SEL,"RouletteWheelSelector(%s)",nMINIMISE?"false":"true");
        else if (!mystricmp(sMIG_SEL,"Random")) sprintf(sMIG_SEL,"RandomSelector()");
        else if (!mystricmp(sMIG_SEL,"Sequential")) sprintf(sMIG_SEL,"BestNSelector(%s,%d)",nMINIMISE?"false":"true",nPOP_SIZE);
        else if (!mystricmp(sMIG_SEL,"Ranking")) sprintf(sMIG_SEL,"RankingSelector(%s)",nMINIMISE?"false":"true");
        else {
          fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sMIG_SEL);
          exit(1);
        }
     }
  |  MIG_SEL IDENTIFIER2 NUMBER2 {
        strcpy(sMIG_SEL, $2->sName);
        if (!mystricmp(sMIG_SEL,"EPTrn")){
          fprintf(stderr,"\n%s - Error line %d: The EP-Tournament selector is not implemented in DREAM.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
          exit(1);
        }
        else if (!mystricmp(sMIG_SEL,"Tournament")) {
          if ($3>=2) sprintf(sMIG_SEL,"TournamentSelector(%s, 1, %d)",(nMINIMISE?"false":"true"),(int)$3);
          else if (($3>.5)&&($3<=1.0)) sprintf(sMIG_SEL,"TournamentSelector(%s, %f, 2)",(nMINIMISE?"false":"true"),(float)$3);
maitre's avatar
maitre committed
1235
          else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
moh_lo's avatar
moh_lo committed
1236 1237 1238
        }
        else if (!mystricmp(sMIG_SEL,"StochTrn")) {
          if (($3>.5)&&($3<=1.0)) sprintf(sMIG_SEL,"TournamentSelector(%s, %f, 2)",(nMINIMISE?"false":"true"),(float)$3);
maitre's avatar
maitre committed
1239
          else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
moh_lo's avatar
moh_lo committed
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
        }
        else if (!mystricmp(sMIG_SEL,"RouletteWheel")) sprintf(sMIG_SEL,"RouletteWheelSelector(%s)",nMINIMISE?"false":"true");
        else if (!mystricmp(sMIG_SEL,"Random")) sprintf(sMIG_SEL,"RandomSelector()");
        else if (!mystricmp(sMIG_SEL,"Sequential")) sprintf(sMIG_SEL,"BestNSelector(%s,%d)",nMINIMISE?"false":"true",nPOP_SIZE);
        else if (!mystricmp(sMIG_SEL,"Ranking")) sprintf(sMIG_SEL,"RankingSelector(%s)",nMINIMISE?"false":"true");
        else {
          fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_OFF);
          exit(1);
        }
     }
  |  MIGRATOR IDENTIFIER2{
      if (!mystricmp($2->sName,"neighbours")) {
        sprintf(sMIGRATOR,"DefaultEMigrator");
        sprintf(sMIG_TARGET_SELECTOR,", new RandomTargetSelector()");
      }
      else if (!mystricmp($2->sName,"mesh")) {
        sprintf(sMIGRATOR,"ToAllEmigrator");
        sMIG_TARGET_SELECTOR[0]=0;     
      }
      else {
         fprintf(stderr,"\n%s - Error line %d: Looking for \"Move\" or \"Clone\".\n",sEZ_FILE_NAME,EASEALexer.yylineno);
         exit(1);
     } }
  |  MIG_FREQ NUMBER2
     {fMIG_FREQ=(float)$2;}
  |  NB_MIG NUMBER2
     {nNB_MIG=(int)$2;}
  |  IMMIG_SEL IDENTIFIER2{
        strcpy(sIMMIG_SEL, $2->sName);
        if (!mystricmp(sIMMIG_SEL,"EPTrn")){
          fprintf(stderr,"\n%s - Error line %d: The EP-Tournament selector is not implemented in DREAM.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
          exit(1);
        }
        else if (!mystricmp(sIMMIG_SEL,"Tournament")) sprintf(sIMMIG_SEL,"TournamentSelector(false, 1, 2)");
        else if (!mystricmp(sIMMIG_SEL,"StochTrn")) {
maitre's avatar
maitre committed
1275
          fprintf(stderr,"\n%s - Warning line %d: The Stochatic Tournament selector needs a parameter in [0.5,1].\nDefault value 1 inserted",sEZ_FILE_NAME,EASEALexer.yylineno);nWARNINGS++;
moh_lo's avatar
moh_lo committed
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
          sprintf(sIMMIG_SEL,"TournamentSelector(false, 1, 2)");
        }
        else if (!mystricmp(sIMMIG_SEL,"RouletteWheel")) sprintf(sIMMIG_SEL,"RouletteWheelSelector(%s)",nMINIMISE?"false":"true");
        else if (!mystricmp(sIMMIG_SEL,"Random")) sprintf(sIMMIG_SEL,"RandomSelector()");
        else if (!mystricmp(sIMMIG_SEL,"Sequential")) sprintf(sIMMIG_SEL,"BestNSelector(%s,%d)",nMINIMISE?"false":"true",nPOP_SIZE);
        else if (!mystricmp(sIMMIG_SEL,"Ranking")) sprintf(sIMMIG_SEL,"RankingSelector(%s)",nMINIMISE?"false":"true");
        else {
          fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sIMMIG_SEL);
          exit(1);
        }
     }
  |  IMMIG_SEL IDENTIFIER2 NUMBER2 {
        strcpy(sIMMIG_SEL, $2->sName);
        if (!mystricmp(sIMMIG_SEL,"EPTrn")){
          fprintf(stderr,"\n%s - Error line %d: The EP-Tournament selector is not implemented in DREAM.\n",sEZ_FILE_NAME,EASEALexer.yylineno);
          exit(1);
        }
        else if (!mystricmp(sIMMIG_SEL,"Tournament")) {
          if ($3>=2) sprintf(sIMMIG_SEL,"TournamentSelector(%s, 1, %d)",(nMINIMISE?"false":"true"),(int)$3);
          else if (($3>.5)&&($3<=1.0)) sprintf(sIMMIG_SEL,"TournamentSelector(%s, %f, 2)",(nMINIMISE?"false":"true"),(float)$3);
maitre's avatar
maitre committed
1296
          else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
moh_lo's avatar
moh_lo committed
1297 1298 1299
        }
        else if (!mystricmp(sIMMIG_SEL,"StochTrn")) {
          if (($3>.5)&&($3<=1.0)) sprintf(sIMMIG_SEL,"TournamentSelector(%s, %f, 2)",(nMINIMISE?"false":"true"),(float)$3);
maitre's avatar
maitre committed
1300
          else {fprintf(stderr,"\n%s - Error line %d: The parameter of the Tournament selector must be either >=2 or within ]0.5, 1].\n",sEZ_FILE_NAME,EASEALexer.yylineno); exit(1);}
moh_lo's avatar
moh_lo committed
1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
        }
        else if (!mystricmp(sIMMIG_SEL,"RouletteWheel")) sprintf(sIMMIG_SEL,"RouletteWheelSelector(%s)",nMINIMISE?"false":"true");
        else if (!mystricmp(sIMMIG_SEL,"Random")) sprintf(sIMMIG_SEL,"RandomSelector()");
        else if (!mystricmp(sIMMIG_SEL,"Sequential")) sprintf(sIMMIG_SEL,"BestNSelector(%s,%d)",nMINIMISE?"false":"true",nPOP_SIZE);
        else if (!mystricmp(sIMMIG_SEL,"Ranking")) sprintf(sIMMIG_SEL,"RankingSelector(%s)",nMINIMISE?"false":"true");
        else {
          fprintf(stderr,"\n%s - Error line %d: The %s selection scheme does not exist.\n",sEZ_FILE_NAME,EASEALexer.yylineno, sRED_OFF);
          exit(1);
        }
     }
  |  IMMIG_REPL IDENTIFIER2{
      if (!mystricmp($2->sName,"replace")) nIMMIG_REPL=1;
      else if (!mystricmp($2->sName,"add")) nIMMIG_REPL=0;
      else {
         fprintf(stderr,"\n%s - Error line %d: Looking for \"Add\" or \"Replace\".\n",sEZ_FILE_NAME,EASEALexer.yylineno);
         exit(1);
     } }
  ;
  
Expr
  : IDENTIFIER '=' Expr { 
      if (SymbolTable.find($1->sName)==NULL){
         fprintf(stderr,"\n%s - Error line %d: Symbol \"%s\" not found.\n",sEZ_FILE_NAME,EASEALexer.yylineno,$1->sName);
         exit(1);
      }
      $$ = assign(SymbolTable.find($1->sName), $3);
    }
  | Expr '+' Expr                    { $$ = $1 + $3; }
  | Expr '-' Expr                     { $$ = $1 - $3; }
  | Expr '*' Expr                     { $$ = $1 * $3; }
  | Expr '/' Expr                     { $$ = divide($1, $3); }
  | '(' Expr ')'                          { $$ = $2; }
  | '-' Expr %prec UMINUS { $$ = -$2; }
  | NUMBER                         { $$ = $1; }
  | IDENTIFIER{
      if (SymbolTable.find($1->sName)==NULL){
         fprintf(stderr,"\n%s - Error line %d: Symbol \"%s\" not found.\n",sEZ_FILE_NAME,EASEALexer.yylineno,$1->sName);
         exit(1);
      }
      $$ = (SymbolTable.find($1->sName))->dValue;
    }
  ;

%%
                       
/////////////////////////////////////////////////////////////////////////////
// main

int main(int argc, char *argv[]){
  int n = YYEXIT_FAILURE;
  int nParamNb=0;
maitre's avatar
maitre committed
1352 1353
  char *sTemp;
  int i=0;
moh_lo's avatar
moh_lo committed
1354 1355 1356 1357 1358
  
  TARGET=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) {
maitre's avatar
maitre committed
1359 1360 1361 1362 1363
    sTemp=&(argv[nParamNb][0]);
    if ((argv[nParamNb][0]=='-')||(argv[nParamNb][0]=='/')) sTemp=&(argv[nParamNb][1]);
    if (!mystricmp(sTemp,"eo"))  TARGET=EO;
    else if (!mystricmp(sTemp,"galib"))  TARGET=GALIB;
    else if (!mystricmp(sTemp,"dream"))  TARGET=DREAM;
maitre's avatar
maitre committed
1364 1365 1366 1367 1368 1369 1370 1371 1372
    else if (!mystricmp(sTemp,"cuda")){
      TARGET=CUDA;
      TARGET_FLAVOR = CUDA_FLAVOR_SO;
    }
    else if( !mystricmp(sTemp,"cuda_mo") ){
      TARGET=CUDA;
      TARGET_FLAVOR = CUDA_FLAVOR_MO;
    }

1373 1374 1375 1376 1377 1378 1379 1380
    else if (!mystricmp(sTemp,"std"))  {
      TARGET=STD;
      TARGET_FLAVOR = STD_FLAVOR_SO;
    }
    else if (!mystricmp(sTemp,"std_mo")) {
      TARGET=STD;
      TARGET_FLAVOR = STD_FLAVOR_MO;
    }
Frederic's avatar
Frederic committed
1381 1382
    else if (!mystricmp(sTemp,"cmaes"))  {
      TARGET=STD;
1383
      TARGET_FLAVOR = STD_FLAVOR_CMAES;
Frederic's avatar
Frederic committed
1384
    }
maitre's avatar
maitre committed
1385

maitre's avatar
maitre committed
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412
    else if (!mystricmp(sTemp,"v"))  bVERBOSE=true;
    else if (!mystricmp(sTemp,"path"))  {
      if (argv[++nParamNb][0]=='"') {
        strcpy(sEZ_PATH,&(argv[nParamNb][1]));
        while (argv[++nParamNb][strlen(argv[nParamNb])]!='"')
          strcat(sEZ_PATH,argv[nParamNb]);
          argv[nParamNb][strlen(argv[nParamNb])]=0;
          strcat(sEZ_PATH,argv[nParamNb]);
      }
      else {
        if (argv[nParamNb][strlen(argv[nParamNb])-1]=='"') argv[nParamNb][strlen(argv[nParamNb])-1]=0;
        strcpy(sEZ_PATH,argv[nParamNb]);
      }
    }
    else if (!mystricmp(sTemp,"eo_dir"))  {
      if (argv[++nParamNb][0]=='"') {
        strcpy(sEO_DIR,&(argv[nParamNb][1]));
        while (argv[++nParamNb][strlen(argv[nParamNb])]!='"')
          strcat(sEO_DIR,argv[nParamNb]);
          argv[nParamNb][strlen(argv[nParamNb])]=0;
          strcat(sEO_DIR,argv[nParamNb]);
      }
      else {
        if (argv[nParamNb][strlen(argv[nParamNb])-1]=='"') argv[nParamNb][strlen(argv[nParamNb])-1]=0;
        strcpy(sEO_DIR,argv[nParamNb]);
      }
    }
moh_lo's avatar
moh_lo committed
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
    else strcpy(sRAW_PROJECT_NAME,argv[nParamNb]);
  }

  CEASEAParser Parser;
  if (Parser.create())  n = Parser.yyparse();
  exit(n);
  return n;
}

/////////////////////////////////////////////////////////////////////////////
// EASEAParser commands

int CEASEAParser::create()
{
  if (!yycreate(&EASEALexer)) {
    return 0;
  }
  if (!EASEALexer.create(this, &SymbolTable)) {
    return 0;
  }
  return 1; // success
}

/////////////////////////////////////////////////////////////////////////////
// calc_parser attribute commands

double CEASEAParser::assign(CSymbol* spIdentifier, double dValue)
{
  assert(spIdentifier != NULL);

  spIdentifier->dValue = dValue;
  return spIdentifier->dValue;
}

double CEASEAParser::divide(double a, double b)
{
  if (b == 0) {
    printf("division by zero\n");
    yyforceerror();   // causes a syntax error
    return 0;
  }
  else {
    return a / b;
  }
}