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

📄 eoprogramming.html

📁 这是linux下的进化计算的源代码。 === === === === === === === === === === === ===== check latest news at http:
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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>EO Programming guide</title></head><body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg"><b><font color="#CC0000">General: </font></b><a href="eoTutorial.html">Tutorialmain page </a>-<a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based</a>- <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EOdocumentation</a></font><br><hr WIDTH="100%"><b><font color="#CC0000">Local: </font></b><a href="#templates">Templates</a>-<a href="#functors">Functors</a> -<a href="#STL">STL Library</a> - <a href="#random">Randomnumbers</a> - <a href="#notations">EO programming style</a>&nbsp; - <a href="#memory">Memorymanagement</a><br><hr WIDTH="100%"><center><h1><font color="#FF0000">EO Programming guide</font></h1></center><hr WIDTH="100%"><br><a NAME="templates"></a><b><font color="#000099"><font size=+1>Templates</font></font></b><p>Most EO code is written using templates. This allows to write genericcode, i.e. involving a class which doesn't have to be known when writingthe code -- but only when compiling it. In some sense this is similar tonaming variables in algebra: you can write a lot of equations involvingsome variable $x$ without knowing even it if will be an integer or a float(or a matrix or ...). The main basic type that is templatized in EO isthe fitness: an EO object is some object which has a fitness of some typeF that can be anything. The definition for that is (see <font face="Arial,Helvetica"><a href="../../doc/html/_e_o_8h-source.html">EO.h</a></font>)<p><b><tt><font color="#999900">template&lt;class F> class EO</font></tt></b><p>The idea is that, later in your code, you can define a class as follows(see for instance&nbsp; <a href="../../doc/html/eo_bit_8h-source.html">eoBit.h</a>).<p><b><tt><font color="#999900">template&lt;class F> class eoBit : publicEO&lt;F></font></tt></b><br><b><tt><font color="#999900">{ ... code for eoBit&nbsp; };</font></tt></b><p>and then use it in your application as<p><b><tt><font color="#999900">eoBit&lt;double> myeoBit;</font></tt></b><p>declares an object of type eoBin which has as fitness a double.<p>Whereas the <b><font color="#FF6600">advantages</font></b> are obvious (writing generic reusable code insteadof having to rewrite the same pieces of code for different types), thereare some <b><font color="#FF6600">drawbacks</font></b>: namely, it makes some of the compiler error messageshard to understand; and it forbids the compilation of most parts of EOinto an object library file, as the actual types are not known in advance.<p><hr WIDTH="100%"><br><a NAME="functors"></a><b><font color="#000099"><font size=+1>Functors</font></font></b><p>Though EO is a library, it contains almost no functions per se!<br>EO mainly contains functors, that are objects which have a method called<b><tt><font color="#FF6600">operator()</font></tt></b>.Such objects are used&nbsp; as if they were functions, but the big differencesare that<ul><li>functors are functions with private data</li><li>you can have different functors objects of the same class, i.e. you canuse at the same time the same functionality with different parameters</li><li>you can have a hierarchy of functors objects, which means that you havea hierarchy of functions with defaults behaviors and specialized sub-functions</li><li>...</li></ul>Functors are so intimately linked to EO that a base class (<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_functor_base.html">eoFunctorBase</a></font></font></b>)has been designed to hold all functors. This base class is itself dividedinto three derived class. These classes tell you immediately what kindof arguments the <b><tt><font color="#993300">operator()</font></tt></b>method requires and what kind of result it produces. See <a href="#notations">EOconventions</a>, and the <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_functor_base.html">inheritancediagram of class eoFunctorBase</a>.&nbsp;</font></font></b> Also note thatif you create new functors, you should also derive from one of these classes,as it is mandatory if you later use the EO <a href="#memory">memory managementmechanism</a>.<br>For a more complete introduction to functors, with detailed discussion,go to the <a href="http://www.sgi.com/tech/stl/functors.html">STL documentation</a>- as STL also heavily relies on functors, and the eoFunctorBase paradigmis borrowed from there.<p><b><font color="#FF0000">Functors:</font><font color="#000099"> Example:</font></b><p>The following is a basic example of how to program and use a functorobject: First code the class:<p><b><tt><font color="#993300">class MyFunctor</font></tt></b><br><b><tt><font color="#993300">{ ...</font></tt></b><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp; void operator()(ArgTypearg)</font></tt></b><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// do what you have to do</font></tt><br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b><br><tt><font color="#993300"><b>}; </b>// end of class declaration</font></tt><p>Then use it&nbsp; later in the code :<p><b><tt><font color="#993300">ArgType myArgument;</font></tt></b><br><tt><font color="#993300"><b>MyFunctor myFunctorInstance;&nbsp;</b>&nbsp;&nbsp;// myFunctorInstance is an object of class MyFUnctor ...</font></tt><br><tt><font color="#993300"><b>myFunctorInstance(myArgument);</b>&nbsp;// calls operator() of myFunctorInstance acting on myArgument ...</font></tt><br>&nbsp;<p><b><font color="#FF0000">Functors:</font><font color="#000099"> Thethree basic classes:</font></b><p><font color="#000000">Direct sub-classes of the root class , three classesare defined to differentiate functors by the number of argument requiredby their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">.These classes are templatized by the types of its arguments, and by itsreturn type. Hence,</font><br><font color="#000000">from the inheritance diagram of any functor classin EO, you can immediately deduce the interface of their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">method.</font><br>&nbsp;<ul><li><b><tt><font color="#FF6600">eoF</font></tt></b><font color="#000000">is for arity-zero functors, i.e.&nbsp; their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">method does not require any argument. It has a single template parameter,the return type of the </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">method. For instance,&nbsp;</font> <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_monitor.html">eoMonitor</a></font></font></b>&nbsp;<font color="#000000">are </font><b><tt><font color="#FF6600">eoF</font></tt></b><font color="#000000">'sthat return an </font><b><tt><font color="#993300">eoMonitor &amp;</font></tt></b><font color="#000000">.</font></li><li><b><tt><font color="#FF6600">eoUF</font></tt></b><font color="#000000">is for unary functors, i.e.&nbsp; their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">method requires one argument. It has two template parameters, the typeof the argument and the return type of the </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">method. For instance,&nbsp;</font> <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b>'s<font color="#000000">are </font><b><tt><font color="#FF6600">eoUF</font></tt></b><font color="#000000">'sthat take as argument an </font><b><tt><font color="#993300">EOT &amp;</font></tt></b><font color="#000000">and return </font><b><tt><font color="#993300">void</font></tt></b><font color="#000000">.</font></li><li><b><tt><font color="#FF6600">eoBF</font></tt></b><font color="#000000">is for binary functors, i.e.&nbsp; their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">method requires two arguments. It has three template parameters, the typesof the arguments and the return type of the </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">method. For instance,&nbsp;</font> <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_bin_op.html">eoBinOp</a></font></font></b>'s<font color="#000000">are </font><b><tt><font color="#FF6600">eoBF</font></tt></b><font color="#000000">'sthat take as arguments a </font><b><tt><font color="#993300">const EOT&amp;</font></tt></b><font color="#000000"> and an </font><b><tt><font color="#993300">EOT&amp;</font></tt></b><font color="#000000">, and return </font><b><tt><font color="#993300">void</font></tt></b><font color="#000000">.</font></li></ul><font color="#000000">Now go back to the </font><b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_functor_base.html">inheritancediagram of class eoFunctorBase</a></font></font></b><font color="#000000">,and guess the interface for all functors!</font><p><b><font color="#FF0000">Note</font></b><font color="#000000">: forobvious simplicity reasons, we very often omit the reference to the </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">,e.g. when we say above:</font><ul><li><b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b>'s<font color="#000000">are </font><b><tt><font color="#FF6600">eoUF</font></tt></b><font color="#000000">'sthat take as argument an </font><b><tt><font color="#993300">EOT &amp;</font></tt></b><font color="#000000">and return </font><b><tt><font color="#993300">void</font></tt></b></li></ul><font color="#000000">it actually means</font><ul><li><b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b>'s<font color="#000000">are </font><b><tt><font color="#FF6600">eoUF</font></tt></b><font color="#000000">'s,their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">method takes as argument an </font><b><tt><font color="#993300">EOT &amp;</font></tt></b><font color="#000000">and returns </font><b><tt><font color="#993300">void</font></tt></b><font color="#000000">.</font></li></ul><p><br><hr WIDTH="100%"><br><a NAME="STL"></a><b><font color="#000099"><font size=+1>A very briefintroduction to STL</font></font></b><p>All EO heavily relies on <b><font color="#FF6600">STL, the StandardTemplate Library</font></b>.<br>But <font color="#FF6600">you don't have to know more than a few wordsof STL</font> to use EO (like with "hello", "please" and "goodbye" youcan survive in a foreign country :-) and even to contribute to new EO features.Moreover, while browsing through EO code, you will gradually learn howto use STL, especially if you check at the <a href="http://www.sgi.com/tech/stl/">SGISTL Web site</a> from time to time, where you can not only download STL,but also browse in the Programmer's guide&nbsp; for isntance from the <a href="http://www.sgi.com/tech/stl/table_of_contents.html">Tableof Content</a>.<p>Anyway, you will only find here, in EO tutorial, the basics of STL thatyou will need to understand most of EO code - and to guess what the partsyou don't understand are actually doing. Don't worry, <b><font color="#FF6600">I</font></b>don'tunderstand everything :-)<p>STL provides the user with <b><font color="#FF6600">container</font></b>s,<b><font color="#FF6600">iterators</font></b>and <b><font color="#FF6600">algorithms</font></b>. And you can access(almost) all containers content using (almost) all iterators, or apply(almost) all algorithms on (almost) all containers (of course the trickypart is to instanciate the "almost" in the previous sentence :-)<p><b><font color="#FF0000">STL: </font><font color="#000099">Containers</font></b><br>Containers are high level data types used to hold simpler data - themost widely used example of a container is the <b><font color="#FF6600">vector</font></b>construct.<br>The use of STL containers relieve the user from memory management.<ul><li><b><tt><font color="#000099"><font size=+1>vector </font></font></tt></b><font color="#000000">Themost widely used container is a one-dimensional array of items.</font></li><br><font color="#000000">Data manipulation: suppose </font><font color="#FF6600">vis an STL </font><b><tt><font color="#993300">vector&lt;AtomType></font></tt></b><font color="#000000">.Then</font><br><b><tt><font color="#993300">v[i]</font></tt></b><font color="#000000">is the ith element of v, as in standard C arrays</font><br><b><tt><font color="#993300">v.size()</font></tt></b><font color="#000000">is the number of elements of v</font><br><b><tt><font color="#993300">v.push_back(atom)</font></tt></b><font color="#000000">appends the </font><b><tt><font color="#993300">atom</font></tt></b><font color="#000000">at end of </font><b><tt><font color="#993300">v</font></tt></b><font color="#000000">,provided of course that </font><b><tt><font color="#993300">atom</font></tt></b><font color="#000000">is of type </font><b><tt><font color="#993300">AtomType</font></tt></b><font color="#000000">,the size is automatically increased...</font><br><font color="#000000">blabla insert, erase, ...</font><li><b><tt><font color="#000099"><font size=+1>list</font></font></tt></b><font color="#000000">STL provides different types of list. The one used in EO is the simplelinked list named ... </font><b><tt><font color="#993300">list</font></tt></b><font color="#000000">.As far as the user is concerned, simple lists are very similar to vectors,and the data manipulation listed above for vectors can be applied to list.</font></li><li><b><tt><font color="#000099"><font size=+1>pair</font></font></tt></b></li><br><font color="#000000">This simple container allows you to hold twodata types together. It is very handy for temporary data handling. Assumingp is a </font><b><tt><font color="#993300">pair&lt;AtomType1, AtomType2></font></tt></b><font color="#000000">,</font><b><tt><font color="#993300">p.first</font></tt></b><font color="#000000">and </font><b><tt><font color="#993300">p.second</font></tt></b><font color="#000000">&nbsp;refer to the encapsulated data, of respective types </font><b><tt><font color="#993300">AtomType1</font></tt></b><font color="#000000">and</font><b><tt><font color="#993300">AtomType2</font></tt></b><li><b><tt><font color="#000099"><font size=+1>Blabla</font></font></tt></b></li></ul>There are many other types of containers that are not used in EO and thatwe will not present here.<p><b><font color="#FF0000">STL: </font><font color="#000099">Iterators</font></b><br>Iterators are accessors to the containers contents that provide unifiedaccess to different containers. They are very similar to pointers, i.e.

⌨️ 快捷键说明

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