From 6afc695dce3e568d1c6ca9f0cc034f429d739121 Mon Sep 17 00:00:00 2001 From: cahon Date: Fri, 29 Mar 2002 15:38:15 +0000 Subject: [PATCH] *** empty log message *** --- .../ParadisEO/Lesson1/IslandBitEA1.cpp | 88 +++++++++++++++++ .../ParadisEO/Lesson1/IslandBitEA2.cpp | 96 +++++++++++++++++++ eo/tutorial/ParadisEO/Lesson1/Makefile | 27 ++++++ eo/tutorial/ParadisEO/Lesson1/binary_value.h | 17 ++++ .../ParadisEO/Lesson1/paradiseo.config | 4 + eo/tutorial/ParadisEO/Lesson2/Makefile | 21 ++++ .../ParadisEO/Lesson2/SlaveDistEvalBitEA.cpp | 41 ++++++++ eo/tutorial/ParadisEO/Lesson2/binary_value.h | 17 ++++ .../ParadisEO/Lesson2/paradiseo.config | 4 + 9 files changed, 315 insertions(+) create mode 100644 eo/tutorial/ParadisEO/Lesson1/IslandBitEA1.cpp create mode 100644 eo/tutorial/ParadisEO/Lesson1/IslandBitEA2.cpp create mode 100644 eo/tutorial/ParadisEO/Lesson1/Makefile create mode 100644 eo/tutorial/ParadisEO/Lesson1/binary_value.h create mode 100644 eo/tutorial/ParadisEO/Lesson1/paradiseo.config create mode 100644 eo/tutorial/ParadisEO/Lesson2/Makefile create mode 100644 eo/tutorial/ParadisEO/Lesson2/SlaveDistEvalBitEA.cpp create mode 100644 eo/tutorial/ParadisEO/Lesson2/binary_value.h create mode 100644 eo/tutorial/ParadisEO/Lesson2/paradiseo.config diff --git a/eo/tutorial/ParadisEO/Lesson1/IslandBitEA1.cpp b/eo/tutorial/ParadisEO/Lesson1/IslandBitEA1.cpp new file mode 100644 index 000000000..f984bf816 --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson1/IslandBitEA1.cpp @@ -0,0 +1,88 @@ +#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 ("Mars1") ; + v.push_back ("Mars2") ; + eoRingConnectivity 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 ("Mars1", 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 ; +} diff --git a/eo/tutorial/ParadisEO/Lesson1/IslandBitEA2.cpp b/eo/tutorial/ParadisEO/Lesson1/IslandBitEA2.cpp new file mode 100644 index 000000000..b3e89644e --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson1/IslandBitEA2.cpp @@ -0,0 +1,96 @@ +#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 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 + + 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 + + // Uniform crossover for bitstring + eoUBitXover xoverU ; + eoPropCombinedQuadOp xover (xoverU, URate) ; + + // eoBitMutation mutationBitFlip (P_MUT_PER_BIT) ; + + eoDetBitFlip mutationOneBit ; + + eoPropCombinedMonOp mutation (mutationOneBit, oneBitRate) ; + + 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 ("Mars1") ; + v.push_back ("Mars2") ; // Algos named "Mars1" or "Mars2" are considered ... + + eoRingConnectivity 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 "Mars2" + eoIslandsEasyEA islgga ("Mars2", 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 ; +} diff --git a/eo/tutorial/ParadisEO/Lesson1/Makefile b/eo/tutorial/ParadisEO/Lesson1/Makefile new file mode 100644 index 000000000..3008b72e2 --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson1/Makefile @@ -0,0 +1,27 @@ +ALL = IslandBitEA IslandBitEA2 IslandBitEA1 + +lesson2 : IslandBitEA IslandBitEA2 IslandBitEA1 + +all : $(ALL) + +clean : + @/bin/rm $(ALL) *.o *~ + +IslandBitEA : IslandBitEA.o + mpiCC -DPACKAGE=\"eo\" -o IslandBitEA IslandBitEA.o ../../../src/utils/libeoutils.a ../../../src/libeo.a + +IslandBitEA.o : IslandBitEA.cpp binary_value.h + mpiCC -DPACKAGE=\"eo\" -I. -I../../../src -c IslandBitEA.cpp + +IslandBitEA1 : IslandBitEA1.o + mpiCC -DPACKAGE=\"eo\" -o IslandBitEA1 IslandBitEA1.o ../../../src/utils/libeoutils.a ../../../src/libeo.a + +IslandBitEA1.o : IslandBitEA1.cpp binary_value.h + mpiCC -DPACKAGE=\"eo\" -I. -I../../../src -c IslandBitEA1.cpp + +IslandBitEA2 : IslandBitEA2.o + mpiCC -DPACKAGE=\"eo\" -o IslandBitEA2 IslandBitEA2.o ../../../src/utils/libeoutils.a ../../../src/libeo.a + +IslandBitEA2.o : IslandBitEA2.cpp binary_value.h + mpiCC -DPACKAGE=\"eo\" -I. -I../../../src -c IslandBitEA2.cpp + diff --git a/eo/tutorial/ParadisEO/Lesson1/binary_value.h b/eo/tutorial/ParadisEO/Lesson1/binary_value.h new file mode 100644 index 000000000..a31c08644 --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson1/binary_value.h @@ -0,0 +1,17 @@ +#include + +//----------------------------------------------------------------------------- + +/** Just a simple function that takes binary value of a chromosome and sets + the fitnes. + @param _chrom A binary chromosome +*/ +// INIT +double binary_value(const vector& _chrom) +{ + double sum = 0; + for (unsigned i = 0; i < _chrom.size(); i++) + sum += _chrom[i]; + return sum; +} + diff --git a/eo/tutorial/ParadisEO/Lesson1/paradiseo.config b/eo/tutorial/ParadisEO/Lesson1/paradiseo.config new file mode 100644 index 000000000..f336791d5 --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson1/paradiseo.config @@ -0,0 +1,4 @@ +127.0.0.1 0 ${HOME}/eo/tutorial/ParadisEO/Lesson1/IslandBitEA1 +127.0.0.1 1 ${HOME}/eo/tutorial/ParadisEO/Lesson1/IslandBitEA1 +127.0.0.1 1 ${HOME}/eo/tutorial/ParadisEO/Lesson1/IslandBitEA2 +127.0.0.1 1 ${HOME}/eo/tutorial/ParadisEO/Lesson1/IslandBitEA2 diff --git a/eo/tutorial/ParadisEO/Lesson2/Makefile b/eo/tutorial/ParadisEO/Lesson2/Makefile new file mode 100644 index 000000000..12b365eaa --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson2/Makefile @@ -0,0 +1,21 @@ +ALL = MasterDistEvalBitEA SlaveDistEvalBitEA + +lesson2 : MasterDistEvalBitEA SlaveDistEvalBitEA + +all : $(ALL) + +clean : + @/bin/rm $(ALL) *.o *~ + +MasterDistEvalBitEA : MasterDistEvalBitEA.o + mpiCC -DPACKAGE=\"eo\" -o MasterDistEvalBitEA MasterDistEvalBitEA.o ../../../src/utils/libeoutils.a ../../../src/libeo.a + +MasterDistEvalBitEA.o : MasterDistEvalBitEA.cpp binary_value.h + mpiCC -DPACKAGE=\"eo\" -I. -I../../../src -c MasterDistEvalBitEA.cpp + +SlaveDistEvalBitEA : SlaveDistEvalBitEA.o + mpiCC -DPACKAGE=\"eo\" -o SlaveDistEvalBitEA SlaveDistEvalBitEA.o ../../../src/utils/libeoutils.a ../../../src/libeo.a + +SlaveDistEvalBitEA.o : SlaveDistEvalBitEA.cpp binary_value.h + mpiCC -DPACKAGE=\"eo\" -I. -I../../../src -c SlaveDistEvalBitEA.cpp + diff --git a/eo/tutorial/ParadisEO/Lesson2/SlaveDistEvalBitEA.cpp b/eo/tutorial/ParadisEO/Lesson2/SlaveDistEvalBitEA.cpp new file mode 100644 index 000000000..590d3d882 --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson2/SlaveDistEvalBitEA.cpp @@ -0,0 +1,41 @@ +#include // runtime_error +#include // cout +#include // ostrstream, istrstream + +#include +#include + +typedef eoBit Indi; // A bitstring with fitness double + +#include "binary_value.h" + +void main_function(int argc, char **argv) { + + eoEvalFuncPtr & > eval (binary_value) ; + + eoListener listen (argc, argv) ; + + eoEvaluator evaluator ("Mars", + listen, + eval) ; + + // Runs + evaluator () ; +} + +// 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; +} diff --git a/eo/tutorial/ParadisEO/Lesson2/binary_value.h b/eo/tutorial/ParadisEO/Lesson2/binary_value.h new file mode 100644 index 000000000..a31c08644 --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson2/binary_value.h @@ -0,0 +1,17 @@ +#include + +//----------------------------------------------------------------------------- + +/** Just a simple function that takes binary value of a chromosome and sets + the fitnes. + @param _chrom A binary chromosome +*/ +// INIT +double binary_value(const vector& _chrom) +{ + double sum = 0; + for (unsigned i = 0; i < _chrom.size(); i++) + sum += _chrom[i]; + return sum; +} + diff --git a/eo/tutorial/ParadisEO/Lesson2/paradiseo.config b/eo/tutorial/ParadisEO/Lesson2/paradiseo.config new file mode 100644 index 000000000..a639308e0 --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson2/paradiseo.config @@ -0,0 +1,4 @@ +127.0.0.1 0 ${HOME}/eo/tutorial/ParadisEO/Lesson2/MasterDistEvalBitEA +127.0.0.1 1 ${HOME}/eo/tutorial/ParadisEO/Lesson2/SlaveDistEvalBitEA +127.0.0.1 1 ${HOME}/eo/tutorial/ParadisEO/Lesson2/SlaveDistEvalBitEA +127.0.0.1 1 ${HOME}/eo/tutorial/ParadisEO/Lesson2/SlaveDistEvalBitEA