paradiseo/eo/tutorial/html/eoOperators.html
2000-12-19 18:32:09 +00:00

677 lines
38 KiB
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.75 [en] (X11; U; Linux 2.2.17-21mdksmp i686) [Netscape]">
<title>Variation Operators</title>
</head>
<body text="#000000" link="#0000EF" vlink="#51188E" alink="#FF0000" background="beige009.jpg">
<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">Programming
hints</a> - <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
documentation</a></font></font></b>
<br>
<hr WIDTH="100%">
<br><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">General
Operators</a> - <a href="#populators">Populators</a> - <a href="#general_combination">General
combinations</a>- <a href="#advanced_general">Advanced operators</a>
<br>
<hr WIDTH="100%">
<center>
<h1>
<b><font color="#CC0000">Variation Operators</font></b></h1></center>
<a NAME="introduction"></a><b><font color="#000099"><font size=+2>Variation
Operators</font></font></b>
<br>Variation operators modify individuals, or, equivalently, move them
in the search space. In Evolutionary Algorithms, varitaion operators are
almost always <b><font color="#FF6600">stochastic</font></b>, i.e. they
are based on random numbers, or equivalently, perform random modifications
of their arguments. Variation operators are classified depending on the
number of arguments they use and/or modify.
<ul>
<li>
Variation operators involving <b><font color="#FF6600">two individuals</font></b>
are called <a href="#crossover">crossover operators</a>. They can either
modify one of the parents according to the material of the other parent,
or modify both parents. In EO, the former are called Binary operators and
the latter Quadratic operators.</li>
<li>
Variation operators involving <b><font color="#FF6600">one single individual</font></b>
are called <a href="#mutation">mutation operators.</a></li>
<li>
Straightforward extensions of these simple operators allow to combine them:
in
<a href="#proportional_simple">proportional combinations</a>, one operator
is chosen among a given set of operators of same arity according to some
weights.</li>
<li>
In EO you can also define and use variation operators that generate any
number of offspring from any number of parents (sometimes termed <b><font color="#FF6600">orgy</font></b>
operators). They are called <a href="#general">general operators</a>.</li>
<li>
However, the interface of such operators was designed for their use inside
<a href="#general_combination">general
combinations</a>: you can use <b><font color="#FF6600">proportional combination</font></b>,
in which one operator is chosen among a given set of operators of same
arity according to some weights, as for simple operators except that operators
of different arities can be mixed, but you can also use <b><font color="#FF6600">sequential
combinations</font></b>, where different operators&nbsp; are applied in
turn with given probability. But you can also embed any of such combinations
at any depth.</li>
<li>
The price to pay for that is that you must use an instermediate class to
access the individuals, the <a href="#populators">eoPopulator</a> class.</li>
<li>
Thanks to that class, it also become easy to design <a href="#advanced_general">advanced
operators</a>, such as crossover operators where the mate is chosen according
to <b><font color="#FF6600">sexual preference</font></b> rather than fitness-based
preferences.</li>
</ul>
<b><font color="#FF0000">EO classes for variation operators</font></b>:
<ul>
<li>
<b><font color="#FF0000">Base classes</font></b>: all variation operators
in EO derive from the base (pure abstract) class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eoop.html">eoOp</a></font></font></b>
(as usual, click to see the inheritance diagram).&nbsp; Four (also abstract)
classes derive from <b><font color="#CC33CC">eoOp</font></b>, namely <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eomonop.html">eoMonOp</a></font></font></b>
(for <a href="#mutation">mutations</a>), <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eobinop.html">eoBinOp</a></font></font></b>
and <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eoquadop.html">eoQuadOp</a></font></font></b>
(for <a href="#crossover">crossover</a>) and <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eogenop.html">eoGenOp</a></font></font></b>
for <a href="#general">all other operators</a>.</li>
<li>
<b><font color="#FF0000">Combined classes</font></b>: those classes combine
variation operators, and are variation operators by themselves: the simple
variation operators can be combined into the corresponding <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eoproportionalcombinedmonop.html">eoProportionalCombinedMonOp</a></font></font></b>,
<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eoproportionalcombinedbinop.html">eoProportionalCombinedBinOp</a></font></font></b>
and <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eoproportionalcombinedquadop.html">eoProportionalCombinedQuadOp</a></font></font></b>.
The general operators <b><font color="#CC33CC">eoGenOp</font></b> can be
combined into some <b><font face="Arial,Helvetica"><font color="#000000"><font size=+1><a href="../../doc/html/class_eoopcontainer.html">eoOpContainer</a></font></font></font></b>,
abstract class with two implementations, <b><font face="Arial,Helvetica"><font color="#000000"><font size=+1><a href="../../doc/html/class_eoproportionalopcontainer.html">eoProportionalOpContainer</a></font></font></font></b>
and <b><font face="Arial,Helvetica"><font color="#000000"><font size=+1><a href="../../doc/html/class_eosequentialopcontainer.html">eoSequentialOpContainer</a></font></font></font></b></li>
<li>
<b><font color="#FF0000">Related classes</font></b>: General operators
of class <b><font color="#CC33CC">eoGenOp</font></b> can only be used through
the <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/class_eopopulator.html">eoPopulator</a></font></font></b>
class.</li>
</ul>
<hr WIDTH="100%"><a NAME="crossover"></a><b><font size=+1><font color="#000099">Simple
operators: </font><font color="#FF0000">Crossover</font></font></b>
<p>The characteristic of crossover operators is that they involve two parents.
However, there are crossover operators that generate two parents, and some
that generate one parent only, and both types are available in EO. The
former type (2 --> 2) is termed quadratic crossover operator, and is implemanted
in the <b><font color="#CC33CC">eoQuadOp</font></b> class; the latter type
(2 --> 1) is termed binary operator and is implemanted in class <b><font color="#CC33CC">eoBinOp</font></b>.
Both classes are, as usual, templatized by the type of individual they
can handle (see documentation for <b><font face="Arial,Helvetica"><font size=+1><a href="doc/html/class_eobinop.html">eoBinOp</a></font></font></b>
and <b><font face="Arial,Helvetica"><font size=+1><a href="doc/html/class_eoquadop.html">eoQuadOp</a></font></font></b>).
<p><b><font color="#FF0000">Note:</font></b> Whereas it is straightforward
to create a binary crossover operator from a quadratic one (by discarding
the changes on the second parent), the reverse might prove impossible (imagine
a binary crossover that simply merges the parents material: there is no
way to generate two new parents from that!).
<p><b><font color="#FF0000">Interfaces</font></b>:
<br>The general approach in EO about simple variation operators is to perform
<b><font color="#FF6600">in-place
modifications</font></b>, i.e. modifying the arguments rather than generating
new (modified) individuals. This results in the following interfaces for
the functor objects eoBinOp and eoQuadOp:
<p><b><tt><font color="#993300">void operator()(EOT &amp; , const EOT &amp;)&nbsp;</font></tt></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
for eoBinOp (note the const)
<br><b><tt><font color="#993300">void operator()(EOT &amp; , EOT &amp;
)&nbsp;</font></tt></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
for eoQuadOp
<p>which you could have guessed from the inheritance diagrams up to the
eoBF abstract class. You can also guess that only the first argument will
be modified by an oeBin object, while both arguments will be modified by
an eoQuad object.
<p><b><font color="#FF0000">Using crossover operators</font></b>:
<br>Directly applying crossover operators is straightforward from the interface
above:
<br><b><tt><font color="#993300">eoBinOpDerivedClass&lt;Indi> myBinOp(parameters);&nbsp;&nbsp;&nbsp;&nbsp;
//&nbsp; use constructor to pass</font></tt></b>
<br><b><tt><font color="#993300">eoQuadOpDerivedClass&lt;Indi> myQuadOp(parameters);&nbsp;&nbsp;
//&nbsp; any useful argument</font></tt></b>
<br><b><tt><font color="#993300">Indi eo1= ..., eo2= ...;&nbsp;&nbsp; //
the candidates to crossover</font></tt></b>
<br><b><tt><font color="#993300">myBinOp(eo1, eo2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// will modify eo1 only</font></tt></b>
<br><b><tt><font color="#993300">myQuadOp(eo1, eo2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// will modify eo1 and eo2</font></tt></b>
<p>However, you will hardly have to do so, as operators are used within
other classes, and are applied systematically to whole sets of individuals
(e.g. that have already been selected, in standard generational evolutionary
algorithms).
<br>Hence the way to use such operators will more likely ressemble, if
you are using for instance an SGA, this (<a href="FirstRealGA.html#operators">definition</a>,
<a href="FirstRealGA.html#generation">usage</a>).
See also the different ways that are described below, encapsulating the
operators into combined operators objects.
<p><a NAME="writing_crossover"></a><b><font color="#FF0000">Writing a crossover
operator:</font></b>
<br>There are only two things to modify in the <a href="../Templates/crossover.tmpl">template
class definitions</a> provided (apart from the name of the class you are
creating!)
<ul>
<li>
The <font color="#FF6600">constructor</font>, where you pass to the object
any useful parameter (see the private data at end of class definition).</li>
<li>
The <font color="#FF6600">operator()</font> method, which performs the
actual crossover.</li>
<li>
<b><font color="#FF6600">Warning</font></b>: don't forget to <b><font color="#FF6600">invalidate</font></b>
the fitness of any individual that has actually been modified. Otherwise,
the <a href="eoEval.html#lazy">lazy fitness evaluation procedure</a> in
EO might not know it should compute the fitness again and will keep the
old value.</li>
</ul>
<hr WIDTH="100%"><a NAME="mutation"></a><b><font color="#000099"><font size=+1>Simple
operators: </font></font><font color="#FF0000"><font size=+2>Mutation</font></font></b>
<br>Mutation operators modify one single individual. The corresponding
EO class is called <b><font color="#CC33CC">eoMonOp</font></b>. and it
si as usual templatized by the type of individual it can handle (see documentation
for <b><font face="Arial,Helvetica"><font size=+1><a href="doc/html/class_eomonop.html">eoMonOp</a></font></font></b>).
<p><b><font color="#FF0000">Interfaces</font></b>:
<br>The general approach in EO about simple variation operators is to perform
<b><font color="#FF6600">in-place
modifications</font></b>, i.e. modifying the arguments rather than generating
new (modified) individuals. This results in the following interface for
the functor objects eoMonOp:
<p><b><tt><font color="#993300">void operator()(EOT &amp; )</font></tt></b>
<p>which you could have guessed from the inheritance diagrams up to the
eoUF abstract class.
<p><b><font color="#FF0000">Using mutation operators</font></b>:
<br>Directly applying mutation operators is straightforward from the interface
above:
<br><b><tt><font color="#993300">eoMonOpDerivedClass&lt;Indi> myMutation(parameters);
//pass parameters in constructor</font></tt></b>
<br><b><tt><font color="#993300">Indi eo1 = ...;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// eo1 is candidate to mutation</font></tt></b>
<br><b><tt><font color="#993300">myMutation(eo1);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// will modify eo1</font></tt></b>
<p>However, you will hardly have to do so, as operators are used within
other classes, and are applied systematically to whole sets of individuals
(e.g. that have already been selected, in standard generational evolutionary
algorithms).
<br>Hence the way to use such operators will more likely ressemble, if
you are using for instance an SGA, this (<a href="FirstRealGA.html#operators">definition</a>,
<a href="FirstRealGA.html#generation">usage</a>).
See also the different ways that are described below, encapsulating the
operators into combined operators objects.
<p><a NAME="writing_mutation"></a><b><font color="#FF0000">Writing a mutation
operator:</font></b>
<br>There are only two things to modify in the <a href="../Templates/mutation.tmpl">template
class definitions</a> provided (apart from the name of the class you are
creating!)
<ul>
<li>
The <font color="#FF6600">constructor</font>, where you pass to the object
any useful parameter (see the private data at end of class definition).</li>
<li>
The <font color="#FF6600">operator()</font> method, which performs the
actual crossover.</li>
<li>
<b><font color="#FF6600">Warning</font></b>: don't forget to <b><font color="#FF6600">invalidate</font></b>
the fitness of the individual - if it has actually been modified. Otherwise,
the <a href="eoEval.html#lazy">lazy fitness evaluation procedure</a> in
EO might not know it should compute the fitness again and will keep the
old value.</li>
</ul>
<hr WIDTH="100%"><a NAME="proportional_simple"></a><b><font size=+1><font color="#000099">Combining
simple operators: </font><font color="#FF0000">proportional combinations</font></font></b>
<p>The best thing to do is to go to the <a href="eoLesson2.html#combined_operators">Lesson2</a>
of the tutorial, where everything is explained. You will find out how you
can use
<br>several mutations (respectiveley crossovers) as a single operator:
every time the operator is called, one of the available operators is chosen
by some roulette wheel selection using realtive weights.
<p>
<hr WIDTH="100%"><a NAME="general"></a><b><font color="#000099"><font size=+2>General
Operators</font></font></b>
<p>General operators in EO are variation operators that are neither simple
mutations nor simple crossovers. They can involve any number of parents,
and create any number of offspring. Moreover, they can make use of different
ways to get the parents they will involve, e.g. they can use a different
selector for each of the parents they need to select.
<p>The corresponding EO class is called <b><font color="#CC33CC">eoGenOp</font></b>.
and it is as usual templatized by the type of individual it can handle
(see documentation for <b><font face="Arial,Helvetica"><font size=+1><a href="doc/html/class_eomonop.html">eoGenOp</a></font></font></b>
:-)
<p><a NAME="interface"></a><b><font color="#FF0000">Interface</font></b>:
<br><font color="#000000">The interface for </font><b><font color="#CC33CC">eoGenOp</font></b><font color="#000000">
is based on that of another class, called </font><b><font color="#999900">eoPopulator</font><font color="#CC33CC">.
</font></b>An
<b><font color="#999900">eoPopulator</font></b>
is a <b><font color="#FF6600">population</font></b>, but also behaves like
an <b><font color="#FF6600">iterator</font></b> over a population (hence
the name, <b><font color="#FF6600">Popul</font></b>ation-Iter<b><font color="#FF6600">ator</font></b>).
<p><a NAME="populator_interface"></a>The <b><font color="#FF6600">basic
interface</font></b> of an <b><font color="#999900">eoPopulator</font></b>
(see also <a href="../../doc/html/class_eogenop.html">the documentation</a>,
of course) is the following: Individuals are accessed through the <b><tt><font color="#993300">operator*</font></tt></b>;
Basic iterator operations are available, like (pre)incrementation through
<b><tt><font color="#993300">operator++</font></tt></b>,
position management through <b><tt><font color="#993300">seekp</font></tt></b>
(returns the current position) and <b><tt><font color="#993300">tellp</font></tt></b>
(go to a given position); Individuals can also be <b><font color="#993300">insert</font></b>ed
and <b><font color="#993300">erase</font></b>d at current position using
the corresponding methods; last but not least, as the individuals are returned
by reference, it is mandatory to ensure that they will not be moved around
later: the memory management&nbsp; routine reserve is called whenever there
is a chance to add some individuals in the population.
<p>This results in the following general interface for an <b><font color="#CC33CC">eoGenOp</font></b>:
It receives as argument an <b><font color="#999900">eoPopulator</font></b>,
gets the individuals it needs using the <b><tt><font color="#993300">operator*</font></tt></b>,
and must handle the positinning of the&nbsp; using the <b><tt><font color="#993300">operator++</font></tt></b>
method.
<p><b><tt><font color="#993300">void operator()(</font><font color="#999900">eoPopulator</font><font color="#993300">&amp;
_pop)</font></tt></b>
<br><b><tt><font color="#993300">{</font></tt></b>
<br><tt><font color="#993300"><b>&nbsp; EOT &amp; eo1 = *_pop; </b>// get
(select if necessary) the guy</font></tt>
<br><tt><font color="#993300"><b>&nbsp; ++_pop;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// advance</font></tt>
<br><tt><font color="#993300"><b>&nbsp; EOT &amp; eo2 = *_pop; </b>// get
(select if necessary) the guy</font></tt>
<br><tt><font color="#993300"><b>&nbsp; ++_pop;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// advance</font></tt>
<br><b><tt><font color="#993300">...</font></tt></b>
<br><tt><font color="#993300"><b>&nbsp; EOT &amp; eoN = *_pop; </b>// get
(select if necessary) the guy</font></tt>
<br><tt><font color="#993300"><b>&nbsp; ++_pop;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// advance</font></tt>
<p><tt><font color="#993300">// do whatever the operator is supposed to
do</font></tt>
<br><b><tt><font color="#993300">}</font></tt></b>
<p><b><font color="#FF6600">What happens next?</font></b> Well, it all
depends on how many parents and how many offspring your general op needs:
<ul>
<li>
If the number of generated offspring is <font color="#FF6600">equal</font>
to the number of parents, the operator simply needs to modify them (they
are passed by reference, no useless copy takes place).</li>
<li>
If the operator produces <font color="#FF6600">more offspring than there
were parents</font>, it needs to insert them into the list using the <b><tt><font color="#993300">insert</font></tt></b>
method of the class <b><font color="#999900">eoPopulator</font></b> as
in the following:</li>
<p><br><b><tt><font color="#993300">void operator()(</font><font color="#999900">eoPopulator</font><font color="#993300">&amp;
_pop)</font></tt></b>
<br><b><tt><font color="#993300">{</font></tt></b>
<br><tt><font color="#993300"><b>&nbsp; EOT &amp; eo1 = *_pop; </b>// get
(select if necessary) the guy</font></tt>
<br><tt><font color="#993300"><b>&nbsp; ++_pop;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// advance</font></tt>
<br><tt><font color="#993300">&nbsp; // Now create second offspring - eo1
is modified too!</font></tt>
<br><b><tt><font color="#993300">&nbsp; EOT eo2 = create_individual(eo1);</font></tt></b>
<br><tt><font color="#993300">&nbsp; // inserts eo2 in _pop after eo1</font></tt>
<br><b><tt><font color="#993300">&nbsp; _pop.insert(eo2);</font></tt></b>
<br><b><tt><font color="#993300">...</font></tt></b>
<br>Of course the size of the resulting population will grow - and you
should have a replacement procedure that takes care of that.
<li>
The case where <font color="#FF6600">more parents are needed than offspring
will be created</font> is a little more delicate: think about <b><font color="#CC33CC">eoBinOp</font></b>,
and try to imagine the reasons why no crossover of that class asre used
in the first lessons of the tutorial, within the SGA framework. There are
two possibilities:</li>
<ul>
<li>
If you think "generational", the first idea is to get the parents from
outside the curent list, so the total number of (intermediate) offspring
is always equal to the initial population size. By chance, the <b><font color="#999900">eoPopulator</font></b>has
a handle on the initial population that was used to start the process,
and you can access it from inside the GenOp method. For instance</li>
<br>&nbsp;
<p>&nbsp;
<p><b><tt><font color="#993300">void operator()(</font><font color="#999900">eoPopulator</font><font color="#993300">&amp;
_pop)</font></tt></b>
<br><b><tt><font color="#993300">{</font></tt></b>
<br><tt><font color="#993300"><b>&nbsp; EOT &amp; eo1 = *_pop; </b>// get
(select if necessary) the guy</font></tt>
<br><tt><font color="#993300"><b>&nbsp; ++_pop;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// advance</font></tt>
<br><b><tt><font color="#993300">&nbsp; const EOT &amp; eo2 = </font><font color="#009900">select</font><font color="#993300">(_pop.source());</font></tt></b>
<p>where select is any selector you like. Note the const: you are not allowed
to modify an element of the original population (but you could of course
have copied it!). Now to find out where that selector comes from, you'll
have to wait until next section. If you can't wait, go directly there.
<li>
If you don't care about the size of the offspring population, you can use
the delete method of the class <b><font color="#999900">eoPopulator</font></b>.
For instance</li>
<br><b><tt><font color="#993300">void operator()(</font><font color="#999900">eoPopulator</font><font color="#993300">&amp;
_pop)</font></tt></b>
<br><b><tt><font color="#993300">{</font></tt></b>
<br><tt><font color="#993300"><b>&nbsp; EOT &amp; eo1 = *_pop; </b>// get
(select if necessary) the guy</font></tt>
<br><tt><font color="#993300"><b>&nbsp; ++_pop;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// advance</font></tt>
<br><tt><font color="#993300"><b>&nbsp; EOT &amp; eo2 = *_pop; </b>// get
(select if necessary) the guy</font></tt>
<br><tt><font color="#993300"><b>&nbsp; ++_pop;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// advance</font></tt>
<br><tt><font color="#993300">&nbsp; // do whatever needs to be done, modifying
eo1 but not eo2</font></tt>
<br><tt><font color="#993300"><b>&nbsp; _pop.delete();&nbsp;&nbsp; </b>//
removes (untouched) eo2 from the list</font></tt></ul>
</ul>
<b><font color="#FF6600">Warning</font></b>: if you use operators that
have different number of parents than offspring, you are deviating from
the simple generational approach. Be careful to have the proper replacement
procedure to take care of the population size: in most instances of algorithms
that come within EO, this is enforced (an exception is thrown if population
size varies from one genertaion to the other) but this might not be true
for all forthcoming EO algorithms.
<p><b><font color="#FF0000">Using general operators</font></b>:
<br>Directly applying general operators to given individuals is impossible
in EO, due to its <a href="#interface">interface</a>. You need the help
of an individual dispenser of class <b><font color="#999900">eoPopulator</font></b>.
But anyway general operators were thought to be used mainly in combination
of one another, as described <a href="#general_combination">below</a>.
<p><a NAME="writing_mutation"></a><b><font color="#FF0000">Writing a general
operator:</font></b>
<br>There are many things to modify in the <a href="../Templates/mutation.tmpl">template
class definitions</a> provided.
<ul>
<li>
The <font color="#FF6600">constructor</font>, where you pass to the object
any useful parameter (see private data at end of class definition).</li>
<li>
The <font color="#FF6600">operator()</font> method, which performs the
actual crossover. Remember you must use the argument <b><font color="#999900">eoPopulator</font></b>to
access the members of the [p[ulation in turn (method
<b><tt><font color="#993300">operator*</font></tt></b>),
you may use the initial population (method <b><tt><font color="#993300">source()</font></tt></b>),
as well as the <b><tt><font color="#993300">insert</font></tt></b> or <b><tt><font color="#993300">delete</font></tt></b>
methods.</li>
<br><b><font color="#FF6600">Warning</font></b>: as usual, don't forget
to <b><font color="#FF6600">invalidate</font></b> the fitness of the individual
- if it has actually been modified. Otherwise, the <a href="eoEval.html#lazy">lazy
fitness evaluation procedure</a> in EO will not know it should compute
the fitness again and will keep the old value.</ul>
<hr WIDTH="100%"><a NAME="populators"></a><b><font color="#000099"><font size=+2>The
populators:</font></font></b>
<br>The public interface class <b><font color="#999900">eoPopulator</font></b>
has been described above. However, a protected method, termed <b><tt><font color="#993300">select</font></tt></b>,&nbsp;
is used inside the object to get new parents for the following operator,
and its implementation distinguishes two types of <b><font color="#999900">eoPopulator</font></b>:
<ul>
<li>
The <b><font color="#999900">eoSeqPopulator</font></b> gets new parents
from its source (the initial population). When the source is exhausted,
an exception if thrown. The idea of such pooulator is to start from a population
of already selected individuals.</li>
<br>The programmer should hence be very careful that the number of available
parents matches the requirements of the operators when using an <b><font color="#999900">eoSeqPopulator</font></b>
object.
<li>
The <b><font color="#999900">eoSelectivePopulator</font></b> , on the opposite,
always gets new parents using its private <b><font color="#009900">eoSelectOne</font></b>
object (passed at construct time). Hence it can handle any number of parents
at will. The idea of such populator is to handle the whole <b><font color="#FF6600">breeding</font></b>
process, i.e. selection and variation operators.</li>
</ul>
An immediate consequence is that if you are not sure of the numebr of&nbsp;
parents you will need in some operators (e.g. because of some stochastic
proportional selection ebtween operators that don't need the same number
of parents, then you <b><font color="#FF6600">must</font></b> use an <b><font color="#CC33CC">eoSelectivePopulator</font></b>
to apply the variation operators to the population.
<br>
<hr WIDTH="100%"><a NAME="general_combination"></a><b><font color="#000099"><font size=+2>General
Combinations:</font></font></b>
<br>There are two main ways to use and combine general operators in EO:
the proportional combination, similar to what has been described for simple
operators <a href="#proportional_simple">above</a>, and the sequential
combination, which amounts to apply all operators in turn to a bunch of
individuals, each operator being applied with a specific probability.
<p><a NAME="prop_container"></a><b><font color="#FF0000">Proportional combinations</font></b>
<br>When called upon a population (through an <b><font color="#999900">eoPopulator</font></b>
object), an <b><font color="#CC33CC">eoProportionalOpContainer</font></b>
enters the following loop:
<p>while there are individuals left in the list
<ul>
<li>
choose one of the included operators according to their relative rates
(by some roulette wheel random choice)</li>
<li>
applies the chosen operator. The parents are dispensed to the operator
from the list on demand.</li>
<li>
What happens next exactly depends on the type of operator, but basically,
some of the parents get modified, some might get removed from the list
and some new individual might get inserted on the list.</li>
<li>
updates the list pointer (if needed) to the individual following the ones
that just have been modified/inserted/deleted.</li>
</ul>
<a NAME="seqential_container"></a><b><font color="#FF0000">Sequential combinations</font></b>
<br>When it is called upon a list of pending candidates, an
<b><font color="#CC33CC">eoSequentialOpContainer</font></b>
enters the following loop:
<p>mark the current position
<br>for all operators it contains,
<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 be
modified, or some can be deleted from the list, or some offspring can be
inserted in the list.</li>
<li>
If false, move the pointer over the required number of parents (i.e. don't
modify thoses parents)</li>
</ul>
<li>
Next pending parent</li>
</ul>
<li>
Next operator</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 to
all concepts.
<br><font color="#FF6600">Exercise</font>: write the code to perform an
eoSGA 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 similar
to all other <b><tt><font color="#993300">add</font></tt></b> methods in
other Combined things in eo (as the simple eoProportionalCombinedXXXop
described above, but also the eoCombinedContinue class or the eoCheckPoint
class).
<br>The syntax is straightforward, and it works with any of the operator
classes <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&lt;Indi> myOperator;</font></tt></b>
<br><b><tt><font color="#993300">eoYYYOpContainer&lt;Indi> myOpContainer;</font></tt></b>
<br><tt><font color="#993300"><b>myOpContainer.add(myOperator, rate); </b>//
rate: double whose <b>meaning depends on XXX</b></font></tt>
<p>where YYY can be one of Proportional and Sequential.
<br><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 take
any value, the only important thing is their <b><font color="#FF6600">relative
values</font></b>.</li>
<li>
The "rates" for <b><font color="#CC33CC">eoSequentialOpContainer </font></b>actually
are <b><font color="#FF6600">probabilities</font></b>, i.e. they will be
used in a coin-flipping to determine whether that particuler operator will
be 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 operator
will be applied systematically - this is equivalent of a rate equal to
1).</li>
</ul>
<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 applied
on 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>,(one
operator is chosen by roulette_wheel, and applied once before control is
given back to the caller), the main loop in method <b><tt><font color="#993300">operator()
</font></tt></b>of
class <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">type
of <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 two
parents and modifies them. The eoMonOp is then called starting from the
forst of thoses two modified individuals, and is hence applied twice, once
on 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 one
parent 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 selector
to get the parent its need and will modify it and put 2 additional offspring
at 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 populator
iterator 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 new
call to the embedded <b><font color="#009900">eoSelectOne</font></b> of
the&nbsp; and everything will go on smoothly, except that a total of 4
offspring 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&nbsp; 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> that
contains an <b><font color="#CC33CC">eoSequentialOpContainer</font></b>,
though not technically forbiddden, will most produce something&nbsp; totally
unpredictable, 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>Advanced
general 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">sexual
preferences</font></b>, i.e. choose a mate for a first parent according
to some characteritics of that first parent).
<br>This is made possible in EO because the general operators have a handle
on the initial population through the method source() of the argument eoPopulator
they work on. Their <b><tt><font color="#993300">operator()</font></tt></b>
method shoudl look like
<p><b><tt><font color="#993300">void operator()(</font><font color="#999900">eoPopulator</font><font color="#993300">&amp;
_pop)</font></tt></b>
<br><b><tt><font color="#993300">{</font></tt></b>
<br><tt><font color="#993300"><b>&nbsp; EOT &amp; eo1 = *_pop; </b>// get
(select if necessary) the first guy</font></tt>
<br><b><tt><font color="#993300">&nbsp; ++_pop;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font></tt></b><tt><font color="#993300">// advance</font></tt>
<br><b><tt><font color="#993300">&nbsp; EOT &amp; eo2 = </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 supposed to
do</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,&nbsp;
in its constructor for instance, which should give something like:
<p><b><tt><font color="#993300">sexualSelectorType&lt;Indi>&nbsp; findBlonde;</font></tt></b>
<br><b><tt><font color="#993300">sexualOperatorType&lt;Indi> yourBrainAndMyBeauty(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">General
Operators</a> - <a href="#populators">Populators</a> - <a href="#general_combination">General
combinations</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">Programming
hints</a> -<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
documentation</a></font></font></b>
<br>
<hr>
<address>
<a href="mailto:Marc.Schoenauer@polytechnique.fr">Marc Schoenauer</a></address>
<br><!-- Created: Mon Oct 30 07:27:13 CET 2000 --><!-- hhmts start -->Last
modified: Fri Dec. 8 2000&nbsp;<!-- hhmts end -->
<br>&nbsp;
</body>
</html>