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

@ -161,7 +161,8 @@
// velocities
#include <eoVelocity.h>
#include <eoStandardVelocity.h>
#include <eoStandardVelocity.h>
#include <eoExtendedVelocity.h>
#include <eoIntegerVelocity.h>
#include <eoConstrictedVelocity.h>
#include <eoFixedInertiaWeightedVelocity.h>

View file

@ -162,17 +162,19 @@ public:
return (neighborhoods[theGoodNhbd].best());
}
/*
/*
* Return the global best of the topology
*/
virtual POT & globalBest(const eoPop<POT>& _pop)
*/
virtual POT & globalBest()
{
unsigned howManyNeighborhood=_pop.size()/ neighborhoodSize;
POT gBest,tmp;
unsigned indGlobalBest=0;
unsigned indGlobalBest=0;
if(neighborhoods.size()==1)
return neighborhoods[0].best();
gBest=neighborhoods[0].best();
for(unsigned i=1;i<howManyNeighborhood;i++)
for(unsigned i=1;i<neighborhoods.size();i++)
{
tmp=neighborhoods[i].best();
if(gBest.best() < tmp.best())

View file

@ -37,8 +37,9 @@
/** Standard velocity performer for particle swarm optimization. Derivated from abstract eoVelocity,
* At step t: v(t+1)= w * v(t) + c1 * r1 * ( xbest(t)-x(t) ) + c2 * r2 * ( gbest(t) - x(t) )
* (ci given and Ri chosen at random in [0;1]).
* At step t: v(t+1)= w * v(t) + c1 * r1 * ( xbest(t)-x(t) ) + c2 * r2 * ( lbest(t) - x(t) )
* lbest depends on the topology evolved, when using eoStarTopology, lbest corresponds to the
* global. Otherwise, lbest is a "local best", i.e the best in a neighborhood.
*/
template < class POT > class eoStandardVelocity:public eoVelocity < POT >
{
@ -53,8 +54,8 @@ public:
/** Full constructor: Bounds and bound modifier required
* @param _topology - The topology to get the global/local/other best
* @param _w - The weight factor.
* @param _c1 - The second learning factor used for the particle's best. Type must be POT::ParticleVelocityType
* @param _c2 - The third learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
* @param _c1 - Learning factor used for the particle's best. Type must be POT::ParticleVelocityType
* @param _c2 - Learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
* @param _bounds - An eoRealBaseVectorBounds: real bounds for real velocities.
* If the velocities are not real, they won't be bounded by default. Should have a eoBounds ?
* @param _boundsModifier - An eoRealBoundModifier used to modify the bounds (for real bounds only).
@ -79,8 +80,8 @@ public:
/** Constructor: No bound updater required <-> fixed bounds
* @param _topology - The topology to get the global/local/other best
* @param _w - The weight factor.
* @param _c1 - The second learning factor used for the particle's best. Type must be POT::ParticleVelocityType
* @param _c2 - The third learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
* @param _c1 - Learning factor used for the particle's best. Type must be POT::ParticleVelocityType
* @param _c2 - Learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
* @param _bounds - An eoRealBaseVectorBounds: real bounds for real velocities.
* If the velocities are not real, they won't be bounded by default. Should have a eoBounds ?
* @param _gen - The eo random generator, default=rng
@ -101,9 +102,10 @@ public:
/** Constructor: Neither bounds nor bound updater required <-> free velocity
* @param _topology - The topology to get the global/local/other best
* @param _w - The weight factor.
* @param _c1 - The second learning factor used for the particle's best. Type must be POT::ParticleVelocityType
* @param _c2 - The third learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
* @param _c1 - Learning factor used for the particle's best. Type must be POT::ParticleVelocityType
* @param _c2 - Learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
* @param _gen - The eo random generator, default=rng
*/
eoStandardVelocity (eoTopology < POT > & _topology,

View file

@ -59,36 +59,19 @@ public:
for (unsigned i = 0; i < _pop.size (); i++)
updateNeighborhood(_pop[i],i);
}
/**
* Builds the neighborhoods contained in the topology.
*/
virtual POT & best (unsigned ) = 0;
/*
* Returns the global best particle of the given population.
* Even if the extended topology does not define a global best,
* it should always be possible to get it by searching in all the neighborhoods.
* This method is virtual in order not to have to define it in all the extended topologies.
*/
virtual POT & globalBest(const eoPop<POT>& _pop)
{
POT gBest,tmp;
unsigned indGlobalBest=0;
gBest=best(0);
for(unsigned i=1;i<_pop.size();i++)
{
tmp=best(i);
if(gBest.best() < tmp.best())
{
gBest=tmp;
indGlobalBest=i;
}
}
return best(indGlobalBest);
}
virtual POT & best (unsigned ) = 0;
/*
* Return the global best of the topology
*/
virtual POT & globalBest(){}
/**
* Prints the neighborhoods contained in the topology.