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;
|
||||
|
|
|
|||
Reference in a new issue