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 @@ + + +
+ + +| /** -*- 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; + } |
+
+
+
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.
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.
+
+
The constructor takes 6 arguments: +
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.
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:
+
Its constructor takes 2 argumenrts: -
eoHowMany(double _rate, bool _interpret_as_rate -= true)
It is used in eoSelectMany (which supersedes +
It has 3 possible constructors, that determine its behavior: +
-
-
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
operators
-
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!!!).
+
+
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: +
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 (
+
+
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.
+
+
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 +
+
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); + } |
+
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!
+
+
| /** -*- 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 << ' +'; |
+
| }
+ /** reading...
+ |
+
|
+// START Code of input
+ /** HINTS
+ // END +Code of input |
+
| }
+ |
+
| private: // +put all data here | +
| //
+START Private data of an eoOneMax object
+ // +END Private data of an eoOneMax object |
+
| };
+ #endif |
+
| /** -*- mode: c++; c-indent-level:
+4; c++-member-init-indent: 8; comment-column: 35; -*-
+ The above line is usefulin Emacs-like editors
+ /*
+ #ifndef _eoOneMaxEvalFunc_h
+ // include whatever general include you need
+ // include the base definition of eoEvalFunc
+ /**
+ |
+
| template <class EOT>
+ class eoOneMaxEvalFunc : public eoEvalFunc<EOT> + { + public: + /// Ctor - no requirement |
+
| { | +
| //
+START Code of Ctor of an eoOneMaxEvalFunc object
+ // +END Code of Ctor of an eoOneMaxEvalFunc object |
+
| }
+ /** Actually compute the fitness
+ |
+
|
+// 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 |
+
| /** -*- mode: c++; c-indent-level:
+4; c++-member-init-indent: 8; comment-column: 35; -*-
+ The above line is usefulin Emacs-like editors + */ + /*
+ #ifndef _eoOneMaxInit_h
+ // include the base definition of eoInit
+ /**
+ |
+
| template <class GenotypeT>
+ class eoOneMaxInit: public eoInit<GenotypeT> +{ + public: + /// Ctor - no requirement |
+
| { | +
| //
+START Code of Ctor of an eoOneMaxInit object
+ // +END Code of Ctor of an eoOneMaxInit object |
+
| }
+ /** initialize a 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 |
+
|
+/** -*- 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 + |
+
| /** -*- 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
+ #include <eoOp.h> + /**
+ |
+
| template<class GenotypeT>
+ class eoOneMaxQuadCrossover: public eoQuadOp<GenotypeT> + { + public: + /** + * Ctor - no requirement + */ |
+
| { | +
| //
+START Code of Ctor of an eoOneMaxEvalFunc object
+ // +END Code of Ctor of an eoOneMaxEvalFunc object |
+
| }
+ /// The class name. Used to
+display statistics
+ /**
+ |
+
| }
+ private: |
+
| // START Private data
+of an eoOneMaxQuadCrossover object
+ // varType anyVariable; +// for example ... + // END Private data of +an eoOneMaxQuadCrossover object |
+
| };
+ #endif |
+
| /** -*- mode: c++; c-indent-level:
+4; c++-member-init-indent: 8; comment-column: 35; -*-
+ The above line is usefulin Emacs-like editors + */ + /*
+ #ifndef _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...
+ |
+
| 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[] ...)
+ |
+
|
+ private: // +put all data here |
+
| std::vector<bool> b; | +
| };
+ #endif |
+
Current version (May. 5, 2001) 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 :-)
-
-
+
|
+
+// -*- 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 + |
+
| // -*- mode: c++; c-indent-level:
+4; c++-member-init-indent: 8; comment-column: 35; -*-
+ //-----------------------------------------------------------------------------
+ #ifndef _make_op_OneMax_h
+ // the operators
+ /** definition of mutation:
+ /** definition of crossover (either as eoBinOp
+(2->1) or eoQuadOp (2->2):
+ // also need the parser and
+state includes
+ /////////////////// variation operators ///////////////
+ /*
+ |
+