added eoEpsMOEA support
This commit is contained in:
parent
29816fc197
commit
d78387591b
4 changed files with 259 additions and 8 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue