00001
00002
00003
00004
00005
00006 #include <eo>
00007
00008 typedef eoRealParticle < double >Indi;
00009
00010
00011 double f (const Indi & _indi)
00012 {
00013 double sum = 0;
00014 for (unsigned i = 0; i < _indi.size (); i++)
00015 sum += pow(_indi[i],2);
00016 return (-sum);
00017 }
00018
00019 int main_function(int argc, char **argv)
00020 {
00021
00022 const unsigned int VEC_SIZE = 2;
00023 const unsigned int POP_SIZE = 10;
00024 const unsigned int NEIGHBORHOOD_SIZE= 3;
00025
00026 rng.reseed (33);
00027 eoEvalFuncPtr<Indi, double, const Indi& > plainEval(f);
00028 eoEvalFuncCounter < Indi > eval (plainEval);
00029 eoUniformGenerator < double >uGen (0., 5.);
00030 eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
00031 eoUniformGenerator < double >sGen (-1., 1.);
00032 eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
00033 eoFirstIsBestInit < Indi > localInit;
00034 eoPop < Indi > pop;
00035 pop.append (POP_SIZE, random);
00036 apply(eval, pop);
00037 apply < Indi > (veloRandom, pop);
00038 apply < Indi > (localInit, pop);
00039 eoRingTopology<Indi> topology(NEIGHBORHOOD_SIZE);
00040 topology.setup(pop);
00041 std::cout<<"\n\n\nPopulation :\n\n"<<pop;
00042 std::cout<<"\n\nNeighborhood :\n\n";
00043 topology.printOn();
00044 int k = NEIGHBORHOOD_SIZE/2;
00045 for(unsigned i=0;i<pop.size();i++)
00046 {
00047 std::cout<<"\nBetween : ";
00048 for(unsigned j=0;j<NEIGHBORHOOD_SIZE;j++)
00049 std::cout<<"\n"<<pop[((pop.size()+i-k+j)%pop.size())];
00050 std::cout<<"\nThe best is : \n"<<topology.best(i)<<"\n";
00051 }
00052 std::cout<<"\n\n";
00053 return 1;
00054 }
00055
00056 int main(int argc, char **argv)
00057 {
00058 try
00059 {
00060 main_function(argc, argv);
00061 }
00062 catch(std::exception& e)
00063 {
00064 std::cout << "Exception: " << e.what() << " in t-eoRingTopology" << std::endl;
00065 }
00066
00067 }