00001
00002
00003
00004
00005
00006 #include <eo>
00007
00008 typedef eoRealParticle < double > Particle;
00009
00010
00011 double f (const Particle & _particle)
00012 {
00013 double sum = 0;
00014 for (unsigned i = 0; i < _particle.size (); i++)
00015 sum += pow(_particle[i],2);
00016 return (-sum);
00017 }
00018
00019 int main_function(int argc, char **argv)
00020 {
00021 const unsigned POP_SIZE = 6, VEC_SIZE = 2, NEIGHBORHOOD_SIZE=2;
00022
00023
00024 eoPop<Particle> pop;
00025
00026
00027 eoEvalFuncPtr<Particle, double, const Particle& > eval( f );
00028
00029
00030 eoUniformGenerator < double >uGen (-3, 3);
00031 eoInitFixedLength < Particle > random (VEC_SIZE, uGen);
00032 eoUniformGenerator < double >sGen (-2, 2);
00033 eoVelocityInitFixedLength < Particle > veloRandom (VEC_SIZE, sGen);
00034 eoFirstIsBestInit < Particle > localInit;
00035 pop.append (POP_SIZE, random);
00036
00037
00038 eoLinearTopology<Particle> topology(NEIGHBORHOOD_SIZE);
00039 eoInitializer <Particle> init(eval,veloRandom,localInit,topology,pop);
00040 init();
00041
00042
00043 eoExtendedVelocity <Particle> velocity (topology,1,1,1,1);
00044
00045
00046 for (unsigned int i = 0; i < POP_SIZE; i++)
00047 {
00048 std::cout << " Initial particle n°" << i << " velocity: " << std::endl;
00049 for (unsigned int j = 0; j < VEC_SIZE; j++)
00050 std::cout << " v" << j << "=" << pop[i].velocities[j] << std::endl;
00051 }
00052
00053 for (unsigned int i = 0; i < POP_SIZE; i++)
00054 velocity (pop[i],i);
00055
00056 for (unsigned int i = 0; i < POP_SIZE; i++)
00057 {
00058 std::cout << " Final particle n°" << i << " velocity: " << std::endl;
00059 for (unsigned int j = 0; j < VEC_SIZE; j++)
00060 std::cout << " v" << j << "=" << pop[i].velocities[j] << std::endl;
00061 }
00062
00063 }
00064
00065 int main(int argc, char **argv)
00066 {
00067 try
00068 {
00069 main_function(argc, argv);
00070 }
00071 catch(std::exception& e)
00072 {
00073 std::cout << "Exception: " << e.what() << " in t-eoExtendedVelocity" << std::endl;
00074 }
00075
00076 }