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

D:/Projekt/ECF_trunk/examples/CEC/FunctionMinEvalOp.cpp

00001 #include <ecf/ECF.h>
00002 #include "FunctionMinEvalOp.h"
00003 #include <float.h>
00004 
00005 
00006 // CEC
00007 extern void cec14_test_func(double *, double *,int,int,int);
00008 double *OShift,*M,*y,*z,*x_bound;
00009 int ini_flag=0,n_flag,func_flag,*SS;
00010 
00011 
00012 void FunctionMinEvalOp::registerParameters(StateP state)
00013 {
00014     state->getRegistry()->registerEntry("cec.function", (voidP) (new uint(1)), ECF::UINT, 
00015         "Sets the CEC test function number (default: 1)");
00016 }
00017 
00018 
00019 bool FunctionMinEvalOp::initialize(StateP state)
00020 {
00021     voidP sptr = state->getRegistry()->getEntry("cec.function"); // get parameter value
00022     iFunction_ = *((uint*) sptr.get()); // convert from voidP to user defined type
00023 
00024     // check function index (CEC does not abort on invalid id)
00025     if(iFunction_ < 1 || iFunction_ > 30) {
00026         ECF_LOG_ERROR(state, "CEC EvalOp: There are only 30 test functions in this test suite!");
00027         throw("");
00028     }
00029 
00030 
00031     // CEC initialization
00032 
00033     return true;
00034 }
00035 
00036 
00037 FitnessP FunctionMinEvalOp::evaluate(IndividualP individual)
00038 {
00039     // evaluation creates a new fitness object using a smart pointer
00040     // in our case, we try to minimize the function value, so we use FitnessMin fitness (for minimization problems)
00041     FitnessP fitness (new FitnessMin);
00042 
00043     // we define FloatingPoint as the only genotype (in the configuration file)
00044     FloatingPoint::FloatingPoint* gen = (FloatingPoint::FloatingPoint*) individual->getGenotype().get();
00045     // (you can also use boost smart pointers:)
00046     //FloatingPointP gen = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (individual->getGenotype());
00047 
00048     // alternative encoding: Binary Genotype
00049     //Binary::Binary* gen = (Binary::Binary*) individual->getGenotype().get();
00050     //BinaryP gen = boost::dynamic_pointer_cast<Binary::Binary> (individual->getGenotype());
00051 
00052     // we implement the fitness function 'as is', without any translation
00053     // the number of variables is read from the genotype itself (size of 'realValue' vactor)
00054     double realTemp = 0, value = 0;
00055 
00056     int n = (int) gen->realValue.size();
00057 
00058     cec14_test_func(&gen->realValue[0], &value, n, 1, iFunction_);
00059 
00060     fitness->setValue(value);
00061     return fitness;
00062 }

Generated on Thu Jul 10 2014 14:13:40 for ECF by  doxygen 1.7.1