Changeset 1271 for trunk/packages/optimizer/src/plugin_pgapack.c
- Timestamp:
- Feb 3, 2009, 3:41:13 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/optimizer/src/plugin_pgapack.c
r1202 r1271 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 int numReplPerPop; /* number of new strings created per population, the rest are the best strings from the previous population*/ 25 double tgtFitness; /* target fitness for stoppage --either best or average*/ 26 double fitnessTol; /* %diff betn tgt fit. and current population fit. -- best or avg*/ 27 double tgtVariance; /* target fitness variance*/ 28 double varianceTol; /* tolerance : %diff betn tgt and current pop. fitness variance*/ 29 double tgtElapsedTime; /* target stoppage time from start of execution*/ 25 30 int stpcriteria; /*stoppage criteria <=> PGASetStoppingRuleType()*/ 26 31 int randnumseed; /*Random Number Seed <=> PGASetRandomSeed()*/ 27 double mutnrate; /*Mutation Rate <=> PGASetMutat ionProb()*/32 double mutnrate; /*Mutation Rate <=> PGASetMutatuionProb()*/ 28 33 double mutnValue; /*use this value while mutating*/ 29 34 double crossovrate; /*Crossover Rate <=> PGASetCrossoverProb();*/ 30 int crossovtype; /*Crossover Type <=> UNIFORM/SBX (SBX Defined from Deb and Kumar 1995)*/35 int crossovtype; /*Crossover Type <=> UNIFORM/SBX/TRIANGULAR (SBX Defined from Deb and Kumar 1995)*/ 31 36 int allowdup; /*Allow duplicate strings in the population or not*/ 32 37 int mutnandcrossover;/*By default strings that do not undergo crossover undergo mutation, this option allows strings to crossover and be mutated*/ … … 78 83 {"-crossovtype",&RpOption_CrossovType,Rp_Offset(PgapackData,crossovtype)}, 79 84 {"-randnumseed",RP_OPTION_INT,Rp_Offset(PgapackData,randnumseed)}, 85 {"-tgtFitness",RP_OPTION_DOUBLE,Rp_Offset(PgapackData,tgtFitness)}, 86 {"-fitnessTol",RP_OPTION_DOUBLE,Rp_Offset(PgapackData,fitnessTol)}, 87 {"-tgtVariance",RP_OPTION_DOUBLE,Rp_Offset(PgapackData,tgtVariance)}, 88 {"-varianceTol",RP_OPTION_DOUBLE,Rp_Offset(PgapackData,varianceTol)}, 89 {"-tgtElapsedTime",RP_OPTION_DOUBLE,Rp_Offset(PgapackData,tgtElapsedTime)}, 80 90 {"-stpcriteria",&RpOption_StpCriteria,Rp_Offset(PgapackData,stpcriteria)}, 81 91 {"-allowdup",RP_OPTION_BOOLEAN,Rp_Offset(PgapackData,allowdup)}, … … 129 139 dataPtr->mutnValue = 0.01;/*value of this number will be changed by plus/minus hundredth of its current value*/ 130 140 dataPtr->randnumseed = 1; /*should be a number greater than one, PGAPack requires it*/ 141 dataPtr->tgtFitness = PGA_UNINITIALIZED_DOUBLE; 142 dataPtr->fitnessTol = PGA_UNINITIALIZED_DOUBLE; /*by default stop only if desired fitness is exactly achieved*/ 143 dataPtr->tgtVariance = PGA_UNINITIALIZED_DOUBLE; 144 dataPtr->varianceTol = PGA_UNINITIALIZED_DOUBLE; /* by default stop only if desired variance is exactly achieved*/ 145 dataPtr->tgtElapsedTime = PGA_UNINITIALIZED_DOUBLE; /* stop if 100 minutes have elapsed since start of optim run*/ 131 146 dataPtr->stpcriteria = PGA_STOP_NOCHANGE; 132 147 dataPtr->allowdup = PGA_FALSE; /*Do not allow duplicate strings by default*/ … … 170 185 PGASetPopSize(ctx, dataPtr->popSize); 171 186 PGASetPopReplaceType(ctx, dataPtr->popRepl); 187 PGASetTgtFitnessVal(ctx,dataPtr->tgtFitness); 188 PGASetFitnessTol(ctx,dataPtr->fitnessTol); 189 PGASetTgtFitnessVariance(ctx,dataPtr->tgtVariance); 190 PGASetVarTol(ctx,dataPtr->varianceTol); 191 PGASetTgtElapsedTime(ctx,dataPtr->tgtElapsedTime); 172 192 PGASetStoppingRuleType(ctx, dataPtr->stpcriteria); 173 193 PGASetMutationProb(ctx,dataPtr->mutnrate); … … 477 497 PgapackData *dataPtr; 478 498 /*declare variables for SBX*/ 479 double ui,beta,eta,powVal; 499 double ui,beta,eta = 1.5,powVal; 500 double slope = 3,xi; 480 501 481 502 envPtr = PgapGetEnvForContext(ctx); … … 502 523 case RP_OPTIMPARAM_NUMBER: 503 524 ui = PGARandom01(ctx,0); 504 eta = 1.5;/*We can adjust eta later....keeping it 1.5 for now*/505 525 powVal = 1/(eta+1); 506 526 if(ui<=0.5){ … … 516 536 } 517 537 break; 538 539 540 case PGA_CROSSOVER_TRIANGULAR: 541 xi = 1/sqrt(slope); 542 switch(parent1[n].type){ 543 case RP_OPTIMPARAM_NUMBER: 544 ui = PGARandom01(ctx,0); 545 546 if(ui<=0.5){ 547 beta = sqrt(2*ui/slope); 548 }else{ 549 beta = 2*xi-sqrt(2*(1-ui)/slope); 550 } 551 child1[n].value.dval = beta + (parent1[n].value.dval - xi) ; 552 child2[n].value.dval = beta + (parent2[n].value.dval - xi) ; 553 break; 554 default: 555 panic("Bad Optim Param Type in PgapCrossover()"); 556 } 557 break; 558 559 518 560 default: 519 561 panic("bad parameter type in PgapCrossover()"); … … 743 785 *ptr = PGA_CROSSOVER_SBX; 744 786 } 787 else if (strcmp(val,"triangular")== 0 ){ 788 *ptr = PGA_CROSSOVER_TRIANGULAR; 789 } 745 790 else { 746 791 Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), … … 766 811 Tcl_SetResult(interp, "sbx", TCL_STATIC); 767 812 break; 813 case PGA_CROSSOVER_TRIANGULAR: 814 Tcl_SetResult(interp,"triangular",TCL_STATIC); 815 break; 768 816 default: 769 817 Tcl_SetResult(interp, "???", TCL_STATIC); … … 833 881 834 882 /* 835 * ====================================================================== 836 * OPTION: -stpcriteria <=> PGA_STOP_MAXITER / PGA_STOP_NOCHANGE / PGA_STOP_TOOSIMILAR 837 * ====================================================================== 883 * ================================================================================================================== 884 * OPTION: -stpcriteria <=> PGA_STOP_MAXITER / PGA_STOP_NOCHANGE / PGA_STOP_TOOSIMILAR / 885 * PGA_STOP_AV_FITNESS / PGA_STOP_BEST_FITNESS / PGA_STOP_VARIANCE / PGA_STOP_TIMEELAPSED 886 * ================================================================================================================== 838 887 */ 839 888 int … … 855 904 *ptr = PGA_STOP_TOOSIMILAR; 856 905 } 906 else if (strcmp(val,"avfitness") == 0){ 907 *ptr = PGA_STOP_AV_FITNESS; 908 } 909 else if (strcmp(val,"bestfitness") == 0){ 910 *ptr = PGA_STOP_BEST_FITNESS; 911 } 912 else if (strcmp(val,"varoffitness") == 0){ 913 *ptr = PGA_STOP_VARIANCE; 914 } 915 else if (strcmp(val,"timeelapsed") == 0){ 916 *ptr = PGA_STOP_TIMEELAPSED; 917 } 918 857 919 else { 858 920 Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), 859 "bad value \"", val, "\": should be maxiter, nochange or toosimilar",921 "bad value \"", val, "\": should be one of the following: maxiter, nochange, toosimilar, avfitness, bestfitness, varoffitness or timeelapsed", 860 922 (char*)NULL); 861 923 return TCL_ERROR; … … 881 943 Tcl_SetResult(interp, "toosimilar", TCL_STATIC); 882 944 break; 945 case PGA_STOP_AV_FITNESS: 946 Tcl_SetResult(interp, "avfitness", TCL_STATIC); 947 break; 948 case PGA_STOP_BEST_FITNESS: 949 Tcl_SetResult(interp, "bestfitness", TCL_STATIC); 950 break; 951 case PGA_STOP_VARIANCE: 952 Tcl_SetResult(interp, "varoffitness", TCL_STATIC); 953 break; 954 case PGA_STOP_TIMEELAPSED: 955 Tcl_SetResult(interp, "timeelapsed", TCL_STATIC); 956 break; 883 957 default: 884 958 Tcl_SetResult(interp, "???", TCL_STATIC);
Note: See TracChangeset
for help on using the changeset viewer.