From ed0e76350a80da4a0087f3b778e6abcb8a88f4ec Mon Sep 17 00:00:00 2001 From: evomarc Date: Tue, 19 Dec 2000 18:43:25 +0000 Subject: [PATCH] Update after the change in replacements --- eo/tutorial/Lesson2/FirstBitEA.cpp | 4 ++-- eo/tutorial/Lesson2/FirstRealEA.cpp | 13 ++++--------- eo/tutorial/Lesson2/exercise3.cpp | 4 ++-- eo/tutorial/Lesson3/SecondBitEA.cpp | 10 +++++----- eo/tutorial/Lesson3/exercise1.cpp | 8 +++++--- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/eo/tutorial/Lesson2/FirstBitEA.cpp b/eo/tutorial/Lesson2/FirstBitEA.cpp index 440d47963..331afbecb 100644 --- a/eo/tutorial/Lesson2/FirstBitEA.cpp +++ b/eo/tutorial/Lesson2/FirstBitEA.cpp @@ -79,7 +79,7 @@ void main_function(int argc, char **argv) // Initialization of the population eoPop pop(POP_SIZE, random); - // and evaluate it in one line + // and evaluate it in one loop apply(eval, pop); // STL syntax // OUTPUT @@ -102,7 +102,7 @@ void main_function(int argc, char **argv) // REPLACE // And we now have the full slection/replacement - though with // no replacement (== generational replacement) at the moment :-) - eoNoReplacement replace; + eoGenerationalReplacement replace; // OPERATORS ////////////////////////////////////// diff --git a/eo/tutorial/Lesson2/FirstRealEA.cpp b/eo/tutorial/Lesson2/FirstRealEA.cpp index 8711e3c68..43256c700 100644 --- a/eo/tutorial/Lesson2/FirstRealEA.cpp +++ b/eo/tutorial/Lesson2/FirstRealEA.cpp @@ -45,13 +45,11 @@ void main_function(int argc, char **argv) const float P_MUT = 0.5; // mutation probability const double EPSILON = 0.01; // range for real uniform mutation - const double SIGMA = 0.01; // std. dev. of normal mutation // some parameters for chosing among different operators const double segmentRate = 0.5; // rate for 1-pt Xover const double arithmeticRate = 0.5; // rate for 2-pt Xover const double uniformMutRate = 0.5; // rate for bit-flip mutation const double detMutRate = 0.5; // rate for one-bit mutation - const double normMutRate = 0.5; // rate for normal mutation // GENERAL ////////////////////////// @@ -79,7 +77,7 @@ void main_function(int argc, char **argv) // Initialization of the population eoPop pop(POP_SIZE, random); - // and evaluate it in one line + // and evaluate it in one loop apply(eval, pop); // STL syntax // OUTPUT @@ -102,7 +100,7 @@ void main_function(int argc, char **argv) // REPLACE // And we now have the full slection/replacement - though with // no replacement (== generational replacement) at the moment :-) - eoNoReplacement replace; + eoGenerationalReplacement replace; // OPERATORS ////////////////////////////////////// @@ -115,19 +113,16 @@ void main_function(int argc, char **argv) eoArithmeticCrossover xoverA; // Combine them with relative rates eoPropCombinedQuadOp xover(xoverS, segmentRate); - xover.add(xoverA, arithmeticRate, eo_verbose); + xover.add(xoverA, arithmeticRate, true); // MUTATION - // Gaussian mutation - std dev as argument - eoNormalMutation mutationN(SIGMA); // offspring(i) uniformly chosen in [parent(i)-epsilon, parent(i)+epsilon] eoUniformMutation mutationU(EPSILON); // k (=1) coordinates of parents are uniformly modified eoDetUniformMutation mutationD(EPSILON); // Combine them with relative rates eoPropCombinedMonOp mutation(mutationU, uniformMutRate); - mutation.add(mutationD, detMutRate); - mutation.add(mutationN, normMutRate, eo_verbose); + mutation.add(mutationD, detMutRate, true); // STOP // CHECKPOINT diff --git a/eo/tutorial/Lesson2/exercise3.cpp b/eo/tutorial/Lesson2/exercise3.cpp index c8e7ab6c7..daff8e639 100644 --- a/eo/tutorial/Lesson2/exercise3.cpp +++ b/eo/tutorial/Lesson2/exercise3.cpp @@ -34,7 +34,7 @@ void main_function(int argc, char **argv) // PARAMETRES 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 VEC_SIZE = 20; // Number of bits in genotypes const unsigned int POP_SIZE = 20; // Size of population const unsigned int MAX_GEN = 500; // Maximum number of generation before STOP @@ -98,7 +98,7 @@ void main_function(int argc, char **argv) eoDetTournament selectOne(T_SIZE); // T_SIZE in [2,POP_SIZE] // solution solution solution solution solution solution solution // modify the rate in the constructor - eoSelectPerc select(selectOne,2.0);// rate is second arg. + eoSelectMany select(selectOne,2, eo_is_an_integer);// rate is second arg. // REPLACE // solution solution solution solution solution solution solution diff --git a/eo/tutorial/Lesson3/SecondBitEA.cpp b/eo/tutorial/Lesson3/SecondBitEA.cpp index c60f29635..731db5426 100644 --- a/eo/tutorial/Lesson3/SecondBitEA.cpp +++ b/eo/tutorial/Lesson3/SecondBitEA.cpp @@ -218,8 +218,8 @@ void main_function(int argc, char **argv) // REPLACE // And we now have the full slection/replacement - though with - // no replacement (== generational replacement) at the moment :-) - eoNoReplacement replace; + // the same generational replacement at the moment :-) + eoGenerationalReplacement replace; // OPERATORS ////////////////////////////////////// @@ -235,7 +235,7 @@ void main_function(int argc, char **argv) // Combine them with relative rates eoPropCombinedQuadOp xover(xover1, onePointRate); xover.add(xoverU, URate); - xover.add(xover2, twoPointsRate, eo_verbose); + xover.add(xover2, twoPointsRate, true); // MUTATION // standard bit-flip mutation for bitstring @@ -244,7 +244,7 @@ void main_function(int argc, char **argv) eoDetBitFlip mutationOneBit; // Combine them with relative rates eoPropCombinedMonOp mutation(mutationBitFlip, bitFlipRate); - mutation.add(mutationOneBit, oneBitRate, eo_verbose); + mutation.add(mutationOneBit, oneBitRate, true); // The operators are encapsulated into an eoTRansform object eoSGATransform transform(xover, pCross, mutation, pMut); @@ -294,7 +294,7 @@ void main_function(int argc, char **argv) checkpoint.add(SecondStat); // The Stdout monitor will print parameters to the screen ... - eoStdoutMonitor monitor(eo_no_verbose); + eoStdoutMonitor monitor(false); // when called by the checkpoint (i.e. at every generation) checkpoint.add(monitor); diff --git a/eo/tutorial/Lesson3/exercise1.cpp b/eo/tutorial/Lesson3/exercise1.cpp index 984395302..35ed26c9d 100644 --- a/eo/tutorial/Lesson3/exercise1.cpp +++ b/eo/tutorial/Lesson3/exercise1.cpp @@ -203,10 +203,11 @@ void main_function(int argc, char **argv) // OUTPUT // sort pop for pretty printout - pop.sort(); + // pop.sort(); // Print (sorted) intial population (raw printout) - cout << "Initial Population" << endl << pop << endl; - + cout << "Initial Population" << endl << pop ; + cout << "and best is " << pop.best_element() << "\n\n"; + cout << "and worse is " << pop.worse_element() << "\n\n"; // ENGINE ///////////////////////////////////// // selection and replacement @@ -221,6 +222,7 @@ void main_function(int argc, char **argv) // And we now have the full slection/replacement - though with // no replacement (== generational replacement) at the moment :-) eoNoReplacement replace; + // eoWeakElitistReplacement replace(replace_main); // OPERATORS //////////////////////////////////////