Added new lesson (6) dedicated to the PSO. Also changed a few things into the PSO-dedicated components (constructors)

This commit is contained in:
tlegrand 2008-03-04 14:01:29 +00:00
commit 4ad79a9148
17 changed files with 771 additions and 115 deletions

View file

@ -30,7 +30,6 @@
#include <eoPSO.h>
#include <eoVelocity.h>
#include <eoFlight.h>
#include <eoDummyFlight.h>
//-----------------------------------------------------------------------------
/** An easy-to-use particle swarm algorithm; you can use any particle,
@ -47,7 +46,7 @@ template < class POT > class eoEasyPSO:public eoPSO < POT >
public:
/** Full constructor
* @param _init - An eoInitializer that initializes the topology, velocity, best particle(s)
* @param _init - An eoInitializerBase that initializes the topology, velocity, best particle(s)
* @param _continuator - An eoContinue that manages the stopping criterion and the checkpointing system
* @param _eval - An eoEvalFunc: the evaluation performer
* @param _velocity - An eoVelocity that defines how to compute the velocities
@ -55,7 +54,7 @@ public:
* to modify the positions according to the velocities
*/
eoEasyPSO (
eoInitializer <POT> &_init,
eoInitializerBase <POT> &_init,
eoContinue < POT > &_continuator,
eoEvalFunc < POT > &_eval,
eoVelocity < POT > &_velocity,
@ -69,13 +68,13 @@ public:
/** Constructor without eoFlight. For special cases when the flight is performed withing the velocity.
* @param _init - An eoInitializer that initializes the topology, velocity, best particle(s)
* @param _init - An eoInitializerBase that initializes the topology, velocity, best particle(s)
* @param _continuator - An eoContinue that manages the stopping criterion and the checkpointing system
* @param _eval - An eoEvalFunc: the evaluation performer
* @param _velocity - An eoVelocity that defines how to compute the velocities
*/
eoEasyPSO (
eoInitializer <POT> &_init,
eoInitializerBase <POT> &_init,
eoContinue < POT > &_continuator,
eoEvalFunc < POT > &_eval,
eoVelocity < POT > &_velocity):
@ -86,6 +85,43 @@ public:
flight (dummyFlight)
{}
/* Constructor without eoInitializerBase. Assume the initialization is done before running the algorithm
* @param _continuator - An eoContinue that manages the stopping criterion and the checkpointing system
* @param _eval - An eoEvalFunc: the evaluation performer
* @param _velocity - An eoVelocity that defines how to compute the velocities
* @param _flight - An eoFlight that defines how to make the particle flying: that means how
* to modify the positions according to the velocities
*/
eoEasyPSO (
eoContinue < POT > &_continuator,
eoEvalFunc < POT > &_eval,
eoVelocity < POT > &_velocity,
eoFlight < POT > &_flight):
init(dummyInit),
continuator (_continuator),
eval (_eval),
velocity (_velocity),
flight (_flight)
{}
/** Constructor without eoFlight nor eoInitializerBase. For special cases when the flight is performed withing the velocity.
* @param _continuator - An eoContinue that manages the stopping criterion and the checkpointing system
* @param _eval - An eoEvalFunc: the evaluation performer
* @param _velocity - An eoVelocity that defines how to compute the velocities
*/
eoEasyPSO (
eoContinue < POT > &_continuator,
eoEvalFunc < POT > &_eval,
eoVelocity < POT > &_velocity):
init(dummyInit),
continuator (_continuator),
eval (_eval),
velocity (_velocity),
flight (dummyFlight)
{}
/// Apply a few iteration of flight to the population (=swarm).
virtual void operator () (eoPop < POT > &_pop)
{
@ -124,15 +160,29 @@ public:
}
private:
eoInitializer <POT> &init;
protected:
eoInitializerBase <POT> &init;
eoContinue < POT > &continuator;
eoEvalFunc < POT > &eval;
eoVelocity < POT > &velocity;
eoFlight < POT > &flight;
// if the flight does not need to be used, use the dummy flight instance
eoDummyFlight<POT> dummyFlight;
// if the flight does not need to be used, use the dummy flight instance
class eoDummyFlight:public eoFlight < POT >
{
public:
eoDummyFlight () {}
void operator () (POT & _po) {}
}dummyFlight;
// if the initializer does not need to be used, use the dummy one instead
class eoDummyInitializer:public eoInitializerBase < POT >
{
public:
eoDummyInitializer () {}
void operator () (POT & _po) {}
}dummyInit;
};