📄 eolesson3.html
字号:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en"><html><head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="GENERATOR" content="Mozilla/4.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]"> <title>Tutorial: Lesson 3</title></head><body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg"><a href="eoLesson2.html">Lesson 2</a> -<a href="eoLesson4.html">Lesson4</a> -<a href="eoTutorial.html">Main page</a> -<a href="eoTopDown.html">Algorithm-Based</a>- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Hints</a>- <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EOdocumentation</a></font></font></b><br><hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- --><center><h1><font color="#FF0000">Tutorial Lesson 3: input/output</font></h1></center>In this lesson, you will still use the same Evolutionary Algorithm, BUTin a much more <b><font color="#FF6600">user-friendly</font></b> way. Youwill discover how to<ul><li><a href="#parser">input parameters</a> on the command-line or from a textfile</li><li><a href="#state">save</a> the population to disk, together with every partof the algorithm you could think of - so you can decide to <font color="#FF6600">reload</font>everything later to continue the same run, eventually with different parameters.</li><li><a href="#stats">generate statistics</a> on the populations, and <a href="#monitor">outputthem</a> to the screen, text or graphic, or to a file (or to any otherdevice you might want to use).</li></ul>First, but you should now have done it without being told, go into the<font color="#FF6600">Lesson3sub-dir</font> of the tutorial dir and type<b><tt><font color="#990000"><font size=+1>make</font></font></tt></b>.This will compile the <b><tt><font color="#660000"><font size=+1>SecondBitEA</font></font></tt></b>and <b><tt><font color="#660000"><font size=+1>SecondRealEA</font></font></tt></b>programs.<p>You can then either<ul><li>browse the corresponding code (<a href="SecondBitEA.html">SecondBitEA</a>and <a href="SecondRealEA.html">SecondRealEA</a>),</li><li>look at the <a href="#changes">summary of changes</a>,</li><li>or find out directly explanations about the new features: the <a href="#parser">eoParser</a>,<a href="#state">eoState</a>and <a href="#checkpoint">eoCheckpoint</a> classes.</li></ul><p><br><hr WIDTH="100%"><br><a NAME="changes"></a><b><font color="#000099"><font size=+2>Changes</font></font></b><br><font color="#000000">As already said, the behavior of the algorithmwill be exactly the same as the previous one as far as optimization isconcerned. Only the input (of algorithm parameters) and output (of programresults) will be very different.</font><br><font color="#000000">Hence, the sections corresponding to the <a href="SecondBitEA.html#eval">fitnessfunction</a>, the <a href="SecondBitEA.html#init">initialization</a>, the<a href="SecondBitEA.html#operators">variationoperators</a>, the <a href="SecondBitEA.html#engine">evolution engine</a>and the <a href="SecondBitEA.html#generation">algorithm</a> itself arealmost identical (apart from variable name changes).</font><ul><li><font color="#000000"><a href="SecondBitEA.html#eval">Fitness function</a>:there is an </font><font color="#FF6600">additional line</font><font color="#000000">after the encapsulation of our </font><font color="#CC0000">binary_function</font><font color="#000000">into an </font><b><tt><font color="#CC0000"><font size=+1>eoEvalFunc</font></font></tt></b><font color="#000000">object, which again encapsulate the </font><b><tt><font color="#CC0000"><font size=+1>eoEvalFunc</font></font></tt></b><font color="#000000">into an </font><b><tt><font color="#CC0000"><font size=+1>eoEvalFuncCounter</font></font></tt></b><font color="#000000">.As its name says, this object will, in addition to computing the fitness,count the </font><b><font color="#FF6600">actual</font></b><font color="#000000">number of evaluations: the fitness of non-modified individuals is of coursenot recomputed - and this is taken care of by this object. Moreover, itcan be later </font><font color="#FF6600">used for displays</font><font color="#000000">in <a href="#monitor">eoMonitor</a> objects, as done in the <a href="SecondBitEA.html#eval_monitor">checkpointsection</a>.</font></li><li><font color="#000000">The <a href="SecondBitEA.html#init">initialization</a>section has been extended to account for the possibility to </font><font color="#CC33CC">re-loada previously saved population</font><font color="#000000">. This is achievedthrough an <a href="#state">eoState</a> object, if the corresponding programparameter is set.</font></li><li><font color="#000000">The<a href="SecondBitEA.html#operators">variationoperators</a> and the <a href="SecondBitEA.html#engine">evolution engine</a> sections are similar to the ones in Lesson2</font></li><li><font color="#000000">The <a href="SecondBitEA.html#parametres">parametersection</a> is completely different from the previous one. All variablescorresponding to </font><font color="#3366FF">program parameters</font><font color="#000000">are now read at run-time using an object of class <a href="#parser">eoParser</a>.</font></li><li><font color="#000000">The <a href="SecondBitEA.html#stop">stopping criterionsection</a>, has in fact now become the checkpoint section, as it involvesmuch more than just stopping criteria. See all details in the <a href="#checkpoint">eoCheckpointparagraph below</a>.</font></li></ul><hr WIDTH="100%"><a NAME="parser"></a><b><font color="#000099"><font size=+2>eoParser:parameter input</font></font></b><br><font color="#000000">The first two examples of Lessons 1 and 2 hada very crude way to set parameter values: they were hard-coded, and youhad to recompile the whole program to change a single value. We shall nowsee now to set parameter values in a flexible way (though we're still lookingfor volunteers to create a Graphical User Interface :-)</font><br><font color="#000000">Two base classes are used for that purpose:</font><ul><li><font color="#000000">The </font><b><tt><font color="#3366FF">eoValueParam</font></tt></b><font color="#000000">class, </font><font color="#FF6600">templatized by the type of the variable</font><font color="#000000">you want to handle (i.e. i</font><b><tt><font color="#660000">integer,double, yourPrivateClass</font></tt></b><font color="#000000">, ...). Inthis lesson, we will not go into details: e.g. we will not tell you thatthe<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_value_param.html">eoValueParam</a></font></font></b>is actually a templatized sub-class of abstract class eoParam (oops, Isaid it!), nor will we deal with parameters outside their use from an eoParser.See the parameter section of the Component-Based tutorial, or wait until<a href="eoLesson4.html">lesson4</a>).</font></li><li><font color="#000000">The </font><b><tt><font color="#3366FF">eoParser</font></tt></b><font color="#000000">class, whose only purpose is the input of parameters. Read <a href="../../doc/html/classeo_parser.html">itsdescription</a> if you are interested.</font></li></ul><hr WIDTH="50%"><a NAME="paraminput"></a><b><font color="#000099">eoParser:</font><font color="#FF0000">Modifying parameter values at run-time:</font></b><br><font color="#000000">Using an eoParser object, the parameter valuesare read, by order of priority</font><ol><li><font color="#000000">from the command-line</font></li><li><font color="#000000">from a text file</font></li><li><font color="#000000">from the environment (forthcoming, if somebody insists)</font></li><li><font color="#000000">from default values</font></li></ol>The syntax of parameter reading is a <b><font color="#FF6600">keyword</font></b>-basedsyntax, now traditional in the Unix world:<ul><li>in EO, each parameter is designated by <font color="#FF6600">a (long) keyword</font>,and optionally by a <font color="#FF6600">short (1 character) keyword</font>.</li><br> <li>the general syntax to modify parameter value at run-time is (either fromthe command-line or in a text file)</li><br> <b><tt><font color="#660000">--longKeyword=value</font></tt></b> or <b><tt><font color="#660000">-cvalue</font></tt></b> if 'c' is the short keyword (though <b><tt><font color="#660000">-c=value</font></tt></b>also works)<br> <li>so, after compiling the executable for Lesson 3 (<b><tt><font color="#FF6666">makelesson3</font></tt></b> at system prompt in Unix), you can try to typein</li><br> <b><tt><font color="#FF6666">SecondBitEA</font></tt></b>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -