Following the change in includes (added ga.h and es.h everywhere pfuhh)

This commit is contained in:
evomarc 2001-01-27 08:20:39 +00:00
commit 9d9958d3bc
8 changed files with 761 additions and 850 deletions

View file

@ -2,9 +2,9 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="cpp2html Marc Schoenauer"> <meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
<title>FirstBitEA.cpp</title> <title>FirstBitEA.cpp</title>
<!-- Changed by: Marc Schoenauer, 28-Nov-2000 --> <!-- Changed by: Marc Schoenauer, 28-Nov-2000 -->
</head> </head>
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000"> <body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
<a href="eoLesson2.html">Back to Lesson 2</a> - <a href="eoTutorial.html">Tutorial <a href="eoLesson2.html">Back to Lesson 2</a> - <a href="eoTutorial.html">Tutorial
@ -16,344 +16,319 @@ documentation</a></font>
<center> <center>
<h1> <h1>
<font color="#FF0000">FirstBitEA.cpp</font></h1></center> <font color="#FF0000">FirstBitEA.cpp</font></h1></center>
Click on the figure to see the corresponding code.<br> Click on the figure to see the corresponding code.
In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a><br> <br>In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a>
The actual code is in boldface and the comment in normal face. <br>The actual code is in boldface and the comment in normal face.
<br><img SRC="EA_tutorial.jpg" USEMAP="#Map" > <br><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>
<map NAME="Map"> <br><a NAME="start"></a>
<!-- 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>&nbsp;
<A NAME="start"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE > <table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr NOSAVE> <tr NOSAVE>
<td NOSAVE><tt><font color="#993300"> <td NOSAVE><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
//-----------------------------------------------------------------------------<br> <br><tt><font color="#993300">// FirstBitEA.cpp</font></tt>
// FirstBitEA.cpp<br> <br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
//-----------------------------------------------------------------------------<br> <br><tt><font color="#993300">//*</font></tt>
//*<br> <br><tt><font color="#993300">// Still an instance of a VERY simple Bitstring
// Still an instance of a VERY simple Bitstring Genetic Algorithm <br> Genetic Algorithm&nbsp;</font></tt>
// (see FirstBitGA.cpp) but now with &nbsp;Breeder - and Combined Ops<br> <br><tt><font color="#993300">// (see FirstBitGA.cpp) but now with&nbsp;
//<br> Breeder - and Combined Ops</font></tt>
//-----------------------------------------------------------------------------<br> <br><tt><font color="#993300">//</font></tt>
// standard includes<br> <br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
<b>#include &lt;stdexcept> &nbsp;</b>// runtime_error <br> <br><tt><font color="#993300">// standard includes</font></tt>
<b>#include &lt;iostream> &nbsp; &nbsp;</b>// cout<br> <br><tt><font color="#993300"><b>#include &lt;stdexcept>&nbsp; </b>// runtime_error&nbsp;</font></tt>
<b>#include &lt;strstream> &nbsp;</b>// ostrstream, istrstream<br> <br><tt><font color="#993300"><b>#include &lt;iostream>&nbsp;&nbsp;&nbsp;
// the general include for eo<br> </b>// cout</font></tt>
<b>#include &lt;eo></b><br> <br><tt><font color="#993300"><b>#include &lt;strstream>&nbsp; </b>// ostrstream,
</font></tt> istrstream</font></tt>
</td> <br><tt><font color="#993300">// the general include for eo</font></tt>
<br><b><tt><font color="#993300">#include &lt;eo></font></tt></b></td>
</tr> </tr>
</table> </table>
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE > <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">// Include the corresponding file&nbsp;</font></tt>
<br><tt><font color="#999900"><b>#include &lt;ga.h></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// bitstring representation &amp; operators&nbsp;</font></tt>
<br><tt><font color="#999900">// define your individuals</font></tt>
<br><tt><font color="#999900"><b>typedef eoBin&lt;double> Indi; </b>//
A bitstring with fitness double</font></tt></td>
</tr>
</table>
<a NAME="evalfunc"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
<tr>
<td><tt><font color="#CC0000">//-----------------------------------------------------------------------------</font></tt>
<br><tt><font color="#CC0000">// a simple fitness function that computes
the number of ones of a bitstring</font></tt>
<br><tt><font color="#CC0000">// Now in a separate file, and declared as
binary_value(const vector&lt;bool> &amp;)</font></tt>
<br><b><tt><font color="#CC0000">#include "binary_value.h"</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">//-----------------------------------------------------------------------------</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><tt><font color="#3366FF"><b>&nbsp;const unsigned int SEED = 42; </b>//
seed for random number generator</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int T_SIZE = 3; </b>//
size for tournament selection</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int VEC_SIZE = 8;
</b>// Number of bits in genotypes</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int POP_SIZE = 20;
</b>// Size of population</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int MAX_GEN = 500;
</b>// Maximum number of generation before STOP</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const float CROSS_RATE = 0.8; </b>//
Crossover rate</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const double P_MUT_PER_BIT = 0.01;
</b>// probability of bit-flip mutation</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const float MUT_RATE = 1.0; </b>//
mutation rate</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;</b>// some parameters for chosing
among different operators</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const double onePointRate = 0.5;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// rate for 1-pt Xover</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const double twoPointsRate = 0.5;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// rate for 2-pt Xover</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const double URate = 0.5;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// rate for Uniform Xover</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const double bitFlipRate = 0.5;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// rate for bit-flip mutation</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const double oneBitRate = 0.5;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// rate for one-bit mutation</font></tt></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"><b>&nbsp;</b>//////////////////////////</font></tt>
<br><tt><font color="#993300"><b>&nbsp;</b>//&nbsp; Random seed</font></tt>
<br><tt><font color="#993300"><b>&nbsp;</b>//////////////////////////</font></tt>
<br><tt><font color="#993300"><b>&nbsp;</b>//reproducible random seed:
if you don't change SEED above,&nbsp;</font></tt>
<br><tt><font color="#993300"><b>&nbsp;</b>// you'll aways get the same
result, NOT a random run</font></tt>
<br><b><tt><font color="#993300">&nbsp;rng.reseed(SEED);</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><tt><font color="#CC0000"><b>&nbsp;</b>// you need to give the full
description of the function</font></tt>
<br><b><tt><font color="#CC0000">&nbsp;eoEvalFuncPtr&lt;Indi, double, const
vector&lt;bool>&amp; > eval(&nbsp; binary_value );</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>// based on boolean_generator
class (see utils/rnd_generator.h)</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoInitFixedLength&lt;Indi, boolean_generator>&nbsp;</font></tt></b>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp; random(VEC_SIZE,
boolean_generator());</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;</b>// Initialization of the population</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoPop&lt;Indi> pop(POP_SIZE, random);</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;</b>// and evaluate it in one line</font></tt>
<br><tt><font color="#993399"><b>&nbsp;apply&lt;Indi>(eval, pop); </b>//
STL syntax</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 before printing
it!</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;</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;cout &lt;&lt; pop;</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;eoDetTournamentSelect&lt;Indi> selectOne(T_SIZE);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// T_SIZE in [2,POP_SIZE]</font></tt>
<br><a NAME="select_encapsulate"></a><tt><font color="#009900"><b> </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> <tr>
<td> <td>
<tt><font color="#999900"> <br><tt><font color="#993399"><b>&nbsp;</b>// standard bit-flip mutation
//-----------------------------------------------------------------------------<br> for bitstring</font></tt>
// define your individuals<br> <br><b><tt><font color="#993399">&nbsp;eoBinMutation&lt;Indi>&nbsp; mutationBitFlip(P_MUT_PER_BIT);</font></tt></b>
<b>typedef eoBin&lt;double> Indi; </b>// A bitstring with fitness double<br> <br><tt><font color="#993399"><b>&nbsp;</b>// mutate exactly 1 bit per
</font></tt> individual</font></tt>
</td> <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>
<p><a NAME="transform"></a><tt><font color="#993399"><b> </b>// The operators
are&nbsp; encapsulated into an eoTRansform object</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoSGATransform&lt;Indi> transform(xover,
CROSS_RATE, mutation, MUT_RATE);</font></tt></b></td>
</tr> </tr>
</table> </table>
<a NAME="evalfunc"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE > <a NAME="stop"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr> <tr>
<td> <td></td>
<tt><font color="#CC0000">
//-----------------------------------------------------------------------------<br>
// a simple fitness function that computes the number of ones of a bitstring<br>
// Now in a separate file, and declared as binary_value(const vector&lt;bool> &)<br>
<b>#include "binary_value.h"</b><br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE > <a NAME="checkpoint"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#3366FF"><b>&nbsp;</b>//////////////////////////////////////</font></tt>
<tt><font color="#993300"> <br><tt><font color="#3366FF"><b>&nbsp;</b>// termination conditions: use
//-----------------------------------------------------------------------------<br> more than one</font></tt>
<b>void main_function(int argc, char **argv)</b><br> <br><tt><font color="#3366FF"><b>&nbsp;</b>/////////////////////////////////////</font></tt>
<b>{</b><br> <br><tt><font color="#3366FF"><b>&nbsp;</b>// stop after MAX_GEN generations</font></tt>
</font></tt> <br><b><tt><font color="#3366FF">&nbsp;eoGenContinue&lt;Indi> genCont(MAX_GEN);</font></tt></b>
</td> <br><tt><font color="#3366FF"><b>&nbsp;</b>// do MIN_GEN gen., then stop
after STEADY_GEN gen. without improvement</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;eoSteadyFitContinue&lt;Indi> steadyCont(MIN_GEN,
STEADY_GEN);</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;</b>// stop when fitness reaches
a target (here VEC_SIZE)</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;eoFitContinue&lt;Indi> fitCont(0);</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;</b>// do stop when one of the above
says so</font></tt>
<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> </tr>
</table> </table>
<a NAME="parametres"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE > <a NAME="generation"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#FF6666"><b>&nbsp;</b>/////////////////////////////////////////</font></tt>
<tt><font color="#3366FF"> <br><tt><font color="#FF6666"><b>&nbsp;</b>// the algorithm</font></tt>
<b> &nbsp;const unsigned int SEED = 42; </b>// seed for random number generator<br> <br><tt><font color="#FF6666"><b>&nbsp;</b>////////////////////////////////////////</font></tt>
<b> &nbsp;const unsigned int T_SIZE = 3; </b>// size for tournament selection<br> <br><tt><font color="#FF6666"><b>&nbsp;</b>// Easy EA requires&nbsp;</font></tt>
<b> &nbsp;const unsigned int VEC_SIZE = 8; </b>// Number of bits in genotypes<br> <br><tt><font color="#FF6666"><b>&nbsp;</b>// selection, transformation,
<b> &nbsp;const unsigned int POP_SIZE = 20; </b>// Size of population<br> eval, replacement, and stopping criterion</font></tt>
<b> &nbsp;const unsigned int MAX_GEN = 500; </b>// Maximum number of generation before STOP<br> <br><b><tt><font color="#FF6666">&nbsp;eoEasyEA&lt;Indi> gga(continuator,
<b> &nbsp;const float CROSS_RATE = 0.8; </b>// Crossover rate<br> eval, select, transform, replace);</font></tt></b>
<b> &nbsp;const double P_MUT_PER_BIT = 0.01; </b>// probability of bit-flip mutation<br> <br><tt><font color="#FF6666"><b>&nbsp;</b>// Apply algo to pop - that's
<b> &nbsp;const float MUT_RATE = 1.0; </b>// mutation rate<br> it!</font></tt>
<b> &nbsp;</b>// some parameters for chosing among different operators<br> <br><b><tt><font color="#FF6666">&nbsp;gga(pop);</font></tt></b>
<b> &nbsp;const double onePointRate = 0.5; &nbsp; &nbsp; &nbsp; &nbsp;</b>// rate for 1-pt Xover<br> <br>&nbsp;</td>
<b> &nbsp;const double twoPointsRate = 0.5; &nbsp; &nbsp; &nbsp; &nbsp;</b>// rate for 2-pt Xover<br>
<b> &nbsp;const double URate = 0.5; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// rate for Uniform Xover<br>
<b> &nbsp;const double bitFlipRate = 0.5; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// rate for bit-flip mutation<br>
<b> &nbsp;const double oneBitRate = 0.5; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// rate for one-bit mutation<br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE > <a NAME="output"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#3366FF"><b>&nbsp;</b>// Print (sorted) intial population</font></tt>
<tt><font color="#993300"> <br><b><tt><font color="#3366FF">&nbsp;pop.sort();</font></tt></b>
<b> &nbsp;</b>//////////////////////////<br> <br><b><tt><font color="#3366FF">&nbsp;cout &lt;&lt; "FINAL Population\n"
<b> &nbsp;</b>// &nbsp;Random seed<br> &lt;&lt; pop &lt;&lt; endl;</font></tt></b></td>
<b> &nbsp;</b>//////////////////////////<br>
<b> &nbsp;</b>//reproducible random seed: if you don't change SEED above, <br>
<b> &nbsp;</b>// you'll aways get the same result, NOT a random run<br>
<b> &nbsp;rng.reseed(SEED);</b><br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="eval"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE > <a NAME="general"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr> <tr>
<td> <td><b><tt><font color="#993300">}</font></tt></b>
<tt><font color="#CC0000"> <br><tt><font color="#993300">// A main that catches the exceptions</font></tt>
<b> &nbsp;</b>/////////////////////////////<br> <br><b><tt><font color="#993300">int main(int argc, char **argv)</font></tt></b>
<b> &nbsp;</b>// Fitness function<br> <br><b><tt><font color="#993300">{</font></tt></b>
<b> &nbsp;</b>////////////////////////////<br> <br><b><tt><font color="#993300">#ifdef _MSC_VER</font></tt></b>
<b> &nbsp;</b>// Evaluation: from a plain C++ fn to an EvalFunc Object<br> <br><tt><font color="#993300"><b>&nbsp;</b>//&nbsp; rng.reseed(42);</font></tt>
<b> &nbsp;</b>// you need to give the full description of the function<br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b>
<b> &nbsp;eoEvalFuncPtr&lt;Indi, double, const vector&lt;bool>& > eval( &nbsp;binary_value );</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag
</font></tt> |= _CRTDBG_LEAK_CHECK_DF;</font></tt></b>
</td> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; _CrtSetDbgFlag(flag);</font></tt></b>
</tr> <br><tt><font color="#993300">//&nbsp;&nbsp;&nbsp; _CrtSetBreakAlloc(100);</font></tt>
</table> <br><b><tt><font color="#993300">#endif</font></tt></b>
<a NAME="init"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE > <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; try</font></tt></b>
<tr> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b>
<td> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<tt><font color="#993399"> main_function(argc, argv);</font></tt></b>
<b> &nbsp;</b>////////////////////////////////<br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b>
<b> &nbsp;</b>// Initilisation of population<br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; catch(exception&amp;
<b> &nbsp;</b>////////////////////////////////<br> e)</font></tt></b>
<b> &nbsp;</b>// based on boolean_generator class (see utils/rnd_generator.h)<br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b>
<b> &nbsp;eoInitFixedLength&lt;Indi, boolean_generator> </b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b> &nbsp; &nbsp; &nbsp;random(VEC_SIZE, boolean_generator());</b><br> cout &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; '\n';</font></tt></b>
<b> &nbsp;</b>// Initialization of the population<br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b>
<b> &nbsp;eoPop&lt;Indi> pop(POP_SIZE, random);</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; return 1;</font></tt></b>
<b> &nbsp;</b>// and evaluate it in one line<br> <br><b><tt><font color="#993300">}</font></tt></b></td>
<b> &nbsp;apply&lt;Indi>(eval, pop); </b>// STL syntax<br>
</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 before printing it!<br>
<b> &nbsp;pop.sort();</b><br>
<b> &nbsp;</b>// Print (sorted) intial population (raw printout)<br>
<b> &nbsp;cout &lt;&lt; "Initial Population" &lt;&lt; endl;</b><br>
<b> &nbsp;cout &lt;&lt; pop;</b><br>
</font></tt>
</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>/////////////////////////////////////<br>
<b> &nbsp;</b>// selection and replacement<br>
<b> &nbsp;</b>////////////////////////////////////<br>
</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<br>
<b> &nbsp;eoDetTournamentSelect&lt;Indi> selectOne(T_SIZE); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// T_SIZE in [2,POP_SIZE]<br>
<a NAME="select_encapsulate"></a>
<b> &nbsp;</b>// is now encapsulated in a eoSelectPerc (entage)<br>
<b> &nbsp;eoSelectPerc&lt;Indi> select(selectOne);</b>// by default rate==1<br>
</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 <br>
<b> &nbsp;</b>// no replacement (== generational replacement) at the moment :-)<br>
<b> &nbsp;eoNoReplacement&lt;Indi> replace; </b><br>
</font></tt>
</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>//////////////////////////////////////<br>
<b> &nbsp;</b>// The variation operators<br>
<b> &nbsp;</b>//////////////////////////////////////<br>
</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<br>
<b> &nbsp;eoBinCrossover&lt;Indi> xover1;</b><br>
<b> &nbsp;</b>// uniform crossover for bitstring<br>
<b> &nbsp;eoBinUxOver&lt;Indi> xoverU;</b><br>
<b> &nbsp;</b>// 2-pots xover<br>
<b> &nbsp;eoBinNxOver&lt;Indi> xover2(2);</b><br>
<b> &nbsp;</b>// Combine them with relative rates<br>
<b> &nbsp;eoPropCombinedQuadOp&lt;Indi> xover(xover1, onePointRate);</b><br>
<b> &nbsp;xover.add(xoverU, URate);</b><br>
<b> &nbsp;xover.add(xover2, twoPointsRate, true);</b><br>
</font></tt>
</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><br>
<b> &nbsp;</b>// standard bit-flip mutation for bitstring<br>
<b> &nbsp;eoBinMutation&lt;Indi> &nbsp;mutationBitFlip(P_MUT_PER_BIT);</b><br>
<b> &nbsp;</b>// mutate exactly 1 bit per individual<br>
<b> &nbsp;eoDetBitFlip&lt;Indi> mutationOneBit; </b><br>
<b> &nbsp;</b>// Combine them with relative rates<br>
<b> &nbsp;eoPropCombinedMonOp&lt;Indi> mutation(mutationBitFlip, bitFlipRate);</b><br>
<b> &nbsp;mutation.add(mutationOneBit, oneBitRate, true);</b><br>
<b> &nbsp;</b><br>
<a NAME="transform"></a>
<b> &nbsp;</b>// The operators are &nbsp;encapsulated into an eoTRansform object<br>
<b> &nbsp;eoSGATransform&lt;Indi> transform(xover, CROSS_RATE, mutation, MUT_RATE);</b><br>
</font></tt>
</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">
</font></tt>
</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>//////////////////////////////////////<br>
<b> &nbsp;</b>// termination conditions: use more than one<br>
<b> &nbsp;</b>/////////////////////////////////////<br>
<b> &nbsp;</b>// stop after MAX_GEN generations<br>
<b> &nbsp;eoGenContinue&lt;Indi> genCont(MAX_GEN);</b><br>
<b> &nbsp;</b>// do MIN_GEN gen., then stop after STEADY_GEN gen. without improvement<br>
<b> &nbsp;eoSteadyFitContinue&lt;Indi> steadyCont(MIN_GEN, STEADY_GEN);</b><br>
<b> &nbsp;</b>// stop when fitness reaches a target (here VEC_SIZE)<br>
<b> &nbsp;eoFitContinue&lt;Indi> fitCont(0);</b><br>
<b> &nbsp;</b>// do stop when one of the above says so<br>
<b> &nbsp;eoCombinedContinue&lt;Indi> continuator(genCont);</b><br>
<b> &nbsp;continuator.add(steadyCont);</b><br>
<b> &nbsp;continuator.add(fitCont);</b><br>
</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>/////////////////////////////////////////<br>
<b> &nbsp;</b>// the algorithm<br>
<b> &nbsp;</b>////////////////////////////////////////<br>
<b> &nbsp;</b>// Easy EA requires <br>
<b> &nbsp;</b>// selection, transformation, eval, replacement, and stopping criterion<br>
<b> &nbsp;eoEasyEA&lt;Indi> gga(continuator, eval, select, transform, replace);</b><br>
<b> &nbsp;</b>// Apply algo to pop - that's it!<br>
<b> &nbsp;gga(pop);</b><br>
<b> &nbsp;</b><br>
</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>// Print (sorted) intial population<br>
<b> &nbsp;pop.sort();</b><br>
<b> &nbsp;cout &lt;&lt; "FINAL Population\n" &lt;&lt; pop &lt;&lt; endl;</b><br>
</font></tt>
</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">
<b>}</b><br>
// A main that catches the exceptions<br>
<b>int main(int argc, char **argv)</b><br>
<b>{</b><br>
<b>#ifdef _MSC_VER</b><br>
<b> &nbsp;</b>// &nbsp;rng.reseed(42);<br>
<b> &nbsp; &nbsp; &nbsp;int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</b><br>
<b> &nbsp; &nbsp; &nbsp; &nbsp;flag |= _CRTDBG_LEAK_CHECK_DF;</b><br>
<b> &nbsp; &nbsp; &nbsp;_CrtSetDbgFlag(flag);</b><br>
// &nbsp; &nbsp;_CrtSetBreakAlloc(100);<br>
<b>#endif</b><br>
<b> &nbsp; &nbsp; &nbsp;try</b><br>
<b> &nbsp; &nbsp; &nbsp;{</b><br>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;main_function(argc, argv);</b><br>
<b> &nbsp; &nbsp; &nbsp;}</b><br>
<b> &nbsp; &nbsp; &nbsp;catch(exception& e)</b><br>
<b> &nbsp; &nbsp; &nbsp;{</b><br>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cout &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; '\n';</b><br>
<b> &nbsp; &nbsp; &nbsp;}</b><br>
<b> &nbsp; &nbsp; &nbsp;return 1;</b><br>
<b>}</b><br>
</font></font></font></td>
</tr> </tr>
</table> </table>
<hr WIDTH="100%"><a href="eoLesson2.html">Back to Lesson 2</a> - <a href="eoTutorial.html">Tutorial <hr WIDTH="100%"><a href="eoLesson2.html">Back to Lesson 2</a> - <a href="eoTutorial.html">Tutorial
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
@ -361,8 +336,8 @@ documentation</a></font>
<hr> <hr>
<address> <address>
<a href="mailto:marc.schoenauer@polytechnique.fr">Marc Schoenauer</a></address> <a href="mailto:marc.schoenauer@polytechnique.fr">Marc Schoenauer</a></address>
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last
modified: Sun Nov 19 22:26:27 2000 <br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Sun Nov
<!-- hhmts end --> 19 22:26:27 2000<!-- hhmts end -->
</body> </body>
</html> </html>

View file

@ -2,9 +2,9 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="cpp2html Marc Schoenauer"> <meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
<title>FirstBitGA.html</title> <title>FirstBitGA.html</title>
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 --> <!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
</head> </head>
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000"> <body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
<a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial <a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial
@ -16,326 +16,290 @@ documentation</a></font>
<center> <center>
<h1> <h1>
<font color="#FF0000">FirstBitGA.html</font></h1></center> <font color="#FF0000">FirstBitGA.html</font></h1></center>
Click on the figure to see the corresponding code.<br> Click on the figure to see the corresponding code.
In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a><br> <br>In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a>
The actual code is in boldface and the comment in normal face. <br>The actual code is in boldface and the comment in normal face.
<br><img SRC="EA_tutorial.jpg" USEMAP="#Map" > <br><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>
<map NAME="Map"> <br><a NAME="start"></a>
<!-- 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>&nbsp;
<A NAME="start"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE > <table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr NOSAVE> <tr NOSAVE>
<td NOSAVE><tt><font color="#993300"> <td NOSAVE><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
//-----------------------------------------------------------------------------<br> <br><tt><font color="#993300">// FirstBitGA.cpp</font></tt>
// FirstBitGA.cpp<br> <br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
//-----------------------------------------------------------------------------<br> <br><tt><font color="#993300">//*</font></tt>
//*<br> <br><tt><font color="#993300">// An instance of a VERY simple Bitstring
// An instance of a VERY simple Bitstring Genetic Algorithm<br> Genetic Algorithm</font></tt>
//<br> <br><tt><font color="#993300">//</font></tt>
//-----------------------------------------------------------------------------<br> <br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
// standard includes<br> <br><tt><font color="#993300">// standard includes</font></tt>
<b>#include &lt;stdexcept> &nbsp;</b>// runtime_error <br> <br><tt><font color="#993300"><b>#include &lt;stdexcept>&nbsp; </b>// runtime_error&nbsp;</font></tt>
<b>#include &lt;iostream> &nbsp; &nbsp;</b>// cout<br> <br><tt><font color="#993300"><b>#include &lt;iostream>&nbsp;&nbsp;&nbsp;
<b>#include &lt;strstream> &nbsp;</b>// ostrstream, istrstream<br> </b>// cout</font></tt>
// the general include for eo<br> <br><tt><font color="#993300"><b>#include &lt;strstream>&nbsp; </b>// ostrstream,
<b>#include &lt;eo></b><br> istrstream</font></tt>
</font></tt> <br><tt><font color="#993300">// the general include for eo</font></tt>
</td> <br><b><tt><font color="#993300">#include &lt;eo></font></tt></b></td>
</tr> </tr>
</table> </table>
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE > <a NAME="representation"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
<tt><font color="#999900"> <br><tt><font color="#999900">// Include the corresponding file</font></tt>
//-----------------------------------------------------------------------------<br> <br><tt><font color="#999900"><b>#include &lt;ga.h></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// define your individuals<br> // bitstring representation &amp; operators</font></tt>
<b>typedef eoBin&lt;double> Indi; &nbsp; &nbsp; &nbsp; &nbsp;</b>// A bitstring with fitness double<br> <br><tt><font color="#999900">// define your individuals</font></tt>
</font></tt> <br><tt><font color="#999900"><b>typedef eoBin&lt;double> Indi;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</td> </b>// A bitstring with fitness double</font></tt></td>
</tr> </tr>
</table> </table>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE > <table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#CC0000">//-----------------------------------------------------------------------------</font></tt>
<tt><font color="#CC0000"> <br><tt><font color="#CC0000">// a simple fitness function that computes
//-----------------------------------------------------------------------------<br> the number of ones of a bitstring</font></tt>
// a simple fitness function that computes the number of ones of a bitstring<br> <br><tt><font color="#CC0000">//&nbsp; @param _indi A biststring individual</font></tt>
// &nbsp;@param _indi A biststring individual<br> <br><a NAME="evalfunc"></a><b><tt><font color="#CC0000">double binary_value(const
<a name="evalfunc"></a> Indi &amp; _indi)</font></tt></b>
<b>double binary_value(const Indi & _indi)</b><br> <br><b><tt><font color="#CC0000">{</font></tt></b>
<b>{</b><br> <br><b><tt><font color="#CC0000">&nbsp;double sum = 0;</font></tt></b>
<b> &nbsp;double sum = 0;</b><br> <br><b><tt><font color="#CC0000">&nbsp;for (unsigned i = 0; i &lt; _indi.size();
<b> &nbsp;for (unsigned i = 0; i &lt; _indi.size(); i++)</b><br> i++)</font></tt></b>
<b> &nbsp; &nbsp; &nbsp;sum += _indi[i];</b><br> <br><b><tt><font color="#CC0000">&nbsp;&nbsp;&nbsp;&nbsp; sum += _indi[i];</font></tt></b>
<b> &nbsp;return sum;</b><br> <br><b><tt><font color="#CC0000">&nbsp;return sum;</font></tt></b>
<b>}</b><br> <br><b><tt><font color="#CC0000">}</font></tt></b></td>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE > <a NAME="general"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr>
<td><tt><font color="#993300">//-----------------------------------------------------------------------------</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><tt><font color="#3366FF"><b>&nbsp;</b>// all parameters are hard-coded!</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int SEED = 42;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// seed for random number generator</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int T_SIZE = 3;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// size for tournament selection</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int VEC_SIZE = 8;&nbsp;&nbsp;&nbsp;
</b>// Number of bits in genotypes</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int POP_SIZE = 20;&nbsp;
</b>// Size of population</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int MAX_GEN = 100;&nbsp;
</b>// Maximum number of generation before STOP</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const float CROSS_RATE = 0.8;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// Crossover rate</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const double P_MUT_PER_BIT = 0.01;
</b>// probability of bit-flip mutation</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const float MUT_RATE = 1.0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// mutation rate</font></tt></td>
</tr>
</table>
<a NAME="general"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr>
<td><a NAME="random"></a><tt><font color="#993300"><b> </b>//////////////////////////</font></tt>
<br><tt><font color="#993300"><b>&nbsp;</b>//&nbsp; Random seed</font></tt>
<br><tt><font color="#993300"><b>&nbsp;</b>//////////////////////////</font></tt>
<br><tt><font color="#993300"><b>&nbsp;</b>//reproducible random seed:
if you don't change SEED above,&nbsp;</font></tt>
<br><tt><font color="#993300"><b>&nbsp;</b>// you'll aways get the same
result, NOT a random run</font></tt>
<br><b><tt><font color="#993300">&nbsp;rng.reseed(SEED);</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> eval(&nbsp;
binary_value );</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>// declare the population</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoPop&lt;Indi> pop;</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;</b>// fill it!</font></tt>
<br><b><tt><font color="#993399">&nbsp;for (unsigned int igeno=0; igeno&lt;POP_SIZE;
igeno++)</font></tt></b>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Indi v;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// void individual, to be filled</font></tt>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
for (unsigned ivar=0; ivar&lt;VEC_SIZE; ivar++)</font></tt></b>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
bool r = rng.flip(); </b>// new value, random in {0,1}</font></tt>
<br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
v.push_back(r);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </b>//
append that random value to v</font></tt>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
eval(v);&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;
</b>// evaluate it</font></tt>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
pop.push_back(v);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font></tt></b><tt><font color="#993399">// and put it in the population</font></tt>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp; }</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>// sort pop before printing
it!</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;</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;cout &lt;&lt; pop;</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;eoDetTournamentSelect&lt;Indi> select(T_SIZE);&nbsp;
</b>// T_SIZE in [2,POP_SIZE]</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>// The simple GA evolution engine
uses generational replacement</font></tt>
<br><tt><font color="#009900"><b>&nbsp;</b>// so no replacement procedure
is needed</font></tt></td>
</tr>
</table>
<a NAME="stop"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr>
<td></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 mutation for bitstring</font></tt>
<br><b><tt><font color="#993399">&nbsp;eoBinCrossover&lt;Indi> xover;</font></tt></b></td>
</tr>
</table>
<a NAME="mutation"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
<tr> <tr>
<td> <td>
<tt><font color="#993300"> <br><tt><font color="#993399"><b>&nbsp;</b>// standard bit-flip mutation
//-----------------------------------------------------------------------------<br> for bitstring</font></tt>
<b>void main_function(int argc, char **argv)</b><br> <br><b><tt><font color="#993399">&nbsp;eoBinMutation&lt;Indi>&nbsp; mutation(P_MUT_PER_BIT);</font></tt></b></td>
<b>{</b><br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="parametres"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE > <a NAME="checkpoint"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#3366FF"><b>&nbsp;</b>//////////////////////////////////////</font></tt>
<tt><font color="#3366FF"> <br><tt><font color="#3366FF"><b>&nbsp;</b>// termination condition</font></tt>
<b> &nbsp;</b>// all parameters are hard-coded!<br> <br><tt><font color="#3366FF"><b>&nbsp;</b>/////////////////////////////////////</font></tt>
<b> &nbsp;const unsigned int SEED = 42; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// seed for random number generator<br> <br><tt><font color="#3366FF"><b>&nbsp;</b>// stop after MAX_GEN generations</font></tt>
<b> &nbsp;const unsigned int T_SIZE = 3; &nbsp; &nbsp; &nbsp; &nbsp;</b>// size for tournament selection<br> <br><b><tt><font color="#3366FF">&nbsp;eoGenContinue&lt;Indi> continuator(MAX_GEN);</font></tt></b>
<b> &nbsp;const unsigned int VEC_SIZE = 8; &nbsp; &nbsp;</b>// Number of bits in genotypes<br> <br>&nbsp;</td>
<b> &nbsp;const unsigned int POP_SIZE = 20; &nbsp;</b>// Size of population<br>
<b> &nbsp;const unsigned int MAX_GEN = 100; &nbsp;</b>// Maximum number of generation before STOP<br>
<b> &nbsp;const float CROSS_RATE = 0.8; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// Crossover rate<br>
<b> &nbsp;const double P_MUT_PER_BIT = 0.01; </b>// probability of bit-flip mutation<br>
<b> &nbsp;const float MUT_RATE = 1.0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// mutation rate<br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE > <a NAME="generation"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#FF6666"><b>&nbsp;</b>/////////////////////////////////////////</font></tt>
<tt><font color="#993300"> <br><tt><font color="#FF6666"><b>&nbsp;</b>// the algorithm</font></tt>
<a NAME="random"></a> <br><tt><font color="#FF6666"><b>&nbsp;</b>////////////////////////////////////////</font></tt>
<b> &nbsp;</b>//////////////////////////<br> <br><tt><font color="#FF6666"><b>&nbsp;</b>// standard Generational GA
<b> &nbsp;</b>// &nbsp;Random seed<br> requires as parameters</font></tt>
<b> &nbsp;</b>//////////////////////////<br> <br><tt><font color="#FF6666"><b>&nbsp;</b>// selection, evaluation, crossover
<b> &nbsp;</b>//reproducible random seed: if you don't change SEED above, <br> and mutation, stopping criterion</font></tt>
<b> &nbsp;</b>// you'll aways get the same result, NOT a random run<br> <p><b><tt><font color="#FF6666">&nbsp;eoSGA&lt;Indi> gga(select, xover,
<b> &nbsp;rng.reseed(SEED);</b><br> CROSS_RATE, mutation, MUT_RATE,&nbsp;</font></tt></b>
</font></tt> <br><b><tt><font color="#FF6666">&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;
</td> eval, continuator);</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>
<br>&nbsp;</td>
</tr> </tr>
</table> </table>
<a NAME="eval"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE > <a NAME="final_output"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#3366FF"><b>&nbsp;</b>// Print (sorted) intial population</font></tt>
<tt><font color="#CC0000"> <br><b><tt><font color="#3366FF">&nbsp;pop.sort();</font></tt></b>
<b> &nbsp;</b>/////////////////////////////<br> <br><b><tt><font color="#3366FF">&nbsp;cout &lt;&lt; "FINAL Population\n"
<b> &nbsp;</b>// Fitness function<br> &lt;&lt; pop &lt;&lt; endl;</font></tt></b></td>
<b> &nbsp;</b>////////////////////////////<br>
<b> &nbsp;</b>// Evaluation: from a plain C++ fn to an EvalFunc Object<br>
<b> &nbsp;eoEvalFuncPtr&lt;Indi> eval( &nbsp;binary_value );</b><br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="init"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE > <a NAME="main"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr> <tr>
<td> <td><b><tt><font color="#993300">}</font></tt></b>
<tt><font color="#993399"> <br><tt><font color="#993300">// A main that catches the exceptions</font></tt>
<b> &nbsp;</b>////////////////////////////////<br> <br><b><tt><font color="#993300">int main(int argc, char **argv)</font></tt></b>
<b> &nbsp;</b>// Initilisation of population<br> <br><b><tt><font color="#993300">{</font></tt></b>
<b> &nbsp;</b>////////////////////////////////<br> <br><b><tt><font color="#993300">#ifdef _MSC_VER</font></tt></b>
<b> &nbsp;</b>// declare the population<br> <br><tt><font color="#993300"><b>&nbsp;</b>//&nbsp; rng.reseed(42);</font></tt>
<b> &nbsp;eoPop&lt;Indi> pop;</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b>
<b> &nbsp;</b>// fill it!<br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag
<b> &nbsp;for (unsigned int igeno=0; igeno&lt;POP_SIZE; igeno++)</b><br> |= _CRTDBG_LEAK_CHECK_DF;</font></tt></b>
<b> &nbsp; &nbsp; &nbsp;{</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; _CrtSetDbgFlag(flag);</font></tt></b>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Indi v; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// void individual, to be filled<br> <br><tt><font color="#993300">//&nbsp;&nbsp;&nbsp; _CrtSetBreakAlloc(100);</font></tt>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (unsigned ivar=0; ivar&lt;VEC_SIZE; ivar++)</b><br> <br><b><tt><font color="#993300">#endif</font></tt></b>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; try</font></tt></b>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bool r = rng.flip(); </b>// new value, random in {0,1}<br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v.push_back(r); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// append that random value to v<br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</b><br> main_function(argc, argv);</font></tt></b>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;eval(v); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// evaluate it<br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pop.push_back(v); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// and put it in the population<br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; catch(exception&amp;
<b> &nbsp; &nbsp; &nbsp;}</b><br> e)</font></tt></b>
</font></tt> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b>
</td> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</tr> cout &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; '\n';</font></tt></b>
</table> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b>
<a NAME="output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE > <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; return 1;</font></tt></b>
<tr> <br><b><tt><font color="#993300">}</font></tt></b></td>
<td>
<tt><font color="#3366FF">
<b> &nbsp;</b>// sort pop before printing it!<br>
<b> &nbsp;pop.sort();</b><br>
<b> &nbsp;</b>// Print (sorted) intial population (raw printout)<br>
<b> &nbsp;cout &lt;&lt; "Initial Population" &lt;&lt; endl;</b><br>
<b> &nbsp;cout &lt;&lt; pop;</b><br>
</font></tt>
</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>/////////////////////////////////////<br>
<b> &nbsp;</b>// selection and replacement<br>
<b> &nbsp;</b>////////////////////////////////////<br>
</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<br>
<b> &nbsp;eoDetTournamentSelect&lt;Indi> select(T_SIZE); &nbsp;</b>// T_SIZE in [2,POP_SIZE]<br>
</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>// The simple GA evolution engine uses generational replacement<br>
<b> &nbsp;</b>// so no replacement procedure is needed<br>
</font></tt>
</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">
</font></tt>
</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>//////////////////////////////////////<br>
<b> &nbsp;</b>// The variation operators<br>
<b> &nbsp;</b>//////////////////////////////////////<br>
</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 mutation for bitstring<br>
<b> &nbsp;eoBinCrossover&lt;Indi> xover;</b><br>
</font></tt>
</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><br>
<b> &nbsp;</b>// standard bit-flip mutation for bitstring<br>
<b> &nbsp;eoBinMutation&lt;Indi> &nbsp;mutation(P_MUT_PER_BIT);</b><br>
</font></tt>
</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>//////////////////////////////////////<br>
<b> &nbsp;</b>// termination condition<br>
<b> &nbsp;</b>/////////////////////////////////////<br>
<b> &nbsp;</b>// stop after MAX_GEN generations<br>
<b> &nbsp;eoGenContinue&lt;Indi> continuator(MAX_GEN);</b><br>
<b> &nbsp;</b><br>
</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>/////////////////////////////////////////<br>
<b> &nbsp;</b>// the algorithm<br>
<b> &nbsp;</b>////////////////////////////////////////<br>
<b> &nbsp;</b>// standard Generational GA requires as parameters<br>
<b> &nbsp;</b>// selection, evaluation, crossover and mutation, stopping criterion<br>
<b> </b><br>
<b> &nbsp;eoSGA&lt;Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE, </b><br>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;eval, continuator);</b><br>
<b> &nbsp;</b>// Apply algo to pop - that's it!<br>
<b> &nbsp;gga(pop);</b><br>
<b> &nbsp;</b><br>
</font></tt>
</td>
</tr>
</table>
<a NAME="final_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) intial population<br>
<b> &nbsp;pop.sort();</b><br>
<b> &nbsp;cout &lt;&lt; "FINAL Population\n" &lt;&lt; pop &lt;&lt; endl;</b><br>
</font></tt>
</td>
</tr>
</table>
<a NAME="main"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr>
<td>
<tt><font color="#993300">
<b>}</b><br>
<b> </b>// A main that catches the exceptions<br>
<b>int main(int argc, char **argv)</b><br>
<b>{</b><br>
<b>#ifdef _MSC_VER</b><br>
<b> &nbsp;</b>// &nbsp;rng.reseed(42);<br>
<b> &nbsp; &nbsp; &nbsp;int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</b><br>
<b> &nbsp; &nbsp; &nbsp; &nbsp;flag |= _CRTDBG_LEAK_CHECK_DF;</b><br>
<b> &nbsp; &nbsp; &nbsp;_CrtSetDbgFlag(flag);</b><br>
// &nbsp; &nbsp;_CrtSetBreakAlloc(100);<br>
<b>#endif</b><br>
<b> &nbsp; &nbsp; &nbsp;try</b><br>
<b> &nbsp; &nbsp; &nbsp;{</b><br>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;main_function(argc, argv);</b><br>
<b> &nbsp; &nbsp; &nbsp;}</b><br>
<b> &nbsp; &nbsp; &nbsp;catch(exception& e)</b><br>
<b> &nbsp; &nbsp; &nbsp;{</b><br>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cout &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; '\n';</b><br>
<b> &nbsp; &nbsp; &nbsp;}</b><br>
<b> &nbsp; &nbsp; &nbsp;return 1;</b><br>
<b>}</b><br>
</font></font></font></td>
</tr> </tr>
</table> </table>
<hr WIDTH="100%"><a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial <hr WIDTH="100%"><a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
@ -343,8 +307,8 @@ documentation</a></font>
<hr> <hr>
<address> <address>
<a href="mailto:marc.schoenauer@polytechnique.fr">Marc Schoenauer</a></address> <a href="mailto:marc.schoenauer@polytechnique.fr">Marc Schoenauer</a></address>
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last
modified: Sun Nov 19 08:31:26 2000 <br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Sun Nov
<!-- hhmts end --> 19 08:31:26 2000<!-- hhmts end -->
</body> </body>
</html> </html>

View file

@ -34,8 +34,9 @@ Breeder - and Combined Ops</font></tt>
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt> <br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
<br><tt><font color="#993300">// standard includes</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;stdexcept>&nbsp; </b>// runtime_error&nbsp;</font></tt>
<br><tt><font color="#993300"><b>#include &lt;iostream>&nbsp;&nbsp;&nbsp; <br><tt><font color="#993300"><b>#include &lt;iostream>&nbsp;&nbsp;
</b>// cout</font></tt> </b>//
cout</font></tt>
<br><tt><font color="#993300"><b>#include &lt;strstream>&nbsp; </b>// ostrstream, <br><tt><font color="#993300"><b>#include &lt;strstream>&nbsp; </b>// ostrstream,
istrstream</font></tt> istrstream</font></tt>
<br><tt><font color="#993300">// the general include for eo</font></tt> <br><tt><font color="#993300">// the general include for eo</font></tt>
@ -46,6 +47,9 @@ istrstream</font></tt>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE > <table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
<tr> <tr>
<td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt> <td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
<br><tt><font color="#999900">// Include the corresponding file&nbsp;</font></tt>
<br><tt><font color="#999900"><b>#include &lt;es.h></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// real-representation &amp; operators&nbsp;</font></tt>
<br><tt><font color="#999900">// define your individuals</font></tt> <br><tt><font color="#999900">// define your individuals</font></tt>
<br><b><tt><font color="#999900">typedef eoReal&lt;double> Indi;&nbsp;</font></tt></b></td> <br><b><tt><font color="#999900">typedef eoReal&lt;double> Indi;&nbsp;</font></tt></b></td>
</tr> </tr>
@ -77,12 +81,16 @@ seed for random number generator</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int T_SIZE = 3; </b>// <br><tt><font color="#3366FF"><b>&nbsp;const unsigned int T_SIZE = 3; </b>//
size for tournament selection</font></tt> size for tournament selection</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int VEC_SIZE = 8; <br><tt><font color="#3366FF"><b>&nbsp;const unsigned int VEC_SIZE = 8;
</b>// Number of object variables in genotypes</font></tt> </b>//
Number of object variables in genotypes</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int POP_SIZE = 20; <br><tt><font color="#3366FF"><b>&nbsp;const unsigned int POP_SIZE = 20;
</b>// Size of population</font></tt> </b>//
Size of population</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int MAX_GEN = 500; <br><tt><font color="#3366FF"><b>&nbsp;const unsigned int MAX_GEN = 500;
</b>// Maximum number of generation before STOP</font></tt> </b>//
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int MIN_GEN = 10;&nbsp; Maximum number of generation before STOP</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int MIN_GEN = 10;
</b>// Minimum number of generation before ...</font></tt> </b>// Minimum number of generation before ...</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const unsigned int STEADY_GEN = <br><tt><font color="#3366FF"><b>&nbsp;const unsigned int STEADY_GEN =
50; </b>// stop after STEADY_GEN gen. without improvelent</font></tt> 50; </b>// stop after STEADY_GEN gen. without improvelent</font></tt>
@ -97,13 +105,17 @@ SIGMA = 0.3;&nbsp;</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // std dev.
for normal mutation</font></tt> for normal mutation</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;</b>// some parameters for chosing <br><tt><font color="#3366FF"><b>&nbsp;</b>// some parameters for chosing
among different operators</font></tt> among different operators</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const double segmentRate = 0.5;&nbsp;&nbsp;&nbsp; <br><tt><font color="#3366FF"><b>&nbsp;const double segmentRate = 0.5;&nbsp;&nbsp;
</b>// relative weight for 1-pt Xover</font></tt> </b>// relative weight for 1-pt Xover</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const double arithmeticRate = 0.5; <br><tt><font color="#3366FF"><b>&nbsp;const double arithmeticRate = 0.5;
</b>// relative weight for 2-pt Xover</font></tt> </b>//
relative weight for 2-pt Xover</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const double uniformMutRate = 0.5; <br><tt><font color="#3366FF"><b>&nbsp;const double uniformMutRate = 0.5;
</b>// relative weight for bit-flip mutation</font></tt> </b>//
<br><tt><font color="#3366FF"><b>&nbsp;const double detMutRate = 0.5;&nbsp;&nbsp;&nbsp;&nbsp; relative weight for bit-flip mutation</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const double detMutRate = 0.5;&nbsp;&nbsp;&nbsp;
</b>// relative weight for one-bit mutation</font></tt> </b>// relative weight for one-bit mutation</font></tt>
<br><tt><font color="#3366FF">&nbsp;<b>const double normalMutRate = 0.5;</b>&nbsp; <br><tt><font color="#3366FF">&nbsp;<b>const double normalMutRate = 0.5;</b>&nbsp;
// relative weight for normal mutation</font></tt></td> // relative weight for normal mutation</font></tt></td>
@ -181,8 +193,8 @@ it!</font></tt>
<tr> <tr>
<td><tt><font color="#009900"><b>&nbsp;</b>// The robust tournament selection</font></tt> <td><tt><font color="#009900"><b>&nbsp;</b>// The robust tournament selection</font></tt>
<br><b><tt><font color="#009900">&nbsp;eoDetTournamentSelect&lt;Indi> selectOne(T_SIZE);</font></tt></b> <br><b><tt><font color="#009900">&nbsp;eoDetTournamentSelect&lt;Indi> selectOne(T_SIZE);</font></tt></b>
<br><a NAME="select_encapsulate"></a><tt><font color="#009900"><b> </b>// <br><a NAME="select_encapsulate"></a><tt><font color="#009900">// is now
is now encapsulated in a eoSelectPerc (entage)</font></tt> encapsulated in a eoSelectPerc (entage)</font></tt>
<br><tt><font color="#009900"><b>&nbsp;eoSelectPerc&lt;Indi> select(selectOne);</b>// <br><tt><font color="#009900"><b>&nbsp;eoSelectPerc&lt;Indi> select(selectOne);</b>//
by default rate==1</font></tt></td> by default rate==1</font></tt></td>
</tr> </tr>
@ -295,8 +307,7 @@ eval, select, transform, replace);</font></tt></b>
it!</font></tt> it!</font></tt>
<br><b><tt><font color="#FF6666">&nbsp;cout &lt;&lt; "\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br><b><tt><font color="#FF6666">&nbsp;cout &lt;&lt; "\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Here we go\n\n";</font></tt></b> Here we go\n\n";</font></tt></b>
<br><b><tt><font color="#FF6666">&nbsp;gga(pop);</font></tt></b> <br><b><tt><font color="#FF6666">&nbsp;gga(pop);</font></tt></b></td>
<br>&nbsp;</td>
</tr> </tr>
</table> </table>
<a NAME="output"></a> <a NAME="output"></a>

View file

@ -2,9 +2,9 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="cpp2html Marc Schoenauer"> <meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
<title>../FirstRealGA.html</title> <title>../FirstRealGA.html</title>
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 --> <!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
</head> </head>
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000"> <body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
<a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial <a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial
@ -16,325 +16,293 @@ documentation</a></font>
<center> <center>
<h1> <h1>
<font color="#FF0000">../FirstRealGA.html</font></h1></center> <font color="#FF0000">../FirstRealGA.html</font></h1></center>
Click on the figure to see the corresponding code.<br> Click on the figure to see the corresponding code.
In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a><br> <br>In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a>
The actual code is in boldface and the comment in normal face. <br>The actual code is in boldface and the comment in normal face.
<br><img SRC="EA_tutorial.jpg" USEMAP="#Map" > <br><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>
<map NAME="Map"> <br><a NAME="start"></a>
<!-- 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>&nbsp;
<A NAME="start"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE > <table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr NOSAVE> <tr NOSAVE>
<td NOSAVE><tt><font color="#993300"> <td NOSAVE><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
//-----------------------------------------------------------------------------<br> <br><tt><font color="#993300">// FirstRealGA.cpp</font></tt>
// FirstRealGA.cpp<br> <br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
//-----------------------------------------------------------------------------<br> <br><tt><font color="#993300">//*</font></tt>
//*<br> <br><tt><font color="#993300">// An instance of a VERY simple Real-coded
// An instance of a VERY simple Real-coded Genetic Algorithm<br> Genetic Algorithm</font></tt>
//<br> <br><tt><font color="#993300">//</font></tt>
//-----------------------------------------------------------------------------<br> <br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
// standard includes<br> <br><tt><font color="#993300">// standard includes</font></tt>
<b>#include &lt;stdexcept> &nbsp;</b>// runtime_error <br> <br><tt><font color="#993300"><b>#include &lt;stdexcept>&nbsp; </b>// runtime_error&nbsp;</font></tt>
<b>#include &lt;iostream> &nbsp; &nbsp;</b>// cout<br> <br><tt><font color="#993300"><b>#include &lt;iostream>&nbsp;&nbsp;&nbsp;
<b>#include &lt;strstream> &nbsp;</b>// ostrstream, istrstream<br> </b>// cout</font></tt>
// the general include for eo<br> <br><tt><font color="#993300"><b>#include &lt;strstream>&nbsp; </b>// ostrstream,
<b>#include &lt;eo></b><br> istrstream</font></tt>
</font></tt> <br><tt><font color="#993300">// the general include for eo</font></tt>
</td> <br><b><tt><font color="#993300">#include &lt;eo></font></tt></b></td>
</tr> </tr>
</table> </table>
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE > <a NAME="representation"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
<tt><font color="#999900"> <br><tt><font color="#999900">// Include the corresponding file</font></tt>
//-----------------------------------------------------------------------------<br> <br><tt><font color="#999900"><b>#include &lt;es.h></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// define your individuals<br> // real-representation &amp; operators</font></tt>
<b> typedef eoReal&lt;double> Indi;</b><br> <br><tt><font color="#999900">// define your individuals</font></tt>
</font></tt> <br><b><tt><font color="#999900">typedef eoReal&lt;double> Indi;</font></tt></b></td>
</td>
</tr> </tr>
</table> </table>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE > <table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#CC0000">//-----------------------------------------------------------------------------</font></tt>
<tt><font color="#CC0000"> <br><tt><font color="#CC0000">// a simple fitness function that computes
//-----------------------------------------------------------------------------<br> the euclidian norm of a real vector</font></tt>
// a simple fitness function that computes the euclidian norm of a real vector<br> <br><tt><font color="#CC0000">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @param _indi
// &nbsp; &nbsp; &nbsp;@param _indi A real-valued individual <br> A real-valued individual&nbsp;</font></tt>
<a name="evalfunc"></a> <br><a NAME="evalfunc"></a><b><tt><font color="#CC0000">double real_value(const
<b>double real_value(const Indi & _indi)</b><br> Indi &amp; _indi)</font></tt></b>
<b>{</b><br> <br><b><tt><font color="#CC0000">{</font></tt></b>
<b> &nbsp;double sum = 0;</b><br> <br><b><tt><font color="#CC0000">&nbsp;double sum = 0;</font></tt></b>
<b> &nbsp;for (unsigned i = 0; i &lt; _indi.size(); i++)</b><br> <br><b><tt><font color="#CC0000">&nbsp;for (unsigned i = 0; i &lt; _indi.size();
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sum += _indi[i]*_indi[i];</b><br> i++)</font></tt></b>
<b> &nbsp;return (-sum); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// maximizing only<br> <br><b><tt><font color="#CC0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b>}</b><br> sum += _indi[i]*_indi[i];</font></tt></b>
</font></tt> <br><tt><font color="#CC0000"><b>&nbsp;return (-sum);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</td> </b>// maximizing only</font></tt>
<br><b><tt><font color="#CC0000">}</font></tt></b></td>
</tr> </tr>
</table> </table>
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE > <a NAME="general"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
<tt><font color="#993300"> <br><b><tt><font color="#993300">void main_function(int argc, char **argv)</font></tt></b>
//-----------------------------------------------------------------------------<br> <br><b><tt><font color="#993300">{</font></tt></b></td>
<b>void main_function(int argc, char **argv)</b><br>
<b>{</b><br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="parametres"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE > <a NAME="parametres"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#3366FF"><b>&nbsp;</b>// all parameters are hard-coded!</font></tt>
<tt><font color="#3366FF"> <br><tt><font color="#3366FF"><b>&nbsp;const unsigned int SEED = 42; </b>//
<b> &nbsp;</b>// all parameters are hard-coded!<br> seed for random number generator</font></tt>
<b> &nbsp;const unsigned int SEED = 42; </b>// seed for random number generator<br> <br><tt><font color="#3366FF"><b>&nbsp;const unsigned int VEC_SIZE = 8;
<b> &nbsp;const unsigned int VEC_SIZE = 8; </b>// Number of object variables in genotypes<br> </b>// Number of object variables in genotypes</font></tt>
<b> &nbsp;const unsigned int POP_SIZE = 20; </b>// Size of population<br> <br><tt><font color="#3366FF"><b>&nbsp;const unsigned int POP_SIZE = 20;
<b> &nbsp;const unsigned int T_SIZE = 3; </b>// size for tournament selection<br> </b>// Size of population</font></tt>
<b> &nbsp;const unsigned int MAX_GEN = 500; </b>// Maximum number of generation before STOP<br> <br><tt><font color="#3366FF"><b>&nbsp;const unsigned int T_SIZE = 3; </b>//
<b> &nbsp;const float CROSS_RATE = 0.8; </b>// Crossover rate<br> size for tournament selection</font></tt>
<b> &nbsp;const double EPSILON = 0.01; &nbsp;</b>// range for real uniform mutation<br> <br><tt><font color="#3366FF"><b>&nbsp;const unsigned int MAX_GEN = 500;
<b> &nbsp;const float MUT_RATE = 0.5; &nbsp; &nbsp;</b>// mutation rate<br> </b>// Maximum number of generation before STOP</font></tt>
</font></tt> <br><tt><font color="#3366FF"><b>&nbsp;const float CROSS_RATE = 0.8; </b>//
</td> Crossover rate</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const double EPSILON = 0.01;&nbsp;
</b>// range for real uniform mutation</font></tt>
<br><tt><font color="#3366FF"><b>&nbsp;const float MUT_RATE = 0.5;&nbsp;&nbsp;&nbsp;
</b>// mutation rate</font></tt></td>
</tr> </tr>
</table> </table>
<a NAME="general"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE > <a NAME="general"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr> <tr>
<td> <td><a NAME="random"></a><tt><font color="#993300"><b> </b>//////////////////////////</font></tt>
<tt><font color="#993300"> <br><tt><font color="#993300"><b>&nbsp;</b>//&nbsp; Random seed</font></tt>
<a NAME="random"></a> <br><tt><font color="#993300"><b>&nbsp;</b>//////////////////////////</font></tt>
<b> &nbsp;</b>//////////////////////////<br> <br><tt><font color="#993300"><b>&nbsp;</b>//reproducible random seed:
<b> &nbsp;</b>// &nbsp;Random seed<br> if you don't change SEED above,&nbsp;</font></tt>
<b> &nbsp;</b>//////////////////////////<br> <br><tt><font color="#993300"><b>&nbsp;</b>// you'll aways get the same
<b> &nbsp;</b>//reproducible random seed: if you don't change SEED above, <br> result, NOT a random run</font></tt>
<b> &nbsp;</b>// you'll aways get the same result, NOT a random run<br> <br><b><tt><font color="#993300">&nbsp;rng.reseed(SEED);</font></tt></b></td>
<b> &nbsp;rng.reseed(SEED);</b><br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="eval"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE > <a NAME="eval"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#CC0000"><b>&nbsp;</b>/////////////////////////////</font></tt>
<tt><font color="#CC0000"> <br><tt><font color="#CC0000"><b>&nbsp;</b>// Fitness function</font></tt>
<b> &nbsp;</b>/////////////////////////////<br> <br><tt><font color="#CC0000"><b>&nbsp;</b>////////////////////////////</font></tt>
<b> &nbsp;</b>// Fitness function<br> <br><tt><font color="#CC0000"><b>&nbsp;</b>// Evaluation: from a plain
<b> &nbsp;</b>////////////////////////////<br> C++ fn to an EvalFunc Object</font></tt>
<b> &nbsp;</b>// Evaluation: from a plain C++ fn to an EvalFunc Object<br> <br><b><tt><font color="#CC0000">&nbsp;eoEvalFuncPtr&lt;Indi> eval(&nbsp;
<b> &nbsp;eoEvalFuncPtr&lt;Indi> eval( &nbsp;real_value );</b><br> real_value );</font></tt></b></td>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="init"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE > <a NAME="init"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#993399"><b>&nbsp;</b>////////////////////////////////</font></tt>
<tt><font color="#993399"> <br><tt><font color="#993399"><b>&nbsp;</b>// Initilisation of population</font></tt>
<b> &nbsp;</b>////////////////////////////////<br> <br><tt><font color="#993399"><b>&nbsp;</b>////////////////////////////////</font></tt>
<b> &nbsp;</b>// Initilisation of population<br> <br><tt><font color="#993399"><b>&nbsp;</b>// declare the population</font></tt>
<b> &nbsp;</b>////////////////////////////////<br> <br><b><tt><font color="#993399">&nbsp;eoPop&lt;Indi> pop;</font></tt></b>
<b> &nbsp;</b>// declare the population<br> <br><tt><font color="#993399"><b>&nbsp;</b>// fill it!</font></tt>
<b> &nbsp;eoPop&lt;Indi> pop;</b><br> <br><b><tt><font color="#993399">&nbsp;for (unsigned int igeno=0; igeno&lt;POP_SIZE;
<b> &nbsp;</b>// fill it!<br> igeno++)</font></tt></b>
<b> &nbsp;for (unsigned int igeno=0; igeno&lt;POP_SIZE; igeno++)</b><br> <br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b>
<b> &nbsp; &nbsp; &nbsp;{</b><br> <br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Indi v; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// void individual, to be filled<br> Indi v;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (unsigned ivar=0; ivar&lt;VEC_SIZE; ivar++)</b><br> </b>// void individual, to be filled</font></tt>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</b><br> <br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double r = 2*rng.uniform() - 1; </b>// new value, random in [-1,1)<br> for (unsigned ivar=0; ivar&lt;VEC_SIZE; ivar++)</font></tt></b>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v.push_back(r); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// append that random value to v<br> <br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</b><br> {</font></tt></b>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;eval(v); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// evaluate it<br> <br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pop.push_back(v); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// and put it in the population<br> double r = 2*rng.uniform() - 1; </b>// new value, random in [-1,1)</font></tt>
<b> &nbsp; &nbsp; &nbsp;}</b><br> <br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font></tt> v.push_back(r);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</td> </b>// append that random value to v</font></tt>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}</font></tt></b>
<br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
eval(v);&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;
</b>// evaluate it</font></tt>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
pop.push_back(v);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font></tt></b><tt><font color="#993399">// and put it in the population</font></tt>
<br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b></td>
</tr> </tr>
</table> </table>
<a NAME="output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE > <a NAME="output"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#3366FF"><b>&nbsp;</b>// sort pop before printing
<tt><font color="#3366FF"> it!</font></tt>
<b> &nbsp;</b>// sort pop before printing it!<br> <br><b><tt><font color="#3366FF">&nbsp;pop.sort();</font></tt></b>
<b> &nbsp;pop.sort();</b><br> <br><tt><font color="#3366FF"><b>&nbsp;</b>// Print (sorted) intial population
<b> &nbsp;</b>// Print (sorted) intial population (raw printout)<br> (raw printout)</font></tt>
<b> &nbsp;cout &lt;&lt; "Initial Population" &lt;&lt; endl;</b><br> <br><b><tt><font color="#3366FF">&nbsp;cout &lt;&lt; "Initial Population"
<b> &nbsp;cout &lt;&lt; pop;</b><br> &lt;&lt; endl;</font></tt></b>
</font></tt> <br><b><tt><font color="#3366FF">&nbsp;cout &lt;&lt; pop;</font></tt></b></td>
</td>
</tr> </tr>
</table> </table>
<a NAME="engine"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE > <a NAME="engine"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#009900"><b>&nbsp;</b>/////////////////////////////////////</font></tt>
<tt><font color="#009900"> <br><tt><font color="#009900"><b>&nbsp;</b>// selection and replacement</font></tt>
<b> &nbsp;</b>/////////////////////////////////////<br> <br><tt><font color="#009900"><b>&nbsp;</b>////////////////////////////////////</font></tt></td>
<b> &nbsp;</b>// selection and replacement<br>
<b> &nbsp;</b>////////////////////////////////////<br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="select"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE > <a NAME="select"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#009900"><b>&nbsp;</b>// The robust tournament selection</font></tt>
<tt><font color="#009900"> <br><tt><font color="#009900"><b>&nbsp;eoDetTournamentSelect&lt;Indi> select(T_SIZE);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b> &nbsp;</b>// The robust tournament selection<br> </b>// T_SIZE in [2,POP_SIZE]</font></tt></td>
<b> &nbsp;eoDetTournamentSelect&lt;Indi> select(T_SIZE); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b>// T_SIZE in [2,POP_SIZE]<br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="replace"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE > <a NAME="replace"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#009900"><b>&nbsp;</b>// eoSGA uses generational replacement
<tt><font color="#009900"> by default</font></tt>
<b> &nbsp;</b>// eoSGA uses generational replacement by default<br> <br><tt><font color="#009900"><b>&nbsp;</b>// so no replacement procedure
<b> &nbsp;</b>// so no replacement procedure has to be given<br> has to be given</font></tt></td>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="stop"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE > <a NAME="stop"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr> <tr>
<td> <td></td>
<tt><font color="#3366FF">
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="checkpoint"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE > <a NAME="checkpoint"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#3366FF"><b>&nbsp;</b>//////////////////////////////////////</font></tt>
<tt><font color="#3366FF"> <br><tt><font color="#3366FF"><b>&nbsp;</b>// termination condition</font></tt>
<b> &nbsp;</b>//////////////////////////////////////<br> <br><tt><font color="#3366FF"><b>&nbsp;</b>/////////////////////////////////////</font></tt>
<b> &nbsp;</b>// termination condition<br> <br><tt><font color="#3366FF"><b>&nbsp;</b>// stop after MAX_GEN generations</font></tt>
<b> &nbsp;</b>/////////////////////////////////////<br> <br><b><tt><font color="#3366FF">&nbsp;eoGenContinue&lt;Indi> continuator(MAX_GEN);</font></tt></b>
<b> &nbsp;</b>// stop after MAX_GEN generations<br> <br>&nbsp;</td>
<b> &nbsp;eoGenContinue&lt;Indi> continuator(MAX_GEN);</b><br>
<b> &nbsp;</b><br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="operators"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE > <a NAME="operators"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#993399"><b>&nbsp;</b>//////////////////////////////////////</font></tt>
<tt><font color="#993399"> <br><tt><font color="#993399"><b>&nbsp;</b>// The variation operators</font></tt>
<b> &nbsp;</b>//////////////////////////////////////<br> <br><tt><font color="#993399"><b>&nbsp;</b>//////////////////////////////////////</font></tt></td>
<b> &nbsp;</b>// The variation operators<br>
<b> &nbsp;</b>//////////////////////////////////////<br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="mutation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE > <a NAME="mutation"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#993399"><b>&nbsp;</b>// offspring(i) uniformly chosen
<tt><font color="#993399"> in [parent(i)-epsilon, parent(i)+epsilon]</font></tt>
<b> &nbsp;</b>// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]<br> <br><b><tt><font color="#993399">&nbsp;eoUniformMutation&lt;Indi>&nbsp;
<b> &nbsp;eoUniformMutation&lt;Indi> &nbsp;mutation(EPSILON); </b><br> mutation(EPSILON);&nbsp;</font></tt></b></td>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="crossover"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE > <a NAME="crossover"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#993399"><b>&nbsp;</b>// offspring(i) is a linear
<tt><font color="#993399"> combination of parent(i)</font></tt>
<b> &nbsp;</b>// offspring(i) is a linear combination of parent(i)<br> <br><b><tt><font color="#993399">&nbsp;eoArithmeticCrossover&lt;Indi> xover;</font></tt></b></td>
<b> &nbsp;eoArithmeticCrossover&lt;Indi> xover;</b><br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="generation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE > <a NAME="generation"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#FF6666"><b>&nbsp;</b>/////////////////////////////////////////</font></tt>
<tt><font color="#FF6666"> <br><tt><font color="#FF6666"><b>&nbsp;</b>// the algorithm</font></tt>
<b> &nbsp;</b>/////////////////////////////////////////<br> <br><tt><font color="#FF6666"><b>&nbsp;</b>////////////////////////////////////////</font></tt>
<b> &nbsp;</b>// the algorithm<br> <br><tt><font color="#FF6666"><b>&nbsp;</b>// standard Generational GA
<b> &nbsp;</b>////////////////////////////////////////<br> requires</font></tt>
<b> &nbsp;</b>// standard Generational GA requires<br> <br><tt><font color="#FF6666"><b>&nbsp;</b>// selection, evaluation, crossover
<b> &nbsp;</b>// selection, evaluation, crossover and mutation, stopping criterion<br> and mutation, stopping criterion</font></tt>
<b> </b><br> <p><b><tt><font color="#FF6666">&nbsp;eoSGA&lt;Indi> gga(select, xover,
<b> &nbsp;eoSGA&lt;Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE, </b><br> CROSS_RATE, mutation, MUT_RATE,&nbsp;</font></tt></b>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;eval, continuator);</b><br> <br><b><tt><font color="#FF6666">&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;
<b> &nbsp;</b>// Apply algo to pop - that's it!<br> eval, continuator);</font></tt></b>
<b> &nbsp;gga(pop);</b><br> <br><tt><font color="#FF6666"><b>&nbsp;</b>// Apply algo to pop - that's
<b> &nbsp;</b><br> it!</font></tt>
</font></tt> <br><b><tt><font color="#FF6666">&nbsp;gga(pop);</font></tt></b>
</td> <br>&nbsp;</td>
</tr> </tr>
</table> </table>
<a NAME="final_output"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE > <a NAME="final_output"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
<tr> <tr>
<td> <td><tt><font color="#3366FF"><b>&nbsp;</b>// Print (sorted) intial population</font></tt>
<tt><font color="#3366FF"> <br><b><tt><font color="#3366FF">&nbsp;pop.sort();</font></tt></b>
<b> &nbsp;</b>// Print (sorted) intial population<br> <br><b><tt><font color="#3366FF">&nbsp;cout &lt;&lt; "FINAL Population\n"
<b> &nbsp;pop.sort();</b><br> &lt;&lt; pop &lt;&lt; endl;</font></tt></b></td>
<b> &nbsp;cout &lt;&lt; "FINAL Population\n" &lt;&lt; pop &lt;&lt; endl;</b><br>
</font></tt>
</td>
</tr> </tr>
</table> </table>
<a NAME="main"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE > <a NAME="main"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
<tr> <tr>
<td> <td><b><tt><font color="#993300">}</font></tt></b>
<tt><font color="#993300"> <br><tt><font color="#993300">// A main that catches the exceptions</font></tt>
<b>}</b><br> <br><b><tt><font color="#993300">int main(int argc, char **argv)</font></tt></b>
// A main that catches the exceptions<br> <br><b><tt><font color="#993300">{</font></tt></b>
<b>int main(int argc, char **argv)</b><br> <br><b><tt><font color="#993300">#ifdef _MSC_VER</font></tt></b>
<b>{</b><br> <br><tt><font color="#993300"><b>&nbsp;</b>//&nbsp; rng.reseed(42);</font></tt>
<b>#ifdef _MSC_VER</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b>
<b> &nbsp;</b>// &nbsp;rng.reseed(42);<br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag
<b> &nbsp; &nbsp; &nbsp;int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</b><br> |= _CRTDBG_LEAK_CHECK_DF;</font></tt></b>
<b> &nbsp; &nbsp; &nbsp; &nbsp;flag |= _CRTDBG_LEAK_CHECK_DF;</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; _CrtSetDbgFlag(flag);</font></tt></b>
<b> &nbsp; &nbsp; &nbsp;_CrtSetDbgFlag(flag);</b><br> <br><tt><font color="#993300">//&nbsp;&nbsp;&nbsp; _CrtSetBreakAlloc(100);</font></tt>
// &nbsp; &nbsp;_CrtSetBreakAlloc(100);<br> <br><b><tt><font color="#993300">#endif</font></tt></b>
<b>#endif</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; try</font></tt></b>
<b> &nbsp; &nbsp; &nbsp;try</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b>
<b> &nbsp; &nbsp; &nbsp;{</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;main_function(argc, argv);</b><br> main_function(argc, argv);</font></tt></b>
<b> &nbsp; &nbsp; &nbsp;}</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b>
<b> &nbsp; &nbsp; &nbsp;catch(exception& e)</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; catch(exception&amp;
<b> &nbsp; &nbsp; &nbsp;{</b><br> e)</font></tt></b>
<b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cout &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; '\n';</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b>
<b> &nbsp; &nbsp; &nbsp;}</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b> &nbsp; &nbsp; &nbsp;return 1;</b><br> cout &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; '\n';</font></tt></b>
<b>}</b><br> <br><b><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b>
</font></font></font></td> <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> </tr>
</table> </table>
<hr WIDTH="100%"><a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial <hr WIDTH="100%"><a href="eoLesson1.html">Back to Lesson 1</a> - <a href="eoTutorial.html">Tutorial
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
@ -342,8 +310,8 @@ documentation</a></font>
<hr> <hr>
<address> <address>
<a href="mailto:marc.schoenauer@polytechnique.fr">Marc Schoenauer</a></address> <a href="mailto:marc.schoenauer@polytechnique.fr">Marc Schoenauer</a></address>
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last
modified: Sun Nov 19 08:31:29 2000 <br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Sun Nov
<!-- hhmts end --> 19 08:31:29 2000<!-- hhmts end -->
</body> </body>
</html> </html>

View file

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <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]"> <meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
<title>Differences</title> <title>Differences</title>
</head> </head>
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg"> <body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
@ -57,11 +57,15 @@ the parameter for the mutation).</li>
</tr> </tr>
<tr> <tr>
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#FFFF00">typedef <td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#FFFF00">#include
eoReal&lt;double> Indi;</font></font></td> &lt;es.h></font></font>
<br><font face="Courier New,Courier"><font color="#FFFF00">typedef eoReal&lt;double>
Indi;</font></font></td>
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#FFFF00">typedef <td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#FFFF00">#include
eoBin&lt;double> Indi;</font></font></td> &lt;ga.h></font></font>
<br><font face="Courier New,Courier"><font color="#FFFF00">typedef eoBin&lt;double>
Indi;</font></font></td>
</tr> </tr>
<tr> <tr>

View file

@ -63,6 +63,9 @@ the number of ones of a bitstring</font></tt>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE > <table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
<tr> <tr>
<td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt> <td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
<br><tt><font color="#999900">// Include the corresponding file</font></tt>
<br><tt><font color="#999900"><b>#include &lt;ga.h></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// bitstring representation &amp; operators</font></tt>
<br><tt><font color="#999900">// define your genotype and fitness types</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> <br><b><tt><font color="#999900">typedef eoBin&lt;double> Indi;</font></tt></b></td>
</tr> </tr>
@ -311,7 +314,6 @@ of initializatio of the population</font></tt></td>
<tr> <tr>
<td><tt><font color="#009900"><b>&nbsp;</b>// The robust tournament selection</font></tt> <td><tt><font color="#009900"><b>&nbsp;</b>// The robust tournament selection</font></tt>
<br><tt><font color="#009900"><b>&nbsp;eoDetTournamentSelect&lt;Indi> selectOne(tSize);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br><tt><font color="#009900"><b>&nbsp;eoDetTournamentSelect&lt;Indi> selectOne(tSize);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b>// tSize in [2,POPSIZE]</font></tt> </b>// tSize in [2,POPSIZE]</font></tt>
<br><tt><font color="#009900"><b>&nbsp;</b>// is now encapsulated in a <br><tt><font color="#009900"><b>&nbsp;</b>// is now encapsulated in a
eoSelectPerc (entage)</font></tt> eoSelectPerc (entage)</font></tt>

View file

@ -99,9 +99,14 @@ this is a file that contains the list of the most important EO files.</font></li
<br>&nbsp; <br>&nbsp;
<li> <li>
<b><font color="#999900">Representation</font></b><font color="#000000">: <b><font color="#999900">Representation</font></b><font color="#000000">:
you then have to declare the type of individuals you will be handling. you need to declare the type of individuals you will be handling. First,
All evolution-related objects you will need are templatized w.r.t. the include some header files where these are defined: </font><b><tt><font color="#999900">ga.h</font></tt></b><font color="#000000">
type of individuals.</font></li> for bitstring, </font><b><tt><font color="#999900">es.h</font></tt></b><font color="#000000">
for real-valued genotypes.<br>
Then a </font><b><tt><font color="#993300">typedef</font></tt></b><font color="#000000">
directive will allow one to handle the abstract </font><b><tt><font color="#993300">Indi</font></tt></b><font color="#000000">
all around in the main code. Remember that all evolution-related objects
you will need are templatized w.r.t. the type of individuals.</font></li>
<ul> <ul>
<li> <li>

View file

@ -67,13 +67,7 @@ argument is a <a href="binary_value.html">vector&lt;bool></a> or a <a href="real
and not an unknown type. This will allow to use the same file for any EO and not an unknown type. This will allow to use the same file for any EO
object that is a sub-class of the corresponding STL vector class.</font></li> object that is a sub-class of the corresponding STL vector class.</font></li>
<br>&nbsp; <p><br><b><font color="#FF0000">Note:</font></b> <font color="#000000">Also,
<p>&nbsp;
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<p><b><font color="#FF0000">Note:</font></b> <font color="#000000">Also,
a non-templatized fitness can be </font><b><font color="#FF6600">compiled a non-templatized fitness can be </font><b><font color="#FF6600">compiled
separately</font></b><font color="#000000"> (not done here) into an object separately</font></b><font color="#000000"> (not done here) into an object
file once and for all (<a href="eoProgramming.html#templates">remember</a> file once and for all (<a href="eoProgramming.html#templates">remember</a>
@ -88,14 +82,8 @@ have to declare 3 template arguments: the type of EO object it will be
applied to, the return type and the type of argument the function actually applied to, the return type and the type of argument the function actually
requires.</font></li> requires.</font></li>
<br>&nbsp; <p><br><b><font color="#FF0000">Note:</font></b> <font color="#000000">In
<p>&nbsp; the previous files (<a href="FirstBitGA.html#eval">Bit</a> - <a href="FirstRealGA.html#eval">Real</a>)
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<p><b><font color="#FF0000">Note:</font></b> <font color="#000000">In the
previous files (<a href="FirstBitGA.html#eval">Bit</a> - <a href="FirstRealGA.html#eval">Real</a>)
, the last 2 types were deduced from the first (2nd argument = fitness , the last 2 types were deduced from the first (2nd argument = fitness
type of EO object, third = first).</font> type of EO object, third = first).</font>
<br>&nbsp; <br>&nbsp;
@ -117,13 +105,7 @@ You can also use different initializers and call them in turn through the
call to <a href="../../doc/html/class_eopop.html#a2">pop.append()</a> function call to <a href="../../doc/html/class_eopop.html#a2">pop.append()</a> function
(see <a href="#exercise2">Exercise 2</a>).</font></li> (see <a href="#exercise2">Exercise 2</a>).</font></li>
<br>&nbsp; <p><br><b><font color="#FF0000">Note</font><font color="#CC33CC">: </font></b><font color="#000000">Don't
<p>&nbsp;
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<p><b><font color="#FF0000">Note</font><font color="#CC33CC">: </font></b><font color="#000000">Don't
forget to </font><b><font color="#CC0000">evaluate the population</font></b><font color="#000000">: forget to </font><b><font color="#CC0000">evaluate the population</font></b><font color="#000000">:
the eoPop has no idea of the eval function, so it has to be done from outside!!!</font> the eoPop has no idea of the eval function, so it has to be done from outside!!!</font>
<br>&nbsp; <br>&nbsp;