From 6bb81f22787fda9ea48cad4043dfab9627379900 Mon Sep 17 00:00:00 2001 From: cahon Date: Fri, 29 Mar 2002 15:30:55 +0000 Subject: [PATCH] How to build an homo/heterogenous island model of EAs ? --- eo/tutorial/ParadisEO/Lesson1/IslandBitEA.cpp | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 eo/tutorial/ParadisEO/Lesson1/IslandBitEA.cpp diff --git a/eo/tutorial/ParadisEO/Lesson1/IslandBitEA.cpp b/eo/tutorial/ParadisEO/Lesson1/IslandBitEA.cpp new file mode 100644 index 000000000..1793bc670 --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson1/IslandBitEA.cpp @@ -0,0 +1,87 @@ +#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 T_SIZE = 3 ; // Size for tournament selection + const unsigned int VEC_SIZE = 50 ; // Number of bits in genotypes + const unsigned int POP_SIZE = 100 ; // Size of population + + const unsigned int MAX_GEN = 1000 ; // Fixed number of generations + + 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 + + eoEvalFuncPtr & > eval (binary_value) ; + eoUniformGenerator uGen ; + eoInitFixedLength random (VEC_SIZE, uGen) ; + + eoPop pop (POP_SIZE, random) ; + + apply (eval, pop) ; // A first evaluation of the population + + eoDetTournamentSelect selectOne(T_SIZE) ; + eoSelectPerc select (selectOne) ; // The selection operator + + eoGenerationalReplacement replace ; // The replacement operator + + eo1PtBitXover xover1 ; + eoPropCombinedQuadOp xover (xover1, onePointRate) ; + eoBitMutation mutationBitFlip (P_MUT_PER_BIT) ; + eoPropCombinedMonOp mutation (mutationBitFlip, bitFlipRate) ; + + eoSGATransform transform (xover, P_CROSS, mutation, P_MUT) ; + + eoGenContinue genCont (MAX_GEN) ; // The continuation criteria + + // First evolutionnary algorithm + eoEasyEA gga (genCont, eval, select, transform, replace) ; + + // What's new ? + eoListener listen (argc, argv) ; + rng.reseed (listen.here ().number ()) ; + + vector v ; + v.push_back ("Mars") ; // Only evol. algos named "Mars" are considered + eoFullConnectivity conn (listen, v) ; // The ring topology used + + eoCyclicGenContinue cycl_cont (300) ; // Immigration step all 300 evolutions + eoRandomSelect sel_rand ; // Random selection of emigrants + eoSelectMany sel (sel_rand, 0.1) ; /* How many individuals should be selected + to be sent ? */ + eoPlusReplacement repl ; // How to integrate new individuals ? + // A island esay evolutionnary named "Mars" + eoIslandsEasyEA islgga ("Mars", listen, conn, gga, cycl_cont, sel, repl) ; + islgga (pop) ; + pop.sort () ; + cout << "The final population is now ..." << endl ; + cout << pop << endl ; +} + +int main(int argc, char **argv) { +#ifdef _MSC_VER + + int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF); + flag |= _CRTDBG_LEAK_CHECK_DF; + _CrtSetDbgFlag(flag); + +#endif + + try { + main_function(argc, argv) ; + } + catch(exception& e) { + cout << "Exception: " << e.what () << '\n' ; + } + + return 1 ; +}