From aec83a00149a63f994cca3e153d7acda450c2584 Mon Sep 17 00:00:00 2001 From: cahon Date: Fri, 29 Mar 2002 15:36:04 +0000 Subject: [PATCH] How to build an EA with a distributed evalaution process ? --- .../ParadisEO/Lesson2/MasterDistEvalBitEA.cpp | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 eo/tutorial/ParadisEO/Lesson2/MasterDistEvalBitEA.cpp diff --git a/eo/tutorial/ParadisEO/Lesson2/MasterDistEvalBitEA.cpp b/eo/tutorial/ParadisEO/Lesson2/MasterDistEvalBitEA.cpp new file mode 100644 index 00000000..978fd556 --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson2/MasterDistEvalBitEA.cpp @@ -0,0 +1,86 @@ +#include +#include +#include + +#include +#include + +typedef eoBit Indi ; // A bitstring with fitness double + +#include "binary_value.h" + +void main_function(int argc, char **argv) { + + // Some parameters + 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 = 100 ; // Size of population + + const unsigned int MAX_GEN = 20 ; // Maximum number of generation before STOP + + const double P_CROSS = 0.8 ; // Crossover probability + const double P_MUT = 1.0 ; // Mutation probability + const double P_MUT_PER_BIT = 0.01 ; // Internal probability for bit-flip mutation + const double onePointRate = 0.5 ; // Rate for 1-pt Xover + const double bitFlipRate = 0.5 ; // Rate for bit-flip mutation + + rng.reseed (SEED) ; + + eoEvalFuncPtr & > eval (binary_value) ; + + eoUniformGenerator uGen ; + eoInitFixedLength random (VEC_SIZE, uGen) ; + + eoPop pop (POP_SIZE, random) ; + + apply (eval, pop) ; + + eoDetTournamentSelect selectOne (T_SIZE) ; + + eoSelectPerc select (selectOne) ; + + eoGenerationalReplacement replace ; + + eo1PtBitXover xover1 ; + + eoBitMutation mutationBitFlip(P_MUT_PER_BIT) ; + + // The operators are encapsulated into an eoTRansform object + eoSGATransform transform(xover1, P_CROSS, mutationBitFlip, P_MUT); + + eoGenContinue genCont (MAX_GEN); + + eoEasyEA gga (genCont, eval, select, transform, replace); + + eoListener listen (argc, argv) ; + + eoDistEvalEasyEA dist_gga (listen, gga, "Mars") ; + + dist_gga (pop) ; + + listen.destroy ("Mars") ; + + // OUTPUT + // Print (sorted) intial population + pop.sort(); + cout << "FINAL Population\n" << pop << endl; +// GENERAL +} + +// 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; +}