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
00035
00036 sptr = state->getRegistry()->getEntry("FloatingPoint.dimension");
00037
00038
00039
00040
00041 uint dim = *((uint*) sptr.get());
00042
00043
00044
00045
00046
00047
00048
00049 if(isCocoInitialized_) {
00050 fgeneric_finalize();
00051 }
00052
00053 ParamStruct params = fgeneric_getDefaultPARAMS();
00054 strcpy(params.dataPath, cocoFolder_.c_str());
00055
00056
00057 params.DIM = dim;
00058 params.funcId = iFunction_;
00059
00060 params.instanceId = 1;
00061
00062
00063 fgeneric_initialize(params);
00064
00065 coco_optimum_ = fgeneric_ftarget() - params.precision;
00066 isCocoInitialized_ = true;
00067
00068 return true;
00069 }
00070
00071
00072 FitnessP FunctionMinEvalOp::evaluate(IndividualP individual)
00073 {
00074
00075
00076 FitnessP fitness (new FitnessMin);
00077
00078
00079
00080
00081 FloatingPoint::FloatingPoint* gen = (FloatingPoint::FloatingPoint*) individual->getGenotype().get();
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 double value = 0;
00092
00093
00094
00095
00096
00097
00098 value = fgeneric_evaluate(&(gen->realValue[0]));
00099
00100 value -= coco_optimum_;
00101
00102 fitness->setValue(value);
00103 return fitness;
00104 }