Changeset 1166 for trunk/packages/optimizer/src/plugin_pgapack.c
- Timestamp:
- Sep 27, 2008, 1:58:13 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/optimizer/src/plugin_pgapack.c
r1154 r1166 22 22 int popSize; /* population size <=> PGASetPopSize() */ 23 23 int popRepl; /* replacement <=> PGASetPopReplacementType() */ 24 int numReplPerPop; /* number of new strings created per population, the rest are the best strings from the previous population*/ 24 25 int stpcriteria; /*stoppage criteria <=> PGASetStoppingRuleType()*/ 25 26 int randnumseed; /*Random Number Seed <=> PGASetRandomSeed()*/ 26 27 double mutnrate; /*Mutation Rate <=> PGASetMutationProb()*/ 28 double mutnValue; /*use this value while mutating*/ 27 29 double crossovrate; /*Crossover Rate <=> PGASetCrossoverProb();*/ 30 int allowdup; /*Allow duplicate strings in the population or not*/ 31 int mutnandcrossover;/*By default strings that do not undergo crossover undergo mutation, this option allows strings to crossover and be mutated*/ 28 32 } PgapackData; 29 33 … … 58 62 {"-operation", &RpOption_Oper, Rp_Offset(PgapackData,operation)}, 59 63 {"-poprepl", &RpOption_PopRepl, Rp_Offset(PgapackData,popRepl)}, 64 {"-numReplPerPop",RP_OPTION_INT,Rp_Offset(PgapackData,numReplPerPop)}, 60 65 {"-popsize", RP_OPTION_INT, Rp_Offset(PgapackData,popSize)}, 61 66 {"-mutnrate",RP_OPTION_DOUBLE,Rp_Offset(PgapackData,mutnrate)}, 67 {"-mutnValue",RP_OPTION_DOUBLE,Rp_Offset(PgapackData,mutnValue)}, 62 68 {"-crossovrate",RP_OPTION_DOUBLE,Rp_Offset(PgapackData,crossovrate)}, 63 69 {"-randnumseed",RP_OPTION_INT,Rp_Offset(PgapackData,randnumseed)}, 64 70 {"-stpcriteria",&RpOption_StpCriteria,Rp_Offset(PgapackData,stpcriteria)}, 71 {"-allowdup",RP_OPTION_BOOLEAN,Rp_Offset(PgapackData,allowdup)}, 72 {"-mutnandcrossover",RP_OPTION_BOOLEAN,Rp_Offset(PgapackData,mutnandcrossover)}, 65 73 {NULL, NULL, 0} 66 74 }; … … 104 112 dataPtr->popRepl = PGA_POPREPL_BEST; 105 113 dataPtr->popSize = 200; 114 dataPtr->numReplPerPop = (dataPtr->popSize)/10; /*10% replaced by default, change to whatever value you need*/ 106 115 dataPtr->crossovrate = 0.85; 107 116 dataPtr->mutnrate = 0.05; /*by default in PGAPack 1/stringlength*/ 117 dataPtr->mutnValue = 0.01;/*value of this number will be changed by plus/minus hundredth of its current value*/ 108 118 dataPtr->randnumseed = 1; /*should be a number greater than one, PGAPack requires it*/ 109 119 dataPtr->stpcriteria = PGA_STOP_NOCHANGE; 120 dataPtr->allowdup = PGA_FALSE; /*Do not allow duplicate strings by default*/ 121 dataPtr->mutnandcrossover = PGA_FALSE;/*do not allow mutation and crossover to take place on the same string by default*/ 110 122 return (ClientData)dataPtr; 111 123 } 112 124 113 125 int pgapack_abort = 0; 126 int pgapack_restart_user_action = 0; 114 127 115 128 /* … … 136 149 pgapack_abort = 0; /* FALSE */ 137 150 PGASetAbortVar(&pgapack_abort); 151 PGASetRestartUserAction(&pgapack_restart_user_action); 138 152 139 153 ctx = PGACreate(&argc, argv, PGA_DATATYPE_USER, envPtr->numParams, … … 145 159 PGASetStoppingRuleType(ctx, dataPtr->stpcriteria); 146 160 PGASetMutationProb(ctx,dataPtr->mutnrate); 161 PGASetMutationRealValue(ctx,dataPtr->mutnValue); 147 162 PGASetCrossoverProb(ctx,dataPtr->crossovrate); 148 163 PGASetRandomSeed(ctx,dataPtr->randnumseed); 149 164 PGASetCrossoverType(ctx, PGA_CROSSOVER_UNIFORM); 165 PGASetNoDuplicatesFlag(ctx,dataPtr->allowdup); 166 PGASetMutationAndCrossoverFlag(ctx,dataPtr->mutnandcrossover); 167 PGASetNumReplaceValue(ctx,dataPtr->numReplPerPop); 150 168 151 169 … … 342 360 343 361 int n, ival,tempmr; 362 double mutnVal; 344 363 RpOptimEnv *envPtr; 345 364 RpOptimParam *paramPtr; … … 358 377 if(numPtr->mutnrate!=PARAM_NUM_UNSPEC_MUTN_RATE){ 359 378 tempmr = numPtr->mutnrate; 379 mutnVal = numPtr->mutnValue; 360 380 }else{ 361 381 tempmr = mr; 382 mutnVal = PGAGetMutationRealValue(ctx); 362 383 } 363 384 if (PGARandomFlip(ctx, tempmr)) { … … 367 388 /* bump the value up/down a little, randomly */ 368 389 if (PGARandomFlip(ctx, 0.5)) { 369 paramPtr[n].value.dval += 0.1*paramPtr[n].value.dval;390 paramPtr[n].value.dval += mutnVal*paramPtr[n].value.dval; /*Made the mutation amount configurable*/ 370 391 } else { 371 paramPtr[n].value.dval -= 0.1*paramPtr[n].value.dval;392 paramPtr[n].value.dval -= mutnVal*paramPtr[n].value.dval; 372 393 } 373 394 /* make sure the resulting value is still in bounds */
Note: See TracChangeset
for help on using the changeset viewer.