From c5e225551ae397fa715efffd3fe2c3b23ee8a427 Mon Sep 17 00:00:00 2001 From: evomarc Date: Wed, 8 May 2002 06:50:58 +0000 Subject: [PATCH] Adding the Lesson5 - how to create your own genotype --- eo/tutorial/html/OneMaxEA.html | 360 ++++++++++++++++++ eo/tutorial/html/SecondRealEA.html | 2 +- eo/tutorial/html/eoEngine.html | 164 +++++++-- eo/tutorial/html/eoLesson2.html | 10 +- eo/tutorial/html/eoLesson5.html | 388 ++++++++++++++++++++ eo/tutorial/html/eoOneMax.html | 209 +++++++++++ eo/tutorial/html/eoOneMaxEvalFunc.html | 160 ++++++++ eo/tutorial/html/eoOneMaxInit.html | 153 ++++++++ eo/tutorial/html/eoOneMaxMutation.html | 168 +++++++++ eo/tutorial/html/eoOneMaxQuadCrossover.html | 168 +++++++++ eo/tutorial/html/eoOneMax_complete.html | 192 ++++++++++ eo/tutorial/html/eoTopDown.html | 63 ++-- eo/tutorial/html/make_genotype_OneMax.html | 160 ++++++++ eo/tutorial/html/make_op_OneMax.html | 351 ++++++++++++++++++ 14 files changed, 2476 insertions(+), 72 deletions(-) create mode 100644 eo/tutorial/html/OneMaxEA.html create mode 100644 eo/tutorial/html/eoLesson5.html create mode 100644 eo/tutorial/html/eoOneMax.html create mode 100644 eo/tutorial/html/eoOneMaxEvalFunc.html create mode 100644 eo/tutorial/html/eoOneMaxInit.html create mode 100644 eo/tutorial/html/eoOneMaxMutation.html create mode 100644 eo/tutorial/html/eoOneMaxQuadCrossover.html create mode 100644 eo/tutorial/html/eoOneMax_complete.html create mode 100644 eo/tutorial/html/make_genotype_OneMax.html create mode 100644 eo/tutorial/html/make_op_OneMax.html diff --git a/eo/tutorial/html/OneMaxEA.html b/eo/tutorial/html/OneMaxEA.html new file mode 100644 index 000000000..47102a452 --- /dev/null +++ b/eo/tutorial/html/OneMaxEA.html @@ -0,0 +1,360 @@ + + + + + + Templates/OneMaxEA.cpp + + +Back to Lesson 5 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
+
+
+

+Templates/OneMaxEA.cpp

+The places where you have to put some code are on pink +background.. Only the the character +colors have the usual meaning. +
+ + + + +
/** -*- mode: c++; c-indent-level: +4; c++-member-init-indent: 8; comment-column: 35; -*- +
The above line is usefulin Emacs-like editors +
*/ +
/* +
Template for creating a new representation +in EO +
================================================ +
This is the template main file. +
It includes all other files that have been +generated by the script create.sh +
so it is the only file to compile. +
In case you want to build up a separate library +for your new Evolving Object, +
you'll need some work - follow what's done +in the src/ga dir, used in the +
main file BitEA in tutorial/Lesson4 dir. +
Or you can wait until we do it :-) +
*/ +
// Miscilaneous include and declaration  +
#include <iostream> +
using namespace std; +
// eo general include +
#include "eo" +
// the real bounds (not yet in general eo +include) +
#include "utils/eoRealVectorBounds.h" +
// include here whatever specific files for +your representation +
// Basically, this should include at least +the following +
/** definition of representation:  +
* class eoOneMax MUST derive from EO<FitT> +for some fitness +
*/
+ + + + + +
#include "eoOneMax.h" +
/** definition of initilizqtion:  +
* class eoOneMaxInit MUST derive from eoInit<eoOneMax> +
*/
+ + + + + +
#include "eoOneMaxInit.h" +
/** definition of evaluation:  +
* class eoOneMaxEvalFunc MUST derive from +eoEvalFunc<eoOneMax> +
* and should test for validity before doing +any computation +
* see tutorial/Templates/evalFunc.tmpl +
*/
+ + + + + +
#include "eoOneMaxEvalFunc.h" +
// GENOTYPE    eoOneMax ***MUST*** +be templatized over the fitness
+ + + + + +
// START fitness type: double or eoMaximizingFitness +if you are maximizing +
//                                        +eoMinimizingFitness if you are minimizing +
typedef eoMinimizingFitness MyFitT ; // +type of fitness  +
// END fitness type
+ + + + + +
+ + + + + +
// Then define your EO objects using that +fitness type +
typedef eoOneMax<MyFitT> Indi;           +// ***MUST*** derive from EO 
+ + + + + +
// create an initializer +
#include "make_genotype_OneMax.h" +
eoInit<Indi> & make_genotype(eoParser& +_parser, eoState&_state, Indi _eo) +
{ +
 return do_make_genotype(_parser, +_state, _eo); +
+ + + + + +
// and the variation operaotrs +
#include "make_op_OneMax.h" +
eoGenOp<Indi>&  make_op(eoParser& +_parser, eoState& _state, eoInit<Indi>& _init) +
{ +
 return do_make_op(_parser, _state, +_init); +
}
+ + + + + +
// Use existing modules to define representation +independent routines +
// These are parser-based definitions of +objects +
// how to initialize the population  +
// it IS representation independent if an +eoInit is given +
#include <do/make_pop.h> +
eoPop<Indi >&  make_pop(eoParser& +_parser, eoState& _state, eoInit<Indi> & _init) +
{ +
 return do_make_pop(_parser, _state, +_init); +
}
+ + + + + +
// the stopping criterion +
#include <do/make_continue.h> +
eoContinue<Indi>& make_continue(eoParser& +_parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval) +
{ +
 return do_make_continue(_parser, +_state, _eval); +
}
+ + + + + +
// outputs (stats, population dumps, ...) +
#include <do/make_checkpoint.h> +
eoCheckPoint<Indi>& make_checkpoint(eoParser& +_parser, eoState& _state, eoEvalFuncCounter<Indi>& _eval, eoContinue<Indi>& +_continue)  +
{ +
 return do_make_checkpoint(_parser, +_state, _eval, _continue); +
}
+ + + + + +
// evolution engine (selection and replacement) +
#include <do/make_algo_scalar.h> +
eoAlgo<Indi>&  make_algo_scalar(eoParser& +_parser, eoState& _state, eoEvalFunc<Indi>& _eval, eoContinue<Indi>& +_continue, eoGenOp<Indi>& _op) +
{ +
 return do_make_algo_scalar(_parser, +_state, _eval, _continue, _op); +
}
+ + + + + +
// simple call to the algo. stays there for +consistency reasons  +
// no template for that one +
#include <do/make_run.h> +
// the instanciating fitnesses +
#include <eoScalarFitness.h> +
void run_ea(eoAlgo<Indi>& _ga, +eoPop<Indi>& _pop) +
{ +
 do_run(_ga, _pop); +
} +
// checks for help demand, and writes the +status file +
// and make_help; in libutils +
void make_help(eoParser & _parser); +
// now use all of the above, + representation +dependent things +
int main(int argc, char* argv[]) +
{ +
 try +
 { +
 eoParser parser(argc, argv);   +// for user-parameter reading +
 eoState state;       +// keeps all things allocated
+ + + + + +
      // +The fitness +
      ////////////// +
   eoOneMaxEvalFunc<Indi> +plainEval /* (varType  _anyVariable) */;; +
    // turn that object +into an evaluation counter +
   eoEvalFuncCounter<Indi> +eval(plainEval);
+ + + + + +
  // the genotype - through a +genotype initializer +
 eoInit<Indi>& init = make_genotype(parser, +state, Indi());
+ + + + + +
  // Build the variation operator +(any seq/prop construct) +
 eoGenOp<Indi>& op = make_op(parser, +state, init); +
  //// Now the representation-independent +things  +
  // +
  // YOU SHOULD NOT NEED TO MODIFY +ANYTHING BEYOND THIS POINT +
  // unless you want to add specific +statistics to the checkpoint +
  //////////////////////////////////////////////
+ + + + + +
  // initialize the population +
  // yes, this is representation +indepedent once you have an eoInit +
 eoPop<Indi>& pop    += make_pop(parser, state, init);
+ + + + + +
  // stopping criteria +
 eoContinue<Indi> & term = +make_continue(parser, state, eval);
+ + + + + +
  // output +
 eoCheckPoint<Indi> & checkpoint += make_checkpoint(parser, state, eval, term);
+ + + + + +
  // algorithm (need the operator!) +
 eoAlgo<Indi>& ga = make_algo_scalar(parser, +state, eval, checkpoint, op); +
  ///// End of construction of +the algorithm +
  ///////////////////////////////////////// +
  // to be called AFTER all parameters +have been read!!! +
 make_help(parser); +
  //// GO +
  ///////
+ + + + + +
  // evaluate intial population +AFTER help and status in case it takes time +
 apply<Indi>(eval, pop); +
  // if you want to print it +out +
//    cout << "Initial +Population\n"; +
//    pop.sortedPrintOn(cout); +
//    cout << endl;
+ + + + + +
 run_ea(ga, pop); // run the +ga +
 cout << "Final Population\n"; +
 pop.sortedPrintOn(cout); +
 cout << endl; +
 } +
 catch(exception& e) +
 { +
     cout << +e.what() << endl; +
 } +
 return 0; +
}
+ +
Back to Lesson 5 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
+
+Marc Schoenauer
+ +
Last modified: Sat May +4 07:37:41 2002 + + diff --git a/eo/tutorial/html/SecondRealEA.html b/eo/tutorial/html/SecondRealEA.html index 551faec90..7882e7bad 100644 --- a/eo/tutorial/html/SecondRealEA.html +++ b/eo/tutorial/html/SecondRealEA.html @@ -460,7 +460,7 @@ page - Programming hints - Marc Schoenauer +Marc Schoenauer
Last modified: Sun Apr 28 06:42:44 2002 diff --git a/eo/tutorial/html/eoEngine.html b/eo/tutorial/html/eoEngine.html index d44a90c6f..367c94177 100644 --- a/eo/tutorial/html/eoEngine.html +++ b/eo/tutorial/html/eoEngine.html @@ -12,9 +12,9 @@ hints - Local: Introduction  - Selection - Replacement -- Popular evolution engines - Tournaments -- Merge - Reduce - HowMany -- SurviveAndDie +- General Replacement - Popular +evolution engines - Tournaments - Merge +- Reduce - HowMany - SurviveAndDie

@@ -314,6 +314,8 @@ the  that uses a deterministic MergeReduce.
 

  +
  +
 

Note: The basic use (and initial motivation) for eoSurviveAndDie takes 2 arguments, an eoMergeReduce and a number of surviving parents. @@ -350,11 +352,81 @@ above replacement procedures within a very simple and easy-to-monitor Dummy EO class.


+
General +Replacement: eoReduceMergeReduce +

In an attempt to unify all the well-known replacements, plus most of +the less-known-though-often-used, the eoReduceMergeReduce +replacement has been designed, and supersedes all of the above instances. +
It allows to implement strong elistism +(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). +

Basically, an eoReduceMergeReduce +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. +
The following image, taken from the graphical interface of EASEA, somehow +demonstrates the different parameters of an eoReduceMergeReduce. +
+


+
eoReduceMergeReduce: The  +interface +
Of course the interface is that of eoReplacement. Let's concentrate +on the constructor. +

The constructor takes 6 arguments: +

    +
  1. +eoHowMany elite determines +the number of parents to be treated as elite (actual behavior determined +by next parameter) using the eoHowMany behavior.
  2. + +
  3. +bool strongElitism tells whether +the elite above corresponds to strong (true) or false(weak) elitism.
  4. + +
    Note: the case of no elitism is +obtained by setting elite to 0 +
  5. +eoHowMany reducedParents gives +the number of parents remaining after reducing them
  6. + +
    Note: 0 means that no parent survive +(except the possible elite), as in eoCommaReplacement +
                +-1 is used inside eoSSGAReplacements +(one parent is killed to make room for the newborn) +
  7. +eoReduce<EOT> & reduceParents +indicates how the parents will be reduced (see available +instances).
  8. + +
  9. +eoHowMany reducedOffspring gives +the number of offspring remaining after reducing them
  10. + +
    Note: 0 is impossible (no evolution!!!) +
  11. +eoReduce<EOT> & reduceOffspring +indicates how the offspring will be reduced (see available +instances).
  12. + +
  13. +eoReduce<EOT> & reduceFinal +indicates how the merged reduced-parents/reduced-offspring will be reduced +(see available instances).
  14. + +
    Note: the number of individuals +remaining after that reduction is of course the original size of the population.
+All popular evolution engines use some replacement procedure that can be +viewed as an instance of an eoReduceMergeReduce. +
Moreover, a parser-based input +of a general  is proposed in file do/make_checkpoint.h. +
+

Popular evolution engines -

This section will be completed soon - in the meantime just trust us -that all of these are already implemented in EO (except maybe some of the -last category :-) !!!!!!

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 @@ -372,10 +444,10 @@ a positive scalar fitness, ranking or tournament (stochatic or deterministic) in all cases.
Replacement: Generational.
Remark: You could -use also the Comma replacement, with exactly the same result as there are -as many offspring as we need indiviudals in the next population. And using -the eoSSGAWorseReplacement would also give the same result, but would be -very inefficient! +use also the eoCommaReplacement, +with exactly the same result as there are as many offspring as we need +indiviudals in the next population. And using the eoSSGAWorseReplacement +would also give the same result, but would be very inefficient!
You can also add weak elitism to preserve the best individual.

  • @@ -461,7 +533,7 @@ is implemented in the eoDetTournamentSelect< class, a sub-class of eoSelectOne, as well as in the eoDetTournamentTruncate class that repeatidly removes from the population the "winner" of the inverse tournament.  These objects use the C++ function determinitic_tournament -in  selectors.h.
  • +in  selectors.h.
  • Stochastic Tournament @@ -471,7 +543,7 @@ parameter R should be in [0.5,1]. It is implemented in the eoStochTournamentTruncate class that repeatidly removes from the population the "winner" of the inverse tournament.  These objects use the C++ function determinitic_tournament -in  selectors.h.
  • +in  selectors.h.
    Note: A stochastic tournament with rate 1.0 is strictly identical to a deterministic tournament of size 2. @@ -592,21 +664,29 @@ as parameter in the constructor (default is 0.75).
    eoHowMany: Choosing a number of individuals

    Many classes in selection/replacement procedures will handle a number -of individuals that may either be fixed or be a fraction of some argument-population +of individuals that may either be fixed or be related to some argument-population size. -
    Of course, it is possible to write two 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 eoSelectPerc +
    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 eoSelectPerc and eoSelectNumber (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). -
    However, rather than multiply the number of class, EO has defined a -class that will handle the problem once and for all, the class eoHowMany. -It receives a double, and -a boolean indicating whether -that double is to be treated as a rate -or as an absolute (unisgned) interger. -
    +
    However, the class eoHowMany +allows one to handle in a single class three different behaviors when given +a poopulatio size as argument: +

      +
    • +return a given rate of the argument population size
    • + +
    • +return an absolute (unsigned) integer, whatever the argument population +size
    • + +
    • +return the argument population size minus a given number
    • +
    +

    eoHowMany: interface
    The class interface for its operator() @@ -618,16 +698,34 @@ is as you see there that eoHowMany derives from
    class eoUF<unsigned int, unsigned int>. -

    Its constructor takes 2 argumenrts: -

    -

    eoHowMany(double _rate, bool _interpret_as_rate -= true)

    -so by default the double is indeed interpreted as a rate. -

    It is used in eoSelectMany (which supersedes +

    It has 3 possible constructors, that determine its behavior: +

      +
    • +eoHowMany(double _rate, bool _interpret_as_rate += true) where _rate +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
    • + +
    • +eoHowMany(int _combien): if +_combien +is positive, it is the absolute number of behavior 2 above, and if _combien +is negative, its absolute value is used to decrease the argument population +in behavior 3 above
    • + +
    • +eoHowMany(unsigned int _combien): +_combien +(positive!)  is the absolute number of behavior 2 above. Note +that this constructor is mandatory to avoid ambiguity, as an unsigned int +can be casted to either an int or a double.
    • +
    +It is used in eoSelectMany (which supersedes eoSelectPerc and eoSelectNumber, but they are left there for tutorial reasons!) as well as in many truncation -methods. +methods, and it is used a lot in the eoGeneralReplacement construct.



    Survive and @@ -661,9 +759,9 @@ should be erased from the source.


    Local: Introduction  - Selection - Replacement -- Popular evolution engines - Tournaments -- Merge - Reduce - HowMany -- SurviveAndDie +- General Replacement - Popular +evolution engines - Tournaments - Merge +- Reduce - HowMany - SurviveAndDie


    General: Algorithm-Based diff --git a/eo/tutorial/html/eoLesson2.html b/eo/tutorial/html/eoLesson2.html index 9d270b50c..6b3cf4580 100644 --- a/eo/tutorial/html/eoLesson2.html +++ b/eo/tutorial/html/eoLesson2.html @@ -2,7 +2,7 @@ - + Tutorial: Lesson 2 @@ -69,8 +69,6 @@ object that is a sub-class of the corresponding STL vector class.

     

      -
      -
     

    Note: Also, a non-templatized fitness can be compiled separately (not done here) into an object @@ -88,8 +86,6 @@ requires.
     

      -
      -
     

    Note: In the previous files (Bit - Real) , the last 2 types were deduced from the first (2nd argument = fitness @@ -115,8 +111,6 @@ call to pop.append() function
     

      -
      -
     

    Note: Don't forget to evaluate the population: the eoPop has no idea of the eval function, so it has to be done from outside!!! @@ -130,7 +124,7 @@ mutation operatorsin the same algorithm, choosing among them according to relative -rates. The +weights. The class eoPropCombinedxxxOp, where xxx is either Mon (for mutations, of class eoMonOp) diff --git a/eo/tutorial/html/eoLesson5.html b/eo/tutorial/html/eoLesson5.html new file mode 100644 index 000000000..1bd4b1eca --- /dev/null +++ b/eo/tutorial/html/eoLesson5.html @@ -0,0 +1,388 @@ + + + + + + Tutorial: Lesson 5 + + +Lesson 4 - +Lesson +6 - +Main page - +Algorithm-Based +- Component-Based - Hints +- EO +documentation +
    +


    +
    +

    +Tutorial Lesson 5: using your own genotype

    +In this lesson, you will learn how to design and evolve your +own genotype structure. 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 :-) +

    The minimum code you'll have to write is first, of course, the code +for the genotype structure. Then, the representation-dependent +code: intialization procedure(s), +variation +operators (quadratic crossover, mutation operator), ... and evaluation +function - 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. +

    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. +
    The examples will be described supposing you want to evolve ... bitstings +to solve the OneMax problem (oh no!!!). +

    +


    Using +template files +
    Follow this very simple procedure: +
      +
    • +choose a name for you application - +here OneMax will be used
    • + +
    • +go to the tutorial/Templates +dir
    • + +
             cd +pathWhereEOisInstalled/tutorial/Templates +
    • +run the create.sh script with +argument OneMax and second optional argument  a directory name (suppose +it's called APPLICATION here)
    • + +
                +./create.sh OneMax APPLICATION +
      This will create a directory tutorial/APPLICATION +
    • +Go to the APPLICATION directory
    • + +
                +cd ../APPLICATION +
      You should see the following files: +
          OneMaxEA.cpp           +the main main file, includes all other, to be compiled +
          Makefile               +with default target eoOneMaxEA +
          eoOneMax.h             +class eoOneMax, the genotype +
          eoOneMaxEvalFunc.h     + +class for the computation of fitness +
          eoOneMaxInit.h         +class for genotype initlialization +
          eoOneMaxMutation.h     +class for mutation +
          eoOneMaxQuadCrossover.h +class +for (quadratic) crossover +
          make_genotype_OneMax.h + +helper function that create the initializer +
          make_op_OneMax.h       +helper function that handles the rates of application of +the variation operators
      +    OneMaxLibEA.cpp        +another main file, for separate compilation of representation-independent +stuff +
          make_OneMaxEA.cpp      +the source for the representation-independent stuff +
        +
    • +Compile the whole application
    • + +
               +make +
      and you should have no error there and see a new executable file named +OneMaxEA. +You can run it and ... it will do nothing (what did you expect???).
      +
      +
    • +Now you should go and edit the files. The minimal  changes that you +will need are
    • + +
         in eoOneMax.h               +define your genotype +
         in eoOneMaxInit.h           +define the initialization of one genotype +
         in eoOneMaxMutation.h       + +define the mutation of one genotype +
         in eoOneMaxQuadCrossover.h  + +define the crossover of 2 genotypes
    +Smooth application building: +
      +
    • +After editing a particular file, compile +the whole thing immediately (by running make) and +run the algorithm, to validate your code
    • + +
    • +In each file, start by only adding code between keyword-pairs START +and END
    • +
    +We shall now take a look in turn at the 4 files mentionned above, then +describe rapidly the other files, especially the main files. +
    +
    Genotype +- and its pre-requisites: eoOneMax.h +

    First thing is to write the code for the structure +of the genotype. This is done by filling in the template file +eoOneMax.h. +There are 4 places that you should consider filling in: +

      +
    • +Of course, the data 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.
    • + +
    • +The default constructor of an instance. +Note that you must provide a default constructor, +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.
    • + +
    • +The printOn method, that writes the object +to a stream. You must +call the EO::printOn method that will take care of the fitness, +and then write the specific code for your data structure.
    • + +
    • +The readFrom method, that will read an +object from a stream. Again, you should call the +EO::readFrom method first to take care of the fitness.
    • + +
      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...
    +You can of course also add a destructor +if needed, and any other helper method. For instance, you will probably +consider adding accessors and setters +for the private data - unless you prefer to make everything public :-( +
    See now an example of a comple eoOneMax.h +file. Note that this is the only "colored" completed file we will show, +you will have to go to the .../tutorial/OneMax +dir to browse all files at once. +
    +
    Initialization: +

    Initializer: eoOneMaxInit.h +
    You must provide an eoInit +object for your genotype, that is an object that will randomize +a genotype built by the default constructor of the EO class +(here, an eoOneMax object) . Here you must at least fill the +code for such randomization. +
    But you might also need some parameters (e.g. the size of the bitstring +in eoOneMax): you should then pass +them through the constructor of the eoOneMaxInit class, and store +it in its private data. +
    And of course you might need to add a destructor (no example here) +if you use complex data type in the object. +

    Parameters: make_genotype_OneMax.h +
    There is another file you will probably want to modify as far as initialization +is concerned, that is make_genotype_OneMax.h. +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 make_genotype_OneMax.h +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 initialize the whole +population in a representation-independent way. +
    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... +
    Note: 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 ( +
    +


    Evaluation: +eoOneMaxEvalFunc.h +

    The eoOneMaxEvalFunc is +the object that will compute the fitness of an +eoOneMax object. You have to fill in the code +for the computation of the fitness value (there is no way that this +can be done automatically :-) Note that this code must  be run only +if the _eo.invalid() 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 fitness(FitnessType) +method. +
    Should you need some specific data for that, the constructor +of the object is the place to get such data, and you should, again, +store it in some private data +of the class. +
    +


    Variation +Operators +
    You can write as many crossover and mutation operators as you like. +However, we only provide the template files for quadratic +crossover and mutation, but +you could then easily write the equivalent code for binary crossover, or +general variation operator. +

    Crossover: eoOneMaxQuadCrossover.h +
    As usual, you must go and write the code +for the operator() that will perform the crossover, possibly modifying +both arguments. Don't forget to update the boolean +parameter 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 parameters +to the crossover by passing +them to the constructor, ans storing them in the private +data of the crossover object. +

    Mutation: eoOneMaxMutation.h +
    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 update the boolean parameter 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 parameters to the mutation +by passing them to the constructor, +ans storing them in the private data +of the mutation object. +

    Parameters: make_op_OneMax.h +
    First of all, if you intend to use only one +crossover operator and one mutation +operator, you have nothing to modify +in make_op_OneMax function, except maybe +reading user-defined parameters (copy the code from make_genotype_OneMax) +and passing them to the appropriate +operator constructor. +
    As it is written now, it allows you enter a crossover probability Pcross +and a mutation probability Pmut, +and to build an eoGeneralOp that will call in sequence the eoOneMaxQuadCrossover +that is defined above with probability Pcross +and the eoOneMaxMutation also +defined above with probability Pmut.  +Beware that all allocated objects must be stored in the eoState otherwise +you will run into trouble (see EO Memory +Management explanations). +

    However, everything is there (commented out) to allow you to use more +than one crossover and one mutation +- provided you write the code for them , of course. +

    The code starts by defining an eoOneMaxQuadCrossoverobject, +then reads some application rate that is totally useless if you have only +one crossover, then creates an eoPropCombinedQuadOp +with this simple oeprator. The same story repeats for the mutation. Finally, +the eoGeneralOp +is created from those combined operators and the individulal level probabilities +Pcross +and  Pmut. +

    In order to add a second crossover operator for instance (called eoOneMaxSecondCrossover +in the commented code) all you need to is +

      +
    • +Create the code for the new class  eoOneMaxSecondCrossover: +simply copy the eoOneMaxQuadCrossover.h +file into eoOneMaxSecondCrossover.h  +and change all names eoOneMaxQuadCrossover +to  eoOneMaxSecondCrossover (inlcluding +after the #ifdef statement!!!);
    • + +
    • +Uncomment the corresponding lines +in make_op_OneMax.h, possibly adding user-defined parameter reading
    • + +
    • +Repeat as many times as you have operators, using of course different names! +The same recommendations hold for mutations.
    • +
    +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. +

    +


    Main +files: OneMaxEA.cpp +and OneMaxLibEA.cpp +

    As a start, you should only (eventually) modify in OneMaxEA.cpp +the type of fitness you +will be handling, namely double +if you are maximizing, or eoMinimizingFitness +if you are minimizing. Then running +make will result in a perfectly +valid executable named OneMaxEA. +

    The skeleton of the main file here mimics that of the main file in +Lesson4, +and uses the make_xxx separate +files construct: the part of an Evolutionary Algorithm related to the +evolution +engine is indepenent of the representation, +and can be directly used ... provided it is compiled with the right template +(remember everything in EO is templatized +over the EO objects it handles.  Main file OneMaxEA.cpp +is written so that it includes eveything - and thus everytime you run make +(or make OneMaxEA), you compile +the code for make_pop, make_continue and make_checkpoint that is defined +in the .../src/do directory. +

    The basic construct is (for instance to build the evolution engine) +
      + + + + +
    #include <do/make_algo_scalar.h> +
    eoAlgo<Indi>&  make_algo_scalar(eoParser& +_parser, eoState& _state, eoEvalFunc<Indi>& _eval, eoContinue<Indi>& +_continue, eoGenOp<Indi>& _op) +
    { +
     return do_make_algo_scalar(_parser, +_state, _eval, _continue, _op); +
    }
    +First, include the code (from the do directory). Then define the make_xxx +function from the do_make_xxx function. +
    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 Lesson4) so we have kept it here for +consistency reasons. +

    Go in your application directory, and look at the differences between +both files and you'll see how this is handled in both cases. +

    Reducing compilation time: +
    However, we also provide another main file (OneMaxLibEA.cpp)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 (make_OneMax.cpp).  +This is done by running make OneMaxLibEA +on the command-line. +
    For example, on a PentiumIII 400MHz with g++ 2.96, compiling OneMaxEA +takes about 33s, compiling both make_OneMax.o +and OneMaxLibEA takes about +54s but compiling only OneMaxLibEA +takes only 14s  make_OneMax.o +is up-to-date ... +

    Hints: +
    While developping the genotype structure itself in file eoOneMax.h, +you should use the OneMaxEA.cpp +file. But after the eoOneMax.h +file is frozen, you should use the eoOneMaxLibEA.cpp +file. Of course, both  resulting programs are strictly identical! +

    +


    Lesson +4 - +Lesson 6 - +Main +page - +Algorithm-Based - Component-Based +- Hints - EO +documentation +
    +
    +
    +Marc Schoenauer
    + + + diff --git a/eo/tutorial/html/eoOneMax.html b/eo/tutorial/html/eoOneMax.html new file mode 100644 index 000000000..8f8cfb03e --- /dev/null +++ b/eo/tutorial/html/eoOneMax.html @@ -0,0 +1,209 @@ + + + + + + Templates/eoOneMax.h + + +Back to Lesson 5 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
    +
    +
    +

    +Templates/eoOneMax.h

    +The places where you have to put some code are on pink +background.. Only the the character +colors have the usual meaning. +
    + + + + +
    /** -*- mode: c++; c-indent-level: +4; c++-member-init-indent: 8; comment-column: 35; -*- +
    The above line is usefulin Emacs-like editors +
    */ +
    /* +
    Template for creating a new representation +in EO +
    ================================================ +
    */ +
    #ifndef _eoOneMax_h +
    #define _eoOneMax_h +
    /**  +
    *  Always write a comment in this format +before class definition +
    *  if you want the class to be documented +by Doxygen +
    * Note that you MUST derive your structure +from EO<fitT> +
    * but you MAY use some other already prepared +class in the hierarchy +
    * like eoVector for instance, if you handle +a vector of something.... +
    * If you create a structure from scratch, +
    * the only thing you need to provide are  +
    *              +a default constructor +
    *              +IO routines printOn and readFrom +
    * +
    * Note that operator<< and operator>> +are defined at EO level +
    * using these routines +
    */
    + + + + + +
    template< class FitT> +
    class eoOneMax: public EO<FitT> { +
    public: +
      /** Ctor: you MUST provide +a default ctor. +
       * though such individuals will +generally be processed  +
       * by some eoInit object +
       */ +
     eoOneMax()  +
     { 
    + + + + + +
          +// START Code of default Ctor of an eoOneMax object +
          // +END    Code of default Ctor of an eoOneMax object
    + + + + + +
     } +

     virtual ~eoOneMax() +
     {

    + + + + + +
          +// START Code of Destructor of an eoEASEAGenome object +
          // +END    Code of Destructor of an eoEASEAGenome object
    + + + + + +
     } +

     virtual string className() const +{ return "eoOneMax"; } +
     

    + + + + + +
      /** printing... */ +
     void printOn(ostream& os) const +
     { +
          // +First write the fitness +
         EO<FitT>::printOn(os); +
         os << ' +';
    + + + + + +
          +// START Code of default output  +

    /** HINTS +
    * in EO we systematically write the sizes +of things before the things +
    * so readFrom is easier to code (see below) +
    */ +

          // END    +Code of default output

    + + + + + +
         } +

      /** reading...  +
       * of course, your readFrom must +be able to read what printOn writes!!! +
       */ +
     void readFrom(istream& is) +
     { +
          // +of course you should read the fitness first! +
         EO<FitT>::readFrom(is);

    + + + + + +
          +// START Code of input +

    /** HINTS +
    * remember the eoOneMax object will come +from the default ctor +
    * this is why having the sizes written out +is useful +
    */ +

          // END    +Code of input

    + + + + + +
     } +
     
    + + + + + +
    private:     // +put all data here
    + + + + + +
          // +START Private data of an eoOneMax object +
          // +END    Private data of an eoOneMax object
    + + + + + +
    }; +

    #endif

    + +
    Back to Lesson 5 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
    +
    +Marc Schoenauer
    + +
    Last modified: Fri May +3 06:06:09 2002 + + diff --git a/eo/tutorial/html/eoOneMaxEvalFunc.html b/eo/tutorial/html/eoOneMaxEvalFunc.html new file mode 100644 index 000000000..4d6eefbff --- /dev/null +++ b/eo/tutorial/html/eoOneMaxEvalFunc.html @@ -0,0 +1,160 @@ + + + + + + Templates/eoOneMaxEvalFunc.h + + +Back to Lesson 5 +- Tutorial main page - Top-Down +page - Bottom-up page - Programming +hints - EO +documentation +
    +
    +
    +

    +Templates/eoOneMaxEvalFunc.h

    +The places where you have to put some code are on pink +background.. Only the the character +colors have the usual meaning. +
    + + + + +
    /** -*- mode: c++; c-indent-level: +4; c++-member-init-indent: 8; comment-column: 35; -*- +

    The above line is usefulin Emacs-like editors +
    */ +

    /* +
    Template for evaluator in EO, a functor that +computes the fitness of an EO +
    ========================================================================== +
    */ +

    #ifndef _eoOneMaxEvalFunc_h +
    #define _eoOneMaxEvalFunc_h +

    // include whatever general include you need +
    #include <stdexcept> +
    #include <fstream> +

    // include the base definition of eoEvalFunc +
    #include "eoEvalFunc.h" +

    /**  +
     Always write a comment in this format +before class definition +
     if you want the class to be documented +by Doxygen +
    */

    + + + + + +
    template <class EOT> +
    class eoOneMaxEvalFunc : public eoEvalFunc<EOT> +
    { +
    public: +
    /// Ctor - no requirement
    + + + + + +
    // START eventually +add or modify the anyVariable argument +
     eoOneMaxEvalFunc() +
      //  eoOneMaxEvalFunc( +varType  _anyVariable) : anyVariable(_anyVariable)  +
    // END eventually add or modify the anyVariable +argument
    + + + + + +
     {
    + + + + + +
          // +START Code of Ctor of an eoOneMaxEvalFunc object +
          // +END    Code of Ctor of an eoOneMaxEvalFunc object
    + + + + + +
     } +

      /** Actually compute the fitness +
       * +
       * @param EOT & _eo the EO +object to evaluate +
       *                                  +it should stay templatized to be usable  +
       *                                  +with any fitness type +
       */ +
     void operator()(EOT & _eo) +
     { +
          // +test for invalid to avoid recomputing fitness of unmodified individuals +
         if (_eo.invalid()) +
             +{ +
    double fit;     +// to hold fitness value

    + + + + + +
          +// START Code of computation of fitness of the eoOneMax object +
    // fit = blablabla +
          // +END    Code of computation of fitness of the eoOneMax object
    + + + + + +
    _eo.fitness(fit); +
             +} +
     } +

    private:

    + + + + + +
    // START Private data +of an eoOneMaxEvalFunc object +
      //  varType anyVariable;    +// for example ... +
    // END    Private data of +an eoOneMaxEvalFunc object
    + + + + + +
    }; +
    #endif
    + +
    Back to Lesson 5 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
    +
    +Marc Schoenauer
    + +
    Last modified: Fri May +3 06:14:25 2002 + + diff --git a/eo/tutorial/html/eoOneMaxInit.html b/eo/tutorial/html/eoOneMaxInit.html new file mode 100644 index 000000000..07475be6f --- /dev/null +++ b/eo/tutorial/html/eoOneMaxInit.html @@ -0,0 +1,153 @@ + + + + + + Templates/eoOneMaxInit.h + + +Back to Lesson 5 - +Tutorial main page - Top-Down +page - Bottom-up page - Programming +hints - EO +documentation +
    +
    +
    +

    +Templates/eoOneMaxInit.h

    +The places where you have to put some code are on pink +background.. Only the the character +colors have the usual meaning. +
    + + + + +
    /** -*- mode: c++; c-indent-level: +4; c++-member-init-indent: 8; comment-column: 35; -*- +
    The above line is usefulin Emacs-like editors +
    */ +

    /* +
    Template for EO objects initialization in +EO +
    ============================================ +
    */ +

    #ifndef _eoOneMaxInit_h +
    #define _eoOneMaxInit_h +

    // include the base definition of eoInit +
    #include <eoInit.h> +

    /**  +
    *  Always write a comment in this format +before class definition +
    *  if you want the class to be documented +by Doxygen +
    * +
    * There is NO ASSUMPTION on the class GenoypeT. +
    * In particular, it does not need to derive +from EO (e.g. to initialize  +
    *      atoms of +an eoVector you will need an eoInit<AtomType>) +
    */

    + + + + + +
    template <class GenotypeT> +
    class eoOneMaxInit: public eoInit<GenotypeT> +{ +
    public: +
    /// Ctor - no requirement
    + + + + + +
    // START eventually +add or modify the anyVariable argument +
     eoOneMaxInit() +
      //  eoOneMaxInit( varType  +_anyVariable) : anyVariable(_anyVariable)  +
    // END eventually add or modify the anyVariable +argument
    + + + + + +
     {
    + + + + + +
          // +START Code of Ctor of an eoOneMaxInit object +
          // +END    Code of Ctor of an eoOneMaxInit object
    + + + + + +
     } +

      /** initialize a genotype +
       * +
       * @param _genotype  generally +a genotype that has been default-constructed +
       *                                    +whatever it contains will be lost +
       */ +
     void operator()(GenotypeT & +_genotype) +
     {

    + + + + + +
          +// START Code of random initialization of an eoOneMax object +
          // +END    Code of random initialization of an eoOneMax object
    + + + + + +
         _genotype.invalidate();     +// IMPORTANT in case the _genotype is old +
     } +

    private:

    + + + + + +
    // START Private data +of an eoOneMaxInit object +
      //  varType anyVariable;    +// for example ... +
    // END    Private data of +an eoOneMaxInit object
    + + + + + +
    }; +

    #endif

    + +
    Back to Lesson 5 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
    +
    +Marc Schoenauer
    + +
    Last modified: Fri May +3 06:17:21 2002 + + diff --git a/eo/tutorial/html/eoOneMaxMutation.html b/eo/tutorial/html/eoOneMaxMutation.html new file mode 100644 index 000000000..5181567ff --- /dev/null +++ b/eo/tutorial/html/eoOneMaxMutation.html @@ -0,0 +1,168 @@ + + + + + + eoOneMaxMutation.h + + +Back to Lesson 5 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
    +
    +
    +

    +eoOneMaxMutation.h

    +The places where you have to put some code are on pink background. +Only the the character colors have the usual meaning. +
      + + + + + +
    +/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    +The above line is useful in Emacs-like editors
    + */
    +/*
    +Template for simple mutation operators
    +======================================
    +*/
    +#ifndef eoOneMaxMutation_H
    +#define eoOneMaxMutation_H
    +#include <eoOp.h>
    +/**
    + *  Always write a comment in this format before class definition
    + *  if you want the class to be documented by Doxygen
    + *
    + * THere is NO ASSUMPTION on the class GenoypeT.
    + * In particular, it does not need to derive from EO
    + */
    +
    +
    + + + + +
    + +template<class GenotypeT>
    +class eoOneMaxMutation: public eoMonOp<GenotypeT>
    +{
    +public:
    +  /**
    +    * Ctor - no requirement
    +    */
    +
    +
    + + + + +
    + +// START eventually add or modify the anyVariable argument
    +  eoOneMaxMutation()
    +  //  eoOneMaxMutation( varType  _anyVariable) : anyVariable(_anyVariable)
    +// END eventually add or modify the anyVariable argument
    +
    +
    + + + + +
    + +  {
    +
    +
    + + + + +
    + +      // START Code of Ctor of an eoOneMaxEvalFunc object
    +      // END    Code of Ctor of an eoOneMaxEvalFunc object
    +
    +
    + + + + +
    + +  }
    +  /// The class name. Used to display statistics
    +  string className() const { return "eoOneMaxMutation"; }
    +  /**
    +    * modifies the parent
    +    * @param _genotype The parent genotype (will be modified)
    +    */
    +  bool operator()(GenotypeT & _genotype)
    +  {
    +      bool isModified;
    +
    +
    + + + + +
    + +      // START code for mutation of the _genotype object
    +            /** Requirement
    +* if (_genotype has been modified)
    +*        isModified = true;
    +* else
    +*        isModified = false;
    +*/
    +      return isModified;
    +      // END code for mutation of the _genotype object
    +
    +
    + + + + +
    + +  }
    +private:
    +
    +
    + + + + +
    + +// START Private data of an eoOneMaxMutation object
    +  //  varType anyVariable;    // for example ...
    +// END    Private data of an eoOneMaxMutation object
    +
    +
    + + + + +
    + +};
    +#endif
    +
    +
    Back to Lesson 5 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
    +
    +Marc Schoenauer
    +
    Last +modified: Wed May 1 07:18:00 2002 + + + diff --git a/eo/tutorial/html/eoOneMaxQuadCrossover.html b/eo/tutorial/html/eoOneMaxQuadCrossover.html new file mode 100644 index 000000000..a91a653ea --- /dev/null +++ b/eo/tutorial/html/eoOneMaxQuadCrossover.html @@ -0,0 +1,168 @@ + + + + + + Templates/eoOneMaxQuadCrossover.h + + +Back to Lesson +5 - Tutorial main page - Top-Down +page - Bottom-up page - Programming +hints - EO +documentation +
    +
    +
    +

    +Templates/eoOneMaxQuadCrossover.h

    +The places where you have to put some code are on pink +background.. Only the the character +colors have the usual meaning. +
    + + + + +
    /** -*- mode: c++; c-indent-level: +4; c++-member-init-indent: 8; comment-column: 35; -*- +
    The above line is usefulin Emacs-like editors +
    */ +
    /* +
    Template for simple quadratic crossover operators +
    ================================================= +
    Quadratic crossover operators modify the +both genotypes +
    */ +

    #ifndef eoOneMaxQuadCrossover_H +
    #define eoOneMaxQuadCrossover_H +

    #include <eoOp.h> +

    /**  +
    *  Always write a comment in this format +before class definition +
    *  if you want the class to be documented +by Doxygen +
    * +
    * THere is NO ASSUMPTION on the class GenoypeT. +
    * In particular, it does not need to derive +from EO +
    */

    + + + + + +
    template<class GenotypeT>  +
    class eoOneMaxQuadCrossover: public eoQuadOp<GenotypeT> +
    { +
    public: +
      /** +
       * Ctor - no requirement +
       */
    + + + + + +
    // START eventually +add or modify the anyVariable argument +
     eoOneMaxQuadCrossover() +
      //  eoOneMaxQuadCrossover( +varType  _anyVariable) : anyVariable(_anyVariable)  +
    // END eventually add or modify the anyVariable +argument
    + + + + + +
     {
    + + + + + +
          // +START Code of Ctor of an eoOneMaxEvalFunc object +
          // +END    Code of Ctor of an eoOneMaxEvalFunc object
    + + + + + +
     } +

      /// The class name. Used to +display statistics +
     string className() const { return +"eoOneMaxQuadCrossover"; } +

      /** +
       * eoQuad crossover - modifies +both parents +
       * @param _genotype1 The first +parent +
       * @param _genotype2 The second +parent +
       */ +
     bool operator()(GenotypeT& _genotype1, +GenotypeT & _genotype2)  +
     { +
         bool oneAtLeastIsModified;

    + + + + + +
          +// START code for crossover of _genotype1 and _genotype2 objects +
                +/** Requirement +
    * if (at least one genotype has been modified) +// no way to distinguish +
    *        +oneAtLeastIsModified = true; +
    * else +
    *        +oneAtLeastIsModified = false; +
    */ +
         return oneAtLeastIsModified; +
          // +END code for crossover of _genotype1 and _genotype2 objects
    + + + + + +
     } +

    private:

    + + + + + +
    // START Private data +of an eoOneMaxQuadCrossover object +
      //  varType anyVariable;    +// for example ... +
    // END    Private data of +an eoOneMaxQuadCrossover object
    + + + + + +
    }; +

    #endif

    + +
    Back to Lesson 5 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
    +
    +Marc Schoenauer
    + +
    Last modified: Fri May +3 07:47:13 2002 + + diff --git a/eo/tutorial/html/eoOneMax_complete.html b/eo/tutorial/html/eoOneMax_complete.html new file mode 100644 index 000000000..0c6c24680 --- /dev/null +++ b/eo/tutorial/html/eoOneMax_complete.html @@ -0,0 +1,192 @@ + + + + + + Templates/eoOneMax_complete.h + + +Back to Lesson 5 +- Tutorial main page - Top-Down +page - Bottom-up page - Programming +hints - EO +documentation +
    +
    +
    +

    +Templates/eoOneMax_complete.h

    +The user-defined code is on pink background.. +Only the the character colors have the +usual meaning. +

    + + + + +
    /** -*- mode: c++; c-indent-level: +4; c++-member-init-indent: 8; comment-column: 35; -*- +
    The above line is usefulin Emacs-like editors +
    */ +

    /* +
    Template for creating a new representation +in EO +
    ================================================ +
    */ +

    #ifndef _eoOneMax_h +
    #define _eoOneMax_h +
     

    + + + + + +
    /**  +
    * A simple example class for bitstring (is +NOT supposed to be used :-) +
    */
    + + + + + +
    + + + + + +
    template< class FitT> +
    class eoOneMax: public EO<FitT> { +
    public: +
      /** Deafult Ctor: nothing to +be done */ +
     eoOneMax() {} +

     virtual string className() const +{ return "eoOneMax"; } +
     

    + + + + + +
      /** printing... */ +
         void printOn(ostream& +_os) const +
         { +
              +// First write the fitness +
             +EO<FitT>::printOn(_os); +
             +_os << ' ';
    + + + + + +
             +_os << b.size() << ' ' ; +
             +for (unsigned i=0; i<b.size(); i++) +
                 +_os << b[i] << ' ' ;
    + + + + + +
         } +

      /** reading...  +
       * of course, your readFrom must +be able to read what printOn writes!!! +
       */ +
     void readFrom(istream& _is) +
     { +
          // +of course you should read the fitness first! +
         EO<FitT>::readFrom(_is);

    + + + + + +
         unsigned s; +
         _is >> s; +
         b.resize(s); +
         for (unsigned +i=0; i<s; i++) +
             +{ +
                 +bool bTmp; +
                 +_is >> bTmp; +
                 +b[i] = bTmp; +
             +} 
    + + + + + +
     }
    + + + + + +
    + + + + + +
      // brute setting (we could +also have defined a Ctor from a vector<bool>) +
     void setB(vector<bool> & +_b) +
     { +
         b=_b; +
     } +

      // brute accessing (we could +also define operator[] ...) +
     const vector<bool> & B() +
     { +
         return b; +
     }

    + + + + + +
    +
    private:     // +put all data here
    + + + + + +
     std::vector<bool> b;
    + + + + + +
    }; +

    #endif

    + +


    Back to Lesson 5 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
    +
    +Marc Schoenauer
    + +
    Last modified: Sat May +4 06:02:46 2002 + + diff --git a/eo/tutorial/html/eoTopDown.html b/eo/tutorial/html/eoTopDown.html index 0334f90a9..2e9d355bb 100644 --- a/eo/tutorial/html/eoTopDown.html +++ b/eo/tutorial/html/eoTopDown.html @@ -2,7 +2,7 @@ - + EO - The Algorithm-Based approach @@ -26,9 +26,9 @@ of "lessons" for you.
  • Lesson 1 - a gentle introduction to the EO way: your first steps into EO representations -using a simple generational GA. Please, spend -the necessary time on that one, since all basic constructs -presented there are used throughout EO.
  • +using a simple generational GA. Please, spend +the necessary time on that one, since all basic constructs presented +there are used throughout EO.
  • Lesson 2 - encapsulate, @@ -48,48 +48,51 @@ populations, ...).
  • -Lesson 4 - The same algorithms - again! - but now fully operational: -every component of the algorithm can be defined -on the command-line, except the type of genotype; -moreover, you now have a full library, i.e. everything except your fitness function is -already compiled. -
  • +Lesson 4 - The same algorithms - again! - +but now fully operational: every component +of the algorithm can be defined on the command-line, +except the type of genotype; moreover, you now have a full library, i.e. +everything except your fitness function is already +compiled. -


    Current version (May. 5, 2001) stops here, but ... +

  • +Lesson 5 (new) +- Use your own representation. Thanks +to template files and a little script in Unix, +or the Application template in MSVC++, you +can easily define a new genotype and run an Evolutionary Algorithm that +will intantly benefit from the power of all EO +Evolution Engines (including easy user-parameter +input presented in Lesson 4). You simply need to gradually fill +in the shell-files that the script will generate for you.
  • + +
    Current version (May. 5, 2002) stops here, but ...

    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 :-) -
      - +

    • -Lesson 4 - More general operators: -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.
    • - -
    • -Lesson 5 - More about checkpointing: +Lesson 6 (forthcoming) - More about checkpointing: write your first adaptive mechanism, and find out how easy it is to update and monitor dynamic parameters
    • -Lesson 6 - Why not go parallel? From -the simple asynchronous SSGA to the more sophisticated island model (no -totally distributed population yet).
    • +Lesson 7 - More general operators: +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.
    • -Lesson 7 - Use your own representation. -You need only to write the base individual class, the initilization class -and the variation operators. EO provides many helps: The eoExternal -paradigm let you encapsulate into EO classes existing code. And the eoFixedLength -and eoVariableLength super classes -allow quick definition of new genotypes that handle identical Atoms.
    • +Lesson 7 - Use predefined generic representations. +The eoFixedLength and eoVariableLength +super classes allow quick definition of new genotypes that handle identical +Atoms, together with generic variation operators.
    Of course, in each lesson, you have links to the corresponding Component-Based -page. ( ... Well, to tell you the truth, as of today, Jan. 5, 2001, this -is not exactly true :-) +page. ( ... Well, to tell you the truth, as of today, this is not exactly +true :-)


    Tutorial main page - Algorithm-Based diff --git a/eo/tutorial/html/make_genotype_OneMax.html b/eo/tutorial/html/make_genotype_OneMax.html new file mode 100644 index 000000000..3920e5548 --- /dev/null +++ b/eo/tutorial/html/make_genotype_OneMax.html @@ -0,0 +1,160 @@ + + + + + + Templates/make_genotype_OneMax.h + + +Back to Lesson 5 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
    +
    +
    +

    +Templates/make_genotype_OneMax.h

    +The places where you have to put some code are on pink +background.. +Only the the character colors have the usual meaning. +
      + + + + + +
    + +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    + +//-----------------------------------------------------------------------------
    + +// make_genotype.h
    + +// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001
    + +/*
    +      This library is free software; you can redistribute it and/or
    +      modify it under the terms of the GNU Lesser General Public
    +      License as published by the Free Software Foundation; either
    +      version 2 of the License, or (at your option) any later version.
    +      This library is distributed in the hope that it will be useful,
    +      but WITHOUT ANY WARRANTY; without even the implied warranty of
    +      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    +      Lesser General Public License for more details.
    +      You should have received a copy of the GNU Lesser General Public
    +      License along with this library; if not, write to the Free Software
    +      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    +      Contact: todos@geneura.ugr.es, http://geneura.ugr.es
    +                        Marc.Schoenauer@inria.fr
    +                        mkeijzer@dhi.dk
    + */
    + +//-----------------------------------------------------------------------------
    +#ifndef _make_genotype_h
    +#define _make_genotype_h
    +#include <eoOneMax.h>
    +#include <eoOneMaxInit.h>
    +   +// also need the parser and param includes
    +#include <utils/eoParser.h>
    +#include <utils/eoState.h>
    + +/*
    + * This fuction does the create an eoInit<eoOneMax>
    + *
    + * It could be here tempatized only on the fitness, as it can be used
    + * to evolve structures with any fitness.
    + * However, for consistency reasons, it was finally chosen, as in
    + * the rest of EO, to templatize by the full EOT, as this eventually
    + * allows to choose the type of genotype at run time (see in es dir)
    + *
    + * It returns an eoInit<EOT> that can later be used to initialize
    + * the population (see make_pop.h).
    + *
    + * It uses a parser (to get user parameters) and a state (to store the memory)
    + * the last argument is to disambiguate the call upon different instanciations.
    + *
    + * WARNING: that last argument will generally be the result of calling
    + *                  the default ctor of EOT, resulting in most cases in an EOT
    + *                  that is ***not properly initialized***
    +*/
    +
    +
    + + + + +
    + +template <class EOT>
    +eoInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
    +{
    +
    +
    + + + + +
    + +   +// read any useful parameter here from the parser
    +   +// the param itself will belong to the parser (as far as memory is concerned)
    +   +//      paramType & param = _parser.createParam(deafultValue, "Keyword", "Comment to appear in help and status", 'c',"Section of status file").value();
    +
    +
    + + + + +
    + +   +// Then built the initializer - a pointer, stored in the eoState
    +  eoInit<EOT>* init = new eoOneMaxInit<EOT> +/* ( param ) */ ; ;
    +
    +
    + + + + +
    + +   +// Eventually by passing the parameters you need
    +  //  eoInit<EOT>* init = new eoOneMaxInit<EOT> +/* ( param ) */ ; ;
    +
    +
    + + + + +
    + +   +// store in state
    +  _state.storeFunctor(init);
    +   +// and return a reference
    +  return *init;
    +}
    +#endif
    +
    +
    Back to Lesson 5 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
    +
    +Marc Schoenauer
    +
    Last +modified: Fri May 3 07:10:52 2002 + + + diff --git a/eo/tutorial/html/make_op_OneMax.html b/eo/tutorial/html/make_op_OneMax.html new file mode 100644 index 000000000..a108fb14f --- /dev/null +++ b/eo/tutorial/html/make_op_OneMax.html @@ -0,0 +1,351 @@ + + + + + + Templates/make_op_OneMax.h + + +Back to Lesson 5 +- Tutorial main page - Top-Down +page - Bottom-up page - Programming +hints - EO +documentation +
    +
    +
    +

    +Templates/make_op_OneMax.h

    +The places where you have to put some code are on pink +background.. Only the the character +colors have the usual meaning. +

    + + + + +
    // -*- mode: c++; c-indent-level: +4; c++-member-init-indent: 8; comment-column: 35; -*- +

    //----------------------------------------------------------------------------- +
    // make_op_OneMax.h +
    // (c) Marc Schoenauer, Maarten Keijzer and +GeNeura Team, 2001 +
    /*  +
         This library is +free software; you can redistribute it and/or +
         modify it under +the terms of the GNU Lesser General Public +
         License as published +by the Free Software Foundation; either +
         version 2 of the +License, or (at your option) any later version. +
         This library is +distributed in the hope that it will be useful, +
         but WITHOUT ANY +WARRANTY; without even the implied warranty of +
         MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU +
         Lesser General Public +License for more details. +
         You should have +received a copy of the GNU Lesser General Public +
         License along with +this library; if not, write to the Free Software +
         Foundation, Inc., +59 Temple Place, Suite 330, Boston, MA  02111-1307  USA +
         Contact: todos@geneura.ugr.es, +http://geneura.ugr.es +
                           +Marc.Schoenauer@inria.fr +
                           +mkeijzer@dhi.dk +
    */ +
    //----------------------------------------------------------------------------- +

    #ifndef _make_op_OneMax_h +
    #define _make_op_OneMax_h +

    // the operators +
    #include <eoOp.h> +
    #include <eoGenOp.h> +
    #include <eoCloneOps.h> +
    #include <eoOpContainer.h> +
    // combinations of simple eoOps (eoMonOp +and eoQuadOp) +
    #include <eoProportionalCombinedOp.h> +

    /** definition of mutation:  +
    * class eoOneMaxMonop MUST derive from eoMonOp<eoOneMax> +
    */ +
    #include "eoOneMaxMutation.h" +

    /** definition of crossover (either as eoBinOp +(2->1) or eoQuadOp (2->2):  +
    * class eoOneMaxBinCrossover MUST derive +from eoBinOp<eoOneMax> +
    * OR  +
    * class eoOneMaxQuadCrossover MUST derive +from eoQuadOp<eoOneMax> +
    */ +
    // #include "eoOneMaxBinOp.h" +
    // OR +
    #include "eoOneMaxQuadCrossover.h" +

      // also need the parser and +state includes +
    #include <utils/eoParser.h> +
    #include <utils/eoState.h> +

    /////////////////// variation operators /////////////// +
    // canonical (crossover + mutation) only +at the moment // +

    /* +
    * This function builds the operators that +will be applied to the eoOneMax +
    * +
    * It uses a parser (to get user parameters), +a state (to store the memory) +
    *      the last +parameter is an eoInit: if some operator needs some info  +
    *      about the +genotypes, the init has it all (e.g. bounds, ...) +
    *      Simply do  +
    *              +EOT myEO; +
    *              +_init(myEO); +
    *      and myEO +is then an ACTUAL object +
    * +
    * As usual, the template is the complete +EOT even though only the fitness +
    * is actually templatized here: the following +only applies to eoOneMax +
    */

    + + + + + +
    template <class EOT> +
    eoGenOp<EOT> & do_make_op(eoParameterLoader& +_parser, eoState& _state, eoInit<EOT>& _init) +
    { +
      // this is a temporary version, +while Maarten codes the full tree-structured +
      // general operator input +
      // BTW we must leave that simple +version available somehow, as it is the one +
      // that 90% people use! +

          ///////////////////////////// +
          // +Variation operators +
          //////////////////////////// +
          // +read crossover and mutations, combine each in a proportional Op +
          // +and create the eoGenOp that calls crossover at rate pCross  +
          // +then mutation with rate pMut +

          // the +crossovers +
          ///////////////// +

          // here +we can have eoQuadOp (2->2) only - no time for the eoBinOp case +

          // you +can have more than one - combined in a proportional way +

          // first, +define the crossover objects and read their rates from the parser +

          // A +first crossover  +
         +eoQuadOp<Indi> *cross = new eoOneMaxQuadCrossover<Indi> /* (varType  +_anyVariable) */; +
          // +store in the state +
         _state.storeFunctor(cross); +

      // read its relative rate in +the combination +
         double cross1Rate += _parser.createParam(1.0, "cross1Rate", "Relative rate for crossover 1", +'1', "Variation Operators").value(); +

      // and create the combined operator +with this one +
     eoPropCombinedQuadOp<Indi> *propXover +=  +
         new eoPropCombinedQuadOp<Indi>(*cross, +cross1Rate); +
      // and of course stor it in +the state +
         _state.storeFunctor(propXover); +
     

    + + + + + +
          +// Optional: A second(and third, and ...)  crossover  +
          //    +of course you must create the corresponding classes +
          // +and all ***MUST*** derive from eoQuadOp<Indi> +

      /* Uncomment if necessary - +and replicate as many time as you need +
             +cross = new eoOneMaxSecondCrossover<Indi>(varType  _anyVariable);  +
             +_state.storeFunctor(cross); +
             +double cross2Rate = _parser.createParam(1.0, "cross2Rate", "Relative rate +for crossover 2", '2', "Variation Operators").value();  +
             +propXover.add(*cross, cross2Rate);  +
     */ +
      // if you want some gentle +output, the last one shoudl be like +
      //  propXover.add(*cross, +crossXXXRate, true); +
     

    + + + + + +
    +
      // the mutation: same story +
      //////////////// +
      // you can have more than one +- combined in a proportional way +

      // for each mutation,  +
      // - define the mutator object +
      // - read its rate from the +parser +
      // - add it to the proportional +combination +

      // a first mutation  +
    eoMonOp<Indi> +*mut = new eoOneMaxMutation<Indi> /* (varType  +_anyVariable) */; +
     _state.storeFunctor(mut); +
      // its relative rate in the +combination +
     double mut1Rate = _parser.createParam(1.0, +"mut1Rate", "Relative rate for mutation 1", '1', "Variation Operators").value(); +
      // and the creation of the +combined operator with this one +
     eoPropCombinedMonOp<Indi> *propMutation += new eoPropCombinedMonOp<Indi>(*mut, mut1Rate); +
     _state.storeFunctor(propMutation); +
     

    + + + + + +
          +// Optional: A second(and third, and ...)  mutation with their rates +
          //    +of course you must create the corresponding classes +
          // +and all ***MUST*** derive from eoMonOp<Indi> +

      /* Uncomment if necessary - +and replicate as many time as you need +
             +mut = new eoOneMaxSecondMutation<Indi>(varType  _anyVariable); +
             +_state.storeFunctor(mut); +
             +double mut2Rate = _parser.createParam(1.0, "mut2Rate", "Relative rate for +mutation 2", '2', "Variation Operators").value();  +
               +propMutation.add(*mut, mut2Rate);  +
     */ +
      // if you want some gentle +output, the last one shoudl be like +
      //  propMutation.add(*mut, +mutXXXRate, true); +

      // end of crossover and mutation +definitions +
     

    + + + + + +
    +
    // from now on, you do not need to modify +anything +
    // though you CAN add things to the checkpointing +(see tutorial) +

      // now build the eoGenOp: +
      // to simulate SGA (crossover +with proba pCross + mutation with proba pMut +
      // we must construct +
      //        +a sequential combination of +
      //                  +with proba 1, a proportional combination of  +
      //                                              +a QuadCopy and our crossover +
      //                  +with proba pMut, our mutation +

      // but of course you're free +to use any smart combination you could think of +
      // especially, if you have +to use eoBinOp rather than eoQuad Op youùll have +
      // to modify that part +

      // +First read the individual level parameters +
         eoValueParam<double>& +pCrossParam = _parser.createParam(0.6, "pCross", "Probability of Crossover", +'C', "Variation Operators" ); +
          // +minimum check +
         if ( (pCrossParam.value() +< 0) || (pCrossParam.value() > 1) ) +
             +throw runtime_error("Invalid pCross"); +

         eoValueParam<double>& +pMutParam = _parser.createParam(0.1, "pMut", "Probability of Mutation", +'M', "Variation Operators" ); +
          // +minimum check +
         if ( (pMutParam.value() +< 0) || (pMutParam.value() > 1) ) +
             +throw runtime_error("Invalid pMut"); +

      // the crossover - with probability +pCross +
     eoProportionalOp<Indi> * propOp += new eoProportionalOp<Indi> ; +
     _state.storeFunctor(propOp); +
     eoQuadOp<Indi> *ptQuad = new +eoQuadCloneOp<Indi>; +
     _state.storeFunctor(ptQuad); +
     propOp->add(*propXover, pCrossParam.value()); +// +crossover, with proba pcross +
     propOp->add(*ptQuad, 1-pCrossParam.value()); +// +nothing, with proba 1-pcross +

      // now the sequential +
     eoSequentialOp<Indi> *op = new +eoSequentialOp<Indi>; +
     _state.storeFunctor(op); +
     op->add(*propOp, 1.0); // always +do combined crossover +
     op->add(*propMutation, pMutParam.value()); +// +then mutation, with proba pmut +

      // that's it - return a reference +
     return *op; +
    } +

    #endif

    + +


    Back to Lesson 5 - Tutorial +main page - Top-Down page - Bottom-up +page - Programming hints - EO +documentation +
    +
    +Marc Schoenauer
    + +
    Last modified: Fri May +3 08:06:20 2002 + +