EaseaYTools.cpp 3.47 KB
Newer Older
kruger's avatar
kruger committed
1 2 3
#ifdef WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif
maitre's avatar
maitre committed
4 5 6 7 8
#include "Easea.h"
#include "EaseaLex.h"
#include "debug.h"


maitre's avatar
maitre committed
9
void pickupSTDSelector(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME, CEASEALexer* EASEALexer){
kruger's avatar
kruger committed
10
  //DEBUG_PRT("Picking up selector without argument %s",sSELECTOR);
maitre's avatar
maitre committed
11
  if (!mystricmp(sSELECTOR,"Roulette")){
maitre's avatar
maitre committed
12
    if (nMINIMISE==1) {
maitre's avatar
maitre committed
13
      fprintf(stderr,"\n%s - Error line %d: The Roulette selection scheme cannot be\n selected when \"minimising the fitness\" is the evaluator goal.\n",
maitre's avatar
maitre committed
14 15 16 17 18 19
	      sEZ_FILE_NAME,EASEALexer->yylineno);
      exit(1);
    }
    else sprintf(sSELECTOR,"Roulette");
  }
  else if (!mystricmp(sSELECTOR,"Tournament")){
maitre's avatar
maitre committed
20
    sprintf(sSELECTOR,"Tournament");
maitre's avatar
maitre committed
21
    // as there is no selection pressure, we put 2
maitre's avatar
maitre committed
22
    *fSELECT_PRM=(float)2.0;
maitre's avatar
maitre committed
23 24 25 26 27
  }
  else if (!mystricmp(sSELECTOR,"StochTrn")) sprintf(sSELECTOR,"StochTour");
  else if (!mystricmp(sSELECTOR,"Random")){
    sprintf(sSELECTOR,"Random");
    if( TARGET==CUDA || TARGET==STD )
maitre's avatar
maitre committed
28
      *fSELECT_PRM = 0.0;
maitre's avatar
maitre committed
29 30
  }
  else if (!mystricmp(sSELECTOR,"Ranking")) sprintf(sSELECTOR,"Ranking");
maitre's avatar
maitre committed
31 32 33
  else if (!mystricmp(sSELECTOR,"Deterministic")){
    sprintf(sSELECTOR,"Deterministic");
    if( TARGET==CUDA || TARGET==STD) *fSELECT_PRM = 0.0;    
maitre's avatar
maitre committed
34 35 36 37 38 39 40 41
  }
  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);
    exit(1);
  }
}


maitre's avatar
maitre committed
42
void pickupSTDSelectorArgument(char* sSELECTOR, float* fSELECT_PRM, char* sEZ_FILE_NAME, float thirdParam, CEASEALexer* EASEALexer){
kruger's avatar
kruger committed
43
  //DEBUG_PRT("Picking up selector with argument %s %d",sSELECTOR,(int) thirdParam);
maitre's avatar
maitre committed
44
  if (!mystricmp(sSELECTOR,"Tournament")||!mystricmp(sSELECTOR,"StochTrn")) {
maitre's avatar
maitre committed
45 46
    if (thirdParam>=2) {sprintf(sSELECTOR,"Tournament");
      *fSELECT_PRM = (float) thirdParam;}
maitre's avatar
maitre committed
47 48
    else if ((thirdParam>.5)&&(thirdParam<=1.0)) {
      sprintf(sSELECTOR,"StochTour");
maitre's avatar
maitre committed
49
      *fSELECT_PRM = (float) thirdParam;
maitre's avatar
maitre committed
50 51 52 53 54 55 56
    }
    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);
    }
  }
maitre's avatar
maitre committed
57
  else if (!mystricmp(sSELECTOR,"Roulette")) {
maitre's avatar
maitre committed
58
    sprintf(sSELECTOR,"Roulette");
maitre's avatar
maitre committed
59
    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.",
maitre's avatar
maitre committed
60 61 62
		       sEZ_FILE_NAME,EASEALexer->yylineno);
      nWARNINGS++;
    }
maitre's avatar
maitre committed
63
    else *fSELECT_PRM = (float) thirdParam;  }
maitre's avatar
maitre committed
64 65 66 67 68 69 70 71 72 73 74
  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.",
	    sEZ_FILE_NAME,EASEALexer->yylineno);
    nWARNINGS++;
  }
  else if (!mystricmp(sSELECTOR,"Ranking")) {
    sprintf(sSELECTOR,"Ranking");
    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++;
maitre's avatar
maitre committed
75
      *fSELECT_PRM = 2.0;
maitre's avatar
maitre committed
76
    }
maitre's avatar
maitre committed
77
    else *fSELECT_PRM = (float) thirdParam;
maitre's avatar
maitre committed
78
  }
maitre's avatar
maitre committed
79 80
  else if (!mystricmp(sSELECTOR,"Deterministic")) {
    sprintf(sSELECTOR,"Deterministic");
maitre's avatar
maitre committed
81 82 83
			    
    if (thirdParam==0)
      if( TARGET==CUDA || TARGET==STD )
maitre's avatar
maitre committed
84
	*fSELECT_PRM = 0.0;
maitre's avatar
maitre committed
85 86 87 88 89 90
  }
  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);
    exit(1);
  }
}