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 state->getRegistry()->registerEntry("coco.enableoutput", (voidP) (new uint(0)), ECF::UINT);
00014 state->getRegistry()->registerEntry("coco.folder", (voidP) (new std::string("")), ECF::STRING);
00015 }
00016
00017
00018 bool FunctionMinEvalOp::initialize(StateP state)
00019 {
00020 voidP sptr = state->getRegistry()->getEntry("coco.function");
00021 iFunction_ = *((uint*) sptr.get());
00022
00023
00024 if(state->getRegistry()->isModified("coco.folder")) {
00025 sptr = state->getRegistry()->getEntry("coco.folder");
00026 cocoFolder_ = *((std::string*) sptr.get());
00027 }
00028
00029
00030 sptr = state->getRegistry()->getEntry("coco.enableoutput");
00031 enableOutput = *((uint*) sptr.get());
00032
00033
00034 sptr = state->getRegistry()->getEntry("FloatingPoint.dimension");
00035 uint dim = *((uint*) sptr.get());
00036
00037
00038
00039
00040
00041
00042
00043 if(isCocoInitialized_) {
00044 fgeneric_finalize();
00045 }
00046
00047 ParamStruct params = fgeneric_getDefaultPARAMS();
00048 strcpy(params.dataPath, cocoFolder_.c_str());
00049
00050
00051 params.DIM = dim;
00052 params.funcId = iFunction_;
00053
00054 params.instanceId = 1;
00055
00056
00057 fgeneric_initialize(params);
00058
00059 coco_optimum_ = fgeneric_ftarget() - params.precision;
00060 isCocoInitialized_ = true;
00061
00062 return true;
00063 }
00064
00065
00066 FitnessP FunctionMinEvalOp::evaluate(IndividualP individual)
00067 {
00068
00069
00070 FitnessP fitness (new FitnessMin);
00071
00072
00073 FloatingPoint::FloatingPoint* gen = (FloatingPoint::FloatingPoint*) individual->getGenotype().get();
00074
00075
00076
00077
00078
00079
00080
00081 double value = 0;
00082
00083
00084
00085
00086
00087
00088 value = fgeneric_evaluate(&(gen->realValue[0]));
00089
00090 value -= coco_optimum_;
00091
00092 fitness->setValue(value);
00093 return fitness;
00094 }