Changeset 1166
- Timestamp:
- Sep 27, 2008, 1:58:13 AM (16 years ago)
- Location:
- trunk/packages/optimizer
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/optimizer/examples/app-qdot.tcl
r1153 r1166 24 24 set popsize 100 ;# size of each population for genetic algorithm 25 25 26 set xml_path [lindex $argv 0] 27 puts $xml_path 28 29 26 30 # ---------------------------------------------------------------------- 27 31 # Create a Tool object based on the tool.xml file... 28 32 # ---------------------------------------------------------------------- 29 33 Rappture::getopts argv params { 30 value -tool tool.xml34 value -tool tool.xml 31 35 } 32 36 37 after 2000 38 puts $params(-tool) 39 after 2000 33 40 #blt::bltdebug 100 34 41 -
trunk/packages/optimizer/examples/simple.tcl
r1071 r1166 23 23 set auto_path [linsert $auto_path 0 /home/ganesh/workspace/optim_post_dir_changes/src/lib] 24 24 package require -exact RapptureOptimizer 1.1 25 set popsize 100 ;# size of each population for genetic algorithm 25 26 26 27 27 # ---------------------------------------------------------------------- … … 64 64 button .quit -text Quit -command "optim abort yes" 65 65 pack .quit 66 button .restart -text Restart -command "optim restart yes" 67 pack .restart 68 66 69 set colors {magenta purple blue DeepSkyBlue cyan green yellow Gold orange tomato red FireBrick black} 67 70 … … 97 100 Rappture::optimizer optim -tool $tool -using pgapack 98 101 99 optim add number input.number(x1) -min -2 -max 2 -randdist gaussian -stddev 0.7 -mean 1 -mutnrate 0.01 -strictmin yes -strictmax yes 100 optim add number input.number(x2) -min -2 -max 2 -randdist gaussian -stddev 0.5 -mean 1 -mutnrate 0.01 -strictmin yes -strictmax yes 101 #optim configure -operation minimize -popsize 50 -maxruns 100 -mutnrate 0.01 -crossovrate 0.9 -randnumseed 24 -stpcriteria toosimilar 102 optim add number input.number(x1) -min -2 -max 2 -randdist uniform -strictmin yes -strictmax yes 103 optim add number input.number(x2) -min -2 -max 2 -randdist uniform -strictmin yes -strictmax yes 104 optim configure -operation minimize -popsize 200 -maxruns 100 -mutnrate 0.5 -crossovrate 0.8 -randnumseed 20 -stpcriteria toosimilar -mutnandcrossover no -allowdup no -numReplPerPop 50 -mutnValue 0.1 105 optim get configure 102 106 103 optim get configure 107 set popsize 200 ;# size of each population for genetic algorithm 104 108 105 109 set status [optim perform \ -
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 */ -
trunk/packages/optimizer/src/rp_optimizer.c
r1154 r1166 115 115 numPtr->max = DBL_MAX; 116 116 numPtr->mutnrate = PARAM_NUM_UNSPEC_MUTN_RATE; /*Unspecified by default, should result in global mutn rate being applied*/ 117 numPtr->mutnValue = 0.01; /* value of this number will be changed by plus/minus hundredth of its current value*/ 117 118 numPtr->randdist = RAND_NUMBER_DIST_GAUSSIAN ;/*Gaussian by default*/ 118 119 numPtr->stddev = 1; -
trunk/packages/optimizer/src/rp_optimizer.h
r1154 r1166 48 48 */ 49 49 typedef enum { 50 RP_OPTIM_SUCCESS=0, RP_OPTIM_UNKNOWN, RP_OPTIM_FAILURE, RP_OPTIM_ABORTED 50 RP_OPTIM_SUCCESS=0, RP_OPTIM_UNKNOWN, RP_OPTIM_FAILURE, RP_OPTIM_ABORTED, RP_OPTIM_RESTARTED 51 51 } RpOptimStatus; 52 52 … … 107 107 double max; /* optimization constraint: max value */ 108 108 double mutnrate; /* independently sets mutation rate for each parameter*/ 109 double mutnValue; /* on mutation bumps up/down the value by val (+-) mutnValue*val */ 109 110 int randdist; /* gaussian or uniform distribution*/ 110 111 int strictmin; /* whether a strict min is to be applied for gauss. rand. numbers*/ -
trunk/packages/optimizer/src/rp_optimizer_tcl.c
r1154 r1166 17 17 18 18 extern int pgapack_abort; 19 extern int pgapack_restart_user_action; 19 20 20 21 /* … … 57 58 {"-max", RP_OPTION_DOUBLE, Rp_Offset(RpOptimParamNumber,max)}, 58 59 {"-mutnrate",RP_OPTION_DOUBLE, Rp_Offset(RpOptimParamNumber,mutnrate)}, 60 {"-mutnValue",RP_OPTION_DOUBLE, Rp_Offset(RpOptimParamNumber,mutnValue)}, 59 61 {"-randdist",&RpOption_RandDist,Rp_Offset(RpOptimParamNumber,randdist)}, 60 62 {"-strictmin",RP_OPTION_BOOLEAN,Rp_Offset(RpOptimParamNumber,strictmin)}, … … 83 85 #endif 84 86 85 extern int pgapack_abort; 87 86 88 extern void PGARuntimeDataTableInit(); 87 89 extern void PGARuntimeDataTableDeInit(); … … 394 396 pgapack_abort = value; 395 397 return TCL_OK; 396 } else if (*option == 'g' && strcmp(option,"get") == 0) { 398 }else if (*option == 'r' && strcmp(option,"restart") == 0){ 399 int value; 400 if (objc < 3) { 401 Tcl_WrongNumArgs(interp, 1, objv, "restart bool"); 402 return TCL_ERROR; 403 } 404 if (Tcl_GetBooleanFromObj(interp, objv[2], &value) != TCL_OK) { 405 return TCL_ERROR; 406 } 407 pgapack_restart_user_action = value; 408 return TCL_OK; 409 }else if (*option == 'g' && strcmp(option,"get") == 0) { 397 410 /* 398 411 * OPTION: get ?globPattern? ?-option?
Note: See TracChangeset
for help on using the changeset viewer.