added eoExtendedvelocity (+doc + test) that takes both the local best and the global of a PSO topology into account. Also updated the doc tags for the other topologies and velocities

This commit is contained in:
tlegrand 2008-04-18 08:50:22 +00:00
commit 78a798d169
7 changed files with 110 additions and 46 deletions

View file

@ -71,6 +71,7 @@ SET (TEST_LIST t-eoParetoFitness
t-eoRingTopology
t-eoSyncEasyPSO
t-eoOrderXover
t-eoExtendedVelocity
# t-eoFrontSorter
# t-eoEpsMOEA
)

View file

@ -0,0 +1,76 @@
//-----------------------------------------------------------------------------
// t-eoExtendedVelocity.cpp
//-----------------------------------------------------------------------------
#include <eo>
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;
}
}
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;
}
}

View file

@ -16,7 +16,7 @@ double f (const Indi & _indi)
return (-sum);
}
int the_main(int argc, char **argv)
int main_function(int argc, char **argv)
{
//Parameters
const unsigned int VEC_SIZE = 2;
@ -31,7 +31,6 @@ int the_main(int argc, char **argv)
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);
@ -58,11 +57,11 @@ int main(int argc, char **argv)
{
try
{
the_main(argc, argv);
main_function(argc, argv);
}
catch(std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
std::cout << "Exception: " << e.what() << " in t-eoRingTopology" << std::endl;
}
}