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

📄 eolesson2.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>Tutorial: Lesson 2</title><!-- Changed by: Marc Schoenauer, 29-Nov-2000 --></head><body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg"><a href="eoLesson1.html">Lesson 1</a> -<a href="eoLesson3.html">Lesson3</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>-<font size=+1> <b><font face="Arial,Helvetica"><a href="../../doc/html/index.html">EOdocumentation</a></font></b></font><br><hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- --><center><h1><font color="#FF0000">Tutorial Lesson 2: more encapsulations</font></h1></center>In this lesson, the same Evolutionary Algorithm will be rewritten in amuch more general context.<br>First, look at the <a href="#changes">changes</a> that have been doneto the algorithms. Then benefit from the new features by<ul><li><a href="#minimize">minimizing</a> (and not only maximize) the fitness</li><li><a href="#combined_operators">combining</a> <font color="#CC33CC">severaloperators</font> of the same type</li><li><a href="#combinedContinue">combining</a> <font color="#3366FF">severalstopping criteria</font></li><li>use <font color="#009900"><a href="#evolution">alternate</a> selection/replacement</font>engines, deviating from the pure generational GA</li></ul><p><br>Again, two basic algorithms are provided, namely <a href="FirstBitEA.html">FirstBitEA</a>and <a href="FirstRealEA.html">FirstRealEA</a>.<br><font color="#FF6600">To compile and run</font> them, go to the <font color="#FF6600">Lesson2sub-directory</font> of the tutorial dir and simply type <b><tt><font color="#990000"><font size=+1>make</font></font></tt></b>.Both examples should get compiled, and you can then run them by callingtheir name from the system prompt.<p>Note the slim difference in names, from <font color="#FF6600">GA</font>to <font color="#FF6600">EA</font>: the behavior of these&nbsp; EAs isalmost identical to that of their GA counterpart, at least with the defaultsettings that are provided. But their potentialities for easy modificationsare much larger, both in terms of <b><font color="#CC33CC">variation operators</font></b>and of <b><font color="#009900">evolution engine</font></b> (i.e. <font color="#009900">selection/replacement</font>mechanism).&nbsp;<hr WIDTH="100%"><a NAME="changes"></a><b><font color="#000099"><font size=+2>Changes</font></font></b><p>Browse through the code, and discover them one after the other:<ul><li><font color="#000000">The</font><font color="#CC0000"> fitness function</font><font color="#000000">nowlies in a </font><b><font color="#CC0000">separate file</font></b><font color="#000000">(<a href="FirstBitEA.html#evalfunc">Bit</a>- <a href="FirstRealEA.html#evalfunc">Real</a>). But, more important, itsargument is a <a href="binary_value.html">vector&lt;bool></a> or a <a href="real_value.html">vector&lt;double></a>,and not an unknown type. This will allow to use the same file for any EOobject that is a sub-class of the corresponding STL vector class.</font></li><br>&nbsp;<p>&nbsp;<p><b><font color="#FF0000">Note:</font></b> <font color="#000000">Also,a non-templatized fitness can be </font><b><font color="#FF6600">compiledseparately</font></b><font color="#000000"> (not done here) into an objectfile once and for all (<a href="eoProgramming.html#templates">remember</a>that templates forbid that).</font><br>&nbsp;<li><a NAME="minimize"></a><font color="#000000">The </font><font color="#CC0000"><b>encapsulation</b>ofthe fitness </font><font color="#000000">(<a href="FirstBitEA.html#eval">Bit</a>- <a href="FirstRealEA.html#eval">Real</a>) looks more complicated: youhave to declare 3 template arguments: the type of EO object it will beapplied to, the return type and the type of argument the function actuallyrequires.</font></li><br>&nbsp;<p>&nbsp;<p><b><font color="#FF0000">Note:</font></b> <font color="#000000">In theprevious files (<a href="FirstBitGA.html#eval">Bit</a> - <a href="FirstRealGA.html#eval">Real</a>), the last 2 types were deduced from the first (2nd argument = fitnesstype of EO object, third = first).</font><br>&nbsp;<li><font color="#000000">Both the above modifications makes it very easy to</font><b><font color="#CC0000">minimize</font></b><font color="#000000">rather than maximize a fitness function (see <a href="#Execrise1">Exercise1)</a>.</font></li><br>&nbsp;<li><font color="#000000">The</font><font color="#CC33CC"> initialization</font><font color="#000000">of the population is now </font><b><font color="#CC33CC">encapsulated</font></b><font color="#000000">intoa </font><font color="#CC33CC"><b>separate initializer</b> </font><font color="#000000">(basedon a <a href="FirstBitEA.html#init">boolean generator</a> or a <a href="FirstRealEA.html#init">double-numbergenerator</a> -see <a href="../../doc/html/class_random_generator.html">random_generators.h</a>)that is then used in the constructor of the population to build the individuals.You can also use different initializers and call them in turn through thecall to <a href="../../doc/html/classeo_pop.html#a2">pop.append()</a> function(see <a href="#exercise2">Exercise 2</a>).</font></li><br>&nbsp;<p>&nbsp;<p><b><font color="#FF0000">Note</font><font color="#CC33CC">: </font></b><font color="#000000">Don'tforget to </font><b><font color="#CC0000">evaluate the population</font></b><font color="#000000">:the eoPop has no idea of the eval function, so it has to be done from outside!!!</font><br>&nbsp;<li><a NAME="combined_operators"></a><font color="#000000">You can now use</font><font color="#CC33CC"><b>different</b>crossover</font><font color="#000000">and</font><font color="#CC33CC">mutation<b>operators</b></font><font color="#000000">in the same algorithm,choosing among them according to</font><b><font color="#FF6600">relativeweights.</font></b><font color="#CC33CC"> </font><font color="#000000">Theclass </font><font color="#CC33CC"><b>eoPropCombinedxxxOp</b>,</font><font color="#000000">wherexxx is either Mon (for mutations, of class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b></font><font color="#CC33CC">)</font><font color="#000000">or Quad (for crossovers, of class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_quad_op.html">eoQuadOp</a></font></font></b>),is derived from the corresponding eoxxxOp class. When applying the eoPropCombinedxxxOp,one of the eoxxxOp it contains is chosen by a <a href="../../doc/html/classeo_rng.html#a12">roulettewheel,</a> according to their respective rates, and is applied to the arguments.For more details on these classes, go to the <a href="eoOperators.html#crossover">algorithm-basedcorresponding pages</a>, or to their respective documentation pages.</font></li><ul><li><font color="#000000"><a href="FirstBitEA.html#operators">Bit</a></font></li><br><font color="#000000">Three </font><b><font color="#FF6600">crossoveroperators</font></b><font color="#000000"> are available: the </font><font color="#FF6600">one-point</font><font color="#000000">crossover is still there (class ), but now you also have the </font><font color="#FF6600">N-point</font><font color="#000000">crossover </font><font color="#CC33CC">eoBinNxOver</font><font color="#000000">(the&nbsp; number of points is 2 by default, but as always you can changethat in the constructor), and the </font><font color="#FF6600">Uniform</font><font color="#000000">crossover </font><font color="#CC33CC">eoBinUxOver</font><font color="#000000">(where you can eventually twidle the choice from one parent to the otherby providing a probability in the constructore - defaulted to 0.5, whichamounts to symmetrical choice).</font><br><font color="#000000">As for </font><b><font color="#FF6600">mutationoperators</font></b><font color="#000000">, apart from the </font><font color="#CC33CC">eoBinMutation</font><font color="#000000">(standard bitstring mutation flipping one bit with a given probability)you can also use the </font><font color="#CC33CC">eoDetBitFlip</font><font color="#000000">that always filps the same number of bits (1 by default, but you can changethat in the constructor), randomly chosen in the bitstring. Even thoughthe average number of bits flipped is the same if the </font><font color="#CC33CC">eoBinMutation</font><font color="#000000">isused with a rate of 1/N (N is the bitstring length) </font><font color="#FF6600">thebehavior of these mutation can be very different</font><font color="#000000">on many problems.</font><li><font color="#000000"><a href="FirstRealEA.html#operators">Real</a></font></li><br><font color="#000000">Two </font><b><font color="#FF6600">crossoveroperators</font></b><font color="#000000"> are available: the </font><font color="#CC33CC">eoSegmentCrossover</font><font color="#000000">chooses one point uniformly on the segment joining the parents, while the</font><font color="#CC33CC">eoHypercubeCrossover</font><font color="#000000">performs a linear combination on each coordinate independently, which amountto choosing the offspring uniformly in the hypercube whose diagonal isthe segment joining the parents.</font><br><font color="#000000">As for </font><b><font color="#FF6600">mutationoperators</font></b><font color="#000000">, apart from the </font><font color="#CC33CC">eoBinMutation</font><font color="#000000">(standard bitstring mutation flipping one bit with a given probability)you can also use the </font><font color="#CC33CC">eoDetBitFlip</font><font color="#000000">that always filps the same number of bits (1 by default, but you can changethat in the constructor), randomly chosen in the bitstring. And last butnot least, the normal mutation eoNormMutation modifies all coordinates

⌨️ 快捷键说明

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