Changeset 1272 for trunk/packages/optimizer
- Timestamp:
- Feb 4, 2009, 10:27:21 AM (15 years ago)
- Location:
- trunk/packages/optimizer/src/pgapack/pgapack
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/optimizer/src/pgapack/pgapack/include/pgapack.h
r1202 r1272 137 137 #define PGA_STOP_NOCHANGE 2 /* Stop: no change in best string */ 138 138 #define PGA_STOP_TOOSIMILAR 4 /* Stop: homogeneous population */ 139 #define PGA_STOP_AV_FITNESS 5 /* Stop: if within a certain % of target av.fitness per pop.*/ 140 #define PGA_STOP_BEST_FITNESS 6 /* Stop: if best fitness in a pop is within % of target best fitness*/ 141 #define PGA_STOP_VARIANCE 7 /* Stop: if variance of fitness in pop is within % of target variance */ 142 #define PGA_STOP_TIMEELAPSED 8 /* Stop: if elapsed time >= target*/ 139 143 140 144 /***************************************** … … 145 149 #define PGA_CROSSOVER_UNIFORM 3 /* Uniform crossover */ 146 150 #define PGA_CROSSOVER_SBX 4 /* Simulated Binary crossover */ 147 151 #define PGA_CROSSOVER_TRIANGULAR 5 /* Triangular Crossover*/ 148 152 /***************************************** 149 153 * SELECTION * … … 252 256 int PopSize; /* Number of strings to use */ 253 257 int StringLen; /* string lengths */ 258 double TgtFitnessVal; /* Target Fitness, best or average depending on stpg criteria*/ 259 double FitnessTol; /* Min Fitness Tolerance to be achieved for stoppage*/ 260 double TgtFitnessVar; /* Target Fitness Variance for stoppage */ 261 double VarTol; /* Tolerance for variance to be achieved for stoppage*/ 262 double TgtElapsedTime; /* Max Execution time of GA before stoppage */ 254 263 int StoppingRule; /* Termination Criteria */ 255 264 int MaxIter; /* Maximum number of iterations to run */ … … 338 347 double Online; 339 348 double Average; 349 double Variance; 340 350 double Best; 341 351 time_t starttime; … … 799 809 void PGASetMaxNoChangeValue(PGAContext *ctx, int max_no_change); 800 810 void PGASetMaxSimilarityValue(PGAContext *ctx, int max_similarity); 811 void PGASetTgtFitnessVal(PGAContext *ctx, double tgt_fitness_val); 812 void PGASetFitnessTol(PGAContext *ctx,double fitness_tol); 813 void PGASetTgtFitnessVariance(PGAContext *ctx,double tgt_fitness_var); 814 void PGASetVarTol(PGAContext *ctx,double var_tol); 815 void PGASetTgtElapsedTime(PGAContext *ctx,double tgt_elapsed_time); 801 816 802 817 /***************************************** -
trunk/packages/optimizer/src/pgapack/pgapack/source/create.c
r1271 r1272 459 459 if ( ctx->ga.MaxSimilarity == PGA_UNINITIALIZED_INT) 460 460 ctx->ga.MaxSimilarity = 95; 461 462 if (ctx->ga.TgtFitnessVal == PGA_UNINITIALIZED_DOUBLE){ 463 ctx->ga.TgtFitnessVal = 0; 464 } 465 466 if (ctx->ga.FitnessTol == PGA_UNINITIALIZED_DOUBLE){ 467 ctx->ga.FitnessTol = 0; 468 } 469 470 if (ctx->ga.VarTol == PGA_UNINITIALIZED_DOUBLE){ 471 ctx->ga.VarTol = 0; 472 } 473 474 if (ctx->ga.TgtFitnessVar == PGA_UNINITIALIZED_DOUBLE){ 475 ctx->ga.TgtFitnessVar = 0; 476 } 477 478 if (ctx->ga.TgtElapsedTime == PGA_UNINITIALIZED_DOUBLE){ 479 ctx->ga.TgtElapsedTime = 0; 480 } 461 481 462 482 if ( ctx->ga.NumReplace == PGA_UNINITIALIZED_INT) -
trunk/packages/optimizer/src/pgapack/pgapack/source/parallel.c
r1271 r1272 70 70 #include "pgapack.h" 71 71 #include <setjmp.h> 72 #include <time.h>73 72 74 73 extern jmp_buf pgapack_jmpbuf; -
trunk/packages/optimizer/src/pgapack/pgapack/source/stop.c
r1271 r1272 71 71 72 72 #include "pgapack.h" 73 #include <time.h> 73 74 74 75 int *pgapack_abortPtr = NULL; … … 144 145 { 145 146 int done = PGA_FALSE; 146 double diff; 147 double diff, process_execution_time; 148 time_t endtime; 147 149 148 150 PGADebugEntered("PGACheckStoppingConditions"); … … 162 164 if(((ctx->ga.StoppingRule & PGA_STOP_AV_FITNESS) == PGA_STOP_AV_FITNESS)){ 163 165 if(ctx->ga.TgtFitnessVal == PGA_UNINITIALIZED_DOUBLE){ 164 fprintf(stderr,"Uninitialized Value 'Target Average'");166 PGAError(ctx,"Uninitialized Value 'Target Average'",PGA_FATAL, PGA_DOUBLE, (void *)&(ctx->ga.TgtFitnessVal)); 165 167 done |= PGA_TRUE; 166 168 }else{ 167 169 diff = ((ctx->ga.TgtFitnessVal - ctx->rep.Average)/(ctx->ga.TgtFitnessVal))*100; 168 if(fabs(diff) <= ctx->ga.FitnessTol){170 if(fabs(diff) <= fabs((double)ctx->ga.FitnessTol)){ 169 171 done |= PGA_TRUE; 170 172 } … … 174 176 if(((ctx->ga.StoppingRule & PGA_STOP_BEST_FITNESS) == PGA_STOP_BEST_FITNESS)){ 175 177 if(ctx->ga.TgtFitnessVal == PGA_UNINITIALIZED_DOUBLE){ 176 fprintf(stderr,"Uninitialized Value 'Target Best Fitness'");178 PGAError(ctx,"Undefined Value 'Target Best Fitness'", PGA_FATAL, PGA_DOUBLE, (void *) &(ctx->ga.TgtFitnessVal)); 177 179 done |= PGA_TRUE; 178 180 }else{ 179 181 diff =(((double)ctx->ga.TgtFitnessVal -(double)ctx->rep.Best)/((double)ctx->ga.TgtFitnessVal))*100; 180 if(fabs(diff) <= ctx->ga.FitnessTol){182 if(fabs(diff) <= fabs((double)ctx->ga.FitnessTol)){ 181 183 done |= PGA_TRUE; 182 184 } … … 186 188 if(((ctx->ga.StoppingRule & PGA_STOP_VARIANCE) == PGA_STOP_VARIANCE)){ 187 189 if(ctx->ga.TgtFitnessVar == PGA_UNINITIALIZED_DOUBLE){ 188 fprintf(stderr,"Uninitialized Value 'Target Fitness Variance'");190 PGAError(ctx,"Undefined Value 'Target Fitness Variance'",PGA_FATAL,PGA_DOUBLE, (void *)&(ctx->ga.TgtFitnessVar)); 189 191 done |= PGA_TRUE; 190 192 }else{ 191 193 diff =(((double)ctx->ga.TgtFitnessVar -(double)ctx->rep.Variance)/((double)ctx->ga.TgtFitnessVar))*100; 192 if(fabs(diff) <= ctx->ga.VarTol){194 if(fabs(diff) <= fabs((double)ctx->ga.VarTol)){ 193 195 done |= PGA_TRUE; 194 196 } … … 197 199 198 200 if(((ctx->ga.StoppingRule & PGA_STOP_TIMEELAPSED) == PGA_STOP_TIMEELAPSED)){ 199 //TODO :GTG Add code for setting initial time and current time and comparing 200 done |= PGA_TRUE; 201 endtime = time(NULL); 202 process_execution_time = difftime(endtime, (time_t)ctx->rep.starttime); 203 if(ctx->ga.TgtElapsedTime == PGA_UNINITIALIZED_DOUBLE){ 204 PGAError(ctx,"Undefined target time of execution",PGA_FATAL,PGA_DOUBLE,(void *)&(ctx->ga.TgtElapsedTime)); 205 } 206 if(((double)process_execution_time/60) >= ((double)ctx->ga.TgtElapsedTime)){ 207 done |= PGA_TRUE; 208 } 201 209 } 202 210 … … 482 490 PGADebugEntered("PGASetFitnessTol"); 483 491 PGAFailIfSetUp("PGASetFitnessTol"); 492 if(fitness_tol < 0){ 493 PGAError(ctx,"Fitness tolerance invalid. Should be a positive quantity.\n",PGA_FATAL,PGA_DOUBLE,(void *)&fitness_tol); 494 } 484 495 ctx->ga.FitnessTol = fitness_tol; 485 496 PGADebugExited("PGASetFitnessTol"); … … 509 520 PGADebugEntered("PGASetTgtFitnessVariance"); 510 521 PGAFailIfSetUp("PGASetTgtFitnessVariance"); 522 if(tgt_fitness_var < 0){ 523 PGAError(ctx,"Fitness variance invalid. Should be a positive quantity.\n",PGA_FATAL,PGA_DOUBLE,(void *)&tgt_fitness_var); 524 } 511 525 ctx->ga.TgtFitnessVar = tgt_fitness_var; 512 526 PGADebugExited("PGASetTgtFitnessVariance"); … … 534 548 PGADebugEntered("PGASetVarTol"); 535 549 PGAFailIfSetUp("PGASetVarTol"); 550 if(var_tol < 0){ 551 PGAError(ctx,"Variance Tolerance Invalid, should be positive quantity", PGA_FATAL, PGA_DOUBLE, (void *) &var_tol); 552 } 536 553 ctx->ga.VarTol = var_tol; 537 554 PGADebugExited("PGASetVarTol"); … … 560 577 PGADebugEntered("PGASetTgtElapsedTime"); 561 578 PGAFailIfSetUp("PGASetTgtElapsedTime"); 579 if(tgt_elapsed_time < 0){ 580 PGAError(ctx,"Invalid Time of execution, cannot be a negative quantity", PGA_FATAL, PGA_DOUBLE, (void*) &tgt_elapsed_time); 581 } 562 582 ctx->ga.TgtElapsedTime = tgt_elapsed_time; 563 583 PGADebugExited("PGASetTgtElapsedTime");
Note: See TracChangeset
for help on using the changeset viewer.