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
|
|
@ -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