Added some explanations about the memory mangement (through eoFunctorStore)

This commit is contained in:
evomarc 2002-03-06 06:25:40 +00:00
commit dcee458c27
5 changed files with 266 additions and 86 deletions

View file

@ -2,7 +2,7 @@
<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-21mdk i686) [Netscape]">
<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">
@ -142,7 +142,7 @@ See the parameter section of the Component-Based tutorial, or wait until
class, whose only purpose is the input of parameters.</font></li>
</ul>
<hr WIDTH="50%"><A NAME="paraminput"><b><font color="#000099">eoParser:</font><font color="#FF0000">
<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 values
are read, by order of priority</font>
@ -172,10 +172,10 @@ the general syntax to modify parameter value at run-time is (either from
the command-line or in a text file)</li>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b><tt><font color="#660000">--longKeyword=value</font></tt></b>&nbsp;&nbsp;&nbsp;&nbsp;
or&nbsp;&nbsp;&nbsp;&nbsp; <b><tt><font color="#660000">-cvalue</font></tt></b>&nbsp;&nbsp;&nbsp;
if 'c' is the short keyword (though <b><tt><font color="#660000">-c=value</font></tt></b> also works)
if 'c' is the short keyword (though <b><tt><font color="#660000">-c=value</font></tt></b>
also works)
<br>&nbsp;
<li>
so, after compiling the executable for Lesson 3 (<b><tt><font color="#FF6666">make
@ -183,12 +183,10 @@ lesson3</font></tt></b> at system prompt in Unix), you can try to type
in</li>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b><tt><font color="#FF6666">SecondBitEA</font></tt></b>
<br>and see the algorithm run as before (OneMax optimized on 8-bits bitstrings).
But you can now type in
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b><tt><font color="#FF6666">SecondBitEA --vecSize=100</font></tt></b>
<br>and see the output of the optimization of OneMax on 100-bit bitstrings.
<br>&nbsp;
@ -196,7 +194,6 @@ But you can now type in
Take a look at all available parameters by typing in</li>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b><tt><font color="#FF6666">SecondBitEA --help</font></tt></b>
<br>or by going into the code: all parameter inputs have been grouped in
the
@ -208,7 +205,8 @@ it contains the list of all actual parameters used, and can directly be
used as parameter input file: change the file name (e.g. to <b><tt><font color="#660000">SecondBitEA.param</font></tt></b>),
edit it, change whichever parameter you want, and type in</li>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b><tt><font color="#FF6666">SecondBitEA @SecondBitEA.param</font></tt></b>
<br>and you will see all values that you defined into the file taken into
account.
@ -247,7 +245,9 @@ of eoParam returns a reference, so you can eventually modify its value
somewhere else later (though of course this is not any useful for variable
<b><tt><font color="#660000">seed</font></tt></b>!).</li>
</ul>
There is however another way to achieve the same result in less lines of
code - with a different memory management (see <a href="eoLesson4.html#parameters">Lesson4</a>).
<br>
<hr WIDTH="100%">
<br><a NAME="state"></a><b><font color="#000099"><font size=+2>eoState:
saving and loading</font></font></b><font color="#000000">You might have
@ -276,7 +276,11 @@ method, as done <a href="SecondBitEA.html#loadstate">here</a>.</font>
method for an </font><b><tt><font color="#3366FF">eoState</font></tt></b><font color="#000000">
object anywhere in the code. But the <a href="#statesaver">checkpointing</a>
mechanism offers you better ways to do that - and it's so easy ....</font>
<p>
<p>Note that an eoState alos has another use in EO whan it comes to memory
management: it can be a repository of pointers that are not allocated within
obects - allowing to delete them by simply deleting the eoState (see <a href="eoLesson4.html#memory">Lesson
4)</a>.
<br>
<hr WIDTH="100%"><a NAME="checkpoint"></a><b><font color="#000099"><font size=+2>eoCheckpoint:
every generation I'd like to ...</font></font></b>
<br><font color="#000000">The checkpointing mechanism is a very powerful
@ -544,4 +548,4 @@ documentation</a></font></font></b>
<br><!-- Created: Fri Nov 3 18:49:12 CET 2000 --><!-- hhmts start -->Last
modified: None of your business!<!-- hhmts end -->
</body>
</html>
</html>

View file

@ -2,12 +2,12 @@
<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-21mdk i686) [Netscape]">
<meta name="GENERATOR" content="Mozilla/4.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]">
<title>Tutorial: Lesson 4</title>
</head>
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
<a href="eoLesson2.html">Lesson 3</a> -
<a href="eoLesson4.html">Lesson
<a href="eoLesson3.html">Lesson 3</a> -
<a href="eoLesson5.html">Lesson
5</a> -
<a href="eoTutorial.html">Main page</a> -
<a href="eoTopDown.html">Algorithm-Based</a>
@ -485,8 +485,8 @@ Bounds for uniform initialization of the real variables. The syntax for
this parameter given in the </font><b><tt><font color="#CC33CC"><font size=+1>objectBounds</font></font></tt></b><font color="#000000">
parameter description below. This argument is mandatory, furthermore the
given bounds </font><b><font color="#FF6600">must be bounded</font></b><font color="#000000">.
</font><font color="#FF0000">The default is [-1,1]</font><font color="#000000">
for all variables.</font>
</font><font color="#FF0000">The
default is [-1,1]</font><font color="#000000"> for all variables.</font>
<br>Note that this parameter is independent of the <b><tt><font color="#CC33CC"><font size=+1>objectBounds</font></font></tt></b>
parameter below.
<p><b><tt><font color="#CC33CC"><font size=+1># --sigmaInit=0.3 # -s :
@ -726,10 +726,88 @@ correlated mutation. </font><font color="#FF0000">Default is 0.0873</font><font
<p>
<hr WIDTH="100%">
<br><a NAME="programmerguide"></a><b><font color="#000099"><font size=+2>Programmer's
guide
<hr WIDTH="100%"></font></font></b><font color="#000000"><a href="eoLesson2.html">Lesson
guide</font></font></b>
<p>At the moment, you will have to browse in the source (colored!) code
(<a href="BitEA.html">Bit</a> - Real) almost by yourself, sorry.
<p>Note that the main file is now very slim, as it only contains calls
to some <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
functions - these functions contain the actual code, very similar to the
code of Lesson3, except for the memory management, performed through an
<b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_state.html">eoState</a></font></font></tt></b>
object (notice that all <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
calls have an eoState as second parameter).
<p><b><font color="#000099"><font size=+2>Programmer's guide: </font></font><font color="#FF0000">The
make_xxx files</font></b>
<p><b><font color="#FF0000">Interface</font></b>: all <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
files have as first two parameters an <b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_parser.html">eoParser</a></font></font></tt></b>
and an <b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_state.html">eoState</a></font></font></tt></b>.
The <b><tt><font color="#3366FF"><font size=+1>eoParser</font></font></tt></b>
is be used within all functions to parse the command-line and/or a parameter
file in order to read any relevant user-parameter, while the <b><tt><font color="#3366FF"><font size=+1>eoState</font></font></tt></b>
is used here to store all pointers to be allocated inside the function
(see <a href="eoProgramming.html#memory">Programming hints</a> for more
detailed explanations).
<p>There are 2 types of <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
files: the ones that do depend on representation, defining the <b><font color="#FF9900">genotype
</font></b>and
<b><font color="#CC33CC">initialization</font></b> (<b><tt><font color="#CC33CC"><font size=+1>make_genotype_xxx</font></font></tt></b>,
with xxx being the type of genotype) and variation operators (<b><tt><font color="#CC33CC"><font size=+1>make_op_xxx</font></font></tt></b>),
and the one that are truly representation-independent (<b><tt><font color="#993300"><font size=+1>make_pop,
make_continue, make _checkpoint, make_algo </font></font></tt></b><font color="#000000">and</font><b><tt><font color="#993300"><font size=+1>
make_run</font></font></tt></b>).
<br>The former are located in the directory corresponding to the actual
genotype (<b><tt><font color="#FF9900"><font size=+1>src/ga</font></font></tt></b>
for eoBit, <b><tt><font color="#FF9900"><font size=+1>src/es</font></font></tt></b>
for eoReal and all eoESxxx genotypes). The latter are in the directory
<b><tt><font color="#993300"><font size=+1>src/do.</font></font></tt></b>
<p>If you take a close look at the code of <b><tt><font color="#993300"><font size=+1><a href="../../src/do/make_continue.h">make_continue</a></font></font></tt></b>
for instance, you will first notice that ... the function declared there
is called <b><tt><font color="#993300"><font size=+1>do_make_continue</font></font></tt></b>
and is not <a href="BitEA.html#continue">the one you are calling</a> in
the main file, though it has the same parameters as arguments.
<br>The explanation lies within the file <b><tt><font color="#FF9900"><font size=+1>make_continue_xxx.cpp</font></font></tt></b>
(with xxx = ga or real/es)which, as its color (and name)&nbsp; should have
told you about, are representation-dependent: in fact the <b><tt><font color="#FF9900"><font size=+1>make_continue_xxx.cpp</font></font></tt></b>
files only instanciates the general &lt;EOT> template into one of the possible
template for eoBit or eoReal/eoES - and this trick allows to <b><font color="#FF6600">compile
them separately</font></b>!
<p>The other thing that you should notice is that the code there is very
similar to the code that was in Lesson 3,&nbsp; regarding parameter reading
and type of object that are allocated - except for memory management. This
goes for all <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
files - so the only thing you need to understand how it goes is to look
at the <a href="#memory">memory management section</a>.
<p><b><font color="#FF0000">Pros</font></b>: you don't have to handle a
huge main function - and many of the make_xxx files can be directly used
in different applications (this is called <b><font color="#FF6600">modularity</font></b>
:-)))
<br>More interesting, you can even <b><font color="#FF6600">compile</font></b>
the <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
files <b><font color="#FF6600">separately</font></b> for a given target
template, and link them e.g. with your fitness function when it is ready
(remember that up to now you needed to compile everything altogether by
including the code into your mail fine). Indeed, if you do a global make,
you will notice that there are additional libraries compiled in <b><tt><font color="#FF9900"><font size=+1>src/ga</font></font></tt></b>
and <b><tt><font color="#FF9900"><font size=+1>src/es</font></font></tt></b>
...
<p><b><font color="#FF0000">Cons</font></b>: It makes the code a little
more complex to understand, first because of the indirection needed for
pre-compilation with a given template, and second because of the memory
management that this imposes.
<p><a NAME="memory"></a><b><font color="#000099"><font size=+2>Programmer's
guide: </font></font><font color="#FF0000">Memory management</font></b>
<br>As already said, all functions have an <b><tt><font color="#3366FF"><font size=+1>eoState</font></font></tt></b>
as second argument - and that object is used to store the functor objects
that were simply declared as variables of the main function up to now :
see <a href="eoProgramming.html#memory">Programming hints</a> for more
detailed explanations and take a look at the code of <b><tt><font color="#993300"><font size=+1><a href="../../src/do/make_continue.h">make_continue</a></font></font></tt></b>
for instance, you will see the implementation of the memory management
in action.
<br>&nbsp;
<p>
<hr WIDTH="100%"><font color="#000000"><a href="eoLesson3.html">Lesson
3</a> -
<a href="eoLesson4.html">Lesson 5</a> -
<a href="eoLesson5.html">Lesson 5</a> -
<a href="eoTutorial.html">Main
page</a> -
<a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based</a>

View file

@ -2,7 +2,7 @@
<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-21mdk i686) [Netscape]">
<meta name="GENERATOR" content="Mozilla/4.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]">
<title>Variation Operators</title>
</head>
<body text="#000000" link="#0000EF" vlink="#51188E" alink="#FF0000" background="beige009.jpg">
@ -148,27 +148,27 @@ an eoQuad object.
<br>Directly applying crossover operators is straightforward from the interface
above:
<br><tt><font color="#993300"><b>eoBinOpDerivedClass&lt;Indi> myBinOp(parameters);
</b>//&nbsp; use constructor to pass</font></tt>
</b>//&nbsp;
use constructor to pass</font></tt>
<br><tt><font color="#993300"><b>eoQuadOpDerivedClass&lt;Indi> myQuadOp(parameters);
</b>//&nbsp;
any useful argument</font></tt>
<br><tt><font color="#993300"><b>Indi eo1= ..., eo2= ...;&nbsp;&nbsp; </b>//
the candidates to crossover</font></tt>
<br><b><tt><font color="#993300">if (myBinOp(eo1, eo2))</font></tt></b>
<br><tt><font color="#993300"><b>&nbsp;&nbsp; { ...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br><tt><font color="#993300"><b>&nbsp;&nbsp; { ...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// eo1 has been modified, <b>not</b> eo2</font></tt>
<br><b><tt><font color="#993300">&nbsp;&nbsp; }</font></tt></b>
<br><tt><font color="#993300"><b>else ...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br><tt><font color="#993300"><b>else ...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// none has been modified</font></tt>
<br><b><tt><font color="#993300">if (myQuadOp(eo1, eo2))</font></tt></b>
<br><tt><font color="#993300"><b>&nbsp;&nbsp; { ...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br><tt><font color="#993300"><b>&nbsp;&nbsp; { ...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// both eo1 and eo2 have been modified</font></tt>
<br><b><tt><font color="#993300">&nbsp;&nbsp; }</font></tt></b>
<br><tt><font color="#993300"><b>else ...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br><tt><font color="#993300"><b>else ...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// none has been modified</font></tt>
<p>However, you will hardly have to actually apply operators to individuals,
@ -225,13 +225,12 @@ above:
<br><tt><font color="#993300"><b>Indi eo = ...;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/</b>/ eo is candidate to mutation</font></tt>
<br><b><tt><font color="#993300">if (myMutation(eo))</font></tt></b>
<br><tt><font color="#993300"><b>&nbsp;&nbsp; { ...&nbsp;&nbsp;&nbsp;&nbsp;
</b>// eo has been modified</font></tt>
<br><tt><font color="#993300"><b>&nbsp;&nbsp; { ...&nbsp;&nbsp;&nbsp; </b>//
eo has been modified</font></tt>
<br><b><tt><font color="#993300">&nbsp;&nbsp; }</font></tt></b>
<br><tt><font color="#993300"><b>else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// eo has not been modified</font></tt>
<br><tt><font color="#993300"><b>else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>//
eo has not been modified</font></tt>
<p>However, you will hardly have to actually apply operators to individuals,
as operators are used within other classes, and are applied systematically
to whole sets of individuals (e.g. that have already been selected, in
@ -303,29 +302,47 @@ but rather through objects of type <a href="#general_combination">eoOpContainer<
<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.
and must handle the positinning of the&nbsp; using the <b><tt><font color="#993300">++operator</font></tt></b>
method (<b><font color="#FF6600">Warning</font></b>: the <b><tt><font color="#993300">operator++</font></tt></b>
method is not defined, as recommended by many good-programming-style books).
<p><a NAME="apply"></a><b><tt><font color="#993300">bool apply()(</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;&nbsp; EOT&amp; parent1 = *_pop;
</b>//
select the first parent</font></tt>
<br><tt><font color="#993300"><b>&nbsp;&nbsp; ++_plop;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// advance once for each selected parents</font></tt>
<br><tt><font color="#993300"><b>&nbsp;&nbsp; ++_plop;&nbsp;&nbsp;
</b>//
advance once for each selected parents</font></tt>
<br><b><tt><font color="#993300">&nbsp;&nbsp; ...</font></tt></b>
<br><tt><font color="#993300"><b>&nbsp;&nbsp; EOT&amp; parentN = *_pop;
</b>//
select the last parent</font></tt>
<br><tt><font color="#993300"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// don't advance after the last one: _plop always</font></tt>
<br><tt><font color="#993300"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b>//
don't advance after the last one: _plop always</font></tt>
<br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// points to the last that has already been treated</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">Warning</font></b>: as said above, an eoPopulator
should always point to the last individual that has already been treated.
This is because it is intended to be used within a loop that looks like
(see e.g. <b><tt><a href="../../doc/html/classeo_general_breeder.html">eoBreeder</a></tt></b>
class):
<p><tt><font color="#993300"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eoSelectivePopulator&lt;EOT>
popit(_parents, _offspring, select);</b>&nbsp;&nbsp;&nbsp; // eoSelect
is an eoSelectOne</font></tt>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (_offspring.size()
&lt; target)</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
op(popit);</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
++it;</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}</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>
@ -340,9 +357,7 @@ were parents</font>, it needs to insert them into the list using the <b><tt><fon
method of the class <b><font color="#999900">eoPopulator</font></b> as
in the following:</li>
<br>&nbsp;
<p>&nbsp;
<p><b><tt><font color="#993300">void apply()(</font><font color="#999900">eoPopulator</font><font color="#993300">&amp;
<p><br><b><tt><font color="#993300">void apply()(</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; </b>// get the necessary number
@ -380,10 +395,8 @@ 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 apply()(</font><font color="#999900">eoPopulator</font><font color="#993300">&amp;
<b><tt><font color="#993300"></font></tt></b>
<p><br><b><tt><font color="#993300">void apply()(</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; </b>// get as many parents as you
@ -414,8 +427,8 @@ If you don't care about the size of the offspring population (that is,
if that size os controlled elsewhere, e.g. in some external loop), you
can use the inbedded select method of the class <b><font color="#999900">eoPopulator</font></b>.
For instance</li>
<br><b><tt><font color="#993300">void apply()(</font><font color="#999900">eoPopulator</font><font color="#993300">&amp;
<b><tt><font color="#993300"></font></tt></b>
<p><br><b><tt><font color="#993300">void apply()(</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; </b>// get as many parents as you
@ -555,7 +568,8 @@ of parents, then you <b><font color="#FF6600">must</font></b> use an <b><font co
to apply the variation operators to the population, and thus get exactly
the number of offspring you want.
<p><b><font color="#FF0000">Example</font></b>: An <b><font color="#CC33CC">eoSelectivePopulator</font></b>
is the main ingredient of the <b><tt><font color="#FF6666">eoGeneralBreeder</font></tt></b><a href="../../doc/html/eogeneralbreeder_h-source.html#l00061">operator()
is the main ingredient of the <b><tt><font color="#FF6666">eoGeneralBreeder
</font></tt></b><a href="../../doc/html/eogeneralbreeder_h-source.html#l00061">operator()
method</a> - a class that creates a population of offspring from the parents
applying an eoGenOp (usually an eoOpContainer) to all selected parents
in turn.
@ -758,17 +772,21 @@ _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; EOT &amp; maBlonde = </font><font color="#009900">findBlonde</font><font color="#993300">(_pop.source());
<br><b><tt><font color="#993300">&nbsp; 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">&nbsp; // do whatever the operator is supposed
to do</font></tt>
to do, e.g</font></tt>
<br><tt><font color="#993300">&nbsp; <b>cross(eo1, maBonde);</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// cross is some embedded crossover</font></tt>
<br><tt><font color="#993300">&nbsp; <b>...</b></font></tt>
<br><tt><font color="#993300">&nbsp; // if you want to put maBlonde into
the offspring, you must</font></tt>
<br><tt><font color="#993300"><b>&nbsp; ++_pop;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// advance</font></tt>
<br><tt><font color="#993300">&nbsp; // if you don't want to put maBlonde
into the offspring,</font></tt>
<br><tt><font color="#993300">&nbsp; // stop here (and use a reference
to maBlonde above). Otherwise</font></tt>
<br><tt><font color="#993300">&nbsp; <b>maBonde.invalidate();</b></font></tt>
<br><tt><font color="#993300"><b>&nbsp;++_pop;&nbsp;&nbsp;&nbsp; </b>//
advance</font></tt>
<br><tt><font color="#993300">&nbsp; <b>_pop.insert(maBlonde);</b>&nbsp;&nbsp;&nbsp;
// and insert it</font></tt>
<br><b><tt><font color="#993300">}</font></tt></b>
@ -776,7 +794,8 @@ the offspring, you must</font></tt>
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>
<br><b><tt><font color="#993300">sexualOperatorType&lt;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>
@ -790,10 +809,10 @@ documentation</a></font></font></b>
<br>
<hr>
<address>
<a href="mailto:Marc.Schoenauer@polytechnique.fr">Marc Schoenauer</a></address>
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
<br><!-- Created: Mon Oct 30 07:27:13 CET 2000 --><!-- hhmts start -->Last
modified: Sat. Feb. 17 2001&nbsp;<!-- hhmts end -->
modified: Sat. Feb. 17 2002&nbsp;<!-- hhmts end -->
<br>&nbsp;
</body>
</html>

View file

@ -2,23 +2,22 @@
<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-21mdk i686) [Netscape]">
<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">Tutorial
main 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">EO
<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">EO
documentation</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">Random
numbers</a> - <a href="#notations">EO programming style</a>
numbers</a> - <a href="#notations">EO programming style</a>&nbsp; - <a href="#memory">Memory
management</a>
<br>
<hr WIDTH="100%">
<center>
@ -77,11 +76,14 @@ into three derived class. These classes tell you immediately what kind
of arguments the <b><tt><font color="#993300">operator()</font></tt></b>
method requires and what kind of result it produces. See <a href="#notations">EO
conventions</a>, and the <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_functor_base.html">inheritance
diagram of class eoFunctorBase</a>.</font></font></b>
diagram of class eoFunctorBase</a>.&nbsp;</font></font></b> Also note that
if 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 management
mechanism</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
paradigm is borrowed from there.
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 paradigm
is 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 functor
object: First code the class:
@ -372,7 +374,13 @@ myfunction(unsigned </font><font color="#FF6600">_popSize</font><font color="#99
The initialization parameters of constructors should be named from the
names of the variables they are used to initialize, e.g.</li>
<p><br><b><tt><font color="#993300">class eoMyClass</font></tt></b>
<br>&nbsp;
<p>&nbsp;
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<p><b><tt><font color="#993300">class eoMyClass</font></tt></b>
<br><b><tt><font color="#993300">{</font></tt></b>
<br><b><tt><font color="#993300">public:</font></tt></b>
<br><b><tt><font color="#993300">&nbsp; eoMyClass(unsigned _popSize):</font><font color="#FF6600">popSize(_popSize)</font><font color="#993300">{...}</font></tt></b>
@ -396,18 +404,91 @@ or&nbsp; <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/c
Blabla</li>
</ul>
<hr WIDTH="100%">
<br><a NAME="memory"></a><b><font color="#000099"><font size=+1>EO memory
management</font></font></b>
<p>Most of EO constructs are based on the <b><font color="#FF6600">encapsulation</font></b>
of objects into other objects, and the embedded objects are passed through
the constructor of the embedding object.
<br>For instance, the construction of an algorithm requires a breeder (plus
many other things of course), the construction of a breeder usually requires
a selector, and in turn the construction of a selector requires some parameters.
This gives something resembling the following
<p><b><tt><font color="#993300">eoTournamentSelection&lt;EOT>&nbsp; select(tSize);</font></tt></b>
<br><b><tt><font color="#993300">eoBreeder&lt;EOT> breed(select);</font></tt></b>
<br><b><tt><font color="#993300">eoEasyAlgo&lt;EOT> algo( ..., breed, ...);</font></tt></b>
<p>Such a practice is no problem when doing <b><font color="#FF6600">everything
in a (large!) main function</font></b>: all objects are local to that function,
but when the end of the function is also the end of the program. For instance,
all programs in <a href="eoLesson1.html">Lesson1</a>, <a href="eoLesson2.html">Lesson2</a>
and <a href="eoLesson3.html">Lesson3</a> of this tutorial are built that
way.
<p>It is however a big problem when you want to outsource some code in
other functions: indeed, the above sequence create objects that <b><font color="#FF6600">dissapear</font></b>
when exiting the function, and thus cannot be used outside their defining
function.
<p>The solution is of course to use <b><font color="#FF6600">pointers</font></b>,
which gives something like
<p><b><tt><font color="#993300">eoTournamentSelection&lt;EOT>&nbsp; *ptSelect
= new eoTournamentSelection&lt;EOT>(tSize);</font></tt></b>
<br><b><tt><font color="#993300">eoBreeder&lt;EOT> *ptBreed = new eoBreeder&lt;EOT>(select);</font></tt></b>
<br><b><tt><font color="#993300">eoEasyAlgo&lt;EOT> *ptAlgo = new eoEasyAlgo&lt;EOT>(
..., breed, ...);</font></tt></b>
<p>and you can then use the dynamically allocated objects anywhere. But
the trouble with such a construct is that after exiting the function where
such objects are defined, <b><font color="#FF6600">you will never be able
to free</font></b> this allocated memory, should you not need the objects
any nore. Whereas this is not in general a big problem (except of being
a very bad practice that will make you a very naughty programmer :-), it
will prevent any re-entrance of the resulting code, and for instance you
will not be able to use an evolutionary algorithm within another loop of
some outside code.
<p>The solution in EO us to use an <b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_functor_store.html">eoFunctorStore</a></font></font></tt></b>
object to store such nowhere-belonging pointers: whenever you allocate
such a thing, store it into an eoState : deleting that state will delete
all the stored pointers - one eoState is thus the only object you have
to care of.
<p>The above pointera llocation sequence thus become
<p><b><tt><font color="#993300">eoTournamentSelection&lt;EOT>&nbsp; *ptSelect
= new eoTournamentSelection&lt;EOT>(tSize);</font></tt></b>
<br><b><tt><font color="#993300">state.storeFunctor(ptSelect);</font></tt></b>
<br><b><tt><font color="#993300">eoBreeder&lt;EOT> *ptBreed = new eoBreeder&lt;EOT>(select);</font></tt></b>
<br><b><tt><font color="#993300">state.storeFunctor(ptBreed);</font></tt></b>
<br><b><tt><font color="#993300">eoEasyAlgo&lt;EOT> *ptAlgo = new eoEasyAlgo&lt;EOT>(
..., breed, ...);</font></tt></b>
<br><b><tt><font color="#993300">state.storeFunctor(ptAlgo);</font></tt></b>
<p>or, even more quickly (though less readably)
<p><b><tt><font color="#993300">eoTournamentSelection&lt;EOT>&nbsp; *ptSelect
=</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
state.storeFunctor(new eoTournamentSelection&lt;EOT>(tSize));</font></tt></b>
<br><b><tt><font color="#993300">eoBreeder&lt;EOT> *ptBreed =</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
state.storeFunctor(new eoBreeder&lt;EOT>(select));</font></tt></b>
<br><b><tt><font color="#993300">eoEasyAlgo&lt;EOT> *ptAlgo =</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
state.storeFunctor(new eoEasyAlgo&lt;EOT>( ..., breed, ...));</font></tt></b>
<p>In both the above code, state is an <b><tt><font color="#993300"><font size=+1>eoFunctorStore</font></font></tt></b>
that is of course <b><font color="#FF6600">passed from outside the function</font></b>
- and it's called state because in most cases it will actually be an eoState.
As its name says, an <b><tt><font color="#993300"><font size=+1>eoFunctorStore</font></font></tt></b>
can store any object that is an (derives from) <b><tt><font size=+1><a href="../../doc/html/classeo_functor_base.html">eoFunctorBase</a></font></tt></b>
- hence all objects in EO that are used as functors should derive from
either <a href="#functors">eoF, eoUF or eBF</a>.
<p>Examples of such constructs are shown in the make_xxx files described
in <a href="eoLesson4.html">Lesson4</a>.
<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">Random
numbers</a> - <a href="#notations">EO programming style</a>
numbers</a> - <a href="#notations">EO programming style</a>&nbsp; - <a href="#memory">Memory
management</a>
<br>
<hr WIDTH="100%">
<br><b><font color="#CC0000">General: </font></b><a href="eoTutorial.html">Tutorial
main 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">EO
main 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">EO
documentation</a></font>
<br>
<hr>

View file

@ -2,7 +2,7 @@
<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-21mdk i686) [Netscape]">
<meta name="GENERATOR" content="Mozilla/4.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]">
<title>Tutorial EO</title>
</head>
<body text="#000000" link="#0000EF" vlink="#51188E" alink="#FF0000" background="beige009.jpg">
@ -18,14 +18,12 @@ and to</font></b></center>
<font color="#FF0000">EO Tutorial</font></h1></center>
<center><font color="#FF0000">Version 0.96 - Nov. 12 2001</font>
<br><b><font color="#FF6600">Nothing really new</font></b> in this
version of the tutorial since
<a href="eoLesson4.html">Lesson4</a>, that includes a user guide of
fully operational program for bitstrings and real-valued with
full support of ES self-adaptive mutation strategies. But EO
itself keeps advancing: for instance, this snapshot now
<b><font color="#FF0000">compiles in MSVC++ v. 6.0</font></b></center>
<br><b><font color="#FF6600">Nothing really new</font></b> in this version
of the tutorial since <a href="eoLesson4.html">Lesson4</a>, that includes
a user guide of fully operational program for bitstrings and real-valued
with full support of ES self-adaptive mutation strategies. But EO itself
keeps advancing: for instance, this snapshot now <b><font color="#FF0000">compiles
in MSVC++ v. 6.0</font></b></center>
<p>Welcome to EO tutorial/on-line documentation.
<p>Please note that <b><font color="#FF6600">this tutorial is not supposed
@ -195,7 +193,7 @@ case you make rapid progress ... This menu bar should be on all pages of
this tutorial, allowing you to navigate easily.
<p>Last, but not least: EO is improving only&nbsp; from the good will of
contributors. This is also true for this tutorial: If you find anything
that you think could be improved, you are welcome to <a href="mailto:Marc.Schoenauer@polytechnique.fr">e-mail
that you think could be improved, you are welcome to <a href="mailto:Marc.Schoenauer@inria.fr">e-mail
me</a>.
<center>
<p><font color="#000099"><font size=+2>Enjoy!