From 9174a37355fc7b48d6ee3266b9b4ea763a138b82 Mon Sep 17 00:00:00 2001 From: tlegrand Date: Thu, 11 Oct 2007 14:08:06 +0000 Subject: [PATCH] added PSO ring topology test --- eo/test/t-eoRingTopology.cpp | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 eo/test/t-eoRingTopology.cpp diff --git a/eo/test/t-eoRingTopology.cpp b/eo/test/t-eoRingTopology.cpp new file mode 100644 index 00000000..9fd1a47c --- /dev/null +++ b/eo/test/t-eoRingTopology.cpp @@ -0,0 +1,68 @@ +//----------------------------------------------------------------------------- +// t-eoRingTopology.cpp +//----------------------------------------------------------------------------- + + +#include + +typedef eoRealParticle < double >Indi; + +//Evaluation function +double f (const Indi & _indi) +{ + double sum = 0; + for (unsigned i = 0; i < _indi.size (); i++) + sum += pow(_indi[i],2); + return (-sum); +} + +int the_main(int argc, char **argv) +{ + //Parameters + const unsigned int VEC_SIZE = 2; + const unsigned int POP_SIZE = 10; + const unsigned int NEIGHBORHOOD_SIZE= 3; + + rng.reseed (33); + eoEvalFuncPtr plainEval(f); + eoEvalFuncCounter < Indi > eval (plainEval); + eoUniformGenerator < double >uGen (0., 5.); + eoInitFixedLength < Indi > random (VEC_SIZE, uGen); + eoUniformGenerator < double >sGen (-1., 1.); + eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen); + eoFirstIsBestInit < Indi > localInit; + eoStandardFlight < Indi > flight; + eoPop < Indi > pop; + pop.append (POP_SIZE, random); + apply(eval, pop); + apply < Indi > (veloRandom, pop); + apply < Indi > (localInit, pop); + eoRingTopology topology(NEIGHBORHOOD_SIZE); + topology.setup(pop); + std::cout<<"\n\n\nPopulation :\n\n"<