📄 make_op_onemax.html
字号:
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE ><tr><td><a NAME="crossover"></a><tt><font color="#993399"><b> </b>// Optional: A second(and third, and ...) crossover </font></tt><br><tt><font color="#993399"><b> </b> // of course you must create the corresponding classes</font></tt><br><tt><font color="#993399"><b> </b> //and all ***MUST*** derive from eoQuadOp<Indi></font></tt><p><tt><font color="#993399"><b> </b> /* Uncomment if necessary -and replicate as many time as you need</font></tt><br><tt><font color="#993399"> cross = new eoOneMaxSecondCrossover<Indi>(varType _anyVariable); </font></tt><br><tt><font color="#993399"> _state.storeFunctor(cross);</font></tt><br><tt><font color="#993399"> double cross2Rate = _parser.createParam(1.0, "cross2Rate", "Relative ratefor crossover 2", '2', "Variation Operators").value(); </font></tt><br><tt><font color="#993399"> propXover.add(*cross, cross2Rate); </font></tt><br><tt><font color="#993399"> */</font></tt><br><tt><font color="#993399"><b> </b> // if you want some gentleoutput, the last one shoudl be like</font></tt><br><tt><font color="#993399"><b> </b> // propXover.add(*cross,crossXXXRate, true);</font></tt><br> </td></tr></table><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><br><tt><font color="#993399"><b> </b> // the mutation: same story</font></tt><br><tt><font color="#993399"><b> </b> ////////////////</font></tt><br><tt><font color="#993399"><b> </b> // you can have more than one- combined in a proportional way</font></tt><p><tt><font color="#993399"><b> </b> // for each mutation, </font></tt><br><tt><font color="#993399"><b> </b> // - define the mutator object</font></tt><br><tt><font color="#993399"><b> </b> // - read its rate from theparser</font></tt><br><tt><font color="#993399"><b> </b> // - add it to the proportionalcombination</font></tt><p><tt><font color="#993399"><b> </b> // a first mutation </font></tt><br><a NAME="mut_ctor"></a><tt><font color="#993399"><b>eoMonOp<Indi>*mut = new eoOneMaxMutation<Indi></b> /* </font><font color="#FF6666">(varType _anyVariable)</font><font color="#993399"> */;</font></tt><br><b><tt><font color="#993399"> _state.storeFunctor(mut);</font></tt></b><br><tt><font color="#993399"><b> </b> // its relative rate in thecombination</font></tt><br><b><tt><font color="#993399"> double mut1Rate = _parser.createParam(1.0,"mut1Rate", "Relative rate for mutation 1", '1', "Variation Operators").value();</font></tt></b><br><tt><font color="#993399"><b> </b> // and the creation of thecombined operator with this one</font></tt><br><b><tt><font color="#993399"> eoPropCombinedMonOp<Indi> *propMutation= new eoPropCombinedMonOp<Indi>(*mut, mut1Rate);</font></tt></b><br><b><tt><font color="#993399"> _state.storeFunctor(propMutation);</font></tt></b><br> </td></tr></table><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE ><tr><td><a NAME="mutation"></a><tt><font color="#993399"><b> </b>// Optional: A second(and third, and ...) mutation with their rates</font></tt><br><tt><font color="#993399"><b> </b> // of course you must create the corresponding classes</font></tt><br><tt><font color="#993399"><b> </b> //and all ***MUST*** derive from eoMonOp<Indi></font></tt><p><tt><font color="#993399"><b> </b> /* Uncomment if necessary -and replicate as many time as you need</font></tt><br><tt><font color="#993399"> mut = new eoOneMaxSecondMutation<Indi>(varType _anyVariable);</font></tt><br><tt><font color="#993399"> _state.storeFunctor(mut);</font></tt><br><tt><font color="#993399"> double mut2Rate = _parser.createParam(1.0, "mut2Rate", "Relative rate formutation 2", '2', "Variation Operators").value(); </font></tt><br><tt><font color="#993399"> propMutation.add(*mut, mut2Rate); </font></tt><br><tt><font color="#993399"> */</font></tt><br><tt><font color="#993399"><b> </b> // if you want some gentleoutput, the last one shoudl be like</font></tt><br><tt><font color="#993399"><b> </b> // propMutation.add(*mut,mutXXXRate, true);</font></tt><p><tt><font color="#993399"><b> </b> // end of crossover and mutationdefinitions</font></tt><br> </td></tr></table><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><br><tt><font color="#993399">// from now on, you do not need to modifyanything</font></tt><br><tt><font color="#993399">// though you CAN add things to the checkpointing(see tutorial)</font></tt><p><tt><font color="#993399"><b> </b> // now build the eoGenOp:</font></tt><br><tt><font color="#993399"><b> </b> // to simulate SGA (crossoverwith proba pCross + mutation with proba pMut</font></tt><br><tt><font color="#993399"><b> </b> // we must construct</font></tt><br><tt><font color="#993399"><b> </b> // a sequential combination of</font></tt><br><tt><font color="#993399"><b> </b> // with proba 1, a proportional combination of </font></tt><br><tt><font color="#993399"><b> </b> // a QuadCopy and our crossover</font></tt><br><tt><font color="#993399"><b> </b> // with proba pMut, our mutation</font></tt><p><tt><font color="#993399"><b> </b> // but of course you're freeto use any smart combination you could think of</font></tt><br><tt><font color="#993399"><b> </b> // especially, if you haveto use eoBinOp rather than eoQuad Op youùll have</font></tt><br><tt><font color="#993399"><b> </b> // to modify that part</font></tt><p><a NAME="donottouch"></a><tt><font color="#993399"><b> </b> //First read the individual level parameters</font></tt><br><b><tt><font color="#993399"> eoValueParam<double>&pCrossParam = _parser.createParam(0.6, "pCross", "Probability of Crossover",'C', "Variation Operators" );</font></tt></b><br><tt><font color="#993399"><b> </b> //minimum check</font></tt><br><b><tt><font color="#993399"> if ( (pCrossParam.value()< 0) || (pCrossParam.value() > 1) )</font></tt></b><br><b><tt><font color="#993399"> throw runtime_error("Invalid pCross");</font></tt></b><p><b><tt><font color="#993399"> eoValueParam<double>&pMutParam = _parser.createParam(0.1, "pMut", "Probability of Mutation",'M', "Variation Operators" );</font></tt></b><br><tt><font color="#993399"><b> </b> //minimum check</font></tt><br><b><tt><font color="#993399"> if ( (pMutParam.value()< 0) || (pMutParam.value() > 1) )</font></tt></b><br><b><tt><font color="#993399"> throw runtime_error("Invalid pMut");</font></tt></b><p><tt><font color="#993399"><b> </b> // the crossover - with probabilitypCross</font></tt><br><b><tt><font color="#993399"> eoProportionalOp<Indi> * propOp= new eoProportionalOp<Indi> ;</font></tt></b><br><b><tt><font color="#993399"> _state.storeFunctor(propOp);</font></tt></b><br><b><tt><font color="#993399"> eoQuadOp<Indi> *ptQuad = neweoQuadCloneOp<Indi>;</font></tt></b><br><b><tt><font color="#993399"> _state.storeFunctor(ptQuad);</font></tt></b><br><tt><font color="#993399"><b> propOp->add(*propXover, pCrossParam.value());</b>//crossover, with proba pcross</font></tt><br><tt><font color="#993399"><b> propOp->add(*ptQuad, 1-pCrossParam.value());</b>//nothing, with proba 1-pcross</font></tt><p><tt><font color="#993399"><b> </b> // now the sequential</font></tt><br><b><tt><font color="#993399"> eoSequentialOp<Indi> *op = neweoSequentialOp<Indi>;</font></tt></b><br><b><tt><font color="#993399"> _state.storeFunctor(op);</font></tt></b><br><tt><font color="#993399"><b> op->add(*propOp, 1.0); </b>// alwaysdo combined crossover</font></tt><br><tt><font color="#993399"><b> op->add(*propMutation, pMutParam.value());</b>//then mutation, with proba pmut</font></tt><p><tt><font color="#993399"><b> </b> // that's it - return a reference</font></tt><br><b><tt><font color="#993399"> return *op;</font></tt></b><br><b><tt><font color="#993399">}</font></tt></b><p><b><tt><font color="#993399">#endif</font></tt></b></td></tr></table><hr WIDTH="100%"><a href="eoLesson5.html">Back to Lesson 5</a> - <a href="eoTutorial.html">Tutorialmain page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-uppage</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EOdocumentation</a></font><hr><address><a href="mailto:marc.schoenauer@inria.fr">Marc Schoenauer</a></address><br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Fri May3 08:06:20 2002<!-- hhmts end --></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -