00001
00020 #include "problemtest.h"
00021 #include "functions.h"
00022 #include <cmath>
00023
00024 using namespace realea;
00025
00026 ProblemTest::ProblemTest(unsigned int dim) {
00027 m_ndim = dim;
00028 }
00029
00030 ProblemTest::~ProblemTest(void) {
00031 }
00032
00033 tFitness sphere_test(const tGen *x, int n)
00034 {
00035 int i;
00036 tFitness sum;
00037
00038 sum = 0.0;
00039 for (i = 0; i < n; i++) {
00040 sum += fabs(x[i]+i);
00041 }
00042
00043 return (sum);
00044 }
00045
00046
00047
00048 ProblemPtr ProblemTest::get(unsigned int fun) {
00049 ProblemPtr prob (new Problem());
00050 prob->setDimension(m_ndim);
00051 int ndim = m_ndim;
00052 double min = -2.5;
00053 double max = 3;
00054
00055 for (unsigned i = 0; i < m_ndim; ++i) {
00056 prob->setDomainValues(i, min, max, true);
00057 }
00058
00059 prob->setOptimize(0, 0);
00060 prob->setMaxEval(1000);
00061 prob->setMinimize();
00062
00063
00064 prob->setEval(sphere_test);
00065
00066 return prob;
00067 }