Simplify configuration.
Remove support for (outdated) <strstream>, require <sstream>. Require uint32_t for now, defined in stdint.h according to C99. Some general cleanup and more documentation.
This commit is contained in:
parent
abe55a641a
commit
cf2a57dd88
46 changed files with 482 additions and 886 deletions
|
|
@ -10,16 +10,8 @@
|
|||
#include <config.h>
|
||||
#endif
|
||||
|
||||
// standard includes
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#ifdef HAVE_SSTREAM
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
#endif
|
||||
|
||||
// the general include for eo
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
|
@ -27,7 +19,7 @@
|
|||
// Use functions from namespace std
|
||||
using namespace std;
|
||||
|
||||
// REPRESENTATION
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your individuals
|
||||
typedef eoBit<double> Indi; // A bitstring with fitness double
|
||||
|
|
@ -63,7 +55,7 @@ void main_function(int argc, char **argv)
|
|||
//////////////////////////
|
||||
// Random seed
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
|
|
@ -136,21 +128,21 @@ void main_function(int argc, char **argv)
|
|||
/////////////////////////////////////
|
||||
// stop after MAX_GEN generations
|
||||
eoGenContinue<Indi> continuator(MAX_GEN);
|
||||
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
// standard Generational GA requires as parameters
|
||||
// selection, evaluation, crossover and mutation, stopping criterion
|
||||
|
||||
|
||||
eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE,
|
||||
|
||||
eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE,
|
||||
eval, continuator);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
gga(pop);
|
||||
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
|
|
|
|||
|
|
@ -9,16 +9,9 @@
|
|||
#include <config.h>
|
||||
#endif
|
||||
|
||||
// standard includes
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#ifdef HAVE_SSTREAM
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
#endif
|
||||
|
||||
// the general include for eo
|
||||
|
||||
#include <eo>
|
||||
#include <es.h>
|
||||
|
|
@ -34,7 +27,7 @@ using namespace std;
|
|||
// EVAL
|
||||
//-----------------------------------------------------------------------------
|
||||
// a simple fitness function that computes the euclidian norm of a real vector
|
||||
// @param _indi A real-valued individual
|
||||
// @param _indi A real-valued individual
|
||||
|
||||
double real_value(const Indi & _indi)
|
||||
{
|
||||
|
|
@ -62,7 +55,7 @@ void main_function(int argc, char **argv)
|
|||
//////////////////////////
|
||||
// Random seed
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
|
|
@ -121,7 +114,7 @@ void main_function(int argc, char **argv)
|
|||
eoSegmentCrossover<Indi> xover;
|
||||
// MUTATION
|
||||
// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]
|
||||
eoUniformMutation<Indi> mutation(EPSILON);
|
||||
eoUniformMutation<Indi> mutation(EPSILON);
|
||||
|
||||
// STOP
|
||||
// CHECKPOINT
|
||||
|
|
@ -130,21 +123,21 @@ void main_function(int argc, char **argv)
|
|||
/////////////////////////////////////
|
||||
// stop after MAX_GEN generations
|
||||
eoGenContinue<Indi> continuator(MAX_GEN);
|
||||
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
// standard Generational GA requires
|
||||
// selection, evaluation, crossover and mutation, stopping criterion
|
||||
|
||||
|
||||
eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE,
|
||||
|
||||
eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE,
|
||||
eval, continuator);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
gga(pop);
|
||||
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
|
|
|
|||
|
|
@ -12,11 +12,6 @@
|
|||
// standard includes
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#ifdef HAVE_SSTREAM
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream>
|
||||
#endif
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
|
|
@ -57,7 +52,7 @@ void main_function(int argc, char **argv)
|
|||
//////////////////////////
|
||||
// Random seed
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
|
|
@ -96,10 +91,10 @@ void main_function(int argc, char **argv)
|
|||
// selection and replacement
|
||||
////////////////////////////////////
|
||||
|
||||
// solution solution solution: uncomment one of the following,
|
||||
// solution solution solution: uncomment one of the following,
|
||||
// comment out the eoDetTournament lines
|
||||
|
||||
// The well-known roulette
|
||||
// The well-known roulette
|
||||
// eoProportionalSelect<Indi> select;
|
||||
|
||||
// could also use stochastic binary tournament selection
|
||||
|
|
@ -121,7 +116,7 @@ void main_function(int argc, char **argv)
|
|||
/////////////////////////////////////
|
||||
// stop after MAX_GEN generations
|
||||
eoGenContinue<Indi> continuator(MAX_GEN);
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////
|
||||
// The variation operators
|
||||
|
|
@ -136,14 +131,14 @@ void main_function(int argc, char **argv)
|
|||
////////////////////////////////////////
|
||||
// standard Generational GA requires as parameters
|
||||
// selection, evaluation, crossover and mutation, stopping criterion
|
||||
|
||||
|
||||
eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE,
|
||||
|
||||
eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE,
|
||||
eval, continuator);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
gga(pop);
|
||||
|
||||
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
cout << "FINAL Population\n" << pop << endl;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// FirstBitEA.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// Still an instance of a VERY simple Bitstring Genetic Algorithm
|
||||
// Still an instance of a VERY simple Bitstring Genetic Algorithm
|
||||
// (see FirstBitGA.cpp) but now with Breeder - and Combined Ops
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -11,13 +11,8 @@
|
|||
#endif
|
||||
|
||||
// standard includes
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#ifdef HAVE_SSTREAM
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
#endif
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
|
|
@ -68,7 +63,7 @@ void main_function(int argc, char **argv)
|
|||
//////////////////////////
|
||||
// Random seed
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
|
|
@ -112,9 +107,9 @@ void main_function(int argc, char **argv)
|
|||
eoSelectPerc<Indi> select(selectOne);// by default rate==1
|
||||
|
||||
// REPLACE
|
||||
// And we now have the full slection/replacement - though with
|
||||
// And we now have the full slection/replacement - though with
|
||||
// no replacement (== generational replacement) at the moment :-)
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
|
|
@ -136,7 +131,7 @@ void main_function(int argc, char **argv)
|
|||
// standard bit-flip mutation for bitstring
|
||||
eoBitMutation<Indi> mutationBitFlip(P_MUT_PER_BIT);
|
||||
// mutate exactly 1 bit per individual
|
||||
eoDetBitFlip<Indi> mutationOneBit;
|
||||
eoDetBitFlip<Indi> mutationOneBit;
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedMonOp<Indi> mutation(mutationBitFlip, bitFlipRate);
|
||||
mutation.add(mutationOneBit, oneBitRate, true);
|
||||
|
|
@ -159,20 +154,20 @@ void main_function(int argc, char **argv)
|
|||
eoCombinedContinue<Indi> continuator(genCont);
|
||||
continuator.add(steadyCont);
|
||||
continuator.add(fitCont);
|
||||
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
|
||||
// Easy EA requires
|
||||
// Easy EA requires
|
||||
// selection, transformation, eval, replacement, and stopping criterion
|
||||
eoEasyEA<Indi> gga(continuator, eval, select, transform, replace);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
cout << "\n Here we go\n\n";
|
||||
gga(pop);
|
||||
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// FirstRealEA.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// Still an instance of a VERY simple Real-coded Genetic Algorithm
|
||||
// Still an instance of a VERY simple Real-coded Genetic Algorithm
|
||||
// (see FirstBitGA.cpp) but now with Breeder - and Combined Ops
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -11,13 +11,8 @@
|
|||
#endif
|
||||
|
||||
// standard includes
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#ifdef HAVE_SSTREAM
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
#endif
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
|
|
@ -26,7 +21,7 @@
|
|||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your individuals
|
||||
typedef eoReal<double> Indi;
|
||||
typedef eoReal<double> Indi;
|
||||
|
||||
// Use functions from namespace std
|
||||
using namespace std;
|
||||
|
|
@ -69,7 +64,7 @@ void main_function(int argc, char **argv)
|
|||
//////////////////////////
|
||||
// Random seed
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
|
|
@ -90,7 +85,7 @@ void main_function(int argc, char **argv)
|
|||
eoInitFixedLength<Indi> random(VEC_SIZE, uGen);
|
||||
// Initialization of the population
|
||||
eoPop<Indi> pop(POP_SIZE, random);
|
||||
|
||||
|
||||
// and evaluate it in one loop
|
||||
apply<Indi>(eval, pop); // STL syntax
|
||||
|
||||
|
|
@ -112,9 +107,9 @@ void main_function(int argc, char **argv)
|
|||
eoSelectPerc<Indi> select(selectOne);// by default rate==1
|
||||
|
||||
// REPLACE
|
||||
// And we now have the full slection/replacement - though with
|
||||
// And we now have the full slection/replacement - though with
|
||||
// no replacement (== generational replacement) at the moment :-)
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
|
|
@ -131,11 +126,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// MUTATION
|
||||
// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]
|
||||
eoUniformMutation<Indi> mutationU(EPSILON);
|
||||
eoUniformMutation<Indi> mutationU(EPSILON);
|
||||
// k (=1) coordinates of parents are uniformly modified
|
||||
eoDetUniformMutation<Indi> mutationD(EPSILON);
|
||||
eoDetUniformMutation<Indi> mutationD(EPSILON);
|
||||
// all coordinates of parents are normally modified (stDev SIGMA)
|
||||
eoNormalMutation<Indi> mutationN(SIGMA);
|
||||
eoNormalMutation<Indi> mutationN(SIGMA);
|
||||
// Combine them with relative weights
|
||||
eoPropCombinedMonOp<Indi> mutation(mutationU, uniformMutRate);
|
||||
mutation.add(mutationD, detMutRate);
|
||||
|
|
@ -156,7 +151,7 @@ void main_function(int argc, char **argv)
|
|||
eoCombinedContinue<Indi> continuator(genCont);
|
||||
continuator.add(steadyCont);
|
||||
continuator.add(fitCont);
|
||||
|
||||
|
||||
// The operators are encapsulated into an eoTRansform object
|
||||
eoSGATransform<Indi> transform(xover, P_CROSS, mutation, P_MUT);
|
||||
|
||||
|
|
@ -165,14 +160,14 @@ void main_function(int argc, char **argv)
|
|||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
|
||||
// Easy EA requires
|
||||
// Easy EA requires
|
||||
// selection, transformation, eval, replacement, and stopping criterion
|
||||
eoEasyEA<Indi> gga(continuator, eval, select, transform, replace);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
cout << "\n Here we go\n\n";
|
||||
gga(pop);
|
||||
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// FirstBitEA.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
//*
|
||||
// Still an instance of a VERY simple Bitstring Genetic Algorithm
|
||||
// Still an instance of a VERY simple Bitstring Genetic Algorithm
|
||||
// (see FirstBitGA.cpp) but now with Breeder - and Combined Ops
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -11,13 +11,8 @@
|
|||
#endif
|
||||
|
||||
// standard includes
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#ifdef HAVE_SSTREAM
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
#endif
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
|
|
@ -68,7 +63,7 @@ void main_function(int argc, char **argv)
|
|||
//////////////////////////
|
||||
// Random seed
|
||||
//////////////////////////
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(SEED);
|
||||
|
||||
|
|
@ -108,7 +103,7 @@ void main_function(int argc, char **argv)
|
|||
// SELECT
|
||||
// The robust tournament selection
|
||||
eoDetTournamentSelect<Indi> selectOne(T_SIZE); // T_SIZE in [2,POP_SIZE]
|
||||
// solution solution solution solution solution solution solution
|
||||
// solution solution solution solution solution solution solution
|
||||
// modify the nb offspring / rate in the constructor. 2 ways:
|
||||
// second arg treated as integer
|
||||
eoSelectMany<Indi> select(selectOne,2, eo_is_an_integer);
|
||||
|
|
@ -116,10 +111,10 @@ void main_function(int argc, char **argv)
|
|||
// eoSelectMany<Indi> select(selectOne,0.1);
|
||||
|
||||
// REPLACE
|
||||
// solution solution solution solution solution solution solution
|
||||
// solution solution solution solution solution solution solution
|
||||
// eoCommaReplacement keeps the best among offspring
|
||||
// eoPlusReplacement keeps the best among parents + offspring
|
||||
// eoCommaReplacement<Indi> replace;
|
||||
// eoCommaReplacement<Indi> replace;
|
||||
eoPlusReplacement<Indi> replace;
|
||||
|
||||
// OPERATORS
|
||||
|
|
@ -142,7 +137,7 @@ void main_function(int argc, char **argv)
|
|||
// standard bit-flip mutation for bitstring
|
||||
eoBitMutation<Indi> mutationBitFlip(P_MUT_PER_BIT);
|
||||
// mutate exactly 1 bit per individual
|
||||
eoDetBitFlip<Indi> mutationOneBit;
|
||||
eoDetBitFlip<Indi> mutationOneBit;
|
||||
// Combine them with relative rates
|
||||
eoPropCombinedMonOp<Indi> mutation(mutationBitFlip, bitFlipRate);
|
||||
mutation.add(mutationOneBit, oneBitRate, true);
|
||||
|
|
@ -165,19 +160,19 @@ void main_function(int argc, char **argv)
|
|||
eoCombinedContinue<Indi> continuator(genCont);
|
||||
continuator.add(steadyCont);
|
||||
continuator.add(fitCont);
|
||||
|
||||
|
||||
// GENERATION
|
||||
/////////////////////////////////////////
|
||||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
|
||||
// Easy EA requires
|
||||
// Easy EA requires
|
||||
// selection, transformation, eval, replacement, and stopping criterion
|
||||
eoEasyEA<Indi> gga(continuator, eval, select, transform, replace);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
gga(pop);
|
||||
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
|
|
|
|||
|
|
@ -14,11 +14,6 @@
|
|||
#include <fstream>
|
||||
#include <iostream> // cout
|
||||
#include <stdexcept> // runtime_error
|
||||
#ifdef HAVE_SSTREAM
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
#endif
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
|
|
|
|||
|
|
@ -15,12 +15,7 @@
|
|||
// standard includes
|
||||
#include <fstream>
|
||||
#include <iostream> // cout
|
||||
#include <stdexcept> // runtime_error
|
||||
#ifdef HAVE_SSTREAM
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
#endif
|
||||
#include <stdexcept> // runtime_error
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
|
|
@ -29,7 +24,7 @@
|
|||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your individuals
|
||||
typedef eoReal<eoMinimizingFitness> Indi;
|
||||
typedef eoReal<eoMinimizingFitness> Indi;
|
||||
|
||||
// Use functions from namespace std
|
||||
using namespace std;
|
||||
|
|
@ -50,18 +45,18 @@ void main_function(int argc, char **argv)
|
|||
//-----------------------------------------------------------------------------
|
||||
// instead of having all values of useful parameters as constants, read them:
|
||||
// either on the command line (--option=value or -o=value)
|
||||
// or in a parameter file (same syntax, order independent,
|
||||
// # = usual comment character
|
||||
// or in a parameter file (same syntax, order independent,
|
||||
// # = usual comment character
|
||||
// or in the environment (TODO)
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
|
||||
// For each parameter, you can in on single line
|
||||
// define the parameter, read it through the parser, and assign it
|
||||
|
||||
|
||||
unsigned seed = parser.createParam(unsigned(time(0)), "seed", "Random number seed", 'S').value(); // will be in default section General
|
||||
|
||||
|
||||
// description of genotype
|
||||
unsigned vecSize = parser.createParam(unsigned(8), "vecSize", "Genotype size",'V', "Representation" ).value();
|
||||
|
||||
|
|
@ -72,7 +67,7 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// init and stop
|
||||
string loadName = parser.createParam(string(""), "Load","A save file to restart from",'L', "Persistence" ).value();
|
||||
|
||||
|
||||
unsigned maxGen = parser.createParam(unsigned(100), "maxGen", "Maximum number of generations",'G', "Stopping criterion" ).value();
|
||||
|
||||
unsigned minGen = parser.createParam(unsigned(100), "minGen", "Minimum number of generations",'g', "Stopping criterion" ).value();
|
||||
|
|
@ -91,7 +86,7 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// internal parameters for the mutations
|
||||
double EPSILON = parser.createParam(double(0.01), "EPSILON", "Width for uniform mutation", '\0', "Genetic Operators" ).value();
|
||||
|
||||
|
||||
double SIGMA = parser.createParam(double(0.3), "SIGMA", "Sigma for normal mutation", '\0', "Genetic Operators" ).value();
|
||||
|
||||
// relative rates for mutations
|
||||
|
|
@ -101,7 +96,7 @@ void main_function(int argc, char **argv)
|
|||
|
||||
double normalMutRate = parser.createParam(double(1), "normalMutRate", "Relative rate for normal mutation", '\0', "Genetic Operators" ).value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
string statusName = parser.createParam(str_status, "status","Status file",'S', "Persistence" ).value();
|
||||
|
||||
|
|
@ -142,11 +137,11 @@ void main_function(int argc, char **argv)
|
|||
// eventually with different parameters
|
||||
inState.registerObject(rng);
|
||||
inState.registerObject(pop);
|
||||
|
||||
|
||||
if (loadName != "")
|
||||
{
|
||||
inState.load(loadName); // load the pop and the rng
|
||||
// the fitness is read in the file:
|
||||
// the fitness is read in the file:
|
||||
// do only evaluate the pop if the fitness has changed
|
||||
}
|
||||
else
|
||||
|
|
@ -156,10 +151,10 @@ void main_function(int argc, char **argv)
|
|||
// based on boolean_generator class (see utils/rnd_generator.h)
|
||||
eoUniformGenerator<double> uGen(-1.0, 1.0);
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
|
||||
// Init pop from the randomizer: need to use the append function
|
||||
pop.append(popSize, random);
|
||||
// and evaluate pop (STL syntax)
|
||||
pop.append(popSize, random);
|
||||
// and evaluate pop (STL syntax)
|
||||
apply<Indi>(eval, pop);
|
||||
} // end of initializatio of the population
|
||||
|
||||
|
|
@ -181,9 +176,9 @@ void main_function(int argc, char **argv)
|
|||
eoSelectPerc<Indi> select(selectOne);// by default rate==1
|
||||
|
||||
// REPLACE
|
||||
// And we now have the full slection/replacement - though with
|
||||
// And we now have the full slection/replacement - though with
|
||||
// no replacement (== generational replacement) at the moment :-)
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
eoGenerationalReplacement<Indi> replace;
|
||||
|
||||
// OPERATORS
|
||||
//////////////////////////////////////
|
||||
|
|
@ -200,11 +195,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// MUTATION
|
||||
// offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]
|
||||
eoUniformMutation<Indi> mutationU(EPSILON);
|
||||
eoUniformMutation<Indi> mutationU(EPSILON);
|
||||
// k (=1) coordinates of parents are uniformly modified
|
||||
eoDetUniformMutation<Indi> mutationD(EPSILON);
|
||||
eoDetUniformMutation<Indi> mutationD(EPSILON);
|
||||
// all coordinates of parents are normally modified (stDev SIGMA)
|
||||
eoNormalMutation<Indi> mutationN(SIGMA);
|
||||
eoNormalMutation<Indi> mutationN(SIGMA);
|
||||
// Combine them with relative weights
|
||||
eoPropCombinedMonOp<Indi> mutation(mutationU, uniformMutRate);
|
||||
mutation.add(mutationD, detMutRate);
|
||||
|
|
@ -223,27 +218,27 @@ void main_function(int argc, char **argv)
|
|||
eoCombinedContinue<Indi> continuator(genCont);
|
||||
continuator.add(steadyCont);
|
||||
continuator.add(fitCont);
|
||||
|
||||
|
||||
|
||||
|
||||
// CHECKPOINT
|
||||
// but now you want to make many different things every generation
|
||||
// but now you want to make many different things every generation
|
||||
// (e.g. statistics, plots, ...).
|
||||
// the class eoCheckPoint is dedicated to just that:
|
||||
|
||||
// Declare a checkpoint (from a continuator: an eoCheckPoint
|
||||
// Declare a checkpoint (from a continuator: an eoCheckPoint
|
||||
// IS AN eoContinue and will be called in the loop of all algorithms)
|
||||
eoCheckPoint<Indi> checkpoint(continuator);
|
||||
|
||||
|
||||
// Create a counter parameter
|
||||
eoValueParam<unsigned> generationCounter(0, "Gen.");
|
||||
|
||||
// Create an incrementor (sub-class of eoUpdater). Note that the
|
||||
// parameter's value is passed by reference,
|
||||
|
||||
// Create an incrementor (sub-class of eoUpdater). Note that the
|
||||
// parameter's value is passed by reference,
|
||||
// so every time the incrementer is updated (every generation),
|
||||
// the data in generationCounter will change.
|
||||
eoIncrementor<unsigned> increment(generationCounter.value());
|
||||
|
||||
// Add it to the checkpoint,
|
||||
// Add it to the checkpoint,
|
||||
// so the counter is updated (here, incremented) every generation
|
||||
checkpoint.add(increment);
|
||||
|
||||
|
|
@ -259,11 +254,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// The Stdout monitor will print parameters to the screen ...
|
||||
eoStdoutMonitor monitor(false);
|
||||
|
||||
|
||||
// when called by the checkpoint (i.e. at every generation)
|
||||
checkpoint.add(monitor);
|
||||
|
||||
// the monitor will output a series of parameters: add them
|
||||
// the monitor will output a series of parameters: add them
|
||||
monitor.add(generationCounter);
|
||||
monitor.add(eval); // because now eval is an eoEvalFuncCounter!
|
||||
monitor.add(bestStat);
|
||||
|
|
@ -271,7 +266,7 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// A file monitor: will print parameters to ... a File, yes, you got it!
|
||||
eoFileMonitor fileMonitor("stats.xg", " ");
|
||||
|
||||
|
||||
// the checkpoint mechanism can handle multiple monitors
|
||||
checkpoint.add(fileMonitor);
|
||||
|
||||
|
|
@ -289,9 +284,9 @@ void main_function(int argc, char **argv)
|
|||
|
||||
// and feed the state to state savers
|
||||
// save state every 100th generation
|
||||
eoCountedStateSaver stateSaver1(20, outState, "generation");
|
||||
// save state every 1 seconds
|
||||
eoTimedStateSaver stateSaver2(1, outState, "time");
|
||||
eoCountedStateSaver stateSaver1(20, outState, "generation");
|
||||
// save state every 1 seconds
|
||||
eoTimedStateSaver stateSaver2(1, outState, "time");
|
||||
|
||||
// Don't forget to add the two savers to the checkpoint
|
||||
checkpoint.add(stateSaver1);
|
||||
|
|
@ -303,13 +298,13 @@ void main_function(int argc, char **argv)
|
|||
// the algorithm
|
||||
////////////////////////////////////////
|
||||
|
||||
// Easy EA requires
|
||||
// Easy EA requires
|
||||
// stopping criterion, eval, selection, transformation, replacement
|
||||
eoEasyEA<Indi> gga(checkpoint, eval, select, transform, replace);
|
||||
|
||||
// Apply algo to pop - that's it!
|
||||
gga(pop);
|
||||
|
||||
|
||||
// OUTPUT
|
||||
// Print (sorted) intial population
|
||||
pop.sort();
|
||||
|
|
|
|||
|
|
@ -14,11 +14,6 @@
|
|||
#include <fstream>
|
||||
#include <iostream> // cout
|
||||
#include <stdexcept> // runtime_error
|
||||
#ifdef HAVE_SSTREAM
|
||||
#include <sstream>
|
||||
#else
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
#endif
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
noinst_PROGRAMS = BitEA RealEA ESEA
|
||||
|
||||
|
||||
|
|
@ -15,9 +14,13 @@ noinst_HEADERS = binary_value.h \
|
|||
extra_DIST = Makefile.simple
|
||||
|
||||
|
||||
LDADD = -L$(top_builddir)/src -L$(top_builddir)/src/es \
|
||||
-L$(top_builddir)/src/ga -L$(top_builddir)/src/utils
|
||||
AM_CXXFLAGS = -I$(top_srcdir)/src
|
||||
|
||||
LIBS = -lga -les -leoutils -leo
|
||||
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
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/src
|
||||
DEPS = $(LIBEO) $(LIBUTILS) $(LIBES) $(LIBGA)
|
||||
|
||||
LIBS = $(LIBES) $(LIBGA) $(LIBEO) $(LIBUTILS)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,12 @@ noinst_HEADERS = eoOneMax.h \
|
|||
extra_DIST = Makefile.simple
|
||||
|
||||
AM_CXXFLAGS = -I$(top_srcdir)/src
|
||||
LDADD = -L$(top_builddir)/src -L$(top_builddir)/src/ga -L$(top_builddir)/src/utils
|
||||
LIBS = -lga -leoutils -leo
|
||||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -14,14 +14,14 @@ Template for simple mutation operators
|
|||
|
||||
#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>
|
||||
template<class GenotypeT>
|
||||
class eoOneMaxMutation: public eoMonOp<GenotypeT>
|
||||
{
|
||||
public:
|
||||
|
|
@ -30,7 +30,7 @@ public:
|
|||
*/
|
||||
// START eventually add or modify the anyVariable argument
|
||||
eoOneMaxMutation()
|
||||
// eoOneMaxMutation( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// eoOneMaxMutation( varType _anyVariable) : anyVariable(_anyVariable)
|
||||
// END eventually add or modify the anyVariable argument
|
||||
{
|
||||
// START Code of Ctor of an eoOneMaxEvalFunc object
|
||||
|
|
@ -44,7 +44,7 @@ public:
|
|||
* modifies the parent
|
||||
* @param _genotype The parent genotype (will be modified)
|
||||
*/
|
||||
bool operator()(GenotypeT & _genotype)
|
||||
bool operator()(GenotypeT & _genotype)
|
||||
{
|
||||
bool isModified;
|
||||
// START code for mutation of the _genotype object
|
||||
|
|
|
|||
Reference in a new issue