From 9d9958d3bc673f9e0dc850dacd3fce9ec084a1cb Mon Sep 17 00:00:00 2001 From: evomarc Date: Sat, 27 Jan 2001 08:20:39 +0000 Subject: [PATCH] Following the change in includes (added ga.h and es.h everywhere pfuhh) --- eo/tutorial/html/FirstBitEA.html | 615 ++++++++++++++---------------- eo/tutorial/html/FirstBitGA.html | 560 +++++++++++++-------------- eo/tutorial/html/FirstRealEA.html | 39 +- eo/tutorial/html/FirstRealGA.html | 492 +++++++++++------------- eo/tutorial/html/Firstmerge.html | 14 +- eo/tutorial/html/SecondBitEA.html | 4 +- eo/tutorial/html/eoLesson1.html | 11 +- eo/tutorial/html/eoLesson2.html | 26 +- 8 files changed, 836 insertions(+), 925 deletions(-) diff --git a/eo/tutorial/html/FirstBitEA.html b/eo/tutorial/html/FirstBitEA.html index 0663d8a2..6b06faac 100644 --- a/eo/tutorial/html/FirstBitEA.html +++ b/eo/tutorial/html/FirstBitEA.html @@ -2,9 +2,9 @@ - + FirstBitEA.cpp - + Back to Lesson 2 - Tutorial @@ -16,344 +16,319 @@ documentation

FirstBitEA.cpp

-Click on the figure to see the corresponding code.
-In the code, the colors are meaningfull
-The actual code is in boldface and the comment in normal face. -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
  - +Click on the figure to see the corresponding code. +
In the code, the colors are meaningfull +
The actual code is in boldface and the comment in normal face. +
+
- +
-//-----------------------------------------------------------------------------
-// FirstBitEA.cpp
-//-----------------------------------------------------------------------------
-//*
-// Still an instance of a VERY simple Bitstring Genetic Algorithm
-// (see FirstBitGA.cpp) but now with  Breeder - and Combined Ops
-//
-//-----------------------------------------------------------------------------
-// standard includes
-#include <stdexcept>  // runtime_error
-#include <iostream>    // cout
-#include <strstream>  // ostrstream, istrstream
-// the general include for eo
-#include <eo>
-
-
//----------------------------------------------------------------------------- +
// FirstBitEA.cpp +
//----------------------------------------------------------------------------- +
//* +
// Still an instance of a VERY simple Bitstring +Genetic Algorithm  +
// (see FirstBitGA.cpp) but now with  +Breeder - and Combined Ops +
// +
//----------------------------------------------------------------------------- +
// standard includes +
#include <stdexcept>  // runtime_error  +
#include <iostream>    +// cout +
#include <strstream>  // ostrstream, +istrstream +
// the general include for eo +
#include <eo>
- + +
+ + + +
//----------------------------------------------------------------------------- +
// Include the corresponding file  +
#include <ga.h>          +// bitstring representation & operators  +
// define your individuals +
typedef eoBin<double> Indi; // +A bitstring with fitness double
+ + + + + +
//----------------------------------------------------------------------------- +
// a simple fitness function that computes +the number of ones of a bitstring +
// Now in a separate file, and declared as +binary_value(const vector<bool> &) +
#include "binary_value.h"
+ + + + + +
//----------------------------------------------------------------------------- +
void main_function(int argc, char **argv) +
{
+ + + + + +
 const unsigned int SEED = 42; // +seed for random number generator +
 const unsigned int T_SIZE = 3; // +size for tournament selection +
 const unsigned int VEC_SIZE = 8; +// Number of bits in genotypes +
 const unsigned int POP_SIZE = 20; +// Size of population +
 const unsigned int MAX_GEN = 500; +// Maximum number of generation before STOP +
 const float CROSS_RATE = 0.8; // +Crossover rate +
 const double P_MUT_PER_BIT = 0.01; +// probability of bit-flip mutation +
 const float MUT_RATE = 1.0; // +mutation rate +
 // some parameters for chosing +among different operators +
 const double onePointRate = 0.5;        +// rate for 1-pt Xover +
 const double twoPointsRate = 0.5;        +// rate for 2-pt Xover +
 const double URate = 0.5;                      +// rate for Uniform Xover +
 const double bitFlipRate = 0.5;          +// rate for bit-flip mutation +
 const double oneBitRate = 0.5;            +// rate for one-bit mutation
+ + + + + +
 ////////////////////////// +
 //  Random seed +
 ////////////////////////// +
 //reproducible random seed: +if you don't change SEED above,  +
 // you'll aways get the same +result, NOT a random run +
 rng.reseed(SEED);
+ + + + + +
 ///////////////////////////// +
 // Fitness function +
 //////////////////////////// +
 // Evaluation: from a plain +C++ fn to an EvalFunc Object +
 // you need to give the full +description of the function +
 eoEvalFuncPtr<Indi, double, const +vector<bool>& > eval(  binary_value );
+ + + + + +
 //////////////////////////////// +
 // Initilisation of population +
 //////////////////////////////// +
 // based on boolean_generator +class (see utils/rnd_generator.h) +
 eoInitFixedLength<Indi, boolean_generator>  +
     random(VEC_SIZE, +boolean_generator()); +
 // Initialization of the population +
 eoPop<Indi> pop(POP_SIZE, random); +
 // and evaluate it in one line +
 apply<Indi>(eval, pop); // +STL syntax
+ + + + + +
 // sort pop before printing +it! +
 pop.sort(); +
 // Print (sorted) intial population +(raw printout) +
 cout << "Initial Population" +<< endl; +
 cout << pop;
+ + + + + +
 ///////////////////////////////////// +
 // selection and replacement +
 ////////////////////////////////////
+ + + + + +
 // The robust tournament selection +
 eoDetTournamentSelect<Indi> selectOne(T_SIZE);            +// T_SIZE in [2,POP_SIZE] +
// +is now encapsulated in a eoSelectPerc (entage) +
 eoSelectPerc<Indi> select(selectOne);// +by default rate==1
+ + + + + +
 // And we now have the full +slection/replacement - though with  +
 // no replacement (== generational +replacement) at the moment :-) +
 eoNoReplacement<Indi> replace; 
+ + + + + +
 ////////////////////////////////////// +
 // The variation operators +
 //////////////////////////////////////
+ + + + + +
 // 1-point crossover for bitstring +
 eoBinCrossover<Indi> xover1; +
 // uniform crossover for bitstring +
 eoBinUxOver<Indi> xoverU; +
 // 2-pots xover +
 eoBinNxOver<Indi> xover2(2); +
 // Combine them with relative +rates +
 eoPropCombinedQuadOp<Indi> xover(xover1, +onePointRate); +
 xover.add(xoverU, URate); +
 xover.add(xover2, twoPointsRate, +true);
+ + +
 // standard bit-flip mutation +for bitstring +
 eoBinMutation<Indi>  mutationBitFlip(P_MUT_PER_BIT); +
 // mutate exactly 1 bit per +individual +
 eoDetBitFlip<Indi> mutationOneBit;  +
 // Combine them with relative +rates +
 eoPropCombinedMonOp<Indi> mutation(mutationBitFlip, +bitFlipRate); +
 mutation.add(mutationOneBit, oneBitRate, +true); +

// The operators +are  encapsulated into an eoTRansform object +
 eoSGATransform<Indi> transform(xover, +CROSS_RATE, mutation, MUT_RATE);

- -//-----------------------------------------------------------------------------
-// define your individuals
-typedef eoBin<double> Indi; // A bitstring with fitness double
-
-
- + +
- +
- -//-----------------------------------------------------------------------------
-// a simple fitness function that computes the number of ones of a bitstring
-// Now in a separate file, and declared as binary_value(const vector<bool> &)
-#include "binary_value.h"
-
-
- + +
- +
- -//-----------------------------------------------------------------------------
-void main_function(int argc, char **argv)
-{
-
-
 ////////////////////////////////////// +
 // termination conditions: use +more than one +
 ///////////////////////////////////// +
 // stop after MAX_GEN generations +
 eoGenContinue<Indi> genCont(MAX_GEN); +
 // do MIN_GEN gen., then stop +after STEADY_GEN gen. without improvement +
 eoSteadyFitContinue<Indi> steadyCont(MIN_GEN, +STEADY_GEN); +
 // stop when fitness reaches +a target (here VEC_SIZE) +
 eoFitContinue<Indi> fitCont(0); +
 // do stop when one of the above +says so +
 eoCombinedContinue<Indi> continuator(genCont); +
 continuator.add(steadyCont); +
 continuator.add(fitCont);
- + +
- +
- -  const unsigned int SEED = 42; // seed for random number generator
-  const unsigned int T_SIZE = 3; // size for tournament selection
-  const unsigned int VEC_SIZE = 8; // Number of bits in genotypes
-  const unsigned int POP_SIZE = 20; // Size of population
-  const unsigned int MAX_GEN = 500; // Maximum number of generation before STOP
-  const float CROSS_RATE = 0.8; // Crossover rate
-  const double P_MUT_PER_BIT = 0.01; // probability of bit-flip mutation
-  const float MUT_RATE = 1.0; // mutation rate
-  // some parameters for chosing among different operators
-  const double onePointRate = 0.5;        // rate for 1-pt Xover
-  const double twoPointsRate = 0.5;        // rate for 2-pt Xover
-  const double URate = 0.5;                      // rate for Uniform Xover
-  const double bitFlipRate = 0.5;          // rate for bit-flip mutation
-  const double oneBitRate = 0.5;            // rate for one-bit mutation
-
-
 ///////////////////////////////////////// +
 // the algorithm +
 //////////////////////////////////////// +
 // 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); +
 
- + +
- +
- -  //////////////////////////
-  //  Random seed
-  //////////////////////////
-  //reproducible random seed: if you don't change SEED above,
-  // you'll aways get the same result, NOT a random run
-  rng.reseed(SEED);
-
-
 // Print (sorted) intial population +
 pop.sort(); +
 cout << "FINAL Population\n" +<< pop << endl;
- + +
- - -
- -  /////////////////////////////
-  // Fitness function
-  ////////////////////////////
-  // Evaluation: from a plain C++ fn to an EvalFunc Object
-  // you need to give the full description of the function
-  eoEvalFuncPtr<Indi, double, const vector<bool>& > eval(  binary_value );
-
-
- - - - -
- -  ////////////////////////////////
-  // Initilisation of population
-  ////////////////////////////////
-  // based on boolean_generator class (see utils/rnd_generator.h)
-  eoInitFixedLength<Indi, boolean_generator>
-      random(VEC_SIZE, boolean_generator());
-  // Initialization of the population
-  eoPop<Indi> pop(POP_SIZE, random);
-  // and evaluate it in one line
-  apply<Indi>(eval, pop); // STL syntax
-
-
- - - - -
- -  // sort pop before printing it!
-  pop.sort();
-  // Print (sorted) intial population (raw printout)
-  cout << "Initial Population" << endl;
-  cout << pop;
-
-
- - - - -
- -  /////////////////////////////////////
-  // selection and replacement
-  ////////////////////////////////////
-
-
- - - - -
- -  // The robust tournament selection
-  eoDetTournamentSelect<Indi> selectOne(T_SIZE);            // T_SIZE in [2,POP_SIZE]
- -  // is now encapsulated in a eoSelectPerc (entage)
-  eoSelectPerc<Indi> select(selectOne);// by default rate==1
-
-
- - - - -
- -  // And we now have the full slection/replacement - though with
-  // no replacement (== generational replacement) at the moment :-)
-  eoNoReplacement<Indi> replace;
-
-
- - - - -
- -  //////////////////////////////////////
-  // The variation operators
-  //////////////////////////////////////
-
-
- - - - -
- -  // 1-point crossover for bitstring
-  eoBinCrossover<Indi> xover1;
-  // uniform crossover for bitstring
-  eoBinUxOver<Indi> xoverU;
-  // 2-pots xover
-  eoBinNxOver<Indi> xover2(2);
-  // Combine them with relative rates
-  eoPropCombinedQuadOp<Indi> xover(xover1, onePointRate);
-  xover.add(xoverU, URate);
-  xover.add(xover2, twoPointsRate, true);
-
-
- - - - -
- -  
-  // standard bit-flip mutation for bitstring
-  eoBinMutation<Indi>  mutationBitFlip(P_MUT_PER_BIT);
-  // mutate exactly 1 bit per individual
-  eoDetBitFlip<Indi> mutationOneBit;
-  // Combine them with relative rates
-  eoPropCombinedMonOp<Indi> mutation(mutationBitFlip, bitFlipRate);
-  mutation.add(mutationOneBit, oneBitRate, true);
-  
- -  // The operators are  encapsulated into an eoTRansform object
-  eoSGATransform<Indi> transform(xover, CROSS_RATE, mutation, MUT_RATE);
-
-
- - - - -
- - -
- - - - -
- -  //////////////////////////////////////
-  // termination conditions: use more than one
-  /////////////////////////////////////
-  // stop after MAX_GEN generations
-  eoGenContinue<Indi> genCont(MAX_GEN);
-  // do MIN_GEN gen., then stop after STEADY_GEN gen. without improvement
-  eoSteadyFitContinue<Indi> steadyCont(MIN_GEN, STEADY_GEN);
-  // stop when fitness reaches a target (here VEC_SIZE)
-  eoFitContinue<Indi> fitCont(0);
-  // do stop when one of the above says so
-  eoCombinedContinue<Indi> continuator(genCont);
-  continuator.add(steadyCont);
-  continuator.add(fitCont);
-
-
- - - - -
- -  /////////////////////////////////////////
-  // the algorithm
-  ////////////////////////////////////////
-  // 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);
-  
-
-
- - - - -
- -  // Print (sorted) intial population
-  pop.sort();
-  cout << "FINAL Population\n" << pop << endl;
-
-
- - - +
- -}
-// A main that catches the exceptions
-int main(int argc, char **argv)
-{
-#ifdef _MSC_VER
-  //  rng.reseed(42);
-      int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
-        flag |= _CRTDBG_LEAK_CHECK_DF;
-      _CrtSetDbgFlag(flag);
-//    _CrtSetBreakAlloc(100);
-#endif
-      try
-      {
-              main_function(argc, argv);
-      }
-      catch(exception& e)
-      {
-              cout << "Exception: " << e.what() << '\n';
-      }
-      return 1;
-}
-
} +
// A main that catches the exceptions +
int main(int argc, char **argv) +
{ +
#ifdef _MSC_VER +
 //  rng.reseed(42); +
     int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF); +
       flag +|= _CRTDBG_LEAK_CHECK_DF; +
     _CrtSetDbgFlag(flag); +
//    _CrtSetBreakAlloc(100); +
#endif +
     try +
     { +
             +main_function(argc, argv); +
     } +
     catch(exception& +e) +
     { +
             +cout << "Exception: " << e.what() << '\n'; +
     } +
     return 1; +
}
+
Back to Lesson 2 - Tutorial main page - Algorithm-Based - Component-Based page - Programming hints - EO @@ -361,8 +336,8 @@ documentation
Marc Schoenauer
-
Last -modified: Sun Nov 19 22:26:27 2000 - + +
Last modified: Sun Nov +19 22:26:27 2000 diff --git a/eo/tutorial/html/FirstBitGA.html b/eo/tutorial/html/FirstBitGA.html index e6e4368e..a7e5f179 100644 --- a/eo/tutorial/html/FirstBitGA.html +++ b/eo/tutorial/html/FirstBitGA.html @@ -2,9 +2,9 @@ - + FirstBitGA.html - + Back to Lesson 1 - Tutorial @@ -16,326 +16,290 @@ documentation

FirstBitGA.html

-Click on the figure to see the corresponding code.
-In the code, the colors are meaningfull
-The actual code is in boldface and the comment in normal face. -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
  - +Click on the figure to see the corresponding code. +
In the code, the colors are meaningfull +
The actual code is in boldface and the comment in normal face. +
+
- +
-//-----------------------------------------------------------------------------
-// FirstBitGA.cpp
-//-----------------------------------------------------------------------------
-//*
-// An instance of a VERY simple Bitstring Genetic Algorithm
-//
-//-----------------------------------------------------------------------------
-// standard includes
-#include <stdexcept>  // runtime_error
-#include <iostream>    // cout
-#include <strstream>  // ostrstream, istrstream
-// the general include for eo
-#include <eo>
-
-
//----------------------------------------------------------------------------- +
// FirstBitGA.cpp +
//----------------------------------------------------------------------------- +
//* +
// An instance of a VERY simple Bitstring +Genetic Algorithm +
// +
//----------------------------------------------------------------------------- +
// standard includes +
#include <stdexcept>  // runtime_error  +
#include <iostream>    +// cout +
#include <strstream>  // ostrstream, +istrstream +
// the general include for eo +
#include <eo>
- + +
- +
- -//-----------------------------------------------------------------------------
-// define your individuals
-typedef eoBin<double> Indi;        // A bitstring with fitness double
-
-
//----------------------------------------------------------------------------- +
// Include the corresponding file +
#include <ga.h>          +// bitstring representation & operators +
// define your individuals +
typedef eoBin<double> Indi;        +// A bitstring with fitness double
+ - +
- -//-----------------------------------------------------------------------------
-// a simple fitness function that computes the number of ones of a bitstring
-//  @param _indi A biststring individual
- -double binary_value(const Indi & _indi)
-{
-  double sum = 0;
-  for (unsigned i = 0; i < _indi.size(); i++)
-      sum += _indi[i];
-  return sum;
-}
-
-
//----------------------------------------------------------------------------- +
// a simple fitness function that computes +the number of ones of a bitstring +
//  @param _indi A biststring individual +
double binary_value(const +Indi & _indi) +
{ +
 double sum = 0; +
 for (unsigned i = 0; i < _indi.size(); +i++) +
     sum += _indi[i]; +
 return sum; +
}
- + +
+ + + +
//----------------------------------------------------------------------------- +
void main_function(int argc, char **argv) +
{
+ + + + + +
 // all parameters are hard-coded! +
 const unsigned int SEED = 42;          +// seed for random number generator +
 const unsigned int T_SIZE = 3;        +// size for tournament selection +
 const unsigned int VEC_SIZE = 8;    +// Number of bits in genotypes +
 const unsigned int POP_SIZE = 20;  +// Size of population +
 const unsigned int MAX_GEN = 100;  +// Maximum number of generation before STOP +
 const float CROSS_RATE = 0.8;          +// Crossover rate +
 const double P_MUT_PER_BIT = 0.01; +// probability of bit-flip mutation +
 const float MUT_RATE = 1.0;              +// mutation rate
+ + + + + +
////////////////////////// +
 //  Random seed +
 ////////////////////////// +
 //reproducible random seed: +if you don't change SEED above,  +
 // you'll aways get the same +result, NOT a random run +
 rng.reseed(SEED);
+ + + + + +
 ///////////////////////////// +
 // Fitness function +
 //////////////////////////// +
 // Evaluation: from a plain +C++ fn to an EvalFunc Object +
 eoEvalFuncPtr<Indi> eval(  +binary_value );
+ + + + + +
 //////////////////////////////// +
 // Initilisation of population +
 //////////////////////////////// +
 // declare the population +
 eoPop<Indi> pop; +
 // fill it! +
 for (unsigned int igeno=0; igeno<POP_SIZE; +igeno++) +
     { +
         +Indi v;                    +// void individual, to be filled +
         +for (unsigned ivar=0; ivar<VEC_SIZE; ivar++) +
             +{ +
                 +bool r = rng.flip(); // new value, random in {0,1} +
                 +v.push_back(r);          // +append that random value to v +
             +} +
         +eval(v);                                +// evaluate it +
         +pop.push_back(v);              +// and put it in the population +
     }
+ + + + + +
 // sort pop before printing +it! +
 pop.sort(); +
 // Print (sorted) intial population +(raw printout) +
 cout << "Initial Population" +<< endl; +
 cout << pop;
+ + + + + +
 ///////////////////////////////////// +
 // selection and replacement +
 ////////////////////////////////////
+ + + + + +
 // The robust tournament selection +
 eoDetTournamentSelect<Indi> select(T_SIZE);  +// T_SIZE in [2,POP_SIZE]
+ + + + + +
 // The simple GA evolution engine +uses generational replacement +
 // so no replacement procedure +is needed
+ + + + + +
+ + + + + +
 ////////////////////////////////////// +
 // The variation operators +
 //////////////////////////////////////
+ + + + + +
 // 1-point mutation for bitstring +
 eoBinCrossover<Indi> xover;
+ + +
 // standard bit-flip mutation +for bitstring +
 eoBinMutation<Indi>  mutation(P_MUT_PER_BIT);
- -//-----------------------------------------------------------------------------
-void main_function(int argc, char **argv)
-{
-
-
- + +
- +
- -  // all parameters are hard-coded!
-  const unsigned int SEED = 42;          // seed for random number generator
-  const unsigned int T_SIZE = 3;        // size for tournament selection
-  const unsigned int VEC_SIZE = 8;    // Number of bits in genotypes
-  const unsigned int POP_SIZE = 20;  // Size of population
-  const unsigned int MAX_GEN = 100;  // Maximum number of generation before STOP
-  const float CROSS_RATE = 0.8;          // Crossover rate
-  const double P_MUT_PER_BIT = 0.01; // probability of bit-flip mutation
-  const float MUT_RATE = 1.0;              // mutation rate
-
-
 ////////////////////////////////////// +
 // termination condition +
 ///////////////////////////////////// +
 // stop after MAX_GEN generations +
 eoGenContinue<Indi> continuator(MAX_GEN); +
 
- + +
- +
- - -  //////////////////////////
-  //  Random seed
-  //////////////////////////
-  //reproducible random seed: if you don't change SEED above,
-  // you'll aways get the same result, NOT a random run
-  rng.reseed(SEED);
-
-
 ///////////////////////////////////////// +
 // 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,  +
                                 +eval, continuator); +
 // Apply algo to pop - that's +it! +
 gga(pop); +
 

- + +
- +
- -  /////////////////////////////
-  // Fitness function
-  ////////////////////////////
-  // Evaluation: from a plain C++ fn to an EvalFunc Object
-  eoEvalFuncPtr<Indi> eval(  binary_value );
-
-
 // Print (sorted) intial population +
 pop.sort(); +
 cout << "FINAL Population\n" +<< pop << endl;
- + +
- - -
- -  ////////////////////////////////
-  // Initilisation of population
-  ////////////////////////////////
-  // declare the population
-  eoPop<Indi> pop;
-  // fill it!
-  for (unsigned int igeno=0; igeno<POP_SIZE; igeno++)
-      {
-          Indi v;                    // void individual, to be filled
-          for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)
-              {
-                  bool r = rng.flip(); // new value, random in {0,1}
-                  v.push_back(r);          // append that random value to v
-              }
-          eval(v);                                // evaluate it
-          pop.push_back(v);              // and put it in the population
-      }
-
-
- - - - -
- -  // sort pop before printing it!
-  pop.sort();
-  // Print (sorted) intial population (raw printout)
-  cout << "Initial Population" << endl;
-  cout << pop;
-
-
- - - - -
- -  /////////////////////////////////////
-  // selection and replacement
-  ////////////////////////////////////
-
-
- - - - -
- -  // The robust tournament selection
-  eoDetTournamentSelect<Indi> select(T_SIZE);  // T_SIZE in [2,POP_SIZE]
-
-
- - - - -
- -  // The simple GA evolution engine uses generational replacement
-  // so no replacement procedure is needed
-
-
- - - - -
- - -
- - - - -
- -  //////////////////////////////////////
-  // The variation operators
-  //////////////////////////////////////
-
-
- - - - -
- -  // 1-point mutation for bitstring
-  eoBinCrossover<Indi> xover;
-
-
- - - - -
- -  
-  // standard bit-flip mutation for bitstring
-  eoBinMutation<Indi>  mutation(P_MUT_PER_BIT);
-
-
- - - - -
- -  //////////////////////////////////////
-  // termination condition
-  /////////////////////////////////////
-  // stop after MAX_GEN generations
-  eoGenContinue<Indi> continuator(MAX_GEN);
-  
-
-
- - - - -
- -  /////////////////////////////////////////
-  // 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,
-                                  eval, continuator);
-  // Apply algo to pop - that's it!
-  gga(pop);
-  
-
-
- - - - -
- -  // Print (sorted) intial population
-  pop.sort();
-  cout << "FINAL Population\n" << pop << endl;
-
-
- - - +
- -}
- // A main that catches the exceptions
-int main(int argc, char **argv)
-{
-#ifdef _MSC_VER
-  //  rng.reseed(42);
-      int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
-        flag |= _CRTDBG_LEAK_CHECK_DF;
-      _CrtSetDbgFlag(flag);
-//    _CrtSetBreakAlloc(100);
-#endif
-      try
-      {
-              main_function(argc, argv);
-      }
-      catch(exception& e)
-      {
-              cout << "Exception: " << e.what() << '\n';
-      }
-      return 1;
-}
-
} +
// A main that catches the exceptions +
int main(int argc, char **argv) +
{ +
#ifdef _MSC_VER +
 //  rng.reseed(42); +
     int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF); +
       flag +|= _CRTDBG_LEAK_CHECK_DF; +
     _CrtSetDbgFlag(flag); +
//    _CrtSetBreakAlloc(100); +
#endif +
     try +
     { +
             +main_function(argc, argv); +
     } +
     catch(exception& +e) +
     { +
             +cout << "Exception: " << e.what() << '\n'; +
     } +
     return 1; +
}
+
Back to Lesson 1 - Tutorial main page - Algorithm-Based - Component-Based page - Programming hints - EO @@ -343,8 +307,8 @@ documentation
Marc Schoenauer
-
Last -modified: Sun Nov 19 08:31:26 2000 - + +
Last modified: Sun Nov +19 08:31:26 2000 diff --git a/eo/tutorial/html/FirstRealEA.html b/eo/tutorial/html/FirstRealEA.html index 63b96094..6b757541 100644 --- a/eo/tutorial/html/FirstRealEA.html +++ b/eo/tutorial/html/FirstRealEA.html @@ -34,8 +34,9 @@ Breeder - and Combined Ops
//-----------------------------------------------------------------------------
// standard includes
#include <stdexcept>  // runtime_error  -
#include <iostream>    -// cout +
#include <iostream>   +// +cout
#include <strstream>  // ostrstream, istrstream
// the general include for eo @@ -46,6 +47,9 @@ istrstream @@ -77,12 +81,16 @@ seed for random number generator
 const unsigned int T_SIZE = 3; // size for tournament selection
 const unsigned int VEC_SIZE = 8; -// Number of object variables in genotypes +// +Number of object variables in genotypes
 const unsigned int POP_SIZE = 20; -// Size of population +// +Size of population
 const unsigned int MAX_GEN = 500; -// Maximum number of generation before STOP -
 const unsigned int MIN_GEN = 10;  +// +Maximum number of generation before STOP +
 const unsigned int MIN_GEN = 10; + // Minimum number of generation before ...
 const unsigned int STEADY_GEN = 50; // stop after STEADY_GEN gen. without improvelent @@ -97,13 +105,17 @@ SIGMA = 0.3;        // std dev. for normal mutation
 // some parameters for chosing among different operators -
 const double segmentRate = 0.5;    +
 const double segmentRate = 0.5;   + // relative weight for 1-pt Xover
 const double arithmeticRate = 0.5; -// relative weight for 2-pt Xover +
// +relative weight for 2-pt Xover

 const double uniformMutRate = 0.5; -// relative weight for bit-flip mutation -
 const double detMutRate = 0.5;     +// +relative weight for bit-flip mutation +
 const double detMutRate = 0.5;    + // relative weight for one-bit mutation
 const double normalMutRate = 0.5;  // relative weight for normal mutation @@ -181,8 +193,8 @@ it! @@ -295,8 +307,7 @@ eval, select, transform, replace); it!
 cout << "\n              Here we go\n\n"; -
 gga(pop); -
  +
 gga(pop);
//----------------------------------------------------------------------------- +
// Include the corresponding file  +
#include <es.h>          +// real-representation & operators 
// define your individuals
typedef eoReal<double> Indi; 
 // The robust tournament selection
 eoDetTournamentSelect<Indi> selectOne(T_SIZE); -
// -is now encapsulated in a eoSelectPerc (entage) +
// is now +encapsulated in a eoSelectPerc (entage)
 eoSelectPerc<Indi> select(selectOne);// by default rate==1
diff --git a/eo/tutorial/html/FirstRealGA.html b/eo/tutorial/html/FirstRealGA.html index b375629f..b3687ec7 100644 --- a/eo/tutorial/html/FirstRealGA.html +++ b/eo/tutorial/html/FirstRealGA.html @@ -2,9 +2,9 @@ - + ../FirstRealGA.html - + Back to Lesson 1 - Tutorial @@ -16,325 +16,293 @@ documentation

../FirstRealGA.html

-Click on the figure to see the corresponding code.
-In the code, the colors are meaningfull
-The actual code is in boldface and the comment in normal face. -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
  - +Click on the figure to see the corresponding code. +
In the code, the colors are meaningfull +
The actual code is in boldface and the comment in normal face. +
+
- +
-//-----------------------------------------------------------------------------
-// FirstRealGA.cpp
-//-----------------------------------------------------------------------------
-//*
-// An instance of a VERY simple Real-coded Genetic Algorithm
-//
-//-----------------------------------------------------------------------------
-// standard includes
-#include <stdexcept>  // runtime_error
-#include <iostream>    // cout
-#include <strstream>  // ostrstream, istrstream
-// the general include for eo
-#include <eo>
-
-
//----------------------------------------------------------------------------- +
// FirstRealGA.cpp +
//----------------------------------------------------------------------------- +
//* +
// An instance of a VERY simple Real-coded +Genetic Algorithm +
// +
//----------------------------------------------------------------------------- +
// standard includes +
#include <stdexcept>  // runtime_error  +
#include <iostream>    +// cout +
#include <strstream>  // ostrstream, +istrstream +
// the general include for eo +
#include <eo>
- + +
- +
- -//-----------------------------------------------------------------------------
-// define your individuals
- typedef eoReal<double> Indi;
-
-
//----------------------------------------------------------------------------- +
// Include the corresponding file +
#include <es.h>          +// real-representation & operators +
// define your individuals +
typedef eoReal<double> Indi;
+ - +
- -//-----------------------------------------------------------------------------
-// a simple fitness function that computes the euclidian norm of a real vector
-//      @param _indi A real-valued individual
- -double real_value(const Indi & _indi)
-{
-  double sum = 0;
-  for (unsigned i = 0; i < _indi.size(); i++)
-          sum += _indi[i]*_indi[i];
-  return (-sum);                      // maximizing only
-}
-
-
//----------------------------------------------------------------------------- +
// a simple fitness function that computes +the euclidian norm of a real vector +
//      @param _indi +A real-valued individual  +
double real_value(const +Indi & _indi) +
{ +
 double sum = 0; +
 for (unsigned i = 0; i < _indi.size(); +i++) +
         +sum += _indi[i]*_indi[i]; +
 return (-sum);                      +// maximizing only +
}
- + +
- +
- -//-----------------------------------------------------------------------------
-void main_function(int argc, char **argv)
-{
-
-
//----------------------------------------------------------------------------- +
void main_function(int argc, char **argv) +
{
- + +
- +
- -  // all parameters are hard-coded!
-  const unsigned int SEED = 42; // seed for random number generator
-  const unsigned int VEC_SIZE = 8; // Number of object variables in genotypes
-  const unsigned int POP_SIZE = 20; // Size of population
-  const unsigned int T_SIZE = 3; // size for tournament selection
-  const unsigned int MAX_GEN = 500; // Maximum number of generation before STOP
-  const float CROSS_RATE = 0.8; // Crossover rate
-  const double EPSILON = 0.01;  // range for real uniform mutation
-  const float MUT_RATE = 0.5;    // mutation rate
-
-
 // all parameters are hard-coded! +
 const unsigned int SEED = 42; // +seed for random number generator +
 const unsigned int VEC_SIZE = 8; +// Number of object variables in genotypes +
 const unsigned int POP_SIZE = 20; +// Size of population +
 const unsigned int T_SIZE = 3; // +size for tournament selection +
 const unsigned int MAX_GEN = 500; +// Maximum number of generation before STOP +
 const float CROSS_RATE = 0.8; // +Crossover rate +
 const double EPSILON = 0.01;  +// range for real uniform mutation +
 const float MUT_RATE = 0.5;    +// mutation rate
- + +
- +
- - -  //////////////////////////
-  //  Random seed
-  //////////////////////////
-  //reproducible random seed: if you don't change SEED above,
-  // you'll aways get the same result, NOT a random run
-  rng.reseed(SEED);
-
-
////////////////////////// +
 //  Random seed +
 ////////////////////////// +
 //reproducible random seed: +if you don't change SEED above,  +
 // you'll aways get the same +result, NOT a random run +
 rng.reseed(SEED);
- + +
- +
- -  /////////////////////////////
-  // Fitness function
-  ////////////////////////////
-  // Evaluation: from a plain C++ fn to an EvalFunc Object
-  eoEvalFuncPtr<Indi> eval(  real_value );
-
-
 ///////////////////////////// +
 // Fitness function +
 //////////////////////////// +
 // Evaluation: from a plain +C++ fn to an EvalFunc Object +
 eoEvalFuncPtr<Indi> eval(  +real_value );
- + +
- +
- -  ////////////////////////////////
-  // Initilisation of population
-  ////////////////////////////////
-  // declare the population
-  eoPop<Indi> pop;
-  // fill it!
-  for (unsigned int igeno=0; igeno<POP_SIZE; igeno++)
-      {
-          Indi v;                  // void individual, to be filled
-          for (unsigned ivar=0; ivar<VEC_SIZE; ivar++)
-              {
-                  double r = 2*rng.uniform() - 1; // new value, random in [-1,1)
-                  v.push_back(r);            // append that random value to v
-              }
-          eval(v);                                  // evaluate it
-          pop.push_back(v);                // and put it in the population
-      }
-
-
 //////////////////////////////// +
 // Initilisation of population +
 //////////////////////////////// +
 // declare the population +
 eoPop<Indi> pop; +
 // fill it! +
 for (unsigned int igeno=0; igeno<POP_SIZE; +igeno++) +
     { +
         +Indi v;                  +// void individual, to be filled +
         +for (unsigned ivar=0; ivar<VEC_SIZE; ivar++) +
             +{ +
                 +double r = 2*rng.uniform() - 1; // new value, random in [-1,1) +
                 +v.push_back(r);            +// append that random value to v +
             +} +
         +eval(v);                                  +// evaluate it +
         +pop.push_back(v);                +// and put it in the population +
     }
- + +
- +
- -  // sort pop before printing it!
-  pop.sort();
-  // Print (sorted) intial population (raw printout)
-  cout << "Initial Population" << endl;
-  cout << pop;
-
-
 // sort pop before printing +it! +
 pop.sort(); +
 // Print (sorted) intial population +(raw printout) +
 cout << "Initial Population" +<< endl; +
 cout << pop;
- + +
- +
- -  /////////////////////////////////////
-  // selection and replacement
-  ////////////////////////////////////
-
-
 ///////////////////////////////////// +
 // selection and replacement +
 ////////////////////////////////////
- + +
- +
- -  // The robust tournament selection
-  eoDetTournamentSelect<Indi> select(T_SIZE);            // T_SIZE in [2,POP_SIZE]
-
-
 // The robust tournament selection +
 eoDetTournamentSelect<Indi> select(T_SIZE);            +// T_SIZE in [2,POP_SIZE]
- + +
- +
- -  // eoSGA uses generational replacement by default
-  // so no replacement procedure has to be given
-
-
 // eoSGA uses generational replacement +by default +
 // so no replacement procedure +has to be given
- + +
- +
- - -
- + +
- +
- -  //////////////////////////////////////
-  // termination condition
-  /////////////////////////////////////
-  // stop after MAX_GEN generations
-  eoGenContinue<Indi> continuator(MAX_GEN);
-  
-
-
 ////////////////////////////////////// +
 // termination condition +
 ///////////////////////////////////// +
 // stop after MAX_GEN generations +
 eoGenContinue<Indi> continuator(MAX_GEN); +
 
- + +
- +
- -  //////////////////////////////////////
-  // The variation operators
-  //////////////////////////////////////
-
-
 ////////////////////////////////////// +
 // The variation operators +
 //////////////////////////////////////
- + +
- +
- -  // offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon]
-  eoUniformMutation<Indi>  mutation(EPSILON);
-
-
 // offspring(i) uniformly chosen +in [parent(i)-epsilon, parent(i)+epsilon] +
 eoUniformMutation<Indi>  +mutation(EPSILON); 
- + +
- +
- -  // offspring(i) is a linear combination of parent(i)
-  eoArithmeticCrossover<Indi> xover;
-
-
 // offspring(i) is a linear +combination of parent(i) +
 eoArithmeticCrossover<Indi> xover;
- + +
- +
- -  /////////////////////////////////////////
-  // the algorithm
-  ////////////////////////////////////////
-  // standard Generational GA requires
-  // selection, evaluation, crossover and mutation, stopping criterion
-
-  eoSGA<Indi> gga(select, xover, CROSS_RATE, mutation, MUT_RATE,
-                                    eval, continuator);
-  // Apply algo to pop - that's it!
-  gga(pop);
-  
-
-
 ///////////////////////////////////////// +
 // the algorithm +
 //////////////////////////////////////// +
 // standard Generational GA +requires +
 // selection, evaluation, crossover +and mutation, stopping criterion +

 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;
-
-
 // Print (sorted) intial population +
 pop.sort(); +
 cout << "FINAL Population\n" +<< pop << endl;
- + +
- +
- -}
-// A main that catches the exceptions
-int main(int argc, char **argv)
-{
-#ifdef _MSC_VER
-  //  rng.reseed(42);
-      int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
-        flag |= _CRTDBG_LEAK_CHECK_DF;
-      _CrtSetDbgFlag(flag);
-//    _CrtSetBreakAlloc(100);
-#endif
-      try
-      {
-              main_function(argc, argv);
-      }
-      catch(exception& e)
-      {
-              cout << "Exception: " << e.what() << '\n';
-      }
-      return 1;
-}
-
} +
// A main that catches the exceptions +
int main(int argc, char **argv) +
{ +
#ifdef _MSC_VER +
 //  rng.reseed(42); +
     int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF); +
       flag +|= _CRTDBG_LEAK_CHECK_DF; +
     _CrtSetDbgFlag(flag); +
//    _CrtSetBreakAlloc(100); +
#endif +
     try +
     { +
             +main_function(argc, argv); +
     } +
     catch(exception& +e) +
     { +
             +cout << "Exception: " << e.what() << '\n'; +
     } +
     return 1; +
}
+
Back to Lesson 1 - Tutorial main page - Algorithm-Based - Component-Based page - Programming hints - EO @@ -342,8 +310,8 @@ documentation
Marc Schoenauer
-
Last -modified: Sun Nov 19 08:31:29 2000 - + +
Last modified: Sun Nov +19 08:31:29 2000 diff --git a/eo/tutorial/html/Firstmerge.html b/eo/tutorial/html/Firstmerge.html index 6345d865..d71236b3 100644 --- a/eo/tutorial/html/Firstmerge.html +++ b/eo/tutorial/html/Firstmerge.html @@ -2,7 +2,7 @@ - + Differences @@ -57,11 +57,15 @@ the parameter for the mutation). -typedef -eoReal<double> Indi; +#include +<es.h> +
typedef eoReal<double> +Indi; -typedef -eoBin<double> Indi; +#include +<ga.h> +
typedef eoBin<double> +Indi; diff --git a/eo/tutorial/html/SecondBitEA.html b/eo/tutorial/html/SecondBitEA.html index c73bf43e..dc56d491 100644 --- a/eo/tutorial/html/SecondBitEA.html +++ b/eo/tutorial/html/SecondBitEA.html @@ -63,6 +63,9 @@ the number of ones of a bitstring @@ -311,7 +314,6 @@ of initializatio of the population
//----------------------------------------------------------------------------- +
// Include the corresponding file +
#include <ga.h>          +// bitstring representation & operators
// define your genotype and fitness types
typedef eoBin<double> Indi;
 // The robust tournament selection
 eoDetTournamentSelect<Indi> selectOne(tSize);       - // tSize in [2,POPSIZE]
 // is now encapsulated in a eoSelectPerc (entage) diff --git a/eo/tutorial/html/eoLesson1.html b/eo/tutorial/html/eoLesson1.html index 581b07f2..9da1a448 100644 --- a/eo/tutorial/html/eoLesson1.html +++ b/eo/tutorial/html/eoLesson1.html @@ -99,9 +99,14 @@ this is a file that contains the list of the most important EO files. 
  • Representation: -you then have to declare the type of individuals you will be handling. -All evolution-related objects you will need are templatized w.r.t. the -type of individuals.
  • +you need to declare the type of individuals you will be handling. First, +include some header files where these are defined: ga.h +for bitstring, es.h +for real-valued genotypes.
    +Then a
    typedef +directive will allow one to handle the abstract Indi +all around in the main code. Remember that all evolution-related objects +you will need are templatized w.r.t. the type of individuals.
    • diff --git a/eo/tutorial/html/eoLesson2.html b/eo/tutorial/html/eoLesson2.html index 5e7b50e9..07f0f91e 100644 --- a/eo/tutorial/html/eoLesson2.html +++ b/eo/tutorial/html/eoLesson2.html @@ -67,13 +67,7 @@ argument is a vector<bool> or a Note: Also, +


      Note: Also, a non-templatized fitness can be compiled separately (not done here) into an object file once and for all (
      remember @@ -88,14 +82,8 @@ have to declare 3 template arguments: the type of EO object it will be applied to, the return type and the type of argument the function actually requires.

    • -
        -

        -
        -
        -
        -
        -

      Note: In the -previous files (Bit - Real) +


      Note: In +the previous files (Bit - Real) , the last 2 types were deduced from the first (2nd argument = fitness type of EO object, third = first).
        @@ -117,13 +105,7 @@ You can also use different initializers and call them in turn through the call to pop.append() function (see Exercise 2).
      -
        -

        -
        -
        -
        -
        -

      Note: Don't +


      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!!!