📄 firstrealea.html
字号:
</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</font></tt><br><b><tt><font color="#009900"> eoDetTournamentSelect<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> eoSelectPerc<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> </b>// And we now have the fullslection/replacement - though with </font></tt><br><tt><font color="#009900"><b> </b>// no replacement (== generationalreplacement) at the moment :-)</font></tt><br><b><tt><font color="#009900"> eoNoReplacement<Indi> replace; </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> </b>//////////////////////////////////////</font></tt><br><tt><font color="#993399"><b> </b>// The variation operators</font></tt><br><tt><font color="#993399"><b> </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> </b>// uniform chooce on segmentmade by the parents</font></tt><br><b><tt><font color="#993399"> eoSegmentCrossover<Indi> xoverS;</font></tt></b><br><tt><font color="#993399"><b> </b>// uniform choice in hypercubebuilt by the parents</font></tt><br><b><tt><font color="#993399"> eoHypercubeCrossover<Indi> xoverA;</font></tt></b><br><tt><font color="#993399"><b> </b>// Combine them with relativeweights</font></tt><br><b><tt><font color="#993399"> eoPropCombinedQuadOp<Indi> xover(xoverS,segmentRate);</font></tt></b><br><b><tt><font color="#993399"> 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> </b>// offspring(i) uniformly chosenin [parent(i)-epsilon, parent(i)+epsilon]</font></tt><br><b><tt><font color="#993399"> eoUniformMutation<Indi> mutationU(EPSILON); </font></tt></b><br><tt><font color="#993399"><b> </b>// k (=1) coordinates of parentsare uniformly modified</font></tt><br><b><tt><font color="#993399"> eoDetUniformMutation<Indi> mutationD(EPSILON); </font></tt></b><br><tt><font color="#993399"> // all coordinates of parents are normallymodified (stDev SIGMA)</font></tt><br><b><tt><font color="#993399"> eoNormalMutation<Indi> mutationN(SIGMA); </font></tt></b><br><tt><font color="#993399"><b> </b>// Combine them with relativeweights</font></tt><br><b><tt><font color="#993399"> eoPropCombinedMonOp<Indi> mutation(mutationU,uniformMutRate);</font></tt></b><br><b><tt><font color="#993399"> mutation.add(mutationD, detMutRate);</font></tt></b><br><b><tt><font color="#993399"> mutation.add(mutationN, normalMutRate,true);</font></tt></b><p><tt><font color="#993399"><b> </b>// The operators are encapsulatedinto an eoTRansform object</font></tt><br><b><tt><font color="#993399"> eoSGATransform<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> </b>//////////////////////////////////////</font></tt><br><tt><font color="#3366FF"><b> </b>// termination conditions: usemore than one</font></tt><br><tt><font color="#3366FF"><b> </b>/////////////////////////////////////</font></tt><br><tt><font color="#3366FF"><b> </b>// stop after MAX_GEN generations</font></tt><br><b><tt><font color="#3366FF"> eoGenContinue<Indi> genCont(MAX_GEN);</font></tt></b><br><tt><font color="#3366FF"><b> </b>// do MIN_GEN gen., then stopafter STEADY_GEN gen. without improvement</font></tt><br><b><tt><font color="#3366FF"> eoSteadyFitContinue<Indi> steadyCont(MIN_GEN,STEADY_GEN);</font></tt></b><br><tt><font color="#3366FF"><b> </b>// stop when fitness reachesa target (here VEC_SIZE)</font></tt><br><b><tt><font color="#3366FF"> eoFitContinue<Indi> fitCont(0);</font></tt></b><br><tt><font color="#3366FF"><b> </b>// do stop when one of the abovesays so</font></tt><br><b><tt><font color="#3366FF"> eoCombinedContinue<Indi> continuator(genCont);</font></tt></b><br><b><tt><font color="#3366FF"> continuator.add(steadyCont);</font></tt></b><br><b><tt><font color="#3366FF"> 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> </b>/////////////////////////////////////////</font></tt><br><tt><font color="#FF6666"><b> </b>// the algorithm</font></tt><br><tt><font color="#FF6666"><b> </b>////////////////////////////////////////</font></tt><br><tt><font color="#FF6666"><b> </b>// Easy EA requires </font></tt><br><tt><font color="#FF6666"><b> </b>// selection, transformation,eval, replacement, and stopping criterion</font></tt><br><b><tt><font color="#FF6666"> eoEasyEA<Indi> gga(continuator,eval, select, transform, replace);</font></tt></b><br><tt><font color="#FF6666"><b> </b>// Apply algo to pop - that'sit!</font></tt><br><b><tt><font color="#FF6666"> cout << "\n Here we go\n\n";</font></tt></b><br><b><tt><font color="#FF6666"> gga(pop);</font></tt></b><br> </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</font></tt><br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b><br><b><tt><font color="#3366FF"> cout << "FINAL Population\n"<< pop << 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> </b>// rng.reseed(42);</font></tt><br><b><tt><font color="#993300"> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b><br><b><tt><font color="#993300"> flag|= _CRTDBG_LEAK_CHECK_DF;</font></tt></b><br><b><tt><font color="#993300"> _CrtSetDbgFlag(flag);</font></tt></b><br><tt><font color="#993300">// _CrtSetBreakAlloc(100);</font></tt><br><b><tt><font color="#993300">#endif</font></tt></b><br><b><tt><font color="#993300"> try</font></tt></b><br><b><tt><font color="#993300"> {</font></tt></b><br><b><tt><font color="#993300"> main_function(argc, argv);</font></tt></b><br><b><tt><font color="#993300"> }</font></tt></b><br><b><tt><font color="#993300"> catch(exception&e)</font></tt></b><br><b><tt><font color="#993300"> {</font></tt></b><br><b><tt><font color="#993300"> cout << "Exception: " << e.what() << '\n';</font></tt></b><br><b><tt><font color="#993300"> }</font></tt></b><br><b><tt><font color="#993300"> 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 + -