From c438dc7863aa43744287dea4a3d5d379402d83f5 Mon Sep 17 00:00:00 2001 From: legrand Date: Wed, 9 Jan 2008 09:20:29 +0000 Subject: [PATCH] added shit init (size init) for main7 + corrected velocity constructor errors git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@865 331e1502-861f-0410-8da2-ba01fb791d7f --- .../paradiseo-peo/tutorial/Wrapper/main3.cpp | 3 ++- .../paradiseo-peo/tutorial/Wrapper/main4.cpp | 5 ++-- .../paradiseo-peo/tutorial/Wrapper/main7.cpp | 27 +++++++++++++++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/main3.cpp b/trunk/paradiseo-peo/tutorial/Wrapper/main3.cpp index eb593a4e1..9c5b20739 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/main3.cpp +++ b/trunk/paradiseo-peo/tutorial/Wrapper/main3.cpp @@ -24,6 +24,7 @@ int main( int __argc, char** __argv ) const double INIT_POSITION_MAX = 2.0; const double INIT_VELOCITY_MIN = -1.; const double INIT_VELOCITY_MAX = 1.; + const double weight = 1; const double C1 = 0.5; const double C2 = 2.; rng.reseed (time(0)); @@ -45,7 +46,7 @@ int main( int __argc, char** __argv ) pop.append (POP_SIZE, random); eoLinearTopology topology(NEIGHBORHOOD_SIZE); eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX); - eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds); + eoStandardVelocity < Indi > velocity (topology,weight,C1,C2,bnds); eoInitializer init(eval,veloRandom,localInit,topology,pop); // Parallel algorithm diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp b/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp index 8fad0059a..491e8f863 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp +++ b/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp @@ -25,6 +25,7 @@ int main( int __argc, char** __argv ) const double INIT_VELOCITY_MIN = -1.; const double INIT_VELOCITY_MAX = 1.; const unsigned int MIG_FREQ = 10; + const double omega = 1; const double C1 = 0.5; const double C2 = 2.; rng.reseed (time(0)); @@ -50,7 +51,7 @@ int main( int __argc, char** __argv ) pop.append (POP_SIZE, random); eoLinearTopology topology(NEIGHBORHOOD_SIZE); eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX); - eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds); + eoStandardVelocity < Indi > velocity (topology,omega,C1,C2,bnds); eoInitializer init(eval,veloRandom,localInit,topology,pop); // Island model @@ -79,7 +80,7 @@ int main( int __argc, char** __argv ) pop2.append (POP_SIZE, random2); eoLinearTopology topology2(NEIGHBORHOOD_SIZE); eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX); - eoStandardVelocity < Indi > velocity2 (topology2,C1,C2,bnds2); + eoStandardVelocity < Indi > velocity2 (topology2,omega,C1,C2,bnds2); eoInitializer init2(eval2,veloRandom2,localInit2,topology2,pop2); // Island model diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/main7.cpp b/trunk/paradiseo-peo/tutorial/Wrapper/main7.cpp index 27cc9cb31..4a3a8aa57 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/main7.cpp +++ b/trunk/paradiseo-peo/tutorial/Wrapper/main7.cpp @@ -12,6 +12,26 @@ double f (const Indi & _indi) return (-sum); } +template +class eoResizerInit: public eoInit +{ + public: + + typedef typename EOT::AtomType AtomType; + + eoResizerInit(unsigned _size) + : size(_size){} + + virtual void operator()(EOT& chrom) + { + chrom.resize(size); + chrom.invalidate(); + } + private : + unsigned size; +}; + + int main( int __argc, char** __argv ) { @@ -24,6 +44,7 @@ int main( int __argc, char** __argv ) const double INIT_POSITION_MAX = 2.0; const double INIT_VELOCITY_MIN = -1.; const double INIT_VELOCITY_MAX = 1.; + const double omega = 1; const double C1 = 0.5; const double C2 = 2.; rng.reseed (time(0)); @@ -38,9 +59,11 @@ int main( int __argc, char** __argv ) eoStandardFlight < Indi > flight(bndsFlight); eoLinearTopology topology(NEIGHBORHOOD_SIZE); eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX); - eoStandardVelocity < Indi > velocity (topology,C1,C2,bnds); + eoStandardVelocity < Indi > velocity (topology,omega,C1,C2,bnds); - eoPop < Indi > pop(POP_SIZE); + eoResizerInit sizeInit(VEC_SIZE); + // need at least a size initialization + eoPop < Indi > pop(POP_SIZE,sizeInit); eoInitFixedLength < Indi > randomSeq (VEC_SIZE, uGen); peoMultiStart initRandom (randomSeq); peoWrapper random (initRandom,pop);