Ignore:
Timestamp:
Feb 3, 2009 3:41:13 PM (15 years ago)
Author:
liveletlive
Message:

Changes made to API and pgapack for addition of new stoppage criteria. TIMEElapsed criteria is not yet added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/optimizer/src/plugin_pgapack.c

    r1202 r1271  
    2222    int popSize;         /* population size <=> PGASetPopSize() */
    2323    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*/
    2530    int stpcriteria;     /*stoppage criteria <=> PGASetStoppingRuleType()*/
    2631    int randnumseed;  /*Random Number Seed <=> PGASetRandomSeed()*/
    27     double mutnrate;     /*Mutation Rate <=> PGASetMutationProb()*/
     32    double mutnrate;     /*Mutation Rate <=> PGASetMutatuionProb()*/
    2833    double mutnValue;     /*use this value while mutating*/
    2934    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)*/
    3136    int allowdup;        /*Allow duplicate strings in the population or not*/
    3237    int mutnandcrossover;/*By default strings that do not undergo crossover undergo mutation, this option allows strings to crossover and be mutated*/
     
    7883  {"-crossovtype",&RpOption_CrossovType,Rp_Offset(PgapackData,crossovtype)},
    7984  {"-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)},
    8090  {"-stpcriteria",&RpOption_StpCriteria,Rp_Offset(PgapackData,stpcriteria)},
    8191  {"-allowdup",RP_OPTION_BOOLEAN,Rp_Offset(PgapackData,allowdup)},
     
    129139    dataPtr->mutnValue = 0.01;/*value of this number will be changed by plus/minus hundredth of its current value*/
    130140    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*/
    131146    dataPtr->stpcriteria = PGA_STOP_NOCHANGE;
    132147    dataPtr->allowdup = PGA_FALSE; /*Do not allow duplicate strings by default*/
     
    170185    PGASetPopSize(ctx, dataPtr->popSize);
    171186    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);
    172192    PGASetStoppingRuleType(ctx, dataPtr->stpcriteria);
    173193    PGASetMutationProb(ctx,dataPtr->mutnrate);
     
    477497    PgapackData *dataPtr;
    478498    /*declare variables for SBX*/
    479     double ui,beta,eta,powVal;
     499    double ui,beta,eta = 1.5,powVal;
     500    double slope = 3,xi;
    480501
    481502    envPtr = PgapGetEnvForContext(ctx);
     
    502523                                case RP_OPTIMPARAM_NUMBER:
    503524                                        ui = PGARandom01(ctx,0);
    504                                         eta = 1.5;/*We can adjust eta later....keeping it 1.5 for now*/
    505525                                        powVal = 1/(eta+1);
    506526                                        if(ui<=0.5){
     
    516536                        }
    517537                        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                       
    518560                default:
    519561                        panic("bad parameter type in PgapCrossover()");
     
    743785        *ptr = PGA_CROSSOVER_SBX;
    744786    }
     787    else if (strcmp(val,"triangular")== 0 ){
     788        *ptr = PGA_CROSSOVER_TRIANGULAR;
     789    }
    745790    else {
    746791        Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
     
    766811        Tcl_SetResult(interp, "sbx", TCL_STATIC);
    767812        break;
     813    case PGA_CROSSOVER_TRIANGULAR:
     814        Tcl_SetResult(interp,"triangular",TCL_STATIC);
     815        break;   
    768816    default:
    769817        Tcl_SetResult(interp, "???", TCL_STATIC);
     
    833881
    834882/*
    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 * ==================================================================================================================
    838887 */
    839888int
     
    855904        *ptr = PGA_STOP_TOOSIMILAR;
    856905    }
     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   
    857919    else {
    858920        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",
    860922            (char*)NULL);
    861923        return TCL_ERROR;
     
    881943        Tcl_SetResult(interp, "toosimilar", TCL_STATIC);
    882944        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;       
    883957    default:
    884958        Tcl_SetResult(interp, "???", TCL_STATIC);
Note: See TracChangeset for help on using the changeset viewer.