Ignore:
Timestamp:
Oct 29, 2008 12:16:26 PM (14 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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");
Note: See TracChangeset for help on using the changeset viewer.