paradiseo/eo/tutorial/html/Firstmerge.html
evomarc 46d9671e05 Changed the links to the EO doc - removed the need for a (Unix) link from
tutorial/html dir to doc/ dir: it's simpler, and I was not able to do
the same thing in Windows anyway!
2000-12-02 08:27:30 +00:00

287 lines
14 KiB
HTML

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdksmp i686) [Netscape]">
<title>Differences</title>
</head>
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
<a href="eoLesson1.html">Back to Lesson 1</a> -
<a href="eoTutorial.html">Tutorial
main page</a> -
<a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
page</a> - <a href="eoProgramming.html">Programming hints</a> - <a href="../../doc/html/index.html">EO
documentation</a>
<br>
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
<center>
<h1>
<font color="#FF0000">FirstBitGA and FirstRealGA: differences</font></h1></center>
Below is a comparison of the codes for both algorithms (comments have been
removed).
<br><b><font color="#FF6600">Warning</font></b>: the <font color="#FF6666">pink
background</font> here denotes the differences, not the section&nbsp; of
the algorithm, which is only recalled by the color of the text!
<br>These differences are limited to
<ul>
<li>
the declaration of <font color="#666600">the type of the genotypes,</font></li>
<li>
the <font color="#990000">fitness function</font> (what did you expect
:-),</li>
<li>
the <font color="#CC33CC">initialization</font> (and if you look carefully,
you'll find out that only a small part of the initialization is different,
as both genotypes are eoFixedLength objects) and of course</li>
<li>
the choice of <font color="#CC33CC">variation operators </font>(including
the parameter for the mutation).</li>
</ul>
<table BORDER=0 CELLPADDING=5 COLS=2 WIDTH="100%" BGCOLOR="#C3C2B4" >
<tr>
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#993300">#include
&lt;stdexcept ></font></font>
<br><font face="Courier New,Courier"><font color="#993300">#include &lt;iostream></font></font>
<br><font face="Courier New,Courier"><font color="#993300">#include &lt;strstream></font></font>
<br><font face="Courier New,Courier"><font color="#FF6666">#include &lt;eo></font></font></td>
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#993300">#include
&lt;stdexcept ></font></font>
<br><font face="Courier New,Courier"><font color="#993300">#include &lt;iostream></font></font>
<br><font face="Courier New,Courier"><font color="#993300">#include &lt;strstream></font></font>
<br><font face="Courier New,Courier"><font color="#FF6666">#include &lt;eo></font></font></td>
</tr>
<tr>
<td BGCOLOR="#F0C6B7"><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
eoBin&lt;double> Indi;</font></font></td>
</tr>
<tr>
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC0000">double
real_value(const Indi &amp; _indi)</font></font>
<br><font face="Courier New,Courier"><font color="#CC0000">{</font></font>
<br><font face="Courier New,Courier"><font color="#CC0000">&nbsp; double
sum = 0;</font></font>
<br><font face="Courier New,Courier"><font color="#CC0000">&nbsp; for (unsigned
i = 0; i &lt; _indi.size(); i++)</font></font>
<br><font face="Courier New,Courier"><font color="#CC0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
sum += _indi[i]*_indi[i];</font></font>
<br><font face="Courier New,Courier"><font color="#CC0000">&nbsp; return
(-sum);&nbsp;&nbsp; // maximizing</font></font>
<br><font face="Courier New,Courier"><font color="#CC0000">}</font></font></td>
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC0000">double
binary_value(const Indi &amp; _indi)</font></font>
<br><font face="Courier New,Courier"><font color="#CC0000">{</font></font>
<br><font face="Courier New,Courier"><font color="#CC0000">&nbsp; double
sum = 0;</font></font>
<br><font face="Courier New,Courier"><font color="#CC0000">&nbsp; for (unsigned
i = 0; i &lt; _indi.size(); i++)</font></font>
<br><font face="Courier New,Courier"><font color="#CC0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
sum += _indi[i];</font></font>
<br><font face="Courier New,Courier"><font color="#CC0000">&nbsp; return
(sum);</font></font>
<br><font face="Courier New,Courier"><font color="#CC0000">}</font></font></td>
</tr>
<tr>
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#993300">void
main_function(int argc, char **argv)</font></font>
<br><font face="Courier New,Courier">{</font>
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
int SEED = 42;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
int VEC_SIZE = 8;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
int POP_SIZE = 20;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
int T_SIZE = 3;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
int MAX_GEN = 500;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">const float
CROSS_RATE = 0.8;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">const float
MUT_RATE = 0.5;</font></font></td>
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#993300">void
main_function(int argc, char **argv)</font></font>
<br><font face="Courier New,Courier">{</font>
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
int SEED = 42;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
int VEC_SIZE = 8;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
int POP_SIZE = 20;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
int T_SIZE = 3;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">const unsigned
int MAX_GEN = 500;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">const float
CROSS_RATE = 0.8;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">const float
MUT_RATE = 0.5;</font></font></td>
</tr>
<tr>
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#3366FF">const
double EPSILON = 0.01;</font></font></td>
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#3366FF">const
double P_MUT_PER_BIT = 0.01;</font></font></td>
</tr>
<tr>
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC0000">eoEvalFuncPtr&lt;Indi>
eval(real_value);</font></font></td>
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC0000">eoEvalFuncPtr&lt;Indi>
eval(binary_value);</font></font></td>
</tr>
<tr>
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#CC33CC">eoPop&lt;Indi>
pop;</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">for (unsigned
int igeno=0; igeno&lt;POP_SIZE; igeno++)</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp; {</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;
Indi v;</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;
for (unsigned ivar=0; ivar&lt;VEC_SIZE; ivar++)</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{</font></font></td>
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#CC33CC">eoPop&lt;Indi>
pop;</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">for (unsigned
int igeno=0; igeno&lt;POP_SIZE; igeno++)</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp; {</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;
Indi v;</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;
for (unsigned ivar=0; ivar&lt;VEC_SIZE; ivar++)</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{</font></font></td>
</tr>
<tr>
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
double r = 2*rng.uniform() - 1;</font></font></td>
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
bool r = rng.flip();&nbsp;</font></font></td>
</tr>
<tr>
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
v.push_back(r); //</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;
eval(v);</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;
pop.push_back(v);</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp; }</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">pop.sort();</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">cout &lt;&lt;
"Initial Population" &lt;&lt; endl;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">cout &lt;&lt;
pop;</font></font>
<br><font face="Courier New,Courier"><font color="#009900">eoDetTournament&lt;Indi>
select(T_SIZE);</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">eoGenContinue&lt;Indi>
continuator(MAX_GEN);</font></font></td>
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
v.push_back(r); //</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;
eval(v);</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp;&nbsp;&nbsp;
pop.push_back(v);</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">&nbsp; }</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">pop.sort();</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">cout &lt;&lt;
"Initial Population" &lt;&lt; endl;</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">cout &lt;&lt;
pop;</font></font>
<br><font face="Courier New,Courier"><font color="#009900">eoDetTournament&lt;Indi>
select(T_SIZE);</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">eoGenContinue&lt;Indi>
continuator(MAX_GEN);</font></font></td>
</tr>
<tr>
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">eoUniformMutation&lt;Indi>&nbsp;
mutation(EPSILON);</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">eoArithmeticCrossover&lt;Indi>
xover;</font></font></td>
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">eoBinMutation&lt;Indi>&nbsp;
mutation(P_MUT_PER_BIT);</font></font>
<br><font face="Courier New,Courier"><font color="#CC33CC">eoBinCrossover&lt;Indi>
xover;</font></font></td>
</tr>
<tr>
<td BGCOLOR="#C3C2B4">
<br><font face="Courier New,Courier"><font color="#FF6666">eoSGA&lt;Indi>
gga(select, xover, CROSS_RATE,</font></font>
<br><font face="Courier New,Courier"><font color="#FF6666">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
mutation, MUT_RATE, eval, continuator);</font></font>
<br><font face="Courier New,Courier"><font color="#FF6666">gga(pop);</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">pop.sort();</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">cout &lt;&lt;
"FINAL Population\n" &lt;&lt; pop &lt;&lt; endl;</font></font>
<br><font face="Courier New,Courier">}</font>
<br><font face="Courier New,Courier"><font color="#993300">int main(int
argc, char **argv)</font></font>
<br><font face="Courier New,Courier"><font color="#993300">{</font></font>
<br><font face="Courier New,Courier"><font color="#993300">... [technical
code removed]</font></font>
<br><font face="Courier New,Courier"><font color="#993300">}</font></font></td>
<td BGCOLOR="#C3C2B4">
<br><font face="Courier New,Courier"><font color="#FF6666">eoSGA&lt;Indi>
gga(select, xover, CROSS_RATE,</font></font>
<br><font face="Courier New,Courier"><font color="#FF6666">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
mutation, MUT_RATE,</font></font>
<br><font face="Courier New,Courier"><font color="#FF6666">eval, continuator);</font></font>
<br><font face="Courier New,Courier"><font color="#FF6666">gga(pop);</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">pop.sort();</font></font>
<br><font face="Courier New,Courier"><font color="#3366FF">cout &lt;&lt;
"FINAL Population\n" &lt;&lt; pop &lt;&lt; endl;</font></font>
<br><font face="Courier New,Courier">}</font>
<br><font face="Courier New,Courier"><font color="#993300">int main(int
argc, char **argv)</font></font>
<br><font face="Courier New,Courier"><font color="#993300">{</font></font>
<br><font face="Courier New,Courier"><font color="#993300">[... technical
code removed ]</font></font>
<br><font face="Courier New,Courier"><font color="#993300">}</font></font></td>
</tr>
</table>
<hr WIDTH="100%"><a href="eoLesson1.html">Back to Lesson 1</a> -
<a href="eoTutorial.html">Tutorial
main page</a> -
<a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
page</a> - <a href="eoProgramming.html">Programming hints</a> - <a href="../../doc/html/index.html">EO
documentation</a>
<br>
<hr>
<address>
<a href="mailto:marc@cmapx.polytechnique.fr">Marc Schoenauer</a></address>
<br><!-- Created: Tue Nov 7 07:04:15 CET 2000 --><!-- hhmts start -->Last
modified: Tue Nov 7 07:49:47 CET 2000<!-- hhmts end -->
</body>
</html>