Paradiseo-eo sources added

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
legrand 2006-12-12 14:49:08 +00:00
commit c3aec878e5
3609 changed files with 342772 additions and 0 deletions

View file

@ -0,0 +1 @@
Makefile.in

View file

@ -0,0 +1,95 @@
#include <iostream>
#include <ga/make_ga.h>
#include <apply.h>
// EVAL
#include "binary_value.h"
// GENERAL
using namespace std;
int main(int argc, char* argv[])
{
try
{
// REPRESENTATION
//-----------------------------------------------------------------------------
// define your genotype and fitness types
typedef eoBit<double> EOT;
// PARAMETRES
eoParser parser(argc, argv); // for user-parameter reading
// GENERAL
eoState state; // keeps all things allocated
///// FIRST, problem or representation dependent stuff
//////////////////////////////////////////////////////
// EVAL
// The evaluation fn - encapsulated into an eval counter for output
eoEvalFuncPtr<EOT, double> mainEval( binary_value<EOT> );
eoEvalFuncCounter<EOT> eval(mainEval);
// REPRESENTATION
// the genotype - through a genotype initializer
eoInit<EOT>& init = make_genotype(parser, state, EOT());
// if you want to do sharing, you'll need a distance.
// here Hamming distance
eoHammingDistance<EOT> dist;
// OPERATORS
// Build the variation operator (any seq/prop construct)
eoGenOp<EOT>& op = make_op(parser, state, init);
// GENERAL
//// Now the representation-independent things
//////////////////////////////////////////////
// initialize the population - and evaluate
// yes, this is representation indepedent once you have an eoInit
eoPop<EOT>& pop = make_pop(parser, state, init);
// STOP
// stopping criteria
eoContinue<EOT> & term = make_continue(parser, state, eval);
// output
eoCheckPoint<EOT> & checkpoint = make_checkpoint(parser, state, eval, term);
// GENERATION
// algorithm (need the operator!)
eoAlgo<EOT>& ga = make_algo_scalar(parser, state, eval, checkpoint, op, &dist);
///// End of construction of the algorith
/////////////////////////////////////////
// PARAMETRES
// to be called AFTER all parameters have been read!!!
make_help(parser);
//// GO
///////
// EVAL
// evaluate intial population AFTER help and status in case it takes time
apply<EOT>(eval, pop);
// STOP
// print it out (sort witout modifying)
cout << "Initial Population\n";
pop.sortedPrintOn(cout);
cout << endl;
// GENERATION
run_ea(ga, pop); // run the ga
// STOP
// print it out (sort witout modifying)
cout << "Final Population\n";
pop.sortedPrintOn(cout);
cout << endl;
// GENERAL
}
catch(exception& e)
{
cout << e.what() << endl;
}
}

View file

@ -0,0 +1,11 @@
/.cvsignore/1.1/Fri Sep 17 16:53:13 2004//
/BitEA.cpp/1.4/Tue May 25 08:03:30 2004//
/ESEA.cpp/1.4/Thu Jan 17 17:51:58 2002//
/ESEA.param/1.1/Mon Dec 27 07:59:58 2004//
/Makefile.am/1.4/Wed Sep 28 21:49:25 2005//
/Makefile.simple/1.1/Fri Sep 17 15:20:18 2004//
/RealEA.cpp/1.2/Thu Jan 17 17:51:58 2002//
/RealEA.param/1.1/Mon Dec 27 07:59:58 2004//
/binary_value.h/1.3/Tue May 25 08:03:30 2004//
/real_value.h/1.1/Thu May 3 13:06:34 2001//
D

View file

@ -0,0 +1 @@
eo/tutorial/Lesson4

View file

@ -0,0 +1 @@
:ext:evomarc@eodev.cvs.sourceforge.net:/cvsroot/eodev

View file

@ -0,0 +1,137 @@
// Program to test several EO-ES features
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include <algorithm>
#include <string>
#include <iostream>
#include <iterator>
#include <stdexcept>
#include <time.h>
using namespace std;
#include <eo>
// representation specific
#include <es/make_es.h>
#include "real_value.h" // the sphere fitness
// Now the main
///////////////
typedef eoMinimizingFitness FitT;
template <class EOT>
void runAlgorithm(EOT, eoParser& _parser, eoState& _state);
int main_function(int argc, char *argv[])
{
// Create the command-line parser
eoParser parser(argc, argv); // for user-parameter reading
eoState state; // keeps all things allocated
eoValueParam<bool>& simpleParam = parser.createParam(true, "Isotropic", "Isotropic self-adaptive mutation", 'i', "ES mutation");
eoValueParam<bool>& stdevsParam = parser.createParam(false, "Stdev", "One self-adaptive stDev per variable", 's', "ES mutation");
eoValueParam<bool>& corrParam = parser.createParam(false, "Correl", "Use correlated mutations", 'c', "ES mutation");
// Run the appropriate algorithm
if (simpleParam.value() == false)
{
cout << "Using eoReal" << endl;
runAlgorithm(eoReal<FitT>(), parser, state);
}
else if (stdevsParam.value() == false)
{
cout << "Using eoEsSimple" << endl;
runAlgorithm(eoEsSimple<FitT>(), parser, state);
}
else if (corrParam.value() == false)
{
cout << "Using eoEsStdev" << endl;
runAlgorithm(eoEsStdev<FitT>(), parser, state);
}
else
{
cout << "Using eoEsFull" << endl;
runAlgorithm(eoEsFull<FitT>(), parser, state);
}
return 0;
}
// A main that catches the exceptions
int main(int argc, char **argv)
{
try
{
main_function(argc, argv);
}
catch(exception& e)
{
cout << "Exception: " << e.what() << '\n';
}
return 1;
}
/** The templatized main (sort of)
* quite similar to the main of other genotypes
* (e.g. t-eoReal and t-eoGA in test dir)
*/
template <class EOT>
void runAlgorithm(EOT, eoParser& _parser, eoState& _state)
{
typedef typename EOT::Fitness FitT;
///// FIRST, problem or representation dependent stuff
//////////////////////////////////////////////////////
// The evaluation fn - encapsulated into an eval counter for output
eoEvalFuncPtr<EOT, double, const std::vector<double>&>
mainEval( real_value );
eoEvalFuncCounter<EOT> eval(mainEval);
// the genotype - through a genotype initializer
eoRealInitBounded<EOT>& init = make_genotype(_parser, _state, EOT());
// Build the variation operator (any seq/prop construct)
eoGenOp<EOT>& op = make_op(_parser, _state, init);
//// Now the representation-independent things
//////////////////////////////////////////////
// initialize the population - and evaluate
// yes, this is representation indepedent once you have an eoInit
eoPop<EOT>& pop = make_pop(_parser, _state, init);
apply<EOT>(eval, pop);
// stopping criteria
eoContinue<EOT> & term = make_continue(_parser, _state, eval);
// output
eoCheckPoint<EOT> & checkpoint = make_checkpoint(_parser, _state, eval, term);
// algorithm (need the operator!)
eoAlgo<EOT>& ga = make_algo_scalar(_parser, _state, eval, checkpoint, op);
///// End of construction of the algorith
/////////////////////////////////////////
// to be called AFTER all parameters have been read!!!
make_help(_parser);
//// GO
///////
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;
}

View file

@ -0,0 +1,62 @@
###### General ######
# --help=0 # -h : Prints this message
# --stopOnUnknownParam=1 # Stop if unkown param entered
# --seed=1104133126 # -S : Random number seed
###### ES mutation ######
# --Isotropic=1 # -i : Isotropic self-adaptive mutation
# --Stdev=0 # -s : One self-adaptive stDev per variable
# --Correl=0 # -c : Use correlated mutations
###### Evolution Engine ######
--popSize=1 # -P : Population Size
--selection=Sequential # -S : Selection: DetTour(T), StochTour(t), Roulette, Ranking(p,e) or Sequential(ordered/unordered)
--nbOffspring=700% # -O : Nb of offspring (percentage or absolute)
--replacement=Comma # -R : Replacement: Comma, Plus or EPTour(T), SSGAWorst, SSGADet(T), SSGAStoch(t)
--weakElitism=0 # -w : Old best parent replaces new worst offspring *if necessary*
###### Genotype Initialization ######
# --vecSize=10 # -n : The number of variables
# --initBounds=10[-1,1] # -B : Bounds for initialization (MUST be bounded)
--sigmaInit=0.3% # -s : Initial value for Sigmas (with a '%' -> scaled by the range of each variable)
###### Output ######
# --useEval=1 # Use nb of eval. as counter (vs nb of gen.)
# --useTime=1 # Display time (s) every generation
# --printBestStat=1 # Print Best/avg/stdev every gen.
# --printPop=0 # Print sorted pop. every gen.
###### Output - Disk ######
# --resDir=Res # Directory to store DISK outputs
# --eraseDir=1 # erase files in dirName if any
# --fileBestStat=0 # Output bes/avg/std to file
###### Output - Graphical ######
# --plotBestStat=0 # Plot Best/avg Stat
# --plotHisto=0 # Plot histogram of fitnesses
###### Persistence ######
# --Load= # -L : A save file to restart from
# --recomputeFitness=0 # -r : Recompute the fitness after re-loading the pop.?
# --saveFrequency=0 # Save every F generation (0 = only final state, absent = never)
# --saveTimeInterval=0 # Save every T seconds (0 or absent = never)
# --status=t-eoESAll.status # Status file
###### Stopping criterion ######
# --maxGen=100 # -G : Maximum number of generations () = none)
# --steadyGen=100 # -s : Number of generations with no improvement
# --minGen=0 # -g : Minimum number of generations
# --maxEval=0 # -E : Maximum number of evaluations (0 = none)
# --targetFitness=0 # -T : Stop when fitness reaches
# --CtrlC=0 # -C : Terminate current generation upon Ctrl C
###### Variation Operators ######
# --objectBounds=10[-inf,+inf] # -B : Bounds for variables
# --operator=SGA # -o : Description of the operator (SGA only now)
# --pCross=1 # -C : Probability of Crossover
# --pMut=1 # -M : Probability of Mutation
# --crossType=global # -C : Type of ES recombination (global or standard)
# --crossObj=discrete # -O : Recombination of object variables (discrete, intermediate or none)
# --crossStdev=intermediate # -S : Recombination of mutation strategy parameters (intermediate, discrete or none)
# --TauLoc=1 # -l : Local Tau (before normalization)

View file

@ -0,0 +1,26 @@
noinst_PROGRAMS = BitEA RealEA ESEA
BitEA_SOURCES = BitEA.cpp
RealEA_SOURCES = RealEA.cpp
ESEA_SOURCES = ESEA.cpp
noinst_HEADERS = binary_value.h \
real_value.h
extra_DIST = Makefile.simple
AM_CXXFLAGS = -I$(top_srcdir)/src
LIBEO = $(top_builddir)/src/libeo.a
LIBES = $(top_builddir)/src/es/libes.a
LIBGA = $(top_builddir)/src/ga/libga.a
LIBUTILS = $(top_builddir)/src/utils/libeoutils.a
DEPS = $(LIBEO) $(LIBUTILS) $(LIBES) $(LIBGA)
LIBS = $(LIBES) $(LIBGA) $(LIBEO) $(LIBUTILS)

View file

@ -0,0 +1,33 @@
### This Makefile is part of the tutorial of the EO library
# Unlike other Makefiles in EO, it is not using the automake/autoconf
# so that it stays easy to understant (you are in the tutorial, remember!)
# MS, Oct. 2002
# if you use this Makefile as a starting point for another application
# you might need to modify the following
DIR_EO = ../../src
.SUFFIXES: .cpp
# Warning: $(CXX) in Linux (RedHat and Mandrake at least) is g++
# However, if you are using this Makefile within xemacs,
# and have problems with the interpretation of the output (and its colors)
# then you should use c++ instead (make CXX=c++ will do)
.cpp: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -o $@ $*.cpp $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
.cpp.o: ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.3\" -I. -I$(DIR_EO) -Wall -g -c $*.cpp
ALL = BitEA RealEA ESEA
all : $(ALL)
BitEA : BitEA.o ;
$(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.2\" -Wall -g -o $@ $< $(DIR_EO)/ga/libga.a $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
RealEA : RealEA.o ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.2\" -Wall -g -o $@ $< $(DIR_EO)/es/libes.a $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
ESEA : ESEA.o ; $(CXX) -DPACKAGE=\"eo\" -DVERSION=\"0.9.2\" -Wall -g -o $@ $< $(DIR_EO)/es/libes.a $(DIR_EO)/utils/libeoutils.a $(DIR_EO)/libeo.a
clean :
@/bin/rm $(ALL) *.o *.sav *.xg *.status *~

View file

@ -0,0 +1,72 @@
#include <iostream>
#include <es/make_real.h>
#include "real_value.h"
#include <apply.h>
using namespace std;
int main(int argc, char* argv[])
{
try
{
typedef eoReal<eoMinimizingFitness> EOT;
eoParser parser(argc, argv); // for user-parameter reading
eoState state; // keeps all things allocated
///// FIRST, problem or representation dependent stuff
//////////////////////////////////////////////////////
// The evaluation fn - encapsulated into an eval counter for output
eoEvalFuncPtr<EOT, double, const std::vector<double>&>
mainEval( real_value );
eoEvalFuncCounter<EOT> eval(mainEval);
// the genotype - through a genotype initializer
eoRealInitBounded<EOT>& init = make_genotype(parser, state, EOT());
// Build the variation operator (any seq/prop construct)
eoGenOp<EOT>& op = make_op(parser, state, init);
//// Now the representation-independent things
//////////////////////////////////////////////
// initialize the population - and evaluate
// yes, this is representation indepedent once you have an eoInit
eoPop<EOT>& pop = make_pop(parser, state, init);
// stopping criteria
eoContinue<EOT> & term = make_continue(parser, state, eval);
// output
eoCheckPoint<EOT> & checkpoint = make_checkpoint(parser, state, eval, term);
// algorithm (need the operator!)
eoAlgo<EOT>& ea = make_algo_scalar(parser, state, eval, checkpoint, op);
///// End of construction of the algorith
/////////////////////////////////////////
// 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<EOT>(eval, pop);
// print it out
cout << "Initial Population\n";
pop.sortedPrintOn(cout);
cout << endl;
run_ea(ea, pop); // run the ea
cout << "Final Population\n";
pop.sortedPrintOn(cout);
cout << endl;
}
catch(exception& e)
{
cout << e.what() << endl;
}
}

View file

@ -0,0 +1,57 @@
###### General ######
# --help=0 # -h : Prints this message
# --stopOnUnknownParam=1 # Stop if unkown param entered
# --seed=1104133126 # -S : Random number seed
###### Evolution Engine ######
--popSize=10 # -P : Population Size
--selection=Sequential # -S : Selection: DetTour(T), StochTour(t), Roulette, Ranking(p,e) or Sequential(ordered/unordered)
--nbOffspring=700% # -O : Nb of offspring (percentage or absolute)
--replacement=Plus # -R : Replacement: Comma, Plus or EPTour(T), SSGAWorst, SSGADet(T), SSGAStoch(t)
--weakElitism=0 # -w : Old best parent replaces new worst offspring *if necessary*
###### Genotype Initialization ######
# --vecSize=10 # -n : The number of variables
# --initBounds=10[-1,1] # -B : Bounds for initialization (MUST be bounded)
--sigmaInit=0.3% # -s : Initial value for Sigmas (with a '%' -> scaled by the range of each variable)
###### Output ######
# --useEval=1 # Use nb of eval. as counter (vs nb of gen.)
# --useTime=1 # Display time (s) every generation
# --printBestStat=1 # Print Best/avg/stdev every gen.
# --printPop=0 # Print sorted pop. every gen.
###### Output - Disk ######
# --resDir=Res # Directory to store DISK outputs
# --eraseDir=1 # erase files in dirName if any
# --fileBestStat=0 # Output bes/avg/std to file
###### Output - Graphical ######
# --plotBestStat=0 # Plot Best/avg Stat
# --plotHisto=0 # Plot histogram of fitnesses
###### Persistence ######
# --Load= # -L : A save file to restart from
# --recomputeFitness=0 # -r : Recompute the fitness after re-loading the pop.?
# --saveFrequency=0 # Save every F generation (0 = only final state, absent = never)
# --saveTimeInterval=0 # Save every T seconds (0 or absent = never)
# --status=t-eoESAll.status # Status file
###### Stopping criterion ######
# --maxGen=100 # -G : Maximum number of generations () = none)
# --steadyGen=100 # -s : Number of generations with no improvement
# --minGen=0 # -g : Minimum number of generations
# --maxEval=0 # -E : Maximum number of evaluations (0 = none)
# --targetFitness=0 # -T : Stop when fitness reaches
# --CtrlC=0 # -C : Terminate current generation upon Ctrl C
###### Variation Operators ######
# --objectBounds=10[-inf,+inf] # -B : Bounds for variables
# --operator=SGA # -o : Description of the operator (SGA only now)
# --pCross=1 # -C : Probability of Crossover
# --pMut=1 # -M : Probability of Mutation
# --crossType=global # -C : Type of ES recombination (global or standard)
# --crossObj=discrete # -O : Recombination of object variables (discrete, intermediate or none)
# --crossStdev=intermediate # -S : Recombination of mutation strategy parameters (intermediate, discrete or none)
# --TauLoc=1 # -l : Local Tau (before normalization)

View file

@ -0,0 +1,25 @@
#include <eo>
//-----------------------------------------------------------------------------
/** Just a simple function that takes binary value of a chromosome and sets
the fitnes.
@param _chrom A binary chromosome
*/
template <class Chrom> double binary_value(const Chrom& _chrom)
{
double sum = 0;
for (unsigned i = 0; i < _chrom.size(); i++)
if (_chrom[i])
sum += _chrom[i];
return sum;
}
struct BinaryValue
{
template <class Chrom> void operator()(Chrom& _chrom)
{
_chrom.fitness(binary_value(_chrom));
}
};

View file

@ -0,0 +1,19 @@
#include <vector>
//-----------------------------------------------------------------------------
/** Just a simple function that takes an eoEsBase<double> and sets the fitnes
to sphere
@param _ind vector<double>
*/
double real_value(const std::vector<double>& _ind)
{
double sum = 0;
for (unsigned i = 0; i < _ind.size(); i++)
sum += _ind[i] * _ind[i];
return sqrt(sum);
}