Changeset 1202 for trunk/packages/optimizer/src/pgapack
- Timestamp:
- Oct 29, 2008, 12:16:26 PM (16 years ago)
- Location:
- trunk/packages/optimizer/src/pgapack/pgapack
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/optimizer/src/pgapack/pgapack/include/pgapack.h
r1178 r1202 144 144 #define PGA_CROSSOVER_TWOPT 2 /* Two point crossover */ 145 145 #define PGA_CROSSOVER_UNIFORM 3 /* Uniform crossover */ 146 #define PGA_CROSSOVER_SBX 4 /* Simulated Binary crossover */ 146 147 147 148 /***************************************** … … 278 279 double FitnessCmaxValue; /* Cmax value used to convert minimizations */ 279 280 double restartAlleleProb;/* prob of changing an allele in a restart */ 281 double randreplprop; /* proportion of randomly generated individuals per generation post initialization*/ 280 282 int restart; /* whether to use the restart operator */ 281 283 int restartFreq; /* frequency with which to restart */ … … 715 717 int PGAGetRandomSeed(PGAContext *ctx); 716 718 void PGASetRandomSeed(PGAContext *ctx, int seed); 719 double PGAGetRandReplProp(PGAContext *ctx); 720 void PGASetRandReplProp(PGAContext *ctx, double randreplprop); 717 721 718 722 /***************************************** -
trunk/packages/optimizer/src/pgapack/pgapack/source/cross.c
r816 r1202 266 266 case PGA_CROSSOVER_TWOPT: 267 267 case PGA_CROSSOVER_UNIFORM: 268 case PGA_CROSSOVER_SBX: 268 269 ctx->ga.CrossoverType = crossover_type; 269 270 break; -
trunk/packages/optimizer/src/pgapack/pgapack/source/duplcate.c
r816 r1202 198 198 PGA_DOUBLE, (void *) &mr ); 199 199 200 while (( changed == PGA_FALSE ) && (mr <= 1.0)) { 201 if (ctx->fops.Mutation) { 202 fp = ((p == PGA_TEMP1) || (p == PGA_TEMP2)) ? p : p+1; 203 nflips = (*ctx->fops.Mutation)(&ctx, &fp, &pop, &mr); 204 } else { 205 nflips = (*ctx->cops.Mutation)( ctx, p, pop, mr ); 206 } 207 208 if ( nflips > 0 ) 209 changed = PGA_TRUE; 210 else 211 mr = 1.1*mr; 200 /**TODO: GTG (Clear)I dont see why we need to wait for iterations to mutate?****/ 201 /**TODO: can't we directly set mr = 1??**/ 202 while (changed == PGA_FALSE) { 203 if (ctx->fops.Mutation) { 204 fp = ((p == PGA_TEMP1) || (p == PGA_TEMP2)) ? p : p+1; 205 nflips = (*ctx->fops.Mutation)(&ctx, &fp, &pop, &mr); 206 } else { 207 nflips = (*ctx->cops.Mutation)( ctx, p, pop, mr ); 208 } 209 210 if ( nflips > 0 ) 211 changed = PGA_TRUE; 212 else 213 mr = ( mr>1 ? 1 :1.1*mr); 214 212 215 } 213 216 -
trunk/packages/optimizer/src/pgapack/pgapack/source/parallel.c
r986 r1202 127 127 if (rank == 0) { 128 128 Restarted = PGA_FALSE; 129 if ((ctx->ga.restart == PGA_TRUE) && 130 (ctx->ga.ItersOfSame % ctx->ga.restartFreq == 0)) { 131 ctx->ga.ItersOfSame++; 132 Restarted = PGA_TRUE; 133 PGARestart(ctx, PGA_OLDPOP, PGA_NEWPOP); 129 if (PGARestartCondition(ctx)) { 130 Restarted = PGA_TRUE; 131 PGARestart(ctx, PGA_OLDPOP, PGA_NEWPOP); 134 132 } else { 135 PGASelect(ctx, PGA_OLDPOP);136 CreateNewGeneration(ctx, PGA_OLDPOP, PGA_NEWPOP);133 PGASelect(ctx, PGA_OLDPOP); 134 CreateNewGeneration(ctx, PGA_OLDPOP, PGA_NEWPOP); 137 135 } 138 136 } -
trunk/packages/optimizer/src/pgapack/pgapack/source/pga.c
r986 r1202 200 200 { 201 201 int i, j, n, m1, m2; 202 int popsize, numreplace ;203 double pc ;202 int popsize, numreplace, randnumreplace; 203 double pc, randreplprop; 204 204 205 205 PGADebugEntered("PGARunMutationAndCrossover"); … … 207 207 popsize = PGAGetPopSize(ctx); 208 208 numreplace = PGAGetNumReplaceValue(ctx); 209 randreplprop = PGAGetRandReplProp(ctx); 210 randnumreplace = (int)randreplprop*popsize; 209 211 /*** first, copy n best strings (sorted by fitness) to new pop ***/ 210 212 PGASortPop( ctx, oldpop ); 211 n = popsize - numreplace ;213 n = popsize - numreplace - randnumreplace; 212 214 for ( i=0; i < n; i++ ) { 213 215 j = PGAGetSortedPopIndex( ctx, i ); … … 216 218 pc = PGAGetCrossoverProb(ctx); 217 219 /*** reproduce to create the rest of the new population ***/ 218 while ( n < popsize) {220 while ( n < (popsize- randnumreplace)) { 219 221 m1 = PGASelectNextIndex( ctx ); 220 222 m2 = PGASelectNextIndex( ctx ); … … 230 232 n++; 231 233 232 if ( n < popsize) {234 if ( n < (popsize-randnumreplace) ) { 233 235 /*** mutate and copy second string to new population ***/ 234 236 PGAMutate ( ctx, PGA_TEMP2, newpop); … … 242 244 PGACopyIndividual ( ctx, m1, oldpop, n, newpop ); 243 245 n++; 244 if ( n < ctx->ga.PopSize) {246 if ( n < (popsize-randnumreplace) ) { 245 247 PGACopyIndividual ( ctx, m2, oldpop, n, newpop ); 246 248 n++; … … 248 250 } 249 251 } 252 253 if(randnumreplace > 0){ 254 while(n < popsize){ 255 PGACreateIndividual(ctx,n,newpop,PGA_TRUE); 256 n++; 257 } 258 } 250 259 251 260 PGADebugExited("PGARunMutationAndCrossover"); … … 276 285 { 277 286 int i, j, n, m1, m2; 278 int popsize, numreplace ;279 double pc ;287 int popsize, numreplace, randnumreplace; 288 double pc, randreplprop; 280 289 281 290 PGADebugEntered("PGARunMutationOrCrossover"); … … 283 292 popsize = PGAGetPopSize(ctx); 284 293 numreplace = PGAGetNumReplaceValue(ctx); 294 randreplprop = PGAGetRandReplProp(ctx); 295 randnumreplace = (int)randreplprop*popsize; 285 296 /*** first, copy n best strings (sorted by fitness) to new pop ***/ 286 297 PGASortPop( ctx, oldpop ); 287 n = popsize - numreplace ;298 n = popsize - numreplace - randnumreplace ; 288 299 for ( i=0; i < n; i++ ) { 289 300 j = PGAGetSortedPopIndex( ctx, i ); … … 292 303 pc = PGAGetCrossoverProb(ctx); 293 304 /*** reproduce to create the rest of the new population ***/ 294 while ( n < popsize) {305 while ( n < (popsize-randnumreplace) ) { 295 306 m1 = PGASelectNextIndex( ctx ); 296 307 m2 = PGASelectNextIndex( ctx ); … … 305 316 n++; 306 317 307 if ( n < popsize)318 if ( n < (popsize-randnumreplace) ) 308 319 { 309 320 /*** copy second string to new population ***/ … … 323 334 n++; 324 335 325 if ( n < popsize) {336 if ( n < (popsize-randnumreplace) ) { 326 337 PGACopyIndividual(ctx, m2, oldpop, PGA_TEMP2, newpop); 327 338 PGAMutate ( ctx, PGA_TEMP2, newpop ); … … 333 344 } 334 345 } 346 347 if(randnumreplace > 0){ 348 while(n < popsize){ 349 PGACreateIndividual(ctx,n,newpop,PGA_TRUE); 350 n++; 351 } 352 } 335 353 336 354 PGADebugExited("PGARunMutationOrCrossover"); -
trunk/packages/optimizer/src/pgapack/pgapack/source/random.c
r816 r1202 403 403 PGADebugExited("PGASetRandomSeed"); 404 404 } 405 406 /***************************************************************************** 407 Category: Generation/Utility 408 409 Inputs: 410 ctx - context variable 411 randreplaceprop - proportion of individuals to be replaced per generation randomly, post initialization 412 413 Outputs: 414 None 415 416 Example: 417 PGAContext *ctx; 418 . 419 . 420 PGASetRandReplProp(ctx, 0.05); 421 ***************************************************************************/ 422 void PGASetRandReplProp(PGAContext *ctx, double randreplprop){ 423 PGADebugEntered("PGASetRandReplProp"); 424 PGAFailIfSetUp("PGASetRandReplProp"); 425 if(randreplprop < 0 || randreplprop > 1){ 426 PGAError ( ctx, "PGASetRandReplProp: Invalid value set:", 427 PGA_FATAL, PGA_DOUBLE, (void *) &randreplprop); 428 }else{ 429 ctx->ga.randreplprop = randreplprop; 430 } 431 PGADebugExited("PGASetRandReplProp"); 432 } 433 434 /***************************************************************************** 435 Category: Generation/Utility 436 437 Inputs: 438 ctx - context variable 439 440 Outputs: 441 randreplprop - proportion of randomly generated individuals per population, post initialization 442 443 Example: 444 PGAContext *ctx; 445 double randreplprop; 446 . 447 . 448 randreplprop = PGAGetRandReplProp(ctx); 449 ***************************************************************************/ 450 double PGAGetRandReplProp(PGAContext *ctx){ 451 PGADebugEntered("PGAGetRandReplProp"); 452 PGADebugExited("PGAGetRandReplProp"); 453 return ctx->ga.randreplprop; 454 }
Note: See TracChangeset
for help on using the changeset viewer.