Changeset 1070 for trunk/packages/optimizer/src/plugin_pgapack.c
- Timestamp:
- Jun 26, 2008, 7:46:14 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/optimizer/src/plugin_pgapack.c
r1067 r1070 291 291 case RP_OPTIMPARAM_NUMBER: 292 292 numPtr = (RpOptimParamNumber*)envPtr->paramList[n]; 293 dval = PGARandom01(ctx,0); 294 newParamPtr[n].value.dval = 293 if(numPtr->randdist == RAND_NUMBER_DIST_UNIFORM){ 294 dval = PGARandom01(ctx,0); 295 newParamPtr[n].value.dval = 295 296 (numPtr->max - numPtr->min)*dval + numPtr->min; 297 }else if(numPtr->randdist == RAND_NUMBER_DIST_GAUSSIAN){ 298 dval = PGARandomGaussian(ctx,numPtr->mean,numPtr->stddev); 299 if(numPtr->strictmax){ 300 if(dval>numPtr->max){ 301 dval = numPtr->max; 302 } 303 } 304 if(numPtr->strictmin){ 305 if(dval<numPtr->min){ 306 dval = numPtr->min; 307 } 308 } 309 newParamPtr[n].value.dval = dval; 310 }else{ 311 panic("Incorrect Random Number distribution option in PgapcreateString()"); 312 } 296 313 break; 297 314 case RP_OPTIMPARAM_STRING: … … 325 342 int count = 0; /* number of mutations */ 326 343 327 int n, ival ;344 int n, ival,tempmr; 328 345 RpOptimEnv *envPtr; 329 346 RpOptimParam *paramPtr; … … 335 352 336 353 for (n=0; n < envPtr->numParams; n++) { 337 if (PGARandomFlip(ctx, mr)) { 338 /* won the coin toss -- change this parameter */ 339 count++; 354 340 355 341 356 switch (paramPtr[n].type) { 342 357 case RP_OPTIMPARAM_NUMBER: 343 /* bump the value up/down a little, randomly */344 if (PGARandomFlip(ctx, 0.5)){345 paramPtr[n].value.dval += 0.1*paramPtr[n].value.dval;346 } else{347 paramPtr[n].value.dval -= 0.1*paramPtr[n].value.dval;358 numPtr = (RpOptimParamNumber*)envPtr->paramList[n]; 359 if(numPtr->mutnrate!=PARAM_NUM_UNSPEC_MUTN_RATE){ 360 tempmr = numPtr->mutnrate; 361 }else{ 362 tempmr = mr; 348 363 } 349 /* make sure the resulting value is still in bounds */ 350 numPtr = (RpOptimParamNumber*)envPtr->paramList[n]; 351 if (paramPtr[n].value.dval > numPtr->max) { 352 paramPtr[n].value.dval = numPtr->max; 353 } 354 if (paramPtr[n].value.dval < numPtr->min) { 355 paramPtr[n].value.dval = numPtr->min; 364 if (PGARandomFlip(ctx, tempmr)) { 365 /* won the coin toss -- change this parameter */ 366 count++; 367 368 /* bump the value up/down a little, randomly */ 369 if (PGARandomFlip(ctx, 0.5)) { 370 paramPtr[n].value.dval += 0.1*paramPtr[n].value.dval; 371 } else { 372 paramPtr[n].value.dval -= 0.1*paramPtr[n].value.dval; 373 } 374 /* make sure the resulting value is still in bounds */ 375 if(numPtr->randdist == RAND_NUMBER_DIST_UNIFORM || 376 (numPtr->randdist == RAND_NUMBER_DIST_GAUSSIAN && numPtr->strictmax)){ 377 if (paramPtr[n].value.dval > numPtr->max) { 378 paramPtr[n].value.dval = numPtr->max; 379 } 380 } 381 /*also make sure it obeys configured parameters when gaussian*/ 382 if(numPtr->randdist == RAND_NUMBER_DIST_UNIFORM || 383 (numPtr->randdist == RAND_NUMBER_DIST_GAUSSIAN && numPtr->strictmin)){ 384 if (paramPtr[n].value.dval < numPtr->min) { 385 paramPtr[n].value.dval = numPtr->min; 386 } 387 } 388 356 389 } 357 390 break; 391 358 392 359 393 case RP_OPTIMPARAM_STRING: 360 ival = paramPtr[n].value.sval.num; 361 if (PGARandomFlip(ctx, 0.5)) { 362 ival += 1; 363 } else { 364 ival -= 1; 365 } 366 strPtr = (RpOptimParamString*)envPtr->paramList[n]; 367 if (ival < 0) ival = 0; 368 if (ival >= strPtr->numValues) ival = strPtr->numValues-1; 369 paramPtr[n].value.sval.num = ival; 370 paramPtr[n].value.sval.str = strPtr->values[ival]; 371 break; 372 394 if (PGARandomFlip(ctx, mr)) { 395 /* won the coin toss -- change this parameter */ 396 count++; 397 398 ival = paramPtr[n].value.sval.num; 399 if (PGARandomFlip(ctx, 0.5)) { 400 ival += 1; 401 } else { 402 ival -= 1; 403 } 404 strPtr = (RpOptimParamString*)envPtr->paramList[n]; 405 if (ival < 0) ival = 0; 406 if (ival >= strPtr->numValues) ival = strPtr->numValues-1; 407 paramPtr[n].value.sval.num = ival; 408 paramPtr[n].value.sval.str = strPtr->values[ival]; 409 } 410 411 break; 412 373 413 default: 374 414 panic("bad parameter type in PgapMutation()"); 375 415 } 376 }416 377 417 } 378 418 return count;
Note: See TracChangeset
for help on using the changeset viewer.