From c99bce368c067f77d7888e74d2087f4b0e90b0c5 Mon Sep 17 00:00:00 2001 From: cahon Date: Thu, 25 Apr 2002 14:26:02 +0000 Subject: [PATCH] *** empty log message *** --- .../ParadisEO/Lesson3/CellularBitEA.cpp | 86 +++++++++++++++++++ eo/tutorial/ParadisEO/Lesson3/Makefile | 15 ++++ eo/tutorial/ParadisEO/Lesson3/binary_value.h | 17 ++++ 3 files changed, 118 insertions(+) create mode 100644 eo/tutorial/ParadisEO/Lesson3/CellularBitEA.cpp create mode 100644 eo/tutorial/ParadisEO/Lesson3/Makefile create mode 100644 eo/tutorial/ParadisEO/Lesson3/binary_value.h diff --git a/eo/tutorial/ParadisEO/Lesson3/CellularBitEA.cpp b/eo/tutorial/ParadisEO/Lesson3/CellularBitEA.cpp new file mode 100644 index 000000000..41640b355 --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson3/CellularBitEA.cpp @@ -0,0 +1,86 @@ +#include +#include +#include + +#include +#include + +typedef eoBit Indi; + +#include "binary_value.h" + +void main_function(int argc, char **argv) +{ + + const unsigned int SEED = 42; + const unsigned int VEC_SIZE = 8; + const unsigned int POP_SIZE = 25; + + const unsigned int MAX_GEN = 100; + + const double P_MUT_PER_BIT = 0.01; + + rng.reseed(SEED); + + eoEvalFuncPtr& > eval( binary_value ); + + eoUniformGenerator uGen; + eoInitFixedLength random(VEC_SIZE, uGen); + + eoPop pop(POP_SIZE, random); + + + apply(eval, pop); + + pop.sort(); + + cout << "Initial Population" << endl; + cout << pop; + + eo1PtBitXover xover1; + + eoBitMutation mutationBitFlip(P_MUT_PER_BIT); + + eoGenContinue genCont(MAX_GEN); + + eoBestSelect select ; + + eoToricCellularEasyEA gga (genCont, + eval, + select, + xover1, + mutationBitFlip, + select, + select) ; + + cout << "\n Here we go\n\n"; + gga(pop); + + 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; +} diff --git a/eo/tutorial/ParadisEO/Lesson3/Makefile b/eo/tutorial/ParadisEO/Lesson3/Makefile new file mode 100644 index 000000000..2e5c0fdfc --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson3/Makefile @@ -0,0 +1,15 @@ +.cpp: ; c++ -DPACKAGE=\"eo\" -DVERSION=\"0.9.1\" -I. -I../../../src -Wall -g -o $@ $*.cpp ../../../src/utils/libeoutils.a ../../../src/libeo.a + +.cpp.o: ; c++ -DPACKAGE=\"eo\" -DVERSION=\"0.9.1\" -I. -I../../../src -Wall -g -c $*.cpp + +ALL = CellularBitEA + +lesson3 : $(firstEA) + +all : $(ALL) + +clean : + @/bin/rm $(ALL) *.o *~ + +CellularBitEA : binary_value.h + diff --git a/eo/tutorial/ParadisEO/Lesson3/binary_value.h b/eo/tutorial/ParadisEO/Lesson3/binary_value.h new file mode 100644 index 000000000..a31c08644 --- /dev/null +++ b/eo/tutorial/ParadisEO/Lesson3/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; +} +