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

📄 firstrealea.html

📁 这是linux下的进化计算的源代码。 === === === === === === === === === === === ===== check latest news at http:
💻 HTML
📖 第 1 页 / 共 2 页
字号:
</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</font></tt><br><b><tt><font color="#009900">&nbsp;eoDetTournamentSelect&lt;Indi> selectOne(T_SIZE);</font></tt></b><br><a NAME="select_encapsulate"></a><tt><font color="#009900"><b> </b>//is now encapsulated in a eoSelectPerc (entage)</font></tt><br><tt><font color="#009900"><b>&nbsp;eoSelectPerc&lt;Indi> select(selectOne);</b>//by default rate==1</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 fullslection/replacement - though with&nbsp;</font></tt><br><tt><font color="#009900"><b>&nbsp;</b>// no replacement (== generationalreplacement) at the moment :-)</font></tt><br><b><tt><font color="#009900">&nbsp;eoNoReplacement&lt;Indi> replace;&nbsp;</font></tt></b></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>//////////////////////////////////////</font></tt><br><tt><font color="#993399"><b>&nbsp;</b>// The variation operators</font></tt><br><tt><font color="#993399"><b>&nbsp;</b>//////////////////////////////////////</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>// uniform chooce on segmentmade by the parents</font></tt><br><b><tt><font color="#993399">&nbsp;eoSegmentCrossover&lt;Indi> xoverS;</font></tt></b><br><tt><font color="#993399"><b>&nbsp;</b>// uniform choice in hypercubebuilt by the parents</font></tt><br><b><tt><font color="#993399">&nbsp;eoHypercubeCrossover&lt;Indi> xoverA;</font></tt></b><br><tt><font color="#993399"><b>&nbsp;</b>// Combine them with relativeweights</font></tt><br><b><tt><font color="#993399">&nbsp;eoPropCombinedQuadOp&lt;Indi> xover(xoverS,segmentRate);</font></tt></b><br><b><tt><font color="#993399">&nbsp;xover.add(xoverA, hypercubeRate,true);</font></tt></b></td></tr></table><a NAME="mutation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE ><tr><td><br><tt><font color="#993399"><b>&nbsp;</b>// offspring(i) uniformly chosenin [parent(i)-epsilon, parent(i)+epsilon]</font></tt><br><b><tt><font color="#993399">&nbsp;eoUniformMutation&lt;Indi>&nbsp;mutationU(EPSILON);&nbsp;</font></tt></b><br><tt><font color="#993399"><b>&nbsp;</b>// k (=1) coordinates of parentsare uniformly modified</font></tt><br><b><tt><font color="#993399">&nbsp;eoDetUniformMutation&lt;Indi>&nbsp;mutationD(EPSILON);&nbsp;</font></tt></b><br><tt><font color="#993399">&nbsp;// all coordinates of parents are normallymodified (stDev SIGMA)</font></tt><br><b><tt><font color="#993399">&nbsp;eoNormalMutation&lt;Indi>&nbsp;mutationN(SIGMA);&nbsp;</font></tt></b><br><tt><font color="#993399"><b>&nbsp;</b>// Combine them with relativeweights</font></tt><br><b><tt><font color="#993399">&nbsp;eoPropCombinedMonOp&lt;Indi> mutation(mutationU,uniformMutRate);</font></tt></b><br><b><tt><font color="#993399">&nbsp;mutation.add(mutationD, detMutRate);</font></tt></b><br><b><tt><font color="#993399">&nbsp;mutation.add(mutationN, normalMutRate,true);</font></tt></b><p><tt><font color="#993399"><b>&nbsp;</b>// The operators are&nbsp; encapsulatedinto an eoTRansform object</font></tt><br><b><tt><font color="#993399">&nbsp;eoSGATransform&lt;Indi> transform(xover,P_CROSS, mutation, P_MUT);</font></tt></b></td></tr></table><a NAME="stop"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE ><tr><td></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>//////////////////////////////////////</font></tt><br><tt><font color="#3366FF"><b>&nbsp;</b>// termination conditions: usemore than one</font></tt><br><tt><font color="#3366FF"><b>&nbsp;</b>/////////////////////////////////////</font></tt><br><tt><font color="#3366FF"><b>&nbsp;</b>// stop after MAX_GEN generations</font></tt><br><b><tt><font color="#3366FF">&nbsp;eoGenContinue&lt;Indi> genCont(MAX_GEN);</font></tt></b><br><tt><font color="#3366FF"><b>&nbsp;</b>// do MIN_GEN gen., then stopafter STEADY_GEN gen. without improvement</font></tt><br><b><tt><font color="#3366FF">&nbsp;eoSteadyFitContinue&lt;Indi> steadyCont(MIN_GEN,STEADY_GEN);</font></tt></b><br><tt><font color="#3366FF"><b>&nbsp;</b>// stop when fitness reachesa target (here VEC_SIZE)</font></tt><br><b><tt><font color="#3366FF">&nbsp;eoFitContinue&lt;Indi> fitCont(0);</font></tt></b><br><tt><font color="#3366FF"><b>&nbsp;</b>// do stop when one of the abovesays so</font></tt><br><b><tt><font color="#3366FF">&nbsp;eoCombinedContinue&lt;Indi> continuator(genCont);</font></tt></b><br><b><tt><font color="#3366FF">&nbsp;continuator.add(steadyCont);</font></tt></b><br><b><tt><font color="#3366FF">&nbsp;continuator.add(fitCont);</font></tt></b></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>/////////////////////////////////////////</font></tt><br><tt><font color="#FF6666"><b>&nbsp;</b>// the algorithm</font></tt><br><tt><font color="#FF6666"><b>&nbsp;</b>////////////////////////////////////////</font></tt><br><tt><font color="#FF6666"><b>&nbsp;</b>// Easy EA requires&nbsp;</font></tt><br><tt><font color="#FF6666"><b>&nbsp;</b>// selection, transformation,eval, replacement, and stopping criterion</font></tt><br><b><tt><font color="#FF6666">&nbsp;eoEasyEA&lt;Indi> gga(continuator,eval, select, transform, replace);</font></tt></b><br><tt><font color="#FF6666"><b>&nbsp;</b>// Apply algo to pop - that'sit!</font></tt><br><b><tt><font color="#FF6666">&nbsp;cout &lt;&lt; "\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Here we go\n\n";</font></tt></b><br><b><tt><font color="#FF6666">&nbsp;gga(pop);</font></tt></b><br>&nbsp;</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</font></tt><br><b><tt><font color="#3366FF">&nbsp;pop.sort();</font></tt></b><br><b><tt><font color="#3366FF">&nbsp;cout &lt;&lt; "FINAL Population\n"&lt;&lt; pop &lt;&lt; endl;</font></tt></b></td></tr></table><a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE ><tr><td><b><tt><font color="#993300">}</font></tt></b><br><tt><font color="#993300">// A main that catches the exceptions</font></tt><br><b><tt><font color="#993300">int main(int argc, char **argv)</font></tt></b><br><b><tt><font color="#993300">{</font></tt></b><br><b><tt><font color="#993300">#ifdef _MSC_VER</font></tt></b><br><tt><font color="#993300"><b>&nbsp;</b>//&nbsp; rng.reseed(42);</font></tt><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag|= _CRTDBG_LEAK_CHECK_DF;</font></tt></b><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; _CrtSetDbgFlag(flag);</font></tt></b><br><tt><font color="#993300">//&nbsp;&nbsp;&nbsp; _CrtSetBreakAlloc(100);</font></tt><br><b><tt><font color="#993300">#endif</font></tt></b><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; try</font></tt></b><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;main_function(argc, argv);</font></tt></b><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; catch(exception&amp;e)</font></tt></b><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; '\n';</font></tt></b><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; return 1;</font></tt></b><br><b><tt><font color="#993300">}</font></tt></b></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 -->Last modified: Wed Nov29 07:38:36 2000<!-- hhmts end --></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -