Migration from SVN
This commit is contained in:
parent
d7d6c3a217
commit
8cd56f37db
29069 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>
|
||||
25
eo/tutorial/html/eoIo.html
Normal file
25
eo/tutorial/html/eoIo.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Input / Output</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Input / Output</h1>
|
||||
|
||||
<p>
|
||||
<A NAME=stop>
|
||||
<h3>Stopping criteria</h3>
|
||||
|
||||
<p>
|
||||
<A NAME=output>
|
||||
<h3>Displaying statistics</h3>
|
||||
|
||||
<hr>
|
||||
<address><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<!-- Created: Mon Oct 30 19:29:46 CET 2000 -->
|
||||
<!-- hhmts start -->
|
||||
Last modified: Tue Oct 31 18:32:22 CET 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
440
eo/tutorial/html/eoLesson1.html
Normal file
440
eo/tutorial/html/eoLesson1.html
Normal file
|
|
@ -0,0 +1,440 @@
|
|||
<!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>Tutorial: Lesson 1</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<a href="eoLesson2.html">Lesson 2</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"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Tutorial: Lesson 1</font></h1></center>
|
||||
This lesson will let you
|
||||
<ul>
|
||||
<li>
|
||||
<a href="#run">run</a> your first Evolutionary Algorithm written within
|
||||
EO Library, choosing between evolving <font color="#999900">bitstrings</font>,
|
||||
or evolving <font color="#999900">vectors of real numbers</font>,</li>
|
||||
|
||||
<li>
|
||||
<a href="#browse">browse</a> through the code of these algorithms, or</li>
|
||||
|
||||
<li>
|
||||
follow the <a href="#tour">guided tour</a>.</li>
|
||||
</ul>
|
||||
Later you will be asked to
|
||||
<ul>
|
||||
<li>
|
||||
<a href="#exercise1">write</a> your own <font color="#990000">fitness function</font>,</li>
|
||||
|
||||
<li>
|
||||
<a href="#exercise2">check</a> that EO let you separate the <font color="#999900">representation</font>
|
||||
from the <font color="#009900">evolution engine</font>.</li>
|
||||
|
||||
<li>
|
||||
<a href="#exercise3">use different kinds</a> of <font color="#009900">selection
|
||||
procedures</font> in the framework of a generational GA <font color="#009900">evolution
|
||||
engine</font>,</li>
|
||||
</ul>
|
||||
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="run"></a><font color="#000099">I want to run
|
||||
an Evolutionary Algorithm
|
||||
<b>now</b></font></h3>
|
||||
You can choose to run a standard <a href="FirstBitGA.html">bitstring Genetic
|
||||
Algorithm</a> (as defined in Goldberg's book) or a standard <a href="FirstRealGA.html">real-valued
|
||||
genetic algorithm</a>, as proposed in Micahlewicz's book.
|
||||
<p>If you have not already done what was recommended in the <a href="eoTutorial.html#install">Tutorial
|
||||
main page</a> , do it <b><font color="#FF6600">NOW</font></b>. Then go
|
||||
to the Lesson1 sub-dir of the tutorial dir, and simply type at the system
|
||||
prompt
|
||||
<p><tt>(myname@myhost) EOdir/Tutorial/Lesson1 % <font color="#FF6666">FirstRealGA</font></tt>
|
||||
<br>or
|
||||
<br><tt>(myname@myhost) EOdir/Tutorial/Lesson1 % <font color="#FF6666">FirstBitGA</font></tt>
|
||||
<p>and something should happen.
|
||||
<h3>
|
||||
<font color="#000099">What is happening?</font></h3>
|
||||
At the moment, the <font color="#FF6600">FirstBitGA</font> maximizes the
|
||||
number of ones in the bitstring (also calls the <font color="#FF6600">OneMaxfunction</font>,
|
||||
whose solution is, as you can guess,
|
||||
<font color="#FF6600">11111111</font>),
|
||||
and the <font color="#FF6600">FirstRealGA</font> is maximizing (the default
|
||||
action for EO is to maximize) the inverse of the sum (i.e. minimizing the
|
||||
sum) of the square of its variables (also called the <font color="#FF6600">sphere
|
||||
function</font>, whose solution is ... <font color="#FF6600">all zeroes</font>).
|
||||
<p>And what you see on the screen when running one of these two programs
|
||||
is, in each case, the initial and final population of an Evolutionary run,
|
||||
one individual per line, its fitness first, then the number of items (bits
|
||||
or real numbers) of the genotype, and the genotype itself. The final population
|
||||
hopefully contains the solution in the discrete case, and is close to it
|
||||
in the continuous case.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="browse"></a><b><font color="#000099"><font size=+1>Browsing
|
||||
the code:</font></font></b>
|
||||
<p>Now you need to take a look at the program codes, either by browsing
|
||||
alone through the sources for <a href="FirstBitGA.html">FirstBitGA</a>
|
||||
and <a href="FirstRealGA.html">FirstRealGA</a>, or by following the guided
|
||||
tour below. You might prefer to go directly to the <a href="#exercise1">exercises</a>.
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="tour"></a><font color="#000099">Guided tour:</font></h3>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<b><font color="#993300">General includes:</font></b><font color="#000000">Like
|
||||
all C-like code, the file starts with include directives (<a href="FirstBitGA.html#start">Bit</a>
|
||||
- <a href="FirstRealGA.html#start">Real</a>). Apart from standard includes,
|
||||
the specific file to include is </font><b><font color="#FF6600">eo</font></b><font color="#000000">:
|
||||
this is a file that contains the list of the all important representation-independent
|
||||
EO files.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#999900">Representation</font></b><font color="#000000">:
|
||||
you then have to declare the type of individuals you will be handling.
|
||||
All evolution-related objects you will need are templatized w.r.t. the
|
||||
type of individuals.</font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a href="FirstBitGA.html#representation">Bit</a> You first need to include
|
||||
the representation-dependent file <b><tt><font color="#993300"><font size=+1>ga.h</font></font></tt></b>,
|
||||
containing the bitstring representation and operators. More details about
|
||||
<a href="eoRepresentation.html#bitstring">what is available for bitstrings
|
||||
here</a>.<br>
|
||||
You then say that you will be handling <b><font face="Arial,Helvetica"><a href="../../doc/html/classeo_bit.html">Bitstring
|
||||
genotypes</a></font></b>, whose fitness is a double. This makes Indi derive
|
||||
from the <a href="eoProgramming.html#STL">STL class</a> <font color="#993300">vector<bool></font></li>
|
||||
|
||||
<li>
|
||||
<a href="FirstRealGA.html#representation">Real</a> You first need to include
|
||||
the representation-dependent file <b><tt><font color="#993300"><font size=+1>es.h</font></font></tt></b>,
|
||||
containing the bitstring representation and operators. More details about
|
||||
<a href="eoRepresentation.html#real">what is available for real-values
|
||||
here</a>.<br>
|
||||
You then say that you will be handling <b><font face="Arial,Helvetica"><a href="../../doc/html/classeo_real.html">Real-valued
|
||||
genotypes</a></font></b>, whose fitness is a double. This makes Indi derive
|
||||
from the <a href="eoProgramming.html#STL">STL class</a> <font color="#993300">vector<double></font></li>
|
||||
|
||||
<br> </ul>
|
||||
|
||||
<li>
|
||||
<b><font color="#CC0000">Fitness function:</font></b><font color="#000000">
|
||||
the code for the fitness function is included in the file. It must take
|
||||
as argument a reference to an individual (at the moment).</font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a href="FirstBitGA.html#evalfunc">Bit</a> This function simply computes
|
||||
the number of ones of the bitstring (it's called the OneMax function).
|
||||
The optimum is of course the all-ones bitstring.</li>
|
||||
|
||||
<li>
|
||||
<a href="FirstRealGA.html#evalfunc">Real</a> This function simply computes
|
||||
the inverse of the sum of the squares of all variables (also called the
|
||||
sphere function). The optimum is of course the all-zeroes vector.</li>
|
||||
|
||||
<br> </ul>
|
||||
|
||||
<li>
|
||||
<a NAME="parametres"></a><b><font color="#3366FF">Parameters</font></b><font color="#000000">:
|
||||
all parameters of the algorithm are declared here (<a href="FirstBitGA.html#parametres">Bit</a>
|
||||
- <a href="FirstRealGA.html#parametres">Real</a>), and their values and
|
||||
assigned. Of course, this means that you will need to recompile to change
|
||||
these values - see Lesson 3 to get rid of that heavy requirement.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#990000">Random seeding:</font></b><font color="#000000">
|
||||
Random numbers play an important role in Evolutionary Algorithms. See in
|
||||
<a href="eoProgramming.html#random">EO
|
||||
programming hints</a> more details about how this is simulated in EO -
|
||||
but as far as you are concerned now, remember that the </font><font color="#660000">global
|
||||
Random Number Generator</font><font color="#000000"> is called </font><b><tt><font color="#660000"><font size=+1>rng</font></font></tt></b><font color="#000000">
|
||||
and should be used everywhere you need a realization of a random variable
|
||||
of known law. Moreover, this RNG requires a </font><b><tt><font color="#660000"><font size=+1>seed</font></font></tt></b><font color="#000000">,
|
||||
which is set here (<a href="FirstBitGA.html#random">Bit</a> - <a href="FirstRealGA.html#random">Real</a>):
|
||||
every time you run the algorithm with the </font><font color="#FF6600">same
|
||||
seed</font><font color="#000000">, you will get the </font><font color="#FF6600">same
|
||||
result</font><font color="#000000">. Hence, to test the robustness of your
|
||||
algorithm, you should run it with different seeds. This is rather time
|
||||
consuming in the present programs, so we suggest that you wait until Lesson
|
||||
3 to do so.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#CC0000">Fitness function encapsulation: </font></b><font color="#000000">EO
|
||||
is based on the notion of <a href="eoProgramming.html#functors">functors</a>
|
||||
- hence you now need to encapsulate your fitness function into a functor
|
||||
object. This is what is done here (<a href="FirstBitGA.html#eval">Bit</a>
|
||||
- <a href="FirstRealGA.html#eval">Real</a>).</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#CC33CC">Initialization</font></b><font color="#000000">:
|
||||
to initialize the population, first declare an empty object of class </font><b><tt><font color="#990000">eoPop<Indi></font></tt></b><font color="#000000">,
|
||||
which is basically an <a href="eoProgramming.html#STL">STL</a> </font><b><tt><font color="#990000">vector<Indi></font></tt></b><font color="#000000">,
|
||||
then fill it with Indi's.</font> And remember that
|
||||
<b><tt><font color="#990000">v.push_back</font></tt></b>
|
||||
simply appends its argument at the end of <a href="eoProgramming.html#STL">STL</a>
|
||||
vector <b><tt><font color="#993300">v.</font></tt></b></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a href="FirstBitGA.html#init">Bit</a> <b><tt><font color="#990000">rng.flip()</font></tt></b>
|
||||
return a <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_rng.html">random
|
||||
boolean</a></font></font></li>
|
||||
|
||||
<li>
|
||||
<a href="FirstRealGA.html#init">Real</a> <b><tt><font color="#990000">rng.uniform()</font></tt></b>
|
||||
returns a <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_rng.html">real
|
||||
value uniformly drawn in [0,1].</a></font></font></li>
|
||||
|
||||
<br> </ul>
|
||||
|
||||
<li>
|
||||
<b><font color="#3366FF">Output</font></b><font color="#000000">: take
|
||||
a snapshot at the initial population (<a href="FirstBitGA.html#output">Bit</a>
|
||||
- <a href="FirstRealGA.html#output">Real</a>). Sort it first, so the best
|
||||
individuals are first, and display it. Note that an eoPop has a </font><b><tt><font color="#990000"><<</font></tt></b><font color="#000000">
|
||||
method, which means that a simple </font><b><tt><font color="#990000">os
|
||||
<< pop </font></tt></b><font color="#000000">streams the </font><b><tt><font color="#990000">pop</font></tt></b><font color="#000000">
|
||||
onto the ostream </font><b><tt><font color="#990000">os</font></tt></b><font color="#000000">.
|
||||
This is true for </font><font color="#FF6600">all objects of of class </font><font color="#000000"><b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_printable.html">eoPrintable</a></font></font></b>
|
||||
(most EO objects) through the method </font><b><tt><font color="#990000">printOn</font></tt></b><font color="#000000">
|
||||
(which is then called by the </font><b><tt><font color="#990000"><<</font></tt></b><font color="#000000">
|
||||
operator).</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#009900">Evolution engine:</font></b><font color="#000000">
|
||||
The selection/replacement mechanism (<a href="FirstBitGA.html#engine">Bit</a>
|
||||
- <a href="FirstRealGA.html#engine">Real</a>) is a simple generational
|
||||
GA here: a simple selector, and a generational replacement. The <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_det_tournament_select.html">eoDetTournamentSelect</a></font></font></b>
|
||||
has been chosen as a robust selection, and the generational replacement
|
||||
(all parents are replaced by the offspring) is hard-coded in the eoSGA
|
||||
<a href="#algorithm">algorithm</a>.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<font color="#CC33CC"><b>Variation operators</b>:</font><font color="#000000">
|
||||
in the simple algorithm considered here, individuals undergo </font><font color="#CC33CC">crossover</font><font color="#000000">
|
||||
and </font><font color="#CC33CC">mutation</font><font color="#000000">.
|
||||
In EO, these operators are (<a href="eoProgramming.html#functors">functor</a>)
|
||||
objects of class</font> <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_quad_op.html">eoQuadOp</a></font></font></b>
|
||||
(binary operator that modifies both its arguments) and <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b>
|
||||
(unary operator). These operators are applied in turn to all selected
|
||||
parents, according to user-defined probabilities. These probabilities
|
||||
are defined with all other <a href="#parametres">parameters</a>, and will
|
||||
be passed to the <b><tt><font color="#FF6666"><font size=+1>eoSGA </font></font></tt></b><a href="#parametres">algorithm</a><font color="#000000">.
|
||||
For more details on these classes, go to the <a href="eoOperators.html#crossover">algorithm-based
|
||||
corresponding pages</a>, or to their respective documentation pages.</font></li>
|
||||
|
||||
<br>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="FirstBitGA.html#operators">Bit</a> The crossover <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo1_pt_bit_crossover.html">eo1PtBitXover</a></font></font></b>
|
||||
is the standard <font color="#CC33CC">1-point crossover</font>, and <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_bit_mutation.html">eoBitMutation</a></font></font></b>
|
||||
is the standard <font color="#FF6600">bit-flip mutation</font> that randomly
|
||||
flips all bits with a given probability <b><tt>P_MUT_PER_BIT.</tt></b></li>
|
||||
|
||||
<br><b><font color="#FF0000">Warning</font></b>: the <b><tt>P_MUT_PER_BIT</tt></b>
|
||||
probability is an <font color="#FF6600">internal parameter</font> of the
|
||||
<b><tt><font color="#CC33CC"><font size=+1>eoBinMutation</font></font></tt></b>,
|
||||
it is <b><font color="#FF6600">NOT</font></b> the probability of mutation
|
||||
at the individual level. EO corrects what can be viewed as an inconsistency
|
||||
in Holland's original work, further used in Goldberg's book by separating
|
||||
the probability of mutation for each individual (independent of the type
|
||||
of mutation that will be applied) from the probability of flipping each
|
||||
bit, which is specific of the bit-flip mutation. Hence, to run the
|
||||
same algorithm as Goldberg's SGA, the mutation probability (at individual
|
||||
level) is 1, and the probability of flipping each bit is <b><tt>P_MUT_PER_BIT.</tt></b>
|
||||
<li>
|
||||
<a href="FirstRealGA.html#operators">Real</a> The crossover <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_segment_crossover.html">eoSegmentCrossover</a></font></font></b>
|
||||
is the standard <font color="#CC33CC">segment crossover</font> for real-valued
|
||||
vectors, that chooses a point randomly on the segment between both parents
|
||||
(also termed <font color="#CC33CC">BLX-0</font>). <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_uniform_mutation.html">eoUniformMutation</a></font></font></b>
|
||||
is the <font color="#CC33CC">uniform mutation</font> for real-valued vectors
|
||||
that chooses a new value for each variable uniformly on an interval centered
|
||||
on the parent value. The width of the interval is an <font color="#FF6600">internal
|
||||
parameter</font> of the object, here called <b><tt>EPSILON</tt></b>.</li>
|
||||
|
||||
<br> </ul>
|
||||
|
||||
<li>
|
||||
<b><font color="#3366FF">Stopping criterion:</font></b><font color="#000000">
|
||||
Specify a </font><font color="#3366FF">maximum number of generations</font><font color="#000000">
|
||||
to run (<a href="FirstBitGA.html#stop">Bit</a> - <a href="FirstRealGA.html#stop">Real</a>):
|
||||
the simplest of all stopping criteria at the moment, using an object of
|
||||
a sub-class of class </font><b><font face="Arial,Helvetica"><font color="#3366FF"><font size=+1><a href="../../doc/html/classeo_continue.html">eoContinue</a></font></font></font></b><font color="#000000">.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<a NAME="algorithm"></a><b><font color="#FF6666">The algorithm: </font></b><font color="#000000">the
|
||||
simple algorithm that is used here, called </font><b><tt><font color="#FF6666"><font size=+1>eoSGA
|
||||
</font></font></tt></b><font color="#000000">requires
|
||||
as parameters a </font><font color="#FF6600">selector</font><font color="#000000">,
|
||||
a </font><font color="#FF6600">crossover</font><font color="#000000"> and
|
||||
the associated </font><font color="#FF6600">crossover rate</font><font color="#000000">,
|
||||
a </font><font color="#FF6600">mutation</font><font color="#000000"> and
|
||||
the associated </font><font color="#FF6600">mutation rate,</font><font color="#000000">
|
||||
and a </font><font color="#FF6600">stopping criterion</font><font color="#000000">.
|
||||
Take a look at the corresponding
|
||||
<a href="eoSGA.html#constructor">constructor</a>
|
||||
of the class </font><b><tt><font color="#FF6666"><font size=+1>eoSGA</font></font></tt></b><font color="#000000">:
|
||||
it only initializes its <a href="eoSGA.html#parametres">private data</a>
|
||||
with the parameters. Now look at the <a href="eoSGA.html#generation">operator()</a>
|
||||
method - the one that is called in the code for <a href="FirstBitGA.html#generation">FirstBitGA</a>
|
||||
or <a href="FirstRealGA.html#generation">FirstRealGA</a> - and you'll find
|
||||
out that is is as simple as it sounds.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#3366FF">Output</font></b><font color="#000000">: After
|
||||
running the algorithm, output the sorted final population (<a href="FirstBitGA.html#final_output">Bit</a>
|
||||
- <a href="FirstRealGA.html#final_output">Real</a>) - and look at the best
|
||||
individual: this is the result of the algorithm.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<b><font color="#990000">Main body:</font></b><font color="#000000"> for
|
||||
technical reasons (intercepting the exceptions), we need a main like this
|
||||
one (<a href="FirstBitGA.html#main">Bit</a> - <a href="FirstRealGA.html#main">Real</a>).,
|
||||
and you should not touch it unless you know what you are doing. Simply
|
||||
note that this main calls the function main_function, which we have been
|
||||
discussing up to now!</font></li>
|
||||
</ul>
|
||||
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="exercise1"></a><font color="#000099">Exercise
|
||||
1: maximize your own function</font></h3>
|
||||
This is very easy - if your search space is that of bitstring or of unbounded
|
||||
real numbers.
|
||||
<ul>
|
||||
<li>
|
||||
Go to the tutorial directory, and <font color="#FF6600">copy</font> the
|
||||
program you want to modify onto <b><tt><font color="#663300">mytest.cpp.</font></tt></b></li>
|
||||
|
||||
<li>
|
||||
<font color="#FF6600">Edit</font> <b><tt><font color="#990000">mytest.cpp</font></tt></b>
|
||||
with any text editor:</li>
|
||||
|
||||
<li>
|
||||
<font color="#FF6600">Modify</font> the fitness function itself (<a href="FirstBitGA.html#evalfunc">binary_value</a>
|
||||
in <font color="#FF6666"><b><tt>FirstBitGA</tt></b><font face="Courier New,Courier">,</font></font><a href="FirstRealGA.html#evalfunc">real_value</a>
|
||||
in <font color="#FF6666"><b><tt>FirstRealGA</tt></b><font face="Courier New,Courier">)</font></font></li>
|
||||
|
||||
<li>
|
||||
<font color="#FF6600">Compile</font> the program by typing <b><tt><font color="#990000">make
|
||||
mytest</font></tt></b> at system prompt</li>
|
||||
|
||||
<li>
|
||||
<font color="#FF6600">Run</font> the new program by entering the command
|
||||
<b><tt><font color="#990000">mytest</font></tt></b>
|
||||
at system prompt.</li>
|
||||
</ul>
|
||||
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="exercise2"></a><font color="#000099">Exercise
|
||||
2: check the differences between both programs</font></h3>
|
||||
Go and take a look at the code for these programs <font color="#000000">(<a href="FirstBitGA.html">Bit</a>
|
||||
- <a href="FirstRealGA.html">Real</a>)</font>. Use the symbolic representation
|
||||
of an Evolutionary Algorithm (you should understand that figure now, otherwise
|
||||
go <a href="eoIntro.html">there</a> and come back) to understand how each
|
||||
part of the EA is coded. Try to spot the differences between both codes:
|
||||
there are not so many!
|
||||
<br>After you've tried that alone, take a look at the <a href="Firstmerge.html">solution</a>
|
||||
:-)
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="exercise3"></a><font color="#000099">Exercise
|
||||
3: change the selection procedure</font></h3>
|
||||
This is rather straightforward ... if you know what other types of selection
|
||||
are available!
|
||||
<br>At the moment, let's only consider only the following simple ones:
|
||||
<ul>
|
||||
<li>
|
||||
You already know the <font color="#FF6600">tournament selection</font></li>
|
||||
|
||||
<br><font color="#FF0000">Syntax: </font><tt><font color="#009900"><b>eoDetTournamentSelect<Indi>
|
||||
select(T_SIZE); </b>// T_SIZE in [2,POP_SIZE)</font></tt>
|
||||
<li>
|
||||
Try the well-known <font color="#FF6600">roulette wheel</font></li>
|
||||
|
||||
<br> <font color="#FF0000">Syntax: </font> <b><tt><font color="#009900">eoProportionalSelect<Indi>
|
||||
select;</font></tt></b>
|
||||
<li>
|
||||
Or the <font color="#FF6600">stochastic binary tournament</font></li>
|
||||
|
||||
<br><font color="#FF0000">Syntax: </font><b><tt><font color="#009900">eoStochTournamentSelect<Indi>
|
||||
select(RATE); </font></tt></b><tt><font color="#009900">
|
||||
// RATE in ]0.5,1]</font></tt>
|
||||
<li>
|
||||
and of course the <font color="#FF6600">random</font> selection should
|
||||
give bad results!</li>
|
||||
|
||||
<br><font color="#FF0000">Syntax: </font><b><tt><font color="#009900">eoRandomSelect<Indi>
|
||||
select;</font></tt></b></ul>
|
||||
Note that all these classes of eoObjects are derived from the abstract
|
||||
class
|
||||
<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_select_one.html">eoSelectOne.</a></font></font></b>
|
||||
To find out exactly how each procedure selects the individuals, read the
|
||||
corresponding <a href="eoEngine.html#selection">component-based page</a>.
|
||||
<p>
|
||||
<hr WIDTH="100%"><b><font color="#000099"><font size=+2>Lessons learned:</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
in EO, all actions are performed by <a href="eoProgramming.html#functors">functor
|
||||
objects</a> (this section is the last time in this tutorial that there
|
||||
is a direct link to the <a href="eoProgramming.html">EO Programming hints</a>
|
||||
page - though the link at top and bottom of all pages will remain there).</li>
|
||||
|
||||
<li>
|
||||
in EO, all object you will usually need to manipulate are <a href="eoProgramming.html#templates">templatized</a><b><font color="#FF6600">
|
||||
w.r.t. the type of the individual</font></b> you are handling.</li>
|
||||
|
||||
<li>
|
||||
The type of the individual is itself <a href="eoProgramming.html#templates">templatized</a><b><font color="#FF6600">
|
||||
w.r.t. the type of fitness</font></b> (double by default).</li>
|
||||
|
||||
<li>
|
||||
In EO (actually, in EC!) <font color="#CC33CC">initialization and variation</font>
|
||||
operators are <font color="#999900">representation</font>-dependent, while
|
||||
the <font color="#009900">evolution engine</font> is <font color="#999900">representation</font>-independent
|
||||
(well, like any rule, this one does have some exceptions).</li>
|
||||
|
||||
<li>
|
||||
Changing the <font color="#990000">fitness function</font>, or the <font color="#009900">selection
|
||||
procedure</font> inside the generational GA evolution engine is straightforward.</li>
|
||||
|
||||
<li>
|
||||
remember, all <font color="#FF6600">solutions</font> to exercises are in
|
||||
the same sub-dir of dir Tutorial than the lesson itself (see <a href="NoWay.html">here</a>).</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson2.html">Lesson 2</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"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font>
|
||||
<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>
|
||||
357
eo/tutorial/html/eoLesson2.html
Normal file
357
eo/tutorial/html/eoLesson2.html
Normal file
|
|
@ -0,0 +1,357 @@
|
|||
<!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>Tutorial: Lesson 2</title>
|
||||
<!-- Changed by: Marc Schoenauer, 29-Nov-2000 -->
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<a href="eoLesson1.html">Lesson 1</a> -
|
||||
<a href="eoLesson3.html">Lesson
|
||||
3</a> -
|
||||
<a href="eoTutorial.html">Main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Hints</a>
|
||||
-<font size=+1> <b><font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></b></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Tutorial Lesson 2: more encapsulations</font></h1></center>
|
||||
In this lesson, the same Evolutionary Algorithm will be rewritten in a
|
||||
much more general context.
|
||||
<br>First, look at the <a href="#changes">changes</a> that have been done
|
||||
to the algorithms. Then benefit from the new features by
|
||||
<ul>
|
||||
<li>
|
||||
<a href="#minimize">minimizing</a> (and not only maximize) the fitness</li>
|
||||
|
||||
<li>
|
||||
<a href="#combined_operators">combining</a> <font color="#CC33CC">several
|
||||
operators</font> of the same type</li>
|
||||
|
||||
<li>
|
||||
<a href="#combinedContinue">combining</a> <font color="#3366FF">several
|
||||
stopping criteria</font></li>
|
||||
|
||||
<li>
|
||||
use <font color="#009900"><a href="#evolution">alternate</a> selection/replacement</font>
|
||||
engines, deviating from the pure generational GA</li>
|
||||
</ul>
|
||||
|
||||
<p><br>Again, two basic algorithms are provided, namely <a href="FirstBitEA.html">FirstBitEA</a>
|
||||
and <a href="FirstRealEA.html">FirstRealEA</a>.
|
||||
<br><font color="#FF6600">To compile and run</font> them, go to the <font color="#FF6600">Lesson2
|
||||
sub-directory</font> of the tutorial dir and simply type <b><tt><font color="#990000"><font size=+1>make</font></font></tt></b>.
|
||||
Both examples should get compiled, and you can then run them by calling
|
||||
their name from the system prompt.
|
||||
<p>Note the slim difference in names, from <font color="#FF6600">GA</font>
|
||||
to <font color="#FF6600">EA</font>: the behavior of these EAs is
|
||||
almost identical to that of their GA counterpart, at least with the default
|
||||
settings that are provided. But their potentialities for easy modifications
|
||||
are much larger, both in terms of <b><font color="#CC33CC">variation operators</font></b>
|
||||
and of <b><font color="#009900">evolution engine</font></b> (i.e. <font color="#009900">selection/replacement</font>
|
||||
mechanism).
|
||||
<hr WIDTH="100%"><a NAME="changes"></a><b><font color="#000099"><font size=+2>Changes</font></font></b>
|
||||
<p>Browse through the code, and discover them one after the other:
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">The</font><font color="#CC0000"> fitness function
|
||||
</font><font color="#000000">now
|
||||
lies in a </font><b><font color="#CC0000">separate file
|
||||
</font></b><font color="#000000">(<a href="FirstBitEA.html#evalfunc">Bit</a>
|
||||
- <a href="FirstRealEA.html#evalfunc">Real</a>). But, more important, its
|
||||
argument is a <a href="binary_value.html">vector<bool></a> or a <a href="real_value.html">vector<double></a>,
|
||||
and not an unknown type. This will allow to use the same file for any EO
|
||||
object that is a sub-class of the corresponding STL vector class.</font></li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<p><b><font color="#FF0000">Note:</font></b> <font color="#000000">Also,
|
||||
a non-templatized fitness can be </font><b><font color="#FF6600">compiled
|
||||
separately</font></b><font color="#000000"> (not done here) into an object
|
||||
file once and for all (<a href="eoProgramming.html#templates">remember</a>
|
||||
that templates forbid that).</font>
|
||||
<br>
|
||||
<li>
|
||||
<a NAME="minimize"></a><font color="#000000">The </font><font color="#CC0000"><b>encapsulation
|
||||
</b>of
|
||||
the fitness </font><font color="#000000">(<a href="FirstBitEA.html#eval">Bit</a>
|
||||
- <a href="FirstRealEA.html#eval">Real</a>) looks more complicated: you
|
||||
have to declare 3 template arguments: the type of EO object it will be
|
||||
applied to, the return type and the type of argument the function actually
|
||||
requires.</font></li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<p><b><font color="#FF0000">Note:</font></b> <font color="#000000">In the
|
||||
previous files (<a href="FirstBitGA.html#eval">Bit</a> - <a href="FirstRealGA.html#eval">Real</a>)
|
||||
, the last 2 types were deduced from the first (2nd argument = fitness
|
||||
type of EO object, third = first).</font>
|
||||
<br>
|
||||
<li>
|
||||
<font color="#000000">Both the above modifications makes it very easy to
|
||||
</font><b><font color="#CC0000">minimize</font></b><font color="#000000">
|
||||
rather than maximize a fitness function (see <a href="#Execrise1">Exercise
|
||||
1)</a>.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<font color="#000000">The</font><font color="#CC33CC"> initialization</font><font color="#000000">
|
||||
of the population is now </font><b><font color="#CC33CC">encapsulated</font></b><font color="#000000">into
|
||||
a </font><font color="#CC33CC"><b>separate initializer</b> </font><font color="#000000">(based
|
||||
on a <a href="FirstBitEA.html#init">boolean generator</a> or a <a href="FirstRealEA.html#init">double-number
|
||||
generator</a> -see <a href="../../doc/html/class_random_generator.html">random_generators.h</a>)
|
||||
that is then used in the constructor of the population to build the individuals.
|
||||
You can also use different initializers and call them in turn through the
|
||||
call to <a href="../../doc/html/classeo_pop.html#a2">pop.append()</a> function
|
||||
(see <a href="#exercise2">Exercise 2</a>).</font></li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<p><b><font color="#FF0000">Note</font><font color="#CC33CC">: </font></b><font color="#000000">Don't
|
||||
forget to </font><b><font color="#CC0000">evaluate the population</font></b><font color="#000000">:
|
||||
the eoPop has no idea of the eval function, so it has to be done from outside!!!</font>
|
||||
<br>
|
||||
<li>
|
||||
<a NAME="combined_operators"></a><font color="#000000">You can now use
|
||||
</font><font color="#CC33CC"><b>different
|
||||
</b>crossover
|
||||
</font><font color="#000000">and</font><font color="#CC33CC">
|
||||
mutation
|
||||
<b>operators</b></font><font color="#000000">in the same algorithm,
|
||||
choosing among them according to
|
||||
</font><b><font color="#FF6600">relative
|
||||
weights.</font></b><font color="#CC33CC"> </font><font color="#000000">The
|
||||
class </font><font color="#CC33CC"><b>eoPropCombinedxxxOp</b>,
|
||||
</font><font color="#000000">where
|
||||
xxx is either Mon (for mutations, of class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b></font><font color="#CC33CC">)</font><font color="#000000">
|
||||
or Quad (for crossovers, of class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_quad_op.html">eoQuadOp</a></font></font></b>),
|
||||
is derived from the corresponding eoxxxOp class. When applying the eoPropCombinedxxxOp,
|
||||
one of the eoxxxOp it contains is chosen by a <a href="../../doc/html/classeo_rng.html#a12">roulette
|
||||
wheel,</a> according to their respective rates, and is applied to the arguments.
|
||||
For more details on these classes, go to the <a href="eoOperators.html#crossover">algorithm-based
|
||||
corresponding pages</a>, or to their respective documentation pages.</font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000"><a href="FirstBitEA.html#operators">Bit</a></font></li>
|
||||
|
||||
<br><font color="#000000">Three </font><b><font color="#FF6600">crossover
|
||||
operators</font></b><font color="#000000"> are available: the </font><font color="#FF6600">one-point</font><font color="#000000">
|
||||
crossover is still there (class ), but now you also have the </font><font color="#FF6600">N-point</font><font color="#000000">
|
||||
crossover </font><font color="#CC33CC">eoBinNxOver</font><font color="#000000">
|
||||
(the number of points is 2 by default, but as always you can change
|
||||
that in the constructor), and the </font><font color="#FF6600">Uniform</font><font color="#000000">
|
||||
crossover </font><font color="#CC33CC">eoBinUxOver</font><font color="#000000">
|
||||
(where you can eventually twidle the choice from one parent to the other
|
||||
by providing a probability in the constructore - defaulted to 0.5, which
|
||||
amounts to symmetrical choice).</font>
|
||||
<br><font color="#000000">As for </font><b><font color="#FF6600">mutation
|
||||
operators</font></b><font color="#000000">, apart from the </font><font color="#CC33CC">eoBinMutation</font><font color="#000000">
|
||||
(standard bitstring mutation flipping one bit with a given probability)
|
||||
you can also use the </font><font color="#CC33CC">eoDetBitFlip</font><font color="#000000">
|
||||
that always filps the same number of bits (1 by default, but you can change
|
||||
that in the constructor), randomly chosen in the bitstring. Even though
|
||||
the average number of bits flipped is the same if the </font><font color="#CC33CC">eoBinMutation
|
||||
</font><font color="#000000">is
|
||||
used with a rate of 1/N (N is the bitstring length) </font><font color="#FF6600">the
|
||||
behavior of these mutation can be very different</font><font color="#000000">
|
||||
on many problems.</font>
|
||||
<li>
|
||||
<font color="#000000"><a href="FirstRealEA.html#operators">Real</a></font></li>
|
||||
|
||||
<br><font color="#000000">Two </font><b><font color="#FF6600">crossover
|
||||
operators</font></b><font color="#000000"> are available: the </font><font color="#CC33CC">eoSegmentCrossover</font><font color="#000000">
|
||||
chooses one point uniformly on the segment joining the parents, while the
|
||||
</font><font color="#CC33CC">eoHypercubeCrossover</font><font color="#000000">
|
||||
performs a linear combination on each coordinate independently, which amount
|
||||
to choosing the offspring uniformly in the hypercube whose diagonal is
|
||||
the segment joining the parents.</font>
|
||||
<br><font color="#000000">As for </font><b><font color="#FF6600">mutation
|
||||
operators</font></b><font color="#000000">, apart from the </font><font color="#CC33CC">eoBinMutation</font><font color="#000000">
|
||||
(standard bitstring mutation flipping one bit with a given probability)
|
||||
you can also use the </font><font color="#CC33CC">eoDetBitFlip</font><font color="#000000">
|
||||
that always filps the same number of bits (1 by default, but you can change
|
||||
that in the constructor), randomly chosen in the bitstring. And last but
|
||||
not least, the normal mutation eoNormMutation modifies all coordinates
|
||||
with a Gaussian noise, with standard deviation passed in the constructor.</font></ul>
|
||||
<b><font color="#FF0000">Note:</font></b> A third optional argument in
|
||||
method <b><tt><font color="#660000">add</font></tt></b> is a boolean (defaulted
|
||||
to false). When true, the actual rates for all operators are displayed
|
||||
on the screen as percentages: you don't have to input rates that sum up
|
||||
to 1, all rates are scaled anyway.
|
||||
<p><a NAME="transform"></a><b><font color="#FF0000">Note:</font></b> The
|
||||
operators have to be encapsulated into an <b><tt><font color="#CC33CC">eoTransform</font></tt></b>
|
||||
object (<a href="FirstBitEA.html#transform">Bit</a> - <a href="FirstRealEA.html#transform">Real</a>)
|
||||
to be passed to the <b><tt><font color="#FF6666">eoEasyEA </font></tt></b>algorithm.
|
||||
The <b><tt><font color="#CC33CC">eoSGATransform</font></tt></b> is a simple
|
||||
<b><tt><font color="#CC33CC">eoTransform</font></tt></b>
|
||||
that does exactly the same thing than <b><tt><font color="#FF6666">eoSGA</font></tt></b>:
|
||||
each pair from the selected parents undergoes the <font color="#CC33CC">crossover
|
||||
operator with given probability</font>, and all individuals (after crossover
|
||||
eventually) undergo <font color="#CC33CC">mutation with given probability</font>.
|
||||
The arguments to the <b><tt><font color="#CC33CC">eoSGATransform</font></tt></b>
|
||||
are an <b><tt><font color="#CC33CC">eoQuadOp</font></tt></b> with its probability
|
||||
and an <b><tt><font color="#CC33CC">eoMonOp</font></tt></b> with the associated
|
||||
probability.
|
||||
<br>
|
||||
<li>
|
||||
<a NAME="combinedContinue"></a><font color="#000000">You can use </font><b><font color="#3366FF">combinations
|
||||
</font></b><font color="#000000">of
|
||||
several stopping criteria by using an object of the class </font><b><tt><font color="#3366FF">eoCombinedContinue
|
||||
</font></tt></b><font color="#000000">(<a href="FirstBitEA.html#stop">Bit</a>
|
||||
- <a href="FirstRealEA.html#stop">Real</a>). Initialize it with an object
|
||||
of class </font><font color="#3366FF"><b><tt>eoContinue</tt></b>, </font><font color="#000000">and
|
||||
</font><b><tt><font color="#3366FF">add</font></tt></b><font color="#000000">
|
||||
as many of other such objects as you wish. And as an </font><b><tt><font color="#3366FF">eoCombinedContinue
|
||||
</font></tt><font color="#FF6600">is
|
||||
an</font><tt><font color="#3366FF"> eoContinue</font></tt></b><font color="#000000">,
|
||||
simply pass it to the algorithm (<a href="FirstBitEA.html#generation">Bit</a>
|
||||
- <a href="FirstRealEA.html#generation">Real</a>). To find out more, and
|
||||
to get the list and syntax of existing eoContinue subclasses, check out
|
||||
the corresponding <a href="eoCheckPoint.html#existingContinue">component-based
|
||||
page</a>.</font></li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
<a NAME="evolution"></a><font color="#000000">The</font><b><font color="#009900">
|
||||
full selection/replacement mechanism </font></b><font color="#000000">is
|
||||
now in place through the </font><font color="#FF6666"><b><tt>eoEasyEA</tt></b>
|
||||
algorithm.</font></li>
|
||||
|
||||
<br>This means that you can use different <font color="#009900">selectors</font>.
|
||||
which was already true in Lesson 1, but also different <font color="#009900">replacement
|
||||
strategies</font> (see <a href="#Exercise3">Exercise 3</a>) whereas <font color="#009900">generational
|
||||
replacement</font> was hard-coded in the algorithm <b><tt><font color="#FF6666">eoSGA</font></tt></b>
|
||||
used in Lesson1.
|
||||
<p>Beware that we have to encapsulate <font color="#000000">(<a href="FirstBitEA.html#select_encapsulate">Bit</a>
|
||||
- <a href="FirstRealEA.html#select_encapsulate">Real</a>) </font>the <font color="#FF6600">eoDetTournament</font>,
|
||||
which is of class <font color="#FF6600">eoSelectOne</font> (i.e. allows
|
||||
to select one individual from a population, its <b><tt><font color="#660000">operator()</font></tt></b>
|
||||
returning a single individual) into an object of the <font color="#FF6600">eoSelectPerc</font>
|
||||
(perc stands for percentage) which allows to select a ... percentage of
|
||||
a population (his <b><tt><font color="#660000">operator()</font></tt></b>
|
||||
returns a population). This was done internally in the <a href="../../doc/html/classeo_s_g_a.html#a0">constructor
|
||||
of eoSGA</a> - see lesson1.</ul>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="Exercise1"></a><b><font size=+2><font color="#000099">Exercise
|
||||
1: </font><font color="#FF0000">minimizing</font></font></b>
|
||||
<br><font color="#000000">Modify the algorithm so that it minimizes the
|
||||
fitness.</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">For the bitstring case, you only have to modify the
|
||||
<a href="FirstBitEA.html#representation">declaration
|
||||
of the representation</a>, using </font><b><tt><font color="#999900">eoMinimizingFitness</font></tt></b><font color="#000000">
|
||||
instead of </font><b><tt><font color="#999900">double</font></tt></b><font color="#000000">.
|
||||
But is that really all? Give it a try, look at the output, and do it right
|
||||
the second time!!!</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">For the real-valued problem, you also need to modify
|
||||
the file <b><tt><a href="real_value.html">real_value.h</a></tt></b> so
|
||||
that it returns the sum of squares instead of its inverse. And again there
|
||||
is something else to modify...</font></li>
|
||||
</ul>
|
||||
<a NAME="exercise2"></a><b><font size=+2><font color="#000099">Exercise
|
||||
2: </font><font color="#FF0000">initialization</font></font></b>
|
||||
<br><font color="#000000">Use different initializers: for instance, on
|
||||
the real-valued sphere function minimization, try to initialize half of
|
||||
the population in [-2,-1] and the other half in [1,2], with and without
|
||||
the segment and hypercube crossovers (and for large values of VEC_SIZE,
|
||||
the size of the vectors). Amazing, isn't it! Explain that result.</font>
|
||||
<p><a NAME="Exercise3"></a><b><font size=+2><font color="#000099">Exercise
|
||||
3: </font><font color="#FF0000">full selection/replacement</font></font></b>
|
||||
<br><font color="#000000">You can now twiddle the number of offspring that
|
||||
will be generated from the parents. But of course you need to adjust the
|
||||
replacement to keep a constant population size.</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">To </font><font color="#FF6600">modify the number
|
||||
of offspring</font><font color="#000000">, use the second argument of the
|
||||
</font>encapsulator<font color="#000000">
|
||||
(<a href="FirstBitEA.html#select_encapsulate">Bit</a> - <a href="FirstRealEA.html#select_encapsulate">Real</a>)
|
||||
of the </font><font color="#009900">selector</font><font color="#000000">
|
||||
of class </font><b><tt><font color="#009900">eoSelectOne</font></tt></b><font color="#000000">
|
||||
into an eoSelectPerc object. For instance, try</font></li>
|
||||
|
||||
<br><b><tt><font color="#009900">
|
||||
eoSelectPerc<Indi> select(selectOne,2.0)</font></tt></b>
|
||||
<br><font color="#000000">to generate twice as many offspring as there
|
||||
are parents.</font>
|
||||
<br><font color="#000000">You can also use the other encapsulator that
|
||||
takes as second argument an absolute number (e.g. if you want to generate
|
||||
2 offspring whatever the population size):</font>
|
||||
<br><b><tt><font color="#009900">
|
||||
eoSelectNumber<Indi> select(selectOne,2)</font></tt></b>
|
||||
<br><font color="#000000">Or you can use the <a href="eoEngine.html#howmany">HowMany</a>
|
||||
paradigm and the </font><b><tt><font color="#009900">eoSelectMany </font></tt></b><font color="#000000">to
|
||||
do either one depending on some command-line input (advanced).</font>
|
||||
<li>
|
||||
<font color="#000000">To </font><font color="#FF6600">keep a constant population
|
||||
size</font><font color="#000000">, you can use either the </font><b><tt><font color="#009900">eoCommaReplacement</font></tt></b><font color="#000000">
|
||||
class, or the </font><b><tt><font color="#009900">eoPlusReplacement</font></tt></b><font color="#000000">.
|
||||
The former selects the best offspring to replace the parents, the latter
|
||||
selects the best among parents+offspring. Of course you cannot use </font><b><tt><font color="#009900">eoCommaReplacement</font></tt></b><font color="#000000">
|
||||
if you have less offspring than parents!</font></li>
|
||||
|
||||
<br>Now if you use <b><tt><font color="#009900">eoSelectRandom</font></tt></b>
|
||||
as selector with a rate of
|
||||
<i>lambda</i>, you end up with exactly the <i>(mu+lambda)</i>
|
||||
or
|
||||
<i>(mu,lambda)</i> strategies from <a href="intro.html#ES">Evolution
|
||||
Strategies</a>.
|
||||
<li>
|
||||
<font color="#FF0000">Question</font><font color="#000000">: what do you
|
||||
get if you select 1 offspring only, and an </font><b><tt><font color="#009900">eoPlusReplacement</font></tt></b><font color="#000000">
|
||||
strategy? Yes, you get almost the replace_worst Steady-State GA, though
|
||||
rather inefficient, as you sort the population at every generation.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#FF0000">Hint</font><font color="#000000">: there are a few
|
||||
Steady-State replacement strategies already there in EO. See the <a href="eoEngine.html#SSGA">Replacement
|
||||
page</a>.</font></li>
|
||||
</ul>
|
||||
<font color="#FF0000">Remember</font><font color="#000000">: all solutions
|
||||
are in the same sub-directory of the Tutorial dir than the examples (i.e.
|
||||
here Lesson2), and are described <a href="NoWay.html">here</a>.</font>
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>Lessons learned:</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
How to write a <font color="#CC0000">fitness function</font> that only
|
||||
needs a genotype, not a full individual. Moreover you can compile it separately.</li>
|
||||
|
||||
<br>How to <font color="#CC33CC">initialize</font> the population using
|
||||
random generators
|
||||
<li>
|
||||
How to use other <font color="#009900">evolution engine</font> than the
|
||||
simple generational GA.</li>
|
||||
|
||||
<li>
|
||||
How to combine different objects of the same kind into a single object
|
||||
that you can use like a simple basic object (<font color="#CC33CC">operators</font>
|
||||
and <font color="#3366FF">stopping criteria</font> here).</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%"><a href="eoLesson1.html">Lesson 1</a> -
|
||||
<a href="eoLesson3.html">Lesson
|
||||
3</a> -
|
||||
<a href="eoTutorial.html">Main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">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>
|
||||
565
eo/tutorial/html/eoLesson3.html
Normal file
565
eo/tutorial/html/eoLesson3.html
Normal file
|
|
@ -0,0 +1,565 @@
|
|||
<!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>Tutorial: Lesson 3</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<a href="eoLesson2.html">Lesson 2</a> -
|
||||
<a href="eoLesson4.html">Lesson
|
||||
4</a> -
|
||||
<a href="eoTutorial.html">Main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">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 Lesson 3: input/output</font></h1></center>
|
||||
In this lesson, you will still use the same Evolutionary Algorithm, BUT
|
||||
in a much more <b><font color="#FF6600">user-friendly</font></b> way. You
|
||||
will discover how to
|
||||
<ul>
|
||||
<li>
|
||||
<a href="#parser">input parameters</a> on the command-line or from a text
|
||||
file</li>
|
||||
|
||||
<li>
|
||||
<a href="#state">save</a> the population to disk, together with every part
|
||||
of the algorithm you could think of - so you can decide to <font color="#FF6600">reload</font>
|
||||
everything later to continue the same run, eventually with different parameters.</li>
|
||||
|
||||
<li>
|
||||
<a href="#stats">generate statistics</a> on the populations, and <a href="#monitor">output
|
||||
them</a> to the screen, text or graphic, or to a file (or to any other
|
||||
device you might want to use).</li>
|
||||
</ul>
|
||||
First, but you should now have done it without being told, go into the
|
||||
<font color="#FF6600">Lesson3
|
||||
sub-dir</font> of the tutorial dir and type
|
||||
<b><tt><font color="#990000"><font size=+1>make</font></font></tt></b>.
|
||||
This will compile the <b><tt><font color="#660000"><font size=+1>SecondBitEA</font></font></tt></b>
|
||||
and <b><tt><font color="#660000"><font size=+1>SecondRealEA</font></font></tt></b>
|
||||
programs.
|
||||
<p>You can then either
|
||||
<ul>
|
||||
<li>
|
||||
browse the corresponding code (<a href="SecondBitEA.html">SecondBitEA</a>
|
||||
and <a href="SecondRealEA.html">SecondRealEA</a>),</li>
|
||||
|
||||
<li>
|
||||
look at the <a href="#changes">summary of changes</a>,</li>
|
||||
|
||||
<li>
|
||||
or find out directly explanations about the new features: the <a href="#parser">eoParser</a>,
|
||||
<a href="#state">eoState</a>
|
||||
and <a href="#checkpoint">eoCheckpoint</a> classes.</li>
|
||||
</ul>
|
||||
|
||||
<p><br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="changes"></a><b><font color="#000099"><font size=+2>Changes</font></font></b>
|
||||
<br><font color="#000000">As already said, the behavior of the algorithm
|
||||
will be exactly the same as the previous one as far as optimization is
|
||||
concerned. Only the input (of algorithm parameters) and output (of program
|
||||
results) will be very different.</font>
|
||||
<br><font color="#000000">Hence, the sections corresponding to the <a href="SecondBitEA.html#eval">fitness
|
||||
function</a>, the <a href="SecondBitEA.html#init">initialization</a>, the
|
||||
<a href="SecondBitEA.html#operators">variation
|
||||
operators</a>, the <a href="SecondBitEA.html#engine">evolution engine</a>
|
||||
and the <a href="SecondBitEA.html#generation">algorithm</a> itself are
|
||||
almost identical (apart from variable name changes).</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000"><a href="SecondBitEA.html#eval">Fitness function</a>:
|
||||
there is an </font><font color="#FF6600">additional line</font><font color="#000000">
|
||||
after the encapsulation of our </font><font color="#CC0000">binary_function</font><font color="#000000">
|
||||
into an </font><b><tt><font color="#CC0000"><font size=+1>eoEvalFunc</font></font></tt></b><font color="#000000">
|
||||
object, which again encapsulate the </font><b><tt><font color="#CC0000"><font size=+1>eoEvalFunc</font></font></tt></b><font color="#000000">
|
||||
into an </font><b><tt><font color="#CC0000"><font size=+1>eoEvalFuncCounter</font></font></tt></b><font color="#000000">.
|
||||
As its name says, this object will, in addition to computing the fitness,
|
||||
count the </font><b><font color="#FF6600">actual</font></b><font color="#000000">
|
||||
number of evaluations: the fitness of non-modified individuals is of course
|
||||
not recomputed - and this is taken care of by this object. Moreover, it
|
||||
can be later </font><font color="#FF6600">used for displays</font><font color="#000000">
|
||||
in <a href="#monitor">eoMonitor</a> objects, as done in the <a href="SecondBitEA.html#eval_monitor">checkpoint
|
||||
section</a>.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The <a href="SecondBitEA.html#init">initialization</a>
|
||||
section has been extended to account for the possibility to </font><font color="#CC33CC">re-load
|
||||
a previously saved population</font><font color="#000000">. This is achieved
|
||||
through an <a href="#state">eoState</a> object, if the corresponding program
|
||||
parameter is set.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The
|
||||
<a href="SecondBitEA.html#operators">variation
|
||||
operators</a> and the <a href="SecondBitEA.html#engine">evolution engine</a>
|
||||
sections are similar to the ones in Lesson2</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The <a href="SecondBitEA.html#parametres">parameter
|
||||
section</a> is completely different from the previous one. All variables
|
||||
corresponding to </font><font color="#3366FF">program parameters</font><font color="#000000">
|
||||
are now read at run-time using an object of class <a href="#parser">eoParser</a>.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The <a href="SecondBitEA.html#stop">stopping criterion
|
||||
section</a>, has in fact now become the checkpoint section, as it involves
|
||||
much more than just stopping criteria. See all details in the <a href="#checkpoint">eoCheckpoint
|
||||
paragraph below</a>.</font></li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="parser"></a><b><font color="#000099"><font size=+2>eoParser:
|
||||
parameter input</font></font></b>
|
||||
<br><font color="#000000">The first two examples of Lessons 1 and 2 had
|
||||
a very crude way to set parameter values: they were hard-coded, and you
|
||||
had to recompile the whole program to change a single value. We shall now
|
||||
see now to set parameter values in a flexible way (though we're still looking
|
||||
for volunteers to create a Graphical User Interface :-)</font>
|
||||
<br><font color="#000000">Two base classes are used for that purpose:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">The </font><b><tt><font color="#3366FF">eoValueParam</font></tt></b><font color="#000000">
|
||||
class, </font><font color="#FF6600">templatized by the type of the variable</font><font color="#000000">
|
||||
you want to handle (i.e. i</font><b><tt><font color="#660000">integer,
|
||||
double, yourPrivateClass</font></tt></b><font color="#000000">, ...). In
|
||||
this lesson, we will not go into details: e.g. we will not tell you that
|
||||
the
|
||||
<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_value_param.html">eoValueParam</a></font></font></b>
|
||||
is actually a templatized sub-class of abstract class eoParam (oops, I
|
||||
said it!), nor will we deal with parameters outside their use from an eoParser.
|
||||
See the parameter section of the Component-Based tutorial, or wait until
|
||||
<a href="eoLesson4.html">lesson
|
||||
4</a>).</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">The </font><b><tt><font color="#3366FF">eoParser</font></tt></b><font color="#000000">
|
||||
class, whose only purpose is the input of parameters. Read <a href="../../doc/html/classeo_parser.html">its
|
||||
description</a> if you are interested.</font></li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="50%"><a NAME="paraminput"></a><b><font color="#000099">eoParser:</font><font color="#FF0000">
|
||||
Modifying parameter values at run-time:</font></b>
|
||||
<br><font color="#000000">Using an eoParser object, the parameter values
|
||||
are read, by order of priority</font>
|
||||
<ol>
|
||||
<li>
|
||||
<font color="#000000">from the command-line</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">from a text file</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">from the environment (forthcoming, if somebody insists)</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">from default values</font></li>
|
||||
</ol>
|
||||
The syntax of parameter reading is a <b><font color="#FF6600">keyword</font></b>-based
|
||||
syntax, now traditional in the Unix world:
|
||||
<ul>
|
||||
<li>
|
||||
in EO, each parameter is designated by <font color="#FF6600">a (long) keyword</font>,
|
||||
and optionally by a <font color="#FF6600">short (1 character) keyword</font>.</li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
the general syntax to modify parameter value at run-time is (either from
|
||||
the command-line or in a text file)</li>
|
||||
|
||||
<br>
|
||||
|
||||
<b><tt><font color="#660000">--longKeyword=value</font></tt></b>
|
||||
or <b><tt><font color="#660000">-cvalue</font></tt></b>
|
||||
if 'c' is the short keyword (though <b><tt><font color="#660000">-c=value</font></tt></b>
|
||||
also works)
|
||||
<br>
|
||||
<li>
|
||||
so, after compiling the executable for Lesson 3 (<b><tt><font color="#FF6666">make
|
||||
lesson3</font></tt></b> at system prompt in Unix), you can try to type
|
||||
in</li>
|
||||
|
||||
<br>
|
||||
|
||||
<b><tt><font color="#FF6666">SecondBitEA</font></tt></b>
|
||||
<br>and see the algorithm run as before (OneMax optimized on 8-bits bitstrings).
|
||||
But you can now type in
|
||||
<br>
|
||||
|
||||
<b><tt><font color="#FF6666">SecondBitEA --vecSize=100</font></tt></b>
|
||||
<br>and see the output of the optimization of OneMax on 100-bit bitstrings.
|
||||
<br>
|
||||
<li>
|
||||
Take a look at all available parameters by typing in</li>
|
||||
|
||||
<br>
|
||||
|
||||
<b><tt><font color="#FF6666">SecondBitEA --help</font></tt></b>
|
||||
<br>or by going into the code: all parameter inputs have been grouped in
|
||||
the
|
||||
<a href="SecondBitEA.html#parametres">read_param</a> function.
|
||||
<br>
|
||||
<li>
|
||||
After running the algorithm, a new file has been created, named <b><tt><font color="#990000">SecondBitEA.status</font></tt></b>:
|
||||
it contains the list of all actual parameters used, and can directly be
|
||||
used as parameter input file: change the file name (e.g. to <b><tt><font color="#660000">SecondBitEA.param</font></tt></b>),
|
||||
edit it, change whichever parameter you want, and type in</li>
|
||||
|
||||
<br>
|
||||
<b><tt><font color="#FF6666">SecondBitEA @SecondBitEA.param</font></tt></b>
|
||||
<br>and you will see all values that you defined into the file taken into
|
||||
account.
|
||||
<br>
|
||||
<li>
|
||||
The <font color="#FF6600">priority</font> remains to the <font color="#FF6600">command-line</font>,
|
||||
so you can still override the values in the parameter file by giving a
|
||||
new value directly on the command-line.</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="50%"><a NAME="parameters"></a><b><font color="#000099">eoParser:</font><font color="#FF0000">
|
||||
Programming parameter input:</font></b>
|
||||
<br>The code of SeconBitEA provides examples of parameters reading. Lets
|
||||
take the example of the <a href="eoProgramming.html#random">random number
|
||||
generator </a><b><tt><font color="#660000">seed</font></tt></b>.
|
||||
Of course, you first need to <a href="SecondBitEA.html#parser_declare">declare
|
||||
an eoParser object</a> (it needs the standard argc and argv in its constructor).
|
||||
<ul>
|
||||
<li>
|
||||
You must first <a href="SecondBitEA.html#random">declare a parameter</a>
|
||||
of type <b><tt><font color="#660000">uint32</font></tt></b> (32-bits integer).
|
||||
The arguments are: default value, long keyword, comment (that will appear
|
||||
in the help message and in the output "status" file if any) and optional
|
||||
character keyword.</li>
|
||||
|
||||
<li>
|
||||
Then you must <a href="SecondBitEA.html#seed_process">pass it to the parser</a>
|
||||
using the processParam method. The optional argument is a section name,
|
||||
that will be used to make the output of the parser look clean and ordered.</li>
|
||||
|
||||
<li>
|
||||
Finally, you need to <a href="SecondBitEA.html#seed_assign">assign the
|
||||
value</a> to the variable <b><tt><font color="#660000">seed</font></tt></b>.
|
||||
Note that the <b><tt><font color="#990000">value()</font></tt></b> method
|
||||
of eoParam returns a reference, so you can eventually modify its value
|
||||
somewhere else later (though of course this is not any useful for variable
|
||||
<b><tt><font color="#660000">seed</font></tt></b>!).</li>
|
||||
</ul>
|
||||
There is however another way to achieve the same result in less lines of
|
||||
code - with a different memory management. This is what is done in the
|
||||
code for eoRealEA. The same parameter for the <a href="eoProgramming.html#random">random
|
||||
number generator </a><b><tt><font color="#660000">seed</font></tt></b>
|
||||
is read, but in <a href="SecondRealEA.html#random">one single line of code</a>.
|
||||
The only difference is that now you cannot access the eoValueParam object
|
||||
itself - but this is not often necessary.
|
||||
<br>Be careful to ensure that the type of the default value in the call
|
||||
to <a href="../../doc/html/classeo_parameter_loader.html#a3">eoParameterLoader::createParam</a>
|
||||
method as this is the only way the compiler can desambiguate the template
|
||||
(remember that eoParameterLoader is <font color="#000000"><a href="../../doc/html/classeo_parser.html">a
|
||||
base class for eoParser</a></font>.
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="state"></a><b><font color="#000099"><font size=+2>eoState:
|
||||
saving and loading</font></font></b><font color="#000000">You might have
|
||||
noticed in the </font><b><tt><font color="#660000">read_param</font></tt></b><font color="#000000">
|
||||
described above a </font><font color="#FF6600">new parameter</font><font color="#000000">
|
||||
named </font><b><tt><font color="#660000"><a href="SecondBitEA.html#_load_name">load_name.</a></font></tt></b><font color="#000000">
|
||||
Now if you go to the <a href="SecondBitEA.html#init">init section</a> of
|
||||
the code, you will see an alternative way of </font><font color="#CC33CC">initializing
|
||||
the population</font><font color="#000000">: if load_name is an empty string,
|
||||
then we do as in the preceding example and use an eoInitFixedLength object.
|
||||
However, if a load_name name was entered, the population is read through
|
||||
the </font><b><tt><font color="#660000"><a href="SecondBitEA.html#instate.load">inState.load(load_name)</a></font></tt></b><font color="#000000">
|
||||
instruction. Moreover, the comment says "Loading pop </font><font color="#FF6600">and
|
||||
rng</font><font color="#000000">".</font>
|
||||
<p><font color="#000000">This is made possible using the </font><b><tt><font color="#3366FF">eoState</font></tt></b><font color="#000000">
|
||||
class. </font><b><tt><font color="#3366FF">eoState</font></tt></b><font color="#000000">
|
||||
objects maintain references to </font><b><tt><font color="#660000">eoObjects</font></tt></b><font color="#000000">
|
||||
that have both an input method (</font><b><tt><font color="#3366FF">readFrom</font></tt></b><font color="#000000">)
|
||||
and an output method (</font><b><tt><font color="#3366FF">printOn</font></tt></b><font color="#000000">),
|
||||
i.e. that derive from the base class </font><b><font face="Arial,Helvetica"><font color="#660000"><font size=+1><a href="../../doc/html/classeo_persistent.html">eoPersistent</a></font></font></font></b><font color="#000000">.
|
||||
You must first </font><b><tt><font color="#3366FF"><a href="SecondBitEA.html#register">register</a></font></tt></b><font color="#000000">
|
||||
object into a state, and can then save them to a (text) file, and later
|
||||
read them from that file using the </font><b><tt><font color="#3366FF">load</font></tt></b><font color="#000000">
|
||||
method, as done <a href="SecondBitEA.html#loadstate">here</a>.</font>
|
||||
<br><font color="#000000">Of course, you can call the </font><b><tt><font color="#3366FF">save</font></tt></b><font color="#000000">
|
||||
method for an </font><b><tt><font color="#3366FF">eoState</font></tt></b><font color="#000000">
|
||||
object anywhere in the code. But the <a href="#statesaver">checkpointing</a>
|
||||
mechanism offers you better ways to do that - and it's so easy ....</font>
|
||||
<p>Note that an eoState alos has another use in EO whan it comes to memory
|
||||
management: it can be a repository of pointers that are not allocated within
|
||||
obects - allowing to delete them by simply deleting the eoState (see <a href="eoLesson4.html#memory">Lesson
|
||||
4)</a>.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="checkpoint"></a><b><font color="#000099"><font size=+2>eoCheckpoint:
|
||||
every generation I'd like to ...</font></font></b>
|
||||
<br><font color="#000000">The checkpointing mechanism is a very powerful
|
||||
construct to perform some </font><b><font color="#FF6600">systematic actions</font></b><font color="#000000">
|
||||
every generation - like </font><font color="#FF6600">saving things</font><font color="#000000">
|
||||
(using eoState objects described above), computing </font><font color="#FF6600">statistics</font><font color="#000000">
|
||||
on the population, </font><font color="#FF6600">updating</font><font color="#000000">
|
||||
dynamical parameters or </font><font color="#FF6600">displaying</font><font color="#000000">
|
||||
information.</font>
|
||||
<p><b><tt><font color="#3366FF">eoCheckpoint</font></tt></b><font color="#000000">
|
||||
objects are </font><b><tt><font color="#3366FF">eoContinue</font></tt></b><font color="#000000">
|
||||
objects that contain </font><font color="#FF6600">pointers to different
|
||||
types</font><font color="#000000"> of objects. When their </font><b><tt><font color="#660000">operator()</font></tt></b><font color="#000000">
|
||||
method is called (i.e. every generation in the examples up to now), they
|
||||
first call the </font><b><tt><font color="#660000">operator()</font></tt></b><font color="#000000">
|
||||
methods of all object they contain, and then return their result as an
|
||||
</font><b><tt><font color="#3366FF">eoContinue</font></tt></b><font color="#000000">
|
||||
object (i.e. should we continue or stop).</font>
|
||||
<br><b><font color="#FF0000">Programming: </font></b><font color="#000000">To
|
||||
do something every generation, you simply need to </font><b><tt><font color="#3366FF">add</font></tt></b><font color="#000000">
|
||||
an object whose </font><b><tt><font color="#660000">operator()</font></tt></b><font color="#000000">
|
||||
does what you want to the eoState that you will use as continuator in the
|
||||
algorithm.</font>
|
||||
<br>
|
||||
<hr WIDTH="50%"><a NAME="stop"></a><b><font color="#000099">eoCheckpoint:
|
||||
</font><font color="#FF0000">Stopping</font></b>
|
||||
<br><font color="#000000">The </font><b><tt><font color="#3366FF">eoContinue</font></tt></b><font color="#000000">
|
||||
part of an </font><b><tt><font color="#3366FF">eoCheckpoint</font></tt></b><font color="#000000">
|
||||
is a single object, <a href="SecondBitEA.html#checkpoint">passed to the
|
||||
constructor</a>. If you want more that one stopping criterion, use an <a href="SecondBitEA.html#stop">eoCombinedContinue</a>
|
||||
object as described in <a href="eoLesson2.html#combinedContinue">Lesson2</a>.</font>
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><a NAME="stats"></a><b><font color="#000099">eoCheckpoint: </font><font color="#FF0000">Computing
|
||||
statistics</font></b>
|
||||
<br><font color="#000000">Statistics are computed using </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
objects, i.e. functor objects whose </font><b><tt><font color="#660000">operator()</font></tt></b><font color="#000000">
|
||||
receives as argument a reference to a population as argument, and can hence
|
||||
compute whatever is needed over that population. </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
objects are </font><font color="#FF6600">templatized</font><font color="#000000">
|
||||
over the type of what they compute (e.g. </font><b><tt><font color="#660000">double</font></tt></b><font color="#000000">,
|
||||
or </font><b><tt><font color="#660000">pair<double></font></tt></b><font color="#000000">,
|
||||
or ...). But looking at the <a href="../../doc/html/classeo_stat.html">inheritance
|
||||
diagram</a> of the </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
class, you find that </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
objects are also </font><b><tt><font color="#3366FF">eoValueParam</font></tt></b><font color="#000000">
|
||||
objects. And this allows </font><b><tt><font color="#3366FF">eoStat</font></tt></b><font color="#000000">
|
||||
to be used within </font><b><tt><font color="#3366FF">eoMonitor</font></tt></b><font color="#000000">
|
||||
object, and hence </font><b><font color="#FF6600">displayed</font></b><font color="#000000">
|
||||
to the user!</font>
|
||||
<p><b><font color="#000099">Statistics: </font><font color="#FF0000">Available
|
||||
instances</font></b>
|
||||
<br>Some widely used statistics are already available (and of course you
|
||||
can build you own!).
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoBestFitnessStat</font></tt></b> returns
|
||||
the fitness value of the best individual in the population (of type <b><tt><font color="#660000">FitnessType</font></tt></b>,
|
||||
whatever this is).</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoAverageStat</font></tt></b> and <b><tt><font color="#3366FF">eoSecondMomentStat</font></tt></b>
|
||||
respectively return the average (type double, assumes that <b><tt><font color="#660000">FitnessType</font></tt></b>
|
||||
is castable to a double) and a pair made of the average and the standard
|
||||
deviation (type <b><tt><font color="#660000">pair<double></font></tt></b>)
|
||||
of the fitnesses in the populations.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoDiversityStat</font></tt></b> returns the
|
||||
diversity in the population: assuming that there is a distance function
|
||||
defined among individuals, it returns the average inter-individuals distance.
|
||||
See also Exercise 2.</li>
|
||||
</ul>
|
||||
<b><font color="#000099">Statistics: </font><font color="#FF0000">Adding
|
||||
to the checkpoint</font></b>
|
||||
<br>To compute more statistics when your algorithm is running, simply <a href="SecondBitEA.html#stat_declare">declare</a>
|
||||
the corresponding eoStat objects, and <a href="SecondBitEA.html#stat_pass">add</a>
|
||||
them to the <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b> you
|
||||
use in the algorithm. But it hardly makes any sense if you don't <b><font color="#3366FF">monitor</font></b>
|
||||
those statistics (i.e. either displaying them on the screen, or storing
|
||||
them into a file): see next section!
|
||||
<p><b><font color="#FF0000">Note</font></b>: actually, there are 2 distinct
|
||||
classes that compute and give access to statistics: <b><tt><font color="#3366FF">eoStat</font></tt></b>and
|
||||
<b><tt><font color="#3366FF">eoSortedStat</font></tt></b>.
|
||||
As its name indicate, the latter is used whenever computing the statistics
|
||||
require a sorted population: not only this avoids to sort the population
|
||||
many times, but also it avoids changing the order of the population at
|
||||
all as <b><tt><font color="#3366FF">eoSortedStat</font></tt></b> objects
|
||||
work on a temporary vector of fitnesses . But <font color="#FF6600">as
|
||||
far as their usage is concerned, its makes no difference</font>.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><a NAME="monitor"></a><b><font color="#000099">eoCheckpoint: </font><font color="#FF0000">Monitoring
|
||||
eoParameters</font></b>
|
||||
<br><font color="#000000">The </font><b><tt><font color="#3366FF">eoMonitor</font></tt></b><font color="#000000">
|
||||
objects are used to display or store to a file a set of </font><b><tt><font color="#3366FF">eoValueParam</font></tt></b><font color="#000000">
|
||||
objects.</font>
|
||||
<p><b><font color="#000099">Monitors</font></b>: <b><font color="#FF0000">Available
|
||||
instances</font></b>
|
||||
<br>A few monitors are available in the EO distribution:
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoStdoutMonitor</font></tt></b> displays its
|
||||
parameters in <font color="#FF6600">text format on the screen</font>. The
|
||||
(optional) boolean value in the constructor modifies the output: when true
|
||||
(the default), verbose output is used, with one line per parameter. When
|
||||
false, parsimonious output displays one line for all parameters.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoFileMonitor</font></tt></b> writes its parameters
|
||||
in <font color="#FF6600">text format in a file</font>. A file name is required
|
||||
in the constructor, and an optional separator character can be added (default
|
||||
is ' '). Note that the file is by default overwritten by next call to the
|
||||
same program, unless you pass "true" as third (optional) boolean parameter,
|
||||
which will result in appending to the file if it ever exists.</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoGnuplot1DMonitor</font></tt></b> displays
|
||||
its parameters in <font color="#FF6600">graphical format on the screen</font>
|
||||
by calling the <b><tt><font color="#660000">gnuplot</font></tt></b> program,
|
||||
and as of today, only works in the Unix version of EO (as always, volunteers
|
||||
are welcome to port that to MS Windows). It takes an optional filename
|
||||
as input, as communication of data with <b><tt><font color="#660000">gnuplot</font></tt></b>
|
||||
is done through a file. If no filename is provided, the file will be erased
|
||||
at the end of the run, while it is otherwise kept (though it will be overwritten
|
||||
by next call to the same program).</li>
|
||||
</ul>
|
||||
|
||||
<p><br><b><font color="#000099">Monitors</font></b>: <b><font color="#FF0000">Adding
|
||||
to the checkpoint</font></b>
|
||||
<br>To display something while the algorithm is running, you need to <a href="SecondBitEA.html#monitor_declare">declare</a>
|
||||
an <b><tt><font color="#3366FF">eoMonitor</font></tt></b> object, <a href="SecondBitEA.html#monitor_add">add</a>
|
||||
some objects (that must be <b><tt><font color="#3366FF">eoValueParam</font></tt></b>
|
||||
objects) to that monitor, and of course <a href="SecondBitEA.html#monitor_pass">add</a>
|
||||
the monitor to the <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b>
|
||||
you use in the algorithm.
|
||||
<br>
|
||||
<hr WIDTH="50%">
|
||||
<br><a NAME="update"></a><b><font color="#000099">eoCheckpoint: Updating
|
||||
things</font></b>
|
||||
<br><font color="#000000">The last type of objects that </font><b><tt><font color="#3366FF">eoCheckpoint</font></tt></b><font color="#000000">
|
||||
can handle are </font><b><tt><font color="#3366FF">eoUpdater</font></tt></b><font color="#000000">
|
||||
objects. You should simply encapsulate in an </font><b><tt><font color="#3366FF">eoUpdater</font></tt></b><font color="#000000">
|
||||
anything you wish to do which does not fit into one of the above category.
|
||||
Note that their </font><b><tt><font color="#660000">operator() method</font></tt></b><font color="#000000">
|
||||
does not receive any argument.</font>
|
||||
<p><b><font color="#000099">Updater: </font><font color="#FF0000">Available
|
||||
instances</font></b>: A few updaters are available in the EO distribution:
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#3366FF">eoIncrementor</font></tt></b> A simple updater
|
||||
which maintains a <font color="#FF6600">counter</font> (an <b><tt><font color="#3366FF">eoValueParam</font></tt></b>
|
||||
that needs to be created beforehand, and passed in the constructor). It
|
||||
is incremented every time the <b><tt><font color="#660000">operator()</font></tt></b>
|
||||
method is called (every generation at the moment). You can of course also
|
||||
give an increment in the constructor (1 by default).</li>
|
||||
|
||||
<li>
|
||||
<a NAME="statesaver"></a><b><tt><font color="#3366FF">eoCountedStateSaver</font></tt></b>
|
||||
and <b><tt><font color="#3366FF">eoTimedStateSaver</font></tt></b> can
|
||||
be used to <font color="#FF6600">save</font> some existing <b><tt><font color="#3366FF">eoState</font></tt></b>
|
||||
(see <a href="#state">above</a>) to a file regularly, either based on the
|
||||
generation count (e.g. every 4 generations) or based on the clock (e.g.
|
||||
every 5 seconds).</li>
|
||||
</ul>
|
||||
<b><font color="#000099">Updater: </font><font color="#FF0000">Adding to
|
||||
the checkpoint</font></b>
|
||||
<br>A very simple example of using an <b><tt><font color="#3366FF">eoUpdater</font></tt></b>
|
||||
is given in the code for SecondBitEA: First <a href="SecondBitEA.html#param_declare">declare</a>
|
||||
an <b><tt><font color="#3366FF">eoValueParam</font></tt></b> object, then
|
||||
<a href="SecondBitEA.html#param_pass">use
|
||||
it to construct</a> an <b><tt><font color="#3366FF">eoIncrementor</font></tt></b>
|
||||
that you must <a href="SecondBitEA.html#updater_pass">add</a> to the <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b>
|
||||
in order to activate its update. You can then use the parameter for your
|
||||
purpose, for instance as a first coordinate for a monitor.
|
||||
<br>Note also how to use the statesavers: first <a href="SecondBitEA.html#outstate_declare">declare</a>
|
||||
a state, then <a href="SecondBitEA.html#outstate_register">register</a>
|
||||
whatever you think necessary to that state, then <a href="SecondBitEA.html#statesaver_declare">pass</a>
|
||||
the state to some state-saver - and don't forget to <a href="SecondBitEA.html#statesaver_pass">add</a>
|
||||
the statesavers to the current <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b>.
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>Exercise 1:</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">The code of </font><b><tt><font color="#660000"><font size=+1>SecondBitEA</font></font></tt></b><font color="#000000">
|
||||
display things in the current window in text format. Replace the </font><b><tt><font color="#3366FF">eoFileMonitor</font></tt></b><font color="#000000">
|
||||
by an </font><b><tt><font color="#3366FF">eoGnuplot1DMonitor</font></tt></b><font color="#000000">
|
||||
and watch the </font><b><font color="#FF6600">graphical output </font></b><font color="#000000">(</font><font color="#FF6600">Unix</font><font color="#000000">
|
||||
systems with </font><font color="#FF6600">gnuplot</font><font color="#000000">
|
||||
installed only, sorry).</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">Note that you must also replace the </font><b><tt><font color="#3366FF">eoSecondMomentStat</font></tt></b><font color="#000000">
|
||||
by an </font><b><tt><font color="#3366FF">eoAverageStat</font></tt></b><font color="#000000">,
|
||||
otherwise the standard deviations won't make any sense here.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">Please try to understand why the average is always
|
||||
0 before taking a look at the solution (file <a href="NoWay.html">exercise1.cpp</a>).</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">Then run</font></li>
|
||||
|
||||
<br><b><tt><font color="#660000">
|
||||
exercise1 --vecSize=1000 --maxGen=1000</font></tt></b>
|
||||
<br><font color="#000000">to get a chance to see something happening before
|
||||
the program ends!</font></ul>
|
||||
|
||||
<hr WIDTH="100%"><b><font color="#000099"><font size=+2>Exercise 2:</font></font></b>
|
||||
<br><font color="#000000">Write the </font><b><tt><font color="#3366FF">eoDiversityStat</font></tt></b><font color="#000000">
|
||||
stat computation and test it. Thanks to send us the code!</font>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>Exercise 3:</font></font></b>
|
||||
<br><font color="#000000">Write the code for an </font><b><tt><font color="#3366FF">eoGnuplotSecondStatMonitor</font></tt></b><font color="#000000">
|
||||
that would display the </font><b><tt><font color="#3366FF">eoSecondMomentStat</font></tt></b><font color="#000000">
|
||||
(i.e. take into account the standard deviations and display them as error-bars.</font>
|
||||
<br><font color="#000000">Again, send us the code afterwards, thanks :-)</font>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#000099"><font size=+2>Lessons learned:</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
Value of program parameters can be set <b><font color="#FF6600">at run-time</font></b>
|
||||
using the <b><tt><font color="#3366FF">eoParser</font></tt></b> class.</li>
|
||||
|
||||
<li>
|
||||
<b><font color="#FF6600">Snapshots</font></b> of the algorithms can easily
|
||||
be <font color="#FF6600">saved</font> (and <font color="#FF6600">restored</font>)
|
||||
thanks to the <b><tt><font color="#3366FF">eoState</font></tt></b> class.</li>
|
||||
|
||||
<li>
|
||||
The <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b> mechanism
|
||||
let you <b><font color="#FF6600">do things every generation</font></b>
|
||||
without modifying existing algorithms, by simply writing the necessary
|
||||
code and encapsulating it into an object that <b><tt><font color="#3366FF">eoCheckpoint</font></tt></b>
|
||||
is aware of, that are at the moment the following:</li>
|
||||
|
||||
<li>
|
||||
computing <b><font color="#FF6600">statistics</font></b>, <b><font color="#FF6600">displaying
|
||||
</font></b>parameters
|
||||
(e.g. statistics), <b><font color="#FF6600">saving</font></b> the
|
||||
<b><tt><font color="#3366FF">(eo)State</font></tt></b>
|
||||
of the program.</li>
|
||||
</ul>
|
||||
In next lesson you will find out that many <a href="intro.html#adaptive">adaptive
|
||||
techniques</a> (the state-of-the-art in Evolutionary Computation) can easily
|
||||
be programmed through the <b><tt><font color="#3366FF">eoUpdater</font></tt></b>
|
||||
construct.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a href="eoLesson2.html">Lesson 2</a> -
|
||||
<a href="eoLesson4.html">Lesson
|
||||
4</a> -
|
||||
<a href="eoTutorial.html">Main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">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: None of your business!<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
940
eo/tutorial/html/eoLesson4.html
Normal file
940
eo/tutorial/html/eoLesson4.html
Normal file
|
|
@ -0,0 +1,940 @@
|
|||
<!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>Tutorial: Lesson 4</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<a href="eoLesson3.html">Lesson 3</a> -
|
||||
<a href="eoLesson5.html">Lesson
|
||||
5</a> -
|
||||
<a href="eoTutorial.html">Main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">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">User's guide:</font></b> <a href="#userguide">General</a>
|
||||
- <a href="#binary">Bitstring</a> - <a href="#real">Real</a> - <a href="#ES">ES</a>
|
||||
- <b><font color="#FF0000">Programmer's guide:</font></b> <a href="#programmerguide">General</a>
|
||||
- <a href="#memory">Memory management </a>- <a href="#parameter">Parameters</a>
|
||||
<br>
|
||||
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">Tutorial Lesson 4: ready-to-use fully operational EA</font></h1></center>
|
||||
In this lesson, you will still use the same Evolutionary Algorithm. But
|
||||
this time you will have <b><font color="#FF6600">full control of all components</font></b>
|
||||
from the <b><font color="#FF6600">command-line or a parameter file</font></b>.<br>
|
||||
You can even use the algorithm decribed here <b><font color="#FF6600">without any other knowledge
|
||||
of EO</font></b>, just by writing your fitness function as a plain C++ function. <br><br>
|
||||
|
||||
<b><font color="#000099"><font size=+2>Contents</font></font></b><br>
|
||||
<ul>
|
||||
<li><b><font color="#FF0000">User's guide</font></b>
|
||||
<ul>
|
||||
<li> <a href="#userguide">Representation independent</a>,
|
||||
useful for <b><font color="#FF6600">all</font></b> applications</li>
|
||||
<li> <a href="#binary">BitEA, the binary version</a>, similar
|
||||
to previous lessons</li>
|
||||
<li> <a href="#real">RealEA, the basic real-valued version</a>,
|
||||
not efficient - see by yourself!</li>
|
||||
<li> <a href="#ES">RealEA, the self-adaptive Evolution Strategy</a>, best choice for continuous optimization in EO today (December 2004)</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><b><font color="#FF0000">Programmer's guide</font></b>:
|
||||
the ultimate purpose of this tutorial is to make you able to do
|
||||
your own experiments - and these these will likely fall outside the scope
|
||||
of the two ready-to-use programs above. You wil hence need to learn more about
|
||||
<ul>
|
||||
<li> <a href="#programmerguide">Building libraries</a> (in spite of the
|
||||
<a href="eoProgramming.html#templates">template problem</a>)</li>
|
||||
<li> <a href="#memory">Memory management</a>: it is radically
|
||||
different that in the 3 previous lessons - though relying
|
||||
of course on the same objects. Note that eoPersistent objects and eoParam
|
||||
objects are handled by different mechanisms.
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="userguide"></a><b><font color="#000099"><font size=+2>User's
|
||||
guide</font></font></b>
|
||||
<p><font color="#000000">As already said, the behavior of the algorithms
|
||||
will be exactly the same as the previous one as far as optimization is
|
||||
concerned. Only now you will be able to tune every component of the algorithms
|
||||
(except the type of genotype) using run-time parameters.</font>
|
||||
<br><font color="#000000">Also, as in previous lessons, most of the code
|
||||
is representation-independent, i.e. is the same for both the binary genotypes
|
||||
and the real-valued genotypes. This small user's guide reflects that, but
|
||||
you can go directly to the <a href="#binary">binary</a> or the <a href="#real">real</a>
|
||||
parts if you wish.</font>
|
||||
<p><b><font color="#FF0000">Warning</font></b><font color="#000000">: this
|
||||
is a user guide, not a programming guide. In particular, the </font><font color="#FF6600">keywords</font><font color="#000000">
|
||||
of the parameters are </font><b><font color="#FF6600">not</font></b><font color="#000000">
|
||||
the </font><font color="#FF6600">names</font><font color="#000000"> of
|
||||
the underlying classes (though they should be similar in most cases).</font>
|
||||
<p><b><font size=+1><font color="#000099">User's guide:</font><font color="#FF0000">Parameter
|
||||
input</font></font></b><font color="#000000"> The way to input parameters
|
||||
has already be described in <a href="eoLesson3.html#paraminput">Lesson
|
||||
3</a>. To get a list of parameters, type the command with option --help
|
||||
(or -h): with both testBit and testReal this will result in</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">Printing the list of keywords on the standard output</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#000000">Creating (or overwriting) a file name testBit.status
|
||||
or testReal.status that contains the list of all recognized parameters
|
||||
and has the format of an input parameter file.</font></li>
|
||||
</ul>
|
||||
<b><font size=+1><font color="#000099">User's guide:</font><font color="#FF0000">The
|
||||
status file</font></font></b>
|
||||
<br><font color="#000000">This file will always contain the list of the
|
||||
parameters that have been actually used by the last run of the program,
|
||||
however thay have been entered (try </font><b><tt><font color="#FF6666"><font size=+1>testBit
|
||||
-G1</font></font></tt></b><font color="#000000"> and take a look a the
|
||||
status file). The parameters that are commented out (a # character comments
|
||||
out the rest of the line) in the file are those that were not specified
|
||||
by the user.</font>
|
||||
<br><font color="#000000">On the status file, the parameters are organized
|
||||
in sections. Note, however, that this format is not mandatory in the param
|
||||
file, as </font><font color="#FF6600">only the keywords</font><font color="#000000">
|
||||
are processed.</font>
|
||||
<p><b><font size=+1><font color="#000099">User's guide:</font><font color="#FF0000">Representation-independent
|
||||
parameters</font></font></b>
|
||||
<br><font color="#000000">In what follows, the fixed font colored text
|
||||
is directly taken from the status file and is commented between the lines.
|
||||
The presentation follows the status file format - only two sections are
|
||||
representation-dependent (see the corresponding <a href="#binary">binary</a>
|
||||
or <a href="#real">real</a> sections). All other sections are presented
|
||||
now:</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<br><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#993300">######
|
||||
General ######</font></tt></font></b>
|
||||
<br><b><tt><font color="#993300"><font size=+1># --help=0 # -h : Prints
|
||||
this message</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter </font><font color="#000000">of
|
||||
absolutely no interest: tells whether or not help was requested.</font>
|
||||
<p><b><tt><font color="#993300"><font size=+1># --seed=988700289 # -S :
|
||||
Random number seed</font></font></tt></b>
|
||||
<br><font color="#FF0000">Unsigned long parameter:</font><font color="#000000">
|
||||
the seed for the <a href="eoProgramming.html#random">Random Number Generator</a>
|
||||
If the parameter is absent, then time(0) is used, which indicates the number
|
||||
of seconds since Jan. 1 1980, is used ... and stored in the status file,
|
||||
of course, so you can repeat the same run by simply assigning that value
|
||||
again. There is </font><font color="#FF0000">no default value ("true" random
|
||||
seed)</font><font color="#000000">.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#009900">######
|
||||
engine ######</font></tt></font></b>
|
||||
<br><font color="#000000">In this section, one chooses all components of
|
||||
the <a href="eoEngine.html">Evolution Engine</a> (selection, replacemenet
|
||||
and the like).</font>
|
||||
<p><b><tt><font color="#009900"><font size=+1># --popSize=20 # -P : Population
|
||||
Size</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
the size of the population (constant along evolution). And yes, this is
|
||||
a representation independent parameter, as the population is created either
|
||||
from a file or using an eoInit object - and only that object is representation-dependent.</font>
|
||||
<br><b><tt><font color="#009900"><font size=+1># --selection=DetTour(2)
|
||||
# -S : Selection: Roulette, DetTour(T), StochTour(t) or Sequential(ordered/unordered)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
Name of <a href="eoEngine.html#selection">selection procedure.</a> Availabable
|
||||
are the </font><b><font color="#FF6600">roulette wheel</font></b><font color="#000000">
|
||||
(name </font><b><tt><font color="#009900"><font size=+1>Roulette</font></font></tt></b><font color="#000000">,
|
||||
fitness scaling coming soon); </font><b><font color="#FF6600">deterministic
|
||||
tournament</font></b><font color="#000000"> (name </font><b><tt><font color="#009900"><font size=+1>DetTour</font></font></tt></b><font color="#000000">
|
||||
with size - integer > 2 - in parentheses right after the name, use double
|
||||
quotes on the command line); </font><b><font color="#FF6600">stochastic
|
||||
tournament</font></b><font color="#000000"> (name </font><b><tt><font color="#009900"><font size=+1>StochTour</font></font></tt></b><font color="#000000">
|
||||
with probability - float in [0.5, 1] - in parentheses); </font><b><font color="#FF6600">sequential</font></b><font color="#000000">
|
||||
(name
|
||||
</font><b><tt><font color="#009900"><font size=+1>Sequential</font></font></tt></b><font color="#000000">,
|
||||
all individuals in turn), either from best to worst (option </font><b><tt><font color="#009900"><font size=+1>ordered</font></font></tt></b><font color="#000000">
|
||||
in parentheses), or in random ordered (option </font><b><tt><font color="#009900"><font size=+1>unordered</font></font></tt></b><font color="#000000">);
|
||||
and finally repeated </font><b><font color="#FF6600">independent uniform
|
||||
choices</font></b><font color="#000000"> (name </font><b><tt><font color="#009900"><font size=+1>Random</font></font></tt></b><font color="#000000">).
|
||||
Default is </font><font color="#FF0000">DetTour(2)</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#009900"><font size=+1># --nbOffspring=100% # -O
|
||||
: Nb of offspring (percentage or absolute)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer or real-valued parameter:</font><font color="#000000">
|
||||
this parameter indicates the </font><b><font color="#FF6600">amount of
|
||||
offspring</font></b><font color="#000000"> that will be generated from
|
||||
the genitors every generation. However, this amount can be specified either
|
||||
</font><font color="#FF6600">relative</font><font color="#000000">
|
||||
to the population size, and it should then end with percent character (%),
|
||||
or as an </font><font color="#FF6600">absolute</font><font color="#000000">
|
||||
integer number (without the percent char).</font>
|
||||
<br><font color="#000000">Indeed, you can either want, say 7 times more
|
||||
offspring than parents (a rather common situation in Evolution Strategies),
|
||||
in which case you give value 700% to </font><b><tt><font color="#009900"><font size=+1>nbOffspring</font></font></tt></b><font color="#000000">
|
||||
parameter; or you might want a single offspring whatever the population
|
||||
size, like in Steady-State evolution engines, in which case you simply
|
||||
enter value 1. </font><font color="#FF0000">Default is 100%</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#009900"><font size=+1># --replacement=Comma # -R
|
||||
: Replacement: Comma, Plus, EPTour(T), SSGAWorst, SSGADet(T), SSGAStoch(t)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
Name of replacement procedure. Availabable are the </font><b><font color="#FF6600">ES
|
||||
plus and comma</font></b><font color="#000000"> deterministic replacement
|
||||
strategies (named respectively </font><b><tt><font color="#009900"><font size=+1>Plus</font></font></tt></b><font color="#000000">
|
||||
and </font><b><tt><font color="#009900"><font size=+1>Comma</font></font></tt></b><font color="#000000">);
|
||||
</font><b><font color="#FF6600">EP
|
||||
stochastic tournament</font></b><font color="#000000"> (name </font><b><tt><font color="#009900"><font size=+1>EPTour</font></font></tt></b><font color="#000000">
|
||||
with tournament size in parentheses); and the </font><b><font color="#FF6600">steady-state
|
||||
</font></b><font color="#000000">replacement
|
||||
procedures, at the moment only based on fitnesses, replacement being either
|
||||
</font><font color="#FF6600">deterministic</font><font color="#000000">
|
||||
(new born replace worst parent, name </font><b><tt><font color="#009900"><font size=+1>SSGAWorst</font></font></tt></b><font color="#000000">),
|
||||
or based on a tournament (name </font><b><tt><font color="#009900"><font size=+1>SSGADet</font></font></tt></b><font color="#000000">
|
||||
for deterministic tournament, size in parentheses, and </font><b><tt><font color="#009900"><font size=+1>SSGAStoch</font></font></tt></b><font color="#000000">
|
||||
for stochastic tournament, probability in parentheses). </font><font color="#FF0000">Default
|
||||
is Comma</font><font color="#000000"> (which btw is also SGA </font><font color="#FF0000">generational
|
||||
replacement</font><font color="#000000"> whenever there are as many offspring
|
||||
as parents).</font>
|
||||
<p><b><tt><font color="#009900"><font size=+1># --weakElitism=0 # -w :
|
||||
Old best parent replaces new worst offspring *if necessary*</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
if true, weak elitism is added to the replacement procedure (i.e. if the
|
||||
best fitness among the offspring is less than the best fitness, the best
|
||||
parent replaces the worst offspring). </font><font color="#FF0000">Default
|
||||
is false.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#3333FF">######
|
||||
Output ######</font></tt></font></b>
|
||||
<br><font color="#000000">This first section on Output contains parameters
|
||||
related to screen text output.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --useEval=1 # Use nb of
|
||||
eval. as counter (vs nb of gen.)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
whether or not you want the nb of evluations to be displayed and used as
|
||||
counter in statistics outputs and plots. </font><font color="#FF0000">Default
|
||||
is true</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --printBestStat=1 # Print
|
||||
Best/avg/stdev every gen.</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
toggles screen output of indicated statistics. </font><font color="#FF0000">Default
|
||||
is true</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --printPop=0 # Print sorted
|
||||
pop. every gen.</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
adds a dump of the whole population to the screen every generation. Is
|
||||
likely to generate </font><b><font color="#FF6600">huge</font></b><font color="#000000">
|
||||
output! </font><font color="#FF0000">Default is false.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --printFDC=1 # Print FDC
|
||||
coeff. every gen.</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
adds Fitness Distance Correlation to output every generation. </font><font color="#FF0000">Default
|
||||
is false.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#3333FF">######
|
||||
Output - Disk ######</font></tt></font></b>
|
||||
<br><font color="#000000">This second section on Output contains parameters
|
||||
related to DISK output.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --resDir=Res # Directory
|
||||
to store DISK outputs</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter: </font><font color="#000000">All
|
||||
</font><font color="#FF6600">DISK
|
||||
output</font><font color="#000000"> will be stored in a separate directory
|
||||
-this is its name. If the directory does not exist, it is created. Note
|
||||
that </font><font color="#FF6600">all graphical displays</font><font color="#000000">
|
||||
will use that directory for their temporary files. Also </font><font color="#FF6600">all
|
||||
job dump</font><font color="#000000"> (see section </font><b><font color="#3333FF">Persistence</font></b><font color="#000000">
|
||||
below) store their files there too.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --eraseDir=0 # erase files
|
||||
in dirName if any</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
in order not to mix up files from different runs, it is mandatory to ensure
|
||||
that the directory where all files will be stored is empty. However, if
|
||||
this parameter is not set and the directory already exists, an exception
|
||||
is thrown and the program stops. It it is set, </font><b><font color="#FF6600">all
|
||||
files in the result directory are erased</font></b><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --fileBestStat=0 # Output
|
||||
Best/avg/stdev to a file</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
if present, the best, average and standard deviation statistics are stored
|
||||
in file </font><b><tt><font color="#993300"><font size=+1>resDir/best.xg</font></font></tt></b><font color="#000000">.
|
||||
Each line contains the generation number, eventualy the evaluation count
|
||||
(depending on parameter </font><b><tt><font color="#3333FF"><font size=+1>useEval</font></font></tt></b><font color="#000000">
|
||||
then the statistics. </font><font color="#FF0000">Default is false.</font>
|
||||
<br>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#3333FF">######
|
||||
Output - Graphical ######</font></tt></font></b>
|
||||
<br><font color="#000000">This last section on Output contains parameters
|
||||
related to graphical output (only available in Unix through gnuplot at
|
||||
the moment).</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --plotBestStat=0 # Plot
|
||||
Best/avg Stat</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
toggles gnuplot output of best and average plots (Linux only at the moment).
|
||||
</font><font color="#FF0000">Default
|
||||
is false.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --plotFDCStat=0 # Plot
|
||||
FDC scatter plot</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
toggles the Fitness Distance Correlation plot (Fitness vs distance to best).
|
||||
</font><font color="#FF0000">Default
|
||||
is false.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --plotHisto=0 # Plot histogram
|
||||
of fitnesses</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
if on, gnuplot is used to plot the sorted population (fitness vs rank).
|
||||
Gives a graphical idea of the diversity. </font><font color="#FF0000">Default
|
||||
is false.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#3333FF">######
|
||||
Persistence ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section contains parameters handling job
|
||||
dump and restart mechanism.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --Load= # -L : A save file
|
||||
to restart from</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
if present, the initial population (and the RNG) is read from indicated
|
||||
file. That file </font><b><font color="#FF0000">must</font></b><font color="#000000">
|
||||
come from a previous save (or must be in same format!), i.e. must contain
|
||||
a popualtion, the RNG and all parameters. If no other parameter is modified,
|
||||
using a previously saved population and RNG will give exactly the same
|
||||
results than having run that previous run longer. And a way to be sure
|
||||
to re-use the same parameters is to ... use that very save file as parameter
|
||||
file, as it contains all actual parameters in the right format.</font>
|
||||
<br><font color="#000000">Note that if not enough individuals are read,
|
||||
the remaining are randomly initialized. </font><font color="#FF0000">No
|
||||
default value</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --recomputeFitness=0 #
|
||||
-r : Recompute the fitness after re-loading the pop.?</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
in case some individuals are read from a file, their fitness is read too.
|
||||
If this one is true, it is nevertheless recomputed. </font><font color="#FF0000">Default
|
||||
is false</font><font color="#000000"> i.e. use fitnes that's in the file.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --saveFrequency=0 # Save
|
||||
every F generation (0 = only final state, absent = never)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
interval between two dump to disk of the whole population (+RNG + parameters),
|
||||
in a file named genNN.sav in the </font><b><tt><font color="#993300"><font size=+1>dirRes</font></font></tt></b><font color="#000000">
|
||||
directory, where NN is the generation number. If this prameter is present
|
||||
(even with 0 or negative value), the final population will always be saved,
|
||||
whatever the reason for stopping. Hence the only way to avoid all saves
|
||||
is to omit the parameter (there is </font><font color="#FF0000">no default
|
||||
value</font><font color="#000000">).</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --saveTimeInterval=0 #
|
||||
Save every T seconds (0 or absent = never)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
time interval between two population (+RNG + parameters) dumps to disks.
|
||||
Files are names timeNN.sav. See pervious parameter description for ore
|
||||
details. </font><font color="#FF0000">No default value.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --status=t-eoGA.status
|
||||
# Status file</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
name of the status file (that contains all parameters in the input format).
|
||||
There is no way to avoid creating that file except recompiling ... or giving
|
||||
the name /dev/null (Unix). Default value is </font><font color="#FF0000">ProgramName.status</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#3333FF">######
|
||||
Stopping criterion ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section allows to decide when the algorithm
|
||||
will stop.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --maxGen=100 # -G : Maximum
|
||||
number of generations (0 = none)</font></font></tt></b>
|
||||
<br><font color="#000000">Integer parameter: maximum number of generations.
|
||||
A value of 0 disables that stopping criterion. </font><font color="#FF0000">Default
|
||||
is 100.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --steadyGen=100 # -s :
|
||||
Number of generations with no improvement</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
stops whenever that number of generations is passed without any improvement
|
||||
of the best fitness in the population, provided the following minimum number
|
||||
of generations has been done. </font><font color="#FF0000">No default value.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --minGen=0 # -g : Minimum
|
||||
number of generations</font></font></tt></b>
|
||||
<br><font color="#000000">Integer parameter: the above steadyGen parameter
|
||||
starts its job only after that minimum nuber of generations is passed.
|
||||
</font><font color="#FF0000">No
|
||||
default value.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --maxEval=0 # -E : Maximum
|
||||
number of evaluations (0 = none)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
maximum number of generations.
|
||||
</font><font color="#FF0000">No default
|
||||
value.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --targetFitness=0 # -T
|
||||
: Stop when fitness reaches</font></font></tt></b>
|
||||
<br><font color="#FF0000">Real-valued parameter:</font><font color="#000000">
|
||||
the algorithm stops whenever the best fitness reaches that target. </font><font color="#FF0000">No
|
||||
default value.</font>
|
||||
<p><b><tt><font color="#3333FF"><font size=+1># --CtrlC=0 # -C : Terminate
|
||||
current generation upon Ctrl C</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
if true, Ctrl C only stops after the current generation as completed (eventually
|
||||
dumping population to a file if some saver is active). This very useful
|
||||
feature is only available in Unix at the moment. </font><font color="#FF0000">Default
|
||||
is false.</font>
|
||||
<br>
|
||||
<hr ALIGN=LEFT SIZE=5 WIDTH="100%">
|
||||
<p><a NAME="binary"></a><b><font size=+1><font color="#000099">User's guide:</font><font color="#FF0000">Bistring
|
||||
specific parameters</font></font></b>
|
||||
<br>The following describes the specific parameters that are available
|
||||
in program BitEA to evolve genotypes that are <b><font color="#FF6600">bitstrings</font></b>.
|
||||
<br>The two representation-dependent sections are concerned repectively
|
||||
with genotype initilization and variation operators.
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#CC33CC">######
|
||||
Genotype Initialization ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section should allow input if all necessary
|
||||
parameters for genitype initialization</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --ChromSize=10 # -n : The
|
||||
length of the bitstrings</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
The bitstring initilization only requires the length of the chromosome.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#CC33CC">######
|
||||
Variation Operators ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section allows to tune the way the variation
|
||||
operators will be applied to the individuals (in the strict limit of SGA
|
||||
model at the moment, see below).</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --operator=SGA # -o : Description
|
||||
of the operator (SGA only now)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
Describes the way the operators are applied. At the moment, </font><b><font color="#FF6600">only
|
||||
SGA</font></b><font color="#000000"> is available. SGA </font><b><font color="#FF6600">sequentially</font></b><font color="#000000">
|
||||
applies a (quadratic) crossover operator with probability </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
and a mutation operator with probability </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">.
|
||||
Both these operators can in turn be </font><b><font color="#FF6600">proportional
|
||||
combinations</font></b><font color="#000000"> of simple operators of the
|
||||
same arity.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --pCross=0.6 # -C : Probability
|
||||
of Crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The probability that a given couple of selected genitors is applied the
|
||||
crossover operator. In SGA operator model, each couple of selected genitors
|
||||
is applied the crossover operator with that probability (and remains unchanged
|
||||
with probability </font><b><tt><font color="#CC33CC"><font size=+1>1-pCross</font></font></tt></b><font color="#000000">.
|
||||
Whenever a couple undergoes crossover, a choice is made upon available
|
||||
crossover operators </font><b><font color="#FF6600">proportionaly to their
|
||||
relative rates</font></b><font color="#000000"> (see below). </font><font color="#FF0000">Default
|
||||
is 0.6</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --pMut=0.1 # -M : Probability
|
||||
of Mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The probability that a given individual (resulting from a crossover or
|
||||
a non-crossover operation, see above) is applied the mutation operator.
|
||||
Whenever an individual undergoes mutation, a choice is made upon available
|
||||
mutation operators </font><b><font color="#FF6600">proportionaly to their
|
||||
relative rates</font></b><font color="#000000"> (see below). </font><font color="#FF0000">Default
|
||||
is 0.1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --onePointRate=1 # -1 :
|
||||
Relative rate for one point crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the 1-point crossover </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to 2-point and uniform below (see </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
parameter). </font><font color="#FF0000">Default is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --twoPointRate=1 # -2 :
|
||||
Relative rate for two point crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the 2-point crossover </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to 1-point above and uniform below (see </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
parameter). </font><font color="#FF0000">Default is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --uRate=2 # -U : Relative
|
||||
rate for uniform crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the 1-point crossover </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to 1- and 2-point above (see </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
parameter). </font><font color="#FF0000">Default is 2</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --pMutPerBit=0.01 # -b
|
||||
: Probability of flipping 1 bit in bit-flip mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
When </font><b><tt><font color="#CC33CC"><font size=+1>bit-flip mutation</font></font></tt></b><font color="#000000">
|
||||
is applied, each bit is flipped independently with probability </font><b><tt><font color="#CC33CC"><font size=+1>pMutPerBit</font></font></tt></b><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --bitFlipRate=0.01 # -s
|
||||
: Relative rate for bit-flip mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the bit-flip mutation </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to one-Bit mutation below (see </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">
|
||||
above). </font><font color="#FF0000">Default is 0.01</font><font color="#000000">
|
||||
(if all relative rates are equal, the choice is uniform among available
|
||||
operators).</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --oneBitRate=0.01 # -d
|
||||
: Relative rate for deterministic bit-flip mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the one-bit mutation </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to bit-flip mutation below (see </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">
|
||||
above). One-bit mutation flips one and only one bit, uniformly chosen in
|
||||
the individual. </font><font color="#FF0000">Default is 0.01</font><font color="#000000">
|
||||
(if all relative rates are equal, the choice is uniform among available
|
||||
operators).</font>
|
||||
<br>
|
||||
<p>
|
||||
<hr ALIGN=LEFT SIZE=5 WIDTH="100%">
|
||||
<p><a NAME="real"></a><b><font size=+1><font color="#000099">User's guide:</font><font color="#FF0000">Real-valued
|
||||
specific parameters</font></font></b>
|
||||
<br>
|
||||
To run your own real-valued application, write your fitness function
|
||||
(see <b><tt><font color="#993300" size=+1>real_value.h</font></font></tt></b>),
|
||||
recompile, and run from the command line <br>
|
||||
<center><b><tt><font color="#993300" size=+1>RealEA @RealEA.param</font></tt></b></center><br>
|
||||
in order to use sensible parameters! (see <a href="eoLesson3.html#paraminput">Lesson 3</a>
|
||||
for details on the parameter file).
|
||||
But remember that <a href="#ES">Self-adaptive ES</a> will work much better!
|
||||
<br><br>
|
||||
The following describes the specific parameters that are available
|
||||
in programs <b><tt><font color="#993300"><font size=+1>RealEA</font></font></tt></b>
|
||||
and <b><tt><font color="#993300"><font size=+1>ESEA</font></font></tt></b>
|
||||
to evolve genotypes that are <b><font color="#FF6600">vector<double></font></b>.
|
||||
<br><b><tt><font color="#993300"><font size=+1>RealEA</font></font></tt></b>
|
||||
implements what can be called a "real-coded GA", where everything is identical
|
||||
to the bitstring case above (except initialization and operators that are
|
||||
specific to vector<double> of course) and <b><tt><font color="#993300"><font size=+1>ESEA</font></font></tt></b>
|
||||
implements the full Evolution-Strategy self-adaptive mutation mechanism
|
||||
- together with specific ES crossover operators. The initialization section
|
||||
for both programs are identical, but the operator sections are totally
|
||||
different. See <a href="#ES">next paragraph</a> for a description of ES
|
||||
specific parameters.
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#CC33CC">######
|
||||
Genotype Initialization ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section should allow input if all necessary
|
||||
parameters for genitype initialization</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --vecSize=10 # -n : The
|
||||
number of variables</font></font></tt></b>
|
||||
<br><font color="#FF0000">Integer parameter:</font><font color="#000000">
|
||||
The initilization requires the length of the vector<double>.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --initBounds=10[-1,1] #
|
||||
-B : Bounds for uniform initialization</font></font></tt></b>
|
||||
<br><font color="#FF0000">Bounds parameter:</font><font color="#000000">
|
||||
Bounds for uniform initialization of the real variables. The syntax for
|
||||
this parameter given in the </font><b><tt><font color="#CC33CC"><font size=+1>objectBounds</font></font></tt></b><font color="#000000">
|
||||
parameter description below. This argument is mandatory, furthermore the
|
||||
given bounds </font><b><font color="#FF6600">must be bounded</font></b><font color="#000000">.
|
||||
</font><font color="#FF0000">The
|
||||
default is [-1,1]</font><font color="#000000"> for all variables.</font>
|
||||
<br>Note that this parameter is independent of the <b><tt><font color="#CC33CC"><font size=+1>objectBounds</font></font></tt></b>
|
||||
parameter below.
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --sigmaInit=0.3 # -s :
|
||||
Initial value for Sigma(s)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The initial value for all standard-deviation mutation strategy parameters.
|
||||
Useless when no self-adaptive mutation mechanism is used.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#CC33CC">######
|
||||
Variation Operators ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section allows to tune the way the variation
|
||||
operators will be applied to the individuals (in the strict limit of SGA
|
||||
model at the moment, see below).</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --objectBounds=10[-inf,+inf]
|
||||
# -B : Bounds for variables</font></font></tt></b>
|
||||
<br><font color="#FF0000">Bounds parameter:</font><font color="#000000">
|
||||
Bounds for object variables. The syntax for this parameter is a succession
|
||||
of (optionally semi-colon separated) items of the form </font><b><tt><font color="#993300"><font size=+1>N[min,Max]</font></font></tt></b><font color="#000000">where
|
||||
the optional integer </font><b><tt><font color="#993300"><font size=+1>N</font></font></tt></b><font color="#000000">
|
||||
indicates how many variables have the given bounds. </font><b><tt><font color="#993300"><font size=+1>min</font></font></tt></b><font color="#000000">
|
||||
and </font><b><tt><font color="#993300"><font size=+1>Max</font></font></tt></b><font color="#000000">
|
||||
are either floating point numbers, or </font><b><tt><font color="#993300"><font size=+1>-inf</font></font></tt></b><font color="#000000">
|
||||
(resp. </font><b><tt><font color="#993300"><font size=+1>+inf</font></font></tt></b><font color="#000000">)
|
||||
to indicate unbounded direction. If not enough bounds are provided, the
|
||||
remaining variables will have the same bounds as the last bounds given.</font>
|
||||
<br><font color="#000000">This argument is mandatory, and
|
||||
</font><font color="#FF0000">default
|
||||
is [-inf,+inf]</font><font color="#000000">, i.e. unbounded variables.</font>
|
||||
<p><b><font color="#FF0000">Examples</font></b><font color="#000000">:
|
||||
</font><b><tt><font color="#CC33CC"><font size=+1>10[-1,1]</font></font></tt></b><font color="#000000">is
|
||||
equivalent to simply </font><b><tt><font color="#CC33CC"><font size=+1>[-1,1]</font></font></tt></b><font color="#000000">
|
||||
or to the extended </font><b><tt><font color="#CC33CC"><font size=+1>[-1,1][-1,1][-1,1][-1,1][-1,1][-1,1][-1,1][-1,1][-1,1][-1,1]</font></font></tt></b><font color="#000000">.</font>
|
||||
<br><font color="#000000">And </font><b><tt><font color="#CC33CC"><font size=+1>[-1,1];2[0,1];[-inf,10]</font></font></tt></b>results
|
||||
in the first variable staying in [-1,1], the second and the third in [0,1]
|
||||
and all remaining variables below 10.
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --operator=SGA # -o : Description
|
||||
of the operator (SGA only now)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
Describes the way the operators are applied. At the moment, </font><b><font color="#FF6600">only
|
||||
SGA</font></b><font color="#000000"> is available. SGA </font><b><font color="#FF6600">sequentially</font></b><font color="#000000">
|
||||
applies a (quadratic) crossover operator with probability </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
and a mutation operator with probability </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">.
|
||||
Both these operators can in turn be </font><b><font color="#FF6600">proportional
|
||||
combinations</font></b><font color="#000000"> of simple operators of the
|
||||
same arity.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --pCross=0.6 # -C : Probability
|
||||
of Crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The probability that a given couple of selected genitors is applied the
|
||||
crossover operator. In SGA operator model, each couple of selected genitors
|
||||
is applied the crossover operator with that probability (and remains unchanged
|
||||
with probability </font><b><tt><font color="#CC33CC"><font size=+1>1-pCross</font></font></tt></b><font color="#000000">.
|
||||
Whenever a couple undergoes crossover, a choice is made upon available
|
||||
crossover operators </font><b><font color="#FF6600">proportionaly to their
|
||||
relative rates</font></b><font color="#000000"> (see below). </font><font color="#FF0000">Default
|
||||
is 0.6</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --pMut=0.1 # -M : Probability
|
||||
of Mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The probability that a given individual (resulting from a crossover or
|
||||
a non-crossover operation, see above) is applied the mutation operator.
|
||||
Whenever an individual undergoes mutation, a choice is made upon available
|
||||
mutation operators </font><b><font color="#FF6600">proportionaly to their
|
||||
relative rates</font></b><font color="#000000"> (see below). </font><font color="#FF0000">Default
|
||||
is 0.1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --alpha=0 # -a : bound
|
||||
for combination factor in real crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Bound for the choices of linear combination factors in both crossover belows
|
||||
(similar to BLX-alpha notation). </font><font color="#FF0000">Default is
|
||||
0</font><font color="#000000"> (i.e. combination factor are chosen in [0,1]).</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --segmentRate=1 # -s :
|
||||
Relative rate for segment crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of application of the segment crossover </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to hypercube and uniform crossovers (see </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
parameter). Segment crossover generates offspring uniformly on the segment
|
||||
joining both parents, i.e. constructs two linear combinations of the parents
|
||||
with a random number uniformly drawn in [</font><b><tt><font color="#CC33CC"><font size=+1>alpha</font></font></tt></b><font color="#000000">,1+</font><b><tt><font color="#CC33CC"><font size=+1>alpha</font></font></tt></b><font color="#000000">].
|
||||
</font><font color="#FF0000">Default
|
||||
is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --hypercubeRate=1 # -A
|
||||
: Relative rate for hypercube crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of application of the hypercube crossover </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to segment and uniform crossovers (see </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
parameter). Hypercube crossover generates offspring uniformly on the hypercube
|
||||
whose diagonal is the segment joining both parents, i.e. by doing linear
|
||||
combinations of each variable independently (a random number in [</font><b><tt><font color="#CC33CC"><font size=+1>alpha</font></font></tt></b><font color="#000000">,1+</font><b><tt><font color="#CC33CC"><font size=+1>alpha</font></font></tt></b><font color="#000000">]
|
||||
is drawn anew for each variable). </font><font color="#FF0000">Default
|
||||
is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --uxoverRate=1 # -A : Relative
|
||||
rate for uniform crossover</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of application of the segment crossover </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to hypercube and segment crossovers (see </font><b><tt><font color="#CC33CC"><font size=+1>pCross</font></font></tt></b><font color="#000000">
|
||||
parameter). Uniform crossover simply exchanges values of variables, i.e.
|
||||
uniformly picks up two other summits of the hypercube defined by the parents.
|
||||
</font><font color="#FF0000">Default
|
||||
is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --epsilon=0.01 # -e : Half-size
|
||||
of interval for Uniform Mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The uniform and deterministic-uniform mutations will choose values of variable
|
||||
X uniformly in </font><b><tt><font size=+1><font color="#993300">[X-</font><font color="#CC33CC">epsilon</font><font color="#993300">,
|
||||
X+</font><font color="#CC33CC">epsilon</font><font color="#993300">]</font></font></tt></b><font color="#000000">.
|
||||
</font><font color="#FF0000">Default
|
||||
is 0.01</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --uniformMutRate=1 # -u
|
||||
: Relative rate for uniform mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the uniform mutation </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to determinitic uniform and the normal mutations (see </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">
|
||||
above). Uniform mutation modifies all variables by choosing new values
|
||||
uniformly on an interval centered on the old value of width </font><b><tt><font size=+1><font color="#993300">2*</font><font color="#CC33CC">epsilon</font></font></tt></b><font color="#000000">
|
||||
(see above). </font><font color="#FF0000">Default is1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --detMutRate=1 # -d : Relative
|
||||
rate for deterministic uniform mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the determinisitc-uniform mutation </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to uniform and normal mutations (see </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">
|
||||
above). Deterministic-uniform mutation modifies one single variable uniformly
|
||||
based on epsilon </font><b><tt><font color="#CC33CC"><font size=+1>epsilon</font></font></tt></b><font color="#000000">.
|
||||
</font><font color="#FF0000">Default
|
||||
is1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --normalMutRate=1 # -d
|
||||
: Relative rate for Gaussian mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
Rate of aplication of the normal mutation </font><b><font color="#FF6600">relatively</font></b><font color="#000000">
|
||||
to two uniform mutations above (see </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">
|
||||
above). </font><font color="#FF0000">Default is1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --sigma=0.3 # -s : Sigma
|
||||
(fixed) for Gaussian mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The value of standard deviation for Gaussian mutation - fixed along evolution
|
||||
(see the Evolution Strategy program below for self-adaptive mutations).</font>
|
||||
<p>
|
||||
<hr ALIGN=LEFT SIZE=5 WIDTH="100%">
|
||||
<p><a NAME="ES"></a><b><font size=+1><font color="#000099">User's guide:</font><font color="#FF0000">ES
|
||||
with self-adative mutation parameters</font></font></b>
|
||||
<br>
|
||||
To run your own SA-ES application, write your fitness function
|
||||
(see <b><tt><font color="#993300" size=+1>real_value.h</font></font></tt></b>),
|
||||
recompile, and run from the command line <br>
|
||||
<center><b><tt><font color="#993300" size=+1>ESEA @ESEA.param</font></tt></b></center><br>
|
||||
in order to use sensible parameters! (see <a href="eoLesson3.html#paraminput">Lesson 3</a>
|
||||
for details on the parameter file).
|
||||
<br><br>
|
||||
The following describes the specific parameters for program <b><tt><font color="#993300"><font size=+1>ESEA</font></font></tt></b>,
|
||||
that implements the full Evolution-Strategy self-adaptive mutation mechanism
|
||||
- together with specific ES crossover operators. The initialization section
|
||||
is the same as the one for plain vector<double> above, so only the opeartor
|
||||
sections will be described here. A new section is now concerned with deciding
|
||||
what kind of self-adaptive mutation strategy will be applied - it has been
|
||||
separated from the other variation operators because it has consequences
|
||||
on the choice of the genotype.
|
||||
<br><b><font color="#FF6600">Warning</font></b>: if you choose not to use
|
||||
any self-adaptive mechanism (i.e. setting all parameters of this section
|
||||
to false) you end up with ... an algorithm that is identical to <b><tt><font color="#993300"><font size=+1>RealEA</font></font></tt></b>
|
||||
above (try it and take alook at the status file).
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#CC33CC">######
|
||||
ES mutation ######</font></tt></font></b>
|
||||
<br><font color="#000000">This section allows to decide which type of self-adaptive
|
||||
mutation will be used. There are three available types: isotropic mutation,
|
||||
using one standard deviation for each individual, that will be applied
|
||||
to all variables; anisotropic mutation, where each individual carries as
|
||||
many standard deviations as it has variables; and correlated mutation where
|
||||
each individuals has its own full correlation matrix.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --Isotropic=1 # -i : Isotropic
|
||||
self-adaptive mutation</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
If true, at least one self-adaptive parameter will be used for each individual.
|
||||
</font><font color="#FF0000">Default
|
||||
is true</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --Stdev=0 # -s : One self-adaptive
|
||||
stDev per variable</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
If true, at least one self-adaptive parameter per variable will be used
|
||||
for each individual. </font><font color="#FF0000">Default is false</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --Correl=0 # -c : Use correlated
|
||||
mutations</font></font></tt></b>
|
||||
<br><font color="#FF0000">Boolean parameter:</font><font color="#000000">
|
||||
If true, full correalted self-adaptive mutation will be used for each individual.
|
||||
</font><font color="#FF0000">Default
|
||||
is false</font><font color="#000000">.</font>
|
||||
<p><b><font color="#FF6600">Note</font></b><font color="#000000">: The
|
||||
default values result in an isotropic self-adaptive mutation to be chosen.</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="30%">
|
||||
<p><b><font size=+1><font color="#FF0000">Section </font><tt><font color="#CC33CC">######
|
||||
Variation Operators ######</font></tt></font></b>
|
||||
<br><font color="#000000">Only the parameters that are specific to ESEA
|
||||
are presented here - the </font><b><tt><font color="#CC33CC"><font size=+1>objectBounds,operator,pCross</font></font></tt></b><font color="#000000">
|
||||
and </font><b><tt><font color="#CC33CC"><font size=+1>pMut</font></font></tt></b><font color="#000000">
|
||||
are exactly the same as for </font><b><tt><font color="#993300"><font size=+1>RealEA</font></font></tt></b><font color="#000000">
|
||||
above.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --crossType=global # -C
|
||||
: Type of ES recombination (global or standard)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
Es crossover can involve only two parents - and it is then identical to
|
||||
the </font><b><tt><font color="#CC33CC"><font size=+1>standard</font></font></tt></b><font color="#000000">
|
||||
hypercube crossover describe for the </font><b><tt><font color="#993300"><font size=+1>RealEA</font></font></tt></b><font color="#000000">
|
||||
parameters above. But new parents can also be chosen anew for each variable
|
||||
before doing the crossover for that variable - and this is called </font><b><tt><font color="#CC33CC"><font size=+1>global</font></font></tt></b><font color="#000000">
|
||||
recombination.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --crossObj=discrete # -O
|
||||
: Recombination of object variables (discrete or intermediate)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
There are two possible crossovers in plain ES. The </font><b><tt><font color="#CC33CC"><font size=+1>discrete</font></font></tt></b><font color="#000000">
|
||||
crossover simpy exchanges variables among the parents. It is similar to
|
||||
the plain uniform crossover for real variables. The crossover performs
|
||||
a linear combination of parents;variables - it si similar to the hypercube
|
||||
crossover described for with alpah parameter set to 0. This parameter
|
||||
allso to choose the type of crossover that will be applied to the </font><b><font color="#FF6600">object
|
||||
variables</font></b><font color="#000000"> (i.e. the origianl variables
|
||||
of the problem). </font><font color="#FF0000">Default is discrete.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --crossStdev=intermediate
|
||||
# -S : Recombination of mutation strategy parameters (intermediate or discrete)</font></font></tt></b>
|
||||
<br><font color="#FF0000">String parameter:</font><font color="#000000">
|
||||
This parameter allows to choose the type of crossover (see above) that
|
||||
will be applied to the </font><b><font color="#FF6600">mutation strategy
|
||||
parameters</font></b><font color="#000000"> that are part of the genotype.
|
||||
</font><font color="#FF0000">Default
|
||||
is intermediate.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --TauLoc=1 # -l : Local
|
||||
Tau (before normalization)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The local factor for the mutation of the mutation strategy parameters (the
|
||||
only one used when a single standard deviation is used). </font><font color="#FF0000">Default
|
||||
is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --TauGlob=1 # -g : Global
|
||||
Tau (before normalization)</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The global factor for the mutation of the mutation strategy parameters
|
||||
(only useful when more than one standard deviation are used). </font><font color="#FF0000">Default
|
||||
is 1</font><font color="#000000">.</font>
|
||||
<p><b><tt><font color="#CC33CC"><font size=+1># --Beta=0.0873 # -b : Beta</font></font></tt></b>
|
||||
<br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">
|
||||
The factor for the mutation of the rotation angles in the case of the full
|
||||
correlated mutation. </font><font color="#FF0000">Default is 0.0873</font><font color="#000000">
|
||||
(following Schwefel).</font>
|
||||
<p>
|
||||
<hr SIZE=5 WIDTH="100%">
|
||||
<br><a NAME="programmerguide"></a><b><font color="#000099"><font size=+2>Programmer's
|
||||
guide</font></font></b>
|
||||
<p>At the moment, you will have to browse in the source (colored!) code
|
||||
(<a href="BitEA.html">Bit</a> - Real) almost by yourself, sorry.
|
||||
<p>Note that the main file is now very slim, as it only contains calls
|
||||
to some <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
|
||||
functions - these functions contain the actual code, very similar to the
|
||||
code of Lesson3, except for the memory management, performed through an
|
||||
<b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_state.html">eoState</a></font></font></tt></b>
|
||||
object (notice that all <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
|
||||
calls have an eoState as second parameter).
|
||||
<p><b><font color="#000099"><font size=+2>Programmer's guide: </font></font><font color="#FF0000"><font size=+1>The
|
||||
make_xxx files</font></font></b>
|
||||
<p><b><font color="#FF0000">Interface</font></b>: all <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
|
||||
files have as first two parameters an <b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_parser.html">eoParser</a></font></font></tt></b>
|
||||
and an <b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_state.html">eoState</a></font></font></tt></b>.
|
||||
The <b><tt><font color="#3366FF"><font size=+1>eoParser</font></font></tt></b>
|
||||
is be used within all functions to parse the command-line and/or a parameter
|
||||
file in order to read any relevant user-parameter, while the <b><tt><font color="#3366FF"><font size=+1>eoState</font></font></tt></b>
|
||||
is used here to store all pointers to be allocated inside the function
|
||||
(see <a href="eoProgramming.html#memory">Programming hints</a> for more
|
||||
detailed explanations).
|
||||
<p>There are 2 types of <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
|
||||
files: the ones that do depend on representation, defining the <b><font color="#FF9900">genotype
|
||||
</font></b>and
|
||||
<b><font color="#CC33CC">initialization</font></b>
|
||||
(<b><tt><font color="#CC33CC"><font size=+1>make_genotype_xxx</font></font></tt></b>,
|
||||
with xxx being the type of genotype) and variation operators (<b><tt><font color="#CC33CC"><font size=+1>make_op_xxx</font></font></tt></b>),
|
||||
and the one that are truly representation-independent (<b><tt><font color="#993300"><font size=+1>make_pop,
|
||||
make_continue, make _checkpoint, make_algo </font></font></tt></b><font color="#000000">and</font><b><tt><font color="#993300"><font size=+1>
|
||||
make_run</font></font></tt></b>).
|
||||
<br>The former are located in the directory corresponding to the actual
|
||||
genotype (<b><tt><font color="#FF9900"><font size=+1>src/ga</font></font></tt></b>
|
||||
for eoBit, <b><tt><font color="#FF9900"><font size=+1>src/es</font></font></tt></b>
|
||||
for eoReal and all eoESxxx genotypes). The latter are in the directory
|
||||
<b><tt><font color="#993300"><font size=+1>src/do.</font></font></tt></b>
|
||||
<p>If you take a close look at the code of <b><tt><font color="#993300"><font size=+1><a href="../../src/do/make_continue.h">make_continue</a></font></font></tt></b>
|
||||
for instance, you will first notice that ... the function declared there
|
||||
is called <b><tt><font color="#993300"><font size=+1>do_make_continue</font></font></tt></b>
|
||||
and is not <a href="BitEA.html#continue">the one you are calling</a> in
|
||||
the main file, though it has the same parameters as arguments.
|
||||
<br>The explanation lies within the file <b><tt><font color="#FF9900"><font size=+1>make_continue_xxx.cpp</font></font></tt></b>
|
||||
(with xxx = ga or real/es)which, as its color (and name) should have
|
||||
told you about, are representation-dependent: in fact the <b><tt><font color="#FF9900"><font size=+1>make_continue_xxx.cpp</font></font></tt></b>
|
||||
files only instanciates the general <EOT> template into one of the possible
|
||||
template for eoBit or eoReal/eoES - and this trick allows to <b><font color="#FF6600">compile
|
||||
them separately</font></b>!
|
||||
<p>The other thing that you should notice is that the code there is very
|
||||
similar to the code that was in Lesson 3, regarding parameter reading
|
||||
and type of object that are allocated - except for memory management. This
|
||||
goes for all <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
|
||||
files - so the only thing you need to understand how it goes is to look
|
||||
at the <a href="#memory">memory management section</a>.
|
||||
<p><b><font color="#FF0000">Pros</font></b>: you don't have to handle a
|
||||
huge main function - and many of the make_xxx files can be directly used
|
||||
in different applications (this is called <b><font color="#FF6600">modularity</font></b>
|
||||
:-)))
|
||||
<br>More interesting, you can even <b><font color="#FF6600">compile</font></b>
|
||||
the <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>
|
||||
files <b><font color="#FF6600">separately</font></b> for a given target
|
||||
template, and link them e.g. with your fitness function when it is ready
|
||||
(remember that up to now you needed to compile everything altogether by
|
||||
including the code into your mail fine). Indeed, if you do a global make,
|
||||
you will notice that there are additional libraries compiled in <b><tt><font color="#FF9900"><font size=+1>src/ga</font></font></tt></b>
|
||||
and <b><tt><font color="#FF9900"><font size=+1>src/es</font></font></tt></b>
|
||||
...
|
||||
<p><b><font color="#FF0000">Cons</font></b>: It makes the code a little
|
||||
more complex to understand, first because of the indirection needed for
|
||||
pre-compilation with a given template, and second because of the memory
|
||||
management that this imposes.
|
||||
<br>
|
||||
<br>
|
||||
<p><a NAME="memory"></a><b><font color="#000099"><font size=+2>Programmer's
|
||||
guide: </font></font><font color="#FF0000"><font size=+1>Memory management</font></font></b>
|
||||
<br>As already said, all functions have an <b><tt><font color="#3366FF"><font size=+1>eoState</font></font></tt></b>
|
||||
as second argument - and that object is used to store the functor objects
|
||||
that were simply declared as variables of the main function up to now :
|
||||
see <a href="eoProgramming.html#memory">Programming hints</a> for more
|
||||
detailed explanations and take a look at the code of <b><tt><font color="#993300"><font size=+1><a href="../../src/do/make_continue.h">make_continue</a></font></font></tt></b>
|
||||
for instance, you will see the implementation of the memory management
|
||||
in action.
|
||||
<p><a NAME="parameter"></a><b><font color="#000099"><font size=+2>Programmer's
|
||||
guide: </font></font><font color="#FF0000"><font size=+1>Memory management
|
||||
of eoParam objects</font></font></b>
|
||||
<p>It has been seen in Lesson 3 that parameters could be read from command-line
|
||||
and/or a parameter file using an <b><tt><font color="#3366FF"><font size=+1>eoParser</font></font></tt></b>
|
||||
object. However, the memory mangement problem also concerns EO parameter
|
||||
objects (<b><tt><font color="#3366FF"><font size=+1>eoParam</font></font></tt></b>):
|
||||
the way there are read in <a href="eoLesson3.html#parameters">Lesson3</a>
|
||||
makes them local variables of the function they are defined in.
|
||||
<br>It is however possible to ask the <b><tt><font color="#3366FF"><font size=+1>eoParser</font></font></tt></b>
|
||||
to hold them, as done for instance in eoContinue for the maximum number
|
||||
of generations. Local declaration would amount to something like :
|
||||
<p><b><tt><font color="#3366FF"><font size=+1>eoValueParam<unsigned
|
||||
int>& maxGenParam(100, "maxGen", "Maximum number of generations ()
|
||||
= none)",'G');</font></font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"><font size=+1> parser.processParam(
|
||||
maxGenParam, "Stopping criterion" );</font></font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"><font size=+1> unsigned maxGen =
|
||||
maxGenParam.value();</font></font></tt></b>
|
||||
<p>while if you want the parser to hold those eoParam objects, you will
|
||||
write something like
|
||||
<p><b><tt><font color="#3366FF"><font size=+1>eoValueParam<unsigned>&
|
||||
maxGenParam = _parser.createParam(unsigned(100), "maxGen", "Maximum number
|
||||
of generations () = none)",'G',"Stopping criterion");</font></font></tt></b>
|
||||
<p>and then use <b><tt><font color="#3366FF"><font size=+1>maxGenParam.value()</font></font></tt></b>
|
||||
to get the value enterred by the user. In that case, you get a <b><font color="#FF6600">reference</font></b>
|
||||
to an eoParam object that is hold by the eoParser - and deleted whith it.
|
||||
<br>Note that there are <b><font color="#FF6600">two important differences</font></b>
|
||||
between the arguments of the constructor of an eoParam object and the method
|
||||
createParam of an eoParser object: first, you need to provide the additional
|
||||
section parameter (used only when outputting the eoParser); second you
|
||||
<b><font color="#FF6600">must</font></b>
|
||||
make sure that the first argument is of the correct type otherwise the
|
||||
compiler will complain.
|
||||
<p>Note that if you don't later need the eoParam, but simply its value,
|
||||
you can even diretly write
|
||||
<p><b><tt><font color="#3366FF"><font size=+1>unsigned maxGen = _parser.createParam(unsigned(100),
|
||||
"maxGen", "Maximum number of generations () = none)",'G',"Stopping criterion").value();</font></font></tt></b>
|
||||
<p><b><font color="#FF0000"><font size=+1>Getting parameter values in different
|
||||
functions:</font></font></b>
|
||||
<p>It is often useful (though probably <b><font color="#FF6600">very bad
|
||||
programming style </font></b>:-))) to be able to get the value of a user-defined
|
||||
parameter in two different places of the code without passing it around
|
||||
through many levels of call. You can then use the alternate function <b><tt><font color="#3366FF"><font size=+1>getORcreateParam</font></font></tt></b>
|
||||
with exactly the same syntax than <b><tt><font color="#3366FF"><font size=+1>createParam</font></font></tt></b>.
|
||||
<br>Be careful that the link between both parameters is made through their
|
||||
longmanes (second argument), and that you must so <b><font color="#FF6600">hard-code</font></b>
|
||||
that name in two different places with of course exactly the same spelling!!!
|
||||
<br><b><font color="#FF6600">Examples</font></b> can be found for instance
|
||||
in the make_genotype_xxx files, for the sizes of the genotypes: it is often
|
||||
the case that the definition of the optimization problem requires (or computes)
|
||||
such size. The idea is then that you either read or compute that size,
|
||||
then create a (dummy) parameter with the name that is used later in the
|
||||
make_genotype file. For instance, for bitstrings, the make_genotype_ga.h
|
||||
contains the following line defining the size of the bitstring
|
||||
<p><b><tt><font color="#3366FF"><font size=+1> unsigned theSize =
|
||||
_parser.getORcreateParam(unsigned(10), "chromSize", "The length of the
|
||||
bitstrings", 'n',"Problem").value();</font></font></tt></b>
|
||||
<p>If you want to define that size earlier, you should write somewhere
|
||||
before
|
||||
<br>
|
||||
<p><b><tt><font color="#3366FF"><font size=+1> unsigned requiredSize
|
||||
= ... ;</font></font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"><font size=+1> _parser.createParam(requiredSize,
|
||||
"chromSize", "The length of the bitstrings", 'n',"Problem");</font></font></tt></b>
|
||||
<p>Of course, if that size is mandatory, you should NOT modify it at run-time
|
||||
by entering anther value !
|
||||
<p>
|
||||
<hr WIDTH="100%"><b><font color="#FF0000">User's guide:</font></b> <a href="#userguide">General</a>
|
||||
- <a href="#binary">Bitstring</a> - <a href="#real">Real</a> - <a href="#ES">ES</a>
|
||||
- <b><font color="#FF0000">Programmer's guide:</font></b> <a href="#programmerguide">General</a>
|
||||
- <a href="#memory">Memory management </a>- <a href="#parameter">Parameters</a>
|
||||
<br>
|
||||
<hr WIDTH="100%"><font color="#000000"><a href="eoLesson3.html">Lesson
|
||||
3</a> -
|
||||
<a href="eoLesson5.html">Lesson 5</a> -
|
||||
<a href="eoTutorial.html">Main
|
||||
page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based</a>
|
||||
- <a href="eoProgramming.html">Hints</a> -<b> <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b></font>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<font color="#000000"><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></font></address>
|
||||
|
||||
<br><!-- Created: Tue May 1 14:49:12 CET 2001 --><!-- hhmts start --><font color="#000000">Last
|
||||
modified: None of your business!</font><!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
415
eo/tutorial/html/eoLesson5.html
Normal file
415
eo/tutorial/html/eoLesson5.html
Normal file
|
|
@ -0,0 +1,415 @@
|
|||
<!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>Tutorial: Lesson 5</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<a href="eoLesson4.html">Lesson 4</a> -
|
||||
<a href="eoLesson6.html">Lesson
|
||||
6</a> -
|
||||
<a href="eoTutorial.html">Main page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">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 Lesson 5: using your own genotype</font></h1></center>
|
||||
In this lesson, you will learn how to design and evolve <b><font color="#FF0000">your
|
||||
own genotype structure</font></b>. Note that at the moment, only algorithms
|
||||
involving a scalar fitness (double) are implemented (see test dir for Pareto
|
||||
optimization of multiple-objective fitness - or be patient :-)
|
||||
<p>The minimum code you'll have to write is first, of course, the code
|
||||
for the <a href="#genotype">genotype structure</a>. Then, the representation-dependent
|
||||
code: <a href="#initialization">intialization procedure(s)</a>,
|
||||
<a href="#variation">variation
|
||||
operators</a> (quadratic crossover, mutation operator), ... and <a href="#evaluation">evaluation
|
||||
function</a> - and that's it : we have prepared some template files and
|
||||
the script create.sh that will take care of generating a few other files
|
||||
to make your application complete.
|
||||
<p>In what follows, we will suppose that you want to evolve some data structure,
|
||||
and that you have enough programming skills to be able to write C code
|
||||
for its random initilialization, its crossover, its mutation and the computation
|
||||
of its fitness.
|
||||
<br>The examples will be described supposing you want to evolve ... bitstings
|
||||
to solve the OneMax problem (oh no!!!).
|
||||
<p>
|
||||
|
||||
<b><blink><font color="#FF0000">New</font></blink></b> May 2004 : A
|
||||
second script, <b><tt><font color="#993300">createSimple</font></tt></b>,
|
||||
was added some time ago, that generates much simpler
|
||||
set of files, and the <font color="#3366FF"><b>stat.tmpl</b></font>
|
||||
file is now used to allow you to
|
||||
<font color="#FF0000"><b>compute</b></font> and
|
||||
<font color="#FF0000"><b>print</b></font> and
|
||||
<font color="#FF0000"><b>save-to-disk</b></font> and
|
||||
<font color="#FF0000"><b>plot-on-line</b></font> your
|
||||
own <font color="#3366FF"><b>statistics</b></font>.
|
||||
But you'll have to find out by yourself how those work, sorry, no
|
||||
time. It should be easy by just looking at the code (in main file, and
|
||||
in <b><tt><font color="#993300">OneMaxEA.cpp</font></tt></b>
|
||||
and the newly created
|
||||
<b><tt><font color="#993300">eoOneMaxStat.h</font></tt></b>.<br><br>
|
||||
|
||||
<b><blink><font color="#FF0000">New</font></blink></b> May 2004 : In
|
||||
the same simplified main file (e.g. <b><tt><font
|
||||
color="#993300">OneMaxEA.cpp</font></tt></b> after running
|
||||
<b><tt><font color="#FF6666">./createsimple OneMax</font></tt></b> in
|
||||
dir <b><tt><font
|
||||
color="#FF6666"><b>.../eo/tutorial/Templates</b></font></tt></b>), you
|
||||
will also be able to use fitness sharing (together with roulette) as a
|
||||
possible selector.
|
||||
|
||||
|
||||
<hr WIDTH="100%"><a NAME="using"></a><b><font color="#000099"><font size=+2>Using
|
||||
template files</font></font></b>
|
||||
<br>Follow this very simple procedure:
|
||||
<ul>
|
||||
<li>
|
||||
choose a <b><font color="#FF6600">name</font></b> for you application -
|
||||
here <b><font color="#FF6600">OneMax</font></b> will be used</li>
|
||||
|
||||
<li>
|
||||
go to the <b><tt><font color="#993300">tutorial/Templates</font></tt></b>
|
||||
dir</li>
|
||||
|
||||
<br><tt><font color="#FF6666"> <b>cd
|
||||
pathWhereEOisInstalled/tutorial/Templates</b></font></tt>
|
||||
<li>
|
||||
run the <b><tt><font color="#993300">create.sh</font></tt></b> script with
|
||||
argument OneMax and second optional argument a directory name (suppose
|
||||
it's called APPLICATION here)</li>
|
||||
|
||||
<br><b><tt><font color="#FF6666">
|
||||
./create.sh OneMax APPLICATION</font></tt></b>
|
||||
<br>This will create a directory <b><tt><font color="#993300">tutorial/APPLICATION</font></tt></b>
|
||||
<li>
|
||||
Go to the APPLICATION directory</li>
|
||||
|
||||
<br><b><tt><font color="#FF6666">
|
||||
cd ../APPLICATION</font></tt></b>
|
||||
<br>You should see the following files:
|
||||
<br> <b><tt><font color="#993300">OneMaxEA.cpp
|
||||
</font></tt></b>the main main file, includes all other, to be compiled
|
||||
<br> <b><tt><font color="#993300">Makefile
|
||||
</font></tt></b>with default target eoOneMaxEA
|
||||
<br> <b><tt><font color="#993300">eoOneMax.h
|
||||
</font></tt></b>class eoOneMax, the genotype
|
||||
<br> <b><tt><font color="#993300">eoOneMaxEvalFunc.h
|
||||
|
||||
</font></tt></b>class for the computation of fitness
|
||||
<br> <b><tt><font color="#993300">eoOneMaxInit.h
|
||||
</font></tt></b>class for genotype initlialization
|
||||
<br> <b><tt><font color="#993300">eoOneMaxMutation.h
|
||||
</font></tt></b>class for mutation
|
||||
<br> <b><tt><font color="#993300">eoOneMaxQuadCrossover.h
|
||||
</font></tt></b>class
|
||||
for (quadratic) crossover
|
||||
<br> <b><tt><font color="#993300">make_genotype_OneMax.h
|
||||
|
||||
</font></tt></b>helper function that create the initializer
|
||||
<br> <b><tt><font color="#993300">make_op_OneMax.h
|
||||
</font></tt></b>helper function that handles the rates of application of
|
||||
the variation operators<br>
|
||||
<b><tt><font color="#993300">OneMaxLibEA.cpp
|
||||
</font></tt></b>another main file, for separate compilation of representation-independent
|
||||
stuff
|
||||
<br> <b><tt><font color="#993300">make_OneMaxEA.cpp
|
||||
</font></tt></b>the source for the representation-independent stuff
|
||||
<br>
|
||||
<li>
|
||||
Compile the whole application</li>
|
||||
|
||||
<br><b><tt><font color="#FF6666">
|
||||
make</font></tt></b>
|
||||
<br>and you should have no error there and see a new executable file named
|
||||
<b><tt><font color="#FF6666">OneMaxEA</font></tt></b>.
|
||||
You can run it and ... it will do nothing (what did you expect???).<br>
|
||||
<BR>
|
||||
<li>
|
||||
Now you should go and edit the files. The minimal changes that you
|
||||
will need are</li>
|
||||
|
||||
<br> in <b><tt><font color="#993300">eoOneMax.h
|
||||
</font></tt></b>define your genotype
|
||||
<br> in <b><tt><font color="#993300">eoOneMaxInit.h
|
||||
</font></tt></b>define the initialization of one genotype
|
||||
<br> in <b><tt><font color="#993300">eoOneMaxMutation.h
|
||||
|
||||
</font></tt></b>define the mutation of one genotype
|
||||
<br> in <b><tt><font color="#993300">eoOneMaxQuadCrossover.h
|
||||
|
||||
</font></tt></b>define the crossover of 2 genotypes</ul>
|
||||
<font color="#FF0000"><font size=+1>Smooth application building:</font></font>
|
||||
<ul>
|
||||
<li>
|
||||
After editing a particular file, <b><font color="#FF6600">compile</font></b>
|
||||
the whole thing immediately (by running make) <b><font color="#FF6600">and
|
||||
run</font></b> the algorithm, to validate your code</li>
|
||||
|
||||
<li>
|
||||
In each file, start by only adding code between keyword-pairs <b><tt><font color="#993300">START</font></tt></b>
|
||||
and <b><font color="#993300">END</font></b></li>
|
||||
</ul>
|
||||
We shall now take a look in turn at the 4 files mentionned above, then
|
||||
describe rapidly the other files, especially the main files.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="genotype"></a><b><font color="#000099"><font size=+2>Genotype
|
||||
- and its pre-requisites: </font></font><tt><font color="#993300"><font size=+1>eoOneMax.h</font></font></tt></b>
|
||||
<p>First thing is to write the code for <font color="#999900"><b>the structure
|
||||
of the genotype</b>.</font> This is done by filling in the template file
|
||||
<a href="eoOneMax.html">eoOneMax.h</a>.
|
||||
There are 4 places that you should consider filling in:
|
||||
<ul>
|
||||
<li>
|
||||
Of course, <a href="eoOneMax.html#data">the data</a> that will build up
|
||||
the genotype. The convention in EO is to have it at the end of the class
|
||||
definition, and as private data.</li>
|
||||
|
||||
<li>
|
||||
The <a href="eoOneMax.html#constructor">default constructor</a> of an instance.
|
||||
Note that <b><font color="#FF6600">you must provide a default constructor</font></b>,
|
||||
and that no other constructor will be called within EO code. you might
|
||||
think you need some other constructor to initialize problem-specific data.
|
||||
This should be rather done in the eoInit object used to randomly initialize
|
||||
all individuals, or in the eoEvalFunc object, used to compute the fitness.</li>
|
||||
|
||||
<li>
|
||||
The <a href="eoOneMax.html#print">printOn</a> method, that writes the object
|
||||
to a stream. You<font color="#000000"> must</font><b><font color="#FF6600">
|
||||
call the EO::printOn</font></b> method that will take care of the fitness,
|
||||
and then write the specific code for your data structure.</li>
|
||||
|
||||
<li>
|
||||
The <a href="eoOneMax.html#read">readFrom</a> method, that will read an
|
||||
object from a stream. Again, you should <b><font color="#FF6600">call the
|
||||
EO::readFrom</font></b> method first to take care of the fitness.</li>
|
||||
|
||||
<br>Also note that readFrom will be generally called from an object that
|
||||
will have been constructed through the default constructor. This is why
|
||||
the EO objects that we provide always start printing structures with their
|
||||
length...</ul>
|
||||
You can of course also add <a href="eoOneMax.html#destructor">a destructor</a>
|
||||
if needed, and any other helper method. For instance, you will probably
|
||||
consider adding <b><font color="#FF6600">accessors and setters</font></b>
|
||||
for the private data - unless you prefer to make everything public :-(
|
||||
<br>See now an example of <a href="eoOneMax_complete.html">a comple eoOneMax.h</a>
|
||||
file. Note that this is the only "colored" completed file we will show,
|
||||
you will have to go to the <b><tt><font color="#993300">.../tutorial/OneMax</font></tt></b>
|
||||
dir to <a href="../OneMax">browse all files at once</a>.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="initialization"></a><b><font color="#000099"><font size=+2>Initialization:</font></font></b>
|
||||
<p><font size=+1><font color="#FF0000">Initializer: </font><b><tt><font color="#993300">eoOneMaxInit.h</font></tt></b></font>
|
||||
<br>You must provide an <b><tt><font color="#CC33CC">eoInit</font></tt></b>
|
||||
object for your genotype, that is an object that will <b><font color="#FF6600">randomize
|
||||
a genotype built by the default constructor</font></b> of the EO class
|
||||
(here, an eoOneMax object) . Here you must at least fill <a href="eoOneMaxInit.html#operator">the
|
||||
code for such randomization.</a>
|
||||
<br>But you might also need some parameters (e.g. the size of the bitstring
|
||||
in eoOneMax): you should then <a href="eoOneMaxInit.html#constructor">pass
|
||||
them through the constructor</a> of the eoOneMaxInit class, and <a href="eoOneMaxInit.html#data">store
|
||||
it in its private data</a>.
|
||||
<br>And of course you might need to add a destructor (no example here)
|
||||
if you use complex data type in the object.
|
||||
<p><font size=+1><font color="#FF0000">Parameters: </font><b><tt><font color="#993300">make_genotype_OneMax.h</font></tt></b></font>
|
||||
<br>There is another file you will probably want to modify as far as initialization
|
||||
is concerned, that is <a href="make_genotype_OneMax.html">make_genotype_OneMax.h.</a>
|
||||
Such helper files are used for all components of advanced EO programs (see
|
||||
Lesson 4). The main reason for that is to allow separate compilation of
|
||||
such sub-components for known EO types, as this is done in the directories
|
||||
src/ga and src/es. But a useful consequence is to make your code modular.
|
||||
For instance, the <a href="make_genotype_OneMax.html#representation">make_genotype_OneMax.h</a>
|
||||
file takes care of all the preparation of all data regarding the eoInit
|
||||
object - and returns to the main fonction a reference to an eoInit that
|
||||
will later be used to <a href="OneMaxEA.html#initPop">initialize the whole
|
||||
population</a> in a representation-independent way.
|
||||
<br>What you have to do in that file is to set values for all parameters
|
||||
needed by the eoOneMaxInit class, for instance by reading them from the
|
||||
parser: this allows later to modify them easily from the command-line.
|
||||
Note however that an alternative could be to pass the parser to the constructor
|
||||
of the eoOneMaxInit class, and to read all parameters there...
|
||||
<br><b><font color="#FF0000">Note</font></b>: Remember that the make_xxx
|
||||
files were first introduced to allow the user to compile sepearately most
|
||||
of the code of standard Evolutionary Algorithm written in EO for bitstring
|
||||
and real vector representations (
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="evaluation"></a><b><font color="#000099"><font size=+2>Evaluation:
|
||||
</font></font><tt><font color="#993300"><font size=+1>eoOneMaxEvalFunc.h</font></font></tt></b>
|
||||
<p>The <b><tt><font color="#CC0000">eoOneMaxEvalFunc</font></tt></b> is
|
||||
the object that will <b><font color="#FF6600">compute the fitness of an
|
||||
eoOneMax object</font></b>. You have to fill in the <a href="eoOneMaxEvalFunc.html#operator">code
|
||||
for the computation of the fitness value</a> (there is no way that this
|
||||
can be done automatically :-) Note that this code must be run <b><font color="#FF6600">only
|
||||
if</font></b> the <b><tt><font color="#993300">_eo.invalid() </font></tt></b>test
|
||||
returns true, to avoid computing the fitness of an object that has not
|
||||
been modified and thus still holds a valid fitness value. After computing
|
||||
the fitness, store it into the object by calling the <b><tt><font color="#993300">fitness(FitnessType)</font></tt></b>
|
||||
method.
|
||||
<br>Should you need some specific data for that, the <a href="eoOneMaxEvalFunc.html#constructor">constructor
|
||||
of the object</a> is the place to get such data, and you should, again,
|
||||
store it in some <a href="eoOneMaxEvalFunc.html#data">private data</a>
|
||||
of the class.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="variation"></a><b><font color="#000099"><font size=+2>Variation
|
||||
Operators</font></font></b>
|
||||
<br>You can write as many crossover and mutation operators as you like.
|
||||
However, we only provide the template files for <a href="eoOperators.html#crossover">quadratic
|
||||
crossover </a>and <a href="eoOperators.html#mutation">mutation</a>, but
|
||||
you could then easily write the equivalent code for binary crossover, or
|
||||
general variation operator.
|
||||
<p><font size=+1><font color="#FF0000">Crossover: </font><b><tt><font color="#993300">eoOneMaxQuadCrossover.h</font></tt></b></font>
|
||||
<br>As usual, you must go and write the <a href="eoOneMaxQuadCrossover.html#operator">code
|
||||
for the operator()</a> that will perform the crossover, possibly modifying
|
||||
both arguments. Don't forget to <b><font color="#FF6600">update the boolean
|
||||
parameter</font></b> that will report whether the genotypes have been modified
|
||||
- allowing to recompute the fitness only of the ones that have actually
|
||||
been modified. You can also have <b><font color="#FF6600">parameters</font></b>
|
||||
to the crossover by <a href="eoOneMaxQuadCrossover.html#constructor">passing
|
||||
them to the constructor</a>, ans storing them in the <a href="eoOneMaxQuadCrossover.html#data">private
|
||||
data of the crossover object</a>.
|
||||
<p><font size=+1><font color="#FF0000">Mutation: </font><b><tt><font color="#993300">eoOneMaxMutation.h</font></tt></b></font>
|
||||
<br>Here again, you must go and write the code for the operator() that
|
||||
will perform the mutation, eventually modifying its arguments. Don't forget
|
||||
to <b><font color="#FF6600">update the boolean parameter</font></b> that
|
||||
will report whether the genotype has been modified - allowing to recompute
|
||||
the fitness only of the ones that have actually been modified. You can
|
||||
also have <b><font color="#FF6600">parameters</font></b> to the mutation
|
||||
by <a href="eoOneMaxMutation.html#constructor">passing them to the constructor</a>,
|
||||
ans storing them in the <a href="eoOneMaxMutation.html#data">private data
|
||||
of the mutation object</a>.
|
||||
<p><font size=+1><font color="#FF0000">Parameters: </font><b><tt><font color="#993300">make_op_OneMax.h</font></tt></b></font>
|
||||
<br>First of all, if you intend to use <b><font color="#FF6600">only one
|
||||
crossover</font></b> operator and <b><font color="#FF6600">one mutation</font></b>
|
||||
operator, you have <b><font color="#FF6600">nothing to modify</font></b>
|
||||
in <a href="make_op_OneMax.html">make_op_OneMax function</a>, except maybe
|
||||
reading user-defined parameters (copy the code from <a href="make_genotype_OneMax.html#representation">make_genotype_OneMax</a>)
|
||||
and passing them to <a href="make_op_OneMax.html#cross_ctor">the appropriate
|
||||
operator constructor</a>.
|
||||
<br>As it is written now, it allows you enter a crossover probability <b><tt><font color="#CC33CC">Pcross</font></tt></b>
|
||||
and a mutation probability <b><tt><font color="#CC33CC">Pmut</font></tt></b>,
|
||||
and to build an eoGeneralOp that will call in sequence the <b><tt><font color="#CC33CC">eoOneMaxQuadCrossover</font></tt></b>
|
||||
that is defined above with probability <b><tt><font color="#CC33CC">Pcross</font></tt></b>
|
||||
and the <b><tt><font color="#CC33CC">eoOneMaxMutation</font></tt></b> also
|
||||
defined above with probability <b><tt><font color="#CC33CC">Pmut</font></tt></b>.
|
||||
Beware that all allocated objects must be stored in the eoState otherwise
|
||||
you will run into trouble (see <a href="eoProgramming.html#memory">EO Memory
|
||||
Management explanations</a>).
|
||||
<p>However, everything is there (commented out) to allow you to use <a href="make_op_OneMax.html#crossover">more
|
||||
than one crossover</a> and <a href="make_op_OneMax.html#mutation">one mutation</a>
|
||||
- provided you write the code for them , of course.
|
||||
<p>The code starts by defining an <b><tt><font color="#CC33CC">eoOneMaxQuadCrossover</font></tt></b>object,
|
||||
then reads some application rate that is totally useless if you have only
|
||||
one crossover, then creates an <b><tt><font color="#CC33CC"><a href="eoLesson2.html#combined_operators">eoPropCombinedQuadOp</a></font></tt></b>
|
||||
with this simple oeprator. The same story repeats for the mutation. <a href="make_op_OneMax.html#donottouch">Finally</a>,
|
||||
the <b><tt><font color="#CC33CC"><a href="eoOperators.html#general_combination">eoGeneralOp</a></font></tt></b>
|
||||
is created from those combined operators and the individulal level probabilities
|
||||
<b><tt><font color="#CC33CC">Pcross</font></tt></b>
|
||||
and <b><tt><font color="#CC33CC">Pmut</font></tt></b>.
|
||||
<p>In order to add a second crossover operator for instance (called <b><tt><font color="#CC33CC">eoOneMaxSecondCrossover</font></tt></b>
|
||||
in the commented code) all you need to is
|
||||
<ul>
|
||||
<li>
|
||||
Create the code for the new class <b><tt><font color="#CC33CC">eoOneMaxSecondCrossover</font></tt></b>:
|
||||
simply copy the <b><tt><font color="#993300">eoOneMaxQuadCrossover.h</font></tt></b>
|
||||
file into <b><tt><font color="#993300">eoOneMaxSecondCrossover.h</font></tt></b>
|
||||
and change all names <b><tt><font color="#CC33CC">eoOneMaxQuadCrossover</font></tt></b>
|
||||
to <b><tt><font color="#CC33CC">eoOneMaxSecondCrossover </font></tt></b>(inlcluding
|
||||
after the #ifdef statement!!!);</li>
|
||||
|
||||
<li>
|
||||
Uncomment the <a href="make_op_OneMax.html#crossover">corresponding lines
|
||||
in make_op_OneMax.h</a>, possibly adding user-defined parameter reading</li>
|
||||
|
||||
<li>
|
||||
Repeat as many times as you have operators, using of course different names!
|
||||
The same recommendations hold for mutations.</li>
|
||||
</ul>
|
||||
In case you have more than one operator of a kind, then of course the relative
|
||||
weights of application do make sense, allowing you to tune with command-line
|
||||
parameters the proportion with which each operator that will be applied.
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="main"></a><b><font color="#000099"><font size=+2>Main
|
||||
files: </font></font><tt><font color="#993300"><font size=+1>OneMaxEA.cpp
|
||||
</font></font></tt></b>and<b><tt><font color="#993300"><font size=+1> OneMaxLibEA.cpp</font></font></tt></b><font color="#FF0000"><font size=+1></font></font>
|
||||
<p>As a start, you should only (eventually) modify in <b><tt><font color="#993300">OneMaxEA.cpp
|
||||
</font></tt></b>the <a href="OneMax.cpp#fitness">type of fitness</a> you
|
||||
will be handling, namely <b><tt><font color="#CC0000">double</font></tt></b>
|
||||
if you are <b><font color="#FF6600">maximizing</font></b>, or <b><tt><font color="#CC0000">eoMinimizingFitness</font></tt></b>
|
||||
if you are <b><font color="#FF6600">minimizing</font></b>. Then running
|
||||
<b><tt><font color="#FF6666">make</font></tt></b> will result in a perfectly
|
||||
valid executable named <b><tt><font color="#FF6666">OneMaxEA</font></tt></b>.
|
||||
<p>The skeleton of the main file here mimics that of the main file in
|
||||
<a href="eoLesson4.html">Lesson4</a>,
|
||||
and <a href="eoLesson4.html#programmerguide">uses the make_xxx separate
|
||||
files construct</a>: the part of an Evolutionary Algorithm related to the
|
||||
<b><font color="#009900">evolution
|
||||
engine</font></b> is <b><font color="#FF6600">indepenent of the representation</font></b>,
|
||||
and can be directly used ... provided it is compiled with the right template
|
||||
(remember everything in EO is <a href="eoProgramming.html#templates">templatized
|
||||
over the EO objects it handles</a>. Main file <b><tt><font color="#993300">OneMaxEA.cpp</font></tt></b>
|
||||
is written so that it includes eveything - and thus everytime you run <b><tt><font color="#FF6666">make</font></tt></b>
|
||||
(or <b><tt><font color="#FF6666">make OneMaxEA</font></tt></b>), you compile
|
||||
the code for make_pop, make_continue and make_checkpoint that is defined
|
||||
in the .../src/do directory.
|
||||
<p>The basic construct is (for instance to build the evolution engine)
|
||||
<br>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><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>
|
||||
First, include the code (from the do directory). Then define the make_xxx
|
||||
function from the do_make_xxx function.
|
||||
<br>Of course, such construct is stupid here, as you could perfectly call
|
||||
directly the do_make_xxx function in the main. However, if you ever want
|
||||
to do separate compilation of some parts, you will need such construct
|
||||
(see <a href="eoLesson4.html">Lesson4</a>) so we have kept it here for
|
||||
consistency reasons.
|
||||
<p>Go in your application directory, and look at the differences between
|
||||
both files and you'll see how this is handled in both cases.
|
||||
<p><b><font color="#FF0000">Reducing compilation time:</font></b>
|
||||
<br>However, we also provide another main file (<b><tt><font color="#993300">OneMaxLibEA.cpp</font></tt></b>)that
|
||||
only includes the code that is specific to your application, and is supposed
|
||||
to be linked with another object file that will contain the code that is
|
||||
representation independent (<b><tt><font color="#993300">make_OneMax.cpp</font></tt></b>).
|
||||
This is done by running <b><tt><font color="#FF6666">make OneMaxLibEA</font></tt></b>
|
||||
on the command-line.
|
||||
<br>For example, on a PentiumIII 400MHz with g++ 2.96, compiling <b><tt><font color="#FF6666">OneMaxEA</font></tt></b>
|
||||
takes about <b><font color="#FF6600">33s</font></b>, compiling both <b><tt><font color="#FF6666">make_OneMax.o</font></tt></b>
|
||||
and <b><tt><font color="#FF6666">OneMaxLibEA</font></tt></b> takes about
|
||||
<b><font color="#FF6600">54s</font></b> but compiling only <b><tt><font color="#FF6666">OneMaxLibEA</font></tt></b>
|
||||
takes only <b><font color="#FF6600">14s</font></b> <b><tt><font color="#FF6666">make_OneMax.o</font></tt></b>
|
||||
is up-to-date ...
|
||||
<p><b><font color="#FF0000">Hints:</font></b>
|
||||
<br>While developping the genotype structure itself in file <b><tt><font color="#993300">eoOneMax.h</font></tt></b>,
|
||||
you should use the <b><tt><font color="#993300">OneMaxEA.cpp</font></tt></b>
|
||||
file. But after the <b><tt><font color="#993300">eoOneMax.h</font></tt></b>
|
||||
file is frozen, you should use the <b><tt><font color="#993300">eoOneMaxLibEA.cpp</font></tt></b>
|
||||
file. Of course, both resulting programs are strictly identical!
|
||||
<p>
|
||||
<hr WIDTH="100%"><font color="#000000"><a href="eoLesson4.html">Lesson
|
||||
4</a> -
|
||||
<a href="eoLesson6.html">Lesson 6</a> -
|
||||
<a href="eoTutorial.html">Main
|
||||
page</a> -
|
||||
<a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based</a>
|
||||
- <a href="eoProgramming.html">Hints</a> -<b> <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b></font>
|
||||
<br>
|
||||
<hr>
|
||||
<address>
|
||||
<font color="#000000"><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></font></address>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
209
eo/tutorial/html/eoOneMax.html
Normal file
209
eo/tutorial/html/eoOneMax.html
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
<!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/eoOneMax.h</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/eoOneMax.h</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">*/</font></tt>
|
||||
<br><b><tt><font color="#993300">#ifndef _eoOneMax_h</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#define _eoOneMax_h</font></tt></b>
|
||||
<br><tt><font color="#993300">/** </font></tt>
|
||||
<br><tt><font color="#993300">* Always write a comment in this format
|
||||
before class definition</font></tt>
|
||||
<br><tt><font color="#993300">* if you want the class to be documented
|
||||
by Doxygen</font></tt>
|
||||
<br><tt><font color="#993300">* Note that you MUST derive your structure
|
||||
from EO<fitT></font></tt>
|
||||
<br><tt><font color="#993300">* but you MAY use some other already prepared
|
||||
class in the hierarchy</font></tt>
|
||||
<br><tt><font color="#993300">* like eoVector for instance, if you handle
|
||||
a vector of something....</font></tt>
|
||||
<br><tt><font color="#993300">* If you create a structure from scratch,</font></tt>
|
||||
<br><tt><font color="#993300">* the only thing you need to provide are </font></tt>
|
||||
<br><tt><font color="#993300">*
|
||||
a default constructor</font></tt>
|
||||
<br><tt><font color="#993300">*
|
||||
IO routines printOn and readFrom</font></tt>
|
||||
<br><tt><font color="#993300">*</font></tt>
|
||||
<br><tt><font color="#993300">* Note that operator<< and operator>>
|
||||
are defined at EO level</font></tt>
|
||||
<br><tt><font color="#993300">* using these routines</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">template< class FitT></font></tt></b>
|
||||
<br><b><tt><font color="#999900">class eoOneMax: public EO<FitT> {</font></tt></b>
|
||||
<br><b><tt><font color="#999900">public:</font></tt></b>
|
||||
<br><tt><font color="#999900"><b> </b> /** Ctor: you MUST provide
|
||||
a default ctor.</font></tt>
|
||||
<br><tt><font color="#999900"> * though such individuals will
|
||||
generally be processed </font></tt>
|
||||
<br><tt><font color="#999900"> * by some eoInit object</font></tt>
|
||||
<br><tt><font color="#999900"> */</font></tt>
|
||||
<br><b><tt><font color="#999900"> eoOneMax() </font></tt></b>
|
||||
<br><b><tt><font color="#999900"> { </font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="constructor"></a><tt><font color="#999900"><b> </b>
|
||||
// START Code of default Ctor of an eoOneMax object</font></tt>
|
||||
<br><tt><font color="#999900"><b> </b> //
|
||||
END Code of default Ctor of an eoOneMax object</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#999900"> }</font></tt></b>
|
||||
<p><b><tt><font color="#999900"> virtual ~eoOneMax()</font></tt></b>
|
||||
<br><b><tt><font color="#999900"> {</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="destructor"></a><tt><font color="#999900"><b> </b>
|
||||
// START Code of Destructor of an eoEASEAGenome object</font></tt>
|
||||
<br><tt><font color="#999900"><b> </b> //
|
||||
END Code of Destructor of an eoEASEAGenome object</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#999900"> }</font></tt></b>
|
||||
<p><b><tt><font color="#999900"> virtual string className() const
|
||||
{ return "eoOneMax"; }</font></tt></b>
|
||||
<br> </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> /** printing... */</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> void printOn(ostream& os) const</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> {</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b> //
|
||||
First write the fitness</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> EO<FitT>::printOn(os);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> os << '
|
||||
';</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="print"></a><tt><font color="#3366FF"><b> </b>
|
||||
// START Code of default output </font></tt>
|
||||
<p><tt><font color="#3366FF">/** HINTS</font></tt>
|
||||
<br><tt><font color="#3366FF">* in EO we systematically write the sizes
|
||||
of things before the things</font></tt>
|
||||
<br><tt><font color="#3366FF">* so readFrom is easier to code (see below)</font></tt>
|
||||
<br><tt><font color="#3366FF">*/</font></tt>
|
||||
<p><tt><font color="#3366FF"><b> </b> // END
|
||||
Code of default output</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#3366FF"> }</font></tt></b>
|
||||
<p><tt><font color="#3366FF"><b> </b> /** reading... </font></tt>
|
||||
<br><tt><font color="#3366FF"> * of course, your readFrom must
|
||||
be able to read what printOn writes!!!</font></tt>
|
||||
<br><tt><font color="#3366FF"> */</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> void readFrom(istream& is)</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> {</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b> //
|
||||
of course you should read the fitness first!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> EO<FitT>::readFrom(is);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="read"></a><tt><font color="#3366FF"><b> </b>
|
||||
// START Code of input</font></tt>
|
||||
<p><tt><font color="#3366FF">/** HINTS</font></tt>
|
||||
<br><tt><font color="#3366FF">* remember the eoOneMax object will come
|
||||
from the default ctor</font></tt>
|
||||
<br><tt><font color="#3366FF">* this is why having the sizes written out
|
||||
is useful</font></tt>
|
||||
<br><tt><font color="#3366FF">*/</font></tt>
|
||||
<p><tt><font color="#3366FF"><b> </b> // END
|
||||
Code of input</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#3366FF"> }</font></tt></b>
|
||||
<br> </td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="data"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900"><b>private: </b> //
|
||||
put all data here</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900"><b> </b> //
|
||||
START Private data of an eoOneMax object</font></tt>
|
||||
<br><tt><font color="#999900"><b> </b> //
|
||||
END Private data of an eoOneMax object</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#999900">};</font></tt></b>
|
||||
<p><b><tt><font color="#999900">#endif</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: Fri May
|
||||
3 06:06:09 2002<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
160
eo/tutorial/html/eoOneMaxEvalFunc.html
Normal file
160
eo/tutorial/html/eoOneMaxEvalFunc.html
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
<!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/eoOneMaxEvalFunc.h</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/eoOneMaxEvalFunc.h</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>
|
||||
<p><tt><font color="#993300">The above line is usefulin Emacs-like editors</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt>
|
||||
<p><tt><font color="#993300">/*</font></tt>
|
||||
<br><tt><font color="#993300">Template for evaluator in EO, a functor that
|
||||
computes the fitness of an EO</font></tt>
|
||||
<br><tt><font color="#993300">==========================================================================</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt>
|
||||
<p><b><tt><font color="#993300">#ifndef _eoOneMaxEvalFunc_h</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#define _eoOneMaxEvalFunc_h</font></tt></b>
|
||||
<p><tt><font color="#993300">// include whatever general include you need</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <stdexcept></font></tt></b>
|
||||
<br><b><tt><font color="#993300">#include <fstream></font></tt></b>
|
||||
<p><tt><font color="#993300">// include the base definition of eoEvalFunc</font></tt>
|
||||
<br><b><tt><font color="#993300">#include "eoEvalFunc.h"</font></tt></b>
|
||||
<p><tt><font color="#993300">/** </font></tt>
|
||||
<br><tt><font color="#993300"> Always write a comment in this format
|
||||
before class definition</font></tt>
|
||||
<br><tt><font color="#993300"> if you want the class to be documented
|
||||
by Doxygen</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="eval"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#CC0000">template <class EOT></font></tt></b>
|
||||
<br><b><tt><font color="#CC0000">class eoOneMaxEvalFunc : public eoEvalFunc<EOT></font></tt></b>
|
||||
<br><b><tt><font color="#CC0000">{</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000">public:</font></tt></b>
|
||||
<br><tt><font color="#CC0000">/// Ctor - no requirement</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="constructor"></a><tt><font color="#CC0000">// START eventually
|
||||
add or modify the anyVariable argument</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> eoOneMaxEvalFunc()</font></tt></b>
|
||||
<br><tt><font color="#CC0000"><b> </b> // eoOneMaxEvalFunc(
|
||||
varType _anyVariable) : anyVariable(_anyVariable) </font></tt>
|
||||
<br><tt><font color="#CC0000">// END eventually add or modify the anyVariable
|
||||
argument</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#CC0000"> {</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#CC0000"><b> </b> //
|
||||
START Code of Ctor of an eoOneMaxEvalFunc object</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b> //
|
||||
END Code of Ctor of an eoOneMaxEvalFunc object</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#CC0000"> }</font></tt></b>
|
||||
<p><tt><font color="#CC0000"><b> </b> /** Actually compute the fitness</font></tt>
|
||||
<br><tt><font color="#CC0000"> *</font></tt>
|
||||
<br><tt><font color="#CC0000"> * @param EOT & _eo the EO
|
||||
object to evaluate</font></tt>
|
||||
<br><tt><font color="#CC0000"> *
|
||||
it should stay templatized to be usable </font></tt>
|
||||
<br><tt><font color="#CC0000"> *
|
||||
with any fitness type</font></tt>
|
||||
<br><tt><font color="#CC0000"> */</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> void operator()(EOT & _eo)</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000"> {</font></tt></b>
|
||||
<br><tt><font color="#CC0000"><b> </b> //
|
||||
test for invalid to avoid recomputing fitness of unmodified individuals</font></tt>
|
||||
<br><b><tt><font color="#CC0000"> if (_eo.invalid())</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000">
|
||||
{</font></tt></b>
|
||||
<br><tt><font color="#CC0000"><b>double fit; </b>
|
||||
// to hold fitness value</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="operator"></a><tt><font color="#CC0000"><b> </b>
|
||||
// START Code of computation of fitness of the eoOneMax object</font></tt>
|
||||
<br><tt><font color="#CC0000">// fit = blablabla</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b> //
|
||||
END Code of computation of fitness of the eoOneMax object</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#CC0000">_eo.fitness(fit);</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000">
|
||||
}</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000"> }</font></tt></b>
|
||||
<p><b><tt><font color="#CC0000">private:</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="data"></a><tt><font color="#CC0000">// START Private data
|
||||
of an eoOneMaxEvalFunc object</font></tt>
|
||||
<br><tt><font color="#CC0000"><b> </b> // varType anyVariable;
|
||||
// for example ...</font></tt>
|
||||
<br><tt><font color="#CC0000">// END Private data of
|
||||
an eoOneMaxEvalFunc object</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#CC0000">};</font></tt></b>
|
||||
<br><b><tt><font color="#CC0000">#endif</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: Fri May
|
||||
3 06:14:25 2002<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
153
eo/tutorial/html/eoOneMaxInit.html
Normal file
153
eo/tutorial/html/eoOneMaxInit.html
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
<!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/eoOneMaxInit.h</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/eoOneMaxInit.h</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>
|
||||
<p><tt><font color="#993300">/*</font></tt>
|
||||
<br><tt><font color="#993300">Template for EO objects initialization in
|
||||
EO</font></tt>
|
||||
<br><tt><font color="#993300">============================================</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt>
|
||||
<p><b><tt><font color="#993300">#ifndef _eoOneMaxInit_h</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#define _eoOneMaxInit_h</font></tt></b>
|
||||
<p><tt><font color="#993300">// include the base definition of eoInit</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <eoInit.h></font></tt></b>
|
||||
<p><tt><font color="#993300">/** </font></tt>
|
||||
<br><tt><font color="#993300">* Always write a comment in this format
|
||||
before class definition</font></tt>
|
||||
<br><tt><font color="#993300">* if you want the class to be documented
|
||||
by Doxygen</font></tt>
|
||||
<br><tt><font color="#993300">*</font></tt>
|
||||
<br><tt><font color="#993300">* There is NO ASSUMPTION on the class GenoypeT.</font></tt>
|
||||
<br><tt><font color="#993300">* In particular, it does not need to derive
|
||||
from EO (e.g. to initialize </font></tt>
|
||||
<br><tt><font color="#993300">* atoms of
|
||||
an eoVector you will need an eoInit<AtomType>)</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="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399">template <class GenotypeT></font></tt></b>
|
||||
<br><b><tt><font color="#993399">class eoOneMaxInit: public eoInit<GenotypeT>
|
||||
{</font></tt></b>
|
||||
<br><b><tt><font color="#993399">public:</font></tt></b>
|
||||
<br><tt><font color="#993399">/// Ctor - no requirement</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="constructor"></a><tt><font color="#993399">// START eventually
|
||||
add or modify the anyVariable argument</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoOneMaxInit()</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b> // eoOneMaxInit( varType
|
||||
_anyVariable) : anyVariable(_anyVariable) </font></tt>
|
||||
<br><tt><font color="#993399">// END eventually add or modify the anyVariable
|
||||
argument</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399"> {</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b> //
|
||||
START Code of Ctor of an eoOneMaxInit object</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
END Code of Ctor of an eoOneMaxInit object</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399"> }</font></tt></b>
|
||||
<p><tt><font color="#993399"><b> </b> /** initialize a genotype</font></tt>
|
||||
<br><tt><font color="#993399"> *</font></tt>
|
||||
<br><tt><font color="#993399"> * @param _genotype generally
|
||||
a genotype that has been default-constructed</font></tt>
|
||||
<br><tt><font color="#993399"> *
|
||||
whatever it contains will be lost</font></tt>
|
||||
<br><tt><font color="#993399"> */</font></tt>
|
||||
<br><b><tt><font color="#993399"> void operator()(GenotypeT &
|
||||
_genotype)</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> {</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="operator"></a><tt><font color="#993399"><b> </b>
|
||||
// START Code of random initialization of an eoOneMax object</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
END Code of random initialization of an eoOneMax object</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> _genotype.invalidate(); </b>
|
||||
// IMPORTANT in case the _genotype is old</font></tt>
|
||||
<br><b><tt><font color="#993399"> }</font></tt></b>
|
||||
<p><b><tt><font color="#993399">private:</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="data"></a><tt><font color="#993399">// START Private data
|
||||
of an eoOneMaxInit object</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // varType anyVariable;
|
||||
// for example ...</font></tt>
|
||||
<br><tt><font color="#993399">// END Private data of
|
||||
an eoOneMaxInit object</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399">};</font></tt></b>
|
||||
<p><b><tt><font color="#993399">#endif</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: Fri May
|
||||
3 06:17:21 2002<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
168
eo/tutorial/html/eoOneMaxMutation.html
Normal file
168
eo/tutorial/html/eoOneMaxMutation.html
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
<!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>eoOneMaxMutation.h</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">eoOneMaxMutation.h</font></h1></center>
|
||||
The places where you have to put some code are on pink background.
|
||||
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">
|
||||
<b>/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-</b><br>
|
||||
<b>The above line is useful in Emacs-like editors</b><br>
|
||||
<b> */</b><br>
|
||||
<b>/*</b><br>
|
||||
<b>Template for simple mutation operators</b><br>
|
||||
<b>======================================</b><br>
|
||||
<b>*/</b><br>
|
||||
<b>#ifndef eoOneMaxMutation_H</b><br>
|
||||
<b>#define eoOneMaxMutation_H</b><br>
|
||||
<b>#include <eoOp.h></b><br>
|
||||
<b>/** </b><br>
|
||||
<b> * Always write a comment in this format before class definition</b><br>
|
||||
<b> * if you want the class to be documented by Doxygen</b><br>
|
||||
<b> *</b><br>
|
||||
<b> * THere is NO ASSUMPTION on the class GenoypeT.</b><br>
|
||||
<b> * In particular, it does not need to derive from EO</b><br>
|
||||
<b> */</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="mutation"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b>template<class GenotypeT> </b><br>
|
||||
<b>class eoOneMaxMutation: public eoMonOp<GenotypeT></b><br>
|
||||
<b>{</b><br>
|
||||
<b>public:</b><br>
|
||||
<b> /**</b><br>
|
||||
<b> * Ctor - no requirement</b><br>
|
||||
<b> */</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
// START eventually add or modify the anyVariable argument<br>
|
||||
<b> eoOneMaxMutation()</b><br>
|
||||
<b> </b>// eoOneMaxMutation( varType _anyVariable) : anyVariable(_anyVariable) <br>
|
||||
// END eventually add or modify the anyVariable argument<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> {</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>// START Code of Ctor of an eoOneMaxEvalFunc object<br>
|
||||
<b> </b>// END Code of Ctor of an eoOneMaxEvalFunc object<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> }</b><br>
|
||||
<b> </b>/// The class name. Used to display statistics<br>
|
||||
<b> string className() const { return "eoOneMaxMutation"; }</b><br>
|
||||
<b> /**</b><br>
|
||||
<b> * modifies the parent</b><br>
|
||||
<b> * @param _genotype The parent genotype (will be modified)</b><br>
|
||||
<b> */</b><br>
|
||||
<b> bool operator()(GenotypeT & _genotype) </b><br>
|
||||
<b> {</b><br>
|
||||
<b> bool isModified;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> </b>// START code for mutation of the _genotype object<br>
|
||||
<b> /** Requirement</b><br>
|
||||
<b>* if (_genotype has been modified)</b><br>
|
||||
<b>* isModified = true;</b><br>
|
||||
<b>* else</b><br>
|
||||
<b>* isModified = false;</b><br>
|
||||
<b>*/</b><br>
|
||||
<b> return isModified;</b><br>
|
||||
<b> </b>// END code for mutation of the _genotype object<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b> }</b><br>
|
||||
<b>private:</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
// START Private data of an eoOneMaxMutation object<br>
|
||||
<b> </b>// varType anyVariable; // for example ...<br>
|
||||
// END Private data of an eoOneMaxMutation object<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#993399">
|
||||
<b>};</b><br>
|
||||
<b>#endif</b><br>
|
||||
</font></font></font></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: Wed May 1 07:18:00 2002
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
168
eo/tutorial/html/eoOneMaxQuadCrossover.html
Normal file
168
eo/tutorial/html/eoOneMaxQuadCrossover.html
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
<!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/eoOneMaxQuadCrossover.h</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/eoOneMaxQuadCrossover.h</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 simple quadratic crossover operators</font></tt>
|
||||
<br><tt><font color="#993300">=================================================</font></tt>
|
||||
<br><tt><font color="#993300">Quadratic crossover operators modify the
|
||||
both genotypes</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt>
|
||||
<p><b><tt><font color="#993300">#ifndef eoOneMaxQuadCrossover_H</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#define eoOneMaxQuadCrossover_H</font></tt></b>
|
||||
<p><b><tt><font color="#993300">#include <eoOp.h></font></tt></b>
|
||||
<p><tt><font color="#993300">/** </font></tt>
|
||||
<br><tt><font color="#993300">* Always write a comment in this format
|
||||
before class definition</font></tt>
|
||||
<br><tt><font color="#993300">* if you want the class to be documented
|
||||
by Doxygen</font></tt>
|
||||
<br><tt><font color="#993300">*</font></tt>
|
||||
<br><tt><font color="#993300">* THere is NO ASSUMPTION on the class GenoypeT.</font></tt>
|
||||
<br><tt><font color="#993300">* In particular, it does not need to derive
|
||||
from EO</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="crossover"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399">template<class GenotypeT> </font></tt></b>
|
||||
<br><b><tt><font color="#993399">class eoOneMaxQuadCrossover: public eoQuadOp<GenotypeT></font></tt></b>
|
||||
<br><b><tt><font color="#993399">{</font></tt></b>
|
||||
<br><b><tt><font color="#993399">public:</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b> /**</font></tt>
|
||||
<br><tt><font color="#993399"> * Ctor - no requirement</font></tt>
|
||||
<br><tt><font color="#993399"> */</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="constructor"></a><tt><font color="#993399">// START eventually
|
||||
add or modify the anyVariable argument</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoOneMaxQuadCrossover()</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b> // eoOneMaxQuadCrossover(
|
||||
varType _anyVariable) : anyVariable(_anyVariable) </font></tt>
|
||||
<br><tt><font color="#993399">// END eventually add or modify the anyVariable
|
||||
argument</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399"> {</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#993399"><b> </b> //
|
||||
START Code of Ctor of an eoOneMaxEvalFunc object</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
END Code of Ctor of an eoOneMaxEvalFunc object</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399"> }</font></tt></b>
|
||||
<p><tt><font color="#993399"><b> </b> /// The class name. Used to
|
||||
display statistics</font></tt>
|
||||
<br><b><tt><font color="#993399"> string className() const { return
|
||||
"eoOneMaxQuadCrossover"; }</font></tt></b>
|
||||
<p><tt><font color="#993399"><b> </b> /**</font></tt>
|
||||
<br><tt><font color="#993399"> * eoQuad crossover - modifies
|
||||
both parents</font></tt>
|
||||
<br><tt><font color="#993399"> * @param _genotype1 The first
|
||||
parent</font></tt>
|
||||
<br><tt><font color="#993399"> * @param _genotype2 The second
|
||||
parent</font></tt>
|
||||
<br><tt><font color="#993399"> */</font></tt>
|
||||
<br><b><tt><font color="#993399"> bool operator()(GenotypeT& _genotype1,
|
||||
GenotypeT & _genotype2) </font></tt></b>
|
||||
<br><b><tt><font color="#993399"> {</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> bool oneAtLeastIsModified;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="operator"></a><tt><font color="#993399"><b> </b>
|
||||
// START code for crossover of _genotype1 and _genotype2 objects</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b>
|
||||
/** Requirement</font></tt>
|
||||
<br><tt><font color="#993399">* if (at least one genotype has been modified)
|
||||
// no way to distinguish</font></tt>
|
||||
<br><tt><font color="#993399">*
|
||||
oneAtLeastIsModified = true;</font></tt>
|
||||
<br><tt><font color="#993399">* else</font></tt>
|
||||
<br><tt><font color="#993399">*
|
||||
oneAtLeastIsModified = false;</font></tt>
|
||||
<br><tt><font color="#993399">*/</font></tt>
|
||||
<br><b><tt><font color="#993399"> return oneAtLeastIsModified;</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
END code for crossover of _genotype1 and _genotype2 objects</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399"> }</font></tt></b>
|
||||
<p><b><tt><font color="#993399">private:</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="data"></a><tt><font color="#993399">// START Private data
|
||||
of an eoOneMaxQuadCrossover object</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // varType anyVariable;
|
||||
// for example ...</font></tt>
|
||||
<br><tt><font color="#993399">// END Private data of
|
||||
an eoOneMaxQuadCrossover object</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399">};</font></tt></b>
|
||||
<p><b><tt><font color="#993399">#endif</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: Fri May
|
||||
3 07:47:13 2002<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
192
eo/tutorial/html/eoOneMax_complete.html
Normal file
192
eo/tutorial/html/eoOneMax_complete.html
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
<!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/eoOneMax_complete.h</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/eoOneMax_complete.h</font></h1></center>
|
||||
The user-defined code is on <b><font color="#FF6666">pink background</font></b>..
|
||||
Only the the <a href="eoTutorial.html#colors">character colors have the
|
||||
usual meaning</a>.
|
||||
<p><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>
|
||||
<p><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">*/</font></tt>
|
||||
<p><b><tt><font color="#993300">#ifndef _eoOneMax_h</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#define _eoOneMax_h</font></tt></b>
|
||||
<br> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#000000">/** </font></tt>
|
||||
<br><tt><font color="#000000">* A simple example class for bitstring (is
|
||||
NOT supposed to be used :-)</font></tt>
|
||||
<br><tt><font color="#000000">*/</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><b><tt><font color="#999900">template< class FitT></font></tt></b>
|
||||
<br><b><tt><font color="#999900">class eoOneMax: public EO<FitT> {</font></tt></b>
|
||||
<br><b><tt><font color="#999900">public:</font></tt></b>
|
||||
<br><tt><font color="#999900"><b> </b> /** Deafult Ctor: nothing to
|
||||
be done */</font></tt>
|
||||
<br><b><tt><font color="#999900"> eoOneMax() {}</font></tt></b>
|
||||
<p><b><tt><font color="#999900"> virtual string className() const
|
||||
{ return "eoOneMax"; }</font></tt></b>
|
||||
<br> </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> /** printing... */</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> void printOn(ostream&
|
||||
_os) const</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> {</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b>
|
||||
// First write the fitness</font></tt>
|
||||
<br><b><tt><font color="#3366FF">
|
||||
EO<FitT>::printOn(_os);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">
|
||||
_os << ' ';</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#3366FF">
|
||||
_os << b.size() << ' ' ;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">
|
||||
for (unsigned i=0; i<b.size(); i++)</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">
|
||||
_os << b[i] << ' ' ;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#3366FF"> }</font></tt></b>
|
||||
<p><tt><font color="#3366FF"><b> </b> /** reading... </font></tt>
|
||||
<br><tt><font color="#3366FF"> * of course, your readFrom must
|
||||
be able to read what printOn writes!!!</font></tt>
|
||||
<br><tt><font color="#3366FF"> */</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> void readFrom(istream& _is)</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> {</font></tt></b>
|
||||
<br><tt><font color="#3366FF"><b> </b> //
|
||||
of course you should read the fitness first!</font></tt>
|
||||
<br><b><tt><font color="#3366FF"> EO<FitT>::readFrom(_is);</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#3366FF"> unsigned s;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> _is >> s;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> b.resize(s);</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> for (unsigned
|
||||
i=0; i<s; i++)</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">
|
||||
{</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">
|
||||
bool bTmp;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">
|
||||
_is >> bTmp;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">
|
||||
b[i] = bTmp;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF">
|
||||
} </font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#3366FF"> }</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="representation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><tt><font color="#999900"><b> </b> // brute setting (we could
|
||||
also have defined a Ctor from a vector<bool>)</font></tt>
|
||||
<br><b><tt><font color="#999900"> void setB(vector<bool> &
|
||||
_b)</font></tt></b>
|
||||
<br><b><tt><font color="#999900"> {</font></tt></b>
|
||||
<br><b><tt><font color="#999900"> b=_b;</font></tt></b>
|
||||
<br><b><tt><font color="#999900"> }</font></tt></b>
|
||||
<p><tt><font color="#999900"><b> </b> // brute accessing (we could
|
||||
also define operator[] ...)</font></tt>
|
||||
<br><b><tt><font color="#999900"> const vector<bool> & B()</font></tt></b>
|
||||
<br><b><tt><font color="#999900"> {</font></tt></b>
|
||||
<br><b><tt><font color="#999900"> return b;</font></tt></b>
|
||||
<br><b><tt><font color="#999900"> }</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<br><tt><font color="#999900"><b>private: </b> //
|
||||
put all data here</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#999900"> std::vector<bool> b;</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#999900">};</font></tt></b>
|
||||
<p><b><tt><font color="#999900">#endif</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 06:02:46 2002<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
818
eo/tutorial/html/eoOperators.html
Normal file
818
eo/tutorial/html/eoOperators.html
Normal file
|
|
@ -0,0 +1,818 @@
|
|||
<!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>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="#crossover">Crossover</a> - <a href="#mutation">Mutation</a>
|
||||
- <a href="#proportional_simple">Combinations</a> - <a href="#general">General
|
||||
Operators</a> - <a href="#populators">Populators</a> - <a href="#general_combination">General
|
||||
combinations</a>- <a href="#advanced_general">Advanced operators</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<center>
|
||||
<h1>
|
||||
<b><font color="#CC0000">Variation Operators</font></b></h1></center>
|
||||
<a NAME="introduction"></a><b><font color="#000099"><font size=+2>Variation
|
||||
Operators</font></font></b>
|
||||
<br>Variation operators modify the gnotype of individuals, or, equivalently,
|
||||
move them in the search space. In Evolutionary Algorithms, varitaion operators
|
||||
are almost always <b><font color="#FF6600">stochastic</font></b>, i.e.
|
||||
they are based on random numbers, or equivalently, perform random modifications
|
||||
of their arguments. Variation operators are classified depending on the
|
||||
number of arguments they use and/or modify.
|
||||
<ul>
|
||||
<li>
|
||||
Variation operators involving <b><font color="#FF6600">two individuals</font></b>
|
||||
are called <a href="#crossover">crossover operators</a>. They can either
|
||||
modify one of the parents according to the material of the other parent,
|
||||
or modify both parents. In EO, the former are called Binary operators and
|
||||
the latter Quadratic operators.</li>
|
||||
|
||||
<li>
|
||||
Variation operators involving <b><font color="#FF6600">one single individual</font></b>
|
||||
are called <a href="#mutation">mutation operators.</a></li>
|
||||
|
||||
<li>
|
||||
Straightforward extensions of these simple operators allow to combine them:
|
||||
in
|
||||
<a href="#proportional_simple">proportional combinations</a>, one operator
|
||||
is chosen among a given set of operators of same arity according to some
|
||||
weights.</li>
|
||||
|
||||
<li>
|
||||
In EO you can also define and use variation operators that generate any
|
||||
number of offspring from any number of parents (sometimes termed <b><font color="#FF6600">orgy</font></b>
|
||||
operators). They are called <a href="#general">general operators</a>.</li>
|
||||
|
||||
<li>
|
||||
However, the interface of such operators was designed for their use inside
|
||||
<a href="#general_combination">general
|
||||
combinations</a>: you can use <b><font color="#FF6600">proportional combination</font></b>,
|
||||
in which one operator is chosen among a given set of operators of same
|
||||
arity according to some weights, as for simple operators except that operators
|
||||
of different arities can be mixed, but you can also use <b><font color="#FF6600">sequential
|
||||
combinations</font></b>, where different operators are applied in
|
||||
turn with given probability. But you can also embed any of such combinations
|
||||
at any depth.</li>
|
||||
|
||||
<li>
|
||||
The price to pay for that is that you must use an instermediate class to
|
||||
access the individuals, the <a href="#populators">eoPopulator</a> class.</li>
|
||||
|
||||
<li>
|
||||
Thanks to that class, it also become easy to design <a href="#advanced_general">advanced
|
||||
operators</a>, such as crossover operators where the mate is chosen according
|
||||
to <b><font color="#FF6600">sexual preference</font></b> rather than fitness-based
|
||||
preferences.</li>
|
||||
</ul>
|
||||
<b><font color="#FF0000">Implementation</font></b>
|
||||
<p>The basic idea of EO variation operators is that they operate on genotypes
|
||||
only. Hence there should be generally no reference to anything related
|
||||
to the fitness within a variation operator. However, whenever the genotype
|
||||
of an individual has been modified, it will be necessary to recompute its
|
||||
fitness before any selection process. This is why <b><font color="#FF6600">all
|
||||
variation operator return</font></b> a bool that indicates whether or not
|
||||
the genotype argument has been modified or not.
|
||||
<p><b><font color="#FF0000">EO classes for variation operators</font></b>:
|
||||
<ul>
|
||||
<li>
|
||||
<b><font color="#FF0000">Base classes</font></b>: all variation operators
|
||||
in EO derive from the base (pure abstract) class <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_op.html">eoOp</a></font></font></b>
|
||||
(as usual, click to see the inheritance diagram). Four (also abstract)
|
||||
classes derive from <b><font color="#CC33CC">eoOp</font></b>, namely <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b>
|
||||
(for <a href="#mutation">mutations</a>), <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_bin_op.html">eoBinOp</a></font></font></b>
|
||||
and <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_quad_op.html">eoQuadOp</a></font></font></b>
|
||||
(for <a href="#crossover">crossover</a>) and <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_gen_op.html">eoGenOp</a></font></font></b>
|
||||
for <a href="#general">all other operators</a>.</li>
|
||||
|
||||
<li>
|
||||
<b><font color="#FF0000">Combined classes</font></b>: those classes combine
|
||||
variation operators, and are variation operators by themselves: the simple
|
||||
variation operators can be combined into the corresponding <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_prop_combined_mon_op.html">eoProportionalCombinedMonOp</a></font></font></b>,
|
||||
<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_prop_combined_bin_op.html">eoProportionalCombinedBinOp</a></font></font></b>
|
||||
and <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_pro_combined_quad_op.html">eoProportionalCombinedQuadOp</a></font></font></b>.
|
||||
The general operators <b><font color="#CC33CC">eoGenOp</font></b> can be
|
||||
combined into some <b><font face="Arial,Helvetica"><font color="#000000"><font size=+1><a href="../../doc/html/classeo_op_container.html">eoOpContainer</a></font></font></font></b>,
|
||||
abstract class with two implementations, <b><font face="Arial,Helvetica"><font color="#000000"><font size=+1><a href="../../doc/html/classeo_proportional_op.html">eoProportionalOp</a></font></font></font></b>
|
||||
and <b><font face="Arial,Helvetica"><font color="#000000"><font size=+1><a href="../../doc/html/classeo_sequential_op.html">eoSequentialOp</a></font></font></font></b></li>
|
||||
|
||||
<li>
|
||||
<b><font color="#FF0000">Related classes</font></b>: General operators
|
||||
of class <b><font color="#CC33CC">eoGenOp</font></b> can only be used through
|
||||
the <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_populator.html">eoPopulator</a></font></font></b>
|
||||
class.</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="crossover"></a><b><font size=+1><font color="#000099">Simple
|
||||
operators: </font><font color="#FF0000">Crossover</font></font></b>
|
||||
<p>The characteristic of crossover operators is that they involve two parents.
|
||||
However, there are crossover operators that generate two parents, and some
|
||||
that generate one parent only, and both types are available in EO. The
|
||||
former type (2 --> 2) is termed quadratic crossover operator, and is implemanted
|
||||
in the <b><font color="#CC33CC">eoQuadOp</font></b> class; the latter type
|
||||
(2 --> 1) is termed binary operator and is implemanted in class <b><font color="#CC33CC">eoBinOp</font></b>.
|
||||
Both classes are, as usual, templatized by the type of individual they
|
||||
can handle (see documentation for <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_bin_op.html">eoBinOp</a></font></font></b>
|
||||
and <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_quad_op.html">eoQuadOp</a></font></font></b>).
|
||||
<p><b><font color="#FF0000">Note:</font></b> Whereas it is straightforward
|
||||
to create a binary crossover operator from a quadratic one (by discarding
|
||||
the changes on the second parent), the reverse might prove impossible (imagine
|
||||
a binary crossover that simply merges the parents material: there is no
|
||||
way to generate two new parents from that!).
|
||||
<p><b><font color="#FF0000">Interfaces</font></b>:
|
||||
<br>The general approach in EO about simple variation operators is to perform
|
||||
<b><font color="#FF6600">in-place
|
||||
modifications</font></b>, i.e. modifying the arguments rather than generating
|
||||
new (modified) individuals. This results in the following interfaces for
|
||||
the functor objects eoBinOp and eoQuadOp:
|
||||
<p><b><tt><font color="#993300">bool operator()(EOT & , const EOT &) </font></tt></b>
|
||||
for eoBinOp (note the const)
|
||||
<br><b><tt><font color="#993300">bool operator()(EOT & , EOT &
|
||||
) </font></tt></b>
|
||||
for eoQuadOp
|
||||
<p>which you could have guessed from the inheritance diagrams up to the
|
||||
eoBF abstract class. You can also guess that only the first argument will
|
||||
be modified by an oeBin object, while both arguments will be modified by
|
||||
an eoQuad object.
|
||||
<p><b><font color="#FF0000">Using crossover operators</font></b>:
|
||||
<br>Directly applying crossover operators is straightforward from the interface
|
||||
above:
|
||||
<br><tt><font color="#993300"><b>eoBinOpDerivedClass<Indi> myBinOp(parameters);
|
||||
</b>//
|
||||
use constructor to pass</font></tt>
|
||||
<br><tt><font color="#993300"><b>eoQuadOpDerivedClass<Indi> myQuadOp(parameters);
|
||||
</b>//
|
||||
any useful argument</font></tt>
|
||||
<br><tt><font color="#993300"><b>Indi eo1= ..., eo2= ...; </b>//
|
||||
the candidates to crossover</font></tt>
|
||||
<br><b><tt><font color="#993300">if (myBinOp(eo1, eo2))</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> { ...
|
||||
</b>// eo1 has been modified, <b>not</b> eo2</font></tt>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><tt><font color="#993300"><b>else ...
|
||||
</b>// none has been modified</font></tt>
|
||||
<br><b><tt><font color="#993300">if (myQuadOp(eo1, eo2))</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> { ...
|
||||
</b>// both eo1 and eo2 have been modified</font></tt>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><tt><font color="#993300"><b>else ...
|
||||
</b>// none has been modified</font></tt>
|
||||
<p>However, you will hardly have to actually apply operators to individuals,
|
||||
as operators are used within other classes, and are applied systematically
|
||||
to whole sets of individuals (e.g. that have already been selected, in
|
||||
standard generation-based evolutionary algorithms).
|
||||
<br>Hence the way to use such operators will more likely ressemble <a href="FirstRealGA.html#operators">this</a>
|
||||
if you are using for instance an SGA. See also the different ways that
|
||||
are described below, encapsulating the operators into combined operators
|
||||
objects.
|
||||
<p><a NAME="writing_crossover"></a><b><font color="#FF0000">Writing a crossover
|
||||
operator:</font></b>
|
||||
<br>There are three things to modify in the template class definitions
|
||||
provided in the Templates directory for both <a href="../Templates/binCrossover.tmpl">binary
|
||||
crossover</a> and <a href="../Templates/quadCrossover.tmpl">quadratic crossovers</a>
|
||||
(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
|
||||
actual crossover.</li>
|
||||
|
||||
<li>
|
||||
The <font color="#FF6600">return value</font>, that should be <b><tt><font color="#993300">true</font></tt></b>
|
||||
as soon as at least one genotype has actually been modified. Otherwise,
|
||||
the <a href="eoEval.html#lazy">lazy fitness evaluation procedure</a> in
|
||||
EO might not know it should compute the fitness again and will keep the
|
||||
old value.</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="mutation"></a><b><font color="#000099"><font size=+1>Simple
|
||||
operators: </font></font><font color="#FF0000"><font size=+2>Mutation</font></font></b>
|
||||
<br>Mutation operators modify one single individual. The corresponding
|
||||
EO class is called <b><font color="#CC33CC">eoMonOp</font></b>. and it
|
||||
si as usual templatized by the type of individual it can handle (see documentation
|
||||
for <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b>).
|
||||
<p><b><font color="#FF0000">Interfaces</font></b>:
|
||||
<br>The general approach in EO about simple variation operators is to perform
|
||||
<b><font color="#FF6600">in-place
|
||||
modifications</font></b>, i.e. modifying the arguments rather than generating
|
||||
new (modified) individuals. This results in the following interface for
|
||||
the functor objects eoMonOp:
|
||||
<p><b><tt><font color="#993300">bool operator()(EOT & )</font></tt></b>
|
||||
<p>which you could have guessed from the inheritance diagrams up to the
|
||||
eoUF abstract class.
|
||||
<p><b><font color="#FF0000">Using mutation operators</font></b>:
|
||||
<br>Directly applying mutation operators is straightforward from the interface
|
||||
above:
|
||||
<br><tt><font color="#993300"><b>eoMonOpDerivedClass<Indi> myMutation(parameters);</b>
|
||||
//pass parameters in constructor</font></tt>
|
||||
<br><tt><font color="#993300"><b>Indi eo = ...;
|
||||
/</b>/ eo is candidate to mutation</font></tt>
|
||||
<br><b><tt><font color="#993300">if (myMutation(eo))</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> { ... </b>//
|
||||
eo has been modified</font></tt>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><tt><font color="#993300"><b>else </b>//
|
||||
eo has not been modified</font></tt>
|
||||
<p>However, you will hardly have to actually apply operators to individuals,
|
||||
as operators are used within other classes, and are applied systematically
|
||||
to whole sets of individuals (e.g. that have already been selected, in
|
||||
standard generational evolutionary algorithms).
|
||||
<br>Hence the way to use such operators will more likely ressemble <a href="FirstRealGA.html#operators">this</a>
|
||||
if you are using for instance an SGA. See also the different ways that
|
||||
are described below, encapsulating the operators into combined operators
|
||||
objects.
|
||||
<p><a NAME="writing_mutation"></a><b><font color="#FF0000">Writing a mutation
|
||||
operator:</font></b>
|
||||
<br>There are only two things to modify in the <a href="../Templates/mutation.tmpl">template
|
||||
class definitions</a> provided in the Templates directory (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
|
||||
actual crossover.</li>
|
||||
|
||||
<li>
|
||||
The <font color="#FF6600">return value</font>, that should be <b><tt><font color="#993300">true</font></tt></b>
|
||||
as soon as the genotype has actually been modified. Otherwise, the
|
||||
<a href="eoEval.html#lazy">lazy
|
||||
fitness evaluation procedure</a> in EO might not know it should compute
|
||||
the fitness again and will keep the old value.</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="proportional_simple"></a><b><font size=+1><font color="#000099">Combining
|
||||
simple operators: </font><font color="#FF0000">proportional combinations</font></font></b>
|
||||
<p>The best thing to do is to go to the <a href="eoLesson2.html#combined_operators">Lesson2</a>
|
||||
of the tutorial, where everything is explained. You will find out how you
|
||||
can use
|
||||
<br>several mutations (respectiveley quadratic crossovers) as a single
|
||||
operator: every time the operator is called, one of the available operators
|
||||
is chosen by some roulette wheel selection using realtive weights.
|
||||
<p>
|
||||
<hr WIDTH="100%"><a NAME="general"></a><b><font color="#000099"><font size=+2>General
|
||||
Operators</font></font></b>
|
||||
<p>General operators in EO are variation operators that are neither simple
|
||||
mutations nor simple crossovers. They can involve any number of parents,
|
||||
and create any number of offspring. Moreover, they can make use of different
|
||||
ways to get the parents they will involve, e.g. they can use a different
|
||||
selector for each of the parents they need to select.
|
||||
<p>The corresponding EO class is called <b><font color="#CC33CC">eoGenOp</font></b>.
|
||||
and it is as usual templatized by the type of individual it can handle
|
||||
(see documentation for <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoGenOp</a></font></font></b>
|
||||
:-)
|
||||
<p><a NAME="interface"></a><b><font color="#FF0000">Interface</font></b>:
|
||||
<br>All the work a general operator is done within the <b><tt><font color="#993300">apply()</font></tt></b>
|
||||
method. WHy not in the usual operator() method? Because some memory management
|
||||
are needed, that are performed in the base class itself - which then calls
|
||||
the virtual <b><tt><font color="#993300">apply()</font></tt></b> method.
|
||||
The interface for a <b><font color="#CC33CC">eoGenOp</font></b> thus is
|
||||
not deducible from its inheritance diagram, and actually is
|
||||
<p><b><tt><font color="#993300"> void apply(eoPopulator<EOT>&
|
||||
_plop)</font></tt></b>
|
||||
<p><font color="#000000">As you can see,the interface for </font><b><font color="#CC33CC">eoGenOp</font></b><font color="#000000">
|
||||
is based on that of another class, called </font><b><font color="#999900">eoPopulator</font><font color="#CC33CC">.
|
||||
</font></b>An
|
||||
<b><font color="#999900">eoPopulator</font></b>
|
||||
is a <b><font color="#FF6600">population</font></b>, but also behaves like
|
||||
an <b><font color="#FF6600">iterator</font></b> over a population (hence
|
||||
the name, <b><font color="#FF6600">Popul</font></b>ation-Iter<b><font color="#FF6600">ator</font></b>).
|
||||
However, please note that you should probably never use an eoGenOp alone,
|
||||
but rather through objects of type <a href="#general_combination">eoOpContainer</a>.
|
||||
<p>This results in the following general interface for an <b><font color="#CC33CC">eoGenOp</font></b>:
|
||||
It receives as argument an <b><font color="#999900">eoPopulator</font></b>,
|
||||
gets the individuals it needs using the <b><tt><font color="#993300">operator*</font></tt></b>,
|
||||
and must handle the positinning of the using the <b><tt><font color="#993300">++operator</font></tt></b>
|
||||
method (<b><font color="#FF6600">Warning</font></b>: the <b><tt><font color="#993300">operator++</font></tt></b>
|
||||
method is not defined, as recommended by many good-programming-style books).
|
||||
<p><a NAME="apply"></a><b><tt><font color="#993300">bool apply()(</font><font color="#999900">eoPopulator</font><font color="#993300">&
|
||||
_pop)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> EOT& parent1 = *_pop;
|
||||
</b>//
|
||||
select the first parent</font></tt>
|
||||
<br><tt><font color="#993300"><b> ++_plop; </b>//
|
||||
advance once for each selected parents</font></tt>
|
||||
<br><b><tt><font color="#993300"> ...</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> EOT& parentN = *_pop;
|
||||
</b>//
|
||||
select the last parent</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>//
|
||||
don't advance after the last one: _plop always</font></tt>
|
||||
<br><tt><font color="#993300">
|
||||
// points to the last that has already been treated</font></tt>
|
||||
<p><tt><font color="#993300">// do whatever the operator is supposed to
|
||||
do</font></tt>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b>
|
||||
<p><b><font color="#FF6600">Warning</font></b>: as said above, an eoPopulator
|
||||
should always point to the last individual that has already been treated.
|
||||
This is because it is intended to be used within a loop that looks like
|
||||
(see e.g. <b><tt><a href="../../doc/html/classeo_general_breeder.html">eoBreeder</a></tt></b>
|
||||
class):
|
||||
<p><tt><font color="#993300"><b> eoSelectivePopulator<EOT>
|
||||
popit(_parents, _offspring, select);</b> // eoSelect
|
||||
is an eoSelectOne</font></tt>
|
||||
<br><b><tt><font color="#993300"> while (_offspring.size()
|
||||
< target)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
{</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
op(popit);</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
++it;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
}</font></tt></b>
|
||||
<p><b><font color="#FF6600">What happens next?</font></b> Well, it all
|
||||
depends on how many parents and how many offspring your general op needs:
|
||||
<ul>
|
||||
<li>
|
||||
If the number of generated offspring is <font color="#FF6600">equal</font>
|
||||
to the number of parents, the operator simply needs to modify them (they
|
||||
are passed by reference, no useless copy takes place).</li>
|
||||
|
||||
<li>
|
||||
If the operator produces <font color="#FF6600">more offspring than there
|
||||
were parents</font>, it needs to insert them into the list using the <b><tt><font color="#993300">insert</font></tt></b>
|
||||
method of the class <b><font color="#999900">eoPopulator</font></b> as
|
||||
in the following:</li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<p><b><tt><font color="#993300">void apply()(</font><font color="#999900">eoPopulator</font><font color="#993300">&
|
||||
_pop)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b>// get the necessary number
|
||||
of parents (see <a href="#apply">above</a>)</font></tt>
|
||||
<br><tt><font color="#993300"> ...</font></tt>
|
||||
<br><tt><font color="#993300"> // Now create any supplementary offspring</font></tt>
|
||||
<br><b><tt><font color="#993300"> EOT ofs1 = create_individual(...);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> ...</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> EOT ofsK = create_individual(...);</font></tt></b>
|
||||
<br><tt><font color="#993300"> // advance and inserts offspring in
|
||||
_pop after parentN</font></tt>
|
||||
<br><b><tt><font color="#993300"> ++_pop;</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> _pop.insert(ofs1);</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> ...</font></tt></b>
|
||||
<p><tt><font color="#993300"><b> </b>// invalidate the parents that
|
||||
have been modified</font></tt>
|
||||
<br><b><tt><font color="#993300"> parent1.invalidate();</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> ...</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> parentN.invalidate();</font></tt></b>
|
||||
<br><tt><font color="#993300"><b>}</b> // over</font></tt>
|
||||
<p>Of course the size of the resulting population will grow - and you should
|
||||
have a replacement procedure that takes care of that.
|
||||
<br>
|
||||
<li>
|
||||
The case where <font color="#FF6600">more parents are needed than offspring
|
||||
will be created</font> is a little more delicate: think about <b><font color="#CC33CC">eoBinOp</font></b>,
|
||||
and try to imagine the reasons why no crossover of that class are used
|
||||
in the first lessons of the tutorial, within the SGA framework.</li>
|
||||
|
||||
<br>There are two possibilities:
|
||||
<ul>
|
||||
<li>
|
||||
If you think "generational", the first idea is to get the parents from
|
||||
outside the curent list, so the total number of (intermediate) offspring
|
||||
is always equal to the initial population size. By chance, the <b><font color="#999900">eoPopulator</font></b>has
|
||||
a handle on the initial population that was used to start the process,
|
||||
and you can access it from inside the GenOp method. For instance</li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<p><b><tt><font color="#993300">void apply()(</font><font color="#999900">eoPopulator</font><font color="#993300">&
|
||||
_pop)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b>// get as many parents as you
|
||||
will have offspring (see <a href="#apply">above</a>)</font></tt>
|
||||
<br><tt><font color="#993300"> ...</font></tt>
|
||||
<br><tt><font color="#993300"><b> // </b>get extra parents - use
|
||||
private selector</font></tt>
|
||||
<br><b><tt><font color="#993300"> const EOT& parentN+1 = </font><font color="#009900">select</font><font color="#993300">(_pop.source());</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> ...</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> const EOT& parentM = </font><font color="#009900">select</font><font color="#993300">(_pop.source());</font></tt></b>
|
||||
<br><tt><font color="#993300"> // do whatever needs to be done</font></tt>
|
||||
<br><tt><font color="#993300"> ...</font></tt>
|
||||
<br><tt><font color="#993300"> // and of course invalidate fitnesses
|
||||
of remaining modified parents</font></tt>
|
||||
<br><tt><font color="#993300"> <b>parent1.invalidate();</b></font></tt>
|
||||
<br><b><tt><font color="#993300"> ...</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> parentN.invalidate();</font></tt></b>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b>
|
||||
<br>where select is any selector you like. <font color="#FF6600">Note the
|
||||
const:</font> you are not allowed to modify an element of the original
|
||||
population (but you could of course have copied it!). As usual, the <b><tt><font color="#009900">select</font></tt></b>
|
||||
selector was passed to the operator at construct time. This typically allows
|
||||
one to use a different selector for one parent and the others, as demonstrated
|
||||
<a href="#advanced_general">here</a>.
|
||||
<br>
|
||||
<li>
|
||||
If you don't care about the size of the offspring population (that is,
|
||||
if that size os controlled elsewhere, e.g. in some external loop), you
|
||||
can use the inbedded select method of the class <b><font color="#999900">eoPopulator</font></b>.
|
||||
For instance</li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<p><b><tt><font color="#993300">void apply()(</font><font color="#999900">eoPopulator</font><font color="#993300">&
|
||||
_pop)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b>// get as many parents as you
|
||||
will have offspring (see <a href="#apply">above</a>)</font></tt>
|
||||
<br><tt><font color="#993300"> ...</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>// get extra parents - use
|
||||
populator selector</font></tt>
|
||||
<br><b><tt><font color="#993300"> const EOT& parentN+1 = _pop.</font><font color="#009900">select</font><font color="#993300">();</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> ...</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> const EOT& parentM = _pop.</font><font color="#009900">select</font><font color="#993300">();</font></tt></b>
|
||||
<br><tt><font color="#993300"> // do whatever needs to be done</font></tt>
|
||||
<br><tt><font color="#993300"> ...</font></tt>
|
||||
<br><tt><font color="#993300"> // and of course invalidate fitnesses
|
||||
of remaining modified parents</font></tt>
|
||||
<br><tt><font color="#993300"> <b>parent1.invalidate();</b></font></tt>
|
||||
<br><b><tt><font color="#993300"> ...</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> parentN.invalidate();</font></tt></b>
|
||||
<br><tt><font color="#993300">}</font></tt></ul>
|
||||
</ul>
|
||||
<b><font color="#FF6600">Warning</font></b>: if you use operators that
|
||||
have different number of parents than offspring, you are deviating from
|
||||
the simple generational approach. Be careful to have the proper replacement
|
||||
procedure to take care of the population size: in most instances of algorithms
|
||||
that come within EO, this is enforced (an exception is thrown if population
|
||||
size varies from one genertaion to the other) but this might not be true
|
||||
for all forthcoming EO algorithms.
|
||||
<p><b><font color="#FF0000">Using general operators</font></b>:
|
||||
<br>Directly applying general operators to given individuals is impossible
|
||||
in EO, due to its <a href="#interface">interface</a>. You need the help
|
||||
of an individual dispenser of class <b><font color="#999900">eoPopulator</font></b>.
|
||||
But anyway general operators were thought to be used putely in <b><tt><font color="#CC33CC">eoOpContainer</font></tt></b>,
|
||||
as described <a href="#general_combination">below</a>.
|
||||
<p><a NAME="writing_mutation"></a><b><font color="#FF0000">Writing a general
|
||||
operator:</font></b>
|
||||
<br>There are many things to do to write a general operator - but the Templates
|
||||
directory contains some sample tempaltes files to help you. It all depends
|
||||
on whether you want more or less offspring than parents, and whetehr you
|
||||
want the same selector for every parent or more specialized selectors.
|
||||
<ul>
|
||||
<li>
|
||||
It you want <font color="#FF6600">more (or as many) </font>offspring than
|
||||
parents, you should use the <a href="../Templates/moreOffspringGenOp.tmpl">moreOffspringGenOp.tmpl</a>
|
||||
template - if you want to use the same selector for all parents, the one
|
||||
embedded in the argument <b><font color="#999900">eoPopulator</font></b>.
|
||||
Otherwise, you'll have to write your own operator based on an external
|
||||
selector, as described in <a href="../Templates/lessOffspringExternalSelectorGenOp.tmpl">lessOffspringExternalSelectorGenOp.tmpl</a>.</li>
|
||||
|
||||
<li>
|
||||
If you decide to have more parents than offspring, you can decide either
|
||||
to get the extra parents using the <b><font color="#999900">eoPopulator</font></b>
|
||||
own selector (see <a href="../Templates/lessOffspringSameSelectorGenOp.tmpl">lessOffspringSameSelectorGenOp.tmpl</a>,
|
||||
or to use an external selector (passed at construct-time) as described
|
||||
in <a href="../Templates/lessOffspringExternalSelectorGenOp.tmpl">lessOffspringExternalSelectorGenOp.tmpl</a>.</li>
|
||||
|
||||
<li>
|
||||
Now you can modify the <font color="#FF6600">constructor</font>, where
|
||||
you pass to the object any useful parameter (see private data at end of
|
||||
class definition). In case you need an external selector, you have to choose
|
||||
it (or write it!) - it should be an <a href="eoEngine.html#selection">eoSelectOne</a>
|
||||
object.</li>
|
||||
|
||||
<li>
|
||||
Finally, write the core of the operator in method <font color="#FF6600">apply()</font>.
|
||||
Remember you must use the argument <b><font color="#999900">eoPopulator
|
||||
</font></b>to
|
||||
access the members of the population in turn (method
|
||||
<b><tt><font color="#993300">operator*</font></tt></b>),
|
||||
you may use the initial population (method <b><tt><font color="#993300">source()</font></tt></b>),
|
||||
as well as the <b><tt><font color="#993300">insert</font></tt></b> methods.</li>
|
||||
</ul>
|
||||
|
||||
<ul><b><font color="#FF6600">Warning</font></b>: in general operators,
|
||||
you must not forget to <b><font color="#FF6600">invalidate</font></b> the
|
||||
fitness of any individual that has actually been modified. this implicitely
|
||||
implies that general operators can only be applied to EO object (i.e. objects
|
||||
with a fitness), and not to any type of structure.
|
||||
<br>It you don't invalidate the individual, the <a href="eoEval.html#lazy">lazy
|
||||
fitness evaluation procedure</a> in EO will not know it should compute
|
||||
the fitness again and will keep the old obsolete value.</ul>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="populators"></a><b><font color="#000099"><font size=+2>The
|
||||
populators:</font></font></b>
|
||||
<br>As has been said above, an
|
||||
<b><font color="#999900">eoPopulator</font></b>
|
||||
mainly behaves like an <b><font color="#FF6600">iterator</font></b> over
|
||||
a population (hence the name, <b><font color="#FF6600">Popul</font></b>ation-Iter<b><font color="#FF6600">ator</font></b>).
|
||||
<p><a NAME="populator_interface"></a>The <b><font color="#FF6600">basic
|
||||
interface</font></b> of an <b><font color="#999900">eoPopulator</font></b>
|
||||
(see also <a href="../../doc/html/classeo_gen_op.html">the documentation</a>,
|
||||
of course) is the following:
|
||||
<ul>
|
||||
<li>
|
||||
Individuals are accessed through the <b><tt><font color="#993300">operator*</font></tt></b>;</li>
|
||||
|
||||
<li>
|
||||
Basic iterator operations are available, like (pre)incrementation through
|
||||
<b><tt><font color="#993300">operator++</font></tt></b>,
|
||||
position management through <b><tt><font color="#993300">seekp</font></tt></b>
|
||||
(returns the current position) and <b><tt><font color="#993300">tellp</font></tt></b>
|
||||
(go to a given position);</li>
|
||||
|
||||
<li>
|
||||
Individuals can also be <b><font color="#993300">insert</font></b>ed at
|
||||
current position using the corresponding methods;</li>
|
||||
|
||||
<li>
|
||||
last but not least, as the individuals are returned by reference, it is
|
||||
mandatory to ensure that they will not be moved around later: the memory
|
||||
management routine <b><tt><font color="#993300">reserve</font></tt></b>
|
||||
is called whenever there is a chance to add some individuals in the population
|
||||
- i.e. in the eoGenOp base class operator() method.</li>
|
||||
</ul>
|
||||
Moreover, a public method termed <b><tt><font color="#993300">select</font></tt></b>,
|
||||
is used inside the object to get new parents for the following <b><tt><font color="#993300">operator*</font></tt></b>,
|
||||
and its implementation distinguishes two types of <b><font color="#999900">eoPopulator</font></b>:
|
||||
<ul>
|
||||
<li>
|
||||
The <b><font color="#999900">eoSeqPopulator</font></b> gets new parents
|
||||
from its source (the initial population). When the source is exhausted,
|
||||
an exception if thrown. The idea of such pooulator is to start from a population
|
||||
of already selected individuals.</li>
|
||||
|
||||
<br>The programmer should hence be very careful that the number of available
|
||||
parents matches the requirements of the operators when using an <b><font color="#999900">eoSeqPopulator</font></b>
|
||||
object.
|
||||
<li>
|
||||
The <b><font color="#999900">eoSelectivePopulator</font></b> , on the opposite,
|
||||
always gets new parents using its private <b><font color="#009900">eoSelectOne</font></b>
|
||||
object (passed at construct time). Hence it can handle any number of parents
|
||||
at will. The idea of such populator is to handle the whole <b><font color="#FF6600">breeding</font></b>
|
||||
process, i.e. selection and variation operators.</li>
|
||||
</ul>
|
||||
An immediate consequence is that if you are not sure of the number of
|
||||
parents you will need in some operators (e.g. because of some stochastic
|
||||
proportional selection ebtween operators that don't need the same number
|
||||
of parents, then you <b><font color="#FF6600">must</font></b> use an <b><font color="#CC33CC">eoSelectivePopulator</font></b>
|
||||
to apply the variation operators to the population, and thus get exactly
|
||||
the number of offspring you want.
|
||||
<p><b><font color="#FF0000">Example</font></b>: An <b><font color="#CC33CC">eoSelectivePopulator</font></b>
|
||||
is the main ingredient of the <b><tt><font color="#FF6666">eoGeneralBreeder
|
||||
</font></tt></b><a href="../../doc/html/eo_general_breeder_8h-source.html#l00061">operator()
|
||||
method</a> - a class that creates a population of offspring from the parents
|
||||
applying an eoGenOp (usually an eoOpContainer) to all selected parents
|
||||
in turn.
|
||||
<br>
|
||||
<hr WIDTH="100%"><a NAME="general_combination"></a><b><font color="#000099"><font size=+2>General
|
||||
Operator Containers:</font></font></b>
|
||||
<br>General operators in EO are meant to be used withing eoOpContainer
|
||||
objects, that allow to combine them in a hierarchical and flexible way.
|
||||
There are two ways to do that: the <b><font color="#FF6600">proportional
|
||||
combination</font></b>, similar to what has been described for simple operators
|
||||
<a href="#proportional_simple">above</a>,
|
||||
and the <b><font color="#FF6600">sequential combination</font></b>, which
|
||||
amounts to apply all operators in turn to a bunch of individuals, each
|
||||
operator being applied with a specific probability.
|
||||
<p><a NAME="prop_container"></a><b><font color="#FF0000">Proportional combinations</font></b>
|
||||
<br>When called upon a population (through an <b><font color="#999900">eoPopulator</font></b>
|
||||
object), an <b><font color="#CC33CC">eoProportionalOpContainer</font></b>
|
||||
enters the following loop:
|
||||
<p>while there are individuals left in the list
|
||||
<ul>
|
||||
<li>
|
||||
choose one of the included operators according to their relative rates
|
||||
(by some roulette wheel random choice)</li>
|
||||
|
||||
<li>
|
||||
applies the chosen operator. The parents are dispensed to the operator
|
||||
from the list on demand.</li>
|
||||
|
||||
<li>
|
||||
What happens next exactly depends on the type of operator, but basically,
|
||||
some of the parents get modified, some might get removed from the list
|
||||
and some new individual might get inserted on the list.</li>
|
||||
|
||||
<li>
|
||||
updates the list pointer (if needed) to the individual following the ones
|
||||
that just have been modified/inserted/deleted.</li>
|
||||
</ul>
|
||||
<a NAME="seqential_container"></a><b><font color="#FF0000">Sequential combinations</font></b>
|
||||
<br>When it is called upon a list of pending candidates, an
|
||||
<b><font color="#CC33CC">eoSequentialOpContainer</font></b>
|
||||
enters the following loop:
|
||||
<p>mark the current position
|
||||
<br>for all operators it contains,
|
||||
<ul>
|
||||
<li>
|
||||
go to marked position</li>
|
||||
|
||||
<li>
|
||||
until <a href="#container_and_populator">current end of population</a>
|
||||
is reached do</li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
flip a coin according to the operator rate.</li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
If true, apply the operator to the parents. The current parents can be
|
||||
modified, or some can be deleted from the list, or some offspring can be
|
||||
inserted in the list.</li>
|
||||
|
||||
<li>
|
||||
If false, move the pointer over the required number of parents (i.e. don't
|
||||
modify thoses parents)</li>
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
Next pending parent</li>
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
Next operator</li>
|
||||
</ul>
|
||||
<b><font color="#FF6600">Warning</font></b>: the way <b><tt><font color="#993300">rate</font></tt></b>
|
||||
will be used is highly dependent on the type of <b><font color="#CC33CC">eoOpContainer</font></b>
|
||||
your are creating there:
|
||||
<ul>
|
||||
<li>
|
||||
The rates for <b><font color="#CC33CC">eoProportionalOpContainer</font></b>
|
||||
will be used in a roulette wheel choice among all operators. They can take
|
||||
any value, the only important thing is their <b><font color="#FF6600">relative
|
||||
values</font></b>.</li>
|
||||
|
||||
<li>
|
||||
The "rates" for <b><font color="#CC33CC">eoSequentialOpContainer </font></b>actually
|
||||
are <b><font color="#FF6600">probabilities</font></b>, i.e. they will be
|
||||
used in a coin-flipping to determine whether that particuler operator will
|
||||
be applied to the next candidates at hand. They should be <b><font color="#FF6600">in
|
||||
[0,1]</font></b> (no error will happen if they are not, but the operator
|
||||
will be applied systematically - this is equivalent of a rate equal to
|
||||
1).</li>
|
||||
</ul>
|
||||
<font color="#FF6600">Remark:</font>The eoSGATransform presented in <a href="eoLesson2.html#transform">Lesson2</a>
|
||||
can be viewed as a particular type of <b><font color="#CC33CC">eoSequentialOpContainer</font></b>.
|
||||
It was not coded that way in order to provide a gradual introduction to
|
||||
all concepts.
|
||||
<br><font color="#FF6600">Exercise</font>: write the code to perform an
|
||||
eoSGA using the eoOpContainer constructs.
|
||||
<p><b><font color="#FF0000">Adding operators to a container:</font></b>
|
||||
<br>The way to add an operator to an <b><font color="#CC33CC">eoOpContainer</font></b>
|
||||
is the method
|
||||
<b><tt><font color="#993300">add</font></tt></b>. It is similar
|
||||
to all other <b><tt><font color="#993300">add</font></tt></b> methods in
|
||||
other Combined things in eo (as the simple eoProportionalCombinedXXXop
|
||||
described above, but also the eoCombinedContinue class or the eoCheckPoint
|
||||
class).
|
||||
<br>The syntax is straightforward, and it works with any of the operator
|
||||
classes <b><font color="#CC33CC">eoXXXOp</font></b>, where XXX stands for
|
||||
<b><font color="#CC33CC">Mon,
|
||||
Bin, Quad </font></b><font color="#000000">or</font><b><font color="#CC33CC">
|
||||
Gen</font></b>:
|
||||
<p><b><tt><font color="#993300">someOperatorType<Indi> myOperator;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">eoYYYOpContainer<Indi> myOpContainer;</font></tt></b>
|
||||
<br><tt><font color="#993300"><b>myOpContainer.add(myOperator, rate); </b>//
|
||||
rate: double whose <b>meaning depends on YYY</b></font></tt>
|
||||
<p>where YYY can be one of Proportional and Sequential. Note that before
|
||||
being added to the container, all simple operators are wrapped into the
|
||||
corresponding eoGenOp (see e.g. how an <b><font color="#CC33CC">eoMonOp</font></b><a href="../../doc/html/eo_gen_op_8h-source.html#l00084">is
|
||||
wrapped</a> into an <b><font color="#CC33CC">eoMonGenOp</font></b>- or
|
||||
how <a href="../../doc/html/eo_gen_op_8h-source.html#l00169">any operator
|
||||
is handled</a> by calling the appropriate wrapper). In particular, the
|
||||
wrapper ensures that <b><font color="#FF6600">individuals who have been
|
||||
modified are invalidated</font></b>.
|
||||
<p><a NAME="container_and_populator"></a><b><font color="#FF0000">Containers,
|
||||
Selectors and Populators</font></b>
|
||||
<br>The way the <b><font color="#CC33CC">eoOpContainer</font></b> are applied
|
||||
on a population using an <b><font color="#999900">eoPopulator</font></b>
|
||||
object. But, whereas the behavior of <b><font color="#CC33CC"><a href="#prop_container">eoProportionalOpContainer</a></font></b>
|
||||
does not depend on the type of <b><font color="#999900">eoPopulator</font></b>,(one
|
||||
operator is chosen by roulette_wheel, and applied once before control is
|
||||
given back to the caller), the main loop in method <b><tt><font color="#993300">operator()
|
||||
</font></tt></b>of
|
||||
class <b><font color="#CC33CC"><a href="#seqential_container">eoSequentialOpContainer</a></font></b>
|
||||
iterates <b><tt><font color="#993300">while (!_pop.exhausted())</font></tt></b>
|
||||
which is interpreted differently depending on the <a href="#populators">type
|
||||
of <b><font color="#CC33CC">eoPopulator</font></b></a>:
|
||||
<ul>
|
||||
<li>
|
||||
if the argument is an <b><font color="#999900">eoSelectivePopulator</font></b>,
|
||||
the default position of the eoPopulator, considered as a population iterator,
|
||||
is at end of population. Individuals are added upon demand of an operator,
|
||||
and in most cases all operators are applied once. This also depends, however,
|
||||
on the arities of all operators:</li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
Consider an <b><font color="#CC33CC">eoSequentialOpContainer</font></b>
|
||||
containing an eoQuadOp and an eoMonOp. The eoQuadOp first asks for two
|
||||
parents and modifies them. The eoMonOp is then called starting from the
|
||||
forst of thoses two modified individuals, and is hence applied twice, once
|
||||
on each parent.</li>
|
||||
|
||||
<li>
|
||||
But consider now an <b><font color="#CC33CC">eoSequentialOpContainer</font></b>
|
||||
containing an <b><font color="#CC33CC">eoGenOp</font></b> that takes one
|
||||
parent and generates three offspring, followed by an <b><font color="#CC33CC">eoQuadOp</font></b>.
|
||||
The <b><font color="#CC33CC">eoGenOp</font></b> will call the selector
|
||||
to get the parent its need and will modify it and put 2 additional offspring
|
||||
at end of the population. The <b><font color="#CC33CC">eoQuadOp</font></b>
|
||||
will then be called on the first of the three outputs of the <b><font color="#CC33CC">eoGenOp</font></b>,
|
||||
and hence will act upon the frist two of them. But at that point, the populator
|
||||
iterator will point to the third of the individuals resulting from the
|
||||
<b><font color="#CC33CC">eoGenOp</font></b>,
|
||||
and the test <b><tt><font color="#993300">_pop.exhausted()</font></tt></b>
|
||||
will return false, so the <b><font color="#CC33CC">eoQuadOp</font></b>
|
||||
will again be called. The second parent it needs will be given by a new
|
||||
call to the embedded <b><font color="#009900">eoSelectOne</font></b> of
|
||||
the and everything will go on smoothly, except that a total of 4
|
||||
offspring will have been generated by application of this particular <b><font color="#CC33CC">eoSequentialOpContainer</font></b>.</li>
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
if the argument is an <b><font color="#999900">eoSeqPopulator</font></b>,
|
||||
the position of the iterator starts from the beginning of an existing population
|
||||
(the source populations), and hence when an an <b><font color="#CC33CC">eoSequentialOpContainer</font></b>
|
||||
is called, it goes through the whole remaining of the population (the test
|
||||
<b><tt><font color="#993300">_pop.exhausted()</font></tt></b>
|
||||
only returns true at end of the source population).</li>
|
||||
|
||||
<li>
|
||||
From the above it is easy to see that passing an <b><font color="#999900">eoSeqPopulator</font></b>
|
||||
to an <b><font color="#CC33CC">eoProportionalOpContainer</font></b> that
|
||||
contains an <b><font color="#CC33CC">eoSequentialOpContainer</font></b>,
|
||||
though not technically forbiddden, will most produce something totally
|
||||
unpredictable, and hence should probably not be used without great care.</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="advanced_general"></a><b><font color="#000099"><font size=+2>Advanced
|
||||
general operators:</font></font></b>
|
||||
<p>It is sometimes useful to be able to use a selector from inside an operator
|
||||
(a typical example is when you want to implement <b><font color="#FF6600">sexual
|
||||
preferences</font></b>, i.e. choose a mate for a first parent according
|
||||
to some characteritics of that first parent).
|
||||
<br>This is made possible in EO because the general operators have a handle
|
||||
on the initial population through the method <b><tt><font color="#993300">source()</font></tt></b>
|
||||
of the argument eoPopulator they work on. Their <b><tt><font color="#993300">apply()</font></tt></b>
|
||||
method shoudl look like
|
||||
<p><b><tt><font color="#993300">void apply()(</font><font color="#999900">eoPopulator</font><font color="#993300">&
|
||||
_pop)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> EOT & eo1 = *_pop; </b>// get
|
||||
(select if necessary) the first guy</font></tt>
|
||||
<br><b><tt><font color="#993300"> EOT maBlonde = </font><font color="#009900">findBlonde</font><font color="#993300">(_pop.source());
|
||||
</font></tt></b><tt><font color="#993300">//
|
||||
select mate</font></tt>
|
||||
<br><tt><font color="#993300"> // do whatever the operator is supposed
|
||||
to do, e.g</font></tt>
|
||||
<br><tt><font color="#993300"> <b>cross(eo1, maBonde);</b>
|
||||
// cross is some embedded crossover</font></tt>
|
||||
<br><tt><font color="#993300"> <b>...</b></font></tt>
|
||||
<br><tt><font color="#993300"> // if you don't want to put maBlonde
|
||||
into the offspring,</font></tt>
|
||||
<br><tt><font color="#993300"> // stop here (and use a reference
|
||||
to maBlonde above). Otherwise</font></tt>
|
||||
<br><tt><font color="#993300"> <b>maBonde.invalidate();</b></font></tt>
|
||||
<br><tt><font color="#993300"><b> ++_pop; </b>//
|
||||
advance</font></tt>
|
||||
<br><tt><font color="#993300"> <b>_pop.insert(maBlonde);</b>
|
||||
// and insert it</font></tt>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b>
|
||||
<p>Where does that <b><tt><font color="#009900">findBlonde</font></tt></b>
|
||||
selector comes from? As usual, you have to attach it to the operator,
|
||||
in its constructor for instance, which should give something like:
|
||||
<p><b><tt><font color="#993300">sexualSelectorType<Indi> findBlonde;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">sexualOperatorType<Indi> yourBrainAndMyBeauty(cross,
|
||||
findBlonde);</font></tt></b>
|
||||
<p>
|
||||
<hr WIDTH="100%"><b><font color="#FF0000">Local</font></b>: <a href="#introduction">Introduction</a>
|
||||
- <a href="#crossover">Crossover</a> - <a href="#mutation">Mutation</a>
|
||||
- <a href="#proportional_simple">Combinations</a> - <a href="#general">General
|
||||
Operators</a> - <a href="#populators">Populators</a> - <a href="#general_combination">General
|
||||
combinations</a>- <a href="#advanced_general">Advanced operators
|
||||
<hr WIDTH="100%"></a><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: Sat. Feb. 17 2002 <!-- hhmts end -->
|
||||
<br>
|
||||
</body>
|
||||
</html>
|
||||
19
eo/tutorial/html/eoOutput.html
Normal file
19
eo/tutorial/html/eoOutput.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Output</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Output</h1>
|
||||
|
||||
|
||||
|
||||
<hr>
|
||||
<address><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<!-- Created: Mon Oct 30 19:29:17 CET 2000 -->
|
||||
<!-- hhmts start -->
|
||||
Last modified: Mon Oct 30 19:29:19 CET 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
502
eo/tutorial/html/eoProgramming.html
Normal file
502
eo/tutorial/html/eoProgramming.html
Normal file
|
|
@ -0,0 +1,502 @@
|
|||
<!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>EO Programming guide</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="beige009.jpg">
|
||||
<b><font color="#CC0000">General: </font></b><a href="eoTutorial.html">Tutorial
|
||||
main page </a>-
|
||||
<a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based</a>
|
||||
- <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr WIDTH="100%"><b><font color="#CC0000">Local: </font></b><a href="#templates">Templates</a>
|
||||
-
|
||||
<a href="#functors">Functors</a> -
|
||||
<a href="#STL">STL Library</a> - <a href="#random">Random
|
||||
numbers</a> - <a href="#notations">EO programming style</a> - <a href="#memory">Memory
|
||||
management</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">EO Programming guide</font></h1></center>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="templates"></a><b><font color="#000099"><font size=+1>Templates</font></font></b>
|
||||
<p>Most EO code is written using templates. This allows to write generic
|
||||
code, i.e. involving a class which doesn't have to be known when writing
|
||||
the code -- but only when compiling it. In some sense this is similar to
|
||||
naming variables in algebra: you can write a lot of equations involving
|
||||
some variable $x$ without knowing even it if will be an integer or a float
|
||||
(or a matrix or ...). The main basic type that is templatized in EO is
|
||||
the fitness: an EO object is some object which has a fitness of some type
|
||||
F that can be anything. The definition for that is (see <font face="Arial,Helvetica"><a href="../../doc/html/_e_o_8h-source.html">EO.h</a></font>)
|
||||
<p><b><tt><font color="#999900">template<class F> class EO</font></tt></b>
|
||||
<p>The idea is that, later in your code, you can define a class as follows
|
||||
(see for instance <a href="../../doc/html/eoOneMax.html">eoOneMax.h</a> - or check <a href="eoLesson5.html">Lesson 5</a> for more details).
|
||||
<p><b><tt><font color="#999900">template<class F> class eoOneMax : public
|
||||
EO<F></font></tt></b>
|
||||
<br><b><tt><font color="#999900">{ ... code for eoOneMax };</font></tt></b>
|
||||
<p>and then use it in your application as
|
||||
<p><b><tt><font color="#999900">eoOneMax<double> myeoBit;</font></tt></b>
|
||||
<p>declares an object of type eoOneMax which has as fitness a double.
|
||||
<p>Whereas the <b><font color="#FF6600">advantages</font></b>
|
||||
are obvious (writing generic reusable code instead
|
||||
of having to rewrite the same pieces of code for different types), there
|
||||
are some <b><font color="#FF6600">drawbacks</font></b>:
|
||||
namely, it makes some of the compiler error messages
|
||||
hard to understand; and it forbids the compilation of most parts of EO
|
||||
into an object library file, as the actual types are not known in advance.
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="functors"></a><b><font color="#000099"><font size=+1>Functors</font></font></b>
|
||||
<p>Though EO is a library, it contains almost no functions per se!
|
||||
<br>EO mainly contains functors, that are objects which have a method called
|
||||
<b><tt><font color="#FF6600">operator()</font></tt></b>.
|
||||
Such objects are used as if they were functions, but the big differences
|
||||
are that
|
||||
<ul>
|
||||
<li>
|
||||
functors are functions with private data</li>
|
||||
|
||||
<li>
|
||||
you can have different functors objects of the same class, i.e. you can
|
||||
use at the same time the same functionality with different parameters</li>
|
||||
|
||||
<li>
|
||||
you can have a hierarchy of functors objects, which means that you have
|
||||
a hierarchy of functions with defaults behaviors and specialized sub-functions</li>
|
||||
|
||||
<li>
|
||||
...</li>
|
||||
</ul>
|
||||
Functors are so intimately linked to EO that a base class (<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_functor_base.html">eoFunctorBase</a></font></font></b>)
|
||||
has been designed to hold all functors. This base class is itself divided
|
||||
into three derived class. These classes tell you immediately what kind
|
||||
of arguments the <b><tt><font color="#993300">operator()</font></tt></b>
|
||||
method requires and what kind of result it produces. See <a href="#notations">EO
|
||||
conventions</a>, and the <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_functor_base.html">inheritance
|
||||
diagram of class eoFunctorBase</a>. </font></font></b> Also note that
|
||||
if you create new functors, you should also derive from one of these classes,
|
||||
as it is mandatory if you later use the EO <a href="#memory">memory management
|
||||
mechanism</a>.
|
||||
<br>For a more complete introduction to functors, with detailed discussion,
|
||||
go to the <a href="http://www.sgi.com/tech/stl/functors.html">STL documentation</a>
|
||||
- as STL also heavily relies on functors, and the eoFunctorBase paradigm
|
||||
is borrowed from there.
|
||||
<p><b><font color="#FF0000">Functors:</font><font color="#000099"> Example:</font></b>
|
||||
<p>The following is a basic example of how to program and use a functor
|
||||
object: First code the class:
|
||||
<p><b><tt><font color="#993300">class MyFunctor</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{ ...</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> void operator()(ArgType
|
||||
arg)</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> {</font></tt></b>
|
||||
<br><tt><font color="#993300">
|
||||
// do what you have to do</font></tt>
|
||||
<br><b><tt><font color="#993300"> }</font></tt></b>
|
||||
<br><tt><font color="#993300"><b>}; </b>// end of class declaration</font></tt>
|
||||
<p>Then use it later in the code :
|
||||
<p><b><tt><font color="#993300">ArgType myArgument;</font></tt></b>
|
||||
<br><tt><font color="#993300"><b>MyFunctor myFunctorInstance; </b>
|
||||
// myFunctorInstance is an object of class MyFUnctor ...</font></tt>
|
||||
<br><tt><font color="#993300"><b>myFunctorInstance(myArgument);</b>
|
||||
// calls operator() of myFunctorInstance acting on myArgument ...</font></tt>
|
||||
<br>
|
||||
<p><b><font color="#FF0000">Functors:</font><font color="#000099"> The
|
||||
three basic classes:</font></b>
|
||||
<p><font color="#000000">Direct sub-classes of the root class , three classes
|
||||
are defined to differentiate functors by the number of argument required
|
||||
by their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">.
|
||||
These classes are templatized by the types of its arguments, and by its
|
||||
return type. Hence,</font>
|
||||
<br><font color="#000000">from the inheritance diagram of any functor class
|
||||
in EO, you can immediately deduce the interface of their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method.</font>
|
||||
<br>
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#FF6600">eoF</font></tt></b><font color="#000000">
|
||||
is for arity-zero functors, i.e. their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method does not require any argument. It has a single template parameter,
|
||||
the return type of the </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method. For instance, </font> <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_monitor.html">eoMonitor</a></font></font></b> <font color="#000000">
|
||||
are </font><b><tt><font color="#FF6600">eoF</font></tt></b><font color="#000000">'s
|
||||
that return an </font><b><tt><font color="#993300">eoMonitor &</font></tt></b><font color="#000000">.</font></li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#FF6600">eoUF</font></tt></b><font color="#000000">
|
||||
is for unary functors, i.e. their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method requires one argument. It has two template parameters, the type
|
||||
of the argument and the return type of the </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method. For instance, </font> <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b>'s<font color="#000000">
|
||||
are </font><b><tt><font color="#FF6600">eoUF</font></tt></b><font color="#000000">'s
|
||||
that take as argument an </font><b><tt><font color="#993300">EOT &</font></tt></b><font color="#000000">
|
||||
and return </font><b><tt><font color="#993300">void</font></tt></b><font color="#000000">
|
||||
.</font></li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#FF6600">eoBF</font></tt></b><font color="#000000">
|
||||
is for binary functors, i.e. their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method requires two arguments. It has three template parameters, the types
|
||||
of the arguments and the return type of the </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method. For instance, </font> <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_bin_op.html">eoBinOp</a></font></font></b>'s<font color="#000000">
|
||||
are </font><b><tt><font color="#FF6600">eoBF</font></tt></b><font color="#000000">'s
|
||||
that take as arguments a </font><b><tt><font color="#993300">const EOT
|
||||
&</font></tt></b><font color="#000000"> and an </font><b><tt><font color="#993300">EOT
|
||||
&</font></tt></b><font color="#000000">, and return </font><b><tt><font color="#993300">void</font></tt></b><font color="#000000">
|
||||
.</font></li>
|
||||
</ul>
|
||||
<font color="#000000">Now go back to the </font><b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_functor_base.html">inheritance
|
||||
diagram of class eoFunctorBase</a></font></font></b><font color="#000000">,
|
||||
and guess the interface for all functors!</font>
|
||||
<p><b><font color="#FF0000">Note</font></b><font color="#000000">: for
|
||||
obvious simplicity reasons, we very often omit the reference to the </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">,
|
||||
e.g. when we say above:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b>'s<font color="#000000">
|
||||
are </font><b><tt><font color="#FF6600">eoUF</font></tt></b><font color="#000000">'s
|
||||
that take as argument an </font><b><tt><font color="#993300">EOT &</font></tt></b><font color="#000000">
|
||||
and return </font><b><tt><font color="#993300">void</font></tt></b></li>
|
||||
</ul>
|
||||
<font color="#000000">it actually means</font>
|
||||
<ul>
|
||||
<li>
|
||||
<b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b>'s<font color="#000000">
|
||||
are </font><b><tt><font color="#FF6600">eoUF</font></tt></b><font color="#000000">'s,
|
||||
their </font><b><tt><font color="#993300">operator()</font></tt></b><font color="#000000">
|
||||
method takes as argument an </font><b><tt><font color="#993300">EOT &</font></tt></b><font color="#000000">
|
||||
and returns </font><b><tt><font color="#993300">void</font></tt></b><font color="#000000">.</font></li>
|
||||
</ul>
|
||||
|
||||
<p><br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="STL"></a><b><font color="#000099"><font size=+1>A very brief
|
||||
introduction to STL</font></font></b>
|
||||
<p>All EO heavily relies on <b><font color="#FF6600">STL, the Standard
|
||||
Template Library</font></b>.
|
||||
<br>But <font color="#FF6600">you don't have to know more than a few words
|
||||
of STL</font> to use EO (like with "hello", "please" and "goodbye" you
|
||||
can survive in a foreign country :-) and even to contribute to new EO features.
|
||||
Moreover, while browsing through EO code, you will gradually learn how
|
||||
to use STL, especially if you check at the <a href="http://www.sgi.com/tech/stl/">SGI
|
||||
STL Web site</a> from time to time, where you can not only download STL,
|
||||
but also browse in the Programmer's guide for isntance from the <a href="http://www.sgi.com/tech/stl/table_of_contents.html">Table
|
||||
of Content</a>.
|
||||
<p>Anyway, you will only find here, in EO tutorial, the basics of STL that
|
||||
you will need to understand most of EO code - and to guess what the parts
|
||||
you don't understand are actually doing. Don't worry, <b><font color="#FF6600">I
|
||||
</font></b>don't
|
||||
understand everything :-)
|
||||
<p>STL provides the user with <b><font color="#FF6600">container</font></b>s,
|
||||
<b><font color="#FF6600">iterators</font></b>
|
||||
and <b><font color="#FF6600">algorithms</font></b>. And you can access
|
||||
(almost) all containers content using (almost) all iterators, or apply
|
||||
(almost) all algorithms on (almost) all containers (of course the tricky
|
||||
part is to instanciate the "almost" in the previous sentence :-)
|
||||
<p><b><font color="#FF0000">STL: </font><font color="#000099">Containers</font></b>
|
||||
<br>Containers are high level data types used to hold simpler data - the
|
||||
most widely used example of a container is the <b><font color="#FF6600">vector</font></b>
|
||||
construct.
|
||||
<br>The use of STL containers relieve the user from memory management.
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#000099"><font size=+1>vector </font></font></tt></b><font color="#000000">The
|
||||
most widely used container is a one-dimensional array of items.</font></li>
|
||||
|
||||
<br><font color="#000000">Data manipulation: suppose </font><font color="#FF6600">v
|
||||
is an STL </font><b><tt><font color="#993300">vector<AtomType></font></tt></b><font color="#000000">.
|
||||
Then</font>
|
||||
<br><b><tt><font color="#993300">v[i]</font></tt></b><font color="#000000">
|
||||
is the ith element of v, as in standard C arrays</font>
|
||||
<br><b><tt><font color="#993300">v.size()</font></tt></b><font color="#000000">
|
||||
is the number of elements of v</font>
|
||||
<br><b><tt><font color="#993300">v.push_back(atom)</font></tt></b><font color="#000000">
|
||||
appends the </font><b><tt><font color="#993300">atom</font></tt></b><font color="#000000">
|
||||
at end of </font><b><tt><font color="#993300">v</font></tt></b><font color="#000000">,
|
||||
provided of course that </font><b><tt><font color="#993300">atom</font></tt></b><font color="#000000">
|
||||
is of type </font><b><tt><font color="#993300">AtomType</font></tt></b><font color="#000000">,
|
||||
the size is automatically increased...</font>
|
||||
<br><font color="#000000">blabla insert, erase, ...</font>
|
||||
<li>
|
||||
<b><tt><font color="#000099"><font size=+1>list</font></font></tt></b><font color="#000000">
|
||||
STL provides different types of list. The one used in EO is the simple
|
||||
linked list named ... </font><b><tt><font color="#993300">list</font></tt></b><font color="#000000">.
|
||||
As far as the user is concerned, simple lists are very similar to vectors,
|
||||
and the data manipulation listed above for vectors can be applied to list.</font></li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#000099"><font size=+1>pair</font></font></tt></b></li>
|
||||
|
||||
<br><font color="#000000">This simple container allows you to hold two
|
||||
data types together. It is very handy for temporary data handling. Assuming
|
||||
p is a </font><b><tt><font color="#993300">pair<AtomType1, AtomType2></font></tt></b><font color="#000000">,
|
||||
</font><b><tt><font color="#993300">p.first</font></tt></b><font color="#000000">
|
||||
and </font><b><tt><font color="#993300">p.second</font></tt></b><font color="#000000">
|
||||
refer to the encapsulated data, of respective types </font><b><tt><font color="#993300">AtomType1</font></tt></b><font color="#000000">
|
||||
and
|
||||
</font><b><tt><font color="#993300">AtomType2</font></tt></b>
|
||||
<li>
|
||||
<b><tt><font color="#000099"><font size=+1>Blabla</font></font></tt></b></li>
|
||||
</ul>
|
||||
There are many other types of containers that are not used in EO and that
|
||||
we will not present here.
|
||||
<p><b><font color="#FF0000">STL: </font><font color="#000099">Iterators</font></b>
|
||||
<br>Iterators are accessors to the containers contents that provide unified
|
||||
access to different containers. They are very similar to pointers, i.e.
|
||||
you can increment them, compare them with one another, etc
|
||||
<p>Some very useful iterators for vectors and lists are <b><font color="#FF6600">begin()</font></b>
|
||||
and e<b><font color="#FF6600">nd()</font></b>, that refer to the first
|
||||
and after-last items of a container. They allow loops to sweep all items
|
||||
contained in a container as follows:
|
||||
<br><b><tt><font color="#993300">STLcontainer myContain;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">STLcontainer::iterator it;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">for (it=myContain.begin(); it!=myContain.end();
|
||||
it++)</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><tt><font color="#993300">// do what you have to do to
|
||||
<b>(*it)</b>
|
||||
the current item in the container</font></tt>
|
||||
<br><b><tt><font color="#993300">}</font></tt></b>
|
||||
<p><b><font color="#FF0000">STL: </font><font color="#000099">Algorithms</font></b>
|
||||
<br>Algorithms are functions acting on containers - the most widely used
|
||||
example of a STL algorithm are the different <b><font color="#FF6600">sort</font></b>ing
|
||||
algorithms.
|
||||
<ul>
|
||||
<li>
|
||||
<b><tt><font color="#993300">sort, nth_element</font></tt></b>, are sorting
|
||||
algorithms used in EO</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#993300">copy</font></tt></b> is used to copy a range
|
||||
of data designated by iterators</li>
|
||||
|
||||
<li>
|
||||
<b><tt><font color="#993300">apply</font></tt></b> is used to perform the
|
||||
same operation to many items designated by a range of iterators</li>
|
||||
|
||||
<li>
|
||||
Blabla - help wanted thanks...</li>
|
||||
</ul>
|
||||
<b><font color="#FF0000">STL: </font><font color="#000099">Advantages</font></b>
|
||||
<br>The main and <b><font color="#FF6600">huge advantage</font></b> of
|
||||
using STL is that it handles (almost all) memory mangement automatically.
|
||||
You can use any STL container the same way you would use a scalar basic
|
||||
C++ type. And it does it in a (supposededly) optimized way. Of course,
|
||||
the user is also responsible for performances: for instance, the insert()
|
||||
method will take more time for vectors than for linked lists, while on
|
||||
the opposite, the operator[] accessor will be faster for vectors. But both
|
||||
will work anyway.
|
||||
<p><b><font color="#FF0000">STL: </font><font color="#000099">Drawbacks</font></b>
|
||||
<br>The main drawback I see in using STL is that it makes it
|
||||
<b><font color="#FF6600">difficult
|
||||
to use a debugger </font></b>normally: whereas access to data is made simple
|
||||
to the programmer, data structures are actually so complex, and debuggers
|
||||
so willing to display everything that you get lines of template instantiation
|
||||
when asking your debugger what is inside some container! <br>
|
||||
However, here is a trick (thanks to Arnaud Quirin!) to actually print what is inside an STL vector with gdb (but it doesn't really work with complex structures like EO genotypes :-( :<br/>
|
||||
<b><tt>(gdb) <font color="#993300">print (*(&v))[i]<br/>
|
||||
$1 = (const double &) @0x934cad0: 0.69543264131061733<br/></font></tt></b>
|
||||
<!-- For instance I
|
||||
could never visualize some
|
||||
<b><tt><font color="#993300">v[i]</font></tt></b>
|
||||
with <b><tt><font color="#FF6600">gbd</font></tt></b>, <b><tt><font color="#993300">v</font></tt></b>
|
||||
being an STL vector! -->
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="random"></a><b><font color="#000099"><font size=+1>Random
|
||||
numbers</font></font></b>
|
||||
<p>Evolutionary Algorithms make intensive use of random numbers. Random
|
||||
numbers are simulated in computers by using <font color="#FF6600">pseudo-random</font>
|
||||
number generators (RNGs for short), i.e. functions that return series of
|
||||
numbers who look random (w.r.t. some statistical criteria).
|
||||
<p>To make sure the random number generator is as good as possible, and
|
||||
to ensure reproducibility of the results across different platforms, EO
|
||||
has its own RNG, the ``<font color="#FF6600">Mersenne Twister</font>''
|
||||
random number generator MT19937 (thanks to <font color="#FF0000">Takuji
|
||||
Nishimura</font>, see <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/eo_r_n_g_8h-source.html">eoRNG.h</a></font></font>
|
||||
comments).
|
||||
<p>Though you can define and use as many RNGs as you wish in EO, the library
|
||||
also provides you with a global RNG termed <b><tt><font color="#993300">eo::rng</font></tt></b>.
|
||||
Using that single RNG in all calls to random numbers allows one to be able
|
||||
to <b><font color="#FF6600">reproduce a given run</font></b>:
|
||||
<ul>
|
||||
<li>
|
||||
as strange as it seems for a random algorithm, it is mandatory for debugging
|
||||
purposes</li>
|
||||
|
||||
<li>
|
||||
random numbers are computed starting from a seed - starting from the same
|
||||
seed will lead to the same series of pseudo-random numbers, and hence to
|
||||
the same results of the algorithms. All examples in this tutorial will
|
||||
use the RNG seeding procedure, see e.g. in <a href="FirstBitGA.html#random">Lesson1</a>.</li>
|
||||
|
||||
<li>
|
||||
to simulate "true" random runs, you can just seed the RNG with a machine-clock
|
||||
related number, e.g. calling time(0), as done for instance in <a href="SecondBitEA.html#random">Lesson3</a>
|
||||
(and after).</li>
|
||||
</ul>
|
||||
As RNGs produce, by definition, integers that are uniformly distributed
|
||||
between 0 and some maximal number, EO provides you with random numbers
|
||||
following <b><font color="#FF6600">different probability distribution</font></b>
|
||||
(e.g. floating point following <font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_rng.html#a8">normal
|
||||
distribution</a></font></font>). See the <a href="../../doc/html/classeo_rng.html">complete
|
||||
list of RNG primitives</a>.
|
||||
<p>EO also provides <a href="../../doc/html/rnd__generators_8h-source.html">random_generators</a>
|
||||
that can be used in STL call to generate series of random numbers, as in
|
||||
<a href="eoInit.html">eoPop
|
||||
initializers</a>.
|
||||
<p><b><font color="#FF0000">Note</font></b>: the <b><tt><font color="#993300">eo::</font></tt></b>
|
||||
prefix indicates that it is in a separate C++ namespace, to avoid collision
|
||||
with possible variables that would also be named rng in some other library.
|
||||
As early versions of EO (<= 9.1) did not use a separate namespace
|
||||
for rng, the compiler directive using eo::rng in eoRNG.h allows you to
|
||||
use the name rng without the <b><tt><font color="#993300">eo::</font></tt></b>
|
||||
prefix. However, the notation <b><tt><font color="#993300">eo::rng</font></tt></b>
|
||||
should be preferred and might become mandatory some day.
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="notations"></a><b><font color="#000099"><font size=+1>EO conventions
|
||||
and naming style</font></font></b>
|
||||
<p>A few naming conventions should help you to navigate more easily through
|
||||
EO:
|
||||
<ul>
|
||||
<li>
|
||||
The name of local variables should start with a lower case letter. Capital
|
||||
letters should be used rather than underscore to separate words in names
|
||||
(e.g. <b><tt><font color="#FF6600">popSize</font></tt></b> rather than
|
||||
<b><tt><font color="#993300">pop_size</font></tt></b>).</li>
|
||||
|
||||
<li>
|
||||
The name of the arguments to a function should start with an underscore,
|
||||
e.g.</li>
|
||||
|
||||
<br><b><tt> <font color="#993300">void
|
||||
myfunction(unsigned </font><font color="#FF6600">_popSize</font><font color="#993300">){...}</font></tt></b>
|
||||
<li>
|
||||
The initialization parameters of constructors should be named from the
|
||||
names of the variables they are used to initialize, e.g.</li>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<br>
|
||||
<br>
|
||||
<p><b><tt><font color="#993300">class eoMyClass</font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300">public:</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> eoMyClass(unsigned _popSize):</font><font color="#FF6600">popSize(_popSize)</font><font color="#993300">{...}</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> ...</font></tt></b>
|
||||
<br><b><tt><font color="#993300">private:</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> unsigned popSize;</font></tt></b>
|
||||
<br><b><tt><font color="#993300">};</font></tt></b>
|
||||
<li>
|
||||
The names of classes should start with eo + an Uppercase letter (as <b><tt><font color="#993300">eoMyClass</font></tt></b>
|
||||
above).</li>
|
||||
|
||||
<li>
|
||||
The name of the EO template should be EOT. This allows quick understanding
|
||||
of the inheritance diagrams for <a href="#functors">functors</a>. and immediate
|
||||
perception of the arguments and return types of the functors oeprator()
|
||||
method (as in <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_mon_op.html">eoMonOp</a></font></font></b>
|
||||
or <b><font face="Arial,Helvetica"><font size=+1><a href="../../doc/html/classeo_bin_op.html">eoBinOp</a></font></font></b>).</li>
|
||||
|
||||
<br>
|
||||
<li>
|
||||
Blabla</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="memory"></a><b><font color="#000099"><font size=+1>EO memory
|
||||
management</font></font></b>
|
||||
<p>Most of EO constructs are based on the <b><font color="#FF6600">encapsulation</font></b>
|
||||
of objects into other objects, and the embedded objects are passed through
|
||||
the constructor of the embedding object.
|
||||
<br>For instance, the construction of an algorithm requires a breeder (plus
|
||||
many other things of course), the construction of a breeder usually requires
|
||||
a selector, and in turn the construction of a selector requires some parameters.
|
||||
This gives something resembling the following
|
||||
<p><b><tt><font color="#993300">eoTournamentSelection<EOT> select(tSize);</font></tt></b>
|
||||
<br><b><tt><font color="#993300">eoBreeder<EOT> breed(select);</font></tt></b>
|
||||
<br><b><tt><font color="#993300">eoEasyAlgo<EOT> algo( ..., breed, ...);</font></tt></b>
|
||||
<p>Such a practice is no problem when doing <b><font color="#FF6600">everything
|
||||
in a (large!) main function</font></b>: all objects are local to that function,
|
||||
but when the end of the function is also the end of the program. For instance,
|
||||
all programs in <a href="eoLesson1.html">Lesson1</a>, <a href="eoLesson2.html">Lesson2</a>
|
||||
and <a href="eoLesson3.html">Lesson3</a> of this tutorial are built that
|
||||
way.
|
||||
<p>It is however a big problem when you want to outsource some code in
|
||||
other functions: indeed, the above sequence create objects that <b><font color="#FF6600">dissapear</font></b>
|
||||
when exiting the function, and thus cannot be used outside their defining
|
||||
function.
|
||||
<p>The solution is of course to use <b><font color="#FF6600">pointers</font></b>,
|
||||
which gives something like
|
||||
<p><b><tt><font color="#993300">eoTournamentSelection<EOT> *ptSelect
|
||||
= new eoTournamentSelection<EOT>(tSize);</font></tt></b>
|
||||
<br><b><tt><font color="#993300">eoBreeder<EOT> *ptBreed = new eoBreeder<EOT>(*ptSselect);</font></tt></b>
|
||||
<br><b><tt><font color="#993300">eoEasyAlgo<EOT> *ptAlgo = new eoEasyAlgo<EOT>(
|
||||
..., *ptBreed, ...);</font></tt></b>
|
||||
<p>and you can then use the dynamically allocated objects anywhere. But
|
||||
the trouble with such a construct is that after exiting the function where
|
||||
such objects are defined, <b><font color="#FF6600">you will never be able
|
||||
to free</font></b> this allocated memory, should you not need the objects
|
||||
any nore. Whereas this is not in general a big problem (except of being
|
||||
a very bad practice that will make you a very naughty programmer :-), it
|
||||
will prevent any re-entrance of the resulting code, and for instance you
|
||||
will not be able to use an evolutionary algorithm within another loop of
|
||||
some outside code.
|
||||
<p>The solution in EO us to use an <b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_functor_store.html">eoFunctorStore</a></font></font></tt></b>
|
||||
object to store such nowhere-belonging pointers: whenever you allocate
|
||||
such a thing, store it into an eoState : deleting that state will delete
|
||||
all the stored pointers - one eoState is thus the only object you have
|
||||
to care of.
|
||||
<p>The above pointer allocation sequence thus become
|
||||
<p><b><tt><font color="#993300">eoTournamentSelection<EOT> *ptSelect
|
||||
= new eoTournamentSelection<EOT>(tSize);</font></tt></b>
|
||||
<br><b><tt><font color="#993300">state.storeFunctor(ptSelect);</font></tt></b>
|
||||
<br><b><tt><font color="#993300">eoBreeder<EOT> *ptBreed = new eoBreeder<EOT>(*ptSelect);</font></tt></b>
|
||||
<br><b><tt><font color="#993300">state.storeFunctor(ptBreed);</font></tt></b>
|
||||
<br><b><tt><font color="#993300">eoEasyAlgo<EOT> *ptAlgo = new eoEasyAlgo<EOT>(
|
||||
..., *ptBreed, ...);</font></tt></b>
|
||||
<br><b><tt><font color="#993300">state.storeFunctor(ptAlgo);</font></tt></b>
|
||||
<p>or, even more quickly (though less readably)
|
||||
<p><b><tt><font color="#993300">eoTournamentSelection<EOT> *ptSelect
|
||||
=</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
state.storeFunctor(new eoTournamentSelection<EOT>(tSize));</font></tt></b>
|
||||
<br><b><tt><font color="#993300">eoBreeder<EOT> *ptBreed =</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
state.storeFunctor(new eoBreeder<EOT>(*ptSelect));</font></tt></b>
|
||||
<br><b><tt><font color="#993300">eoEasyAlgo<EOT> *ptAlgo =</font></tt></b>
|
||||
<br><b><tt><font color="#993300">
|
||||
state.storeFunctor(new eoEasyAlgo<EOT>( ..., *ptBreed, ...));</font></tt></b>
|
||||
<p>In both the above code, state is an <b><tt><font color="#993300"><font size=+1>eoFunctorStore</font></font></tt></b>
|
||||
that is of course <b><font color="#FF6600">passed from outside the function</font></b>
|
||||
- and it's called state because in most cases it will actually be an eoState.
|
||||
As its name says, an <b><tt><font color="#993300"><font size=+1>eoFunctorStore</font></font></tt></b>
|
||||
can store any object that is an (derives from) <b><tt><font size=+1><a href="../../doc/html/classeo_functor_base.html">eoFunctorBase</a></font></tt></b>
|
||||
- hence all objects in EO that are used as functors should derive from
|
||||
either <a href="#functors">eoF, eoUF or eBF</a>.
|
||||
<p>Examples of such constructs are shown in the make_xxx files described
|
||||
in <a href="eoLesson4.html">Lesson4</a>.
|
||||
<br>
|
||||
<hr WIDTH="100%"><b><font color="#CC0000">Local: </font></b><a href="#templates">Templates</a>
|
||||
-
|
||||
<a href="#functors">Functors</a> -
|
||||
<a href="#STL">STL Library</a> - <a href="#random">Random
|
||||
numbers</a> - <a href="#notations">EO programming style</a> - <a href="#memory">Memory
|
||||
management</a>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><b><font color="#CC0000">General: </font></b><a href="eoTutorial.html">Tutorial
|
||||
main page </a>- <a href="eoTopDown.html">Algorithm-Based</a> - <a href="eoBottomUp.html">Component-Based</a>
|
||||
- <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font>
|
||||
<br>
|
||||
<hr>
|
||||
<br><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a>
|
||||
</body>
|
||||
</html>
|
||||
19
eo/tutorial/html/eoRepresentation.html
Normal file
19
eo/tutorial/html/eoRepresentation.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Representation</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Representation</h1>
|
||||
|
||||
|
||||
|
||||
<hr>
|
||||
<address><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<!-- Created: Mon Oct 30 19:27:59 CET 2000 -->
|
||||
<!-- hhmts start -->
|
||||
Last modified: Mon Oct 30 19:28:01 CET 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
157
eo/tutorial/html/eoSGA.html
Normal file
157
eo/tutorial/html/eoSGA.html
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
<!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>eoSGA.h</title>
|
||||
</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">eoSGA.h</font></h1></center>
|
||||
<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">// eoSGA.h</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><b><tt><font color="#993300">#ifndef _eoSGA_h</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#define _eoSGA_h</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#include <eoOp.h></font></tt></b>
|
||||
<br><b><tt><font color="#993300">#include <eoContinue.h></font></tt></b>
|
||||
<br><b><tt><font color="#993300">#include <eoPop.h></font></tt></b>
|
||||
<br><b><tt><font color="#993300">#include <eoSelectOne.h></font></tt></b>
|
||||
<br><b><tt><font color="#993300">#include <eoSelectPerc.h></font></tt></b>
|
||||
<br><b><tt><font color="#993300">#include <eoEvalFunc.h></font></tt></b>
|
||||
<br><b><tt><font color="#993300">#include <eoAlgo.h></font></tt></b>
|
||||
<br><b><tt><font color="#993300">#include <apply.h></font></tt></b>
|
||||
<br><tt><font color="#993300">/** The Simple Genetic Algorithm, following
|
||||
Holland and Goldberg </font></tt>
|
||||
<br><tt><font color="#993300">* Needs a selector (class eoSelectOne)
|
||||
a crossover (eoQuadratic, </font></tt>
|
||||
<br><tt><font color="#993300">* i.e. a 2->2
|
||||
operator) and a mutation with their respective rates, </font></tt>
|
||||
<br><tt><font color="#993300">* of course
|
||||
an evaluation function (eoEvalFunc) and a continuator </font></tt>
|
||||
<br><tt><font color="#993300">* (eoContinue)
|
||||
which gives the stopping criterion. Performs full</font></tt>
|
||||
<br><tt><font color="#993300">* generational
|
||||
replacement.</font></tt>
|
||||
<br><tt><font color="#993300">*/ </font></tt>
|
||||
<br><b><tt><font color="#993300">template <class EOT></font></tt></b>
|
||||
<br><b><tt><font color="#993300">class eoSGA : public eoAlgo<EOT></font></tt></b>
|
||||
<br><b><tt><font color="#993300">{</font></tt></b>
|
||||
<br><b><tt><font color="#993300">public :</font></tt></b>
|
||||
<br><tt><font color="#993300"><b> </b>// added this second ctor as
|
||||
I didn't like the ordering of the parameters</font></tt>
|
||||
<br><tt><font color="#993300"><b> </b>// in the one above. Any objection
|
||||
:-) MS</font></tt>
|
||||
<br><a NAME="constructor"></a><b><tt><font color="#993300">eoSGA(</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> eoSelectOne<EOT>&
|
||||
_select,</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> eoQuadraticOp<EOT>&
|
||||
_cross, float _crate,</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> eoMonOp<EOT>&
|
||||
_mutate, float _mrate,</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> eoEvalFunc<EOT>&
|
||||
_eval,</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> eoContinue<EOT>&
|
||||
_cont)</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> : cont(_cont), </font></tt></b>
|
||||
<br><b><tt><font color="#993300"> mutate(_mutate), </font></tt></b>
|
||||
<br><b><tt><font color="#993300"> mutationRate(_mrate),</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> cross(_cross),</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> crossoverRate(_crate),</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> select(_select),</font></tt></b>
|
||||
<br><b><tt><font color="#993300"> eval(_eval)
|
||||
{}</font></tt></b></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="generation"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCC99" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#FF6666"> void operator()(eoPop<EOT>&
|
||||
_pop)</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666"> {</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666"> eoPop<EOT> offspring;</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666"> do {</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
select(_pop, offspring);</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
unsigned i;</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
for (i=0; i<_pop.size()/2; i++) </font></tt></b>
|
||||
<br><tt><font color="#FF6666"><b>
|
||||
{ </b>// generates 2 offspring from two parents</font></tt>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
if ( rng.flip(crossoverRate) ) </font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
{ </font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
cross(offspring[2*i], offspring[2*i+1]);</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
}</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
}</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
for (i=0; i < _pop.size(); i++) </font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
{</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
if (rng.flip(mutationRate) ) </font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
{</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
mutate(offspring[i]);</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
}</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
}</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
_pop.swap(offspring);</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">
|
||||
apply<EOT>(eval, _pop);</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666"> } while (cont(_pop));</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666"> }</font></tt></b>
|
||||
<br> </td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="parametres"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCFFFF" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#3366FF">private :</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> eoContinue<EOT>& cont;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> eoMonOp<EOT>& mutate;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> float mutationRate;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> eoQuadraticOp<EOT>& cross;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> float crossoverRate;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> eoSelectPerc<EOT> select;</font></tt></b>
|
||||
<br><b><tt><font color="#3366FF"> eoEvalFunc<EOT>& eval;</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><b><tt><font color="#993300">#endif</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 19:36:21 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
19
eo/tutorial/html/eoSelect.html
Normal file
19
eo/tutorial/html/eoSelect.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Selection</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Selection</h1>
|
||||
|
||||
|
||||
|
||||
<hr>
|
||||
<address><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<!-- Created: Mon Oct 30 17:51:54 CET 2000 -->
|
||||
<!-- hhmts start -->
|
||||
Last modified: Mon Oct 30 17:51:55 CET 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
25
eo/tutorial/html/eoStop.html
Normal file
25
eo/tutorial/html/eoStop.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Input / Output</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Input / Output</h1>
|
||||
|
||||
<p>
|
||||
<A NAME=stop>
|
||||
<h3>Stopping criteria</h3>
|
||||
|
||||
<p>
|
||||
<A NAME=output>
|
||||
<h3>Displaying statistics</h3>
|
||||
|
||||
<hr>
|
||||
<address><a href="mailto:Marc.Schoenauer@inria.fr">Marc Schoenauer</a></address>
|
||||
<!-- Created: Mon Oct 30 19:29:46 CET 2000 -->
|
||||
<!-- hhmts start -->
|
||||
Last modified: Tue Oct 31 18:32:22 CET 2000
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
111
eo/tutorial/html/eoTopDown.html
Normal file
111
eo/tutorial/html/eoTopDown.html
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<!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>EO - The Algorithm-Based approach</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%">
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">EO - The Algorithm-Based approach</font></h1></center>
|
||||
|
||||
<p><br>Congratulations - You have chosen the algorithm-based approach!
|
||||
This means that you want to start from something that already works, and
|
||||
gradually learn about the more complex constructs. We have prepared a series
|
||||
of "lessons" for you.
|
||||
<ul>
|
||||
<li>
|
||||
<a href="eoLesson1.html">Lesson 1 </a>- a gentle introduction to the <font color="#FF6600">EO
|
||||
way</font>: your first steps into <b><font color="#999900">EO representations</font></b>
|
||||
using a simple generational GA. Please, <b><font color="#FF0000">spend
|
||||
the necessary time</font></b> on that one, since all basic constructs presented
|
||||
there are used throughout EO.</li>
|
||||
|
||||
<li>
|
||||
<a href="eoLesson2.html">Lesson 2</a> - <font color="#FF6600">encapsulate</font>,
|
||||
encapsulate, and try more sophisticated <b><font color="#009900">selection/replacement</font></b>
|
||||
mechanisms, as well as <b><font color="#CC33CC">multiple operators</font></b></li>
|
||||
|
||||
<li>
|
||||
<a href="eoLesson3.html">Lesson 3 </a>- The same algorithms, but with <font color="#FF6600">improved
|
||||
input/outputs</font>: <font color="#000000">user-friendly input (i.e. without
|
||||
the need to recompile!</font>) of <b><font color="#3366FF">algorithm parameters</font></b><font color="#000000">,
|
||||
and </font><font color="#FF6600">checkpointing </font>(<b><font color="#3366FF">display</font></b>
|
||||
of on-line <b><font color="#3366FF">statistics</font></b>, <b><font color="#3366FF">save
|
||||
</font></b><font color="#000000">and
|
||||
</font><b><font color="#3366FF">restore</font></b>
|
||||
populations,
|
||||
<b><font color="#3366FF">restart</font></b> stopped runs,
|
||||
...).</li>
|
||||
|
||||
<li>
|
||||
<a href="eoLesson4.html">Lesson 4 </a>- The same algorithms - again! -
|
||||
but now fully operational: <font color="#FF6600">every component</font>
|
||||
of the algorithm can be defined <font color="#FF6600">on the command-line</font>,
|
||||
except the type of genotype; moreover, you now have a full library, i.e.
|
||||
everything except your fitness function is <font color="#FF6600">already
|
||||
compiled.</font></li>
|
||||
|
||||
<li>
|
||||
<a href="eoLesson5.html">Lesson 5</a> <b><blink><font color="#FF6600">(new)</font></blink></b>
|
||||
- Use your own <b><font color="#999900">representation</font></b>. Thanks
|
||||
to <font color="#FF6600">template files and a little script</font> in Unix,
|
||||
or the <font color="#FF6600">Application template</font> in MSVC++, you
|
||||
can easily define a new genotype and run an Evolutionary Algorithm that
|
||||
will intantly benefit from the power of <b><font color="#009900">all EO
|
||||
Evolution Engines</font></b> (including <b><font color="#3366FF">easy user-parameter
|
||||
input </font></b>presented in Lesson 4). You simply need to gradually fill
|
||||
in the shell-files that the script will generate for you.</li>
|
||||
|
||||
|
||||
<p><br>Current version (May. 5, 2002) stops here, but ...
|
||||
<p>From there on, you don't need to follow the lesson order any more: you
|
||||
can go directly to any lesson and experiment. Of course, you will need
|
||||
to bring together the different pieces to write exactly what you want -
|
||||
but only because we had no idea of what you exactly want :-)
|
||||
<ul>
|
||||
<li>
|
||||
Lesson 6 (forthcoming) - More about <b><font color="#3366FF">checkpointing</font></b>:
|
||||
write your first <b><font color="#FF6600">adaptive mechanism</font></b>,
|
||||
and find out how easy it is to <b><font color="#3366FF">update</font></b>
|
||||
and <b><font color="#3366FF">monitor </font><font color="#FF6600">dynamic
|
||||
parameters</font></b></li>
|
||||
|
||||
<li>
|
||||
Lesson 7 - More <b><font color="#CC33CC">general operators</font></b>:
|
||||
e.g. binary, n-ary, or even specific mate selection (your brain and my
|
||||
beauty)! Add your own to the basic algorithm using the template files.</li>
|
||||
|
||||
<li>
|
||||
Lesson 8 - Use predefined generic <b><font color="#999900">representations</font></b>.
|
||||
The <b><font color="#999900">eoFixedLength</font></b> and <b><font color="#999900">eoVariableLength</font></b>
|
||||
super classes allow quick definition of new genotypes that handle identical
|
||||
Atoms, together with generic variation operators.</li>
|
||||
</ul>
|
||||
Of course, in each lesson, you have links to the corresponding Component-Based
|
||||
page. ( ... Well, to tell you the truth, as of today, this is not exactly
|
||||
true :-)
|
||||
<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> - <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: DATE --><!-- hhmts start -->Last modified: Tue Dec 19
|
||||
2000 <!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
286
eo/tutorial/html/eoTutorial.html
Normal file
286
eo/tutorial/html/eoTutorial.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.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]">
|
||||
<title>Tutorial EO</title>
|
||||
</head>
|
||||
<body text="#000000" link="#0000EF" vlink="#51188E" alink="#FF0000" background="beige009.jpg">
|
||||
<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%">
|
||||
<center><b><font color="#FF0000">Welcome to EO, the Evolving Objects library,
|
||||
and to</font></b></center>
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
<font color="#FF0000">EO Tutorial</font></h1></center>
|
||||
|
||||
<center><font color="#FF0000">Important notice - December 2006</font>
|
||||
</center><br>
|
||||
The code that is proposed in this tutorial should <font color="#FF0000"><b>not</b></font>
|
||||
be used
|
||||
as a basis for any comparison with any original method on any benchmark problem.
|
||||
It is an illustration of what you can achieve with EO, but reaching state-of-the-art results
|
||||
requires more work. In particular, if you want to compare your evolutionary
|
||||
algorithm with a good performing algorithm in parameteric optimisation,
|
||||
do <font color="#FF0000"><b>not</b></font>
|
||||
use <font color="#FF6666"><b>ESEA</b></font> in Lesson4,
|
||||
but go to the <font color="#FF6666"><b>test</b></font> directory, type
|
||||
<font color="#FF6600"><b>make t-eoCMAES</b></font> and use the resulting <font
|
||||
color="#FF6666"><b>t-eoCMAES</b></font>. But as of today,
|
||||
the latest algorithms (and comparative results)
|
||||
are better found on <a href="http://www.bionik.tu-berlin.de/user/niko/">Nikolaus Hansen Web page</a>
|
||||
and on his <a href="http://www.bionik.tu-berlin.de/user/niko/cec2005.html">"Comparison of Evolutionary Algorithms on a Benchmark Function Set" page</a>).<br>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<center><font color="#FF0000">Version 0.98a - December 2004</font>
|
||||
</center>
|
||||
|
||||
<ul>
|
||||
<li><b><font color="#FF0000">New</font></b> -
|
||||
Well, in fact, nothing really new,
|
||||
but some people advised us to announce from the very beginning that
|
||||
if you are looking for a <font color="#FF0000"><b>ready-to-use</b></font>
|
||||
(except for the fitness) <font color="#FF0000"><b>fully tunable Evolutionary
|
||||
Algorithm</b></font> evolving real values or bitstring, you can
|
||||
<font color="#FF0000"><b>go directly to</font><font color="#000000">
|
||||
<a href="eoLesson4.html">Lesson 4</a></font></b> after just reading
|
||||
this page, and maybe the <a href="eoProgramming.html">Programming
|
||||
hints</a> (link on top of each page too). <br/>
|
||||
|
||||
In fact, there is something new: EO's automatic configuration and
|
||||
build process has been cleaned up and upgraded. For consistency, the
|
||||
same automatically-built <tt><font
|
||||
color="#FF6666"><b>Makefiles</b></font></tt> have been created in the
|
||||
tutorial directories. The good-old manually-created files are
|
||||
still there, now named
|
||||
<tt><font color="#FF6666"><b>Makefile.simple</b></font></tt>.
|
||||
Moreover, when you compile the whole library (typing <font color="#FF6600"><b>make</b></font> in the main EO dir), all lessons of the tutorial gets compiled, too.
|
||||
</li>
|
||||
<br>
|
||||
|
||||
<center><font color="#FF0000">Version 0.98 - May 2004</font></center>
|
||||
</b>
|
||||
<li><b><font color="#000000"><a href="eoLesson5.html">Lesson 5</a>
|
||||
</font></b><font color="#000000">has been improved: some of
|
||||
the empty template files in dir
|
||||
<b><tt><font color="#FF6666"><b>.../eo/tutorial/Templates</b></font></tt></b>
|
||||
have been simplified, and file <font color="#3366FF"><b>stat.tmpl</b></font>
|
||||
has been added, allowing you to
|
||||
<font color="#FF6600"><b>compute</b></font> and
|
||||
<font color="#FF6600"><b>print</b></font> and
|
||||
<font color="#FF6600"><b>save-to-disk</b></font> and
|
||||
<font color="#FF6600"><b>plot-on-line</b></font> your
|
||||
own <font color="#3366FF"><b>statistics</b></font>.
|
||||
The magic script is now (see Lesson5) <b><tt><font color="#993300">createSimple</font></tt></b>.<br>
|
||||
|
||||
The same simplified main file in
|
||||
dir <b><tt><font
|
||||
color="#FF6666"><b>.../eo/tutorial/Templates</b></font></tt></b>)
|
||||
also allows you to use
|
||||
<font color="#FF6600"><b>fitness sharing</b></font>
|
||||
(together with roulette wheel) as a possible selector.<br>
|
||||
|
||||
Unfortunately, the HTML file for Lesson5 and the corresponding
|
||||
html-ized code are not yet updated - time is missing
|
||||
(volunteers welcome).<br><br>
|
||||
</li>
|
||||
|
||||
<center><font color="#FF0000">May 2002</font></center>
|
||||
<li>
|
||||
<center>
|
||||
<font color="#000000">Thanks to <a href="mailto:paradiseo-help@lists.gforge.inria.fr">Sébastien
|
||||
Cahon</a> (LIFL, Lille)</font></center>
|
||||
|
||||
</ul>
|
||||
<hr WIDTH="100%">
|
||||
<center><b>Welcome to EO tutorial/on-line documentation.</b></center>
|
||||
<hr WIDTH="100%"><b><h2><font color="#000099">About this tutorial</font></b></h2>
|
||||
First, please note that <b><font color="#FF6600">this tutorial is <font color="#FF0000">not</font> supposed
|
||||
to be printed and read off-line</font></b>, as it takes full advantage
|
||||
of hyper-text links between the different parts, and with the technical
|
||||
documentation.
|
||||
This tutorial can be used in 2 different ways: algorithm-based and component-based.
|
||||
<ul>
|
||||
<li>
|
||||
<a href="eoTopDown.html">Algorithm-Based</a> means you start from a <font color="#FF6600">very
|
||||
simple, ready-to-run algorithm,</font> and gradually modify it, making
|
||||
it both more powerful and more complex.</li>
|
||||
|
||||
<li>
|
||||
<a href="eoBottomUp.html">Component-Based</a> means you start by examining
|
||||
the
|
||||
<font color="#FF6600">components of an EA one by one</font>, down to
|
||||
the level of complexity you feel comfortable with, and then build the whole
|
||||
algorithm using those components you need (or the one you are mastering).
|
||||
Such approach might be viewed as going through a simplified user guide,
|
||||
too.</li>
|
||||
</ul>
|
||||
However, it is <b><font color="#FF6600">strongly recommended</font></b>
|
||||
that you take some time on the first lesson of the Algorithm-Based approach
|
||||
to get familiar with the basic concepts that are used throughout EO. Anyway,
|
||||
as of today, December 19, the Component-Based is only very sparsely written
|
||||
:-)
|
||||
<p>
|
||||
<hr WIDTH="100%"><b><font color="#000099"><font size=+2>Links and Related
|
||||
documents</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
There are of course a few (very few) <a href="eoProgramming.html">programming
|
||||
hints</a> that you should know.</li>
|
||||
|
||||
<li>
|
||||
THe <a href="../../doc/html/index.html">EO documentation </a>- automatically
|
||||
generated from the comments in the code - is very helpful to get an idea
|
||||
of the <b><font color="#FF6600">inheritance diagrams</font></b> of EO classes,
|
||||
and to quickly reach some specific part of the code.</li>
|
||||
|
||||
<br>The top page of each class documentation is for instance the inheritance
|
||||
diagram of the class, and you'll learn a lot by simply looking at it.
|
||||
<li>
|
||||
For those who wish to get deeper in STL (Standard Template Library), you
|
||||
might visit the well documented <a href="http://www.sgi.com/Technology/STL/">SGI
|
||||
STL Web site</a>. But don't forget you'll find the very basic minimum in
|
||||
EO <a href="eoProgramming.html#STL">programming hints</a>.</li>
|
||||
|
||||
<li>
|
||||
And, last but not least, we assume you know approximately that an Evolutionary
|
||||
Algorithm looks like this, but otherwise you can try this <a href="eoIntroEA.html">very
|
||||
brief introduction</a> (not written yet, Jan. 2001, sorry).</li>
|
||||
</ul>
|
||||
|
||||
<p><br>
|
||||
<hr WIDTH="100%"><b><font color="#000099"><font size=+2>Colors and navigation:</font></font></b>
|
||||
<p>You will see this diagram in quite many places, as for instance at the
|
||||
top of all examples - usually it will be clickable and will help you navigate
|
||||
among the different parts of an EO program. See the <a href="eoIntroEA.html">brief
|
||||
introduction to Evolutionary Computation</a> for a detailed explanation.
|
||||
<center>
|
||||
<p><img SRC="EA_tutorial.jpg" ></center>
|
||||
<a NAME="colors"></a>
|
||||
<p>But in the text itself, <b><font color="#FF6600">colors are important</font></b>,
|
||||
as they will be used throughout this tutorial to clearly mark which part
|
||||
of the algorithm we are discussing. So please keep in mind that, whereas
|
||||
<b><font color="#FF6600">orange
|
||||
is for emphasis</font></b>,
|
||||
<ul>
|
||||
<li>
|
||||
<b><font color="#999900">Yellowish</font></b> is for <b><font color="#999900">representation</font></b>,
|
||||
i.e. the choice of the <b><font color="#999900">genotype</font></b></li>
|
||||
|
||||
<li>
|
||||
<font color="#CC33CC">Magenta</font> is for the <font color="#CC33CC">stochastic
|
||||
operators</font> that are <b><font color="#999900">representation-dependent</font>,</b>
|
||||
i.e. <font color="#CC33CC">initialisation</font> and variation operators
|
||||
(<font color="#CC33CC">crossover</font>, <font color="#CC33CC">mutation</font>
|
||||
and the like).</li>
|
||||
|
||||
<li>
|
||||
<font color="#009900">Green</font> is for the implementation of <font color="#009900">Darwinism</font>,
|
||||
i.e. the way the individuals are <font color="#009900">selected</font>
|
||||
for reproduction and <font color="#009900">survive.</font></li>
|
||||
|
||||
<li>
|
||||
<font color="#CC0000">Red</font> is for evaluation, i.e. the computation
|
||||
of the <font color="#CC0000">fitness</font> of all individuals</li>
|
||||
|
||||
<li>
|
||||
<font color="#3366FF">Blue</font> is for interactions of the user and the
|
||||
program, as for instance choice of <font color="#3366FF">stopping criterion</font>,
|
||||
on-line display of nice <font color="#3366FF">statistics</font> or initial
|
||||
<font color="#3366FF">choice
|
||||
of all program parameters</font>.</li>
|
||||
|
||||
<li>
|
||||
<font color="#993300">Brown</font> is for everything that is NOT part of
|
||||
any of the above, i.e. random number generator, or basic C++/STL syntax
|
||||
.</li>
|
||||
|
||||
<li>
|
||||
Note that <font color="#FF6666">pink</font> will be used to describe the
|
||||
syntax of compile orders (i.e. at the operating system level, see e.g.
|
||||
<a href="#install">below</a>).</li>
|
||||
|
||||
<li>
|
||||
<b><font face="Arial,Helvetica"><font size=+1>Last, but not least, all
|
||||
links into EO documentation will use the Helvetica typeface, like this
|
||||
line you are now reading.</font></font></b></li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%"><b><font color="#000099"><font size=+1>This tutorial is
|
||||
not</font></font></b>
|
||||
<ul>
|
||||
<li>
|
||||
A course on Evolutionary Computation. You can find such things on the Internet,
|
||||
maybe you can start <a href="http://www.evonet.polytechnique.fr/CIRCUS2/node.php?node=240">here.</a></li>
|
||||
|
||||
<li>
|
||||
An interface that would allow you to build your Evolutionary Programs by
|
||||
a few clicks; such a thing does exist, is called <a href="http://www-rocq.inria.fr/EASEA/">EASEA</a>,
|
||||
and is complementary to this tutorial as it helps the user to build some
|
||||
simple EO programs from simple description. But there are things that EASEA
|
||||
cannot do, and you will have to do it yourself and will need to increase
|
||||
your knowledge about EO for that - hence this tutorial.</li>
|
||||
|
||||
<li>
|
||||
A coffee machine - though you might want to spend some time here when you're
|
||||
tired of everything else, to improve your knowledge of EO slowly and gradually
|
||||
rather than when you have something urgent to code :-)</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%"><a NAME="install"></a><b><font color="#000099"><font size=+1>Before
|
||||
you start</font></font></b>
|
||||
<p>You should of course have downloaded and installed the whole <a href="http://www.sourceforge.net/projects/eodev">EO
|
||||
library</a> (how did you get this file if not???).
|
||||
If you are using a recent version of EO (0.9.3+), all tutorial Lessons
|
||||
should have been compiled when installing the library, and you can now
|
||||
proceed with <a href="eoLesson1.html">Lesson1</a>. <br>
|
||||
<br>Otherwise, we'll assume that you are now in the tutorial directory, and that
|
||||
your prompt looks something like
|
||||
<p><b><tt><font color="#FF6666">(myname@myhost) EOdir/tutorial %</font></tt></b>
|
||||
<p>so you should now type in
|
||||
<p><b><tt><font color="#FF6666">make Lesson1</font></tt></b>
|
||||
<p>and see something like
|
||||
<p><font face="Courier New,Courier"><font color="#000000">(myname@myhost)
|
||||
EOdir/tutorial % make Lesson1</font></font>
|
||||
<br><b><tt><font color="#FF6666">c++ -DPACKAGE=\"eo\" -DVERSION=\"0.9.1\"
|
||||
-I. -I../../src -Wall -g -c FirstBitGA.cpp</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">c++ -Wall -g -o FirstBitGA FirstBitGA.o
|
||||
../../src/libeo.a ../../src/utils/libeoutils.a</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">c++ -DPACKAGE=\"eo\" -DVERSION=\"0.9.1\"
|
||||
-I. -I../../src -Wall -g -c FirstRealGA.cpp</font></tt></b>
|
||||
<br><b><tt><font color="#FF6666">c++ -Wall -g -o FirstRealGA FirstRealGA.o
|
||||
../../src/libeo.a ../../src/utils/libeoutils.a</font></tt></b>
|
||||
<p>and two now executable files should have appeared in the subdirectory
|
||||
Lesson1, namely <b><tt><font color="#990000">FirstBitGA</font></tt></b>
|
||||
and <b><tt><font color="#990000">FirstRealGA</font></tt></b> (see <a href="eoLesson1.html">First
|
||||
lesson</a> to know more about these two ready-to-run programs). If this
|
||||
doesn't work, please go back to the main EO directory and run the installation
|
||||
program.
|
||||
<p>You should also test that you can access the EO documentation in the
|
||||
menu line below: you might not need to go there immediately, but just in
|
||||
case you make rapid progress ... This menu bar should be on all pages of
|
||||
this tutorial, allowing you to navigate easily.
|
||||
<p>Last, but not least: EO is improving only from the good will of
|
||||
contributors. This is also true for this tutorial: If you find anything
|
||||
that you think could be improved, you are welcome to <a href="mailto:Marc.Schoenauer@inria.fr">e-mail
|
||||
me</a>.
|
||||
<center>
|
||||
<p><font color="#000099"><font size=+2>Enjoy!
|
||||
<hr WIDTH="100%"></font></font><a href="eoTopDown.html">Algorithm-Based</a>
|
||||
- <a href="eoBottomUp.html">Component-Based</a> - <a href="eoProgramming.html">Programming
|
||||
hints</a> -<b><font size=+1> <font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO
|
||||
documentation</a></font></font></b></center>
|
||||
|
||||
<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: Wed Feb 22 2006 <!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
160
eo/tutorial/html/make_genotype_OneMax.html
Normal file
160
eo/tutorial/html/make_genotype_OneMax.html
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
<!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>Templates/make_genotype_OneMax.h</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/make_genotype_OneMax.h</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">
|
||||
<b></b>
|
||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-<br>
|
||||
<b></b>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
<b></b>
|
||||
// make_genotype.h<br>
|
||||
<b></b>
|
||||
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001<br>
|
||||
<b></b>
|
||||
/* <br>
|
||||
This library is free software; you can redistribute it and/or<br>
|
||||
modify it under the terms of the GNU Lesser General Public<br>
|
||||
License as published by the Free Software Foundation; either<br>
|
||||
version 2 of the License, or (at your option) any later version.<br>
|
||||
This library is distributed in the hope that it will be useful,<br>
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
|
||||
Lesser General Public License for more details.<br>
|
||||
You should have received a copy of the GNU Lesser General Public<br>
|
||||
License along with this library; if not, write to the Free Software<br>
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA<br>
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es<br>
|
||||
Marc.Schoenauer@inria.fr<br>
|
||||
mkeijzer@dhi.dk<br>
|
||||
*/<br>
|
||||
<b></b>
|
||||
//-----------------------------------------------------------------------------<br>
|
||||
<b>#ifndef _make_genotype_h</b><br>
|
||||
<b>#define _make_genotype_h</b><br>
|
||||
<b>#include <eoOneMax.h></b><br>
|
||||
<b>#include <eoOneMaxInit.h></b><br>
|
||||
<b> </b>
|
||||
// also need the parser and param includes<br>
|
||||
<b>#include <utils/eoParser.h></b><br>
|
||||
<b>#include <utils/eoState.h></b><br>
|
||||
<b></b>
|
||||
/*<br>
|
||||
* This fuction does the create an eoInit<eoOneMax><br>
|
||||
*<br>
|
||||
* It could be here tempatized only on the fitness, as it can be used <br>
|
||||
* to evolve structures with any fitness.<br>
|
||||
* However, for consistency reasons, it was finally chosen, as in <br>
|
||||
* the rest of EO, to templatize by the full EOT, as this eventually <br>
|
||||
* allows to choose the type of genotype at run time (see in es dir)<br>
|
||||
*<br>
|
||||
* It returns an eoInit<EOT> that can later be used to initialize <br>
|
||||
* the population (see make_pop.h).<br>
|
||||
*<br>
|
||||
* It uses a parser (to get user parameters) and a state (to store the memory)<br>
|
||||
* the last argument is to disambiguate the call upon different instanciations.<br>
|
||||
*<br>
|
||||
* WARNING: that last argument will generally be the result of calling <br>
|
||||
* the default ctor of EOT, resulting in most cases in an EOT <br>
|
||||
* that is ***not properly initialized***<br>
|
||||
*/<br>
|
||||
</font></tt>
|
||||
</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>template <class EOT></b><br>
|
||||
<b>eoInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)</b><br>
|
||||
<b>{</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
<b> </b>
|
||||
// read any useful parameter here from the parser <br>
|
||||
<b> </b>
|
||||
// the param itself will belong to the parser (as far as memory is concerned)<br>
|
||||
<b> </b>
|
||||
// paramType & param = _parser.createParam(deafultValue, "Keyword", "Comment to appear in help and status", 'c',"Section of status file").value();<br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
<b> </b>
|
||||
// Then built the initializer - a pointer, stored in the eoState<br>
|
||||
<b> eoInit<EOT>* init = new eoOneMaxInit<EOT> </b>
|
||||
/* ( param ) */ ;<b> ;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
<b> </b>
|
||||
// Eventually by passing the parameters you need<br>
|
||||
<b> // eoInit<EOT>* init = new eoOneMaxInit<EOT> </b>
|
||||
/* ( param ) */ ;<b> ;</b><br>
|
||||
</font></tt>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<tt><font color="#999900">
|
||||
<b> </b>
|
||||
// store in state<br>
|
||||
<b> _state.storeFunctor(init);</b><br>
|
||||
<b> </b>
|
||||
// and return a reference<br>
|
||||
<b> return *init;</b><br>
|
||||
<b>}</b><br>
|
||||
<b>#endif</b><br>
|
||||
</font></font></font></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: Fri May 3 07:10:52 2002
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
351
eo/tutorial/html/make_op_OneMax.html
Normal file
351
eo/tutorial/html/make_op_OneMax.html
Normal file
|
|
@ -0,0 +1,351 @@
|
|||
<!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/make_op_OneMax.h</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/make_op_OneMax.h</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>.
|
||||
<p><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>
|
||||
<p><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">// make_op_OneMax.h</font></tt>
|
||||
<br><tt><font color="#993300">// (c) Marc Schoenauer, Maarten Keijzer and
|
||||
GeNeura Team, 2001</font></tt>
|
||||
<br><tt><font color="#993300">/* </font></tt>
|
||||
<br><tt><font color="#993300"> This library is
|
||||
free software; you can redistribute it and/or</font></tt>
|
||||
<br><tt><font color="#993300"> modify it under
|
||||
the terms of the GNU Lesser General Public</font></tt>
|
||||
<br><tt><font color="#993300"> License as published
|
||||
by the Free Software Foundation; either</font></tt>
|
||||
<br><tt><font color="#993300"> version 2 of the
|
||||
License, or (at your option) any later version.</font></tt>
|
||||
<br><tt><font color="#993300"> This library is
|
||||
distributed in the hope that it will be useful,</font></tt>
|
||||
<br><tt><font color="#993300"> but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of</font></tt>
|
||||
<br><tt><font color="#993300"> MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font></tt>
|
||||
<br><tt><font color="#993300"> Lesser General Public
|
||||
License for more details.</font></tt>
|
||||
<br><tt><font color="#993300"> You should have
|
||||
received a copy of the GNU Lesser General Public</font></tt>
|
||||
<br><tt><font color="#993300"> License along with
|
||||
this library; if not, write to the Free Software</font></tt>
|
||||
<br><tt><font color="#993300"> Foundation, Inc.,
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</font></tt>
|
||||
<br><tt><font color="#993300"> Contact: todos@geneura.ugr.es,
|
||||
http://geneura.ugr.es</font></tt>
|
||||
<br><tt><font color="#993300">
|
||||
Marc.Schoenauer@inria.fr</font></tt>
|
||||
<br><tt><font color="#993300">
|
||||
mkeijzer@dhi.dk</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<p><b><tt><font color="#993300">#ifndef _make_op_OneMax_h</font></tt></b>
|
||||
<br><b><tt><font color="#993300">#define _make_op_OneMax_h</font></tt></b>
|
||||
<p><tt><font color="#993300">// the operators</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <eoOp.h></font></tt></b>
|
||||
<br><b><tt><font color="#993300">#include <eoGenOp.h></font></tt></b>
|
||||
<br><b><tt><font color="#993300">#include <eoCloneOps.h></font></tt></b>
|
||||
<br><b><tt><font color="#993300">#include <eoOpContainer.h></font></tt></b>
|
||||
<br><tt><font color="#993300">// combinations of simple eoOps (eoMonOp
|
||||
and eoQuadOp)</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <eoProportionalCombinedOp.h></font></tt></b>
|
||||
<p><tt><font color="#993300">/** definition of mutation: </font></tt>
|
||||
<br><tt><font color="#993300">* class eoOneMaxMonop MUST derive from eoMonOp<eoOneMax></font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt>
|
||||
<br><b><tt><font color="#993300">#include "eoOneMaxMutation.h"</font></tt></b>
|
||||
<p><tt><font color="#993300">/** definition of crossover (either as eoBinOp
|
||||
(2->1) or eoQuadOp (2->2): </font></tt>
|
||||
<br><tt><font color="#993300">* class eoOneMaxBinCrossover MUST derive
|
||||
from eoBinOp<eoOneMax></font></tt>
|
||||
<br><tt><font color="#993300">* OR </font></tt>
|
||||
<br><tt><font color="#993300">* class eoOneMaxQuadCrossover MUST derive
|
||||
from eoQuadOp<eoOneMax></font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt>
|
||||
<br><tt><font color="#993300">// #include "eoOneMaxBinOp.h"</font></tt>
|
||||
<br><tt><font color="#993300">// OR</font></tt>
|
||||
<br><b><tt><font color="#993300">#include "eoOneMaxQuadCrossover.h"</font></tt></b>
|
||||
<p><tt><font color="#993300"><b> </b> // also need the parser and
|
||||
state includes</font></tt>
|
||||
<br><b><tt><font color="#993300">#include <utils/eoParser.h></font></tt></b>
|
||||
<br><b><tt><font color="#993300">#include <utils/eoState.h></font></tt></b>
|
||||
<p><tt><font color="#993300">/////////////////// variation operators ///////////////</font></tt>
|
||||
<br><tt><font color="#993300">// canonical (crossover + mutation) only
|
||||
at the moment //</font></tt>
|
||||
<p><tt><font color="#993300">/*</font></tt>
|
||||
<br><tt><font color="#993300">* This function builds the operators that
|
||||
will be applied to the eoOneMax</font></tt>
|
||||
<br><tt><font color="#993300">*</font></tt>
|
||||
<br><tt><font color="#993300">* It uses a parser (to get user parameters),
|
||||
a state (to store the memory)</font></tt>
|
||||
<br><tt><font color="#993300">* the last
|
||||
parameter is an eoInit: if some operator needs some info </font></tt>
|
||||
<br><tt><font color="#993300">* about the
|
||||
genotypes, the init has it all (e.g. bounds, ...)</font></tt>
|
||||
<br><tt><font color="#993300">* Simply do </font></tt>
|
||||
<br><tt><font color="#993300">*
|
||||
EOT myEO;</font></tt>
|
||||
<br><tt><font color="#993300">*
|
||||
_init(myEO);</font></tt>
|
||||
<br><tt><font color="#993300">* and myEO
|
||||
is then an ACTUAL object</font></tt>
|
||||
<br><tt><font color="#993300">*</font></tt>
|
||||
<br><tt><font color="#993300">* As usual, the template is the complete
|
||||
EOT even though only the fitness</font></tt>
|
||||
<br><tt><font color="#993300">* is actually templatized here: the following
|
||||
only applies to eoOneMax</font></tt>
|
||||
<br><tt><font color="#993300">*/</font></tt></td>
|
||||
</tr>
|
||||
</table>
|
||||
<a NAME="operators"></a>
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><b><tt><font color="#993399">template <class EOT></font></tt></b>
|
||||
<br><b><tt><font color="#993399">eoGenOp<EOT> & do_make_op(eoParameterLoader&
|
||||
_parser, eoState& _state, eoInit<EOT>& _init)</font></tt></b>
|
||||
<br><b><tt><font color="#993399">{</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b> // this is a temporary version,
|
||||
while Maarten codes the full tree-structured</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // general operator input</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // BTW we must leave that simple
|
||||
version available somehow, as it is the one</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // that 90% people use!</font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> /////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
Variation operators</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> ////////////////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
read crossover and mutations, combine each in a proportional Op</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
and create the eoGenOp that calls crossover at rate pCross </font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
then mutation with rate pMut</font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> // the
|
||||
crossovers</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> /////////////////</font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> // here
|
||||
we can have eoQuadOp (2->2) only - no time for the eoBinOp case</font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> // you
|
||||
can have more than one - combined in a proportional way</font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> // first,
|
||||
define the crossover objects and read their rates from the parser</font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> // A
|
||||
first crossover </font></tt>
|
||||
<br><a NAME="cross_ctor"></a><tt><font color="#993399"><b>
|
||||
eoQuadOp<Indi> *cross = new eoOneMaxQuadCrossover<Indi> </b>/* </font><font color="#FF6666">(varType
|
||||
_anyVariable)</font><font color="#993399"> */;</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
store in the state</font></tt>
|
||||
<br><b><tt><font color="#993399"> _state.storeFunctor(cross);</font></tt></b>
|
||||
<p><tt><font color="#993399"><b> </b> // read its relative rate in
|
||||
the combination</font></tt>
|
||||
<br><b><tt><font color="#993399"> double cross1Rate
|
||||
= _parser.createParam(1.0, "cross1Rate", "Relative rate for crossover 1",
|
||||
'1', "Variation Operators").value();</font></tt></b>
|
||||
<p><tt><font color="#993399"><b> </b> // and create the combined operator
|
||||
with this one</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPropCombinedQuadOp<Indi> *propXover
|
||||
= </font></tt></b>
|
||||
<br><b><tt><font color="#993399"> new eoPropCombinedQuadOp<Indi>(*cross,
|
||||
cross1Rate);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b> // and of course stor it in
|
||||
the state</font></tt>
|
||||
<br><b><tt><font color="#993399"> _state.storeFunctor(propXover);</font></tt></b>
|
||||
<br> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="crossover"></a><tt><font color="#993399"><b> </b>
|
||||
// Optional: A second(and third, and ...) crossover </font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
of course you must create the corresponding classes</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
and all ***MUST*** derive from eoQuadOp<Indi></font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> /* Uncomment if necessary -
|
||||
and replicate as many time as you need</font></tt>
|
||||
<br><tt><font color="#993399">
|
||||
cross = new eoOneMaxSecondCrossover<Indi>(varType _anyVariable); </font></tt>
|
||||
<br><tt><font color="#993399">
|
||||
_state.storeFunctor(cross);</font></tt>
|
||||
<br><tt><font color="#993399">
|
||||
double cross2Rate = _parser.createParam(1.0, "cross2Rate", "Relative rate
|
||||
for crossover 2", '2', "Variation Operators").value(); </font></tt>
|
||||
<br><tt><font color="#993399">
|
||||
propXover.add(*cross, cross2Rate); </font></tt>
|
||||
<br><tt><font color="#993399"> */</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // if you want some gentle
|
||||
output, the last one shoudl be like</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // propXover.add(*cross,
|
||||
crossXXXRate, true);</font></tt>
|
||||
<br> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<br><tt><font color="#993399"><b> </b> // the mutation: same story</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> ////////////////</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // you can have more than one
|
||||
- combined in a proportional way</font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> // for each mutation, </font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // - define the mutator object</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // - read its rate from the
|
||||
parser</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // - add it to the proportional
|
||||
combination</font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> // a first mutation </font></tt>
|
||||
<br><a NAME="mut_ctor"></a><tt><font color="#993399"><b>eoMonOp<Indi>
|
||||
*mut = new eoOneMaxMutation<Indi></b> /* </font><font color="#FF6666">(varType
|
||||
_anyVariable)</font><font color="#993399"> */;</font></tt>
|
||||
<br><b><tt><font color="#993399"> _state.storeFunctor(mut);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b> // its relative rate in the
|
||||
combination</font></tt>
|
||||
<br><b><tt><font color="#993399"> double mut1Rate = _parser.createParam(1.0,
|
||||
"mut1Rate", "Relative rate for mutation 1", '1', "Variation Operators").value();</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b> // and the creation of the
|
||||
combined operator with this one</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoPropCombinedMonOp<Indi> *propMutation
|
||||
= new eoPropCombinedMonOp<Indi>(*mut, mut1Rate);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> _state.storeFunctor(propMutation);</font></tt></b>
|
||||
<br> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td><a NAME="mutation"></a><tt><font color="#993399"><b> </b>
|
||||
// Optional: A second(and third, and ...) mutation with their rates</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
of course you must create the corresponding classes</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
and all ***MUST*** derive from eoMonOp<Indi></font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> /* Uncomment if necessary -
|
||||
and replicate as many time as you need</font></tt>
|
||||
<br><tt><font color="#993399">
|
||||
mut = new eoOneMaxSecondMutation<Indi>(varType _anyVariable);</font></tt>
|
||||
<br><tt><font color="#993399">
|
||||
_state.storeFunctor(mut);</font></tt>
|
||||
<br><tt><font color="#993399">
|
||||
double mut2Rate = _parser.createParam(1.0, "mut2Rate", "Relative rate for
|
||||
mutation 2", '2', "Variation Operators").value(); </font></tt>
|
||||
<br><tt><font color="#993399">
|
||||
propMutation.add(*mut, mut2Rate); </font></tt>
|
||||
<br><tt><font color="#993399"> */</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // if you want some gentle
|
||||
output, the last one shoudl be like</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // propMutation.add(*mut,
|
||||
mutXXXRate, true);</font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> // end of crossover and mutation
|
||||
definitions</font></tt>
|
||||
<br> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
|
||||
<tr>
|
||||
<td>
|
||||
<br><tt><font color="#993399">// from now on, you do not need to modify
|
||||
anything</font></tt>
|
||||
<br><tt><font color="#993399">// though you CAN add things to the checkpointing
|
||||
(see tutorial)</font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> // now build the eoGenOp:</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // to simulate SGA (crossover
|
||||
with proba pCross + mutation with proba pMut</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // we must construct</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
a sequential combination of</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
with proba 1, a proportional combination of </font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
a QuadCopy and our crossover</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
with proba pMut, our mutation</font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> // but of course you're free
|
||||
to use any smart combination you could think of</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // especially, if you have
|
||||
to use eoBinOp rather than eoQuad Op youùll have</font></tt>
|
||||
<br><tt><font color="#993399"><b> </b> // to modify that part</font></tt>
|
||||
<p><a NAME="donottouch"></a><tt><font color="#993399"><b> </b> //
|
||||
First read the individual level parameters</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoValueParam<double>&
|
||||
pCrossParam = _parser.createParam(0.6, "pCross", "Probability of Crossover",
|
||||
'C', "Variation Operators" );</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
minimum check</font></tt>
|
||||
<br><b><tt><font color="#993399"> if ( (pCrossParam.value()
|
||||
< 0) || (pCrossParam.value() > 1) )</font></tt></b>
|
||||
<br><b><tt><font color="#993399">
|
||||
throw runtime_error("Invalid pCross");</font></tt></b>
|
||||
<p><b><tt><font color="#993399"> eoValueParam<double>&
|
||||
pMutParam = _parser.createParam(0.1, "pMut", "Probability of Mutation",
|
||||
'M', "Variation Operators" );</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> </b> //
|
||||
minimum check</font></tt>
|
||||
<br><b><tt><font color="#993399"> if ( (pMutParam.value()
|
||||
< 0) || (pMutParam.value() > 1) )</font></tt></b>
|
||||
<br><b><tt><font color="#993399">
|
||||
throw runtime_error("Invalid pMut");</font></tt></b>
|
||||
<p><tt><font color="#993399"><b> </b> // the crossover - with probability
|
||||
pCross</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoProportionalOp<Indi> * propOp
|
||||
= new eoProportionalOp<Indi> ;</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> _state.storeFunctor(propOp);</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> eoQuadOp<Indi> *ptQuad = new
|
||||
eoQuadCloneOp<Indi>;</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> _state.storeFunctor(ptQuad);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> propOp->add(*propXover, pCrossParam.value());
|
||||
</b>//
|
||||
crossover, with proba pcross</font></tt>
|
||||
<br><tt><font color="#993399"><b> propOp->add(*ptQuad, 1-pCrossParam.value());
|
||||
</b>//
|
||||
nothing, with proba 1-pcross</font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> // now the sequential</font></tt>
|
||||
<br><b><tt><font color="#993399"> eoSequentialOp<Indi> *op = new
|
||||
eoSequentialOp<Indi>;</font></tt></b>
|
||||
<br><b><tt><font color="#993399"> _state.storeFunctor(op);</font></tt></b>
|
||||
<br><tt><font color="#993399"><b> op->add(*propOp, 1.0); </b>// always
|
||||
do combined crossover</font></tt>
|
||||
<br><tt><font color="#993399"><b> op->add(*propMutation, pMutParam.value());
|
||||
</b>//
|
||||
then mutation, with proba pmut</font></tt>
|
||||
<p><tt><font color="#993399"><b> </b> // that's it - return a reference</font></tt>
|
||||
<br><b><tt><font color="#993399"> return *op;</font></tt></b>
|
||||
<br><b><tt><font color="#993399">}</font></tt></b>
|
||||
<p><b><tt><font color="#993399">#endif</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: Fri May
|
||||
3 08:06:20 2002<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
56
eo/tutorial/html/real_value.html
Normal file
56
eo/tutorial/html/real_value.html
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<!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>real_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 size=+1>
|
||||
<font face="Arial,Helvetica"><a href="../../doc/html/index.html">EO documentation</a></font></font></b>
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br><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 <vector></font></tt></b>
|
||||
<br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt>
|
||||
<br><tt><font color="#993300">/** Just a simple function that takes an
|
||||
vector<double> and sets the fitnes </font></tt>
|
||||
<br><tt><font color="#993300"> to the sphere function.
|
||||
Please use doubles not float!!!</font></tt>
|
||||
<br><tt><font color="#993300"> @param _ind A floatingpoint
|
||||
vector </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 real_value(const std::vector<double>&
|
||||
_ind)</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 < _ind.size();
|
||||
i++)</font></tt></b>
|
||||
<br><b><tt><font color="#993399">
|
||||
sum += _ind[i] * _ind[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 08:58:50 2000<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue