• Main Page
  • Modules
  • Classes
  • Files
  • File List

D:/Projekt/ECF_trunk/examples/FunctionMin/FunctionMinEvalOp_coco.cpp

00001 #include <ecf/ECF.h>
00002 #include "FunctionMinEvalOp.h"
00003 
00004 // COCO
00005 #include "bbobStructures.h" /* Include all declarations for BBOB calls */
00006 double coco_optimum;
00007 bool coco_initialized = false;
00008 
00009 
00010 
00011 void FunctionMinEvalOp::registerParameters(StateP state)
00012 {
00013     state->getRegistry()->registerEntry("function", (voidP) (new uint(1)), ECF::UINT);
00014 }
00015 
00016 
00017 bool FunctionMinEvalOp::initialize(StateP state)
00018 {
00019     voidP sptr = state->getRegistry()->getEntry("function"); // get parameter value
00020     iFunction_ = *((uint*) sptr.get()); // convert from voidP to user defined type
00021 
00022     sptr = state->getRegistry()->getEntry("FloatingPoint.dimension");
00023     uint dim = *((uint*) sptr.get());
00024 
00025     //
00026     // COCO
00027     //
00028     if(coco_initialized) {
00029         fgeneric_finalize();
00030     }
00031     ParamStruct params = fgeneric_getDefaultPARAMS();
00032 
00033     /* set DIM, funcId, instanceId to initialize BBOB fgeneric */
00034     params.DIM = dim;
00035     params.funcId = iFunction_;
00036     params.instanceId = 1;
00037 
00038     /* call the BBOB initialization */
00039     fgeneric_initialize(params);
00040     coco_optimum = fgeneric_ftarget();
00041     coco_initialized = true;
00042 
00043 
00044     return true;
00045 }
00046 
00047 
00048 FitnessP FunctionMinEvalOp::evaluate(IndividualP individual)
00049 {
00050     // evaluation creates a new fitness object using a smart pointer
00051     // in our case, we try to minimize the function value, so we use FitnessMin fitness (for minimization problems)
00052     FitnessP fitness (new FitnessMin);
00053 
00054     // we define FloatingPoint as the only genotype (in the configuration file)
00055     FloatingPoint::FloatingPoint* gen = (FloatingPoint::FloatingPoint*) individual->getGenotype().get();
00056     // (you can also use boost smart pointers:)
00057     //FloatingPointP gen = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (individual->getGenotype());
00058 
00059     // alternative encoding: Binary Genotype
00060     //Binary::Binary* gen = (Binary::Binary*) individual->getGenotype().get();
00061     //BinaryP gen = boost::dynamic_pointer_cast<Binary::Binary> (individual->getGenotype());
00062 
00063     // we implement the fitness function 'as is', without any translation
00064     // the number of variables is read from the genotype itself (size of 'realValue' vactor)
00065     double realTemp = 0, value = 0;
00066 
00067 
00068     //
00069     // COCO
00070     //
00071     value = fgeneric_evaluate(&(gen->realValue[0]));
00072     value -= coco_optimum;
00073 
00074     fitness->setValue(value);
00075     return fitness;
00076 }

Generated on Tue Nov 4 2014 13:04:32 for ECF by  doxygen 1.7.1