// from now on, you do not need to modify
anything
// though you CAN add things to the checkpointing
(see tutorial)
// now build the eoGenOp:
// to simulate SGA (crossover
with proba pCross + mutation with proba pMut
// we must construct
//
a sequential combination of
//
with proba 1, a proportional combination of
//
a QuadCopy and our crossover
//
with proba pMut, our mutation
// but of course you're free
to use any smart combination you could think of
// especially, if you have
to use eoBinOp rather than eoQuad Op youùll have
// to modify that part
//
First read the individual level parameters
eoValueParam<double>&
pCrossParam = _parser.createParam(0.6, "pCross", "Probability of Crossover",
'C', "Variation Operators" );
//
minimum check
if ( (pCrossParam.value()
< 0) || (pCrossParam.value() > 1) )
throw runtime_error("Invalid pCross");
eoValueParam<double>&
pMutParam = _parser.createParam(0.1, "pMut", "Probability of Mutation",
'M', "Variation Operators" );
//
minimum check
if ( (pMutParam.value()
< 0) || (pMutParam.value() > 1) )
throw runtime_error("Invalid pMut");
// the crossover - with probability
pCross
eoProportionalOp<Indi> * propOp
= new eoProportionalOp<Indi> ;
_state.storeFunctor(propOp);
eoQuadOp<Indi> *ptQuad = new
eoQuadCloneOp<Indi>;
_state.storeFunctor(ptQuad);
propOp->add(*propXover, pCrossParam.value());
//
crossover, with proba pcross
propOp->add(*ptQuad, 1-pCrossParam.value());
//
nothing, with proba 1-pcross
// now the sequential
eoSequentialOp<Indi> *op = new
eoSequentialOp<Indi>;
_state.storeFunctor(op);
op->add(*propOp, 1.0); // always
do combined crossover
op->add(*propMutation, pMutParam.value());
//
then mutation, with proba pmut
// that's it - return a reference
return *op;
}
#endif |