From f48fbcf51a17e76138a0eda1944b70251fe724ae Mon Sep 17 00:00:00 2001 From: gustavoromero Date: Wed, 8 Nov 2000 12:56:14 +0000 Subject: [PATCH] adding a include for apply.h --- eo/src/eoSGA.h | 84 +++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/eo/src/eoSGA.h b/eo/src/eoSGA.h index 110430b4..fecd9557 100644 --- a/eo/src/eoSGA.h +++ b/eo/src/eoSGA.h @@ -34,6 +34,7 @@ #include #include #include +#include /** The Simple Genetic Algorithm, following Holland and Goldberg * Needs a selector (class eoSelectOne) a crossover (eoQuadratic, @@ -47,13 +48,13 @@ template class eoSGA : public eoAlgo { public : - eoSGA( + eoSGA( eoContinue& _cont, eoMonOp& _mutate, float _mrate, eoQuadraticOp& _cross, float _crate, eoSelectOne& _select, eoEvalFunc& _eval) - : cont(_cont), + : cont(_cont), mutate(_mutate), mutationRate(_mrate), cross(_cross), @@ -63,13 +64,13 @@ public : // added this second ctor as I didn't like the ordering of the parameters // in the one above. Any objection :-) MS - eoSGA( + eoSGA( eoSelectOne& _select, eoQuadraticOp& _cross, float _crate, eoMonOp& _mutate, float _mrate, eoEvalFunc& _eval, eoContinue& _cont) - : cont(_cont), + : cont(_cont), mutate(_mutate), mutationRate(_mrate), cross(_cross), @@ -77,49 +78,48 @@ public : select(_select), eval(_eval) {} - void operator()(eoPop& _pop) - { - eoPop offspring; + void operator()(eoPop& _pop) + { + eoPop offspring; - do - { - select(_pop, offspring); + do + { + select(_pop, offspring); - unsigned i; + unsigned i; - for (i=0; i<_pop.size()/2; i++) - { - if ( rng.flip(crossoverRate) ) - { - // this crossover generates 2 offspring from two parents - cross(offspring[2*i], offspring[2*i+1]); - } - } - - for (i=0; i < _pop.size(); i++) - { - if (rng.flip(mutationRate) ) - { - mutate(offspring[i]); - } - - } - - _pop.swap(offspring); - apply(eval, _pop); - - } while (cont(_pop)); - } - + for (i=0; i<_pop.size()/2; i++) + { + if ( rng.flip(crossoverRate) ) + { + // this crossover generates 2 offspring from two parents + cross(offspring[2*i], offspring[2*i+1]); + } + } + + for (i=0; i < _pop.size(); i++) + { + if (rng.flip(mutationRate) ) + { + mutate(offspring[i]); + } + } + + _pop.swap(offspring); + apply(eval, _pop); + + } while (cont(_pop)); + } + private : - eoContinue& cont; - eoMonOp& mutate; - float mutationRate; - eoQuadraticOp& cross; - float crossoverRate; - eoSelectPerc select; - eoEvalFunc& eval; + eoContinue& cont; + eoMonOp& mutate; + float mutationRate; + eoQuadraticOp& cross; + float crossoverRate; + eoSelectPerc select; + eoEvalFunc& eval; }; #endif