paradiseo/eo/tutorial/html/SecondBitEA.html

610 lines
39 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-21mdk i686) [Netscape]">
<title>SecondBitEA.cpp</title>
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
</head>
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
<a href="eoLesson3.html">Back to Lesson 3</a> - <a href="eoTutorial.html">Tutorial
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
page</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%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
<center>
<h1>
<font color="#FF0000">SecondBitEA.cpp</font></h1></center>
Click on the figure to see the corresponding code.
<br>In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a>
<br>The actual code is in boldface and the comment in normal face.
<p>For this particular program, as all new lines are concerned with program
parameter input and information output, the <font color="#FF6600">font
color</font> for program-parameter-related sections will <font color="#FF6600">refer
to the section where the parameters are used</font> whereas the background
color will remain blue.
<p><img SRC="EA_tutorial.jpg" USEMAP="#Map" ><map NAME="Map"><!-- Init --><area SHAPE="rect" HREF="#init" COORDS="14,31,135,70"><area SHAPE="rect" HREF="#eval" COORDS="14,110,135,150"><!-- main loop --><area SHAPE="rect" HREF="#representation" COORDS="170,110,295,150"><area SHAPE="rect" HREF="#output" COORDS="280,45,480,70"><area SHAPE="rect" HREF="#stop" COORDS="348,110,430,150"><area SHAPE="rect" HREF="#select" COORDS="495,110,615,150"><area SHAPE="rect" HREF="#representation" COORDS="495,190,615,230"><area SHAPE="rect" HREF="#crossover" COORDS="495,265,625,287"><area SHAPE="rect" HREF="#mutation" COORDS="495,287,625,305"><area SHAPE="rect" HREF="#representation" COORDS="240,270,465,310"><area SHAPE="rect" HREF="#eval" COORDS="170,270,295,310"><area SHAPE="rect" HREF="#replace" COORDS="170,190,295,230"><!-- Center of loop --><area SHAPE="rect" HREF="#generation" COORDS="310,160,485,260"><!-- 4 bottom lines --><area SHAPE="rect" HREF="#operators" COORDS="15,350,260,370"><area SHAPE="rect" HREF="#representation" COORDS="270,350,460,370"><area SHAPE="rect" HREF="#engine" COORDS="15,377,400,397"><area SHAPE="rect" HREF="#eval" COORDS="15,403,230,423"><area SHAPE="rect" HREF="#checkpoint" COORDS="15,430,221,450"><area SHAPE="rect" HREF="#stop" COORDS="221,430,345,450"><area SHAPE="rect" HREF="#stat" COORDS="375,430,445,450"><area SHAPE="rect" HREF="#parametres" COORDS="0,358,278,378"></map>
<br><a NAME="start"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr NOSAVE>
<td NOSAVE><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
<br><tt><font color="#993300">// SecondGA.cpp</font></tt>
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
<br><tt><font color="#993300">//*</font></tt>
<br><tt><font color="#993300">// Same code than FirstBitEA as far as Evolutionary
Computation is concerned</font></tt>
<br><tt><font color="#993300">// but now you learn to enter the parameters
in a more flexible way</font></tt>
<br><tt><font color="#993300">// and to twidle the output to your preferences!</font></tt>
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
<br><tt><font color="#993300">// standard includes</font></tt>
<br><tt><font color="#993300"><b>#include &lt;stdexcept>&nbsp; </b>// runtime_error&nbsp;</font></tt>
<br><tt><font color="#993300"><b>#include &lt;iostream>&nbsp;&nbsp; </b>//
cout</font></tt>
<br><tt><font color="#993300"><b>#include &lt;strstream>&nbsp; </b>// ostrstream,
istrstream</font></tt>
<br><b><tt><font color="#993300">#include &lt;fstream></font></tt></b>
<br><tt><font color="#993300">// the general include for eo</font></tt>
<br><b><tt><font color="#993300">#include &lt;eo></font></tt></b>
</tr>
</table>
<a NAME="evalfunc"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
<tr>
<td><tt><font color="#CC0000">// a simple fitness function that computes the number of ones of a bitstring</font></tt><br>
<b><tt><font color="#CC0000">#include "binary_value.h"</font></tt></b></td>
</tr>
</table>
<a NAME="representation"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
<tr>
<td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
<br><tt><font color="#999900">// define your genotype and fitness types</font></tt>
<br><b><tt><font color="#999900">typedef eoBin&lt;double> Indi;</font></tt></b></td>
</tr>
</table>
<a NAME="parametres"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr>
<td><tt><font color="#3366FF">//-----------------------------------------------------------------------------</font></tt>
<br><tt><font color="#3366FF">// instead of having all values of useful
parameters as constants, read them:</font></tt>
<br><tt><font color="#3366FF">// either on the command line (--option=value
or -o=value)</font></tt>
<br><tt><font color="#3366FF">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
or in a parameter file (same syntax, order independent,&nbsp;</font></tt>
<br><tt><font color="#3366FF">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# = usual comment character&nbsp;</font></tt>
<br><tt><font color="#3366FF">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
or in the environment (TODO)</font></tt>
<br><tt><font color="#3366FF">// note that the parameters are passed by
reference so they can be updated</font></tt>
<br><a NAME="seed_passing"></a><b><tt><font color="#3366FF">void read_param(eoParser & _parser,&nbsp;</font></tt></b>
<br><b><tt><font color="#660000">uint32 &amp;
_seed</font><font color="#3366FF">,</font></tt></b>
<br><b><tt><font color="#999900">unsigned int &amp; _vecSize</font><font color="#3366FF">,</font></tt></b>
<br><b><tt><font color="#009900">unsigned int &amp; _popSize,</font></tt></b>
<br><b><tt><font color="#009900">unsigned int &amp; _tSize</font><font color="#3366FF">,</font></tt></b>
<br><b><tt><font color="#CC33CC">double &amp; _pCross,</font></tt></b>
<br><b><tt><font color="#CC33CC">double &amp; _pMut</font><font color="#3366FF">,</font></tt></b>
<br><b><tt><font color="#3366FF">string &amp; _load_name,</font></tt></b>
<br><b><tt><font color="#3366FF">unsigned int &amp; _maxGen,</font></tt></b>
<br><b><tt><font color="#3366FF">unsigned int &amp; _minGen,</font></tt></b>
<br><b><tt><font color="#3366FF">unsigned int &amp; _steadyGen,</font></tt></b>
<br><b><tt><font color="#CC33CC">double &amp; _onePointRate,&nbsp;</font></tt></b>
<br><b><tt><font color="#CC33CC">double &amp; _twoPointsRate,&nbsp;</font></tt></b>
<br><b><tt><font color="#CC33CC">double &amp; _uRate,&nbsp;</font></tt></b>
<br><b><tt><font color="#CC33CC">double &amp; _pMutPerBit,&nbsp;</font></tt></b>
<br><b><tt><font color="#CC33CC">double &amp; _bitFlipRate,&nbsp;</font></tt></b>
<br><b><tt><font color="#CC33CC">double &amp; _oneBitRate</font></tt></b>
<br><b><tt><font color="#3366FF">)</font></tt></b>
<br><b><tt><font color="#3366FF">{&nbsp;</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// For each
parameter, define Parameters directly in the parser,&nbsp;</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// and assign
the value to the variable</font></tt>
<br><a NAME="random"></a><a NAME="_seed_declare"></a><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;
</font><font color="#660000">eoValueParam&lt;uint32>&amp; seedParam = _parser.createParam&lt;uint32>(time(0),
"seed", "Random number seed", 'S');</font></tt></b>
<br><a NAME="seed_assign"></a><b><tt><font color="#660000">&nbsp;&nbsp;&nbsp;&nbsp;
_seed = seedParam.value();</font></tt></b>
<p><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#999900">eoValueParam&lt;unsigned
int>&amp; vecSizeParam = _parser.createParam&lt;unsigned int>(8, "vecSize",
"Genotype size",'V', "Representation");</font></tt></b>
<br><b><tt><font color="#999900">&nbsp;&nbsp;&nbsp;&nbsp; _vecSize = vecSizeParam.value();</font></tt></b>
<p><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#009900">eoValueParam&lt;unsigned
int>&amp; popSizeParam = _parser.createParam&lt;unsigned int>(10, "popSize",
"Population size",'P', "Evolution");</font></tt></b>
<br><b><tt><font color="#009900">&nbsp;&nbsp;&nbsp;&nbsp; _popSize = popSizeParam.value();</font></tt></b>
<br><b><tt><font color="#009900">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;unsigned
int>&amp; tSizeParam = _parser.createParam&lt;unsigned int>(10, "tSize",
"Tournament size",'T', "Evolution");</font></tt></b>
<br><b><tt><font color="#009900">&nbsp;&nbsp;&nbsp;&nbsp; _tSize = tSizeParam.value();</font></tt></b>
<br><a NAME="_load_name"></a>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp; eoValueParam&lt;string>&amp;
load_nameParam = _parser.createParam&lt;string>("", "Load","A save file
to restart from",'L', "Persistence");</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; _load_name =
load_nameParam.value();</font></tt></b>
<p><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;unsigned
int>&amp; maxGenParam = _parser.createParam&lt;unsigned int>(100, "maxGen",
"Maximum number of generations",'G', "Stopping criterion");</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; _maxGen = maxGenParam.value();</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;unsigned
int>&amp; minGenParam = _parser.createParam&lt;unsigned int>(100, "minGen",
"Minimum number of generations",'g', "Stopping criterion");</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; _minGen = minGenParam.value();</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;unsigned
int>&amp; steadyGenParam = _parser.createParam&lt;unsigned int>(100, "steadyGen",
"Number of generations with no improvement",'s', "Stopping criterion");</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; _steadyGen =
steadyGenParam.value();</font></tt></b>
<p><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;double>&amp;
pCrossParam = _parser.createParam&lt;double>(0.6, "pCross", "Probability
of Crossover", 'C', "Genetic Operators");&nbsp;</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; _pCross = pCrossParam.value();</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;double>&amp;
pMutParam = _parser.createParam&lt;double>(0.1, "pMut", "Probability of
Mutation", 'M', "Genetic Operators");</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; _pMut = pMutParam.value();</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;double>&amp;
onePointRateParam = _parser.createParam&lt;double>(1, "onePointRate", "Relative
rate for one point crossover", '1', "Genetic Operators");</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; _onePointRate
= onePointRateParam.value();</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;double>&amp;
twoPointsRateParam = _parser.createParam&lt;double>(1, "twoPointRate", "Relative
rate for two point crossover", '2', "Genetic Operators");</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; _twoPointsRate
= twoPointsRateParam.value();</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;double>&amp;
uRateParam = _parser.createParam&lt;double>(2, "uRate", "Relative rate for
uniform crossover", 'U', "Genetic Operators");</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; _uRate =&nbsp;
uRateParam.value();</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;double>&amp;
pMutPerBitParam = _parser.createParam&lt;double>(0.01, "pMutPerBit", "Probability
of flipping 1 bit in bit-flip mutation", 'b', "Genetic Operators");</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; _pMutPerBit =
pMutPerBitParam.value();</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;double>&amp;
bitFlipRateParam = _parser.createParam&lt;double>(0.01, "bitFlipRate", "Relative
rate for bit-flip mutation", 'B', "Genetic Operators");</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; _bitFlipRate
=&nbsp; bitFlipRateParam.value();</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;double>&amp;
oneBitRateParam = _parser.createParam&lt;double>(0.01, "oneBitRate", "Relative
rate for deterministic bit-flip mutation", 'D', "Genetic Operators");</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
_oneBitRate = oneBitRateParam.value();</font></tt></b>
<p><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// the name
of the "status" file where all actual parameter values will be saved</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; string str_status
= _parser.ProgramName() + ".status";</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;string>&amp;
status_nameParam = _parser.createParam&lt;string>(str_status.c_str(), "status","Status
file",'S', "Persistence");</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp; </b>// do the following AFTER
ALL PARAMETERS HAVE BEEN PROCESSED</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp; </b>// i.e. in case you need
parameters somewhere else, postpone these</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; if (_parser.userNeedsHelp())</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
_parser.printHelp(cout);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
exit(1);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; if (status_nameParam.value()
!= "")</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{</font></tt></b>
<br><b><tt><font color="#3366FF">ofstream os(status_nameParam.value().c_str());</font></tt></b>
<br><tt><font color="#3366FF"><b>os &lt;&lt; _parser; </b>// and you can
use that file as parameter file</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}</font></tt></b>
<br><b><tt><font color="#3366FF">}</font></tt></b></td>
</tr>
</table>
<a NAME="general"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr>
<td><tt><font color="#993300">// now the main_function: nothing changed,
except input/output</font></tt>
<br><b><tt><font color="#993300">void main_function(int argc, char **argv)</font></tt></b>
<br><b><tt><font color="#993300">{</font></tt></b></td>
</tr>
</table>
<a NAME="parametres"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr>
<td><a NAME="seed_declare"></a><b><tt><font color="#660000">&nbsp;&nbsp;
uint32 seed;</font></tt></b>
<br><tt><font color="#999900"><b>&nbsp;&nbsp; </b>// decription of genotype</font></tt>
<br><b><tt><font color="#999900">&nbsp;&nbsp; unsigned int vecSize;</font></tt></b>
<br><tt><font color="#33CC00"><b>&nbsp;&nbsp; </b>// parameters for evolution
engine</font></tt>
<br><b><tt><font color="#33CC00">&nbsp;&nbsp; unsigned int popSize;</font></tt></b>
<br><b><tt><font color="#33CC00">&nbsp;&nbsp; unsigned int tSize;</font></tt></b>
<br><tt><font color="#CC33CC"><b>&nbsp;&nbsp; </b>// operators probabilities
at the algorithm level</font></tt>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp; double pCross;</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp; double pMut;</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp; </b>// init and stop</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp; string load_name;</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp; unsigned int maxGen;</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp; unsigned int minGen;</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp; unsigned int steadyGen;</font></tt></b>
<br><tt><font color="#CC33CC"><b>&nbsp;&nbsp; </b>// rates for crossovers</font></tt>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp; double onePointRate;</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp; double twoPointsRate;</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp; double URate;</font></tt></b>
<br><tt><font color="#CC33CC"><b>&nbsp;&nbsp; </b>// rates and private
parameters for mutations;</font></tt>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp; double pMutPerBit;</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp; double bitFlipRate;</font></tt></b>
<br><b><tt><font color="#CC33CC">&nbsp;&nbsp; double oneBitRate;</font></tt></b>
<br><a NAME="parser_declare"></a><tt><font color="#3366FF"><b>&nbsp;&nbsp; </b>// define a
parser from the command-line arguments</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; eoParser parser(argc,
argv);</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp; </b>// Now read the parameters
of the program</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; read_param(argc,
argv, seed, vecSize, popSize, tSize,</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
pCross, pMut, load_name, maxGen, minGen, steadyGen,</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
onePointRate, twoPointsRate, URate,&nbsp;</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
pMutPerBit, bitFlipRate, oneBitRate );</font></tt></b></td>
</tr>
</table>
<a NAME="eval"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
<tr>
<td><tt><font color="#CC0000"><b>&nbsp;</b>/////////////////////////////</font></tt>
<br><tt><font color="#CC0000"><b>&nbsp;</b>// Fitness function</font></tt>
<br><tt><font color="#CC0000"><b>&nbsp;</b>////////////////////////////</font></tt>
<br><tt><font color="#CC0000"><b>&nbsp;</b>// Evaluation: from a plain
C++ fn to an EvalFunc Object ...</font></tt>
<br><b><tt><font color="#CC0000">&nbsp;eoEvalFuncPtr&lt;Indi, double, const
vector&lt;bool>&amp; > plainEval( binary_value );</font></tt></b>
<br><a NAME="evalcounter"></a><tt><font color="#CC0000">// ... to an object
that counts the nb of actual evaluations</font></tt>
<br><b><tt><font color="#CC0000">&nbsp;eoEvalFuncCounter&lt;Indi> eval(plainEval);</font></tt></b></td>
</tr>
</table>
<a NAME="init"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
<tr>
<td><tt><font color="#993399"><b>&nbsp;</b>////////////////////////////////</font></tt>
<br><tt><font color="#993399"><b>&nbsp;</b>// Initilisation of population</font></tt>
<br><tt><font color="#993399"><b>&nbsp;</b>////////////////////////////////</font></tt>
<br><tt><font color="#993399"><b>&nbsp;</b>// Either load or initialize</font></tt>
<br><tt><font color="#993399"><b>&nbsp;</b>// create an empty pop</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoPop&lt;Indi> pop;</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;</b>// create a state for reading</font></tt>
<br><tt><font color="#993399"><b>&nbsp;eoState inState; </b>// a state
for loading - WITHOUT the parser</font></tt>
<br><a NAME="register"></a><tt><font color="#993399">// register the rng
and the pop in the state, so they can be loaded,</font></tt>
<br><tt><font color="#993399"><b>&nbsp;</b>// and the present run will
be the exact conitnuation of the saved run</font></tt>
<br><tt><font color="#993399"><b>&nbsp;</b>// eventually with different
parameters</font></tt>
<br><b><tt><font color="#993399">&nbsp;inState.registerObject(rng);</font></tt></b>
<br><b><tt><font color="#993399">&nbsp;inState.registerObject(pop);</font></tt></b>
<p><a NAME="instate.load"></a><b><tt><font color="#993399">if (load_name
!= "")</font></tt></b>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b>
<br><a NAME="loadstate"></a><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
inState.load(load_name); </b>//&nbsp; load the pop and the rng</font></tt>
<br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// the fitness is read in the file:&nbsp;</font></tt>
<br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// do only evaluate the pop if the fitness has changed</font></tt>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b>
<br><b><tt><font color="#993399">&nbsp;else</font></tt></b>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
rng.reseed(seed);</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// a Indi random initializer</font></tt>
<br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// based on boolean_generator class (see utils/rnd_generator.h)</font></tt>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
eoInitFixedLength&lt;Indi, boolean_generator>&nbsp;</font></tt></b>
<br><b><tt><font color="#993399">random(vecSize, boolean_generator());</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// Init pop from the randomizer: need to use the append function</font></tt>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
pop.append(popSize, random);&nbsp;</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// and evaluate pop (STL syntax)&nbsp;</font></tt>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
apply&lt;Indi>(eval, pop);</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp; } </b>// end
of initializatio of the population</font></tt></td>
</tr>
</table>
<a NAME="output"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr>
<td><tt><font color="#3366FF"><b>&nbsp;</b>// sort pop for pretty printout</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;pop.sort();</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;</b>// Print (sorted) intial population
(raw printout)</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;cout &lt;&lt; "Initial Population"
&lt;&lt; endl &lt;&lt; pop &lt;&lt; endl;</font></tt></b></td>
</tr>
</table>
<a NAME="engine"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
<tr>
<td><tt><font color="#009900"><b>&nbsp;</b>/////////////////////////////////////</font></tt>
<br><tt><font color="#009900"><b>&nbsp;</b>// selection and replacement</font></tt>
<br><tt><font color="#009900"><b>&nbsp;</b>////////////////////////////////////</font></tt></td>
</tr>
</table>
<a NAME="select"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
<tr>
<td><tt><font color="#009900"><b>&nbsp;</b>// The robust tournament selection</font></tt>
<br><tt><font color="#009900"><b>&nbsp;eoDetTournament&lt;Indi> selectOne(tSize);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// tSize in [2,POPSIZE]</font></tt>
<br><tt><font color="#009900"><b>&nbsp;</b>// is now encapsulated in a
eoSelectPerc (entage)</font></tt>
<br><tt><font color="#009900"><b>&nbsp;eoSelectPerc&lt;Indi> select(selectOne);</b>//
by default rate==1</font></tt></td>
</tr>
</table>
<a NAME="replace"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
<tr>
<td><tt><font color="#009900"><b>&nbsp;</b>// And we now have the full
slection/replacement - though with&nbsp;</font></tt>
<br><tt><font color="#009900"><b>&nbsp;</b>// no replacement (== generational
replacement) at the moment :-)</font></tt>
<br><b><tt><font color="#009900">&nbsp;eoNoReplacement&lt;Indi> replace;&nbsp;</font></tt></b></td>
</tr>
</table>
<a NAME="operators"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
<tr>
<td><tt><font color="#993399"><b>&nbsp;</b>//////////////////////////////////////</font></tt>
<br><tt><font color="#993399"><b>&nbsp;</b>// The variation operators</font></tt>
<br><tt><font color="#993399"><b>&nbsp;</b>//////////////////////////////////////</font></tt></td>
</tr>
</table>
<a NAME="crossover"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
<tr>
<td><tt><font color="#993399"><b>&nbsp;</b>// 1-point crossover for bitstring</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoBinCrossover&lt;Indi> xover1;</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;</b>// uniform crossover for bitstring</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoBinUxOver&lt;Indi> xoverU;</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;</b>// 2-pots xover</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoBinNxOver&lt;Indi> xover2(2);</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;</b>// Combine them with relative
rates</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoPropCombinedQuadOp&lt;Indi> xover(xover1,
onePointRate);</font></tt></b>
<br><b><tt><font color="#993399">&nbsp;xover.add(xoverU, URate);</font></tt></b>
<br><b><tt><font color="#993399">&nbsp;xover.add(xover2, twoPointsRate,
true);</font></tt></b></td>
</tr>
</table>
<a NAME="mutation"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
<tr>
<td><tt><font color="#993399"><b>&nbsp;</b>// standard bit-flip mutation
for bitstring</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoBinMutation&lt;Indi>&nbsp; mutationBitFlip(pMutPerBit);</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;</b>// mutate exactly 1 bit per
individual</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoDetBitFlip&lt;Indi> mutationOneBit;&nbsp;</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;</b>// Combine them with relative
rates</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoPropCombinedMonOp&lt;Indi> mutation(mutationBitFlip,
bitFlipRate);</font></tt></b>
<br><b><tt><font color="#993399">&nbsp;mutation.add(mutationOneBit, oneBitRate,
true);</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;</b>// The operators are&nbsp; encapsulated
into an eoTRansform object</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoSGATransform&lt;Indi> transform(xover,
pCross, mutation, pMut);</font></tt></b></td>
</tr>
</table>
<a NAME="stop"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr>
<td><tt><font color="#3366FF"><b>&nbsp;</b>//////////////////////////////////////</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;</b>// termination condition see
FirstBitEA.cpp</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;</b>/////////////////////////////////////</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;eoGenContinue&lt;Indi> genCont(maxGen);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;eoSteadyFitContinue&lt;Indi> steadyCont(minGen,
steadyGen);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;eoFitContinue&lt;Indi> fitCont(vecSize);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;eoCombinedContinue&lt;Indi> continuator(genCont);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;continuator.add(steadyCont);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;continuator.add(fitCont);</font></tt></b></td>
</tr>
</table>
<a NAME="checkpoint"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr>
<td><tt><font color="#3366FF"><b>&nbsp;</b>// but now you want to make
many different things every generation&nbsp;</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;</b>// (e.g. statistics, plots,
...).</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;</b>// the class eoCheckPoint is
dedicated to just that:</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;</b>// Declare a checkpoint (from
a continuator: an eoCheckPoint&nbsp;</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;</b>// IS AN eoContinue and will
be called in the loop of all algorithms)</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;eoCheckPoint&lt;Indi> checkpoint(continuator);</font></tt></b>
<p><a NAME="param_declare"></a><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;
</b>// Create a counter parameter</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; eoValueParam&lt;unsigned>
generationCounter(0, "Gen.");</font></tt></b>
<p><a NAME="param_pass"></a><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;
</b>// Create an incrementor (sub-class of eoUpdater). Note that the&nbsp;</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// parameter's
value is passed by reference,&nbsp;</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// so every
time the incrementer is updated (every generation),</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// the data
in generationCounter will change.</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; eoIncrementor&lt;unsigned>
increment(generationCounter.value());</font></tt></b>
<br><a NAME="updater_pass"></a><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;
</b>// Add it to the checkpoint,&nbsp;</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// so the
counter is updated (here, incremented) every generation</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; checkpoint.add(increment);</font></tt></b>
<br><a NAME="stat_declare"></a><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;
</b>// now some statistics on the population:</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// Best fitness
in population</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; eoBestFitnessStat&lt;Indi>
bestStat;</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// Second
moment stats: average and stdev</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; eoSecondMomentStats&lt;Indi>
SecondStat;</font></tt></b>
<br><a NAME="stat_pass"></a><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;
</b>// Add them to the checkpoint to get them called at the appropriate
time</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; checkpoint.add(bestStat);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; checkpoint.add(SecondStat);</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// The Stdout
monitor will print parameters to the screen ...</font></tt>
<br><a NAME="monitor_declare"></a><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;
eoStdoutMonitor monitor(false);</font></tt></b>
<p><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// when called
by the checkpoint (i.e. at every generation)</font></tt>
<br><a NAME="monitor_pass"></a><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;
checkpoint.add(monitor);</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// the monitor
will output a series of parameters: add them&nbsp;</font></tt>
<br><a NAME="monitor_add"></a><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;
monitor.add(generationCounter);</font></tt></b>
<a name="eval_monitor"></a>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; monitor.add(eval);
</b>//
because now eval is an eoEvalFuncCounter!</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; monitor.add(bestStat);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; monitor.add(SecondStat);</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// A file
monitor: will print parameters to ... a File, yes, you got it!</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; eoFileMonitor
fileMonitor("stats.xg", " ");</font></tt></b>
<p><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// the checkpoint
mechanism can handle multiple monitors</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; checkpoint.add(fileMonitor);</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// the fileMonitor
can monitor parameters, too, but you must tell it!</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; fileMonitor.add(generationCounter);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; fileMonitor.add(bestStat);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; fileMonitor.add(SecondStat);</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// Last type
of item the eoCheckpoint can handle: state savers:</font></tt>
<br><a NAME="outstate_declare"></a><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;
eoState outState;</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// Register
the algorithm into the state</font></tt>
<br><a NAME="outstate_register"></a><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; outState.registerObject(parser);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; outState.registerObject(pop);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; outState.registerObject(rng);</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// and feed
the state to state savers</font></tt>
<br><a NAME="statesaver_declare"></a><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;
</b>// save state every 100th&nbsp; generation</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; eoCountedStateSaver
stateSaver1(100, outState, "generation");&nbsp;</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// save state
every 1 seconds&nbsp;</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; eoTimedStateSaver&nbsp;&nbsp;&nbsp;
stateSaver2(1, outState, "time");&nbsp;</font></tt></b>
<br><a NAME="statesaver_pass"></a><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;
</b>// Don't forget to add the two savers to the checkpoint</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; checkpoint.add(stateSaver1);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; checkpoint.add(stateSaver2);</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp; </b>// and that's
it for the (control and) output</font></tt></td>
</tr>
</table>
<a NAME="generation"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr>
<td><tt><font color="#FF6666"><b>&nbsp;</b>/////////////////////////////////////////</font></tt>
<br><tt><font color="#FF6666"><b>&nbsp;</b>// the algorithm</font></tt>
<br><tt><font color="#FF6666"><b>&nbsp;</b>////////////////////////////////////////</font></tt>
<br><tt><font color="#FF6666"><b>&nbsp;</b>// Easy EA requires&nbsp;</font></tt>
<br><tt><font color="#FF6666"><b>&nbsp;</b>// selection, transformation,
eval, replacement, and stopping criterion</font></tt>
<br><b><tt><font color="#FF6666">&nbsp;eoEasyEA&lt;Indi> gga(checkpoint,
eval, select, transform, replace);</font></tt></b>
<br><tt><font color="#FF6666"><b>&nbsp;</b>// Apply algo to pop - that's
it!</font></tt>
<br><b><tt><font color="#FF6666">&nbsp;gga(pop);</font></tt></b></td>
</tr>
</table>
<a NAME="output"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr>
<td><tt><font color="#3366FF"><b>&nbsp;</b>// Print (sorted) final population</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;pop.sort();</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;cout &lt;&lt; "FINAL Population\n"
&lt;&lt; pop &lt;&lt; endl;</font></tt></b></td>
</tr>
</table>
<a NAME="general"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr>
<td><b><tt><font color="#993300">}</font></tt></b>
<br><tt><font color="#993300">// A main that catches the exceptions</font></tt>
<br><b><tt><font color="#993300">int main(int argc, char **argv)</font></tt></b>
<br><b><tt><font color="#993300">{</font></tt></b>
<br><b><tt><font color="#993300">#ifdef _MSC_VER</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag
|= _CRTDBG_LEAK_CHECK_DF;</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; _CrtSetDbgFlag(flag);</font></tt></b>
<br><tt><font color="#993300">//&nbsp;&nbsp;&nbsp; _CrtSetBreakAlloc(100);</font></tt>
<br><b><tt><font color="#993300">#endif</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; try</font></tt></b>
<br><b><tt><font color="#993300">&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;
main_function(argc, argv);</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; catch(exception&amp;
e)</font></tt></b>
<br><b><tt><font color="#993300">&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;
cout &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; '\n';</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b>
<br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; return 1;</font></tt></b>
<br><b><tt><font color="#993300">}</font></tt></b></td>
</tr>
</table>
<hr WIDTH="100%"><a href="eoLesson3.html">Back to Lesson 3</a> - <a href="eoTutorial.html">Tutorial
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
page</a> - <a href="eoProgramming.html">Programming hints</a> - <b><font face="Arial,Helvetica"><a href="doc/html/index.html">EO
documentation</a></font></b>
<hr>
<address>
<a href="mailto:marc.schoenauer@polytechnique.fr">Marc Schoenauer</a></address>
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Sun Nov
26 09:31:04 2000<!-- hhmts end -->
</body>
</html>