📄 eooperators.html
字号:
<ul><li>go to marked position</li><li>until <a href="#container_and_populator">current end of population</a>is reached do</li><ul><li>flip a coin according to the operator rate.</li><ul><li>If true, apply the operator to the parents. The current parents can bemodified, or some can be deleted from the list, or some offspring can beinserted in the list.</li><li>If false, move the pointer over the required number of parents (i.e. don'tmodify thoses parents)</li></ul><li>Next pending parent</li></ul><li>Next operator</li></ul><b><font color="#FF6600">Warning</font></b>: the way <b><tt><font color="#993300">rate</font></tt></b>will be used is highly dependent on the type of <b><font color="#CC33CC">eoOpContainer</font></b>your are creating there:<ul><li>The rates for <b><font color="#CC33CC">eoProportionalOpContainer</font></b>will be used in a roulette wheel choice among all operators. They can takeany value, the only important thing is their <b><font color="#FF6600">relativevalues</font></b>.</li><li>The "rates" for <b><font color="#CC33CC">eoSequentialOpContainer </font></b>actuallyare <b><font color="#FF6600">probabilities</font></b>, i.e. they will beused in a coin-flipping to determine whether that particuler operator willbe applied to the next candidates at hand. They should be <b><font color="#FF6600">in[0,1]</font></b> (no error will happen if they are not, but the operatorwill be applied systematically - this is equivalent of a rate equal to1).</li></ul><font color="#FF6600">Remark:</font>The eoSGATransform presented in <a href="eoLesson2.html#transform">Lesson2</a>can be viewed as a particular type of <b><font color="#CC33CC">eoSequentialOpContainer</font></b>.It was not coded that way in order to provide a gradual introduction toall concepts.<br><font color="#FF6600">Exercise</font>: write the code to perform aneoSGA using the eoOpContainer constructs.<p><b><font color="#FF0000">Adding operators to a container:</font></b><br>The way to add an operator to an <b><font color="#CC33CC">eoOpContainer</font></b>is the method<b><tt><font color="#993300">add</font></tt></b>. It is similarto all other <b><tt><font color="#993300">add</font></tt></b> methods inother Combined things in eo (as the simple eoProportionalCombinedXXXopdescribed above, but also the eoCombinedContinue class or the eoCheckPointclass).<br>The syntax is straightforward, and it works with any of the operatorclasses <b><font color="#CC33CC">eoXXXOp</font></b>, where XXX stands for<b><font color="#CC33CC">Mon,Bin, Quad </font></b><font color="#000000">or</font><b><font color="#CC33CC">Gen</font></b>:<p><b><tt><font color="#993300">someOperatorType<Indi> myOperator;</font></tt></b><br><b><tt><font color="#993300">eoYYYOpContainer<Indi> myOpContainer;</font></tt></b><br><tt><font color="#993300"><b>myOpContainer.add(myOperator, rate); </b>//rate: double whose <b>meaning depends on YYY</b></font></tt><p>where YYY can be one of Proportional and Sequential. Note that beforebeing added to the container, all simple operators are wrapped into thecorresponding eoGenOp (see e.g. how an <b><font color="#CC33CC">eoMonOp</font></b><a href="../../doc/html/eo_gen_op_8h-source.html#l00084">iswrapped</a> into an <b><font color="#CC33CC">eoMonGenOp</font></b>- orhow <a href="../../doc/html/eo_gen_op_8h-source.html#l00169">any operatoris handled</a> by calling the appropriate wrapper). In particular, thewrapper ensures that <b><font color="#FF6600">individuals who have beenmodified are invalidated</font></b>.<p><a NAME="container_and_populator"></a><b><font color="#FF0000">Containers,Selectors and Populators</font></b><br>The way the <b><font color="#CC33CC">eoOpContainer</font></b> are appliedon a population using an <b><font color="#999900">eoPopulator</font></b>object. But, whereas the behavior of <b><font color="#CC33CC"><a href="#prop_container">eoProportionalOpContainer</a></font></b>does not depend on the type of <b><font color="#999900">eoPopulator</font></b>,(oneoperator is chosen by roulette_wheel, and applied once before control isgiven back to the caller), the main loop in method <b><tt><font color="#993300">operator()</font></tt></b>ofclass <b><font color="#CC33CC"><a href="#seqential_container">eoSequentialOpContainer</a></font></b>iterates <b><tt><font color="#993300">while (!_pop.exhausted())</font></tt></b>which is interpreted differently depending on the <a href="#populators">typeof <b><font color="#CC33CC">eoPopulator</font></b></a>:<ul><li>if the argument is an <b><font color="#999900">eoSelectivePopulator</font></b>,the default position of the eoPopulator, considered as a population iterator,is at end of population. Individuals are added upon demand of an operator,and in most cases all operators are applied once. This also depends, however,on the arities of all operators:</li><ul><li>Consider an <b><font color="#CC33CC">eoSequentialOpContainer</font></b>containing an eoQuadOp and an eoMonOp. The eoQuadOp first asks for twoparents and modifies them. The eoMonOp is then called starting from theforst of thoses two modified individuals, and is hence applied twice, onceon each parent.</li><li>But consider now an <b><font color="#CC33CC">eoSequentialOpContainer</font></b>containing an <b><font color="#CC33CC">eoGenOp</font></b> that takes oneparent and generates three offspring, followed by an <b><font color="#CC33CC">eoQuadOp</font></b>.The <b><font color="#CC33CC">eoGenOp</font></b> will call the selectorto get the parent its need and will modify it and put 2 additional offspringat end of the population. The <b><font color="#CC33CC">eoQuadOp</font></b>will then be called on the first of the three outputs of the <b><font color="#CC33CC">eoGenOp</font></b>,and hence will act upon the frist two of them. But at that point, the populatoriterator will point to the third of the individuals resulting from the<b><font color="#CC33CC">eoGenOp</font></b>,and the test <b><tt><font color="#993300">_pop.exhausted()</font></tt></b>will return false, so the <b><font color="#CC33CC">eoQuadOp</font></b>will again be called. The second parent it needs will be given by a newcall to the embedded <b><font color="#009900">eoSelectOne</font></b> ofthe and everything will go on smoothly, except that a total of 4offspring will have been generated by application of this particular <b><font color="#CC33CC">eoSequentialOpContainer</font></b>.</li></ul><li>if the argument is an <b><font color="#999900">eoSeqPopulator</font></b>,the position of the iterator starts from the beginning of an existing population(the source populations), and hence when an an <b><font color="#CC33CC">eoSequentialOpContainer</font></b>is called, it goes through the whole remaining of the population (the test<b><tt><font color="#993300">_pop.exhausted()</font></tt></b>only returns true at end of the source population).</li><li>From the above it is easy to see that passing an <b><font color="#999900">eoSeqPopulator</font></b>to an <b><font color="#CC33CC">eoProportionalOpContainer</font></b> thatcontains an <b><font color="#CC33CC">eoSequentialOpContainer</font></b>,though not technically forbiddden, will most produce something totallyunpredictable, and hence should probably not be used without great care.</li></ul><hr WIDTH="100%"><a NAME="advanced_general"></a><b><font color="#000099"><font size=+2>Advancedgeneral operators:</font></font></b><p>It is sometimes useful to be able to use a selector from inside an operator(a typical example is when you want to implement <b><font color="#FF6600">sexualpreferences</font></b>, i.e. choose a mate for a first parent accordingto some characteritics of that first parent).<br>This is made possible in EO because the general operators have a handleon the initial population through the method <b><tt><font color="#993300">source()</font></tt></b>of the argument eoPopulator they work on. Their <b><tt><font color="#993300">apply()</font></tt></b>method shoudl look like<p><b><tt><font color="#993300">void apply()(</font><font color="#999900">eoPopulator</font><font color="#993300">&_pop)</font></tt></b><br><b><tt><font color="#993300">{</font></tt></b><br><tt><font color="#993300"><b> EOT & eo1 = *_pop; </b>// get(select if necessary) the first guy</font></tt><br><b><tt><font color="#993300"> EOT maBlonde = </font><font color="#009900">findBlonde</font><font color="#993300">(_pop.source());</font></tt></b><tt><font color="#993300">//select mate</font></tt><br><tt><font color="#993300"> // do whatever the operator is supposedto do, e.g</font></tt><br><tt><font color="#993300"> <b>cross(eo1, maBonde);</b> // cross is some embedded crossover</font></tt><br><tt><font color="#993300"> <b>...</b></font></tt><br><tt><font color="#993300"> // if you don't want to put maBlondeinto the offspring,</font></tt><br><tt><font color="#993300"> // stop here (and use a referenceto maBlonde above). Otherwise</font></tt><br><tt><font color="#993300"> <b>maBonde.invalidate();</b></font></tt><br><tt><font color="#993300"><b> ++_pop; </b>//advance</font></tt><br><tt><font color="#993300"> <b>_pop.insert(maBlonde);</b> // and insert it</font></tt><br><b><tt><font color="#993300">}</font></tt></b><p>Where does that <b><tt><font color="#009900">findBlonde</font></tt></b>selector comes from? As usual, you have to attach it to the operator, in its constructor for instance, which should give something like:<p><b><tt><font color="#993300">sexualSelectorType<Indi> findBlonde;</font></tt></b><br><b><tt><font color="#993300">sexualOperatorType<Indi> yourBrainAndMyBeauty(cross,findBlonde);</font></tt></b><p><hr WIDTH="100%"><b><font color="#FF0000">Local</font></b>: <a href="#introduction">Introduction</a>- <a href="#crossover">Crossover</a> - <a href="#mutation">Mutation</a>- <a href="#proportional_simple">Combinations</a> - <a href="#general">GeneralOperators</a> - <a href="#populators">Populators</a> - <a href="#general_combination">Generalcombinations</a>- <a href="#advanced_general">Advanced operators<hr WIDTH="100%"></a><b><font color="#FF0000">General</font></b>: <a href="eoTopDown.html">Algorithm-Based</a>- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programminghints</a> -<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EOdocumentation</a></font></font></b><br><hr><address><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address><br><!-- Created: Mon Oct 30 07:27:13 CET 2000 --><!-- hhmts start -->Lastmodified: Sat. Feb. 17 2002 <!-- hhmts end --><br> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -