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

@ -140,7 +140,7 @@ public:
* Write object. Called printOn since it prints the object _on_ a stream.
* @param _os A std::ostream.
*/
virtual void printOn(std::ostream& _os) const { _os << bestFitness <<' ' ;}
virtual void printOn(std::ostream& _os) const { _os << bestFitness << ' ' ;}
/**

View file

@ -172,7 +172,6 @@
#include <eoFlight.h>
#include <eoStandardFlight.h>
#include <eoVelocityInit.h>
#include <eoDummyFlight.h>
#include <eoBinaryFlight.h>
#include <eoSigBinaryFlight.h>

View file

@ -1,51 +0,0 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// eoDummyFlight.h
// (c) OPAC 2007
/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: thomas.legrand@lifl.fr
*/
//-----------------------------------------------------------------------------
#ifndef EODUMMYFLIGHT_H
#define EODUMMYFLIGHT_H
//-----------------------------------------------------------------------------
#include <eoFlight.h>
//-----------------------------------------------------------------------------
/**
* A dummy flight that does nothing !
*/
template < class POT > class eoDummyFlight:public eoFlight < POT >
{
public:
// Ctor
eoDummyFlight () {}
/**
* Dummy move: do nothing
*/
void operator () (POT & _po1) {}
};
#endif /*EODUMMYFLIGHT_H */

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;
};

View file

@ -111,13 +111,14 @@ private :
@param proc First evaluation
@param initVelo Initialization of the velocity
@param initBest Initialization of the best
*/
eoPop < POT > & pop;
*/
eoUF<POT&, void>& proc;
eoPopEvalFunc <POT>& procPara;
eoVelocityInit < POT > & initVelo;
eoParticleBestInit <POT> & initBest;
eoPopEvalFunc <POT>& procPara;
eoTopology <POT> & topology;
eoPop < POT > & pop;
class eoDummyEval : public eoPopEvalFunc<POT>
{
public:

View file

@ -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;
};