📄 onemaxea.html
字号:
_parser, eoState& _state, eoEvalFuncCounter<Indi>& _eval, eoContinue<Indi>&_continue) </font></tt></b><br><b><tt><font color="#3366FF">{</font></tt></b><br><b><tt><font color="#3366FF"> return do_make_checkpoint(_parser,_state, _eval, _continue);</font></tt></b><br><b><tt><font color="#3366FF">}</font></tt></b></td></tr></table><a NAME="engine"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><tt><font color="#009900">// evolution engine (selection and replacement)</font></tt><br><b><tt><font color="#009900">#include <do/make_algo_scalar.h></font></tt></b><br><b><tt><font color="#009900">eoAlgo<Indi>& make_algo_scalar(eoParser&_parser, eoState& _state, eoEvalFunc<Indi>& _eval, eoContinue<Indi>&_continue, eoGenOp<Indi>& _op)</font></tt></b><br><b><tt><font color="#009900">{</font></tt></b><br><b><tt><font color="#009900"> return do_make_algo_scalar(_parser,_state, _eval, _continue, _op);</font></tt></b><br><b><tt><font color="#009900">}</font></tt></b></td></tr></table><a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><tt><font color="#993300">// simple call to the algo. stays there forconsistency reasons </font></tt><br><tt><font color="#993300">// no template for that one</font></tt><br><b><tt><font color="#993300">#include <do/make_run.h></font></tt></b><br><tt><font color="#993300">// the instanciating fitnesses</font></tt><br><b><tt><font color="#993300">#include <eoScalarFitness.h></font></tt></b><br><b><tt><font color="#993300">void run_ea(eoAlgo<Indi>& _ga,eoPop<Indi>& _pop)</font></tt></b><br><b><tt><font color="#993300">{</font></tt></b><br><b><tt><font color="#993300"> do_run(_ga, _pop);</font></tt></b><br><b><tt><font color="#993300">}</font></tt></b><br><tt><font color="#993300">// checks for help demand, and writes thestatus file</font></tt><br><tt><font color="#993300">// and make_help; in libutils</font></tt><br><b><tt><font color="#993300">void make_help(eoParser & _parser);</font></tt></b><br><tt><font color="#993300">// now use all of the above, + representationdependent things</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"> try</font></tt></b><br><b><tt><font color="#993300"> {</font></tt></b><br><tt><font color="#993300"><b> eoParser parser(argc, argv); </b>// for user-parameter reading</font></tt><br><tt><font color="#993300"><b> eoState state; </b>// keeps all things allocated</font></tt></td></tr></table><a NAME="eval"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><tt><font color="#CC0000"><b> </b> //The fitness</font></tt><br><tt><font color="#CC0000"><b> </b> //////////////</font></tt><br><tt><font color="#CC0000"><b> eoOneMaxEvalFunc<Indi>plainEval</b> /* (varType _anyVariable) */;<b>;</b></font></tt><br><tt><font color="#CC0000"><b> </b> // turn that objectinto an evaluation counter</font></tt><br><b><tt><font color="#CC0000"> eoEvalFuncCounter<Indi>eval(plainEval);</font></tt></b></td></tr></table><a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><tt><font color="#999900"><b> </b> // the genotype - through agenotype initializer</font></tt><br><b><tt><font color="#999900"> eoInit<Indi>& init = make_genotype(parser,state, Indi());</font></tt></b></td></tr></table><a NAME="operators"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><tt><font color="#993399"><b> </b> // Build the variation operator(any seq/prop construct)</font></tt><br><b><tt><font color="#993399"> eoGenOp<Indi>& op = make_op(parser,state, init);</font></tt></b><br><tt><font color="#993399"><b> </b> //// Now the representation-independentthings </font></tt><br><tt><font color="#993399"><b> </b> //</font></tt><br><tt><font color="#993399"><b> </b> // YOU SHOULD NOT NEED TO MODIFYANYTHING BEYOND THIS POINT</font></tt><br><tt><font color="#993399"><b> </b> // unless you want to add specificstatistics to the checkpoint</font></tt><br><tt><font color="#993399"><b> </b> //////////////////////////////////////////////</font></tt></td></tr></table><a NAME="init"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><tt><font color="#993399"><b> </b> // initialize the population</font></tt><br><tt><font color="#993399"><b> </b> // yes, this is representationindepedent once you have an eoInit</font></tt><br><b><tt><font color="#993399"> eoPop<Indi>& pop = make_pop(parser, state, init);</font></tt></b></td></tr></table><a NAME="stop"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><tt><font color="#3366FF"><b> </b> // stopping criteria</font></tt><br><b><tt><font color="#3366FF"> eoContinue<Indi> & term =make_continue(parser, state, eval);</font></tt></b></td></tr></table><a NAME="output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><tt><font color="#3366FF"><b> </b> // output</font></tt><br><b><tt><font color="#3366FF"> eoCheckPoint<Indi> & checkpoint= make_checkpoint(parser, state, eval, term);</font></tt></b></td></tr></table><a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><tt><font color="#993300"><b> </b> // algorithm (need the operator!)</font></tt><br><b><tt><font color="#993300"> eoAlgo<Indi>& ga = make_algo_scalar(parser,state, eval, checkpoint, op);</font></tt></b><br><tt><font color="#993300"><b> </b> ///// End of construction ofthe algorithm</font></tt><br><tt><font color="#993300"><b> </b> /////////////////////////////////////////</font></tt><br><tt><font color="#993300"><b> </b> // to be called AFTER all parametershave been read!!!</font></tt><br><b><tt><font color="#993300"> make_help(parser);</font></tt></b><br><tt><font color="#993300"><b> </b> //// GO</font></tt><br><tt><font color="#993300"><b> </b> ///////</font></tt></td></tr></table><a NAME="eval"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><tt><font color="#CC0000"><b> </b> // evaluate intial populationAFTER help and status in case it takes time</font></tt><br><b><tt><font color="#CC0000"> apply<Indi>(eval, pop);</font></tt></b><br><tt><font color="#CC0000"><b> </b> // if you want to print itout</font></tt><br><tt><font color="#CC0000">// cout << "InitialPopulation\n";</font></tt><br><tt><font color="#CC0000">// pop.sortedPrintOn(cout);</font></tt><br><tt><font color="#CC0000">// cout << endl;</font></tt></td></tr></table><a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><tt><font color="#993300"><b> run_ea(ga, pop); </b>// run thega</font></tt><br><b><tt><font color="#993300"> cout << "Final Population\n";</font></tt></b><br><b><tt><font color="#993300"> pop.sortedPrintOn(cout);</font></tt></b><br><b><tt><font color="#993300"> cout << endl;</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 <<e.what() << endl;</font></tt></b><br><b><tt><font color="#993300"> }</font></tt></b><br><b><tt><font color="#993300"> return 0;</font></tt></b><br><b><tt><font color="#993300">}</font></tt></b></td></tr></table><hr WIDTH="100%"><a href="eoLesson5.html">Back to Lesson 5</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 -->Last modified: Sat May4 07:37:41 2002<!-- hhmts end --></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -