corrected PSO dummy errors and completed documentation

This commit is contained in:
tlegrand 2008-01-08 15:13:32 +00:00
commit ef252cf7de
3 changed files with 121 additions and 114 deletions

View file

@ -47,6 +47,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 _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
@ -54,37 +55,44 @@ public:
* to modify the positions according to the velocities
*/
eoEasyPSO (
eoInitializer <POT> &_init,
eoContinue < POT > &_continuator,
eoEvalFunc < POT > &_eval,
eoVelocity < POT > &_velocity,
eoFlight < POT > &_flight):
init(_init),
continuator (_continuator),
eval (_eval),
velocity (_velocity),
flight (_flight){}
flight (_flight)
{}
/** 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 _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,
eoContinue < POT > &_continuator,
eoEvalFunc < POT > &_eval,
eoVelocity < POT > &_velocity):
init(_init),
continuator (_continuator),
eval (_eval),
velocity (_velocity),
flight (dummyFlight){}
flight (dummyFlight)
{}
/// Apply a few iteration of flight to the population (=swarm).
virtual void operator () (eoPop < POT > &_pop)
{
try
{
// initializes the topology, velocity, best particle(s)
init();
do
{
// loop over all the particles for the current iteration
@ -103,7 +111,8 @@ public:
velocity.updateNeighborhood(_pop[idx],idx);
}
}while (continuator (_pop));
}
while (continuator (_pop));
}
catch (std::exception & e)
@ -116,6 +125,7 @@ public:
}
private:
eoInitializer <POT> &init;
eoContinue < POT > &continuator;
eoEvalFunc < POT > &eval;
eoVelocity < POT > &velocity;

View file

@ -38,15 +38,15 @@
* Abstract class for initialization of algorithm PSO
*/
template <class POT> class eoInitializerBase : public eoFunctorBase
{
public :
{
public :
virtual ~eoInitializerBase()
{}
virtual void operator()()
{};
};
};
/**
Base (name) class for Initialization of algorithm PSO
@ -54,8 +54,8 @@ template <class POT> class eoInitializerBase : public eoFunctorBase
@see eoInitializerBase eoUF apply
*/
template <class POT> class eoInitializer : public eoInitializerBase <POT>
{
public:
{
public:
//! Constructor
//! @param _proc Evaluation function
@ -69,12 +69,7 @@ template <class POT> class eoInitializer : public eoInitializerBase <POT>
eoTopology <POT> &_topology,
eoPop < POT > &_pop
) : proc(_proc), procPara(dummyEval), initVelo(_initVelo), initBest(_initBest), topology(_topology), pop(_pop)
{
/* apply(proc, _pop);
apply < POT > (initVelo, _pop);
apply < POT > (initBest, _pop);
topology.setup(_pop);*/
}
{}
//! Constructor for parallel evaluation
//! @param _proc Evaluation function
@ -100,7 +95,7 @@ template <class POT> class eoInitializer : public eoInitializerBase <POT>
virtual void operator () (/*eoPop < POT > &_pop*/)
virtual void operator() ()
{
eoPop<POT> empty_pop;
apply(proc, pop);
@ -110,13 +105,12 @@ template <class POT> class eoInitializer : public eoInitializerBase <POT>
topology.setup(pop);
}
private :
private :
/*
@param proc First evaluation
@param initVelo Initialization of the velocity
@param initBest Initialization of the best
*/
eoPop < POT > & pop;
eoUF<POT&, void>& proc;
@ -124,14 +118,14 @@ template <class POT> class eoInitializer : public eoInitializerBase <POT>
eoVelocityInit < POT > & initVelo;
eoParticleBestInit <POT> & initBest;
eoTopology <POT> & topology;
class eoDummyEval : public eoPopEvalFunc<POT>
class eoDummyEval : public eoPopEvalFunc<POT>
{
public:
void operator()(eoPop<POT> &,eoPop<POT> &_pop)
{}
}
dummyEval;
class eoDummy : public eoUF<POT&, void>
class eoDummy : public eoUF<POT&, void>
{
public:
void operator()(POT &)
@ -139,7 +133,7 @@ template <class POT> class eoInitializer : public eoInitializerBase <POT>
}
dummy;
};
};
#endif

View file

@ -44,10 +44,11 @@
* -- update the neighborhoods
*/
template < class POT > class eoSyncEasyPSO:public eoPSO < POT >
{
public:
{
public:
/** Full constructor
* @param _init - An eoInitializer 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
@ -71,6 +72,7 @@ template < class POT > class eoSyncEasyPSO:public eoPSO < POT >
/** 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 _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
@ -90,6 +92,7 @@ template < class POT > class eoSyncEasyPSO:public eoPSO < POT >
{}
/** Full constructor - Can be used in parallel
* @param _init - An eoInitializer 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
@ -117,13 +120,13 @@ template < class POT > class eoSyncEasyPSO:public eoPSO < POT >
try
{
// initializes the topology, velocity, best particle(s)
init();
// just to use a loop eval
eoPop<POT> empty_pop;
do
{
// perform velocity evaluation
velocity.apply (_pop);
@ -149,7 +152,7 @@ template < class POT > class eoSyncEasyPSO:public eoPSO < POT >
}
private:
private:
eoInitializer <POT> &init;
eoContinue < POT > &continuator;
@ -165,7 +168,7 @@ template < class POT > class eoSyncEasyPSO:public eoPSO < POT >
eoDummyFlight<POT> dummyFlight;
// if the eval does not need to be used, use the dummy eval instance
class eoDummyEval : public eoEvalFunc<POT>
class eoDummyEval : public eoEvalFunc<POT>
{
public:
void operator()(POT &)
@ -173,7 +176,7 @@ template < class POT > class eoSyncEasyPSO:public eoPSO < POT >
}
dummyEval;
};
};
#endif /*_EOSYNCEASYPSO_H*/