Ignore:
Timestamp:
Oct 29, 2008, 12:16:26 PM (16 years ago)
Author:
liveletlive
Message:

Changes made to include the following items:
1) Hard restart
2) SBX
3) Random population replacement proportion
4) Definitions and macros for the above functions in pgapack.h

Location:
trunk/packages/optimizer/src/pgapack/pgapack
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/optimizer/src/pgapack/pgapack/include/pgapack.h

    r1178 r1202  
    144144#define PGA_CROSSOVER_TWOPT     2    /* Two point crossover                */
    145145#define PGA_CROSSOVER_UNIFORM   3    /* Uniform   crossover                */
     146#define PGA_CROSSOVER_SBX               4    /* Simulated Binary crossover                 */
    146147
    147148/*****************************************
     
    278279    double FitnessCmaxValue; /* Cmax value used to convert minimizations  */
    279280    double restartAlleleProb;/* prob of changing an allele in a restart   */
     281    double randreplprop;     /* proportion of randomly generated individuals per generation post initialization*/
    280282    int restart;             /* whether to use the restart operator       */
    281283    int restartFreq;         /* frequency with which to restart           */
     
    715717int PGAGetRandomSeed(PGAContext *ctx);
    716718void PGASetRandomSeed(PGAContext *ctx, int seed);
     719double PGAGetRandReplProp(PGAContext *ctx);
     720void PGASetRandReplProp(PGAContext *ctx, double randreplprop);
    717721
    718722/*****************************************
  • trunk/packages/optimizer/src/pgapack/pgapack/source/cross.c

    r816 r1202  
    266266        case PGA_CROSSOVER_TWOPT:
    267267        case PGA_CROSSOVER_UNIFORM:
     268        case PGA_CROSSOVER_SBX:
    268269            ctx->ga.CrossoverType = crossover_type;
    269270            break;
  • trunk/packages/optimizer/src/pgapack/pgapack/source/duplcate.c

    r816 r1202  
    198198                   PGA_DOUBLE, (void *) &mr );
    199199
    200     while (( changed == PGA_FALSE ) && (mr <= 1.0)) {
    201         if (ctx->fops.Mutation) {
    202             fp = ((p == PGA_TEMP1) || (p == PGA_TEMP2)) ? p : p+1;
    203             nflips = (*ctx->fops.Mutation)(&ctx, &fp, &pop, &mr);
    204         } else {
    205             nflips = (*ctx->cops.Mutation)( ctx, p, pop, mr );
    206         }
    207 
    208         if ( nflips > 0 )
    209             changed = PGA_TRUE;
    210         else
    211             mr = 1.1*mr;
     200/**TODO: GTG (Clear)I dont see why we need to wait for iterations to mutate?****/
     201/**TODO: can't we directly set mr = 1??**/
     202    while (changed == PGA_FALSE) {
     203                if (ctx->fops.Mutation) {
     204                    fp = ((p == PGA_TEMP1) || (p == PGA_TEMP2)) ? p : p+1;
     205                    nflips = (*ctx->fops.Mutation)(&ctx, &fp, &pop, &mr);
     206                } else {
     207                        nflips = (*ctx->cops.Mutation)( ctx, p, pop, mr );
     208                }
     209       
     210                if ( nflips > 0 )
     211                    changed = PGA_TRUE;
     212                else
     213                    mr = ( mr>1 ? 1 :1.1*mr);
     214                   
    212215    }
    213216
  • trunk/packages/optimizer/src/pgapack/pgapack/source/parallel.c

    r986 r1202  
    127127        if (rank == 0) {
    128128            Restarted = PGA_FALSE;
    129             if ((ctx->ga.restart == PGA_TRUE) &&
    130                 (ctx->ga.ItersOfSame % ctx->ga.restartFreq == 0)) {
    131                 ctx->ga.ItersOfSame++;
    132                 Restarted = PGA_TRUE;
    133                 PGARestart(ctx, PGA_OLDPOP, PGA_NEWPOP);
     129            if (PGARestartCondition(ctx)) {
     130                        Restarted = PGA_TRUE;
     131                        PGARestart(ctx, PGA_OLDPOP, PGA_NEWPOP);
    134132            } else {
    135                 PGASelect(ctx, PGA_OLDPOP);
    136                 CreateNewGeneration(ctx, PGA_OLDPOP, PGA_NEWPOP);
     133                        PGASelect(ctx, PGA_OLDPOP);
     134                        CreateNewGeneration(ctx, PGA_OLDPOP, PGA_NEWPOP);
    137135            }
    138136        }
  • trunk/packages/optimizer/src/pgapack/pgapack/source/pga.c

    r986 r1202  
    200200{
    201201    int i, j, n, m1, m2;
    202     int popsize, numreplace;
    203     double pc;
     202    int popsize, numreplace, randnumreplace;
     203    double pc, randreplprop;
    204204
    205205    PGADebugEntered("PGARunMutationAndCrossover");
     
    207207    popsize = PGAGetPopSize(ctx);
    208208    numreplace = PGAGetNumReplaceValue(ctx);
     209    randreplprop = PGAGetRandReplProp(ctx);
     210    randnumreplace = (int)randreplprop*popsize;
    209211    /*** first, copy n best strings (sorted by fitness) to new pop ***/
    210212    PGASortPop( ctx, oldpop );
    211     n = popsize - numreplace;
     213    n = popsize - numreplace - randnumreplace;
    212214    for ( i=0; i < n; i++ ) {
    213215        j = PGAGetSortedPopIndex( ctx, i );
     
    216218    pc = PGAGetCrossoverProb(ctx);
    217219    /*** reproduce to create the rest of the new population ***/
    218     while ( n < popsize) {
     220    while ( n < (popsize- randnumreplace)) {
    219221        m1 = PGASelectNextIndex( ctx );
    220222        m2 = PGASelectNextIndex( ctx );
     
    230232              n++;
    231233
    232               if ( n < popsize ) {
     234              if ( n < (popsize-randnumreplace) ) {
    233235              /*** mutate and copy second string to new population ***/
    234236              PGAMutate ( ctx, PGA_TEMP2, newpop);
     
    242244            PGACopyIndividual ( ctx, m1, oldpop, n, newpop );
    243245            n++;
    244             if ( n < ctx->ga.PopSize ) {
     246            if ( n < (popsize-randnumreplace) ) {
    245247                PGACopyIndividual ( ctx, m2, oldpop, n, newpop );
    246248                n++;
     
    248250       }
    249251    }
     252   
     253    if(randnumreplace > 0){
     254            while(n < popsize){
     255                PGACreateIndividual(ctx,n,newpop,PGA_TRUE);
     256                n++;
     257            }
     258    }
    250259
    251260    PGADebugExited("PGARunMutationAndCrossover");
     
    276285{
    277286    int i, j, n, m1, m2;
    278     int popsize, numreplace;
    279     double pc;
     287    int popsize, numreplace, randnumreplace;
     288    double pc, randreplprop;
    280289
    281290    PGADebugEntered("PGARunMutationOrCrossover");
     
    283292    popsize = PGAGetPopSize(ctx);
    284293    numreplace = PGAGetNumReplaceValue(ctx);
     294    randreplprop = PGAGetRandReplProp(ctx);
     295    randnumreplace = (int)randreplprop*popsize;
    285296    /*** first, copy n best strings (sorted by fitness) to new pop ***/
    286297    PGASortPop( ctx, oldpop );
    287     n = popsize - numreplace;
     298    n = popsize - numreplace - randnumreplace ;
    288299    for ( i=0; i < n; i++ ) {
    289300        j = PGAGetSortedPopIndex( ctx, i );
     
    292303    pc = PGAGetCrossoverProb(ctx);
    293304    /*** reproduce to create the rest of the new population ***/
    294     while ( n < popsize ) {
     305    while ( n < (popsize-randnumreplace) ) {
    295306        m1 = PGASelectNextIndex( ctx );
    296307        m2 = PGASelectNextIndex( ctx );
     
    305316            n++;
    306317
    307             if ( n < popsize )
     318            if ( n < (popsize-randnumreplace) )
    308319            {
    309320                 /*** copy second string to new population ***/
     
    323334             n++;
    324335
    325              if ( n < popsize ) {
     336             if ( n < (popsize-randnumreplace) ) {
    326337                  PGACopyIndividual(ctx, m2, oldpop, PGA_TEMP2, newpop);
    327338                  PGAMutate ( ctx, PGA_TEMP2, newpop );
     
    333344        }
    334345    }
     346   
     347    if(randnumreplace > 0){
     348            while(n < popsize){
     349                PGACreateIndividual(ctx,n,newpop,PGA_TRUE);
     350                n++;
     351            }
     352    }
    335353
    336354    PGADebugExited("PGARunMutationOrCrossover");
  • trunk/packages/optimizer/src/pgapack/pgapack/source/random.c

    r816 r1202  
    403403    PGADebugExited("PGASetRandomSeed");
    404404}
     405
     406/*****************************************************************************
     407 Category: Generation/Utility
     408 
     409 Inputs:
     410                ctx - context variable
     411                randreplaceprop - proportion of individuals to be replaced per generation randomly, post initialization
     412               
     413 Outputs:
     414                None
     415               
     416 Example:
     417        PGAContext *ctx;
     418        .
     419        .
     420        PGASetRandReplProp(ctx, 0.05);         
     421 ***************************************************************************/
     422void PGASetRandReplProp(PGAContext *ctx, double randreplprop){
     423        PGADebugEntered("PGASetRandReplProp");
     424        PGAFailIfSetUp("PGASetRandReplProp");
     425        if(randreplprop < 0 || randreplprop > 1){
     426                PGAError ( ctx, "PGASetRandReplProp: Invalid value set:",
     427                  PGA_FATAL, PGA_DOUBLE, (void *) &randreplprop);
     428        }else{
     429                ctx->ga.randreplprop = randreplprop;
     430        }
     431        PGADebugExited("PGASetRandReplProp");
     432}
     433
     434/*****************************************************************************
     435 Category: Generation/Utility
     436 
     437 Inputs:
     438                ctx - context variable
     439               
     440 Outputs:
     441                randreplprop - proportion of randomly generated individuals per population, post initialization
     442               
     443 Example:
     444        PGAContext *ctx;
     445        double randreplprop;
     446        .
     447        .
     448        randreplprop = PGAGetRandReplProp(ctx);         
     449 ***************************************************************************/
     450double PGAGetRandReplProp(PGAContext *ctx){
     451        PGADebugEntered("PGAGetRandReplProp");
     452        PGADebugExited("PGAGetRandReplProp");
     453        return ctx->ga.randreplprop;
     454}
Note: See TracChangeset for help on using the changeset viewer.