⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 firstbitea.html

📁 这是linux下的进化计算的源代码。 === === === === === === === === === === === ===== check latest news at http:
💻 HTML
📖 第 1 页 / 共 2 页
字号:
</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>  &nbsp;</b>/////////////////////////////////////<br><b>  &nbsp;</b>// selection and replacement<br><b>  &nbsp;</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>  &nbsp;</b>// The robust tournament selection<br><b>  &nbsp;eoDetTournamentSelect&lt;Indi> selectOne(T_SIZE);  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// T_SIZE in [2,POP_SIZE]<br><a NAME="select_encapsulate"></a><b>  &nbsp;</b>// is now encapsulated in a eoSelectPerc (entage)<br><b>  &nbsp;eoSelectPerc&lt;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>  &nbsp;</b>// And we now have the full slection/replacement - though with <br><b>  &nbsp;</b>// no replacement (== generational replacement) at the moment :-)<br><b>  &nbsp;eoNoReplacement&lt;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>  &nbsp;</b>//////////////////////////////////////<br><b>  &nbsp;</b>// The variation operators<br><b>  &nbsp;</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>  &nbsp;</b>// 1-point crossover for bitstring<br><b>  &nbsp;eo1PtBitXover&lt;Indi> xover1;</b><br><b>  &nbsp;</b>// uniform crossover for bitstring<br><b>  &nbsp;eoUBitXover&lt;Indi> xoverU;</b><br><b>  &nbsp;</b>// 2-pots xover<br><b>  &nbsp;eoNPtsBitXover&lt;Indi> xover2(2);</b><br><b>  &nbsp;</b>// Combine them with relative rates<br><b>  &nbsp;eoPropCombinedQuadOp&lt;Indi> xover(xover1, onePointRate);</b><br><b>  &nbsp;xover.add(xoverU, URate);</b><br><b>  &nbsp;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>  &nbsp;</b><br><b>  &nbsp;</b>// standard bit-flip mutation for bitstring<br><b>  &nbsp;eoBitMutation&lt;Indi>  &nbsp;mutationBitFlip(P_MUT_PER_BIT);</b><br><b>  &nbsp;</b>// mutate exactly 1 bit per individual<br><b>  &nbsp;eoDetBitFlip&lt;Indi> mutationOneBit; </b><br><b>  &nbsp;</b>// Combine them with relative rates<br><b>  &nbsp;eoPropCombinedMonOp&lt;Indi> mutation(mutationBitFlip, bitFlipRate);</b><br><b>  &nbsp;mutation.add(mutationOneBit, oneBitRate, true);</b><br><b>  &nbsp;</b><br><a NAME="transform"></a><b>  &nbsp;</b>// The operators are  &nbsp;encapsulated into an eoTRansform object<br><b>  &nbsp;eoSGATransform&lt;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>  &nbsp;</b>//////////////////////////////////////<br><b>  &nbsp;</b>// termination conditions: use more than one<br><b>  &nbsp;</b>/////////////////////////////////////<br><b>  &nbsp;</b>// stop after MAX_GEN generations<br><b>  &nbsp;eoGenContinue&lt;Indi> genCont(MAX_GEN);</b><br><b>  &nbsp;</b>// do MIN_GEN gen., then stop after STEADY_GEN gen. without improvement<br><b>  &nbsp;eoSteadyFitContinue&lt;Indi> steadyCont(MIN_GEN, STEADY_GEN);</b><br><b>  &nbsp;</b>// stop when fitness reaches a target (here VEC_SIZE)<br><b>  &nbsp;eoFitContinue&lt;Indi> fitCont(0);</b><br><b>  &nbsp;</b>// do stop when one of the above says so<br><b>  &nbsp;eoCombinedContinue&lt;Indi> continuator(genCont);</b><br><b>  &nbsp;continuator.add(steadyCont);</b><br><b>  &nbsp;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>  &nbsp;</b>/////////////////////////////////////////<br><b>  &nbsp;</b>// the algorithm<br><b>  &nbsp;</b>////////////////////////////////////////<br><b>  &nbsp;</b>// Easy EA requires <br><b>  &nbsp;</b>// selection, transformation, eval, replacement, and stopping criterion<br><b>  &nbsp;eoEasyEA&lt;Indi> gga(continuator, eval, select, transform, replace);</b><br><b>  &nbsp;</b>// Apply algo to pop - that's it!<br><b>  &nbsp;gga(pop);</b><br><b>  &nbsp;</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>  &nbsp;</b>// Print (sorted) intial population<br><b>  &nbsp;pop.sort();</b><br><b>  &nbsp;cout &lt;&lt; "FINAL Population\n" &lt;&lt; pop &lt;&lt; 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>  &nbsp;</b>//  &nbsp;rng.reseed(42);<br><b>  &nbsp; &nbsp; &nbsp;int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</b><br><b>  &nbsp; &nbsp; &nbsp; &nbsp;flag |= _CRTDBG_LEAK_CHECK_DF;</b><br><b>  &nbsp; &nbsp; &nbsp;_CrtSetDbgFlag(flag);</b><br>//  &nbsp; &nbsp;_CrtSetBreakAlloc(100);<br><b>#endif</b><br><b>  &nbsp; &nbsp; &nbsp;try</b><br><b>  &nbsp; &nbsp; &nbsp;{</b><br><b>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;main_function(argc, argv);</b><br><b>  &nbsp; &nbsp; &nbsp;}</b><br><b>  &nbsp; &nbsp; &nbsp;catch(exception& e)</b><br><b>  &nbsp; &nbsp; &nbsp;{</b><br><b>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cout &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; '\n';</b><br><b>  &nbsp; &nbsp; &nbsp;}</b><br><b>  &nbsp; &nbsp; &nbsp;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 + -