Ignore:
Timestamp:
Sep 27, 2008 1:58:13 AM (14 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.

Location:
trunk/packages/optimizer/src
Files:
4 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 */
  • trunk/packages/optimizer/src/rp_optimizer.c

    r1154 r1166  
    115115    numPtr->max = DBL_MAX;
    116116    numPtr->mutnrate = PARAM_NUM_UNSPEC_MUTN_RATE; /*Unspecified by default, should result in global mutn rate being applied*/
     117    numPtr->mutnValue = 0.01; /* value of this number will be changed by plus/minus hundredth of its current value*/
    117118    numPtr->randdist = RAND_NUMBER_DIST_GAUSSIAN ;/*Gaussian by default*/
    118119    numPtr->stddev = 1;
  • trunk/packages/optimizer/src/rp_optimizer.h

    r1154 r1166  
    4848 */
    4949typedef enum {
    50     RP_OPTIM_SUCCESS=0, RP_OPTIM_UNKNOWN, RP_OPTIM_FAILURE, RP_OPTIM_ABORTED
     50    RP_OPTIM_SUCCESS=0, RP_OPTIM_UNKNOWN, RP_OPTIM_FAILURE, RP_OPTIM_ABORTED, RP_OPTIM_RESTARTED
    5151} RpOptimStatus;
    5252
     
    107107    double max;                     /* optimization constraint: max value */
    108108    double mutnrate;                    /* independently sets mutation rate for each parameter*/
     109    double mutnValue;               /* on mutation bumps up/down the value by val (+-) mutnValue*val */
    109110    int randdist;                       /* gaussian or uniform distribution*/
    110111    int strictmin;                                      /* whether a strict min is to be applied for gauss. rand. numbers*/
  • trunk/packages/optimizer/src/rp_optimizer_tcl.c

    r1154 r1166  
    1717
    1818extern int pgapack_abort;
     19extern int pgapack_restart_user_action;
    1920
    2021/*
     
    5758  {"-max", RP_OPTION_DOUBLE, Rp_Offset(RpOptimParamNumber,max)},
    5859  {"-mutnrate",RP_OPTION_DOUBLE, Rp_Offset(RpOptimParamNumber,mutnrate)},
     60  {"-mutnValue",RP_OPTION_DOUBLE, Rp_Offset(RpOptimParamNumber,mutnValue)},
    5961  {"-randdist",&RpOption_RandDist,Rp_Offset(RpOptimParamNumber,randdist)},
    6062  {"-strictmin",RP_OPTION_BOOLEAN,Rp_Offset(RpOptimParamNumber,strictmin)},
     
    8385#endif
    8486
    85 extern int pgapack_abort;
     87
    8688extern void PGARuntimeDataTableInit();
    8789extern void PGARuntimeDataTableDeInit();
     
    394396        pgapack_abort = value;
    395397        return TCL_OK;
    396     } else if (*option == 'g' && strcmp(option,"get") == 0) {
     398    }else if (*option == 'r' && strcmp(option,"restart") == 0){
     399                int value;
     400        if (objc < 3) {
     401            Tcl_WrongNumArgs(interp, 1, objv, "restart bool");
     402            return TCL_ERROR;
     403        }
     404                if (Tcl_GetBooleanFromObj(interp, objv[2], &value) != TCL_OK) {
     405                return TCL_ERROR;
     406                }
     407                pgapack_restart_user_action = value;
     408                return TCL_OK;   
     409        }else if (*option == 'g' && strcmp(option,"get") == 0) {
    397410        /*
    398411         * OPTION:  get ?globPattern? ?-option?
Note: See TracChangeset for help on using the changeset viewer.