Well, what do you know, major commit.
Changed the signature of eoMon, eoBin and eoQuadOp to return a bool, without invalidating fitness. Added a set of invalidators to take over that job (see for instance eoSGA and eoSGATransform how this can transparantly used) Derived eoState from eoFunctorStore (for convenience, from a design perspective this may sound wrong) Added a wrap_op function that does the wrapping for you (see eoOpContainer how this made this functor exceedingly less hairy). Checked all the tests removed the eoGeneric*Op family (not needed anymore) and of course changed all the operators to reflect the change (and found a few that didn't invalidate the fitness, thus really pointing out the advantage of the current approach)
This commit is contained in:
parent
17d55ae92b
commit
3a9b5a0e7e
30 changed files with 651 additions and 564 deletions
|
|
@ -10,11 +10,10 @@ DEPS = $(top_builddir)/src/libeo.a $(top_builddir)/src/utils/libeoutils.a
|
|||
|
||||
INCLUDES = -I$(top_builddir)/src
|
||||
LDADDS = $(top_builddir)/src/libeo.a $(top_builddir)/src/utils/libeoutils.a
|
||||
|
||||
CXXFLAGS = -g
|
||||
###############################################################################
|
||||
|
||||
bin_PROGRAMS = gprop
|
||||
|
||||
###############################################################################
|
||||
|
||||
gprop_SOURCES = gprop.cc
|
||||
|
|
|
|||
|
|
@ -109,11 +109,11 @@ mlp::set trn_set, val_set, tst_set;
|
|||
class eoChromMutation: public eoMonOp<Chrom>
|
||||
{
|
||||
public:
|
||||
void operator()(Chrom& chrom)
|
||||
bool operator()(Chrom& chrom)
|
||||
{
|
||||
mse::net tmp(chrom);
|
||||
tmp.train(trn_set, 10, 0, 0.001);
|
||||
chrom.invalidate();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ public:
|
|||
class eoChromXover: public eoQuadOp<Chrom>
|
||||
{
|
||||
public:
|
||||
void operator()(Chrom& chrom1, Chrom& chrom2)
|
||||
bool operator()(Chrom& chrom1, Chrom& chrom2)
|
||||
{
|
||||
chrom1.normalize();
|
||||
chrom2.desaturate();
|
||||
|
|
@ -132,8 +132,8 @@ public:
|
|||
mse::net tmp1(chrom1), tmp2(chrom2);
|
||||
tmp1.train(trn_set, 100, 0, 0.001);
|
||||
tmp2.train(trn_set, 100, 0, 0.001);
|
||||
chrom1.invalidate();
|
||||
chrom2.invalidate();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ void init_eoChromEvaluator(const unsigned& c, const unsigned& l, string s)
|
|||
uniform_generator<int> color(0, num_colors);
|
||||
generate(solution.begin(), solution.end(), color);
|
||||
}
|
||||
|
||||
|
||||
solution.fitness(eoChromEvaluator(solution));
|
||||
}
|
||||
|
||||
|
|
@ -143,14 +143,14 @@ public:
|
|||
class eoChromMutation: public eoMonOp<Chrom>
|
||||
{
|
||||
// many operators in one :(
|
||||
void operator()(Chrom& chrom)
|
||||
bool operator()(Chrom& chrom)
|
||||
{
|
||||
uniform_generator<unsigned> what(0, 2);
|
||||
uniform_generator<unsigned> position(0, chrom.size());
|
||||
|
||||
switch(what())
|
||||
{
|
||||
case 0:
|
||||
case 0:
|
||||
{
|
||||
// mutation
|
||||
uniform_generator<int> color(0, num_colors);
|
||||
|
|
@ -171,7 +171,7 @@ class eoChromMutation: public eoMonOp<Chrom>
|
|||
}
|
||||
}
|
||||
|
||||
chrom.invalidate();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -182,12 +182,11 @@ class eoChromMutation: public eoMonOp<Chrom>
|
|||
class eoChromXover: public eoQuadOp<Chrom>
|
||||
{
|
||||
public:
|
||||
void operator()(Chrom& chrom1, Chrom& chrom2)
|
||||
bool operator()(Chrom& chrom1, Chrom& chrom2)
|
||||
{
|
||||
uniform_generator<unsigned> position(0, chrom1.size());
|
||||
swap_ranges(chrom1.begin(), chrom1.begin() + position(), chrom2.begin());
|
||||
chrom1.invalidate();
|
||||
chrom2.invalidate();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -195,6 +194,6 @@ public:
|
|||
|
||||
#endif // mastermind_h
|
||||
|
||||
// Local Variables:
|
||||
// mode:C++
|
||||
// Local Variables:
|
||||
// mode:C++
|
||||
// End:
|
||||
|
|
|
|||
Reference in a new issue