From 41ff11bd7fc8368d024fcdfb76f2f1493372a3a7 Mon Sep 17 00:00:00 2001 From: evomarc Date: Sat, 27 Jan 2001 07:41:46 +0000 Subject: [PATCH] I have separated the include files into eo everything that is general to any representation es.h everything about real representation (in es dir) ga.h everything related to bitstring representation (in ga dir) To be continued by gp.h, and ... This has lead to some slight modifications in test file eobin and all tutorial examples files... --- eo/src/eo | 43 +++++------------------------ eo/src/eoGenericQuadOp.h | 2 +- eo/src/es/eoEsChromInit.h | 29 ++++++++++--------- eo/src/es/eoRealBounds.h | 8 ++++-- eo/test/t-eobin.cpp | 4 +-- eo/tutorial/Lesson1/FirstBitGA.cpp | 7 +++++ eo/tutorial/Lesson1/FirstRealGA.cpp | 2 ++ eo/tutorial/Lesson1/exercise1.3.cpp | 2 ++ eo/tutorial/Lesson2/FirstBitEA.cpp | 2 ++ eo/tutorial/Lesson2/FirstRealEA.cpp | 2 ++ eo/tutorial/Lesson2/exercise2.3.cpp | 2 ++ eo/tutorial/Lesson3/SecondBitEA.cpp | 2 ++ eo/tutorial/Lesson3/exercise3.1.cpp | 2 ++ 13 files changed, 51 insertions(+), 56 deletions(-) diff --git a/eo/src/eo b/eo/src/eo index 95b80408..b3c5149d 100644 --- a/eo/src/eo +++ b/eo/src/eo @@ -61,46 +61,26 @@ #include #include -//#include - -//#include -//#include #include -#include -#include #include -//#include -//#include -//#include #include -//#include -//#include -//#include -//#include -//#include -//#include - #include -#include -#include -#include // Evaluation functions #include #include -// Continuators -// #include // already included in the following +// Continuators - all include eoContinue.h #include #include #include #include // Selection -// the eoSelectOne +// the eoSelectOne's #include #include #include @@ -111,7 +91,9 @@ #include #include #include -// other batch selections +// other batch selections +// DetSelect probably shoudl be turned into an eoSelectOne +// (using setup and an index) #include @@ -127,14 +109,7 @@ #include #include -//#include -//#include -//#include -//#include -//#include - -//#include - +// a simple transformer #include // Algorithms @@ -151,16 +126,12 @@ #include // aliens -//#include #include //----------------------------------------------------------------------------- // to be continued ... //----------------------------------------------------------------------------- -/* -//#include -//#include -*/ + //----------------------------------------------------------------------------- #endif _eo_ diff --git a/eo/src/eoGenericQuadOp.h b/eo/src/eoGenericQuadOp.h index 0df6b966..95b3667d 100644 --- a/eo/src/eoGenericQuadOp.h +++ b/eo/src/eoGenericQuadOp.h @@ -50,7 +50,7 @@ class eoGenericQuadOp: public eoOp, public eoBF public: /// Ctor eoGenericQuadOp() - : eoOp( eoOp::binary ) {}; + : eoOp( eoOp::quadratic ) {}; virtual string className() const {return "eoGenericQuadOp";}; }; diff --git a/eo/src/es/eoEsChromInit.h b/eo/src/es/eoEsChromInit.h index 41fa33ba..43a61af0 100644 --- a/eo/src/es/eoEsChromInit.h +++ b/eo/src/es/eoEsChromInit.h @@ -27,7 +27,7 @@ #ifndef _eoEsChromInit_H #define _eoEsChromInit_H -#include +#include #include #include #include @@ -59,7 +59,7 @@ class eoEsChromInit : public eoInit public : typedef typename EOT::Fitness FitT; - eoEsChromInit(eoEsObjectiveBounds& _bounds) : bounds(_bounds) + eoEsChromInit(eoRealVectorBounds& _bounds) : bounds(_bounds) {} void operator()(EOT& _eo) @@ -71,29 +71,28 @@ private : eoEsSimple& create(eoEsSimple& result) { - result.resize(bounds.chromSize()); + result.resize(bounds.size()); - for (unsigned i = 0; i < result.size(); ++i) - { - result[i] = bounds.minimum(i) + rng.uniform(bounds.maximum(i) - bounds.minimum(i)); - } + bounds.uniform(result); + + result.stdev = 0.3*bounds.averageRange(); // 0.3 should be read as a parameter return result; } eoEsStdev create(eoEsStdev& result) { - unsigned chromSize = bounds.chromSize(); + unsigned chromSize = bounds.size(); result.resize(chromSize); result.stdevs.resize(chromSize); + bounds.uniform(result); for (unsigned i = 0; i < chromSize; ++i) { - double length = bounds.maximum(i) - bounds.minimum(i); - result[i] = bounds.minimum(i) + rng.uniform(length); - - // Just a guess at the stdevs (anyone a better idea?) - result.stdevs[i] = rng.uniform(length); + // uniformly in [0.2,0.4) + // scaled by the range of the object variable) + // Just a guess (anyone a better idea?) + result.stdevs[i] = bounds.range(i) * (0.2 + 0.2*eo::rng.uniform()); } return result; @@ -101,7 +100,7 @@ private : eoEsFull create(eoEsFull& result) { - unsigned chromSize = bounds.chromSize(); + unsigned chromSize = bounds.size(); result.resize(chromSize); result.stdevs.resize(chromSize); @@ -128,7 +127,7 @@ private : return result; } - eoEsObjectiveBounds& bounds; + eoRealVectorBounds& bounds; }; #endif diff --git a/eo/src/es/eoRealBounds.h b/eo/src/es/eoRealBounds.h index 97b5f551..19b4c1e9 100644 --- a/eo/src/es/eoRealBounds.h +++ b/eo/src/es/eoRealBounds.h @@ -204,11 +204,15 @@ public: // virtual desctructor (to avoid warining?) virtual ~eoRealVectorBounds(){} + // Default Ctor + eoRealVectorBounds() : + vector(0) {} + /** Simple bounds = minimum and maximum (allowed) */ // Ctor: same bonds for everybody, explicit - eoRealVectorBounds(unsigned _dim, double _min=0, double _max=1) : + eoRealVectorBounds(unsigned _dim, double _min, double _max) : vector(_dim, new eoRealInterval(_min, _max)) { if (_max-_min<=0) @@ -328,7 +332,7 @@ public: Simple bounds = minimum and maximum (allowed) */ // Ctor: nothing to do! - eoRealVectorNoBounds(unsigned _dim=0) : eoRealVectorBounds(_dim) {} + eoRealVectorNoBounds(unsigned _dim=0) {} virtual bool isBounded(unsigned) {return false;} diff --git a/eo/test/t-eobin.cpp b/eo/test/t-eobin.cpp index 55dee20b..feee305d 100644 --- a/eo/test/t-eobin.cpp +++ b/eo/test/t-eobin.cpp @@ -25,8 +25,8 @@ #include // cout #include // ostrstream, istrstream -#include // eoBin - +#include // general EO +#include // bitstring representation & operators #include "binary_value.h" //----------------------------------------------------------------------------- diff --git a/eo/tutorial/Lesson1/FirstBitGA.cpp b/eo/tutorial/Lesson1/FirstBitGA.cpp index 97b5a0f8..1ea79a76 100644 --- a/eo/tutorial/Lesson1/FirstBitGA.cpp +++ b/eo/tutorial/Lesson1/FirstBitGA.cpp @@ -16,6 +16,8 @@ // REPRESENTATION //----------------------------------------------------------------------------- +// Include the corresponding file +#include // bitstring representation & operators // define your individuals typedef eoBin Indi; // A bitstring with fitness double @@ -87,6 +89,11 @@ void main_function(int argc, char **argv) // Print (sorted) intial population (raw printout) cout << "Initial Population" << endl; cout << pop; + // shuffle - this is a test + pop.shuffle(); + // Print (sorted) intial population (raw printout) + cout << "Shuffled Population" << endl; + cout << pop; // ENGINE ///////////////////////////////////// diff --git a/eo/tutorial/Lesson1/FirstRealGA.cpp b/eo/tutorial/Lesson1/FirstRealGA.cpp index f1b719a6..5e1c69e4 100644 --- a/eo/tutorial/Lesson1/FirstRealGA.cpp +++ b/eo/tutorial/Lesson1/FirstRealGA.cpp @@ -16,6 +16,8 @@ // REPRESENTATION //----------------------------------------------------------------------------- +// Include the corresponding file +#include // real-representation & operators // define your individuals typedef eoReal Indi; diff --git a/eo/tutorial/Lesson1/exercise1.3.cpp b/eo/tutorial/Lesson1/exercise1.3.cpp index c0c248c8..f2e03652 100644 --- a/eo/tutorial/Lesson1/exercise1.3.cpp +++ b/eo/tutorial/Lesson1/exercise1.3.cpp @@ -17,6 +17,8 @@ #include //----------------------------------------------------------------------------- +// Include the corresponding file +#include // bitstring representation & operators // define your individuals typedef eoBin Indi; // A bitstring with fitness double diff --git a/eo/tutorial/Lesson2/FirstBitEA.cpp b/eo/tutorial/Lesson2/FirstBitEA.cpp index 0c34adae..a5b3e0de 100644 --- a/eo/tutorial/Lesson2/FirstBitEA.cpp +++ b/eo/tutorial/Lesson2/FirstBitEA.cpp @@ -16,6 +16,8 @@ // REPRESENTATION //----------------------------------------------------------------------------- +// Include the corresponding file +#include // bitstring representation & operators // define your individuals typedef eoBin Indi; // A bitstring with fitness double diff --git a/eo/tutorial/Lesson2/FirstRealEA.cpp b/eo/tutorial/Lesson2/FirstRealEA.cpp index 7c5b4580..934fb0c3 100644 --- a/eo/tutorial/Lesson2/FirstRealEA.cpp +++ b/eo/tutorial/Lesson2/FirstRealEA.cpp @@ -16,6 +16,8 @@ // REPRESENTATION //----------------------------------------------------------------------------- +// Include the corresponding file +#include // real-valued representation & operators // define your individuals typedef eoReal Indi; diff --git a/eo/tutorial/Lesson2/exercise2.3.cpp b/eo/tutorial/Lesson2/exercise2.3.cpp index 48995698..09b6bbc0 100644 --- a/eo/tutorial/Lesson2/exercise2.3.cpp +++ b/eo/tutorial/Lesson2/exercise2.3.cpp @@ -16,6 +16,8 @@ // REPRESENTATION //----------------------------------------------------------------------------- +// Include the corresponding file +#include // bitstring representation & operators // define your individuals typedef eoBin Indi; // A bitstring with fitness double diff --git a/eo/tutorial/Lesson3/SecondBitEA.cpp b/eo/tutorial/Lesson3/SecondBitEA.cpp index 5ec56882..60412fb1 100644 --- a/eo/tutorial/Lesson3/SecondBitEA.cpp +++ b/eo/tutorial/Lesson3/SecondBitEA.cpp @@ -20,6 +20,8 @@ // REPRESENTATION //----------------------------------------------------------------------------- +// Include the corresponding file +#include // bitstring representation & operators // define your genotype and fitness types typedef eoBin Indi; diff --git a/eo/tutorial/Lesson3/exercise3.1.cpp b/eo/tutorial/Lesson3/exercise3.1.cpp index 66532bb9..5264002e 100644 --- a/eo/tutorial/Lesson3/exercise3.1.cpp +++ b/eo/tutorial/Lesson3/exercise3.1.cpp @@ -21,6 +21,8 @@ // REPRESENTATION //----------------------------------------------------------------------------- +// Include the corresponding file +#include // bitstring representation & operators // define your genotype and fitness types typedef eoBin Indi;