Changeset 1272


Ignore:
Timestamp:
Feb 4, 2009 10:27:21 AM (12 years ago)
Author:
liveletlive
Message:

Committing additions made for including time of execution as a stoppage criteria.
also committing some changes to pgapack.h required to make these changes in stoppage criteria.
This code is yet untested, and will be tested once some more test benches are added.

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

Legend:

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

    r1202 r1272  
    137137#define PGA_STOP_NOCHANGE       2    /* Stop: no change in best string    */
    138138#define PGA_STOP_TOOSIMILAR     4    /* Stop: homogeneous population      */
     139#define PGA_STOP_AV_FITNESS     5    /* Stop: if within a certain % of target av.fitness per pop.*/
     140#define PGA_STOP_BEST_FITNESS   6    /* Stop: if best fitness in a pop is within % of target best fitness*/
     141#define PGA_STOP_VARIANCE       7        /* Stop: if variance of fitness in pop is within % of target variance */
     142#define PGA_STOP_TIMEELAPSED    8        /* Stop: if elapsed time >= target*/
    139143
    140144/*****************************************
     
    145149#define PGA_CROSSOVER_UNIFORM   3    /* Uniform   crossover                */
    146150#define PGA_CROSSOVER_SBX               4    /* Simulated Binary crossover                 */
    147 
     151#define PGA_CROSSOVER_TRIANGULAR 5   /* Triangular Crossover*/
    148152/*****************************************
    149153*            SELECTION                   *
     
    252256    int PopSize;             /* Number of strings to use                  */
    253257    int StringLen;           /* string lengths                            */
     258    double TgtFitnessVal;                /* Target Fitness, best or average depending on stpg criteria*/
     259    double FitnessTol;           /* Min Fitness Tolerance to be achieved for stoppage*/
     260    double TgtFitnessVar;       /* Target Fitness Variance for stoppage */
     261    double VarTol;                       /* Tolerance for variance to be achieved for stoppage*/       
     262    double TgtElapsedTime;   /* Max Execution time of GA before stoppage */
    254263    int StoppingRule;        /* Termination Criteria                      */
    255264    int MaxIter;             /* Maximum number of iterations to run       */
     
    338347     double Online;
    339348     double Average;
     349     double Variance;
    340350     double Best;
    341351     time_t starttime;
     
    799809void PGASetMaxNoChangeValue(PGAContext *ctx, int max_no_change);
    800810void PGASetMaxSimilarityValue(PGAContext *ctx, int max_similarity);
     811void PGASetTgtFitnessVal(PGAContext *ctx, double tgt_fitness_val);
     812void PGASetFitnessTol(PGAContext *ctx,double fitness_tol);
     813void PGASetTgtFitnessVariance(PGAContext *ctx,double tgt_fitness_var);
     814void PGASetVarTol(PGAContext *ctx,double var_tol);
     815void PGASetTgtElapsedTime(PGAContext *ctx,double tgt_elapsed_time);
    801816
    802817/*****************************************
  • trunk/packages/optimizer/src/pgapack/pgapack/source/create.c

    r1271 r1272  
    459459    if ( ctx->ga.MaxSimilarity      == PGA_UNINITIALIZED_INT)
    460460         ctx->ga.MaxSimilarity       = 95;
     461         
     462    if (ctx->ga.TgtFitnessVal           == PGA_UNINITIALIZED_DOUBLE){
     463         ctx->ga.TgtFitnessVal          = 0;
     464    }
     465   
     466    if (ctx->ga.FitnessTol                      == PGA_UNINITIALIZED_DOUBLE){
     467         ctx->ga.FitnessTol                     = 0;
     468    }
     469   
     470    if (ctx->ga.VarTol                          == PGA_UNINITIALIZED_DOUBLE){
     471         ctx->ga.VarTol                         = 0;
     472    }
     473   
     474    if (ctx->ga.TgtFitnessVar           == PGA_UNINITIALIZED_DOUBLE){
     475         ctx->ga.TgtFitnessVar          = 0;
     476    }
     477   
     478    if (ctx->ga.TgtElapsedTime          == PGA_UNINITIALIZED_DOUBLE){
     479         ctx->ga.TgtElapsedTime         = 0;
     480    }     
    461481
    462482    if ( ctx->ga.NumReplace         == PGA_UNINITIALIZED_INT)
  • trunk/packages/optimizer/src/pgapack/pgapack/source/parallel.c

    r1271 r1272  
    7070#include "pgapack.h"
    7171#include <setjmp.h>
    72 #include <time.h>
    7372
    7473extern jmp_buf pgapack_jmpbuf;
  • trunk/packages/optimizer/src/pgapack/pgapack/source/stop.c

    r1271 r1272  
    7171
    7272#include "pgapack.h"
     73#include <time.h>
    7374
    7475int *pgapack_abortPtr = NULL;
     
    144145{
    145146    int done = PGA_FALSE;
    146     double diff;
     147    double diff, process_execution_time;
     148    time_t endtime;
    147149
    148150    PGADebugEntered("PGACheckStoppingConditions");
     
    162164        if(((ctx->ga.StoppingRule & PGA_STOP_AV_FITNESS) == PGA_STOP_AV_FITNESS)){
    163165                if(ctx->ga.TgtFitnessVal == PGA_UNINITIALIZED_DOUBLE){
    164                         fprintf(stderr,"Uninitialized Value 'Target Average'");
     166                        PGAError(ctx,"Uninitialized Value 'Target Average'",PGA_FATAL, PGA_DOUBLE, (void *)&(ctx->ga.TgtFitnessVal));
    165167                        done |= PGA_TRUE;
    166168                }else{
    167169                        diff = ((ctx->ga.TgtFitnessVal - ctx->rep.Average)/(ctx->ga.TgtFitnessVal))*100;
    168                         if(fabs(diff) <= ctx->ga.FitnessTol){
     170                        if(fabs(diff) <= fabs((double)ctx->ga.FitnessTol)){
    169171                                done |= PGA_TRUE;
    170172                        }
     
    174176        if(((ctx->ga.StoppingRule & PGA_STOP_BEST_FITNESS) == PGA_STOP_BEST_FITNESS)){
    175177                if(ctx->ga.TgtFitnessVal == PGA_UNINITIALIZED_DOUBLE){
    176                         fprintf(stderr,"Uninitialized Value 'Target Best Fitness'");
     178                        PGAError(ctx,"Undefined Value 'Target Best Fitness'", PGA_FATAL, PGA_DOUBLE, (void *) &(ctx->ga.TgtFitnessVal));
    177179                        done |= PGA_TRUE;
    178180                }else{
    179181                        diff =(((double)ctx->ga.TgtFitnessVal -(double)ctx->rep.Best)/((double)ctx->ga.TgtFitnessVal))*100;
    180                         if(fabs(diff) <= ctx->ga.FitnessTol){
     182                        if(fabs(diff) <= fabs((double)ctx->ga.FitnessTol)){
    181183                                done |= PGA_TRUE;
    182184                        }
     
    186188        if(((ctx->ga.StoppingRule & PGA_STOP_VARIANCE) == PGA_STOP_VARIANCE)){
    187189                if(ctx->ga.TgtFitnessVar == PGA_UNINITIALIZED_DOUBLE){
    188                         fprintf(stderr,"Uninitialized Value 'Target Fitness Variance'");
     190                        PGAError(ctx,"Undefined Value 'Target Fitness Variance'",PGA_FATAL,PGA_DOUBLE, (void *)&(ctx->ga.TgtFitnessVar));
    189191                        done |= PGA_TRUE;
    190192                }else{
    191193                        diff =(((double)ctx->ga.TgtFitnessVar -(double)ctx->rep.Variance)/((double)ctx->ga.TgtFitnessVar))*100;
    192                         if(fabs(diff) <= ctx->ga.VarTol){
     194                        if(fabs(diff) <= fabs((double)ctx->ga.VarTol)){
    193195                                done |= PGA_TRUE;
    194196                        }
     
    197199       
    198200        if(((ctx->ga.StoppingRule & PGA_STOP_TIMEELAPSED) == PGA_STOP_TIMEELAPSED)){
    199                 //TODO :GTG Add code for setting initial time and current time and comparing
    200                 done |= PGA_TRUE;
     201                endtime = time(NULL);
     202                process_execution_time = difftime(endtime, (time_t)ctx->rep.starttime);
     203                if(ctx->ga.TgtElapsedTime == PGA_UNINITIALIZED_DOUBLE){
     204                        PGAError(ctx,"Undefined target time of execution",PGA_FATAL,PGA_DOUBLE,(void *)&(ctx->ga.TgtElapsedTime));
     205                }
     206                if(((double)process_execution_time/60) >= ((double)ctx->ga.TgtElapsedTime)){
     207                        done |= PGA_TRUE;
     208                }
    201209        }
    202210
     
    482490        PGADebugEntered("PGASetFitnessTol");
    483491    PGAFailIfSetUp("PGASetFitnessTol");
     492    if(fitness_tol < 0){
     493        PGAError(ctx,"Fitness tolerance invalid. Should be a positive quantity.\n",PGA_FATAL,PGA_DOUBLE,(void *)&fitness_tol);
     494    }
    484495        ctx->ga.FitnessTol = fitness_tol;
    485496        PGADebugExited("PGASetFitnessTol");
     
    509520        PGADebugEntered("PGASetTgtFitnessVariance");
    510521    PGAFailIfSetUp("PGASetTgtFitnessVariance");
     522    if(tgt_fitness_var < 0){
     523        PGAError(ctx,"Fitness variance invalid. Should be a positive quantity.\n",PGA_FATAL,PGA_DOUBLE,(void *)&tgt_fitness_var);
     524    }
    511525        ctx->ga.TgtFitnessVar = tgt_fitness_var;
    512526        PGADebugExited("PGASetTgtFitnessVariance");
     
    534548        PGADebugEntered("PGASetVarTol");
    535549    PGAFailIfSetUp("PGASetVarTol");
     550    if(var_tol < 0){
     551        PGAError(ctx,"Variance Tolerance Invalid, should be positive quantity", PGA_FATAL, PGA_DOUBLE, (void *) &var_tol);
     552    }
    536553        ctx->ga.VarTol = var_tol;
    537554        PGADebugExited("PGASetVarTol");
     
    560577        PGADebugEntered("PGASetTgtElapsedTime");
    561578    PGAFailIfSetUp("PGASetTgtElapsedTime");
     579    if(tgt_elapsed_time < 0){
     580        PGAError(ctx,"Invalid Time of execution, cannot be a negative quantity", PGA_FATAL, PGA_DOUBLE, (void*) &tgt_elapsed_time);
     581    }
    562582        ctx->ga.TgtElapsedTime = tgt_elapsed_time;
    563583        PGADebugExited("PGASetTgtElapsedTime");
Note: See TracChangeset for help on using the changeset viewer.