00001 #include <ecf/ECF.h>
00002 #include "FunctionMinEvalOp.h"
00003 #include <float.h>
00004 #include <fstream>
00005
00006
00007
00008 extern void cec14_test_func(double *, double *, int, int, int);
00009 double *OShift,*M,*y,*z,*x_bound;
00010 int ini_flag=0,n_flag,func_flag,*SS;
00011
00012
00013 void FunctionMinEvalOp::registerParameters(StateP state)
00014 {
00015 state->getRegistry()->registerEntry("cec.function", (voidP) (new uint(1)), ECF::UINT,
00016 "Sets the CEC test function number, 1-30 (default: 1)");
00017 }
00018
00019
00020 bool FunctionMinEvalOp::initialize(StateP state)
00021 {
00022 voidP sptr = state->getRegistry()->getEntry("cec.function");
00023 iFunction_ = *((uint*) sptr.get());
00024
00025
00026 if(iFunction_ < 1 || iFunction_ > 30) {
00027 ECF_LOG_ERROR(state, "CEC EvalOp: There are only 30 test functions in this test suite!");
00028 throw("");
00029 }
00030
00031
00032 std::string fileName("input_data/M_" + uint2str(iFunction_) + "_D2.txt");
00033 ifstream m_file(fileName.c_str());
00034 if (!m_file) {
00035 std::string msg("\nError: the CEC input data folder must be in path to run the experiments.\n");
00036 msg += "DOWNLOAD the required data and place them in \"input_data\" folder from http://web.mysites.ntu.edu.sg/epnsugan/PublicSite/Shared%20Documents/CEC-2014/cec14-c-code.zip.\n";
00037 msg += "Since the data size is 35MB, it is NOT included in the ECF package.";
00038 ECF_LOG_ERROR(state, msg);
00039 throw("");
00040 }
00041
00042 return true;
00043 }
00044
00045
00046 FitnessP FunctionMinEvalOp::evaluate(IndividualP individual)
00047 {
00048
00049
00050 FitnessP fitness (new FitnessMin);
00051
00052
00053 FloatingPoint::FloatingPoint* gen = (FloatingPoint::FloatingPoint*) individual->getGenotype().get();
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 double realTemp = 0, value = 0;
00064
00065 int n = (int) gen->realValue.size();
00066
00067
00068 cec14_test_func(&gen->realValue[0], &value, n, 1, iFunction_);
00069
00070 fitness->setValue(value);
00071 return fitness;
00072 }