paradiseo/test/eo/t-eoExtendedVelocity.cpp
Adèle Harrissart 490e837f7a * New tree configuration of the project:
.../
   ...           + -- EO
   |             |
   |             |
   +-- src ----- + -- EDO
   |             |
   |             |
   +-- test      + -- MO
   |             |
   |             |
   +-- tutorial  + -- MOEO
   |             |
   |             |
   +-- doc       + -- SMP
   |             |
   |             |
   ...           + -- EOMPI
                 |
                 |
                 + -- EOSERIAL

Question for current maintainers: ./README: new release?

Also:

* Moving out eompi & eoserial modules (issue #2).

* Correction of the errors when executing "make doc" command.

* Adding a solution for the conflicting headers problem (see the two CMake Cache
 Values: PROJECT_TAG & PROJECT_HRS_INSTALL_SUBPATH) (issue #1)

* Header inclusions:
        ** src: changing absolute paths into relative paths ('#include <...>' -> '#include "..."')
        ** test, tutorial: changing relative paths into absolute paths ('#include "..."' -> '#include <...>')

* Moving out some scripts from EDO -> to the root

* Add a new script for compilation and installation (see build_gcc_linux_install)

* Compilation with uBLAS library or EDO module: now ok

* Minor modifications on README & INSTALL files

* Comment eompi failed tests with no end

*** TODO: CPack (debian (DEB) & RedHat (RPM) packages) (issues #6 & #7) ***
2014-09-06 13:04:35 +02:00

76 lines
2.1 KiB
C++
Executable file

//-----------------------------------------------------------------------------
// t-eoExtendedVelocity.cpp
//-----------------------------------------------------------------------------
#include <paradiseo/eo.h>
typedef eoRealParticle < double > Particle;
//Evaluation function
double f (const Particle & _particle)
{
double sum = 0;
for (unsigned i = 0; i < _particle.size (); i++)
sum += pow(_particle[i],2);
return (-sum);
}
int main_function(int argc, char **argv)
{
const unsigned POP_SIZE = 6, VEC_SIZE = 2, NEIGHBORHOOD_SIZE=2;
// the population:
eoPop<Particle> pop;
// Evaluation
eoEvalFuncPtr<Particle, double, const Particle& > eval( f );
// position + velocity + best init
eoUniformGenerator < double >uGen (-3, 3);
eoInitFixedLength < Particle > random (VEC_SIZE, uGen);
eoUniformGenerator < double >sGen (-2, 2);
eoVelocityInitFixedLength < Particle > veloRandom (VEC_SIZE, sGen);
eoFirstIsBestInit < Particle > localInit;
pop.append (POP_SIZE, random);
// topology
eoLinearTopology<Particle> topology(NEIGHBORHOOD_SIZE);
eoInitializer <Particle> init(eval,veloRandom,localInit,topology,pop);
init();
// velocity
eoExtendedVelocity <Particle> velocity (topology,1,1,1,1);
// the test itself
for (unsigned int i = 0; i < POP_SIZE; i++)
{
std::cout << " Initial particle n°" << i << " velocity: " << std::endl;
for (unsigned int j = 0; j < VEC_SIZE; j++)
std::cout << " v" << j << "=" << pop[i].velocities[j] << std::endl;
}
for (unsigned int i = 0; i < POP_SIZE; i++)
velocity (pop[i],i);
for (unsigned int i = 0; i < POP_SIZE; i++)
{
std::cout << " Final particle n°" << i << " velocity: " << std::endl;
for (unsigned int j = 0; j < VEC_SIZE; j++)
std::cout << " v" << j << "=" << pop[i].velocities[j] << std::endl;
}
return EXIT_SUCCESS;
}
int main(int argc, char **argv)
{
try
{
main_function(argc, argv);
}
catch(std::exception& e)
{
std::cout << "Exception: " << e.what() << " in t-eoExtendedVelocity" << std::endl;
}
return EXIT_SUCCESS;
}