00001 #include <ecf/ECF.h>
00002 #include "FunctionMinEvalOp.h"
00003
00004
00005 #include "./bbob/bbobStructures.h"
00006 #include <string.h>
00007 extern int enableOutput;
00008
00009
00010 void FunctionMinEvalOp::registerParameters(StateP state)
00011 {
00012 state->getRegistry()->registerEntry("coco.function", (voidP) (new uint(1)), ECF::UINT,
00013 "sets the COCO objective function (default: 1)");
00014 state->getRegistry()->registerEntry("coco.instance", (voidP) (new uint(1)), ECF::UINT,
00015 "set instance no. for COCO function (default: 1)");
00016 state->getRegistry()->registerEntry("coco.enableoutput", (voidP) (new uint(0)), ECF::UINT,
00017 "enable COCO folder output (default: 0/no)");
00018 state->getRegistry()->registerEntry("coco.folder", (voidP) (new std::string("")), ECF::STRING,
00019 "sets the COCO output folder (default: none)");
00020 state->getRegistry()->registerEntry("coco.algorithm", (voidP) (new std::string("")), ECF::STRING,
00021 "set algorithm name for post processing (default: none)");
00022 state->getRegistry()->registerEntry("coco.comments", (voidP) (new std::string("")), ECF::STRING,
00023 "set algorithm description for post processing (default: none)");
00024 }
00025
00026
00027 bool FunctionMinEvalOp::initialize(StateP state)
00028 {
00029 if(experimentMode_)
00030 return true;
00031
00032
00033 if(isCocoInitialized_) {
00034 fgeneric_finalize();
00035 }
00036
00037 voidP sptr = state->getRegistry()->getEntry("coco.function");
00038 iFunction_ = *((uint*) sptr.get());
00039
00040 sptr = state->getRegistry()->getEntry("coco.instance");
00041 cocoInstance_ = *((uint*) sptr.get());
00042
00043
00044 if(state->getRegistry()->isModified("coco.folder")) {
00045 sptr = state->getRegistry()->getEntry("coco.folder");
00046 cocoFolder_ = *((std::string*) sptr.get());
00047 }
00048
00049
00050 if(!enableOutput) {
00051 sptr = state->getRegistry()->getEntry("coco.enableoutput");
00052 enableOutput = *((uint*) sptr.get());
00053 }
00054
00055
00056
00057
00058
00059 sptr = state->getRegistry()->getEntry("FloatingPoint.dimension");
00060
00061
00062
00063 uint dim = *((uint*) sptr.get());
00064
00065
00066
00067
00068
00069
00070 ParamStruct params = fgeneric_getDefaultPARAMS();
00071 strcpy(params.dataPath, cocoFolder_.c_str());
00072
00073
00074 params.DIM = dim;
00075 params.funcId = iFunction_;
00076
00077 params.instanceId = cocoInstance_;
00078
00079
00080 sptr = state->getRegistry()->getEntry("coco.algorithm");
00081 cocoAlgName_ = *((std::string*) sptr.get());
00082 strcpy(params.algName, cocoAlgName_.c_str());
00083
00084
00085 sptr = state->getRegistry()->getEntry("coco.comments");
00086 cocoAlgComments_ = *((std::string*) sptr.get());
00087 strcpy(params.comments, cocoAlgComments_.c_str());
00088
00089
00090 fgeneric_initialize(params);
00091
00092 coco_optimum_ = fgeneric_ftarget() - params.precision;
00093 isCocoInitialized_ = true;
00094
00095 return true;
00096 }
00097
00098
00099 FitnessP FunctionMinEvalOp::evaluate(IndividualP individual)
00100 {
00101
00102
00103 FitnessP fitness (new FitnessMin);
00104
00105
00106
00107
00108 FloatingPoint::FloatingPoint* gen = (FloatingPoint::FloatingPoint*) individual->getGenotype().get();
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 double value = 0;
00119
00120
00121
00122
00123
00124
00125 value = fgeneric_evaluate(&(gen->realValue[0]));
00126
00127 value -= coco_optimum_;
00128
00129 fitness->setValue(value);
00130 return fitness;
00131 }