Added new lesson (6) dedicated to the PSO. Also changed a few things into the PSO-dedicated components (constructors)
This commit is contained in:
parent
4834adbe5f
commit
4ad79a9148
17 changed files with 771 additions and 115 deletions
|
|
@ -31,7 +31,6 @@
|
|||
#include <eoPSO.h>
|
||||
#include <eoVelocity.h>
|
||||
#include <eoFlight.h>
|
||||
#include <eoDummyFlight.h>
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** An easy-to-use synchronous particle swarm algorithm; you can use any particle,
|
||||
|
|
@ -48,7 +47,7 @@ template < class POT > class eoSyncEasyPSO: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
|
||||
|
|
@ -56,7 +55,7 @@ public:
|
|||
* to modify the positions according to the velocities
|
||||
*/
|
||||
eoSyncEasyPSO (
|
||||
eoInitializer <POT> &_init,
|
||||
eoInitializerBase <POT> &_init,
|
||||
eoContinue < POT > &_continuator,
|
||||
eoEvalFunc < POT > &_eval,
|
||||
eoVelocity < POT > &_velocity,
|
||||
|
|
@ -72,13 +71,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
|
||||
*/
|
||||
eoSyncEasyPSO (
|
||||
eoInitializer <POT> &_init,
|
||||
eoInitializerBase <POT> &_init,
|
||||
eoContinue < POT > &_continuator,
|
||||
eoEvalFunc < POT > &_eval,
|
||||
eoVelocity < POT > &_velocity):
|
||||
|
|
@ -92,14 +91,14 @@ public:
|
|||
{}
|
||||
|
||||
/** Full constructor - Can be used in parallel
|
||||
* @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 eoPopEvalFunc
|
||||
* @param _velocity - An eoVelocity that defines how to compute the velocities
|
||||
* @param _flight - An eoFlight
|
||||
*/
|
||||
eoSyncEasyPSO (
|
||||
eoInitializer <POT> &_init,
|
||||
eoInitializerBase <POT> &_init,
|
||||
eoContinue < POT > &_continuator,
|
||||
eoPopEvalFunc < POT > &_eval,
|
||||
eoVelocity < POT > &_velocity,
|
||||
|
|
@ -114,6 +113,66 @@ public:
|
|||
{}
|
||||
|
||||
|
||||
/** Another constructor without initializer
|
||||
* @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
|
||||
*/
|
||||
eoSyncEasyPSO (
|
||||
eoContinue < POT > &_continuator,
|
||||
eoEvalFunc < POT > &_eval,
|
||||
eoVelocity < POT > &_velocity,
|
||||
eoFlight < POT > &_flight):
|
||||
init(dummyInit),
|
||||
continuator (_continuator),
|
||||
eval (_eval),
|
||||
loopEval(_eval),
|
||||
popEval(loopEval),
|
||||
velocity (_velocity),
|
||||
flight (_flight)
|
||||
{}
|
||||
|
||||
|
||||
/** Constructor without eoFlight nor eoInitializer. 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
|
||||
*/
|
||||
eoSyncEasyPSO (
|
||||
eoContinue < POT > &_continuator,
|
||||
eoEvalFunc < POT > &_eval,
|
||||
eoVelocity < POT > &_velocity):
|
||||
init(dummyInit),
|
||||
continuator (_continuator),
|
||||
eval (_eval),
|
||||
loopEval(_eval),
|
||||
popEval(loopEval),
|
||||
velocity (_velocity),
|
||||
flight (dummyFlight)
|
||||
{}
|
||||
|
||||
/** Full constructor - Can be used in parallel
|
||||
* @param _continuator - An eoContinue that manages the stopping criterion and the checkpointing system
|
||||
* @param _eval - An eoPopEvalFunc
|
||||
* @param _velocity - An eoVelocity that defines how to compute the velocities
|
||||
* @param _flight - An eoFlight
|
||||
*/
|
||||
eoSyncEasyPSO (
|
||||
eoContinue < POT > &_continuator,
|
||||
eoPopEvalFunc < POT > &_eval,
|
||||
eoVelocity < POT > &_velocity,
|
||||
eoFlight <POT> &_flight):
|
||||
init(dummyInit),
|
||||
continuator (_continuator),
|
||||
eval (dummyEval),
|
||||
loopEval(dummyEval),
|
||||
popEval(_eval),
|
||||
velocity (_velocity),
|
||||
flight (_flight)
|
||||
{}
|
||||
|
||||
/// Apply a few iteration of flight to the population (=swarm).
|
||||
virtual void operator () (eoPop < POT > &_pop)
|
||||
{
|
||||
|
|
@ -122,6 +181,7 @@ public:
|
|||
{
|
||||
// initializes the topology, velocity, best particle(s)
|
||||
init();
|
||||
|
||||
// just to use a loop eval
|
||||
eoPop<POT> empty_pop;
|
||||
|
||||
|
|
@ -154,7 +214,7 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
eoInitializer <POT> &init;
|
||||
eoInitializerBase <POT> &init;
|
||||
eoContinue < POT > &continuator;
|
||||
|
||||
eoEvalFunc < POT > &eval;
|
||||
|
|
@ -164,18 +224,30 @@ private:
|
|||
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 eval does not need to be used, use the dummy eval instance
|
||||
class eoDummyEval : public eoEvalFunc<POT>
|
||||
{
|
||||
public:
|
||||
void operator()(POT &)
|
||||
{}
|
||||
}
|
||||
dummyEval;
|
||||
class eoDummyEval : public eoEvalFunc<POT>
|
||||
{
|
||||
public:
|
||||
void operator()(POT &)
|
||||
{}
|
||||
}
|
||||
dummyEval;
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue