📄 firstbitea.html
字号:
</td></tr></table><a NAME="engine"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE ><tr><td><tt><font color="#009900"><b> </b>/////////////////////////////////////<br><b> </b>// selection and replacement<br><b> </b>////////////////////////////////////<br></font></tt></td></tr></table><a NAME="select"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE ><tr><td><tt><font color="#009900"><b> </b>// The robust tournament selection<br><b> eoDetTournamentSelect<Indi> selectOne(T_SIZE); </b>// T_SIZE in [2,POP_SIZE]<br><a NAME="select_encapsulate"></a><b> </b>// is now encapsulated in a eoSelectPerc (entage)<br><b> eoSelectPerc<Indi> select(selectOne);</b>// by default rate==1<br></font></tt></td></tr></table><a NAME="replace"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE ><tr><td><tt><font color="#009900"><b> </b>// And we now have the full slection/replacement - though with <br><b> </b>// no replacement (== generational replacement) at the moment :-)<br><b> eoNoReplacement<Indi> replace; </b><br></font></tt></td></tr></table><a NAME="operators"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE ><tr><td><tt><font color="#993399"><b> </b>//////////////////////////////////////<br><b> </b>// The variation operators<br><b> </b>//////////////////////////////////////<br></font></tt></td></tr></table><a NAME="crossover"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE ><tr><td><tt><font color="#993399"><b> </b>// 1-point crossover for bitstring<br><b> eo1PtBitXover<Indi> xover1;</b><br><b> </b>// uniform crossover for bitstring<br><b> eoUBitXover<Indi> xoverU;</b><br><b> </b>// 2-pots xover<br><b> eoNPtsBitXover<Indi> xover2(2);</b><br><b> </b>// Combine them with relative rates<br><b> eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);</b><br><b> xover.add(xoverU, URate);</b><br><b> xover.add(xover2, twoPointsRate, true);</b><br></font></tt></td></tr></table><a NAME="mutation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE ><tr><td><tt><font color="#993399"><b> </b><br><b> </b>// standard bit-flip mutation for bitstring<br><b> eoBitMutation<Indi> mutationBitFlip(P_MUT_PER_BIT);</b><br><b> </b>// mutate exactly 1 bit per individual<br><b> eoDetBitFlip<Indi> mutationOneBit; </b><br><b> </b>// Combine them with relative rates<br><b> eoPropCombinedMonOp<Indi> mutation(mutationBitFlip, bitFlipRate);</b><br><b> mutation.add(mutationOneBit, oneBitRate, true);</b><br><b> </b><br><a NAME="transform"></a><b> </b>// The operators are encapsulated into an eoTRansform object<br><b> eoSGATransform<Indi> transform(xover, CROSS_RATE, mutation, MUT_RATE);</b><br></font></tt></td></tr></table><a NAME="stop"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE ><tr><td><tt><font color="#3366FF"></font></tt></td></tr></table><a NAME="checkpoint"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE ><tr><td><tt><font color="#3366FF"><b> </b>//////////////////////////////////////<br><b> </b>// termination conditions: use more than one<br><b> </b>/////////////////////////////////////<br><b> </b>// stop after MAX_GEN generations<br><b> eoGenContinue<Indi> genCont(MAX_GEN);</b><br><b> </b>// do MIN_GEN gen., then stop after STEADY_GEN gen. without improvement<br><b> eoSteadyFitContinue<Indi> steadyCont(MIN_GEN, STEADY_GEN);</b><br><b> </b>// stop when fitness reaches a target (here VEC_SIZE)<br><b> eoFitContinue<Indi> fitCont(0);</b><br><b> </b>// do stop when one of the above says so<br><b> eoCombinedContinue<Indi> continuator(genCont);</b><br><b> continuator.add(steadyCont);</b><br><b> continuator.add(fitCont);</b><br></font></tt></td></tr></table><a NAME="generation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE ><tr><td><tt><font color="#FF6666"><b> </b>/////////////////////////////////////////<br><b> </b>// the algorithm<br><b> </b>////////////////////////////////////////<br><b> </b>// Easy EA requires <br><b> </b>// selection, transformation, eval, replacement, and stopping criterion<br><b> eoEasyEA<Indi> gga(continuator, eval, select, transform, replace);</b><br><b> </b>// Apply algo to pop - that's it!<br><b> gga(pop);</b><br><b> </b><br></font></tt></td></tr></table><a NAME="output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE ><tr><td><tt><font color="#3366FF"><b> </b>// Print (sorted) intial population<br><b> pop.sort();</b><br><b> cout << "FINAL Population\n" << pop << endl;</b><br></font></tt></td></tr></table><a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE ><tr><td><tt><font color="#993300"><b>}</b><br>// A main that catches the exceptions<br><b>int main(int argc, char **argv)</b><br><b>{</b><br><b>#ifdef _MSC_VER</b><br><b> </b>// rng.reseed(42);<br><b> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</b><br><b> flag |= _CRTDBG_LEAK_CHECK_DF;</b><br><b> _CrtSetDbgFlag(flag);</b><br>// _CrtSetBreakAlloc(100);<br><b>#endif</b><br><b> try</b><br><b> {</b><br><b> main_function(argc, argv);</b><br><b> }</b><br><b> catch(exception& e)</b><br><b> {</b><br><b> cout << "Exception: " << e.what() << '\n';</b><br><b> }</b><br><b> return 1;</b><br><b>}</b><br></font></font></font></td></tr></table><hr WIDTH="100%"><a href="eoLesson2.html">Back to Lesson 2</a> - <a href="eoTutorial.html">Tutorialmain page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Basedpage</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 -->Lastmodified: Sun Nov 19 22:26:27 2000<!-- hhmts end --></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -