Ignore:
Timestamp:
Sep 27, 2008, 1:58:13 AM (16 years ago)
Author:
liveletlive
Message:

Changes Made: Vanilla restart added, no modifications can be made to existing parameters in the middle of a run. Only mutation creates a new population on restart.
New configuration options added: MutationandCrossover? option. amount to be mutated made configurable. configration for (not)allowing duplicate strings added. app-qdot and simple modified to keep pace with these changes.

File:
1 edited

Legend:

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

    r1154 r1166  
    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*/
    2425    int stpcriteria;     /*stoppage criteria <=> PGASetStoppingRuleType()*/
    2526    int randnumseed;  /*Random Number Seed <=> PGASetRandomSeed()*/
    2627    double mutnrate;     /*Mutation Rate <=> PGASetMutationProb()*/
     28    double mutnValue;     /*use this value while mutating*/
    2729    double crossovrate;  /*Crossover Rate <=> PGASetCrossoverProb();*/
     30    int allowdup;        /*Allow duplicate strings in the population or not*/
     31    int mutnandcrossover;/*By default strings that do not undergo crossover undergo mutation, this option allows strings to crossover and be mutated*/
    2832} PgapackData;
    2933
     
    5862  {"-operation", &RpOption_Oper, Rp_Offset(PgapackData,operation)},
    5963  {"-poprepl", &RpOption_PopRepl, Rp_Offset(PgapackData,popRepl)},
     64  {"-numReplPerPop",RP_OPTION_INT,Rp_Offset(PgapackData,numReplPerPop)},
    6065  {"-popsize", RP_OPTION_INT, Rp_Offset(PgapackData,popSize)},
    6166  {"-mutnrate",RP_OPTION_DOUBLE,Rp_Offset(PgapackData,mutnrate)},
     67  {"-mutnValue",RP_OPTION_DOUBLE,Rp_Offset(PgapackData,mutnValue)},
    6268  {"-crossovrate",RP_OPTION_DOUBLE,Rp_Offset(PgapackData,crossovrate)},
    6369  {"-randnumseed",RP_OPTION_INT,Rp_Offset(PgapackData,randnumseed)},
    6470  {"-stpcriteria",&RpOption_StpCriteria,Rp_Offset(PgapackData,stpcriteria)},
     71  {"-allowdup",RP_OPTION_BOOLEAN,Rp_Offset(PgapackData,allowdup)},
     72  {"-mutnandcrossover",RP_OPTION_BOOLEAN,Rp_Offset(PgapackData,mutnandcrossover)},
    6573  {NULL, NULL, 0}
    6674};
     
    104112    dataPtr->popRepl = PGA_POPREPL_BEST;
    105113    dataPtr->popSize = 200;
     114    dataPtr->numReplPerPop = (dataPtr->popSize)/10; /*10% replaced by default, change to whatever value you need*/
    106115    dataPtr->crossovrate = 0.85;
    107116    dataPtr->mutnrate = 0.05; /*by default in PGAPack 1/stringlength*/
     117    dataPtr->mutnValue = 0.01;/*value of this number will be changed by plus/minus hundredth of its current value*/
    108118    dataPtr->randnumseed = 1; /*should be a number greater than one, PGAPack requires it*/
    109119    dataPtr->stpcriteria = PGA_STOP_NOCHANGE;
     120    dataPtr->allowdup = PGA_FALSE; /*Do not allow duplicate strings by default*/
     121    dataPtr->mutnandcrossover = PGA_FALSE;/*do not allow mutation and crossover to take place on the same string by default*/
    110122    return (ClientData)dataPtr;
    111123}
    112124
    113125int pgapack_abort = 0;
     126int pgapack_restart_user_action = 0;
    114127
    115128/*
     
    136149    pgapack_abort = 0;          /* FALSE */
    137150    PGASetAbortVar(&pgapack_abort);
     151    PGASetRestartUserAction(&pgapack_restart_user_action);
    138152
    139153    ctx = PGACreate(&argc, argv, PGA_DATATYPE_USER, envPtr->numParams,
     
    145159    PGASetStoppingRuleType(ctx, dataPtr->stpcriteria);
    146160    PGASetMutationProb(ctx,dataPtr->mutnrate);
     161    PGASetMutationRealValue(ctx,dataPtr->mutnValue);
    147162    PGASetCrossoverProb(ctx,dataPtr->crossovrate);
    148163    PGASetRandomSeed(ctx,dataPtr->randnumseed);
    149164    PGASetCrossoverType(ctx, PGA_CROSSOVER_UNIFORM);
     165    PGASetNoDuplicatesFlag(ctx,dataPtr->allowdup);
     166    PGASetMutationAndCrossoverFlag(ctx,dataPtr->mutnandcrossover);
     167    PGASetNumReplaceValue(ctx,dataPtr->numReplPerPop);
    150168
    151169
     
    342360
    343361    int n, ival,tempmr;
     362    double mutnVal;
    344363    RpOptimEnv *envPtr;
    345364    RpOptimParam *paramPtr;
     
    358377                if(numPtr->mutnrate!=PARAM_NUM_UNSPEC_MUTN_RATE){
    359378                        tempmr = numPtr->mutnrate;
     379                        mutnVal = numPtr->mutnValue;
    360380                }else{
    361381                        tempmr = mr;
     382                        mutnVal = PGAGetMutationRealValue(ctx);
    362383                }
    363384                if (PGARandomFlip(ctx, tempmr)) {
     
    367388                        /* bump the value up/down a little, randomly */
    368389                        if (PGARandomFlip(ctx, 0.5)) {
    369                             paramPtr[n].value.dval += 0.1*paramPtr[n].value.dval;
     390                            paramPtr[n].value.dval += mutnVal*paramPtr[n].value.dval; /*Made the mutation amount configurable*/
    370391                        } else {
    371                             paramPtr[n].value.dval -= 0.1*paramPtr[n].value.dval;
     392                            paramPtr[n].value.dval -= mutnVal*paramPtr[n].value.dval;
    372393                        }
    373394                        /* make sure the resulting value is still in bounds */
Note: See TracChangeset for help on using the changeset viewer.