Migration from SVN
This commit is contained in:
parent
d7d6c3a217
commit
8cd56f37db
44 changed files with 0 additions and 4096888 deletions
261
eo/tutorial/html/BitEA.html
Normal file
261
eo/tutorial/html/BitEA.html
Normal file
|
|
@ -0,0 +1,261 @@
|
|||
<!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="cpp2html Marc Schoenauer">
|
||||
<title>BitEA.cpp</title>
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson4.html">Back to Lesson 4</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">BitEA.cpp</font></h1></center>
|
||||
Click on the figure to see the corresponding code.<br>
|
||||
In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a><br>
|
||||
The actual code is in boldface and the comment in normal face.
|
||||
<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>
|
||||
<br>
|
||||
<A NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">
|
||||
<b>#include <iostream></b><br>
|
||||
<b>#include <ga/make_ga.h></b><br>
|
||||
<b>#include <apply.h></b><br>
|
||||
</font></tt>
|
||||
</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>#include "binary_value.h"</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>using namespace std;</b><br>
|
||||
<b>int main(int argc, char* argv[])</b><br>
|
||||
<b>{</b><br>
|
||||
<b> try</b><br>
|
||||
<b> {</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// define your genotype and fitness types<br>
|
||||
<b> typedef eoBit<double> EOT;</b><br>
|
||||
</font></tt>
|
||||
</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> eoParser parser(argc, argv); </b>// for user-parameter reading<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> eoState state; </b>// keeps all things allocated<br>
|
||||
<b> </b>///// FIRST, problem or representation dependent stuff<br>
|
||||
<b> </b>//////////////////////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</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> </b>// The evaluation fn - encapsulated into an eval counter for output <br>
|
||||
<b> eoEvalFuncPtr<EOT, float> mainEval( binary_value<EOT> );</b><br>
|
||||
<b> eoEvalFuncCounter<EOT> eval(mainEval);</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
<b> </b>// the genotype - through a genotype initializer<br>
|
||||
<b> eoInit<EOT>& init = make_genotype(parser, state, EOT());</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> </b>// Build the variation operator (any seq/prop construct)<br>
|
||||
<b> eoGenOp<EOT>& op = make_op(parser, state, init);</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>//// Now the representation-independent things<br>
|
||||
<b> </b>//////////////////////////////////////////////<br>
|
||||
<b> </b>// initialize the population - and evaluate<br>
|
||||
<b> </b>// yes, this is representation indepedent once you have an eoInit<br>
|
||||
<b> eoPop<EOT>& pop = make_pop(parser, state, init);</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">
|
||||
<b> </b>// stopping criteria<br>
|
||||
<b> eoContinue<EOT> & term = make_continue(parser, state, eval);</b><br>
|
||||
<b> </b>// output<br>
|
||||
<b> eoCheckPoint<EOT> & checkpoint = make_checkpoint(parser, state, eval, term);</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> </b>// algorithm (need the operator!)<br>
|
||||
<b> eoAlgo<EOT>& ga = make_algo_scalar(parser, state, eval, checkpoint, op);</b><br>
|
||||
<b> </b>///// End of construction of the algorith<br>
|
||||
<b> </b>/////////////////////////////////////////<br>
|
||||
</font></tt>
|
||||
</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> </b>// to be called AFTER all parameters have been read!!!<br>
|
||||
<b> make_help(parser);</b><br>
|
||||
<b> </b>//// GO<br>
|
||||
<b> </b>///////<br>
|
||||
</font></tt>
|
||||
</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> </b>// evaluate intial population AFTER help and status in case it takes time<br>
|
||||
<b> apply(eval, pop);</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">
|
||||
<b> </b>// print it out (sort witout modifying) <br>
|
||||
<b> cout << "Initial Population\n";</b><br>
|
||||
<b> pop.sortedPrintOn(cout);</b><br>
|
||||
<b> cout << endl;</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> run_ea(ga, pop); </b>// run the ga<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> </b>// print it out (sort witout modifying) <br>
|
||||
<b> cout << "Final Population\n";</b><br>
|
||||
<b> pop.sortedPrintOn(cout);</b><br>
|
||||
<b> cout << 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>
|
||||
<b> catch(exception& e)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> cout << e.what() << endl;</b><br>
|
||||
<b> }</b><br>
|
||||
<b>}</b><br>
|
||||
</font></font></font></td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr WIDTH="100%"><a href="eoLesson4.html">Back to Lesson 4</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last
|
||||
modified: Wed Mar 6 05:40:27 2002
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
BIN
eo/tutorial/html/EA_tutorial.jpg
Normal file
BIN
eo/tutorial/html/EA_tutorial.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 174 KiB |
369
eo/tutorial/html/FirstBitEA.html
Normal file
369
eo/tutorial/html/FirstBitEA.html
Normal file
|
|
@ -0,0 +1,369 @@
|
|||
<!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="cpp2html Marc Schoenauer">
|
||||
<title>FirstBitEA.cpp</title>
|
||||
<!-- Changed by: Marc Schoenauer, 28-Nov-2000 -->
|
||||
</head>
|
||||
<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
|
||||
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
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">FirstBitEA.cpp</font></h1></center>
|
||||
Click on the figure to see the corresponding code.<br>
|
||||
In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a><br>
|
||||
The actual code is in boldface and the comment in normal face.
|
||||
<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>
|
||||
<br>
|
||||
<A NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// FirstBitEA.cpp<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
//*<br>
|
||||
// Still an instance of a VERY simple Bitstring Genetic Algorithm <br>
|
||||
// (see FirstBitGA.cpp) but now with Breeder - and Combined Ops<br>
|
||||
//<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// standard includes<br>
|
||||
<b>#include <stdexcept> </b>// runtime_error <br>
|
||||
<b>#include <iostream> </b>// cout<br>
|
||||
<b>#include <strstream> </b>// ostrstream, istrstream<br>
|
||||
// the general include for eo<br>
|
||||
<b>#include <eo></b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
<b>#include <ga.h></b><br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// define your individuals<br>
|
||||
<b>typedef eoBit<double> Indi; </b>// A bitstring with fitness double<br>
|
||||
</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">
|
||||
//-----------------------------------------------------------------------------<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<bool> &)<br>
|
||||
<b>#include "binary_value.h"</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">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
<b>void main_function(int argc, char **argv)</b><br>
|
||||
<b>{</b><br>
|
||||
</font></tt>
|
||||
</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> const unsigned int SEED = 42; </b>// seed for random number generator<br>
|
||||
<b> const unsigned int T_SIZE = 3; </b>// size for tournament selection<br>
|
||||
<b> const unsigned int VEC_SIZE = 8; </b>// Number of bits in genotypes<br>
|
||||
<b> const unsigned int POP_SIZE = 20; </b>// Size of population<br>
|
||||
<b> const unsigned int MAX_GEN = 500; </b>// Maximum number of generation before STOP<br>
|
||||
<b> const float CROSS_RATE = 0.8; </b>// Crossover rate<br>
|
||||
<b> const double P_MUT_PER_BIT = 0.01; </b>// probability of bit-flip mutation<br>
|
||||
<b> const float MUT_RATE = 1.0; </b>// mutation rate<br>
|
||||
<b> </b>// some parameters for chosing among different operators<br>
|
||||
<b> const double onePointRate = 0.5; </b>// rate for 1-pt Xover<br>
|
||||
<b> const double twoPointsRate = 0.5; </b>// rate for 2-pt Xover<br>
|
||||
<b> const double URate = 0.5; </b>// rate for Uniform Xover<br>
|
||||
<b> const double bitFlipRate = 0.5; </b>// rate for bit-flip mutation<br>
|
||||
<b> const double oneBitRate = 0.5; </b>// rate for one-bit mutation<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>
|
||||
<b> </b>// Random seed<br>
|
||||
<b> </b>//////////////////////////<br>
|
||||
<b> </b>//reproducible random seed: if you don't change SEED above, <br>
|
||||
<b> </b>// you'll aways get the same result, NOT a random run<br>
|
||||
<b> rng.reseed(SEED);</b><br>
|
||||
</font></tt>
|
||||
</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> </b>/////////////////////////////<br>
|
||||
<b> </b>// Fitness function<br>
|
||||
<b> </b>////////////////////////////<br>
|
||||
<b> </b>// Evaluation: from a plain C++ fn to an EvalFunc Object<br>
|
||||
<b> </b>// you need to give the full description of the function<br>
|
||||
<b> eoEvalFuncPtr<Indi, double, const vector<bool>& > eval( binary_value );</b><br>
|
||||
</font></tt>
|
||||
</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> </b>////////////////////////////////<br>
|
||||
<b> </b>// Initilisation of population<br>
|
||||
<b> </b>////////////////////////////////<br>
|
||||
<b> </b>// based on eoUniformGenerator class (see utils/eoRndGenerators.h)<br>
|
||||
<b> eoUniformGenerator<bool> uGen;</b><br>
|
||||
<b> eoInitFixedLength<Indi> random(VEC_SIZE, uGen);</b><br>
|
||||
<b> </b>// Initialization of the population<br>
|
||||
<b> eoPop<Indi> pop(POP_SIZE, random);</b><br>
|
||||
<b> </b>// and evaluate it in one line<br>
|
||||
<b> apply<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> </b>// sort pop before printing it!<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> </b>// Print (sorted) intial population (raw printout)<br>
|
||||
<b> cout << "Initial Population" << endl;</b><br>
|
||||
<b> cout << 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> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// selection and replacement<br>
|
||||
<b> </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> </b>// The robust tournament selection<br>
|
||||
<b> eoDetTournamentSelect<Indi> selectOne(T_SIZE); </b>// T_SIZE in [2,POP_SIZE]<br>
|
||||
<a NAME="select_encapsulate"></a>
|
||||
<b> </b>// is now encapsulated in a eoSelectPerc (entage)<br>
|
||||
<b> eoSelectPerc<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> </b>// And we now have the full slection/replacement - though with <br>
|
||||
<b> </b>// no replacement (== generational replacement) at the moment :-)<br>
|
||||
<b> eoNoReplacement<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> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// The variation operators<br>
|
||||
<b> </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> </b>// 1-point crossover for bitstring<br>
|
||||
<b> eo1PtBitXover<Indi> xover1;</b><br>
|
||||
<b> </b>// uniform crossover for bitstring<br>
|
||||
<b> eoUBitXover<Indi> xoverU;</b><br>
|
||||
<b> </b>// 2-pots xover<br>
|
||||
<b> eoNPtsBitXover<Indi> xover2(2);</b><br>
|
||||
<b> </b>// Combine them with relative rates<br>
|
||||
<b> eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);</b><br>
|
||||
<b> xover.add(xoverU, URate);</b><br>
|
||||
<b> 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> </b><br>
|
||||
<b> </b>// standard bit-flip mutation for bitstring<br>
|
||||
<b> eoBitMutation<Indi> mutationBitFlip(P_MUT_PER_BIT);</b><br>
|
||||
<b> </b>// mutate exactly 1 bit per individual<br>
|
||||
<b> eoDetBitFlip<Indi> mutationOneBit; </b><br>
|
||||
<b> </b>// Combine them with relative rates<br>
|
||||
<b> eoPropCombinedMonOp<Indi> mutation(mutationBitFlip, bitFlipRate);</b><br>
|
||||
<b> mutation.add(mutationOneBit, oneBitRate, true);</b><br>
|
||||
<b> </b><br>
|
||||
<a NAME="transform"></a>
|
||||
<b> </b>// The operators are encapsulated into an eoTRansform object<br>
|
||||
<b> eoSGATransform<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> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// termination conditions: use more than one<br>
|
||||
<b> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// stop after MAX_GEN generations<br>
|
||||
<b> eoGenContinue<Indi> genCont(MAX_GEN);</b><br>
|
||||
<b> </b>// do MIN_GEN gen., then stop after STEADY_GEN gen. without improvement<br>
|
||||
<b> eoSteadyFitContinue<Indi> steadyCont(MIN_GEN, STEADY_GEN);</b><br>
|
||||
<b> </b>// stop when fitness reaches a target (here VEC_SIZE)<br>
|
||||
<b> eoFitContinue<Indi> fitCont(0);</b><br>
|
||||
<b> </b>// do stop when one of the above says so<br>
|
||||
<b> eoCombinedContinue<Indi> continuator(genCont);</b><br>
|
||||
<b> continuator.add(steadyCont);</b><br>
|
||||
<b> 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> </b>/////////////////////////////////////////<br>
|
||||
<b> </b>// the algorithm<br>
|
||||
<b> </b>////////////////////////////////////////<br>
|
||||
<b> </b>// Easy EA requires <br>
|
||||
<b> </b>// selection, transformation, eval, replacement, and stopping criterion<br>
|
||||
<b> eoEasyEA<Indi> gga(continuator, eval, select, transform, replace);</b><br>
|
||||
<b> </b>// Apply algo to pop - that's it!<br>
|
||||
<b> gga(pop);</b><br>
|
||||
<b> </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> </b>// Print (sorted) intial population<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> cout << "FINAL Population\n" << pop << 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> </b>// rng.reseed(42);<br>
|
||||
<b> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</b><br>
|
||||
<b> flag |= _CRTDBG_LEAK_CHECK_DF;</b><br>
|
||||
<b> _CrtSetDbgFlag(flag);</b><br>
|
||||
// _CrtSetBreakAlloc(100);<br>
|
||||
<b>#endif</b><br>
|
||||
<b> try</b><br>
|
||||
<b> {</b><br>
|
||||
<b> main_function(argc, argv);</b><br>
|
||||
<b> }</b><br>
|
||||
<b> catch(exception& e)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> cout << "Exception: " << e.what() << '\n';</b><br>
|
||||
<b> }</b><br>
|
||||
<b> return 1;</b><br>
|
||||
<b>}</b><br>
|
||||
</font></font></font></td>
|
||||
</tr>
|
||||
</table>
|
||||
<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
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last
|
||||
modified: Sun Nov 19 22:26:27 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
312
eo/tutorial/html/FirstBitGA.html
Normal file
312
eo/tutorial/html/FirstBitGA.html
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
<!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.76 [en] (X11; U; Linux 2.2.17-21mdksmp i686) [Netscape]">
|
||||
<title>FirstBitGA.html</title>
|
||||
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
|
||||
</head>
|
||||
<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
|
||||
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
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Code for FirstBitGA</font></h1></center>
|
||||
Click on the figure to see the corresponding code.
|
||||
<br>In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a>
|
||||
<br>The actual code is in boldface and the comment in normal face.
|
||||
<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>
|
||||
<br><a NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// FirstBitGA.cpp</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">//*</font></tt>
|
||||
<br><tt><font color="#993300">// An instance of a VERY simple Bitstring
|
||||
Genetic Algorithm</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"><b>#include <stdexcept> </b>// runtime_error </font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <iostream>
|
||||
</b>// cout</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <strstream> </b>// ostrstream,
|
||||
istrstream</font></tt>
|
||||
<br><tt><font color="#993300">// the general include for eo</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <eo></font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#999900">#include <ga.h></font></tt></b><br>
|
||||
<tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#999900">// define your individuals</font></tt>
|
||||
<br><tt><font color="#999900"><b>typedef eoBit<double> Indi;
|
||||
</b>// A bitstring with fitness double</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<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">// @param _indi A biststring individual</font></tt>
|
||||
<br><a NAME="evalfunc"></a><b><tt><font color="#CC0000">double binary_value(const
|
||||
Indi & _indi)</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000">{</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000"> double sum = 0;</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000"> for (unsigned i = 0; i < _indi.size();
|
||||
i++)</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000"> sum += _indi[i];</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000"> return sum;</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000">}</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> </b>// all parameters are hard-coded!</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int SEED = 42;
|
||||
</b>// seed for random number generator</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int T_SIZE = 3;
|
||||
</b>// size for tournament selection</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int VEC_SIZE = 8;
|
||||
</b>// Number of bits in genotypes</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int POP_SIZE = 20;
|
||||
</b>// Size of population</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int MAX_GEN = 100;
|
||||
</b>// Maximum number of generation before STOP</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const float CROSS_RATE = 0.8;
|
||||
</b>// Crossover rate</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double P_MUT_PER_BIT = 0.01;
|
||||
</b>// probability of bit-flip mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const float MUT_RATE = 1.0;
|
||||
</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> </b>// Random seed</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>//////////////////////////</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>//reproducible random seed:
|
||||
if you don't change SEED above, </font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>// you'll aways get the same
|
||||
result, NOT a random run</font></tt>
|
||||
<br><b><tt><font color="#993300"> 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> </b>/////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Fitness function</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Evaluation: from a plain
|
||||
C++ fn to an EvalFunc Object</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> eoEvalFuncPtr<Indi> eval(
|
||||
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> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// Initilisation of population</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// declare the population</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPop<Indi> pop;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// fill it!</font></tt>
|
||||
<br><b><tt><font color="#993399"> for (unsigned int igeno=0; igeno<POP_SIZE;
|
||||
igeno++)</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> {</font></tt></b>
|
||||
<br><tt><font color="#993399"><b>
|
||||
Indi v;
|
||||
</b>// void individual, to be filled</font></tt>
|
||||
<br><b><tt><font color="#993399">
|
||||
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)</font></tt></b>
|
||||
<br><b><tt><font color="#993399">
|
||||
{</font></tt></b>
|
||||
<br><tt><font color="#993399"><b>
|
||||
bool r = rng.flip(); </b>// new value, random in {0,1}</font></tt>
|
||||
<br><tt><font color="#993399"><b>
|
||||
v.push_back(r); </b>//
|
||||
append that random value to v</font></tt>
|
||||
<br><b><tt><font color="#993399">
|
||||
}</font></tt></b>
|
||||
<br><tt><font color="#993399"><b>
|
||||
eval(v);
|
||||
</b>// evaluate it</font></tt>
|
||||
<br><b><tt><font color="#993399">
|
||||
pop.push_back(v);
|
||||
</font></tt></b><tt><font color="#993399">// and put it in the population</font></tt>
|
||||
<br><b><tt><font color="#993399"> }</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> </b>// sort pop before printing
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Print (sorted) intial population
|
||||
(raw printout)</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> cout << "Initial Population"
|
||||
<< endl;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << 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> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// selection and replacement</font></tt>
|
||||
<br><tt><font color="#009900"><b> </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> </b>// The robust tournament selection</font></tt>
|
||||
<br><tt><font color="#009900"><b> eoDetTournamentSelect<Indi> select(T_SIZE);
|
||||
</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> </b>// The simple GA evolution engine
|
||||
uses generational replacement</font></tt>
|
||||
<br><tt><font color="#009900"><b> </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> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// The variation operators</font></tt>
|
||||
<br><tt><font color="#993399"><b> </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> </b>// 1-point crossover for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eo1PtBitXover<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>
|
||||
<td>
|
||||
<br><tt><font color="#993399"><b> </b>// standard bit-flip mutation
|
||||
for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBitMutation<Indi> mutation(P_MUT_PER_BIT);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// termination condition</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// stop after MAX_GEN generations</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoGenContinue<Indi> continuator(MAX_GEN);</font></tt></b>
|
||||
<br> </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> </b>/////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// the algorithm</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// standard Generational GA
|
||||
requires as parameters</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// selection, evaluation, crossover
|
||||
and mutation, stopping criterion</font></tt>
|
||||
<p><b><tt><font color="#FF6666"> eoSGA<Indi> gga(select, xover,
|
||||
CROSS_RATE, mutation, MUT_RATE, </font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
eval, continuator);</font></tt></b>
|
||||
<br><tt><font color="#FF6666"><b> </b>// Apply algo to pop - that's
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> gga(pop);</font></tt></b>
|
||||
<br> </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> </b>// Print (sorted) intial population</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << "FINAL Population\n"
|
||||
<< pop << endl;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="main"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993300">}</font></tt></b>
|
||||
<br><tt><font color="#993300">// A main that catches the exceptions</font></tt>
|
||||
<br><b><tt><font color="#993300">int main(int argc, char **argv)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#ifdef _MSC_VER</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b>// rng.reseed(42);</font></tt>
|
||||
<br><b><tt><font color="#993300"> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> flag
|
||||
|= _CRTDBG_LEAK_CHECK_DF;</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> _CrtSetDbgFlag(flag);</font></tt></b>
|
||||
<br><tt><font color="#993300">// _CrtSetBreakAlloc(100);</font></tt>
|
||||
<br><b><tt><font color="#993300">#endif</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> try</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
main_function(argc, argv);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> catch(exception&
|
||||
e)</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
cout << "Exception: " << e.what() << '\n';</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> return 1;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b></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">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
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Sun Nov
|
||||
19 08:31:26 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
354
eo/tutorial/html/FirstRealEA.html
Normal file
354
eo/tutorial/html/FirstRealEA.html
Normal file
|
|
@ -0,0 +1,354 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
|
||||
<title>FirstRealEA.cpp</title>
|
||||
</head>
|
||||
<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
|
||||
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
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">FirstRealEA.cpp</font></h1></center>
|
||||
Click on the figure to see the corresponding code.
|
||||
<br>In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a>
|
||||
<br>The actual code is in boldface and the comment in normal face.
|
||||
<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>
|
||||
<br><a NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// FirstRealEA.cpp</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">//*</font></tt>
|
||||
<br><tt><font color="#993300">// Still an instance of a VERY simple Real-coded
|
||||
Genetic Algorithm </font></tt>
|
||||
<br><tt><font color="#993300">// (see FirstBitGA.cpp) but now with
|
||||
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"><b>#include <stdexcept> </b>// runtime_error </font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <iostream>
|
||||
</b>// cout</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <strstream> </b>// ostrstream,
|
||||
istrstream</font></tt>
|
||||
<br><tt><font color="#993300">// the general include for eo</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <eo></font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900"><b>#include <es.h></b></font></tt><br>
|
||||
<tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#999900">// define your individuals</font></tt>
|
||||
<br><b><tt><font color="#999900">typedef eoReal<double> Indi; </font></tt></b></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 euclidian norm of a real vector</font></tt>
|
||||
<br><tt><font color="#CC0000">// Now in a separate file, and declared as
|
||||
binary_value(const vector<bool> &)</font></tt>
|
||||
<br><b><tt><font color="#CC0000">#include "real_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> const unsigned int SEED = 42; </b>//
|
||||
seed for random number generator</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int T_SIZE = 3; </b>//
|
||||
size for tournament selection</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int VEC_SIZE = 8;
|
||||
</b>// Number of object variables in genotypes</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int POP_SIZE = 20;
|
||||
</b>// Size of population</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int MAX_GEN = 500;
|
||||
</b>// Maximum number of generation before STOP</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int MIN_GEN = 10;
|
||||
</b>// Minimum number of generation before ...</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const unsigned int STEADY_GEN =
|
||||
50; </b>// stop after STEADY_GEN gen. without improvelent</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const float P_CROSS = 0.8; </b>//
|
||||
Crossover probability</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const float P_MUT = 0.5; </b>//
|
||||
mutation probability</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double EPSILON = 0.01; </b>//
|
||||
range for real uniform mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"> <b>double
|
||||
SIGMA = 0.3; </b> // std dev.
|
||||
for normal mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// some parameters for chosing
|
||||
among different operators</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double hypercubeRate = 0.5;
|
||||
</b>// relative weight for hypercube Xover</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double segmentRate = 0.5;
|
||||
</b>// relative weight for segment Xover</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double uniformMutRate = 0.5;
|
||||
</b>// relative weight for uniform mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> const double detMutRate = 0.5;
|
||||
</b>// relative weight for det-uniform mutation</font></tt>
|
||||
<br><tt><font color="#3366FF"> <b>const double normalMutRate = 0.5;</b>
|
||||
// relative weight for normal 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> </b>//////////////////////////</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>// Random seed</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>//////////////////////////</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>//reproducible random seed:
|
||||
if you don't change SEED above, </font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>// you'll aways get the same
|
||||
result, NOT a random run</font></tt>
|
||||
<br><b><tt><font color="#993300"> 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> </b>/////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Fitness function</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Evaluation: from a plain
|
||||
C++ fn to an EvalFunc Object</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// you need to give the full
|
||||
description of the function</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> eoEvalFuncPtr<Indi, double, const
|
||||
vector<double>& > eval( real_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> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// Initilisation of population</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// based on a uniform generator</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoInitFixedLength<Indi, uniform_generator<double>
|
||||
></font></tt></b>
|
||||
<br><b><tt><font color="#993399">
|
||||
random(VEC_SIZE, uniform_generator<double>(-1.0, 1.0));</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Initialization of
|
||||
the population</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPop<Indi> pop(POP_SIZE, random);</font></tt></b>
|
||||
<p><tt><font color="#993399"><b> </b>// and evaluate it in one loop</font></tt>
|
||||
<br><tt><font color="#993399"><b> apply<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> </b>// sort pop before printing
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Print (sorted) intial population
|
||||
(raw printout)</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> cout << "Initial Population"
|
||||
<< endl;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << 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> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// selection and replacement</font></tt>
|
||||
<br><tt><font color="#009900"><b> </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> </b>// The robust tournament selection</font></tt>
|
||||
<br><b><tt><font color="#009900"> eoDetTournamentSelect<Indi> selectOne(T_SIZE);</font></tt></b>
|
||||
<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> eoSelectPerc<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> </b>// And we now have the full
|
||||
slection/replacement - though with </font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// no replacement (== generational
|
||||
replacement) at the moment :-)</font></tt>
|
||||
<br><b><tt><font color="#009900"> eoNoReplacement<Indi> replace; </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> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// The variation operators</font></tt>
|
||||
<br><tt><font color="#993399"><b> </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> </b>// uniform chooce on segment
|
||||
made by the parents</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoSegmentCrossover<Indi> xoverS;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// uniform choice in hypercube
|
||||
built by the parents</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoHypercubeCrossover<Indi> xoverA;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Combine them with relative
|
||||
weights</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPropCombinedQuadOp<Indi> xover(xoverS,
|
||||
segmentRate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> xover.add(xoverA, hypercubeRate,
|
||||
true);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="mutation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<br><tt><font color="#993399"><b> </b>// offspring(i) uniformly chosen
|
||||
in [parent(i)-epsilon, parent(i)+epsilon]</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoUniformMutation<Indi>
|
||||
mutationU(EPSILON); </font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// k (=1) coordinates of parents
|
||||
are uniformly modified</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoDetUniformMutation<Indi>
|
||||
mutationD(EPSILON); </font></tt></b>
|
||||
<br><tt><font color="#993399"> // all coordinates of parents are normally
|
||||
modified (stDev SIGMA)</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoNormalMutation<Indi>
|
||||
mutationN(SIGMA); </font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Combine them with relative
|
||||
weights</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPropCombinedMonOp<Indi> mutation(mutationU,
|
||||
uniformMutRate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> mutation.add(mutationD, detMutRate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> mutation.add(mutationN, normalMutRate,
|
||||
true);</font></tt></b>
|
||||
<p><tt><font color="#993399"><b> </b>// The operators are encapsulated
|
||||
into an eoTRansform object</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoSGATransform<Indi> transform(xover,
|
||||
P_CROSS, mutation, P_MUT);</font></tt></b></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="checkpoint"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// termination conditions: use
|
||||
more than one</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// stop after MAX_GEN generations</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoGenContinue<Indi> genCont(MAX_GEN);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// do MIN_GEN gen., then stop
|
||||
after STEADY_GEN gen. without improvement</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoSteadyFitContinue<Indi> steadyCont(MIN_GEN,
|
||||
STEADY_GEN);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// stop when fitness reaches
|
||||
a target (here VEC_SIZE)</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoFitContinue<Indi> fitCont(0);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// do stop when one of the above
|
||||
says so</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoCombinedContinue<Indi> continuator(genCont);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> continuator.add(steadyCont);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> continuator.add(fitCont);</font></tt></b></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> </b>/////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// the algorithm</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// Easy EA requires </font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// selection, transformation,
|
||||
eval, replacement, and stopping criterion</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> eoEasyEA<Indi> gga(continuator,
|
||||
eval, select, transform, replace);</font></tt></b>
|
||||
<br><tt><font color="#FF6666"><b> </b>// Apply algo to pop - that's
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> cout << "\n
|
||||
Here we go\n\n";</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666"> gga(pop);</font></tt></b>
|
||||
<br> </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> </b>// Print (sorted) intial population</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << "FINAL Population\n"
|
||||
<< pop << endl;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993300">}</font></tt></b>
|
||||
<br><tt><font color="#993300">// A main that catches the exceptions</font></tt>
|
||||
<br><b><tt><font color="#993300">int main(int argc, char **argv)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#ifdef _MSC_VER</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b>// rng.reseed(42);</font></tt>
|
||||
<br><b><tt><font color="#993300"> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> flag
|
||||
|= _CRTDBG_LEAK_CHECK_DF;</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> _CrtSetDbgFlag(flag);</font></tt></b>
|
||||
<br><tt><font color="#993300">// _CrtSetBreakAlloc(100);</font></tt>
|
||||
<br><b><tt><font color="#993300">#endif</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> try</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
main_function(argc, argv);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> catch(exception&
|
||||
e)</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
cout << "Exception: " << e.what() << '\n';</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> return 1;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<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
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Wed Nov
|
||||
29 07:38:36 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
350
eo/tutorial/html/FirstRealGA.html
Normal file
350
eo/tutorial/html/FirstRealGA.html
Normal file
|
|
@ -0,0 +1,350 @@
|
|||
<!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="cpp2html Marc Schoenauer">
|
||||
<title>FirstRealGA.html</title>
|
||||
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
|
||||
</head>
|
||||
<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
|
||||
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
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Code for FirstRealGA</font></h1></center>
|
||||
Click on the figure to see the corresponding code.<br>
|
||||
In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a><br>
|
||||
The actual code is in boldface and the comment in normal face.
|
||||
<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>
|
||||
<br>
|
||||
<A NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// FirstRealGA.cpp<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
//*<br>
|
||||
// An instance of a VERY simple Real-coded Genetic Algorithm<br>
|
||||
//<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// standard includes<br>
|
||||
<b>#include <stdexcept> </b>// runtime_error <br>
|
||||
<b>#include <iostream> </b>// cout<br>
|
||||
<b>#include <strstream> </b>// ostrstream, istrstream<br>
|
||||
// the general include for eo<br>
|
||||
<b>#include <eo></b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
<b>#include <es.h></b><br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// define your individuals<br>
|
||||
<b> typedef eoReal<double> Indi;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#CC0000">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// a simple fitness function that computes the euclidian norm of a real vector<br>
|
||||
// @param _indi A real-valued individual <br>
|
||||
<a name="evalfunc"></a>
|
||||
<b>double real_value(const Indi & _indi)</b><br>
|
||||
<b>{</b><br>
|
||||
<b> double sum = 0;</b><br>
|
||||
<b> for (unsigned i = 0; i < _indi.size(); i++)</b><br>
|
||||
<b> sum += _indi[i]*_indi[i];</b><br>
|
||||
<b> return (-sum); </b>// maximizing only<br>
|
||||
<b>}</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">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
<b>void main_function(int argc, char **argv)</b><br>
|
||||
<b>{</b><br>
|
||||
</font></tt>
|
||||
</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> </b>// all parameters are hard-coded!<br>
|
||||
<b> const unsigned int SEED = 42; </b>// seed for random number generator<br>
|
||||
<b> const unsigned int VEC_SIZE = 8; </b>// Number of object variables in genotypes<br>
|
||||
<b> const unsigned int POP_SIZE = 20; </b>// Size of population<br>
|
||||
<b> const unsigned int T_SIZE = 3; </b>// size for tournament selection<br>
|
||||
<b> const unsigned int MAX_GEN = 500; </b>// Maximum number of generation before STOP<br>
|
||||
<b> const float CROSS_RATE = 0.8; </b>// Crossover rate<br>
|
||||
<b> const double EPSILON = 0.01; </b>// range for real uniform mutation<br>
|
||||
<b> const float MUT_RATE = 0.5; </b>// mutation rate<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">
|
||||
<a NAME="random"></a>
|
||||
<b> </b>//////////////////////////<br>
|
||||
<b> </b>// Random seed<br>
|
||||
<b> </b>//////////////////////////<br>
|
||||
<b> </b>//reproducible random seed: if you don't change SEED above, <br>
|
||||
<b> </b>// you'll aways get the same result, NOT a random run<br>
|
||||
<b> rng.reseed(SEED);</b><br>
|
||||
</font></tt>
|
||||
</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> </b>/////////////////////////////<br>
|
||||
<b> </b>// Fitness function<br>
|
||||
<b> </b>////////////////////////////<br>
|
||||
<b> </b>// Evaluation: from a plain C++ fn to an EvalFunc Object<br>
|
||||
<b> eoEvalFuncPtr<Indi> eval( real_value );</b><br>
|
||||
</font></tt>
|
||||
</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> </b>////////////////////////////////<br>
|
||||
<b> </b>// Initilisation of population<br>
|
||||
<b> </b>////////////////////////////////<br>
|
||||
<b> </b>// declare the population<br>
|
||||
<b> eoPop<Indi> pop;</b><br>
|
||||
<b> </b>// fill it!<br>
|
||||
<b> for (unsigned int igeno=0; igeno<POP_SIZE; igeno++)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> Indi v; </b>// void individual, to be filled<br>
|
||||
<b> for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> double r = 2*rng.uniform() - 1; </b>// new value, random in [-1,1)<br>
|
||||
<b> v.push_back(r); </b>// append that random value to v<br>
|
||||
<b> }</b><br>
|
||||
<b> eval(v); </b>// evaluate it<br>
|
||||
<b> pop.push_back(v); </b>// and put it in the population<br>
|
||||
<b> }</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> </b>// sort pop before printing it!<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> </b>// Print (sorted) intial population (raw printout)<br>
|
||||
<b> cout << "Initial Population" << endl;</b><br>
|
||||
<b> cout << 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> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// selection and replacement<br>
|
||||
<b> </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> </b>// The robust tournament selection<br>
|
||||
<b> eoDetTournamentSelect<Indi> select(T_SIZE); </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> </b>// eoSGA uses generational replacement by default<br>
|
||||
<b> </b>// so no replacement procedure has to be given<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> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// termination condition<br>
|
||||
<b> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// stop after MAX_GEN generations<br>
|
||||
<b> eoGenContinue<Indi> continuator(MAX_GEN);</b><br>
|
||||
<b> </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> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// The variation operators<br>
|
||||
<b> </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> </b>// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]<br>
|
||||
<b> eoUniformMutation<Indi> mutation(EPSILON); </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> </b>// offspring(i) is a linear combination of parent(i)<br>
|
||||
<b> eoSegmentCrossover<Indi> xover;</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> </b>/////////////////////////////////////////<br>
|
||||
<b> </b>// the algorithm<br>
|
||||
<b> </b>////////////////////////////////////////<br>
|
||||
<b> </b>// standard Generational GA requires<br>
|
||||
<b> </b>// selection, evaluation, crossover and mutation, stopping criterion<br>
|
||||
<b> </b><br>
|
||||
<b> eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE, </b><br>
|
||||
<b> eval, continuator);</b><br>
|
||||
<b> </b>// Apply algo to pop - that's it!<br>
|
||||
<b> gga(pop);</b><br>
|
||||
<b> </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> </b>// Print (sorted) intial population<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> cout << "FINAL Population\n" << pop << 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>
|
||||
// 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> </b>// rng.reseed(42);<br>
|
||||
<b> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</b><br>
|
||||
<b> flag |= _CRTDBG_LEAK_CHECK_DF;</b><br>
|
||||
<b> _CrtSetDbgFlag(flag);</b><br>
|
||||
// _CrtSetBreakAlloc(100);<br>
|
||||
<b>#endif</b><br>
|
||||
<b> try</b><br>
|
||||
<b> {</b><br>
|
||||
<b> main_function(argc, argv);</b><br>
|
||||
<b> }</b><br>
|
||||
<b> catch(exception& e)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> cout << "Exception: " << e.what() << '\n';</b><br>
|
||||
<b> }</b><br>
|
||||
<b> return 1;</b><br>
|
||||
<b>}</b><br>
|
||||
</font></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">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
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last
|
||||
modified: Sun Nov 19 08:31:29 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
286
eo/tutorial/html/Firstmerge.html
Normal file
286
eo/tutorial/html/Firstmerge.html
Normal file
|
|
@ -0,0 +1,286 @@
|
|||
<!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">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
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 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
|
||||
<stdexcept ></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">#include <iostream></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">#include <strstream></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">#include <eo></font></font></td>
|
||||
|
||||
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#993300">#include
|
||||
<stdexcept ></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">#include <iostream></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#993300">#include <strstream></font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">#include <eo></font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#FFFF00">#include <es.h><br>
|
||||
typedef eoReal<double> Indi;</font></font></td>
|
||||
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#FFFF00">#include <ga.h><br>
|
||||
typedef eoBit<double> Indi;</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC0000">double
|
||||
real_value(const Indi & _indi)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000">{</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000"> double
|
||||
sum = 0;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000"> for (unsigned
|
||||
i = 0; i < _indi.size(); i++)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000">
|
||||
sum += _indi[i]*_indi[i];</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000"> return
|
||||
(-sum); // 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 & _indi)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000">{</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000"> double
|
||||
sum = 0;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000"> for (unsigned
|
||||
i = 0; i < _indi.size(); i++)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000">
|
||||
sum += _indi[i];</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC0000"> 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<Indi>
|
||||
eval(real_value);</font></font></td>
|
||||
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC0000">eoEvalFuncPtr<Indi>
|
||||
eval(binary_value);</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#CC33CC">eoPop<Indi>
|
||||
pop;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">for (unsigned
|
||||
int igeno=0; igeno<POP_SIZE; igeno++)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC"> {</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
Indi v;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
{</font></font></td>
|
||||
|
||||
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#CC33CC">eoPop<Indi>
|
||||
pop;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">for (unsigned
|
||||
int igeno=0; igeno<POP_SIZE; igeno++)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC"> {</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
Indi v;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
{</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
double r = 2*rng.uniform() - 1;</font></font></td>
|
||||
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
bool r = rng.flip(); </font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
v.push_back(r); //</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
}</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
eval(v);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
pop.push_back(v);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC"> }</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 <<
|
||||
"Initial Population" << endl;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">cout <<
|
||||
pop;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#009900">eoDetTournament<Indi>
|
||||
select(T_SIZE);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">eoGenContinue<Indi>
|
||||
continuator(MAX_GEN);</font></font></td>
|
||||
|
||||
<td BGCOLOR="#C3C2B4"><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
v.push_back(r); //</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
}</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
eval(v);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">
|
||||
pop.push_back(v);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC"> }</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 <<
|
||||
"Initial Population" << endl;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">cout <<
|
||||
pop;</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#009900">eoDetTournament<Indi>
|
||||
select(T_SIZE);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#3366FF">eoGenContinue<Indi>
|
||||
continuator(MAX_GEN);</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">eoUniformMutation<Indi>
|
||||
mutation(EPSILON);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">eoSegmentCrossover<Indi>
|
||||
xover;</font></font></td>
|
||||
|
||||
<td BGCOLOR="#F0C6B7"><font face="Courier New,Courier"><font color="#CC33CC">eoBitMutation<Indi>
|
||||
mutation(P_MUT_PER_BIT);</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#CC33CC">eo1PtBitXover<Indi>
|
||||
xover;</font></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#C3C2B4">
|
||||
<font face="Courier New,Courier"><font color="#FF6666">eoSGA<Indi>
|
||||
gga(select, xover, CROSS_RATE,</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">
|
||||
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 <<
|
||||
"FINAL Population\n" << pop << 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">
|
||||
<font face="Courier New,Courier"><font color="#FF6666">eoSGA<Indi>
|
||||
gga(select, xover, CROSS_RATE,</font></font>
|
||||
<br><font face="Courier New,Courier"><font color="#FF6666">
|
||||
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 <<
|
||||
"FINAL Population\n" << pop << 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">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
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.Schoenauer@inria.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>
|
||||
77
eo/tutorial/html/NoWay.html
Normal file
77
eo/tutorial/html/NoWay.html
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
|
||||
<title>Tutorial: Solutions</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<a href="eoTutorial.html">Tutorial main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> -<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Tutorial:</font></h1></center>
|
||||
|
||||
<center><b><font color="#FF0000"><font size=+2>Solutions of exercises</font></font></b></center>
|
||||
|
||||
<p>No, <b><font color="#33CC00">w</font><font color="#FF9900">e </font><font color="#CC66CC">w</font><font color="#33CCFF">o</font><font color="#FFFF00">n</font><font color="#FF0000">'t</font><font color="#999999">
|
||||
p</font><font color="#999900">r</font><font color="#CC6600">o</font><font color="#993399">v</font><font color="#006600">i</font><font color="#990000">d</font><font color="#867CE9">e
|
||||
</font></b><font color="#000000">any
|
||||
hypertext link directly to the correct code, so</font> you get a chance
|
||||
to find out the solution by yourself without immediately going there
|
||||
:-)))
|
||||
<p><b><font color="#000099"><font size=+2>What you should do:</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
copy the code of an example onto another name (e.g. <b><tt><font color="#660000">mytest.cpp</font></tt></b>)</li>
|
||||
|
||||
<li>
|
||||
edit and modify <b><tt><font color="#660000">mytest.cpp</font></tt></b>
|
||||
according to the corresponding instructions of the exercise</li>
|
||||
|
||||
<li>
|
||||
compile <b><tt><font color="#660000">mytest.cpp</font></tt></b> by typing
|
||||
<b><tt><font color="#FF6666">make
|
||||
mytest</font></tt></b> at system prompt, and you will hopefully get an
|
||||
executable file named <b><tt><font color="#660000">mytest</font></tt></b>
|
||||
(for Unix systems: if eventually someone tells me how to do that in Windows,
|
||||
apart that you'll probably end up with an executable file named <b><tt><font color="#660000">mytest.exe...</font></tt></b>).</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>What you may do later:</font></font></b>
|
||||
<p>All solutions to exercises are in the same<b><font color="#FF6600">
|
||||
sub-dir</font></b> of the Tutorial directory than the example files (i.e.
|
||||
Lesson1 for Lesson1, yes!) and are named <b><tt><font color="#990000">exerciseN.p.cpp</font></tt></b>
|
||||
where N is the lesson number and p the exercise number. Hence you may browse
|
||||
through the code, eventually modifying it, and then simply type, in the
|
||||
corresponding directory,
|
||||
<br><b><tt><font color="#FF6666">... % make exerciseN.p</font></tt></b>
|
||||
<br>which will compile file <b><tt><font color="#660000">exerciseN.p.cpp</font></tt></b>
|
||||
into executable <b><tt><font color="#660000">exerciseN.p</font></tt></b>
|
||||
(for Unix systems: if eventually someone tells me how to do that in Windows,
|
||||
you'll probably end up with an executable file named <b><tt><font color="#660000">exerciseN.p.exe</font></tt></b>).
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>What you may not do:</font></font></b>
|
||||
<center>Complain that it does not work under Windows :-)</center>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoTutorial.html">Tutorial main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> -<b> <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Fri Nov 3 18:49:12 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: Fri Nov 3 18:49:12 CET 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
360
eo/tutorial/html/OneMaxEA.html
Normal file
360
eo/tutorial/html/OneMaxEA.html
Normal file
|
|
@ -0,0 +1,360 @@
|
|||
<!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.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]">
|
||||
<title>Templates/OneMaxEA.cpp</title>
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson5.html">Back to Lesson 5</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Templates/OneMaxEA.cpp</font></h1></center>
|
||||
The places where you have to put some code are on <b><font color="#FF6666">pink
|
||||
background</font></b>.. Only the the <a href="eoTutorial.html#colors">character
|
||||
colors have the usual meaning</a>.
|
||||
<br><a NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">/** -*- mode: c++; c-indent-level:
|
||||
4; c++-member-init-indent: 8; comment-column: 35; -*-</font></tt>
|
||||
<br><tt><font color="#993300">The above line is usefulin Emacs-like editors</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt>
|
||||
<br><tt><font color="#993300">/*</font></tt>
|
||||
<br><tt><font color="#993300">Template for creating a new representation
|
||||
in EO</font></tt>
|
||||
<br><tt><font color="#993300">================================================</font></tt>
|
||||
<br><tt><font color="#993300">This is the template main file.</font></tt>
|
||||
<br><tt><font color="#993300">It includes all other files that have been
|
||||
generated by the script create.sh</font></tt>
|
||||
<br><tt><font color="#993300">so it is the only file to compile.</font></tt>
|
||||
<br><tt><font color="#993300">In case you want to build up a separate library
|
||||
for your new Evolving Object,</font></tt>
|
||||
<br><tt><font color="#993300">you'll need some work - follow what's done
|
||||
in the src/ga dir, used in the</font></tt>
|
||||
<br><tt><font color="#993300">main file BitEA in tutorial/Lesson4 dir.</font></tt>
|
||||
<br><tt><font color="#993300">Or you can wait until we do it :-)</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt>
|
||||
<br><tt><font color="#993300">// Miscilaneous include and declaration </font></tt>
|
||||
<br><b><tt><font color="#993300">#include <iostream></font></tt></b>
|
||||
<br><b><tt><font color="#993300">using namespace std;</font></tt></b>
|
||||
<br><tt><font color="#993300">// eo general include</font></tt>
|
||||
<br><b><tt><font color="#993300">#include "eo"</font></tt></b>
|
||||
<br><tt><font color="#993300">// the real bounds (not yet in general eo
|
||||
include)</font></tt>
|
||||
<br><b><tt><font color="#993300">#include "utils/eoRealVectorBounds.h"</font></tt></b>
|
||||
<br><tt><font color="#993300">// include here whatever specific files for
|
||||
your representation</font></tt>
|
||||
<br><tt><font color="#993300">// Basically, this should include at least
|
||||
the following</font></tt>
|
||||
<br><tt><font color="#993300">/** definition of representation: </font></tt>
|
||||
<br><tt><font color="#993300">* class eoOneMax MUST derive from EO<FitT>
|
||||
for some fitness</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#999900">#include "eoOneMax.h"</font></tt></b>
|
||||
<br><tt><font color="#999900">/** definition of initilizqtion: </font></tt>
|
||||
<br><tt><font color="#999900">* class eoOneMaxInit MUST derive from eoInit<eoOneMax></font></tt>
|
||||
<br><tt><font color="#999900">*/</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399">#include "eoOneMaxInit.h"</font></tt></b>
|
||||
<br><tt><font color="#993399">/** definition of evaluation: </font></tt>
|
||||
<br><tt><font color="#993399">* class eoOneMaxEvalFunc MUST derive from
|
||||
eoEvalFunc<eoOneMax></font></tt>
|
||||
<br><tt><font color="#993399">* and should test for validity before doing
|
||||
any computation</font></tt>
|
||||
<br><tt><font color="#993399">* see tutorial/Templates/evalFunc.tmpl</font></tt>
|
||||
<br><tt><font color="#993399">*/</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="fitness"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#CC0000">#include "eoOneMaxEvalFunc.h"</font></tt></b>
|
||||
<br><tt><font color="#CC0000">// GENOTYPE eoOneMax ***MUST***
|
||||
be templatized over the fitness</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000">// START fitness type: double or eoMaximizingFitness
|
||||
if you are maximizing</font></tt>
|
||||
<br><tt><font color="#CC0000">//
|
||||
eoMinimizingFitness if you are minimizing</font></tt>
|
||||
<br><tt><font color="#CC0000"><b>typedef eoMinimizingFitness MyFitT ; </b>//
|
||||
type of fitness </font></tt>
|
||||
<br><tt><font color="#CC0000">// END fitness type</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900">// Then define your EO objects using that
|
||||
fitness type</font></tt>
|
||||
<br><tt><font color="#999900"><b>typedef eoOneMax<MyFitT> Indi; </b>
|
||||
// ***MUST*** derive from EO </font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399">// create an initializer</font></tt>
|
||||
<br><b><tt><font color="#993399">#include "make_genotype_OneMax.h"</font></tt></b>
|
||||
<br><b><tt><font color="#993399">eoInit<Indi> & make_genotype(eoParser&
|
||||
_parser, eoState&_state, Indi _eo)</font></tt></b>
|
||||
<br><b><tt><font color="#993399">{</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> return do_make_genotype(_parser,
|
||||
_state, _eo);</font></tt></b>
|
||||
<br><b><tt><font color="#993399">} </font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399">// and the variation operaotrs</font></tt>
|
||||
<br><b><tt><font color="#993399">#include "make_op_OneMax.h"</font></tt></b>
|
||||
<br><b><tt><font color="#993399">eoGenOp<Indi>& make_op(eoParser&
|
||||
_parser, eoState& _state, eoInit<Indi>& _init)</font></tt></b>
|
||||
<br><b><tt><font color="#993399">{</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> return do_make_op(_parser, _state,
|
||||
_init);</font></tt></b>
|
||||
<br><b><tt><font color="#993399">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399">// Use existing modules to define representation
|
||||
independent routines</font></tt>
|
||||
<br><tt><font color="#993399">// These are parser-based definitions of
|
||||
objects</font></tt>
|
||||
<br><tt><font color="#993399">// how to initialize the population </font></tt>
|
||||
<br><tt><font color="#993399">// it IS representation independent if an
|
||||
eoInit is given</font></tt>
|
||||
<br><b><tt><font color="#993399">#include <do/make_pop.h></font></tt></b>
|
||||
<br><b><tt><font color="#993399">eoPop<Indi >& make_pop(eoParser&
|
||||
_parser, eoState& _state, eoInit<Indi> & _init)</font></tt></b>
|
||||
<br><b><tt><font color="#993399">{</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> return do_make_pop(_parser, _state,
|
||||
_init);</font></tt></b>
|
||||
<br><b><tt><font color="#993399">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF">// the stopping criterion</font></tt>
|
||||
<br><b><tt><font color="#3366FF">#include <do/make_continue.h></font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">eoContinue<Indi>& make_continue(eoParser&
|
||||
_parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval)</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">{</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> return do_make_continue(_parser,
|
||||
_state, _eval);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stat"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF">// outputs (stats, population dumps, ...)</font></tt>
|
||||
<br><b><tt><font color="#3366FF">#include <do/make_checkpoint.h></font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">eoCheckPoint<Indi>& make_checkpoint(eoParser&
|
||||
_parser, eoState& _state, eoEvalFuncCounter<Indi>& _eval, eoContinue<Indi>&
|
||||
_continue) </font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">{</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> return do_make_checkpoint(_parser,
|
||||
_state, _eval, _continue);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="engine"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900">// evolution engine (selection and replacement)</font></tt>
|
||||
<br><b><tt><font color="#009900">#include <do/make_algo_scalar.h></font></tt></b>
|
||||
<br><b><tt><font color="#009900">eoAlgo<Indi>& make_algo_scalar(eoParser&
|
||||
_parser, eoState& _state, eoEvalFunc<Indi>& _eval, eoContinue<Indi>&
|
||||
_continue, eoGenOp<Indi>& _op)</font></tt></b>
|
||||
<br><b><tt><font color="#009900">{</font></tt></b>
|
||||
<br><b><tt><font color="#009900"> return do_make_algo_scalar(_parser,
|
||||
_state, _eval, _continue, _op);</font></tt></b>
|
||||
<br><b><tt><font color="#009900">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993300">// simple call to the algo. stays there for
|
||||
consistency reasons </font></tt>
|
||||
<br><tt><font color="#993300">// no template for that one</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <do/make_run.h></font></tt></b>
|
||||
<br><tt><font color="#993300">// the instanciating fitnesses</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <eoScalarFitness.h></font></tt></b>
|
||||
<br><b><tt><font color="#993300">void run_ea(eoAlgo<Indi>& _ga,
|
||||
eoPop<Indi>& _pop)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> do_run(_ga, _pop);</font></tt></b>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b>
|
||||
<br><tt><font color="#993300">// checks for help demand, and writes the
|
||||
status file</font></tt>
|
||||
<br><tt><font color="#993300">// and make_help; in libutils</font></tt>
|
||||
<br><b><tt><font color="#993300">void make_help(eoParser & _parser);</font></tt></b>
|
||||
<br><tt><font color="#993300">// now use all of the above, + representation
|
||||
dependent things</font></tt>
|
||||
<br><b><tt><font color="#993300">int main(int argc, char* argv[])</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> try</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> eoParser parser(argc, argv); </b>
|
||||
// for user-parameter reading</font></tt>
|
||||
<br><tt><font color="#993300"><b> eoState state; </b>
|
||||
// keeps all things allocated</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000"><b> </b> //
|
||||
The fitness</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b> //////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> eoOneMaxEvalFunc<Indi>
|
||||
plainEval</b> /* (varType _anyVariable) */;<b>;</b></font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b> // turn that object
|
||||
into an evaluation counter</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> eoEvalFuncCounter<Indi>
|
||||
eval(plainEval);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900"><b> </b> // the genotype - through a
|
||||
genotype initializer</font></tt>
|
||||
<br><b><tt><font color="#999900"> eoInit<Indi>& init = make_genotype(parser,
|
||||
state, Indi());</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b> // Build the variation operator
|
||||
(any seq/prop construct)</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoGenOp<Indi>& op = make_op(parser,
|
||||
state, init);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b> //// Now the representation-independent
|
||||
things </font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // YOU SHOULD NOT NEED TO MODIFY
|
||||
ANYTHING BEYOND THIS POINT</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // unless you want to add specific
|
||||
statistics to the checkpoint</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //////////////////////////////////////////////</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b> // initialize the population</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // yes, this is representation
|
||||
indepedent once you have an eoInit</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPop<Indi>& pop
|
||||
= make_pop(parser, state, init);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b> // stopping criteria</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoContinue<Indi> & term =
|
||||
make_continue(parser, state, eval);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b> // output</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoCheckPoint<Indi> & checkpoint
|
||||
= make_checkpoint(parser, state, eval, term);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993300"><b> </b> // algorithm (need the operator!)</font></tt>
|
||||
<br><b><tt><font color="#993300"> eoAlgo<Indi>& ga = make_algo_scalar(parser,
|
||||
state, eval, checkpoint, op);</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b> ///// End of construction of
|
||||
the algorithm</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b> /////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b> // to be called AFTER all parameters
|
||||
have been read!!!</font></tt>
|
||||
<br><b><tt><font color="#993300"> make_help(parser);</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b> //// GO</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b> ///////</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000"><b> </b> // evaluate intial population
|
||||
AFTER help and status in case it takes time</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> apply<Indi>(eval, pop);</font></tt></b>
|
||||
<br><tt><font color="#CC0000"><b> </b> // if you want to print it
|
||||
out</font></tt>
|
||||
<br><tt><font color="#CC0000">// cout << "Initial
|
||||
Population\n";</font></tt>
|
||||
<br><tt><font color="#CC0000">// pop.sortedPrintOn(cout);</font></tt>
|
||||
<br><tt><font color="#CC0000">// cout << endl;</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993300"><b> run_ea(ga, pop); </b>// run the
|
||||
ga</font></tt>
|
||||
<br><b><tt><font color="#993300"> cout << "Final Population\n";</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> pop.sortedPrintOn(cout);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> cout << endl;</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> catch(exception& e)</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> cout <<
|
||||
e.what() << endl;</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> return 0;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson5.html">Back to Lesson 5</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:marc.schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Sat May
|
||||
4 07:37:41 2002<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
569
eo/tutorial/html/SecondBitEA.html
Normal file
569
eo/tutorial/html/SecondBitEA.html
Normal file
|
|
@ -0,0 +1,569 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
|
||||
<title>SecondBitEA.cpp</title>
|
||||
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson3.html">Back to Lesson 3</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
</a>-
|
||||
<a href="eoProgramming.html">Programming
|
||||
hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">SecondBitEA.cpp</font></h1></center>
|
||||
Click on the figure to see the corresponding code.
|
||||
<br>In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a>
|
||||
<br>The actual code is in boldface and the comment in normal face.
|
||||
<p>For this particular program, as all new lines are concerned with program
|
||||
parameter input and information output, the <font color="#FF6600">font
|
||||
color</font> for program-parameter-related sections will <font color="#FF6600">refer
|
||||
to the section where the parameters are used</font> whereas the background
|
||||
color will remain blue.
|
||||
<p><img SRC="EA_tutorial.jpg" USEMAP="#Map" ><map NAME="Map"><!-- Init --><area SHAPE="rect" HREF="#init" COORDS="14,31,135,70"><area SHAPE="rect" HREF="#eval" COORDS="14,110,135,150"><!-- main loop --><area SHAPE="rect" HREF="#representation" COORDS="170,110,295,150"><area SHAPE="rect" HREF="#output" COORDS="280,45,480,70"><area SHAPE="rect" HREF="#stop" COORDS="348,110,430,150"><area SHAPE="rect" HREF="#select" COORDS="495,110,615,150"><area SHAPE="rect" HREF="#representation" COORDS="495,190,615,230"><area SHAPE="rect" HREF="#crossover" COORDS="495,265,625,287"><area SHAPE="rect" HREF="#mutation" COORDS="495,287,625,305"><area SHAPE="rect" HREF="#representation" COORDS="240,270,465,310"><area SHAPE="rect" HREF="#eval" COORDS="170,270,295,310"><area SHAPE="rect" HREF="#replace" COORDS="170,190,295,230"><!-- Center of loop --><area SHAPE="rect" HREF="#generation" COORDS="310,160,485,260"><!-- 4 bottom lines --><area SHAPE="rect" HREF="#operators" COORDS="15,350,260,370"><area SHAPE="rect" HREF="#representation" COORDS="270,350,460,370"><area SHAPE="rect" HREF="#engine" COORDS="15,377,400,397"><area SHAPE="rect" HREF="#eval" COORDS="15,403,230,423"><area SHAPE="rect" HREF="#checkpoint" COORDS="15,430,221,450"><area SHAPE="rect" HREF="#stop" COORDS="221,430,345,450"><area SHAPE="rect" HREF="#stat" COORDS="375,430,445,450"><area SHAPE="rect" HREF="#parametres" COORDS="0,358,278,378"></map>
|
||||
<br><a NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// SecondGA.cpp</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">//*</font></tt>
|
||||
<br><tt><font color="#993300">// Same code than FirstBitEA as far as Evolutionary
|
||||
Computation is concerned</font></tt>
|
||||
<br><tt><font color="#993300">// but now you learn to enter the parameters
|
||||
in a more flexible way</font></tt>
|
||||
<br><tt><font color="#993300">// and to twidle the output to your preferences!</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// standard includes</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <stdexcept> </b>// runtime_error </font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <iostream> </b>//
|
||||
cout</font></tt>
|
||||
<br><tt><font color="#993300"><b>#include <strstream> </b>// ostrstream,
|
||||
istrstream</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <fstream></font></tt></b>
|
||||
<br><tt><font color="#993300">// the general include for eo</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <eo></font></tt></b></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">// a simple fitness function that computes
|
||||
the number of ones of a bitstring</font></tt>
|
||||
<br><b><tt><font color="#CC0000">#include "binary_value.h"</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#999900">// define your genotype and fitness types</font></tt>
|
||||
<br><b><tt><font color="#999900">typedef eoBit<double> Indi;</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">// the main_function: nothing changed(!),
|
||||
except variable initialization</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">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#3366FF">// instead of having all values of useful
|
||||
parameters as constants, read them:</font></tt>
|
||||
<br><tt><font color="#3366FF">// either on the command line (--option=value
|
||||
or -o=value)</font></tt>
|
||||
<br><tt><font color="#3366FF">//
|
||||
or in a parameter file (same syntax, order independent, </font></tt>
|
||||
<br><tt><font color="#3366FF">//
|
||||
# = usual comment character </font></tt>
|
||||
<br><tt><font color="#3366FF">//
|
||||
or in the environment (TODO)</font></tt>
|
||||
<p><tt><font color="#3366FF">// First define a parser from the command-line
|
||||
arguments</font></tt>
|
||||
<br><a NAME="parser_declare"></a><b><tt><font color="#3366FF">eoParser
|
||||
parser(argc, argv);</font></tt></b>
|
||||
<p><tt><font color="#3366FF">// For each parameter, define Parameter, read
|
||||
it through the parser,</font></tt>
|
||||
<br><tt><font color="#3366FF">// and assign the value to the variable</font></tt>
|
||||
<br><a NAME="random"></a>
|
||||
<br><b><tt><font color="#990000">eoValueParam<uint32> seedParam(time(0),
|
||||
"seed", "Random number seed", 'S');</font></tt></b>
|
||||
<br><a NAME="seed_process"></a><b><tt><font color="#990000">parser.processParam(
|
||||
seedParam );</font></tt></b>
|
||||
<br><a NAME="seed_assign"></a><b><tt><font color="#990000">unsigned seed
|
||||
= seedParam.value();</font></tt></b>
|
||||
<p><a NAME="_seed_declare"></a><tt><font color="#999900">// decription
|
||||
of genotype</font></tt>
|
||||
<br><b><tt><font color="#999900">eoValueParam<unsigned int>& vecSizeParam(8,
|
||||
"vecSize", "Genotype size",'V');</font></tt></b>
|
||||
<br><b><tt><font color="#999900">parser.processParam( vecSizeParam, "Representation"
|
||||
);</font></tt></b>
|
||||
<br><b><tt><font color="#999900">unsigned vecSize = vecSizeParam.value();</font></tt></b>
|
||||
<p><tt><font color="#009900">// parameters for evolution engine</font></tt>
|
||||
<br><b><tt><font color="#009900">eoValueParam<unsigned int>& popSizeParam(10,
|
||||
"popSize", "Population size",'P');</font></tt></b>
|
||||
<br><b><tt><font color="#009900">parser.processParam( popSizeParam, "Evolution
|
||||
engine" );</font></tt></b>
|
||||
<br><b><tt><font color="#009900">unsigned popSize = popSizeParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#009900">eoValueParam<unsigned int>& tSizeParam(10,
|
||||
"tSize", "Tournament size",'T');</font></tt></b>
|
||||
<br><b><tt><font color="#009900">parser.processParam( seedParam );</font></tt></b>
|
||||
<br><b><tt><font color="#009900">unsigned tSize = tSizeParam.value();</font></tt></b>
|
||||
<br><a NAME="_load_name"></a>
|
||||
<br><tt><font color="#3366FF"><b> </b>// init and stop</font></tt>
|
||||
<br><b><tt><font color="#3366FF">eoValueParam<string> loadNameParam("",
|
||||
"Load","A save file to restart from",'L');</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">parser.processParam( loadNameParam, "Persistence"
|
||||
);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">string loadName = loadNameParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#3366FF">eoValueParam<unsigned int> maxGenParam(100,
|
||||
"maxGen", "Maximum number of generations",'G');</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">parser.processParam( maxGenParam, "Stopping
|
||||
criterion" );</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">unsigned maxGen = maxGenParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#3366FF">eoValueParam<unsigned int> minGenParam(100,
|
||||
"minGen", "Minimum number of generations",'g');</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">parser.processParam( minGenParam, "Stopping
|
||||
criterion" );</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">unsigned minGen = minGenParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#3366FF">eoValueParam<unsigned int> steadyGenParam(100,
|
||||
"steadyGen", "Number of generations with no improvement",'s');</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">parser.processParam( steadyGenParam, "Stopping
|
||||
criterion" );</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">unsigned steadyGen = steadyGenParam.value();</font></tt></b>
|
||||
<p><tt><font color="#CC33CC">// operators probabilities at the algorithm
|
||||
level</font></tt>
|
||||
<br><b><tt><font color="#CC33CC">eoValueParam<double> pCrossParam(0.6,
|
||||
"pCross", "Probability of Crossover", 'C'); </font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( pCrossParam, "Genetic
|
||||
Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double pCross = pCrossParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#CC33CC">eoValueParam<double> pMutParam(0.1,
|
||||
"pMut", "Probability of Mutation", 'M');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( pMutParam, "Genetic
|
||||
Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double pMut = pMutParam.value();</font></tt></b>
|
||||
<p><tt><font color="#CC33CC">// relative rates for crossovers</font></tt>
|
||||
<br><b><tt><font color="#CC33CC">eoValueParam<double> onePointRateParam(1,
|
||||
"onePointRate", "Relative rate for one point crossover", '1');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( onePointRateParam,
|
||||
"Genetic Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double onePointRate = onePointRateParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#CC33CC">eoValueParam<double> twoPointsRateParam(1,
|
||||
"twoPointRate", "Relative rate for two point crossover", '2');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( twoPointsRateParam,
|
||||
"Genetic Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double twoPointsRate = twoPointsRateParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#CC33CC">eoValueParam<double> uRateParam(2, "uRate",
|
||||
"Relative rate for uniform crossover", 'U');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( uRateParam, "Genetic
|
||||
Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double URate = uRateParam.value();</font></tt></b>
|
||||
<p><tt><font color="#CC33CC">// relative rates and private parameters for
|
||||
mutations;</font></tt>
|
||||
<br><b><tt><font color="#CC33CC">eoValueParam<double> pMutPerBitParam(0.01,
|
||||
"pMutPerBit", "Probability of flipping 1 bit in bit-flip mutation", 'b');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( pMutPerBitParam,
|
||||
"Genetic Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double pMutPerBit = pMutPerBitParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#CC33CC">eoValueParam<double> bitFlipRateParam(0.01,
|
||||
"bitFlipRate", "Relative rate for bit-flip mutation", 'B');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( bitFlipRateParam,
|
||||
"Genetic Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double bitFlipRate = bitFlipRateParam.value();</font></tt></b>
|
||||
<p><b><tt><font color="#CC33CC">eoValueParam<double> oneBitRateParam(0.01,
|
||||
"oneBitRate", "Relative rate for deterministic bit-flip mutation", 'D');</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">parser.processParam( oneBitRateParam,
|
||||
"Genetic Operators" );</font></tt></b>
|
||||
<br><b><tt><font color="#CC33CC">double oneBitRate = oneBitRateParam.value();</font></tt></b>
|
||||
<p><tt><font color="#3366FF">// the name of the "status" file where all
|
||||
actual parameter values will be saved</font></tt>
|
||||
<br><b><tt><font color="#3366FF">string str_status = parser.ProgramName()
|
||||
+ ".status"; // default value</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">eoValueParam<string> statusParam(str_status.c_str(),
|
||||
"status","Status file",'S');</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">parser.processParam( statusParam, "Persistence"
|
||||
);</font></tt></b>
|
||||
<p><tt><font color="#3366FF">// do the following AFTER ALL PARAMETERS HAVE
|
||||
BEEN PROCESSED</font></tt>
|
||||
<br><tt><font color="#3366FF">// i.e. in case you need parameters somewhere
|
||||
else, postpone these</font></tt>
|
||||
<br><b><tt><font color="#3366FF">if (parser.userNeedsHelp())</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> {</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> parser.printHelp(cout);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> exit(1);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> }</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">if (statusParam.value() != "")</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> {</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> ofstream
|
||||
os(statusParam.value().c_str());</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> os <<
|
||||
parser; </b>// and you can use that file as parameter file</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> }</font></tt></b></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td></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> </b>/////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Fitness function</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>////////////////////////////</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b>// Evaluation: from a plain
|
||||
C++ fn to an EvalFunc Object ...</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> eoEvalFuncPtr<Indi, double, const
|
||||
vector<bool>& > plainEval( binary_value );</font></tt></b>
|
||||
<br><a NAME="evalcounter"></a><tt><font color="#CC0000">// ... to an object
|
||||
that counts the nb of actual evaluations</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> eoEvalFuncCounter<Indi> eval(plainEval);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// Initilisation of population</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// Either load or initialize</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// create an empty pop</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPop<Indi> pop;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// create a state for reading</font></tt>
|
||||
<br><tt><font color="#993399"><b> eoState inState; </b>// a state
|
||||
for loading - WITHOUT the parser</font></tt>
|
||||
<br><a NAME="register"></a><tt><font color="#993399">// register the rng
|
||||
and the pop in the state, so they can be loaded,</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// and the present run will
|
||||
be the exact conitnuation of the saved run</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// eventually with different
|
||||
parameters</font></tt>
|
||||
<br><b><tt><font color="#993399"> inState.registerObject(rng);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> inState.registerObject(pop);</font></tt></b>
|
||||
<p><a NAME="instate.load"></a><b><tt><font color="#993399">if (load_name
|
||||
!= "")</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> {</font></tt></b>
|
||||
<br><a NAME="loadstate"></a><tt><font color="#993399"><b>
|
||||
inState.load(load_name); </b>// load the pop and the rng</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>//
|
||||
the fitness is read in the file: </font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>//
|
||||
do only evaluate the pop if the fitness has changed</font></tt>
|
||||
<br><b><tt><font color="#993399"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> else</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993399">
|
||||
rng.reseed(seed);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>//
|
||||
a Indi random initializer</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>//
|
||||
based on eoUniformGenerator class (see utils/eoRndGenerators.h)</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoUniformGenerator<bool>
|
||||
uGen;</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> eoInitFixedLength<Indi>
|
||||
random(vecSize, uGen);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>//
|
||||
Init pop from the randomizer: need to use the append function</font></tt>
|
||||
<br><b><tt><font color="#993399">
|
||||
pop.append(popSize, random); </font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>//
|
||||
and evaluate pop (STL syntax) </font></tt>
|
||||
<br><b><tt><font color="#993399">
|
||||
apply<Indi>(eval, pop);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> } </b>// end
|
||||
of initialization of the population</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// sort pop for pretty printout</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Print (sorted) intial population
|
||||
(raw printout)</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> cout << "Initial Population"
|
||||
<< endl << pop << endl;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="engine"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#99FFCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#009900"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// selection and replacement</font></tt>
|
||||
<br><tt><font color="#009900"><b> </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> </b>// The robust tournament selection</font></tt>
|
||||
<br><tt><font color="#009900"><b> eoDetTournamentSelect<Indi> selectOne(tSize);
|
||||
</b>// tSize in [2,POPSIZE]</font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// is now encapsulated in a
|
||||
eoSelectPerc (entage)</font></tt>
|
||||
<br><b><tt><font color="#009900"> eoSelectPerc<Indi> select(selectOne);</font></tt></b>
|
||||
<br><tt><font color="#009900"> // or eoSelectPerc<Indi> select(selectOne,
|
||||
rate); </font></tt>
|
||||
<br><tt><font color="#009900"> // but 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> </b>// And we now have the full
|
||||
slection/replacement - though with </font></tt>
|
||||
<br><tt><font color="#009900"><b> </b>// the same generational replacement
|
||||
at the moment :-)</font></tt>
|
||||
<br><b><tt><font color="#009900"> eoGenerationalReplacement<Indi>
|
||||
replace; </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> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>// The variation operators</font></tt>
|
||||
<br><tt><font color="#993399"><b> </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> </b>// 1-point crossover for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eo1PtBitXover<Indi> xover1;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// uniform crossover for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoUBitXover<Indi> xoverU;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// 2-pots xover</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoNPtsBitXover<Indi> xover2(2);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Combine them with relative
|
||||
rates</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPropCombinedQuadOp<Indi> xover(xover1,
|
||||
onePointRate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> xover.add(xoverU, URate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> xover.add(xover2, twoPointsRate,
|
||||
true);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="mutation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b>// standard bit-flip mutation
|
||||
for bitstring</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoBitMutation<Indi> mutationBitFlip(pMutPerBit);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// mutate exactly 1 bit per
|
||||
individual</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoDetBitFlip<Indi> mutationOneBit; </font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// Combine them with relative
|
||||
rates</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPropCombinedMonOp<Indi> mutation(mutationBitFlip,
|
||||
bitFlipRate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> mutation.add(mutationOneBit, oneBitRate,
|
||||
true);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b>// The operators are encapsulated
|
||||
into an eoTRansform object</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoSGATransform<Indi> transform(xover,
|
||||
pCross, mutation, pMut);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="stop"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>//////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// termination condition see
|
||||
FirstBitEA.cpp</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>/////////////////////////////////////</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoGenContinue<Indi> genCont(maxGen);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> eoSteadyFitContinue<Indi> steadyCont(minGen,
|
||||
steadyGen);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> eoFitContinue<Indi> fitCont(vecSize);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> eoCombinedContinue<Indi> continuator(genCont);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> continuator.add(steadyCont);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> continuator.add(fitCont);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="checkpoint"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// but now you want to make
|
||||
many different things every generation </font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// (e.g. statistics, plots,
|
||||
...).</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// the class eoCheckPoint is
|
||||
dedicated to just that:</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Declare a checkpoint (from
|
||||
a continuator: an eoCheckPoint </font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// IS AN eoContinue and will
|
||||
be called in the loop of all algorithms)</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoCheckPoint<Indi> checkpoint(continuator);</font></tt></b>
|
||||
<p><a NAME="param_declare"></a><tt><font color="#3366FF"><b> </b>//
|
||||
Create a counter parameter</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoValueParam<unsigned>
|
||||
generationCounter(0, "Gen.");</font></tt></b>
|
||||
<p><a NAME="param_pass"></a><tt><font color="#3366FF"><b> </b>//
|
||||
Create an incrementor (sub-class of eoUpdater). Note that the </font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// parameter's
|
||||
value is passed by reference, </font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// so every
|
||||
time the incrementer is updated (every generation),</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// the data
|
||||
in generationCounter will change.</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoIncrementor<unsigned>
|
||||
increment(generationCounter.value());</font></tt></b>
|
||||
<br><a NAME="updater_pass"></a><tt><font color="#3366FF"><b> </b>//
|
||||
Add it to the checkpoint, </font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// so the
|
||||
counter is updated (here, incremented) every generation</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> checkpoint.add(increment);</font></tt></b>
|
||||
<br><a NAME="stat_declare"></a><tt><font color="#3366FF"><b> </b>//
|
||||
now some statistics on the population:</font></tt>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Best fitness
|
||||
in population</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoBestFitnessStat<Indi>
|
||||
bestStat;</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Second
|
||||
moment stats: average and stdev</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoSecondMomentStats<Indi>
|
||||
SecondStat;</font></tt></b>
|
||||
<br><a NAME="stat_pass"></a><tt><font color="#3366FF"><b> </b>//
|
||||
Add them to the checkpoint to get them called at the appropriate time</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> checkpoint.add(bestStat);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> checkpoint.add(SecondStat);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// The Stdout
|
||||
monitor will print parameters to the screen ...</font></tt>
|
||||
<br><a NAME="monitor_declare"></a><b><tt><font color="#3366FF">
|
||||
eoStdoutMonitor monitor(false);</font></tt></b>
|
||||
<p><tt><font color="#3366FF"><b> </b>// when called
|
||||
by the checkpoint (i.e. at every generation)</font></tt>
|
||||
<br><a NAME="monitor_pass"></a><b><tt><font color="#3366FF">
|
||||
checkpoint.add(monitor);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// the monitor
|
||||
will output a series of parameters: add them </font></tt>
|
||||
<br><a NAME="monitor_add"></a><b><tt><font color="#3366FF">
|
||||
monitor.add(generationCounter);</font></tt></b><a NAME="eval_monitor"></a>
|
||||
<br><tt><font color="#3366FF"><b> monitor.add(eval);
|
||||
</b>//
|
||||
because now eval is an eoEvalFuncCounter!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> monitor.add(bestStat);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> monitor.add(SecondStat);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// A file
|
||||
monitor: will print parameters to ... a File, yes, you got it!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoFileMonitor
|
||||
fileMonitor("stats.xg", " ");</font></tt></b>
|
||||
<p><tt><font color="#3366FF"><b> </b>// the checkpoint
|
||||
mechanism can handle multiple monitors</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> checkpoint.add(fileMonitor);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// the fileMonitor
|
||||
can monitor parameters, too, but you must tell it!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> fileMonitor.add(generationCounter);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> fileMonitor.add(bestStat);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> fileMonitor.add(SecondStat);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Last type
|
||||
of item the eoCheckpoint can handle: state savers:</font></tt>
|
||||
<br><a NAME="outstate_declare"></a><b><tt><font color="#3366FF">
|
||||
eoState outState;</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// Register
|
||||
the algorithm into the state</font></tt>
|
||||
<br><a NAME="outstate_register"></a><b><tt><font color="#3366FF">
|
||||
outState.registerObject(parser);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> outState.registerObject(pop);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> outState.registerObject(rng);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// and feed
|
||||
the state to state savers</font></tt>
|
||||
<br><a NAME="statesaver_declare"></a><tt><font color="#3366FF">// save
|
||||
state every 100th generation</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoCountedStateSaver
|
||||
stateSaver1(100, outState, "generation"); </font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// save state
|
||||
every 1 seconds </font></tt>
|
||||
<br><b><tt><font color="#3366FF"> eoTimedStateSaver
|
||||
stateSaver2(1, outState, "time"); </font></tt></b>
|
||||
<br><a NAME="statesaver_pass"></a><tt><font color="#3366FF"><b> </b>//
|
||||
Don't forget to add the two savers to the checkpoint</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> checkpoint.add(stateSaver1);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> checkpoint.add(stateSaver2);</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>// and that's
|
||||
it for the (control and) output</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="generation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#FF6666"><b> </b>/////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// the algorithm</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>////////////////////////////////////////</font></tt>
|
||||
<br><tt><font color="#FF6666"><b> </b>// Easy EA requires </font></tt>
|
||||
<br><tt><font color="#FF6666"> // stopping criterion, eval, selection,
|
||||
transformation, replacement</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> eoEasyEA<Indi> gga(checkpoint,
|
||||
eval, select, transform, replace);</font></tt></b>
|
||||
<br><tt><font color="#FF6666"><b> </b>// Apply algo to pop - that's
|
||||
it!</font></tt>
|
||||
<br><b><tt><font color="#FF6666"> gga(pop);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="output"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#3366FF"><b> </b>// Print (sorted) final population</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> pop.sort();</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> cout << "FINAL Population\n"
|
||||
<< pop << endl;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="general"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993300">}</font></tt></b>
|
||||
<br><tt><font color="#993300">// A main that catches the exceptions</font></tt>
|
||||
<br><b><tt><font color="#993300">int main(int argc, char **argv)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#ifdef _MSC_VER</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> flag
|
||||
|= _CRTDBG_LEAK_CHECK_DF;</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> _CrtSetDbgFlag(flag);</font></tt></b>
|
||||
<br><tt><font color="#993300">// _CrtSetBreakAlloc(100);</font></tt>
|
||||
<br><b><tt><font color="#993300">#endif</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> try</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
main_function(argc, argv);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> catch(exception&
|
||||
e)</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
cout << "Exception: " << e.what() << '\n';</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> return 1;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson3.html">Back to Lesson 3</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based
|
||||
</a>-
|
||||
<a href="eoProgramming.html">Programming
|
||||
hints</a> - <b><font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></b>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Sun Nov
|
||||
26 09:31:04 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
468
eo/tutorial/html/SecondRealEA.html
Normal file
468
eo/tutorial/html/SecondRealEA.html
Normal file
|
|
@ -0,0 +1,468 @@
|
|||
<!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="cpp2html Marc Schoenauer">
|
||||
<title>SecondRealEA</title>
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoLesson3.html">Back to Lesson 3</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">SecondRealEA</font></h1></center>
|
||||
Click on the figure to see the corresponding code.<br>
|
||||
In the code, the <a href="eoTutorial.html#colors">colors are meaningfull</a><br>
|
||||
The actual code is in boldface and the comment in normal face.
|
||||
<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>
|
||||
<br>
|
||||
<A NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><tt><font color="#993300">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// SecondRealEA.cpp<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
//*<br>
|
||||
// Same code than FirstBitEA as far as Evolutionary Computation is concerned<br>
|
||||
// but now you learn to enter the parameters in a more flexible way<br>
|
||||
// (also slightly different than in SecondBitEA.cpp)<br>
|
||||
// and to twidle the output to your preferences (as in SecondBitEA.cpp)<br>
|
||||
//<br>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// standard includes<br>
|
||||
<b>#include <stdexcept> </b>// runtime_error <br>
|
||||
<b>#include <iostream> </b>// cout<br>
|
||||
<b>#include <strstream> </b>// ostrstream, istrstream<br>
|
||||
// the general include for eo<br>
|
||||
<b>#include <eo></b><br>
|
||||
<b>#include <es.h></b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFFFCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// define your individuals<br>
|
||||
<b>typedef eoReal<eoMinimizingFitness> Indi; </b><br>
|
||||
</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">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// a simple fitness function that computes the euclidian norm of a real vector<br>
|
||||
// Now in a separate file, and declared as binary_value(const vector<bool> &)<br>
|
||||
<b>#include "real_value.h"</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">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
<b>void main_function(int argc, char **argv)</b><br>
|
||||
<b>{</b><br>
|
||||
</font></tt>
|
||||
</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">
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
// instead of having all values of useful parameters as constants, read them:<br>
|
||||
// either on the command line (--option=value or -o=value)<br>
|
||||
// or in a parameter file (same syntax, order independent, <br>
|
||||
// # = usual comment character <br>
|
||||
// or in the environment (TODO)<br>
|
||||
<b> </b>// First define a parser from the command-line arguments<br>
|
||||
<b> eoParser parser(argc, argv);</b><br>
|
||||
<b> </b><br>
|
||||
<b> </b>// For each parameter, you can in on single line<br>
|
||||
<b> </b>// define the parameter, read it through the parser, and assign it<br>
|
||||
<b> </b><br>
|
||||
<a NAME="random"></a>
|
||||
<b> unsigned seed = parser.createParam(unsigned(time(0)), "seed", "Random number seed", 'S').value(); </b>// will be in default section General<br>
|
||||
<b> </b><br>
|
||||
<b> </b>// description of genotype<br>
|
||||
<b> unsigned vecSize = parser.createParam(unsigned(8), "vecSize", "Genotype size",'V', "Representation" ).value();</b><br>
|
||||
<b> </b>// parameters for evolution engine<br>
|
||||
<b> unsigned popSize = parser.createParam(unsigned(10), "popSize", "Population size",'P', "Evolution engine" ).value();</b><br>
|
||||
<b> unsigned tSize = parser.createParam(unsigned(2), "tSize", "Tournament size",'T', "Evolution Engine" ).value();</b><br>
|
||||
<b> </b>// init and stop<br>
|
||||
<b> string loadName = parser.createParam(string(""), "Load","A save file to restart from",'L', "Persistence" ).value();</b><br>
|
||||
<b> </b><br>
|
||||
<b> unsigned maxGen = parser.createParam(unsigned(100), "maxGen", "Maximum number of generations",'G', "Stopping criterion" ).value();</b><br>
|
||||
<b> unsigned minGen = parser.createParam(unsigned(100), "minGen", "Minimum number of generations",'g', "Stopping criterion" ).value();</b><br>
|
||||
<b> unsigned steadyGen = parser.createParam(unsigned(100), "steadyGen", "Number of generations with no improvement",'s', "Stopping criterion" ).value();</b><br>
|
||||
<b> </b>// operators probabilities at the algorithm level<br>
|
||||
<b> double pCross = parser.createParam(double(0.6), "pCross", "Probability of Crossover", 'C', "Genetic Operators" ).value();</b><br>
|
||||
<b> double pMut = parser.createParam(double(0.1), "pMut", "Probability of Mutation", 'M', "Genetic Operators" ).value();</b><br>
|
||||
<b> </b>// relative rates for crossovers<br>
|
||||
<b> double hypercubeRate = parser.createParam(double(1), "hypercubeRate", "Relative rate for hypercube crossover", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> double segmentRate = parser.createParam(double(1), "segmentRate", "Relative rate for segment crossover", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> </b>// internal parameters for the mutations<br>
|
||||
<b> double EPSILON = parser.createParam(double(0.01), "EPSILON", "Width for uniform mutation", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> </b><br>
|
||||
<b> double SIGMA = parser.createParam(double(0.3), "SIGMA", "Sigma for normal mutation", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> </b>// relative rates for mutations<br>
|
||||
<b> double uniformMutRate = parser.createParam(double(1), "uniformMutRate", "Relative rate for uniform mutation", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> double detMutRate = parser.createParam(double(1), "detMutRate", "Relative rate for det-uniform mutation", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> double normalMutRate = parser.createParam(double(1), "normalMutRate", "Relative rate for normal mutation", '\0', "Genetic Operators" ).value();</b><br>
|
||||
<b> </b>// the name of the "status" file where all actual parameter values will be saved <br>
|
||||
<b> string str_status = parser.ProgramName() + ".status"; </b>// default value<br>
|
||||
<b> string statusName = parser.createParam(str_status, "status","Status file",'S', "Persistence" ).value();</b><br>
|
||||
<b> </b>// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED<br>
|
||||
<b> </b>// i.e. in case you need parameters somewhere else, postpone these<br>
|
||||
<b> if (parser.userNeedsHelp())</b><br>
|
||||
<b> {</b><br>
|
||||
<b> parser.printHelp(cout);</b><br>
|
||||
<b> exit(1);</b><br>
|
||||
<b> }</b><br>
|
||||
<b> if (statusName != "")</b><br>
|
||||
<b> {</b><br>
|
||||
<b>ofstream os(statusName.c_str());</b><br>
|
||||
<b>os << parser; </b>// and you can use that file as parameter file<br>
|
||||
<b> }</b><br>
|
||||
</font></tt>
|
||||
</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> </b>/////////////////////////////<br>
|
||||
<b> </b>// Fitness function<br>
|
||||
<b> </b>////////////////////////////<br>
|
||||
<b> </b>// Evaluation: from a plain C++ fn to an EvalFunc Object<br>
|
||||
<b> </b>// you need to give the full description of the function<br>
|
||||
<b> eoEvalFuncPtr<Indi, double, const vector<double>& > plainEval( real_value );</b><br>
|
||||
<b> </b>// ... to an object that counts the nb of actual evaluations<br>
|
||||
<b> eoEvalFuncCounter<Indi> eval(plainEval);</b><br>
|
||||
</font></tt>
|
||||
</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> </b>////////////////////////////////<br>
|
||||
<b> </b>// Initilisation of population<br>
|
||||
<b> </b>////////////////////////////////<br>
|
||||
<b> </b>// Either load or initialize<br>
|
||||
<b> </b>// create an empty pop<br>
|
||||
<b> eoPop<Indi> pop;</b><br>
|
||||
<b> </b>// create a state for reading<br>
|
||||
<b> eoState inState; </b>// a state for loading - WITHOUT the parser<br>
|
||||
<b> </b>// register the rng and the pop in the state, so they can be loaded,<br>
|
||||
<b> </b>// and the present run will be the exact conitnuation of the saved run<br>
|
||||
<b> </b>// eventually with different parameters<br>
|
||||
<b> inState.registerObject(rng);</b><br>
|
||||
<b> inState.registerObject(pop);</b><br>
|
||||
<b> </b><br>
|
||||
<b> if (loadName != "")</b><br>
|
||||
<b> {</b><br>
|
||||
<b> inState.load(loadName); </b>// load the pop and the rng<br>
|
||||
<b> </b>// the fitness is read in the file: <br>
|
||||
<b> </b>// do only evaluate the pop if the fitness has changed<br>
|
||||
<b> }</b><br>
|
||||
<b> else</b><br>
|
||||
<b> {</b><br>
|
||||
<b> rng.reseed(seed);</b><br>
|
||||
<b> </b>// a Indi random initializer<br>
|
||||
<b> </b>// based on boolean_generator class (see utils/rnd_generator.h)<br>
|
||||
<b> eoUniformGenerator<double> uGen(-1.0, 1.0);</b><br>
|
||||
<b> eoInitFixedLength<Indi> random(vecSize, uGen);</b><br>
|
||||
<b> </b>// Init pop from the randomizer: need to use the append function<br>
|
||||
<b> pop.append(popSize, random); </b><br>
|
||||
<b> </b>// and evaluate pop (STL syntax) <br>
|
||||
<b> apply<Indi>(eval, pop);</b><br>
|
||||
<b> } </b>// end of initializatio of the population<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">
|
||||
<b> </b>// sort pop before printing it!<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> </b>// Print (sorted) intial population (raw printout)<br>
|
||||
<b> cout << "Initial Population" << endl;</b><br>
|
||||
<b> cout << 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> </b>/////////////////////////////////////<br>
|
||||
<b> </b>// selection and replacement<br>
|
||||
<b> </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> </b>// The robust tournament selection<br>
|
||||
<b> eoDetTournamentSelect<Indi> selectOne(tSize);</b><br>
|
||||
<b> </b>// is now encapsulated in a eoSelectPerc (entage)<br>
|
||||
<b> eoSelectPerc<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> </b>// And we now have the full slection/replacement - though with <br>
|
||||
<b> </b>// no replacement (== generational replacement) at the moment :-)<br>
|
||||
<b> eoGenerationalReplacement<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> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// The variation operators<br>
|
||||
<b> </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> </b>// uniform chooce on segment made by the parents<br>
|
||||
<b> eoSegmentCrossover<Indi> xoverS;</b><br>
|
||||
<b> </b>// uniform choice in hypercube built by the parents<br>
|
||||
<b> eoHypercubeCrossover<Indi> xoverA;</b><br>
|
||||
<b> </b>// Combine them with relative weights<br>
|
||||
<b> eoPropCombinedQuadOp<Indi> xover(xoverS, segmentRate);</b><br>
|
||||
<b> xover.add(xoverA, hypercubeRate, 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> </b>// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]<br>
|
||||
<b> eoUniformMutation<Indi> mutationU(EPSILON); </b><br>
|
||||
<b> </b>// k (=1) coordinates of parents are uniformly modified<br>
|
||||
<b> eoDetUniformMutation<Indi> mutationD(EPSILON); </b><br>
|
||||
<b> </b>// all coordinates of parents are normally modified (stDev SIGMA)<br>
|
||||
<b> eoNormalMutation<Indi> mutationN(SIGMA); </b><br>
|
||||
<b> </b>// Combine them with relative weights<br>
|
||||
<b> eoPropCombinedMonOp<Indi> mutation(mutationU, uniformMutRate);</b><br>
|
||||
<b> mutation.add(mutationD, detMutRate);</b><br>
|
||||
<b> mutation.add(mutationN, normalMutRate, true);</b><br>
|
||||
<b> </b>// The operators are encapsulated into an eoTRansform object<br>
|
||||
<b> eoSGATransform<Indi> transform(xover, pCross, mutation, pMut);</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">
|
||||
<b> </b>//////////////////////////////////////<br>
|
||||
<b> </b>// termination condition see FirstBitEA.cpp<br>
|
||||
<b> </b>/////////////////////////////////////<br>
|
||||
<b> eoGenContinue<Indi> genCont(maxGen);</b><br>
|
||||
<b> eoSteadyFitContinue<Indi> steadyCont(minGen, steadyGen);</b><br>
|
||||
<b> eoFitContinue<Indi> fitCont(0);</b><br>
|
||||
<b> eoCombinedContinue<Indi> continuator(genCont);</b><br>
|
||||
<b> continuator.add(steadyCont);</b><br>
|
||||
<b> continuator.add(fitCont);</b><br>
|
||||
<b> </b><br>
|
||||
<b> </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> </b>// but now you want to make many different things every generation <br>
|
||||
<b> </b>// (e.g. statistics, plots, ...).<br>
|
||||
<b> </b>// the class eoCheckPoint is dedicated to just that:<br>
|
||||
<b> </b>// Declare a checkpoint (from a continuator: an eoCheckPoint <br>
|
||||
<b> </b>// IS AN eoContinue and will be called in the loop of all algorithms)<br>
|
||||
<b> eoCheckPoint<Indi> checkpoint(continuator);</b><br>
|
||||
<b> </b><br>
|
||||
<b> </b>// Create a counter parameter<br>
|
||||
<b> eoValueParam<unsigned> generationCounter(0, "Gen.");</b><br>
|
||||
<b> </b><br>
|
||||
<b> </b>// Create an incrementor (sub-class of eoUpdater). Note that the <br>
|
||||
<b> </b>// parameter's value is passed by reference, <br>
|
||||
<b> </b>// so every time the incrementer is updated (every generation),<br>
|
||||
<b> </b>// the data in generationCounter will change.<br>
|
||||
<b> eoIncrementor<unsigned> increment(generationCounter.value());</b><br>
|
||||
<b> </b>// Add it to the checkpoint, <br>
|
||||
<b> </b>// so the counter is updated (here, incremented) every generation<br>
|
||||
<b> checkpoint.add(increment);</b><br>
|
||||
<b> </b>// now some statistics on the population:<br>
|
||||
<b> </b>// Best fitness in population<br>
|
||||
<b> eoBestFitnessStat<Indi> bestStat;</b><br>
|
||||
<b> </b>// Second moment stats: average and stdev<br>
|
||||
<b> eoSecondMomentStats<Indi> SecondStat;</b><br>
|
||||
<b> </b>// Add them to the checkpoint to get them called at the appropriate time<br>
|
||||
<b> checkpoint.add(bestStat);</b><br>
|
||||
<b> checkpoint.add(SecondStat);</b><br>
|
||||
<b> </b>// The Stdout monitor will print parameters to the screen ...<br>
|
||||
<b> eoStdoutMonitor monitor(false);</b><br>
|
||||
<b> </b><br>
|
||||
<b> </b>// when called by the checkpoint (i.e. at every generation)<br>
|
||||
<b> checkpoint.add(monitor);</b><br>
|
||||
<b> </b>// the monitor will output a series of parameters: add them <br>
|
||||
<b> monitor.add(generationCounter);</b><br>
|
||||
<b> monitor.add(eval); </b>// because now eval is an eoEvalFuncCounter!<br>
|
||||
<b> monitor.add(bestStat);</b><br>
|
||||
<b> monitor.add(SecondStat);</b><br>
|
||||
<b> </b>// A file monitor: will print parameters to ... a File, yes, you got it!<br>
|
||||
<b> eoFileMonitor fileMonitor("stats.xg", " ");</b><br>
|
||||
<b> </b><br>
|
||||
<b> </b>// the checkpoint mechanism can handle multiple monitors<br>
|
||||
<b> checkpoint.add(fileMonitor);</b><br>
|
||||
<b> </b>// the fileMonitor can monitor parameters, too, but you must tell it!<br>
|
||||
<b> fileMonitor.add(generationCounter);</b><br>
|
||||
<b> fileMonitor.add(bestStat);</b><br>
|
||||
<b> fileMonitor.add(SecondStat);</b><br>
|
||||
<b> </b>// Last type of item the eoCheckpoint can handle: state savers:<br>
|
||||
<b> eoState outState;</b><br>
|
||||
<b> </b>// Register the algorithm into the state (so it has something to save!!)<br>
|
||||
<b> outState.registerObject(parser);</b><br>
|
||||
<b> outState.registerObject(pop);</b><br>
|
||||
<b> outState.registerObject(rng);</b><br>
|
||||
<b> </b>// and feed the state to state savers<br>
|
||||
<b> </b>// save state every 100th generation<br>
|
||||
<b> eoCountedStateSaver stateSaver1(20, outState, "generation"); </b><br>
|
||||
<b> </b>// save state every 1 seconds <br>
|
||||
<b> eoTimedStateSaver stateSaver2(1, outState, "time"); </b><br>
|
||||
<b> </b>// Don't forget to add the two savers to the checkpoint<br>
|
||||
<b> checkpoint.add(stateSaver1);</b><br>
|
||||
<b> checkpoint.add(stateSaver2);</b><br>
|
||||
<b> </b>// and that's it for the (control and) output<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> </b>/////////////////////////////////////////<br>
|
||||
<b> </b>// the algorithm<br>
|
||||
<b> </b>////////////////////////////////////////<br>
|
||||
<b> </b>// Easy EA requires <br>
|
||||
<b> </b>// stopping criterion, eval, selection, transformation, replacement<br>
|
||||
<b> eoEasyEA<Indi> gga(checkpoint, eval, select, transform, replace);</b><br>
|
||||
<b> </b>// Apply algo to pop - that's it!<br>
|
||||
<b> gga(pop);</b><br>
|
||||
<b> </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">
|
||||
<b> </b>// Print (sorted) intial population<br>
|
||||
<b> pop.sort();</b><br>
|
||||
<b> cout << "FINAL Population\n" << pop << 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> try</b><br>
|
||||
<b> {</b><br>
|
||||
<b> main_function(argc, argv);</b><br>
|
||||
<b> }</b><br>
|
||||
<b> catch(exception& e)</b><br>
|
||||
<b> {</b><br>
|
||||
<b> cout << "Exception: " << e.what() << '\n';</b><br>
|
||||
<b> }</b><br>
|
||||
<b> return 1;</b><br>
|
||||
<b>}</b><br>
|
||||
</font></font></font></td>
|
||||
</tr>
|
||||
</table>
|
||||
<hr WIDTH="100%"><a href="eoLesson3.html">Back to Lesson 3</a> - <a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:marc.schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last
|
||||
modified: Sun Apr 28 06:42:44 2002
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
BIN
eo/tutorial/html/beige009.jpg
Normal file
BIN
eo/tutorial/html/beige009.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.5 KiB |
57
eo/tutorial/html/binary_value.html
Normal file
57
eo/tutorial/html/binary_value.html
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (X11; U; Linux 2.2.17-21mdk i686) [Netscape]">
|
||||
<title>binary_value.h</title>
|
||||
</head>
|
||||
<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
|
||||
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> - <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">binary_value.h</font></h1></center>
|
||||
<a NAME="start"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE><b><tt><font color="#993300">#include <eo></font></tt></b>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">/** Just a simple function that takes binary
|
||||
value of a chromosome and sets</font></tt>
|
||||
<br><tt><font color="#993300"> the fitnes.</font></tt>
|
||||
<br><tt><font color="#993300"> @param _chrom A
|
||||
binary chromosome </font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="init"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCFF" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399">double binary_value(const vector<bool>&
|
||||
_chrom)</font></tt></b>
|
||||
<br><b><tt><font color="#993399">{</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> double sum = 0;</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> for (unsigned i = 0; i < _chrom.size();
|
||||
i++)</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> sum += _chrom[i];</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> return sum;</font></tt></b>
|
||||
<br><b><tt><font color="#993399">}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<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
|
||||
page</a> - <a href="eoProgramming.html">Programming hints</a> - <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Wed Nov
|
||||
29 09:03:09 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
21
eo/tutorial/html/debut.html
Normal file
21
eo/tutorial/html/debut.html
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>TITRE</title>
|
||||
</head>
|
||||
|
||||
<body text="#000000" background="beige009.jpg" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoTutorial.html">Tutorial main page </a>-
|
||||
<a href="eoTopDown.html">Algorithm-Based
|
||||
page</a> - <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<!-- -------------- End of header ------------------ -->
|
||||
<!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1><font color="#FF0000">TITRE</font></h1>
|
||||
</center>
|
||||
|
||||
<font face="Courier New,Courier"><font size=+1>
|
||||
<p>
|
||||
77
eo/tutorial/html/eoBottomUp.html
Normal file
77
eo/tutorial/html/eoBottomUp.html
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<!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.72 [en] (X11; U; Linux 2.2.16 i686) [Netscape]">
|
||||
<title>EO - The Component-Based approach</title>
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#CCCCCC" link="#0000EF" vlink="#51188E" alink="#FF0000">
|
||||
<a href="eoTutorial.html">Tutorial main page </a>-
|
||||
<a href="eoTopDown.html">Algorithm-Based
|
||||
</a> - <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <a href="../../doc/html/index.html">EO documentation</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">EO - Component-Based approach</font></h1></center>
|
||||
|
||||
<p><br>Congratulations - You have chosen the component-based approach!
|
||||
From here you will be allowed to browse into the different components of
|
||||
an Evolutionary Algorithm, and to see how to program your favorite using
|
||||
the EO library.
|
||||
|
||||
<h3>
|
||||
<font color="#000099">Table of Content</font></h3>
|
||||
|
||||
<center>
|
||||
<p><img SRC="EA_tutorial.jpg" USEMAP="#Map" ></center>
|
||||
|
||||
<p>Yes, this is the table of content of this part
|
||||
of the EO tutorial. If you don't already know what this symbolic
|
||||
representation of an EA means, you should try <a
|
||||
href="eoIntroEA.html">here</a>. Otherwise, <font color="#FF6600">click on the figure</font>
|
||||
to go directly to the corresponding section of the tutorial.
|
||||
<br>
|
||||
<map NAME="Map">
|
||||
<area SHAPE="rect" HREF="eoInit.html" COORDS="14,31,135,70">
|
||||
<area SHAPE="rect" HREF="eoEval.html" COORDS="14,110,135,150">
|
||||
|
||||
<area SHAPE="rect" HREF="eoRepresentation.html" COORDS="340,270,465,310">
|
||||
<area SHAPE="rect" HREF="eoIo.html#output" COORDS="280,45,480,70">
|
||||
<area SHAPE="rect" HREF="eoIo.html#stop" COORDS="348,110,430,150">
|
||||
<area SHAPE="rect" HREF="eoEngine.html#selection" COORDS="495,110,615,150">
|
||||
|
||||
<area SHAPE="rect" HREF="eoRepresentation.html" COORDS="495,190,615,230">
|
||||
<area SHAPE="rect" HREF="eoOperators.html#crossover" COORDS="495,265,625,287">
|
||||
<area SHAPE="rect" HREF="eoOperators.html#mutation" COORDS="495,287,625,305">
|
||||
|
||||
<area SHAPE="rect" HREF="eoRepresentation.html" COORDS="170,110,295,150">
|
||||
<area SHAPE="rect" HREF="eoEval.html" COORDS="170,270,295,310">
|
||||
<area SHAPE="rect" HREF="eoEngine.html#replacement" COORDS="170,190,295,230">
|
||||
|
||||
<area SHAPE="rect" HREF="eoGeneration.html" COORDS="310,160,485,260">
|
||||
|
||||
|
||||
<area SHAPE="rect" HREF="eoOperators.html" COORDS="15,350,260,370">
|
||||
<area SHAPE="rect" HREF="eoRepresentation.html" COORDS="270,350,460,370">
|
||||
<area SHAPE="rect" HREF="eoEngine.html" COORDS="15,377,400,397">
|
||||
<area SHAPE="rect" HREF="eoEval.html" COORDS="15,403,230,423">
|
||||
<area SHAPE="rect" HREF="eoCheckPoint.html" COORDS="15,430,221,450">
|
||||
<area SHAPE="rect" HREF="eoCheckpoint.html#stop" COORDS="221,430,345,450">
|
||||
<area SHAPE="rect" HREF="eoCheckpoint.html#stat" COORDS="375,430,445,450">
|
||||
</map>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="eoTutorial.html">Tutorial main page </a>- <a href="eoTopDown.html">Algorithm-Based
|
||||
</a> - <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <a href="../../doc/html/index.html">EO documentation</a>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Mon Oct 30 07:27:13 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: Mon Oct 30 07:28:36 CET 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
150
eo/tutorial/html/eoCheckPoint.html
Normal file
150
eo/tutorial/html/eoCheckPoint.html
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
<!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.73 [en] (X11; I; Linux 2.2.15-4mdk i686) [Netscape]">
|
||||
<title>Variation Operators</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EF" vlink="#51188E" alink="#FF0000" background="beige009.jpg">
|
||||
<b><font color="#FF0000">General</font></b>: <a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#FF0000">Local</font></b>: <a href="#introduction">Introduction</a>
|
||||
- <a href="#continuator">Continuators</a> - <a href="#combined_continue">Combined
|
||||
continuators</a> - <a href="#checkpoint">Checkpoints</a> - <a href="#statistic">Statistics</a>
|
||||
- <a href="#monitor">Monitors</a> - <a href="#updater">Updaters</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<center>
|
||||
<h1>
|
||||
<b><font color="#CC0000">CheckPointing</font></b></h1></center>
|
||||
<a NAME="introduction"></a><b><font color="#000099"><font size=+2>What
|
||||
is Checkpointing about?</font></font></b>
|
||||
<br>Evolutionary Algorithms are almost all timely ticked, the basic time
|
||||
unit being what is called a generation. EO checkpointing mechanism allow
|
||||
you to program things that you want to be done at the end of every generation.
|
||||
This includes deciding to stop, outputing some statistics on the current
|
||||
state of the algorithm, updating some dynamical variables of your
|
||||
algorithm, saving the population to disk, ...
|
||||
<p><b><font color="#FF0000">EO classes described in this page</font></b>:
|
||||
<ul>
|
||||
<li>
|
||||
<b><font color="#FF0000">Base classes</font></b>: eoCheckPoint, <a href="#continuator">eoContinue</a>,
|
||||
eoStat, eoSortedStat, eoMonitor, eoUpdater</li>
|
||||
|
||||
<li>
|
||||
<b><font color="#FF0000">Derived classes</font></b>: eoCombinedContinue,</li>
|
||||
|
||||
<li>
|
||||
<b><font color="#FF0000">Related classes</font></b>: eoGnuPlot1DMonitor,
|
||||
eoGnuPlot1DSnapshotMonitor,</li>
|
||||
</ul>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="continuator"></a><b><font color="#000099"><font size=+1>Continuators:</font></font></b>
|
||||
<p>Continuators are functors that compute stopping critera. They receive
|
||||
a population and return a boolean value which is set to false only when
|
||||
some stopping vriterion is met. All algorithms in EO have a loop that goes
|
||||
<b><font color="#993300">do{...}while(continuator(pop)</font></b>which
|
||||
means that the algorithm stops only when the continuator returns <b><font color="#993300">false</font></b>.
|
||||
<p><b><font color="#FF0000">Interface</font></b>: The abstract class
|
||||
for computing stopping conditions is <b><font color="#3366FF">eoContinue</font></b>,
|
||||
and the interface for its operator() is
|
||||
<p>
|
||||
|
||||
<b><tt><font color="#993300"><font size=+1>bool operator()(const eoPop<EOT>&
|
||||
)</font></font></tt></b>
|
||||
<p>which you could have guessed from the <a href="../../doc/html/classeo_continue.html">inheritance
|
||||
diagram</a> for class <b><font color="#3366FF">eoContinue</font></b>, as
|
||||
you see there that <b><font color="#3366FF">eoContinue</font></b> derives
|
||||
from class <b><tt><font color="#993300"><font size=+1>eoUF<const eoPop<EOT>&,
|
||||
bool></font></font></tt></b>.
|
||||
<p><b><font color="#FF0000">Using a continuator</font></b>:
|
||||
<br>You can find an first example of using a continuator in the code for
|
||||
<a href="FirstBitGA.html#stop">FirstBitEA</a>
|
||||
ior more sophisticated continue conditions in <a href="eoLesson2.html#combinedContinue">Lesson2</a>.
|
||||
<br>If you want to find out how it is used inside an algorithm, go and
|
||||
see for instance in eoSGA, the simplest EA within EO.
|
||||
<p><a NAME="writing_continuator"></a><b><font color="#FF0000">Writing a
|
||||
continuator:</font></b>
|
||||
<br>There are only two things to modify in the <a href="../Templates/continue.tmpl">template
|
||||
class definitions</a> provided (apart from the name of the class you are
|
||||
creating!)
|
||||
<ul>
|
||||
<li>
|
||||
The <font color="#FF6600">constructor</font>, where you pass to the object
|
||||
any useful parameter (see the private data at end of class definition).</li>
|
||||
|
||||
<li>
|
||||
The <font color="#FF6600">operator()</font> method, which performs the
|
||||
computation of the actual test using the population plus any other parameter
|
||||
passed at construct time. Don't forget to <b><font color="#FF6600">returnfalse</font></b>
|
||||
when the stopping criterion <b><font color="#FF6600">is met!</font></b></li>
|
||||
</ul>
|
||||
<a NAME="existingContinue"></a><b><font color="#FF0000">Existing continuators:
|
||||
</font></b>Of
|
||||
course you can find out all existing (non-virtual!) subclasses of eoContinue
|
||||
by looking at its <a href="../../doc/html/classeo_continue.html">inheritance
|
||||
diagram</a>. But you might find it more convenient to have them listed
|
||||
here:
|
||||
<ul>
|
||||
<li>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p><br>
|
||||
<hr WIDTH="100%"><a NAME="combined_continue"></a><b><font color="#000099"><font size=+1>Combining
|
||||
continuators:</font></font></b>
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="checkpoint"></a><b><font color="#000099"><font size=+1>CheckPoints:</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>:
|
||||
<p><b><font color="#FF0000">Using a checkpoint</font></b>: An eoCheckPoint
|
||||
being an eoContinue, its usage is exactly the same. However, an eoCheckPoint
|
||||
will actually do many more things than an eoContinue before returning its
|
||||
boolean result as an eoContinue.
|
||||
<p><a NAME="writing_checkpoint"></a><b><font color="#FF0000">Writing a
|
||||
checkpoint:</font></b>
|
||||
<br>This is something you should never have to do. However, should you
|
||||
feel you have to do it, please do - and send us both the reasons that lead
|
||||
you to that (what is it you couldn't do with existing eoCheckPoint), and
|
||||
the resulting code, of course.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="statistic"></a><b><font color="#000099"><font size=+1>Statistics:</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>:
|
||||
<p><b><font color="#FF0000">Using statistics</font></b>:
|
||||
<p><a NAME="writing_statistic"></a><b><font color="#FF0000">Writing a statitic</font></b>:
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="monitor"></a><b><font color="#000099"><font size=+1>Monitors:</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>:
|
||||
<p><b><font color="#FF0000">Using monitors</font></b>:
|
||||
<p><a NAME="writing_monitor"></a><b><font color="#FF0000">Writing a monitor</font></b>:
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="updater"></a><b><font color="#000099"><font size=+1>Updater:</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>:
|
||||
<p><b><font color="#FF0000">Using updaters</font></b>:
|
||||
<p><a NAME="writing_updater"></a><b><font color="#FF0000">Writing an updater</font></b>:
|
||||
<br>
|
||||
<p>
|
||||
<hr WIDTH="100%"><b><font color="#FF0000">Local</font></b>: <a href="#introduction">Introduction</a>
|
||||
- <a href="#continuator">Continuators</a> - <a href="#combined_continue">Combined
|
||||
continuators</a> - <a href="#checkpoint">Checkpoints</a> - <a href="#statistic">Statistics</a>
|
||||
- <a href="#monitor">Monitors</a> - <a href="#updater">Updaters</a>
|
||||
<br>
|
||||
<hr WIDTH="100%"><b><font color="#FF0000">General</font></b>: <a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> -<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Mon Oct 30 07:27:13 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: Fri Dec. 8 2000 <!-- hhmts end -->
|
||||
<br>
|
||||
</body>
|
||||
</html>
|
||||
778
eo/tutorial/html/eoEngine.html
Normal file
778
eo/tutorial/html/eoEngine.html
Normal file
|
|
@ -0,0 +1,778 @@
|
|||
<!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.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]">
|
||||
<title>Genetic Engine</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EF" vlink="#51188E" alink="#FF0000" background="beige009.jpg">
|
||||
<b><font color="#CC0000">General: </font></b><a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation
|
||||
<hr WIDTH="100%"></a></font></font><font color="#CC0000">Local: </font></b><a href="#introduction">Introduction</a>
|
||||
- <a href="#selection">Selection</a> - <a href="#replacement">Replacement</a>
|
||||
- <a href="#general">General Replacement</a> - <a href="#popular">Popular
|
||||
evolution engines</a> - <a href="#tournament">Tournaments</a> - <a href="#merge">Merge</a>
|
||||
- <a href="#reduce">Reduce</a> - <a href="#howmany">HowMany</a> - <a href="#SAD">SurviveAndDie</a>
|
||||
<hr WIDTH="100%">
|
||||
<center>
|
||||
<h1>
|
||||
<b><font color="#CC0000">Evolution Engine</font></b></h1></center>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="introduction"></a><b><font color="#000099"><font size=+2>Evolution
|
||||
Engines</font></font></b>
|
||||
<p>The term <b><font color="#FF6600">evolution engine</font></b> denotes
|
||||
the different parts of an Evolutionary Algorithm that simulate the Darwinism:
|
||||
<center>
|
||||
<p><i><font color="#009900">The fittest individuals are more likely to
|
||||
reproduce and survive.</font></i></center>
|
||||
|
||||
<p>Darwinism takes place in two different phases of an EA, though in many
|
||||
<a href="#popular">popular
|
||||
variants</a>, only one phase is activated.
|
||||
<p><a href="#selection">Selection</a> is the Darwinistic choice of parents
|
||||
that will be allowed to <b><font color="#009900">reproduce</font></b><font color="#CC33CC">.</font>
|
||||
<br><a href="#replacement">Replacement</a> takes place after reproduction,
|
||||
and is the Darwinistic choice of those individuals that will <b><font color="#009900">survive</font></b>,
|
||||
i.e. become the parents of the next generation.
|
||||
<p>Both selection and replacement will be discussed in turn, before some
|
||||
helper classes that are used within selection and replacement procedures
|
||||
are presented.
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="selection"></a><b><font color="#000099"><font size=+2>Selection</font></font></b>
|
||||
<p>The very beginning of the generation loop is the selection phase, where
|
||||
some individuals from the population are chosen to become the parents,
|
||||
to be later modified by the variation operators and become the offspring.
|
||||
This is the first step of the <font color="#009900">artificial Darwinism</font>,
|
||||
where the <i><font color="#FF6600">fittest individuals are allowed to reproduce</font></i>.
|
||||
<br>Conceptually, there are two distinct ways to choose the lucky ones:
|
||||
one by one from the very same population (i.e. with replacement), which
|
||||
means that at the extreme the same individual can be chosen every time;
|
||||
or as a whole, in some sort of batch procedure. Of course, repeated selection
|
||||
of one individual results in a batch selection!
|
||||
<p>There are hence two basic EO classes for selection: <font color="#009900">eoSelectOne</font>
|
||||
and <font color="#009900">eoSelect</font>, with different interfaces.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoSelectOne: </font><font color="#FF0000">The
|
||||
interface</font></b>
|
||||
<p>The abstract class for selection of a single individual from a population
|
||||
is <font color="#009900">eoSelectOne</font>, and the interface for its
|
||||
<tt><font color="#993300">operator()</font></tt>
|
||||
is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">const EOT & operator()(const eoPop<EOT>&
|
||||
_parents)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_select_one.html">eoSelectOne</a></font></font></b>.,
|
||||
as you see there that <font color="#009900">eoSelectOne</font> derives
|
||||
from <tt><font color="#993300">class eoUF<const eoPop<EOT>&,
|
||||
const EOT&></font></tt>.
|
||||
<br>This means that it takes <font color="#FF6600">1 population</font>
|
||||
(without the right to modify it - see the <b><tt><font color="#993300">const</font></tt></b>
|
||||
keyword in argument) and returns a const reference to an individual (again,
|
||||
the <b><tt><font color="#993300">const</font></tt></b> keyword ensures
|
||||
that nothing will happen to the individual in the population - remember
|
||||
it returns a reference).
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoSelectOne: </font><font color="#FF0000">Instances</font></b>
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoDetTournamentSelect</font></tt></b> uses
|
||||
the <a href="#detTournament">(deterministic) tournament</a> to choose one
|
||||
individual. Its constructor has one parameter, the tournament size (integer
|
||||
>= 2).</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoStochTournamentSelect</font></tt></b> uses
|
||||
the <a href="#stochTournament">binary stochastic tournament</a> to choose
|
||||
one individual. Its constructor has one parameter, the tournament rate
|
||||
(real in [0.5,1]).</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoProportionalSelect</font></tt></b>
|
||||
is the original <font color="#FF6600">roulette wheel</font> selection:
|
||||
each parent is selected with a probability proportional to its fitness.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoRandomSelect</font></tt></b> is the <font color="#FF6600">random</font>
|
||||
selection and should give bad results! At the moment, it selects one individual
|
||||
uniformly, but it would be easy to use any probability distribution.</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoSelect: </font><font color="#FF0000">The
|
||||
interface</font></b>
|
||||
<p>The abstract class for batch selection of a whole set of individuals
|
||||
from a population is <font color="#009900">eoSelect</font>, and the interface
|
||||
for its
|
||||
<tt><font color="#993300">operator()</font></tt> is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">void operator()(const eoPop<EOT>&
|
||||
_source, eoPop<EOT>& _dest)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_select.html">eoSelect</a></font></font></b>.,
|
||||
as you see there that <font color="#009900">eoSelect</font> derives from
|
||||
<tt><font color="#993300">class
|
||||
eoBF<const eoPop<EOT>&, eoPop<EOT>&, void></font></tt>.
|
||||
<br>This means that it takes <font color="#FF6600">2 populations</font>,
|
||||
and fills the second one with individuals from the first one without modifying
|
||||
it (see the <b><tt><font color="#993300">const</font></tt></b> keyword).
|
||||
This raises two questions:
|
||||
<ul>
|
||||
<li>
|
||||
How does it know how many individuals to select?</li>
|
||||
|
||||
<li>
|
||||
How to use repeated selection of one individual (see above the <font color="#009900">eoSelectOne</font>
|
||||
class)?</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoSelect: </font><font color="#FF0000">HowMany</font></b>
|
||||
<p>There are two ways an can derive the number of individuals it
|
||||
has to select: either it is a fixed number, or it is some percentage of
|
||||
the source population size (any positive real number). In both case, this
|
||||
must be passed to the constructor. In most instances, however, the constructor
|
||||
will accept a real number (double) and a boolean indicating whether this
|
||||
real number should be used as an absolute integer or as a rate, thanks
|
||||
to the <a href="#howmany">eoHowMany</a> class.
|
||||
<p><b><font color="#FF0000">Note</font></b>: an <font color="#009900">eoSelect</font>
|
||||
can select more individuals than there are in the original population.
|
||||
It is the job of the <font color="#009900">replacement</font> to ensure
|
||||
that the population size does not grow along the generations.
|
||||
<p>
|
||||
<hr WIDTH="50%"><b><font color="#000099">eoSelectMany: </font><font color="#FF0000">Encapsulating
|
||||
eoSelectOne</font></b>
|
||||
<p>It is clear that repeated selection of a single individual is a way
|
||||
to do batch selection. This is why it is possible to encapsulate an object
|
||||
of class <font color="#009900">eoSelectOne</font> into an object of class
|
||||
<font color="#009900">eoSelect</font>
|
||||
using the class <font color="#009900">eoSelectMany</font>. Class <font color="#009900">eoSelectMany</font>
|
||||
is derived from class <font color="#009900">eoSelect</font> and takes in
|
||||
its constructor an <font color="#009900">eoSelectOne</font> (plus the number
|
||||
of individuals it should select, according to the <a href="#howmany">eoHowMany</a>
|
||||
paradigm).
|
||||
<p><b><font color="#FF0000">Note</font></b>: some procedures for selecting
|
||||
a single individual require some pre-processing of the whole population
|
||||
that takes place before any selection, and will be repeated identically
|
||||
for every individual. The encapsulation of an into an allows
|
||||
to call such technical processing only once through the use of method setup
|
||||
of class . This method does nothing by default, but is mandatory
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoSelect: </font><font color="#FF0000">Other
|
||||
instances</font></b>
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoDetSelect</font></tt></b> selects individuals
|
||||
<b><font color="#FF6600">deterministically</font></b>,
|
||||
i.e. starting from the best ones down to the worse ones. If the total number
|
||||
to select is less than the size of the source populations, the best individuals
|
||||
are selected once. If more individuals are needed after reaching the bottom
|
||||
of the population, then the selection starts again at top. It the total
|
||||
number required is N times that of the source size, all individuals are
|
||||
selected exactly N times.</li>
|
||||
</ul>
|
||||
No other instances of <font color="#009900">eoSelect</font> that are not
|
||||
encapsualtions of <font color="#009900">eoSelectOne</font> procedures are
|
||||
avaiable as of today (Jan. 4 2001).
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="replacement"></a><b><font color="#000099"><font size=+2>Replacement</font></font></b>
|
||||
<p>The replacement phase takes plac<font color="#000000">e after the birth
|
||||
of all offspring through </font>variation operators. This is the second
|
||||
step of the <font color="#009900">artificial Darwinism</font>, where the
|
||||
<i><font color="#FF6600">fittest
|
||||
individuals are allowed to survive</font></i>.
|
||||
<br>It can also be viewed on the algorithmic side as closing the generation
|
||||
loop, i.e. building the population that will be the initial population
|
||||
of next generation. That population will be <font color="#FF6600">built
|
||||
upon the old parents and the new-born offspring</font>. In all algorithms
|
||||
that come up with EO, the <font color="#FF6600">population size</font>
|
||||
is supposed to be <font color="#FF6600">constant</font> from one generation
|
||||
to the next one - though nothing stops you from writing an algorithm with
|
||||
varying population size.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">Replacement: </font><font color="#FF0000">The
|
||||
interface</font></b>
|
||||
<p>The abstract class for replacement procedures is the functor class
|
||||
<font color="#009900">eoReplacement</font>,
|
||||
and the interface for its <tt><font color="#993300">operator()</font></tt>
|
||||
is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">void operator()(eoPop<EOT>& _parents,
|
||||
eoPop<EOT>& _offspring)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_replacement.html">eoReplacement</a></font></font></b>.,
|
||||
as you see there that <font color="#009900">eoReplacement</font> derives
|
||||
from <tt><font color="#993300">class eoBF<eoPop<EOT>&, eoPop<EOT>&,
|
||||
void></font></tt>.
|
||||
<br>This means that it takes <font color="#FF6600">2 populations</font>
|
||||
(called, for obvious anthropomorphic reasons, _parents and _offspring :-)
|
||||
and is free to modify both, but the resulting population should be placed
|
||||
in the first argument (usually called_parents) to close the loop and go
|
||||
to next generation.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">Replacement: </font><font color="#FF0000">Instances</font></b>
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoGenerationalReplacement </font></tt></b>This
|
||||
is the most straightforward replacement, called <font color="#FF6600">generational
|
||||
replacement</font>: all offspring replace all parents (used in Holland's
|
||||
and Goldberg's traditional GAs). It takes no argument, and supposes
|
||||
that offspring and parents are of the same size (but does not check!).</li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<a NAME="SSGA"></a><b><tt><font color="#009900">eoMergeReduce</font></tt></b>
|
||||
This is one the basic types of replacement in EO. It has two major steps,
|
||||
<font color="#FF6600">merging</font>
|
||||
both populations of parents and offspring, and <font color="#FF6600">reducing</font>
|
||||
this big population to the right size. It <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_merge_reduce.html">contains
|
||||
two objects</a></font></font> of respective types <b><font color="#009900"><a href="#merge">eoMerge</a></font></b>
|
||||
and <b><font color="#009900"><a href="#reduce">eoReduce</a></font></b>
|
||||
and you can probably guess what each of them actually does :-)</li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<br>
|
||||
<br>
|
||||
<p>Available <font color="#FF6600">instances of eoMergeReduce</font> replacement
|
||||
include
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoCommaReplacement</font></tt></b>, one of
|
||||
the two standard strategies in <font color="#000000">Evolution Strategies</font>,
|
||||
<b><font color="#FF6600">selects
|
||||
the best offspring</font></b>. It is an
|
||||
<b><tt><font color="#993300">eoMergeReduce(eoNoElitism,
|
||||
eoTruncate)</font></tt></b>.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoPlusReplacement</font></tt></b>, the other
|
||||
standar<font color="#000000">d Evolution Startegies repla</font>cement,
|
||||
where <b><font color="#FF6600">the best from offspring+parents</font></b>
|
||||
become the next generation. It is an <b><tt><font color="#993300">eoMergeReduce(eoPlus,
|
||||
eoTruncate)</font></tt></b>.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoEPReplacement</font></tt></b>, used in th<font color="#000000">e
|
||||
Evolutionary Programming historical </font>algorithm, does an EP stochastic
|
||||
tournament among parents + offspring. It is an <b><tt><font color="#993300">eoMergeReduce(eoPlus,
|
||||
eoEPReduce)</font></tt></b> and its constructor requires as argument T,
|
||||
the size of the tournament (unsigned int).</li>
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoReduceMerge</font></tt></b> is another important
|
||||
type of eoReplacement: the parents are first reduced, and then merged with
|
||||
the offspring. Note that the parent population is reduced of the exact
|
||||
number of offspring.</li>
|
||||
|
||||
<br>Though not mandatory, it is implicitely assumed that few offspring
|
||||
have been generated. Hence, all derived replacement procedures of class
|
||||
<b><tt><font color="#009900">eoReduceMerge</font></tt></b>
|
||||
are termed <b><tt><font color="#009900">eoSSGAxxx</font></tt></b>, as they
|
||||
are the ones to use in SteadyState Genetic Algorithm engine. This gives
|
||||
the following <font color="#FF6600">instances of eoReduceMerge</font>:
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoSSGAWorseReplacement</font></tt></b>
|
||||
in which the worse parents are killed and replaced by all offsprings (no
|
||||
additional argument needed);</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoSSGADetTournamentReplacement</font></tt></b>
|
||||
in which parents to be killed are chosen by a (reverse) determinitic tournament.
|
||||
Additional parameter (in the constructor) is the tournament size, an <b><tt><font color="#993300">unsigned
|
||||
int</font></tt></b>.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoSSGAStochTournamentReplacement</font></tt></b>
|
||||
in which parents to be killed are chosen by a (reverse) stochastic tournament.
|
||||
Additional parameter (in the constructor) is the tournament rate, a <b><tt><font color="#993300">double</font></tt></b>.</li>
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
<a NAME="SADreplacement"></a><b><tt><font color="#009900">eoSurviveAndDie</font></tt></b>
|
||||
replacement strategies are a generalization of both the above that allows
|
||||
strong elitist and eugenism in both the parent population and the offspring
|
||||
population. The <b><tt><font color="#009900"><a href="#SAD">eoSurviveAndDie</a></font></tt></b>
|
||||
building block takes one population, kills the worse and moves the best
|
||||
to some safe place. The corresponding replacements apply an <b><tt><font color="#009900">eoSurviveAndDie</font></tt></b>
|
||||
to the parents, another one to the offspring, and finally merges the remaining
|
||||
parents and offspring before reducing the resulting population to the right
|
||||
size. Available instances of <b><tt><font color="#009900">eoSurviveAndDieReplacement</font></tt></b>
|
||||
are limited todayto the <b><tt><font color="#009900">eoDeterministicSaDReplacement</font></tt></b>,
|
||||
the that uses a deterministic MergeReduce.</li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<br>
|
||||
<br>
|
||||
<p><b><font color="#FF0000">Note</font></b>: The basic use (and initial
|
||||
motivation) for <b><tt><font color="#009900">eoSurviveAndDie</font></tt></b>
|
||||
takes 2 arguments, an eoMergeReduce and a number of surviving parents.
|
||||
It starts by copying the best parents to the new populations, then merges
|
||||
the remaining parents with the offspring before reducing to the number
|
||||
of remaining seats in the new population.</ul>
|
||||
|
||||
<hr WIDTH="50%">
|
||||
<br><a NAME="weakelitism"></a><b><font color="#000099">Replacement: </font><font color="#FF0000">Adding
|
||||
(weak) elitism</font></b>
|
||||
<p>You can add what is called <font color="#FF6600">weak elitism</font>
|
||||
to any replacement by encapsulating it into an <b><tt><font color="#009900">eoWeakElitismReplacement</font></tt></b>
|
||||
object. Weak elitism ensures that the overall <font color="#FF6600">best
|
||||
fitness</font> in the population <font color="#FF6600">will never decrease</font>:
|
||||
if the best fitness in the new population is less than the best fitness
|
||||
of the parent population, then the best parent is added back to the new
|
||||
population, replacing the worse.
|
||||
<p>Within EO, this is very easy to add:
|
||||
<p>First, declare your replacement functor (here, generational, but it
|
||||
can be any replacement object):
|
||||
<br><b><tt><font color="#009900">eoGenerationalReplacement<Indi> genReplace;</font></tt></b>
|
||||
<br>Then wrap the weak elitism around it:
|
||||
<br><b><tt><font color="#009900">eoWeakElitismReplacement<Indi> replace(genReplace);</font></tt></b>
|
||||
<br>and use now replace as your replacement procedure within your algorithm.
|
||||
<p><font color="#FF0000">Note</font>: of course, adding weak elitism to
|
||||
an elitist replacement makes no sense - but will not harm either :-)
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">Replacement: </font><font color="#FF0000">Test
|
||||
file</font></b>
|
||||
<p>The file <b><tt><font color="#993300">t-eoReplacement</font></tt></b>
|
||||
in the <b><font color="#FF6600">test directory</font></b> implements all
|
||||
above replacement procedures within a very simple and easy-to-monitor Dummy
|
||||
EO class.
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="general"></a><b><font color="#000099"><font size=+2>General
|
||||
Replacement: eoReduceMergeReduce</font></font></b>
|
||||
<p>In an attempt to unify all the well-known replacements, plus most of
|
||||
the less-known-though-often-used, the <b><tt><font color="#009900">eoReduceMergeReduce</font></tt></b>
|
||||
replacement has been designed, and supersedes all of the above instances.
|
||||
<br>It allows to implement <b><font color="#FF0000">strong elistism</font></b>
|
||||
(i.e. some parents survive, whatever their fitness and that of the offspring),
|
||||
as well as multiple weak elistism (the best parents are put back in the
|
||||
next population if they outperform the best offspring).
|
||||
<p>Basically, an <b><tt><font color="#009900">eoReduceMergeReduce</font></tt></b>
|
||||
starts by eventually preserving the (strong) elite parents, proceeds by
|
||||
reducing both the parent and offspring populations, merges those populations,
|
||||
and eventually reduces the resulting populations (augmented with the elite
|
||||
parents) to the right size. Last, the weak elitism is taken care of if
|
||||
necessary.
|
||||
<br>The following image, taken from the graphical interface of EASEA, somehow
|
||||
demonstrates the different parameters of an <b><tt><font color="#009900">eoReduceMergeReduce.</font></tt></b>
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoReduceMergeReduce: </font><font color="#FF0000">The
|
||||
interface</font></b>
|
||||
<br>Of course the interface is that of eoReplacement. Let's concentrate
|
||||
on the constructor.
|
||||
<p>The constructor takes 6 arguments:
|
||||
<ol>
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoHowMany elite</font></tt></b> determines
|
||||
the number of parents to be treated as elite (actual behavior determined
|
||||
by next parameter) using the <a href="#howmany">eoHowMany</a> behavior.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#993300">bool strongElitism</font></tt></b> tells whether
|
||||
the elite above corresponds to strong (true) or false(weak) elitism.</li>
|
||||
|
||||
<br><b><font color="#FF0000">Note</font></b>: the case of no elitism is
|
||||
obtained by setting elite to 0
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoHowMany reducedParents </font></tt></b>gives
|
||||
the number of parents remaining after reducing them</li>
|
||||
|
||||
<br><b><font color="#FF0000">Note</font></b>: 0 means that no parent survive
|
||||
(except the possible elite), as in <b><tt><font color="#009900">eoCommaReplacement</font></tt></b>
|
||||
<br>
|
||||
-1 is used inside <b><tt><font color="#009900">eoSSGAReplacement</font></tt></b>s
|
||||
(one parent is killed to make room for the newborn)
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoReduce<EOT> & reduceParents</font></tt></b>
|
||||
indicates how the parents will be reduced (see <a href="#reduce">available
|
||||
instances</a>).</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoHowMany reducedOffspring </font></tt></b>gives
|
||||
the number of offspring remaining after reducing them</li>
|
||||
|
||||
<br><b><font color="#FF0000">Note</font></b>: 0 is impossible (no evolution!!!)
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoReduce<EOT> & reduceOffspring</font></tt></b>
|
||||
indicates how the offspring will be reduced (see <a href="#reduce">available
|
||||
instances</a>).</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoReduce<EOT> & reduceFinal</font></tt></b>
|
||||
indicates how the merged reduced-parents/reduced-offspring will be reduced
|
||||
(see <a href="#reduce">available instances</a>).</li>
|
||||
|
||||
<br><b><font color="#FF0000">Note</font></b>: the number of individuals
|
||||
remaining after that reduction is of course the original size of the population.</ol>
|
||||
All popular evolution engines use some replacement procedure that can be
|
||||
viewed as an instance of an <b><tt><font color="#009900">eoReduceMergeReduce</font></tt></b>.
|
||||
<br>Moreover, a <b><font color="#FF0000">parser-based</font></b> input
|
||||
of a general is proposed in file do/make_checkpoint.h.
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="popular"></a><b><font color="#000099"><font size=+2>Popular
|
||||
evolution engines</font></font></b>
|
||||
<p>The most popular evolution engines are listed below, together with the
|
||||
way to use them in EO. If you don't find your particuler algorithm, please
|
||||
send it to us, and we might include it here! In the following, P will denote
|
||||
the number of individuals in the initial population.
|
||||
<ul>
|
||||
<li>
|
||||
<a NAME="GGA"></a><b><font color="#000099">Generational Genetic Algorihtm</font></b><font color="#000000">:
|
||||
popularized by Holland (75) and Goldberg (89), it uses</font></li>
|
||||
|
||||
<br><font color="#FF0000">Number of offspring: </font><font color="#000000">
|
||||
P</font>
|
||||
<br><font color="#FF0000">Selection:</font><font color="#000000"> Proportional
|
||||
(the historical roulette wheel) </font><b><font color="#FF6600">when maximizing
|
||||
a positive scalar fitness</font></b><font color="#000000">, ranking or
|
||||
tournament (stochatic or deterministic) in all cases.</font>
|
||||
<br><font color="#FF0000">Replacement:</font><font color="#000000"> Generational.</font>
|
||||
<br><font color="#FF0000">Remark:</font><font color="#000000"> You could
|
||||
use also the </font><b><tt><font color="#009900">eoCommaReplacement</font></tt></b><font color="#000000">,
|
||||
with exactly the same result as there are as many offspring as we need
|
||||
indiviudals in the next population. And using the </font><b><tt><font color="#009900">eoSSGAWorseReplacement</font></tt></b><font color="#000000">
|
||||
would also give the same result, but would be very inefficient!</font>
|
||||
<br><font color="#000000">You can also add <a href="#weakelitism">weak
|
||||
elitism</a> to preserve the best individual.</font>
|
||||
<li>
|
||||
<a NAME="SSGA"></a><b><font color="#000099">Steady-State Genetic Algorithm</font></b><font color="#000000">:
|
||||
widely used in GA/GP community</font></li>
|
||||
|
||||
<br><font color="#FF0000">Number of offspring: </font><font color="#000000">
|
||||
small (historically, 1)</font>
|
||||
<br><font color="#FF0000">Selection:</font><font color="#000000"> tournament
|
||||
(you can use ranking or proportional, but it will be rather inefficient).</font>
|
||||
<br><font color="#FF0000">Replacement:</font><font color="#000000"> An
|
||||
eoSSGAxxxReplacement.</font>
|
||||
<br><font color="#FF0000">Remark:</font><font color="#000000"> You can
|
||||
also use the eoPlusReplacement, but you divert from the original SSGA</font>
|
||||
<li>
|
||||
<a NAME="ESPlus"></a><b><font color="#000099">(MU+Lambda)-Evolution Strategy</font></b><font color="#000000">:
|
||||
The elitist ES strategy (Rechenberg 71 and Schwefel 81)</font></li>
|
||||
|
||||
<br><font color="#FF0000">Number of offspring: </font><font color="#000000">
|
||||
Any</font>
|
||||
<br><font color="#FF0000">Selection:</font><font color="#000000"> eoDetSelect
|
||||
(batch deterministic).</font>
|
||||
<br><font color="#FF0000">Replacement:</font><font color="#000000"> eoPlusReplacement</font>
|
||||
<br><font color="#FF0000">Remark:</font><font color="#000000"> You could
|
||||
also use eoEPReplacement, to smoothen the selective pressure during replacement,
|
||||
thus getting close to EP evolution engine</font>
|
||||
<li>
|
||||
<a NAME="ESComma"></a><b><font color="#000099">(MU,Lambda)-Evolution Strategy</font></b><font color="#000000">:
|
||||
The non-elitist ES strategy</font></li>
|
||||
|
||||
<br><font color="#FF0000">Number of offspring: </font><font color="#000000">
|
||||
> P</font>
|
||||
<br><font color="#FF0000">Selection:</font><font color="#000000"> eoDetSelect
|
||||
(batch deterministic).</font>
|
||||
<br><font color="#FF0000">Replacement:</font><font color="#000000"> eoCommaReplacement</font>
|
||||
<br><font color="#FF0000">Remark:</font><font color="#000000"> You can
|
||||
also add <a href="#weakelitism">weak elitism</a> to preserve the best individual
|
||||
- though you'd probably use the plus strategy if you want (strong) elitism.</font>
|
||||
<li>
|
||||
<a NAME="EP"></a><b><font color="#000099">Evolutionary Programming</font></b><font color="#000000">:
|
||||
The historical method of L. Fogel (65)</font></li>
|
||||
|
||||
<br><font color="#FF0000">Number of offspring: </font><font color="#000000">
|
||||
P</font>
|
||||
<br><font color="#FF0000">Selection:</font><font color="#000000"> eoDetSelect
|
||||
(batch deterministic). Every individual reproduces exactly once.</font>
|
||||
<br><font color="#FF0000">Replacement:</font><font color="#000000"> eoEPReplacement,
|
||||
though one historical replacement was the determnistic replacement - i.e.
|
||||
in EO the eoPlusReplacement).</font>
|
||||
<br><font color="#FF0000">Remark:</font><font color="#000000"> Close to
|
||||
an (P+P)-ES</font>
|
||||
<li>
|
||||
<a NAME="General"></a><font color="#FF0000">You name it :-)</font><font color="#000000">:
|
||||
you can of course choose whatever combination you like - respecting a few
|
||||
constraints and common-sense remarks. For instance, eoProportionalSelect
|
||||
should be used only when maximizing a positive fitness, eoCommaReplacement
|
||||
requires more offspring than parents, and, over all, existing EO algorithms
|
||||
wirk with fixed size population - and it is your responsability to use
|
||||
a cmbinatino of selection/replacement that fulfills this requirement (or
|
||||
to create your own eoAlgo that handles varying size populations).</font></li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="tournament"></a><b><font color="#000099"><font size=+2>Tournaments</font></font></b>
|
||||
<p>Tournaments are an easy and quick way to <b><font color="#FF6600">select</font></b>
|
||||
individuals within a population based on simple comparisons. Though usually
|
||||
based on fitness comparisons, they can use any comparison operator.
|
||||
<br>In EO, there are two variants of tournaments used to select one single
|
||||
individual, namely <b><tt><font color="#009900">Deterministic Tournament</font></tt></b>
|
||||
and <b><tt><font color="#009900">Stochastic Tournament</font></tt></b>,
|
||||
that are used in selection and in replacement procedures, and a global
|
||||
tournament-based selection of a whole bunch of individuals, the <b><tt><font color="#009900">EP
|
||||
Tournament</font></tt></b>. Though the single-selection tournaments can
|
||||
be repeated to select more than one individual, and the batch tournament
|
||||
selection can be used to select a single individual, both uses are probably
|
||||
a waste of CPU time.
|
||||
<ul>
|
||||
<li>
|
||||
<a NAME="detTournament"></a><b><tt><font color="#009900">Deterministic
|
||||
Tournament</font></tt></b> of size T returns the best of T uniformly chosen
|
||||
individuals in the population. Its size T should be an integer >= 2. It
|
||||
is implemented in the <b><tt><font color="#009900">eoDetTournamentSelect</font></tt></b>
|
||||
class, a sub-class of eoSelectOne, as well as in the <b><tt><font color="#009900">eoDetTournamentTruncate</font></tt></b>
|
||||
class that repeatidly removes from the population the "winner" of the inverse
|
||||
tournament. These objects use the C++ function determinitic_tournament
|
||||
in <a href="../../doc/html/selectors_h-source.html">selectors.h</a>.</li>
|
||||
|
||||
<li>
|
||||
<a NAME="stochTournament"></a><b><tt><font color="#009900">Stochastic Tournament</font></tt></b>
|
||||
of rate R first choses two individuals from the population, and selects
|
||||
the best one with probability R (the worse one with probability 1-R). Real
|
||||
parameter R should be in [0.5,1]. It is implemented in the <b><tt><font color="#009900">eoStochTournamentSelect</font></tt></b>
|
||||
class, a sub-class of eoSelectOne, as well as in the <b><tt><font color="#009900">eoStochTournamentTruncate</font></tt></b>
|
||||
class that repeatidly removes from the population the "winner" of the inverse
|
||||
tournament. These objects use the C++ function determinitic_tournament
|
||||
in <a href="../../doc/html/selectors_h-source.html">selectors.h</a>.</li>
|
||||
|
||||
<br><b><font color="#FF0000">Note</font></b>: A stochastic tournament with
|
||||
rate 1.0 is strictly identical to a deterministic tournament of size 2.
|
||||
<li>
|
||||
<a NAME="EPTournament"></a><b><tt><font color="#009900">EP Tournament</font></tt></b>
|
||||
of size T is a global tournament: it works by assigning a score to all
|
||||
individuals in the population the following way: starting with a score
|
||||
of 0, each individual I is "opposed" T times to a uniformly chosen individual.
|
||||
Everytime I wins, its score in incremented by 1 (and by 0.5 for every draw).
|
||||
The individuals are then selected deterministically based on their scores
|
||||
from that procedure. The <b><tt><font color="#009900">EP Tournament</font></tt></b>
|
||||
is implemented in the <b><tt><font color="#009900">eoEPReduce</font></tt></b>
|
||||
truncation method used in the <b><tt><font color="#009900">eoEPReplacement</font></tt></b>
|
||||
procedure.</li>
|
||||
|
||||
<br><b><font color="#FF0000">Note</font></b>: whereas both the determinitic
|
||||
and the stochastic tournament select one individual, the EP tournament
|
||||
is designed for batch selection. Of course it could be used to select a
|
||||
single individual, but at a rather high computational cost.</ul>
|
||||
|
||||
<p><br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="merge"></a><b><font color="#000099"><font size=+2>Merging
|
||||
populations</font></font></b>
|
||||
<p>In replacement procedures, one frequently needs to merge two populations
|
||||
(computed form old parents and new-born offspring). Classes derived from
|
||||
the abstract class eoMerge are written for that purpose.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoMerge</font></b>: <b><font color="#FF0000">interface</font></b>
|
||||
<br>The abstract class for merging procedures is the functor class
|
||||
<font color="#009900">eoMerge</font>,
|
||||
and the interface for its <tt><font color="#993300">operator()</font></tt>
|
||||
is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">void operator()(const eoPop<EOT>&
|
||||
_parents, eoPop<EOT>& _offspring)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_merge.html">eoMerge</a></font></font></b>,
|
||||
as you see there that <font color="#009900">eoMerge</font> derives from
|
||||
<br><tt><font color="#993300">class eoBF<const eoPop<EOT>&, eoPop<EOT>&,
|
||||
void></font></tt>.
|
||||
<br>This means that it takes <font color="#FF6600">2 populations</font>
|
||||
and modifies the seond one by adding some individuals from the first one
|
||||
(which is supposed to remain <b><tt><font color="#993300">const</font></tt></b>ant).
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoMerge</font></b>: <b><font color="#FF0000">instances</font></b>
|
||||
<br>Available <font color="#FF6600">instances of eoMerge</font> objects
|
||||
are <b><tt><font color="#009900">eoPlus</font></tt></b>, that simply adds
|
||||
the parents to the offspring, or <b><tt><font color="#009900">eoElitism</font></tt></b>,
|
||||
that adds only some of the (best) parents to the offspring. A special case
|
||||
of eoElistism is <b><tt><font color="#009900">eoNoElitism</font></tt></b>,
|
||||
an eoMerge that does nothing.
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="reduce"></a><b><font color="#000099"><font size=+2>Reducing
|
||||
populations</font></font></b>
|
||||
<p>The other useful component of replacement procedures, <font color="#009900">eoReduce</font>,
|
||||
<font color="#FF6600">kills
|
||||
some individuals</font> from a given population.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoReduce</font></b>: <b><font color="#FF0000">interface</font></b>
|
||||
<br>The abstract class for reducing procedures is the functor class
|
||||
<font color="#009900">eoReduce</font>,
|
||||
and the interface for its <tt><font color="#993300">operator()</font></tt>
|
||||
is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">void operator()(eoPop<EOT>& _parents,
|
||||
unsigned int new_size)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_reduce.html">eoReduce</a></font></font></b>,
|
||||
as you see there that <font color="#009900">eoReduce</font> derives from
|
||||
<br><tt><font color="#993300">class eoBF<eoPop<EOT>&, unsigned
|
||||
int, void></font></tt>.
|
||||
<br>An <font color="#009900">eoReduce</font> shoud take a<font color="#FF6600">
|
||||
population</font> and shrink it to the required size.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoReduce</font></b>: <b><font color="#FF0000">instances</font></b>
|
||||
<br>Available <font color="#FF6600">instances of eoReduce</font> are
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoTruncate</font></tt></b>, deterministically
|
||||
kills the worse individuals, keeping only the required number. It starts
|
||||
by sorting teh populations, and hence does <font color="#FF6600">modify
|
||||
its order</font>.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoLinearTruncate</font></tt></b>, deterministically
|
||||
kills the worse individuals, keeping only the required number. It does
|
||||
so by repeatedly removing the worsr individual. Hence does <font color="#FF6600">not
|
||||
modify its order</font>, but takes longer time than <b><tt><font color="#009900">eoTruncate</font></tt></b>
|
||||
in case of many offspring.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoEPReduce</font></tt></b>, uses the <a href="#EPtournament">EP
|
||||
stochastic tournament</a> to reduce the population. It requires an additinal
|
||||
argument, the tournament size.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoDetTournamentTruncate</font></tt></b> uses
|
||||
inverse deterministic tournament to repeatidly kill one individual until
|
||||
the propoer size is reached. As <b><tt><font color="#009900">eoLinearTruncate</font></tt></b>,
|
||||
it might take some time in the case of many offspring. It requires the
|
||||
size of the tournament (<b><tt><font color="#993300">unsigned int</font></tt></b>)
|
||||
as parameter in the constructor (default is 2).</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#009900">eoStochTournamentruncate</font></tt></b>
|
||||
uses inverse stochastic tournament to repeatidly kill individuals from
|
||||
the population. It requires the rate of the tournament (<b><tt><font color="#993300">double</font></tt></b>)
|
||||
as parameter in the constructor (default is 0.75).</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="howmany"></a><b><font color="#000099"><font size=+2>eoHowMany:
|
||||
Choosing a number of individuals</font></font></b>
|
||||
<p>Many classes in selection/replacement procedures will handle a number
|
||||
of individuals that may either be fixed or be related to some argument-population
|
||||
size.
|
||||
<br>Of course, it is possible to write different classes that will only
|
||||
differ by the way they compute the number of individuals they have to treat,
|
||||
as it is done for selectors with the two classes <font color="#009900">eoSelectPerc</font>
|
||||
and <font color="#009900">eoSelectNumber</font> (it could also have been
|
||||
possible to have some pure abstrat class and implement the computation
|
||||
of the number of individuals to treat in some derived classes).
|
||||
<br>However, the class <b><tt><font color="#993300">eoHowMany</font></tt></b>
|
||||
allows one to handle in a single class three different behaviors when given
|
||||
a poopulatio size as argument:
|
||||
<ul>
|
||||
<li>
|
||||
return a given rate of the argument population size</li>
|
||||
|
||||
<li>
|
||||
return an absolute (unsigned) integer, whatever the argument population
|
||||
size</li>
|
||||
|
||||
<li>
|
||||
return the argument population size minus a given number</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="50%">
|
||||
<br><b><font color="#000099">eoHowMany</font></b>: <b><font color="#FF0000">interface</font></b>
|
||||
<br>The class interface for its <tt><font color="#993300">operator()</font></tt>
|
||||
is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">unsigned int operator()(unsigned int _pop_size)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_how_many.html">eoHowMany</a></font></font></b>,
|
||||
as you see there that <b><tt><font color="#993300">eoHowMany</font></tt></b>
|
||||
derives from
|
||||
<br><tt><font color="#993300">class eoUF<unsigned int, unsigned int></font></tt>.
|
||||
<p>It has 3 possible constructors, that determine its behavior:
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoHowMany(double _rate, bool _interpret_as_rate
|
||||
= true)</font></tt></b> where <b><tt><font color="#993300">_rate</font></tt></b>
|
||||
is by default the fixed rate of behavior 1 above. However, if the boolean
|
||||
second argument is false, the rate is transformed into a positive integer,
|
||||
and is used for behavior 2 above</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoHowMany(int _combien)</font></tt></b>: if
|
||||
<b><tt><font color="#993300">_combien</font></tt></b>
|
||||
is positive, it is the absolute number of behavior 2 above, and if <b><tt><font color="#993300">_combien</font></tt></b>
|
||||
is negative, its absolute value is used to decrease the argument population
|
||||
in behavior 3 above</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#993300">eoHowMany(unsigned int _combien)</font></tt></b>:
|
||||
<b><tt><font color="#993300">_combien</font></tt></b>
|
||||
(positive!) is the absolute number of behavior 2 above. <b><font color="#FF6600">Note</font></b>
|
||||
that this constructor is mandatory to avoid ambiguity, as an unsigned int
|
||||
can be casted to either an int or a double.</li>
|
||||
</ul>
|
||||
It is used in <font color="#009900">eoSelectMany</font> (which supersedes
|
||||
<font color="#009900">eoSelectPerc</font>
|
||||
and <font color="#009900">eoSelectNumber</font>, but they are left there
|
||||
for tutorial reasons!) as well as in many <a href="#reduce">truncation</a>
|
||||
methods, and it is used a lot in the eoGeneralReplacement construct.
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="SAD"></a><b><font color="#000099"><font size=+2>Survive and
|
||||
Die</font></font></b>
|
||||
<br>This class is highly politically incorrect: it implements strong elitism
|
||||
and eugenism :-)
|
||||
<br>It starts by killing the worse individuals from the source argument,
|
||||
then appends the best ones to the destination argument and removes them
|
||||
from the source argument. It is used in <b><tt><a href="#SADreplacement">eoSurviveAndDieReplacement</a></tt></b>,
|
||||
where the same dest is used successively for the parents and the offspring.
|
||||
<p><b><font color="#000099">eoSurviveAndDie</font></b>: <b><font color="#FF0000">interface</font></b>
|
||||
<br>The class interface for its <tt><font color="#993300">operator()</font></tt>
|
||||
is
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">void operator()(eoPop<EOT>& _source,
|
||||
eoPop<EOT>& _dest)</font></tt></b></center>
|
||||
|
||||
<p>which you could have guessed from the inheritance tree for class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_survive_and_die.html">eoSurviveAndDie</a></font></font></b>,
|
||||
as you see there that <b><tt><font color="#993300">eoSurviveAndDie</font></tt></b>
|
||||
derives from <tt><font color="#993300">class eoBF<eoPop<EOT>&,
|
||||
eoPop<EOT>&, void></font></tt>.
|
||||
<p>Its constructor takes 3 argumenrts:
|
||||
<center>
|
||||
<p><b><tt><font color="#993300">eoHowMany(double _survive, double _die,
|
||||
bool _interpret_as_rate = true)</font></tt></b></center>
|
||||
|
||||
<p>to indicate how many (or what proportion, according to <b><tt><font color="#993300">_interpret_as_rate</font></tt></b>)
|
||||
of the source should be copied to the dest population, and how many (or
|
||||
what proportion, according to <b><tt><font color="#993300">_interpret_as_rate</font></tt></b>)
|
||||
should be erased from the source.
|
||||
<p>
|
||||
<hr WIDTH="100%"><b><font color="#CC0000">Local: </font></b><a href="#introduction">Introduction</a>
|
||||
- <a href="#selection">Selection</a> - <a href="#replacement">Replacement</a>
|
||||
- <a href="#general">General Replacement</a> - <a href="#popular">Popular
|
||||
evolution engines</a> - <a href="#tournament">Tournaments</a> - <a href="#merge">Merge</a>
|
||||
- <a href="#reduce">Reduce</a> - <a href="#howmany">HowMany</a> - <a href="#SAD">SurviveAndDie</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#CC0000">General: </font></b><a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b>
|
||||
<hr WIDTH="100%">
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
|
||||
<br><!-- Created: Mon Oct 30 07:27:13 CET 2000 --><!-- hhmts start -->Last
|
||||
modified: Tue. Jan. 9 2001 <!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
34
eo/tutorial/html/eoEval.html
Normal file
34
eo/tutorial/html/eoEval.html
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Evaluation</title>
|
||||
</head>
|
||||
|
||||
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoTutorial.html">Tutorial main page </a>-
|
||||
<a href="eoTopDown.html">Algorithm-Based
|
||||
page</a> - <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <a href="../../doc/html/index.html">EO documentation</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
|
||||
<center>
|
||||
<h1><font color="#FF0000">Evaluation</font></h1>
|
||||
</center>
|
||||
|
||||
|
||||
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<a href="eoTutorial.html">Tutorial main page </a>-
|
||||
<a href="eoTopDown.html">Algorithm-Based
|
||||
page</a> - <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <a href="../../doc/html/index.html">EO documentation</a>
|
||||
<hr>
|
||||
<address><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<!-- Created: Mon Oct 30 17:51:43 CET 2000 -->
|
||||
<!-- hhmts start -->
|
||||
Last modified: Mon Nov 6 10:54:33 CET 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
19
eo/tutorial/html/eoGeneration.html
Normal file
19
eo/tutorial/html/eoGeneration.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Generation</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Generation</h1>
|
||||
|
||||
|
||||
|
||||
<hr>
|
||||
<address><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<!-- Created: Mon Oct 30 19:29:28 CET 2000 -->
|
||||
<!-- hhmts start -->
|
||||
Last modified: Mon Oct 30 19:29:29 CET 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
36
eo/tutorial/html/eoInit.html
Normal file
36
eo/tutorial/html/eoInit.html
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Initialization</title>
|
||||
</head>
|
||||
<body text="#000000" background="beige009.jpg" link="#0000EE" vlink="#551A8B" alink="#FF0000">
|
||||
<a href="eoTutorial.html">Tutorial main page </a>-
|
||||
<a href="eoTopDown.html">Algorithm-Based
|
||||
page</a> - <a href="eoBottomUp.html">Component-Based</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>
|
||||
<b><font color="#CC0000">Initialization</font></b></h1></center>
|
||||
|
||||
|
||||
|
||||
<!-- Bottom of file: display some links and address -->
|
||||
<!-- ----------------------------------------------- -->
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<a href="eoTutorial.html">Tutorial main page </a>- <a href="eoTopDown.html">Algorithm-Based
|
||||
page</a> - <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> - <a href="../../doc/html/index.html">EO documentation</a>
|
||||
<hr>
|
||||
<address>
|
||||
<a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<!-- Created: Mon Oct 30 17:51:29 CET 2000 -->
|
||||
<!-- hhmts start -->
|
||||
Last modified: Mon Nov 6 11:25:18 CET 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue