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

📄 secondrealea.html

📁 这是linux下的进化计算的源代码。 === === === === === === === === === === === ===== check latest news at http:
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<b>  &nbsp;cout &lt;&lt; pop;</b><br></font></tt></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(tSize);</b><br><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;eoGenerationalReplacement&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>// uniform chooce on segment made by the parents<br><b>  &nbsp;eoSegmentCrossover&lt;Indi> xoverS;</b><br><b>  &nbsp;</b>// uniform choice in hypercube built by the parents<br><b>  &nbsp;eoHypercubeCrossover&lt;Indi> xoverA;</b><br><b>  &nbsp;</b>// Combine them with relative weights<br><b>  &nbsp;eoPropCombinedQuadOp&lt;Indi> xover(xoverS, segmentRate);</b><br><b>  &nbsp;xover.add(xoverA, hypercubeRate, 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>// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]<br><b>  &nbsp;eoUniformMutation&lt;Indi>  &nbsp;mutationU(EPSILON); </b><br><b>  &nbsp;</b>// k (=1) coordinates of parents are uniformly modified<br><b>  &nbsp;eoDetUniformMutation&lt;Indi>  &nbsp;mutationD(EPSILON); </b><br><b>  &nbsp;</b>// all coordinates of parents are normally modified (stDev SIGMA)<br><b>  &nbsp;eoNormalMutation&lt;Indi>  &nbsp;mutationN(SIGMA); </b><br><b>  &nbsp;</b>// Combine them with relative weights<br><b>  &nbsp;eoPropCombinedMonOp&lt;Indi> mutation(mutationU, uniformMutRate);</b><br><b>  &nbsp;mutation.add(mutationD, detMutRate);</b><br><b>  &nbsp;mutation.add(mutationN, normalMutRate, true);</b><br><b>  &nbsp;</b>// The operators are  &nbsp;encapsulated into an eoTRansform object<br><b>  &nbsp;eoSGATransform&lt;Indi> transform(xover, pCross, mutation, pMut);</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"><b>  &nbsp;</b>//////////////////////////////////////<br><b>  &nbsp;</b>// termination condition see FirstBitEA.cpp<br><b>  &nbsp;</b>/////////////////////////////////////<br><b>  &nbsp;eoGenContinue&lt;Indi> genCont(maxGen);</b><br><b>  &nbsp;eoSteadyFitContinue&lt;Indi> steadyCont(minGen, steadyGen);</b><br><b>  &nbsp;eoFitContinue&lt;Indi> fitCont(0);</b><br><b>  &nbsp;eoCombinedContinue&lt;Indi> continuator(genCont);</b><br><b>  &nbsp;continuator.add(steadyCont);</b><br><b>  &nbsp;continuator.add(fitCont);</b><br><b>  &nbsp;</b><br><b>  &nbsp;</b><br></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>// but now you want to make many different things every generation <br><b>  &nbsp;</b>// (e.g. statistics, plots, ...).<br><b>  &nbsp;</b>// the class eoCheckPoint is dedicated to just that:<br><b>  &nbsp;</b>// Declare a checkpoint (from a continuator: an eoCheckPoint <br><b>  &nbsp;</b>// IS AN eoContinue and will be called in the loop of all algorithms)<br><b>  &nbsp;eoCheckPoint&lt;Indi> checkpoint(continuator);</b><br><b>  &nbsp;</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// Create a counter parameter<br><b>  &nbsp; &nbsp; &nbsp;eoValueParam&lt;unsigned> generationCounter(0, "Gen.");</b><br><b>  &nbsp; &nbsp; &nbsp;</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// Create an incrementor (sub-class of eoUpdater). Note that the <br><b>  &nbsp; &nbsp; &nbsp;</b>// parameter's value is passed by reference, <br><b>  &nbsp; &nbsp; &nbsp;</b>// so every time the incrementer is updated (every generation),<br><b>  &nbsp; &nbsp; &nbsp;</b>// the data in generationCounter will change.<br><b>  &nbsp; &nbsp; &nbsp;eoIncrementor&lt;unsigned> increment(generationCounter.value());</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// Add it to the checkpoint, <br><b>  &nbsp; &nbsp; &nbsp;</b>// so the counter is updated (here, incremented) every generation<br><b>  &nbsp; &nbsp; &nbsp;checkpoint.add(increment);</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// now some statistics on the population:<br><b>  &nbsp; &nbsp; &nbsp;</b>// Best fitness in population<br><b>  &nbsp; &nbsp; &nbsp;eoBestFitnessStat&lt;Indi> bestStat;</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// Second moment stats: average and stdev<br><b>  &nbsp; &nbsp; &nbsp;eoSecondMomentStats&lt;Indi> SecondStat;</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// Add them to the checkpoint to get them called at the appropriate time<br><b>  &nbsp; &nbsp; &nbsp;checkpoint.add(bestStat);</b><br><b>  &nbsp; &nbsp; &nbsp;checkpoint.add(SecondStat);</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// The Stdout monitor will print parameters to the screen ...<br><b>  &nbsp; &nbsp; &nbsp;eoStdoutMonitor monitor(false);</b><br><b>  &nbsp; &nbsp; &nbsp; &nbsp;</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// when called by the checkpoint (i.e. at every generation)<br><b>  &nbsp; &nbsp; &nbsp;checkpoint.add(monitor);</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// the monitor will output a series of parameters: add them <br><b>  &nbsp; &nbsp; &nbsp;monitor.add(generationCounter);</b><br><b>  &nbsp; &nbsp; &nbsp;monitor.add(eval);		</b>// because now eval is an eoEvalFuncCounter!<br><b>  &nbsp; &nbsp; &nbsp;monitor.add(bestStat);</b><br><b>  &nbsp; &nbsp; &nbsp;monitor.add(SecondStat);</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// A file monitor: will print parameters to ... a File, yes, you got it!<br><b>  &nbsp; &nbsp; &nbsp;eoFileMonitor fileMonitor("stats.xg", " ");</b><br><b>  &nbsp; &nbsp; &nbsp; &nbsp;</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// the checkpoint mechanism can handle multiple monitors<br><b>  &nbsp; &nbsp; &nbsp;checkpoint.add(fileMonitor);</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// the fileMonitor can monitor parameters, too, but you must tell it!<br><b>  &nbsp; &nbsp; &nbsp;fileMonitor.add(generationCounter);</b><br><b>  &nbsp; &nbsp; &nbsp;fileMonitor.add(bestStat);</b><br><b>  &nbsp; &nbsp; &nbsp;fileMonitor.add(SecondStat);</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// Last type of item the eoCheckpoint can handle: state savers:<br><b>  &nbsp; &nbsp; &nbsp;eoState outState;</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// Register the algorithm into the state (so it has something to save!!)<br><b>  &nbsp; &nbsp; &nbsp;outState.registerObject(parser);</b><br><b>  &nbsp; &nbsp; &nbsp;outState.registerObject(pop);</b><br><b>  &nbsp; &nbsp; &nbsp;outState.registerObject(rng);</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// and feed the state to state savers<br><b>  &nbsp; &nbsp; &nbsp;</b>// save state every 100th  &nbsp;generation<br><b>  &nbsp; &nbsp; &nbsp;eoCountedStateSaver stateSaver1(20, outState, "generation"); </b><br><b>  &nbsp; &nbsp; &nbsp;</b>// save state every 1 seconds <br><b>  &nbsp; &nbsp; &nbsp;eoTimedStateSaver  &nbsp; &nbsp;stateSaver2(1, outState, "time"); </b><br><b>  &nbsp; &nbsp; &nbsp;</b>// Don't forget to add the two savers to the checkpoint<br><b>  &nbsp; &nbsp; &nbsp;checkpoint.add(stateSaver1);</b><br><b>  &nbsp; &nbsp; &nbsp;checkpoint.add(stateSaver2);</b><br><b>  &nbsp; &nbsp; &nbsp;</b>// and that's it for the (control and) output<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>// stopping criterion, eval, selection, transformation, replacement<br><b>  &nbsp;eoEasyEA&lt;Indi> gga(checkpoint, 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="stop"></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>  &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="eoLesson3.html">Back to Lesson 3</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 -->Lastmodified: Sun Apr 28 06:42:44 2002<!-- hhmts end --></body></html>

⌨️ 快捷键说明

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