Big modifications - now the init and most important the operators
are handled in separate files make_genotype_xxx and make_op_xxx as it was done in the examples of Lesson4
This commit is contained in:
parent
c34db3eb29
commit
f3db65795b
7 changed files with 525 additions and 45 deletions
|
|
@ -1,7 +1,7 @@
|
|||
This directory contains sample files that should make it easy to
|
||||
create an EO algorithm to evolve any type of structure
|
||||
(EO comes with two examples, bitstrings and vector of real variables,
|
||||
so you'll need this qs soon as you want to evolve something else).
|
||||
so you'll need this as soon as you want to evolve something else).
|
||||
|
||||
At the moment, only algorithms involving a scalar fitness (double)
|
||||
are implemented (see test dir for Pareto optimization of multiple-
|
||||
|
|
@ -9,7 +9,7 @@ objective fitness - or be patient :-)
|
|||
|
||||
This file will help you to build the same algorithm than the ones
|
||||
in the Lesson4 of the tutorial, but with YOUR genotype instead of
|
||||
*bitstrings or vector<double>
|
||||
bitstrings or vector<double>
|
||||
|
||||
It is assumed in the following that you have read the first part of
|
||||
the tutorial (Lessons 1 to 4).
|
||||
|
|
@ -21,18 +21,19 @@ 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 helper script create.sh will create for you the files you need
|
||||
from teh examples in tutorial/Templates dir, and all you'll have to do
|
||||
The helper script * create.sh * will create for you the files you need
|
||||
from the samples in tutorial/Templates dir, and all you'll have to do
|
||||
is to include the actual code where indicated in those files (between
|
||||
keywords START and END).
|
||||
|
||||
First, let's choose a name: let's call the new EO class eoAppli.
|
||||
All newly created classes will be named eoApplicationXXX (in the file
|
||||
eoApplicationXXX)
|
||||
All newly created classes will be named eoAppliXXX (in the file
|
||||
eoAppliXXX)
|
||||
|
||||
1- create a directory for your application in the tutorial dir, "parallel" to
|
||||
the LessonX dirs (though any name can do, of course, we will suppose
|
||||
its full name, from the / root dir, is APPLICATION in what follows)
|
||||
1- choose a directory name for your application in the tutorial dir,
|
||||
"parallel" to the LessonX dirs (though any name can do, of course, we
|
||||
will suppose its full name, from the / root dir, is APPLICATION in
|
||||
what follows)
|
||||
|
||||
2- cd to the tutorial/Templates dir
|
||||
|
||||
|
|
@ -41,25 +42,30 @@ its full name, from the / root dir, is APPLICATION in what follows)
|
|||
|
||||
4- cd to the APPLICATION dir. You should see there the following
|
||||
files:
|
||||
AppliEA.cpp the main file, includes all other, to be compiled
|
||||
Makefile with default target eoAppliEA
|
||||
eoAppli.h class eoAppli<FitT>, FitT = template fitness
|
||||
eoAppliEA.cpp the main file, includes all other, to be compiled
|
||||
eoAppliEvalFunc.h class for the computation of fotness
|
||||
eoAppliInit.h class for genotype initlialization
|
||||
eoAppliMutation.h class for mutation
|
||||
eoAppliQuadCrossover.h class for (quadratic) crossover
|
||||
make_genotype_Appli.h helper function that create the initializer
|
||||
make_op_Appli.h helper function that creates the variatin operators
|
||||
|
||||
Note: You can go directly to step 6 and 7: you'll get a lot of
|
||||
warnings, but will be able to run an EA that does nothing!
|
||||
|
||||
5- Edit those files one after the other and add you code where
|
||||
indicated (look for keywords START and END and modify code in
|
||||
between).
|
||||
5- Edit those files to suit your needs. The minimal addition you'll need
|
||||
to make are
|
||||
in eoAppli.h define your genotype
|
||||
in eoAppliInit.h define the initialization of one genotype
|
||||
in eoAppliMutation.h define the mutation of one genotype
|
||||
in eoAppliQuadCrossover.h define the crossover of 2 genotypes
|
||||
|
||||
Note: If your APPLICATION dir is in the tutorial dir, you don't need
|
||||
to modify Makefile.
|
||||
HINT: look for keywords START and END and modify code in between.
|
||||
|
||||
6- Compile eoAppliEA.cpp:
|
||||
6- Compile eoAppliEA.cpp. If your APPLICATION dir is in the tutorial
|
||||
dir, you don't need to modify Makefile. Just type in
|
||||
|
||||
% make
|
||||
|
||||
|
|
@ -83,24 +89,22 @@ want to become active), and run
|
|||
HINTS
|
||||
-----
|
||||
|
||||
1- All new classes you will create probably require some parameters in
|
||||
the constructor, and some (if not all) thoses parameters are likele to
|
||||
be user parameter: you can either read them in the main file (as is
|
||||
done in the sample eoAppliEA.cpp) or pass the eoParser to the
|
||||
1- If some new classes you create require some user parameter, you can
|
||||
either read them in the file where they are created (e.g.
|
||||
make_op_Appli.h for variation operators), or pass the eoParser to the
|
||||
constructor of the class, and read the parameter from the parser.
|
||||
|
||||
2- If you stick to privacy for the data in your EO class, you will
|
||||
probably need to write accessors to those data, as well as some public
|
||||
methods to modify them.
|
||||
methods to modify them, as soon as some other methods need them too.
|
||||
|
||||
3- The sample eoAppliEA.cpp supposes that you ony have one crossover
|
||||
and one mutation operator. However, the code for multiple operators
|
||||
is there: you can have for instance 2 crossover operators, and choose
|
||||
3- The sample make_op_Appli.h supposes that you ony have one crossover
|
||||
and one mutation operator. However, the code for multiple operators is
|
||||
there: you can have for instance 2 crossover operators, and choose
|
||||
among them according to relative weights (proportional choice) - same
|
||||
for mutation. Look at the operator section in eoAppliEA.cpp
|
||||
In particular, the user parameter mutationRate is totally useless for
|
||||
a single operator, and is there only as a provision for using more
|
||||
than one.
|
||||
for mutation. Look at the operator section in eoAppliEA.cpp In
|
||||
particular, the user parameters cross1Rate and mut1Rate are totally
|
||||
useless for a single operator.
|
||||
|
||||
To add another operator, you have to create another class by mimicking
|
||||
what has been done for the first operator.
|
||||
|
|
@ -113,13 +117,16 @@ name in the class declaration, in the constructor and in the
|
|||
className() method.
|
||||
* in the new eoAppliBetterMutation class, change the code for the
|
||||
operator() - and eventually the code for the constructor.
|
||||
* in the eoAppliEA.cpp file, in the mutation section, uncomment the
|
||||
* in the make_op_Appli.h file, in the mutation section, uncomment the
|
||||
lines
|
||||
eoMyStructSecondMutation<Indi> mut2(varType _anyVariable);
|
||||
double mut2Rate = parser.createParam(1.0, "mut2Rate", "Relative rate for mutation 2", '2', "Variation Operators").value();
|
||||
propMutation.add(mut2, mut2Rate);
|
||||
mut = new eoAppliSecondMutation<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);
|
||||
|
||||
and change the name of the class from eoAppliSecondMutation to your
|
||||
name eoAppliBetterMutation (you can also change the keyword from
|
||||
mut2Rate to something more meaningful like BetterMutationRate).
|
||||
You're done!
|
||||
|
||||
In case of problem: Marc.Schoenauer@inria.fr
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue