added eoEpsMOEA support

This commit is contained in:
maartenkeijzer 2007-09-04 15:30:42 +00:00
commit d78387591b
4 changed files with 259 additions and 8 deletions

View file

@ -8,11 +8,12 @@
using namespace std;
// Look: overloading the maximization without overhead (thing can be inlined)
class MinimizingFitnessTraits : public eoMOFitnessTraits
class MinimizingFitnessTraits
{
public :
static double maximizing(int) { return -1; }
static unsigned nObjectives() { return 2; }
static double direction(unsigned) { return -1; }
static double tol() { return 1e-9; }
};
typedef eoMOFitness<MinimizingFitnessTraits> fitness_type;
@ -45,12 +46,27 @@ class Mutate : public eoMonOp<eoDouble>
}
};
class Cross : public eoBinOp<eoDouble> {
bool operator()(eoDouble& _eo, const eoDouble& eo2)
{
for (unsigned i = 0; i < chromsize; ++i)
{
if (rng.flip(0.5)) {
_eo.value[i] = eo2.value[i];
}
}
return true;
}
};
class Eval : public eoEvalFunc<eoDouble>
{
void operator()(eoDouble& _eo)
{
vector<double> x(_eo.value, _eo.value + chromsize);
fitness_type f;
fitness_type f(0.0);
for (unsigned i = 0; i < chromsize; ++i)
{
@ -121,6 +137,7 @@ void the_main(int argc, char* argv[])
Init init;
Eval simple_eval;
Mutate mutate;
Cross cross;
eoParser parser(argc, argv);
eoState state;
@ -138,6 +155,7 @@ void the_main(int argc, char* argv[])
// One general operator
eoProportionalOp<eoDouble> opsel;
opsel.add(mutate, 1.0);
opsel.add(cross, 1.0);
// the breeder
eoGeneralBreeder<eoDouble> breeder(select, opsel);