Documentation for PEO

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@908 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
canape 2008-01-29 13:50:22 +00:00
commit ff3abc32ff
16 changed files with 354 additions and 384 deletions

View file

@ -1,9 +1,9 @@
/* /*
* <peo> * <peo>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2008
* *
* Sebastien Cahon, Alexandru-Adrian Tantar * Sebastien Cahon, Alexandru-Adrian Tantar, Clive Canape
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,

View file

@ -1,7 +1,7 @@
/* /*
* <peo.h> * <peo.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2008
* *
* Sebastien Cahon, Alexandru-Adrian Tantar, Clive Canape * Sebastien Cahon, Alexandru-Adrian Tantar, Clive Canape
* *

View file

@ -1,9 +1,9 @@
/* /*
* <peoAggEvalFunc.h> * <peoAggEvalFunc.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2008
* *
* Sebastien Cahon, Alexandru-Adrian Tantar * Sebastien Cahon, Alexandru-Adrian Tantar, Clive Canape
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,

View file

@ -1,9 +1,9 @@
/* /*
* <peoAsyncIslandMig.h> * <peoAsyncIslandMig.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2008
* *
* Sebastien Cahon, Alexandru-Adrian Tantar * Sebastien Cahon, Alexandru-Adrian Tantar, Clive Canape
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -56,105 +56,24 @@
#include "core/peo_debug.h" #include "core/peo_debug.h"
//! Class providing the basis for the asynchronous island migration model. //! @class peoAsyncIslandMig
//! @brief Specific class for a asynchronous migration
//! The peoAsyncIslandMig class offers the elementary basis for implementating an //! @see Cooperative eoUpdater
//! asynchronous island migration model - requires the specification of several basic //! @version 2.0
//! parameters, i.e. continuation criterion, selection and replacement strategies, //! @date january 2008
//! a topological model and the source and destination population for the migrating individuals.
//! As opposed to the synchronous migration model, in the asynchronous migration approach, there is
//! no synchronization step between islands after performing the emigration phase.
//!
//! The migration operator is called at the end of each generation of an evolutionary algorithms
//! as a checkpoint object - the following code exposes the structure of a classic evolutionary algorithm:
//!
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
//! <tr><td><b>do</b> { &nbsp;</td> <td> &nbsp; </td></tr>
//! <tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select( population, offsprings ); &nbsp;</td> <td>// select the offsprings from the current population</td></tr>
//! <tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transform( offsprings ); &nbsp;</td> <td>// crossover and mutation operators are applied on the selected offsprings</td></tr>
//! <tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; evaluate( offsprings ); &nbsp;</td> <td>// evaluation step of the resulting offsprings</td></tr>
//! <tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; replace( population, offsprings ); &nbsp;</td> <td>// replace the individuals in the current population whith individuals from the offspring population, according to a specified replacement strategy</td></tr>
//! <tr><td>} <b>while</b> ( eaCheckpointContinue( population ) ); &nbsp;</td> <td>// checkpoint operators are applied on the current population, including the migration operator, if any specified </td></tr>
//! </table>
//!
//! Constructing an asynchronous island migration model requires having defined (1) a topological migration model,
//! (2) the control parameters of the migration process, (3) a checkpoint object associated with an evolutionary algorithm,
//! and (4) an owner object must be set. The owner object must be derived from the <b>Runner</b> class (for example
//! a peoEA object represents a possible owner).
//! A simple example is offered bellow:
//!
//! <ol>
//! <li> topological model to be followed when performing migrations: <br/>
//! <br/>
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
//! <tr><td>RingTopology migTopology; &nbsp;</td> <td>// a simple ring topological model - each island communicates with two other islands</td></tr>
//! </table>
//! </li>
//!
//! <li> the continuation criterion, selection and replacement strategy etc. are defined: <br/>
//! <br/>
//! <table style="border:none; border-spacing:0px; font-size:8pt;" border="0">
//! <tr><td>eoPop< EOT > population( POP_SIZE, popInitializer ); &nbsp;</td> <td>// population of individuals to be used for the evolutionary algorithm</td></tr>
//! <tr><td> &nbsp; </td> <td> &nbsp; </td></tr>
//! <tr><td>eoPeriodicContinue< EOT > migCont( MIG_FREQ ); &nbsp;</td> <td>// migrations occur periodically at MIG_FREQ iterations</td></tr>
//! <tr><td>eoRandomSelect< EOT > migSelectStrategy; &nbsp;</td> <td>// selection strategy - in this case a random selection is applied</td></tr>
//! <tr><td>eoSelectNumber< EOT > migSelect( migSelectStrategy, MIG_SIZE ); &nbsp;</td> <td>// number of individuals to be selected using the specified strategy</td></tr>
//! <tr><td>eoPlusReplacement< EOT > migReplace; &nbsp;</td> <td>// immigration strategy - the worse individuals in the destination population are replaced by the immigrant individuals</td></tr>
//! <tr><td> &nbsp; </td> <td> &nbsp; </td></tr>
//! <tr><td>peoAsyncIslandMig< EOT > asyncMigration(
//! <br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; migCont, migSelect, migReplace, migTopology,
//! <br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; population, population
//! <br/> ); &nbsp; </td>
//! <td>// asynchronous migration object - the emigrant individuals are selected from the same from population in which the immigrant individuals are being integrated </td></tr>
//! </table>
//! </li>
//!
//! <li> creation of a checkpoint object as part of the definition of an evolutionary algoritm (details of th EA not given as being out of scope): <br/>
//! <br/>
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
//! <tr><td>... &nbsp;</td> <td> &nbsp; </td></tr>
//! <tr><td>eoGenContinue< EOT > eaCont( NUM_GEN ); &nbsp;</td> <td>// the evolutionary algorithm will stop after NUM_GEN generations</td></tr>
//! <tr><td>eoCheckPoint< EOT > eaCheckpointContinue( eaCont ); &nbsp;</td> <td>// number of individuals to be selected using the specified strategy</td></tr>
//! <tr><td>... &nbsp;</td> <td> &nbsp; </td></tr>
//! <tr><td>eaCheckpointContinue.add( asyncMigration ); &nbsp;</td> <td>// adding the migration operator as checkpoint element</td></tr>
//! <tr><td>... &nbsp;</td> <td> &nbsp; </td></tr>
//! </table>
//! </li>
//!
//! <li> definition of an owner evolutionary algorithm (an object inheriting the <b>Runner</b> class): <br/>
//! <br/>
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
//! <tr><td>peoEA< EOT > eaAlg( eaCheckpointContinue, eaPopEval, eaSelect, eaTransform, eaReplace); &nbsp;</td> <td>// evolutionary algorithm having as checkpoint the eaCheckpointContinue object defined above </td></tr>
//! <tr><td>asyncMigration.setOwner( eaAlg ); &nbsp;</td> <td>// setting the evolutionary algorithm as owner of the migration object </td></tr>
//! <tr><td>eaAlg( population ); &nbsp;</td> <td>// applying the evolutionary algorithm on a given population </td></tr>
//! </table>
//! </li>
//! </ol>
//!
//! The source and the destination population for the migration object were specified as being the same, in step no. 2,
//! as we are usually interested in selecting the emigrants and integrating the immigrant individuals from and in, respectively, one unique
//! population, iteratively evolved by an evolutionary algorithm. There is no restriction in having two distinct populations
//! as source and destination for the emigrant and immigrant individuals respectively.
//!
//! The above steps only create an asynchronous migration object associated to an evolutionary algorithm. The creation of several
//! islands requires the reiteration of the steps 2 through 4 for creating distinct algorithms, with distinct populations and
//! the associated distinctly parametrized migration objects. The interconnecting element is the underlying topology, defined at step 1
//! (the same C++ migTopology object has to be passed as parameter for all the migration objects, in order to interconnect them).
template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative, public eoUpdater template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative, public eoUpdater
{ {
public: public:
//! Constructor for the peoAsyncIslandMig class; the characteristics of the migration model are defined //! @brief Constructor
//! through the specified parameters - out of the box objects provided in EO, etc., or custom, derived objects may be passed as parameters. //! @param continuator & __cont
//! //! @param selector <TYPE> & __select
//! @param eoContinue< EOT >& __cont - continuation criterion specifying whether the migration is performed or not; //! @param replacement <TYPE> & __replace
//! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of emigrant individuals out of the source population; //! @param Topology& __topology
//! @param eoReplacement< EOT >& __replace - replacement strategy used for integrating the immigrant individuals in the destination population; //! @param peoData & __source
//! @param Topology& __topology - topological model to be followed when performing migrations; //! @param eoData & __destination
//! @param eoPop< EOT >& __source - source population from which the emigrant individuals are selected; peoAsyncIslandMig(
//! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated.
peoAsyncIslandMig(
continuator & __cont, continuator & __cont,
selector <TYPE> & __select, selector <TYPE> & __select,
replacement <TYPE> & __replace, replacement <TYPE> & __replace,
@ -163,33 +82,35 @@ template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative,
peoData & __destination peoData & __destination
); );
//! @brief operator
//! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected
//! from the source population and sent to the next island (defined by the topology object) while the immigrant
//! individuals are integrated in the destination population. There is no need to explicitly call the function - the
//! wrapper checkpoint object (please refer to the above example) will perform the call when required.
void operator()(); void operator()();
//! @brief Function realizing packages
//! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function.
void pack(); void pack();
//! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function. //! @brief Function reconstituting packages
void unpack(); void unpack();
//! Auxiliary function dealing with the packing of synchronization requests - not the case. //! @brief Function packSynchronizeReq
void packSynchronizeReq(); void packSynchronizeReq();
private: private:
//! @brief Function which sends some emigrants
void emigrate(); void emigrate();
//! @brief Function which receives some immigrants
void immigrate(); void immigrate();
private: private:
//! @param continuator & cont
continuator & cont; // continuator //! @param selector <TYPE> & select
selector <TYPE> & select; // the selection strategy //! @param replacement <TYPE> & replace
replacement <TYPE> & replace; // the replacement strategy //! @param Topology& topology
Topology& topology; // the neighboring topology //! @param peoData & source
//! @param peoData & destination
//! @param std :: queue< TYPE > imm
//! @param std :: queue< TYPE > em
//! @param std :: queue< Cooperative* > coop_em
continuator & cont;
selector <TYPE> & select;
replacement <TYPE> & replace;
Topology& topology;
peoData & source; peoData & source;
peoData & destination; peoData & destination;
std :: queue< TYPE > imm; std :: queue< TYPE > imm;
@ -278,8 +199,8 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: operato
if (cont.check()) if (cont.check())
{ {
emigrate(); // sending emigrants emigrate();
immigrate(); // receiving immigrants immigrate();
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
* <peoData.h> * <peoData.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2008
* *
* Clive Canape, Thomas Legrand * Clive Canape, Thomas Legrand
* *
@ -44,25 +44,35 @@
/************************** DEFINE A DATA ******************************************/ /************************** DEFINE A DATA ******************************************/
/**************************************************************************************/ /**************************************************************************************/
//! @class peoData
//! @brief Abstract class for a data exchanged by migration
//! @version 1.0
//! @date january 2008
class peoData class peoData
{ {
public: public:
//! @brief Function realizing packages
virtual void pack () virtual void pack ()
{} {}
//! @brief Function reconstituting packages
virtual void unpack () virtual void unpack ()
{} {}
}; };
//! @class peoPop
// Specific implementation : migration of a population //! @brief Specific class for a migration of a population
//! @see peoData eoPop
//! @version 1.0
//! @date january 2008
template<class EOT> template<class EOT>
class peoPop: public eoPop<EOT>, public peoData class peoPop: public eoPop<EOT>, public peoData
{ {
public: public:
//! @brief Function realizing packages
virtual void pack () virtual void pack ()
{ {
::pack ((unsigned) this->size ()); ::pack ((unsigned) this->size ());
@ -70,6 +80,7 @@ class peoPop: public eoPop<EOT>, public peoData
::pack ((*this)[i]); ::pack ((*this)[i]);
} }
//! @brief Function reconstituting packages
virtual void unpack () virtual void unpack ()
{ {
unsigned n; unsigned n;
@ -86,28 +97,45 @@ class peoPop: public eoPop<EOT>, public peoData
/************************** DEFINE A CONTINUATOR ***********************************/ /************************** DEFINE A CONTINUATOR ***********************************/
/**************************************************************************************/ /**************************************************************************************/
//! @class continuator
//! @brief Abstract class for a continuator within the exchange of data by migration
//! @version 1.0
//! @date january 2008
class continuator class continuator
{ {
public: public:
//! @brief Virtual function of check
//! @return true if the algorithm must continue
virtual bool check()=0; virtual bool check()=0;
}; };
// Specific implementation : migration of a population //! @class eoContinuator
//! @brief Specific class for a continuator within the exchange of migration of a population
//! @see continuator
//! @version 1.0
//! @date january 2008
template < class EOT> class eoContinuator : public continuator template < class EOT> class eoContinuator : public continuator
{ {
public: public:
//! @brief Constructor
//! @param eoContinue<EOT> &
//! @param eoPop<EOT> &
eoContinuator(eoContinue<EOT> & _cont, const eoPop<EOT> & _pop): cont (_cont), pop(_pop) eoContinuator(eoContinue<EOT> & _cont, const eoPop<EOT> & _pop): cont (_cont), pop(_pop)
{} {}
//! @brief Virtual function of check
//! @return true if the algorithm must continue
virtual bool check() virtual bool check()
{ {
return cont(pop); return cont(pop);
} }
protected: protected:
//! @param eoContinue<EOT> &
//! @param eoPop<EOT> &
eoContinue<EOT> & cont ; eoContinue<EOT> & cont ;
const eoPop<EOT> & pop; const eoPop<EOT> & pop;
}; };
@ -117,23 +145,39 @@ template < class EOT> class eoContinuator : public continuator
/************************** DEFINE A SELECTOR **************************************/ /************************** DEFINE A SELECTOR **************************************/
/**************************************************************************************/ /**************************************************************************************/
//! @class selector
//! @brief Abstract class for a selector within the exchange of data by migration
//! @version 1.0
//! @date january 2008
template < class TYPE> class selector template < class TYPE> class selector
{ {
public: public:
//! @brief Virtual operator on the template type
//! @param TYPE &
virtual void operator()(TYPE &)=0; virtual void operator()(TYPE &)=0;
}; };
// Specific implementation : migration of a population //! @class eoSelector
//! @brief Specific class for a selector within the exchange of migration of a population
//! @see selector
//! @version 1.0
//! @date january 2008
template < class EOT, class TYPE> class eoSelector : public selector< TYPE > template < class EOT, class TYPE> class eoSelector : public selector< TYPE >
{ {
public: public:
//! @brief Constructor
//! @param eoSelectOne<EOT> &
//! @param unsigned _nb_select
//! @param TYPE & _source (with TYPE which is the template type)
eoSelector(eoSelectOne<EOT> & _select, unsigned _nb_select, const TYPE & _source): selector (_select), nb_select(_nb_select), source(_source) eoSelector(eoSelectOne<EOT> & _select, unsigned _nb_select, const TYPE & _source): selector (_select), nb_select(_nb_select), source(_source)
{} {}
virtual void operator()(TYPE & _dest) //! @brief Virtual operator on the template type
//! @param TYPE & _dest
virtual void operator()(TYPE & _dest)
{ {
size_t target = static_cast<size_t>(nb_select); size_t target = static_cast<size_t>(nb_select);
_dest.resize(target); _dest.resize(target);
@ -142,6 +186,9 @@ template < class EOT, class TYPE> class eoSelector : public selector< TYPE >
} }
protected: protected:
//! @param eoSelectOne<EOT> &
//! @param unsigned nb_select
//! @param TYPE & source
eoSelectOne<EOT> & selector ; eoSelectOne<EOT> & selector ;
unsigned nb_select; unsigned nb_select;
const TYPE & source; const TYPE & source;
@ -152,27 +199,43 @@ template < class EOT, class TYPE> class eoSelector : public selector< TYPE >
/************************** DEFINE A REPLACEMENT ***********************************/ /************************** DEFINE A REPLACEMENT ***********************************/
/**************************************************************************************/ /**************************************************************************************/
//! @class replacement
//! @brief Abstract class for a replacement within the exchange of data by migration
//! @version 1.0
//! @date january 2008
template < class TYPE> class replacement template < class TYPE> class replacement
{ {
public: public:
//! @brief Virtual operator on the template type
//! @param TYPE &
virtual void operator()(TYPE &)=0; virtual void operator()(TYPE &)=0;
}; };
// Specific implementation : migration of a population //! @class eoReplace
//! @brief Specific class for a replacement within the exchange of migration of a population
//! @see replacement
//! @version 1.0
//! @date january 2008
template < class EOT, class TYPE> class eoReplace : public replacement< TYPE > template < class EOT, class TYPE> class eoReplace : public replacement< TYPE >
{ {
public: public:
//! @brief Constructor
//! @param eoReplacement<EOT> &
//! @param TYPE & _destination (with TYPE which is the template type)
eoReplace(eoReplacement<EOT> & _replace, TYPE & _destination): replace(_replace), destination(_destination) eoReplace(eoReplacement<EOT> & _replace, TYPE & _destination): replace(_replace), destination(_destination)
{} {}
//! @brief Virtual operator on the template type
//! @param TYPE & _source
virtual void operator()(TYPE & _source) virtual void operator()(TYPE & _source)
{ {
replace(destination, _source); replace(destination, _source);
} }
protected: protected:
//! @param eoReplacement<EOT> &
//! @param TYPE & destination
eoReplacement<EOT> & replace; eoReplacement<EOT> & replace;
TYPE & destination; TYPE & destination;
}; };
@ -182,14 +245,23 @@ template < class EOT, class TYPE> class eoReplace : public replacement< TYPE >
/************************ Continuator for synchrone migartion ************************/ /************************ Continuator for synchrone migartion ************************/
/**************************************************************************************/ /**************************************************************************************/
//! @class eoSyncContinue
//! @brief Class for a continuator within the exchange of data by synchrone migration
//! @see continuator
//! @version 1.0
//! @date january 2008
class eoSyncContinue: public continuator class eoSyncContinue: public continuator
{ {
public: public:
//! @brief Constructor
//! @param unsigned __period
//! @param unsigned __init_counter
eoSyncContinue (unsigned __period, unsigned __init_counter = 0): period (__period),counter (__init_counter) eoSyncContinue (unsigned __period, unsigned __init_counter = 0): period (__period),counter (__init_counter)
{} {}
//! @brief Virtual function of check
//! @return true if the algorithm must continue
virtual bool check() virtual bool check()
{ {
return ((++ counter) % period) != 0 ; return ((++ counter) % period) != 0 ;
@ -197,11 +269,10 @@ class eoSyncContinue: public continuator
private: private:
//! @param unsigned period
//! @param unsigned counter
unsigned period; unsigned period;
unsigned counter; unsigned counter;
}; };

View file

@ -1,7 +1,7 @@
/* /*
* <peoEvalFunc.h> * <peoEvalFunc.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, INRIA, 2007 * (C) OPAC Team, INRIA, 2008
* *
* Clive Canape * Clive Canape
* *
@ -37,6 +37,11 @@
#ifndef PEOEVALFUNC_H #ifndef PEOEVALFUNC_H
#define PEOEVALFUNC_H #define PEOEVALFUNC_H
//! @class peoEvalFunc
//! @brief Specific class for evaluation
//! @see eoEvalFunc
//! @version 1.0
//! @date november 2007
#ifdef _MSC_VER #ifdef _MSC_VER
template< class EOT, class FitT = EOT::Fitness, class FunctionArg = const EOT& > template< class EOT, class FitT = EOT::Fitness, class FunctionArg = const EOT& >
#else #else
@ -45,16 +50,21 @@ template< class EOT, class FitT = typename EOT::Fitness, class FunctionArg = con
struct peoEvalFunc: public eoEvalFunc<EOT> struct peoEvalFunc: public eoEvalFunc<EOT>
{ {
//! @brief Constructor
//! @param FitT (* _eval)( FunctionArg )
peoEvalFunc( FitT (* _eval)( FunctionArg ) ) peoEvalFunc( FitT (* _eval)( FunctionArg ) )
: eoEvalFunc<EOT>(), evalFunc( _eval ) : eoEvalFunc<EOT>(), evalFunc( _eval )
{}; {};
//! @brief Virtual operator
//! @param EOT & _peo
virtual void operator() ( EOT & _peo ) virtual void operator() ( EOT & _peo )
{ {
_peo.fitness((*evalFunc)( _peo )); _peo.fitness((*evalFunc)( _peo ));
}; };
private: private:
//! @param FitT (* evalFunc )( FunctionArg )
FitT (* evalFunc )( FunctionArg ); FitT (* evalFunc )( FunctionArg );
}; };

View file

@ -46,19 +46,28 @@
#include <eoReplacement.h> #include <eoReplacement.h>
#include <utils/eoHowMany.h> #include <utils/eoHowMany.h>
//! @class peoGlobalBestVelocity
//! @brief Specific class for a replacement thanks to the velocity migration of a population of a PSO
//! @see eoReplacement
//! @version 1.1
//! @date october 2007
template <class POT> template <class POT>
class peoGlobalBestVelocity : public eoReplacement<POT> class peoGlobalBestVelocity : public eoReplacement<POT>
{ {
public: public:
//! @brief typedef : creation of VelocityType
typedef typename POT::ParticleVelocityType VelocityType; typedef typename POT::ParticleVelocityType VelocityType;
peoGlobalBestVelocity( const double & _c3, //! @brief Constructor
eoVelocity < POT > &_velocity): //! @param double & _c3
c3 (_c3), //! @param eoVelocity < POT > &_velocity
velocity (_velocity) peoGlobalBestVelocity( const double & _c3, eoVelocity < POT > &_velocity): c3 (_c3),velocity (_velocity)
{} {}
//! @brief Virtual operator
//! @param eoPop<POT>& _dest
//! @param eoPop<POT>& _source
void operator()(eoPop<POT>& _dest, eoPop<POT>& _source) void operator()(eoPop<POT>& _dest, eoPop<POT>& _source)
{ {
@ -74,6 +83,8 @@ class peoGlobalBestVelocity : public eoReplacement<POT>
} }
protected: protected:
//! @param double & c3
//! @param eoVelocity < POT > & velocity
const double & c3; const double & c3;
eoVelocity < POT > & velocity; eoVelocity < POT > & velocity;
}; };

View file

@ -1,9 +1,9 @@
/* /*
* <peoMoeoPopEval.h> * <peoMoeoPopEval.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2008
* *
* Sebastien Cahon, Alexandru-Adrian Tantar * Clive Canape
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -45,12 +45,11 @@
#include "peoAggEvalFunc.h" #include "peoAggEvalFunc.h"
#include "peoNoAggEvalFunc.h" #include "peoNoAggEvalFunc.h"
//! @class peoPopEval
//! Parallel evaluation functor wrapper. //! @brief Parallel evaluation functor wrapper with MOEO
//! @see Service eoPopEvalFunc
//! The peoMoeoPopEval represents a wrapper for creating a functor capable of applying in parallel //! @version 1.0
//! an EO-derived evaluation functor. The class offers the possibility of chosing between a single-function evaluation //! @date 2008
//! and an aggregate evaluation function, including several sub-evalution functions.
template< class EOT > class peoMoeoPopEval : public Service, public eoPopEvalFunc<EOT> template< class EOT > class peoMoeoPopEval : public Service, public eoPopEvalFunc<EOT>
{ {
@ -72,6 +71,10 @@ template< class EOT > class peoMoeoPopEval : public Service, public eoPopEvalFun
//! //!
//! @param eoPop< EOT >& __pop - population to be evaluated by applying the evaluation functor specified in the constructor. //! @param eoPop< EOT >& __pop - population to be evaluated by applying the evaluation functor specified in the constructor.
void operator()(eoPop< EOT >& __pop); void operator()(eoPop< EOT >& __pop);
//! @brief Operator ()( eoPop< EOT >& __dummy, eoPop< EOT >& __pop )
//! @param eoPop< EOT >& __dummy
//! @param eoPop< EOT >& __pop
void operator()( eoPop< EOT >& __dummy, eoPop< EOT >& __pop ); void operator()( eoPop< EOT >& __dummy, eoPop< EOT >& __pop );
//! Auxiliary function for transferring data between the process requesting an evaluation operation and the process that //! Auxiliary function for transferring data between the process requesting an evaluation operation and the process that
@ -102,24 +105,25 @@ template< class EOT > class peoMoeoPopEval : public Service, public eoPopEvalFun
void notifySendingAllResourceRequests(); void notifySendingAllResourceRequests();
private: private:
//! @param std :: vector< eoEvalFunc < EOT >* >& funcs
//! @param std :: vector< eoEvalFunc < EOT >* > one_func
//! @param peoAggEvalFunc< EOT >& merge_eval
//! @param peoNoAggEvalFunc< EOT > no_merge_eval
//! @param std :: queue< EOT* >tasks
//! @param std :: map< EOT*, std :: pair< unsigned, unsigned > > progression
//! @param unsigned num_func
//! @param EOT sol
//! @param EOT *ad_sol
//! @param unsigned total
const std :: vector< eoEvalFunc < EOT >* >& funcs; const std :: vector< eoEvalFunc < EOT >* >& funcs;
std :: vector< eoEvalFunc < EOT >* > one_func; std :: vector< eoEvalFunc < EOT >* > one_func;
peoAggEvalFunc< EOT >& merge_eval; peoAggEvalFunc< EOT >& merge_eval;
peoNoAggEvalFunc< EOT > no_merge_eval; peoNoAggEvalFunc< EOT > no_merge_eval;
std :: queue< EOT* >tasks; std :: queue< EOT* >tasks;
std :: map< EOT*, std :: pair< unsigned, unsigned > > progression; std :: map< EOT*, std :: pair< unsigned, unsigned > > progression;
unsigned num_func; unsigned num_func;
EOT sol; EOT sol;
EOT *ad_sol; EOT *ad_sol;
unsigned total; unsigned total;
}; };

View file

@ -1,9 +1,9 @@
/* /*
* <peoMultiStart.h> * <peoMultiStart.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2008
* *
* Sebastien Cahon, Alexandru-Adrian Tantar * Sebastien Cahon, Alexandru-Adrian Tantar, Clive Canape
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -41,204 +41,188 @@
#include "core/service.h" #include "core/service.h"
#include "core/messaging.h" #include "core/messaging.h"
//! @class peoMultiStart
//! @brief Class allowing the launch of several algorithms
//! @see Service
//! @version 1.1
//! @date january 2008
template < typename EntityType > class peoMultiStart : public Service template < typename EntityType > class peoMultiStart : public Service
{ {
public: public:
//! @brief Constructor
//! @param AlgorithmType& externalAlgorithm
template < typename AlgorithmType > peoMultiStart( AlgorithmType& externalAlgorithm ) template < typename AlgorithmType > peoMultiStart( AlgorithmType& externalAlgorithm )
{ {
singularAlgorithm = new Algorithm< AlgorithmType >( externalAlgorithm ); singularAlgorithm = new Algorithm< AlgorithmType >( externalAlgorithm );
algorithms.push_back( singularAlgorithm ); algorithms.push_back( singularAlgorithm );
aggregationFunction = new NoAggregationFunction(); aggregationFunction = new NoAggregationFunction();
} }
//! @brief Constructor
//! @param AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& )
template < typename AlgorithmReturnType, typename AlgorithmDataType > peoMultiStart( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) ) template < typename AlgorithmReturnType, typename AlgorithmDataType > peoMultiStart( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) )
{ {
singularAlgorithm = new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm ); singularAlgorithm = new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm );
algorithms.push_back( singularAlgorithm ); algorithms.push_back( singularAlgorithm );
aggregationFunction = new NoAggregationFunction(); aggregationFunction = new NoAggregationFunction();
} }
//! @brief Constructor
//! @param std::vector< AlgorithmType* >& externalAlgorithms
//! @param AggregationFunctionType& externalAggregationFunction
template < typename AlgorithmType, typename AggregationFunctionType > peoMultiStart( std::vector< AlgorithmType* >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction ) template < typename AlgorithmType, typename AggregationFunctionType > peoMultiStart( std::vector< AlgorithmType* >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction )
{ {
for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ ) for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ )
{ {
algorithms.push_back( new Algorithm< AlgorithmType >( *externalAlgorithms[ index ] ) ); algorithms.push_back( new Algorithm< AlgorithmType >( *externalAlgorithms[ index ] ) );
} }
aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction ); aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction );
} }
template < typename AlgorithmReturnType, typename AlgorithmDataType, typename AggregationFunctionType > //! @brief Constructor
peoMultiStart( std::vector< AlgorithmReturnType (*)( AlgorithmDataType& ) >& externalAlgorithms, //! @param std::vector< AlgorithmReturnType (*)( AlgorithmDataType& ) >& externalAlgorithms
AggregationFunctionType& externalAggregationFunction ) //! @param AggregationFunctionType& externalAggregationFunction
template < typename AlgorithmReturnType, typename AlgorithmDataType, typename AggregationFunctionType > peoMultiStart( std::vector< AlgorithmReturnType (*)( AlgorithmDataType& ) >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction )
{ {
for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ ) for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ )
{ {
algorithms.push_back( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithms[ index ] ) ); algorithms.push_back( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithms[ index ] ) );
} }
aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction ); aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction );
} }
//! @brief Destructor
~peoMultiStart() ~peoMultiStart()
{ {
for ( unsigned int index = 0; index < data.size(); index++ ) delete data[ index ]; for ( unsigned int index = 0; index < data.size(); index++ ) delete data[ index ];
for ( unsigned int index = 0; index < algorithms.size(); index++ ) delete algorithms[ index ]; for ( unsigned int index = 0; index < algorithms.size(); index++ ) delete algorithms[ index ];
delete aggregationFunction;
delete aggregationFunction;
} }
//! @brief operator on the template type
//! @param Type& externalData
template < typename Type > void operator()( Type& externalData ) template < typename Type > void operator()( Type& externalData )
{ {
for ( typename Type::iterator externalDataIterator = externalData.begin(); externalDataIterator != externalData.end(); externalDataIterator++ ) for ( typename Type::iterator externalDataIterator = externalData.begin(); externalDataIterator != externalData.end(); externalDataIterator++ )
{ {
data.push_back( new DataType< EntityType >( *externalDataIterator ) ); data.push_back( new DataType< EntityType >( *externalDataIterator ) );
} }
functionIndex = dataIndex = idx = num_term = 0; functionIndex = dataIndex = idx = num_term = 0;
requestResourceRequest( data.size() * algorithms.size() ); requestResourceRequest( data.size() * algorithms.size() );
stop(); stop();
} }
//! @brief operator on the template type
//! @param Type& externalDataBegin
//! @param Type& externalDataEnd
template < typename Type > void operator()( const Type& externalDataBegin, const Type& externalDataEnd ) template < typename Type > void operator()( const Type& externalDataBegin, const Type& externalDataEnd )
{ {
for ( Type externalDataIterator = externalDataBegin; externalDataIterator != externalDataEnd; externalDataIterator++ ) for ( Type externalDataIterator = externalDataBegin; externalDataIterator != externalDataEnd; externalDataIterator++ )
{ {
data.push_back( new DataType< EntityType >( *externalDataIterator ) ); data.push_back( new DataType< EntityType >( *externalDataIterator ) );
} }
functionIndex = dataIndex = idx = num_term = 0; functionIndex = dataIndex = idx = num_term = 0;
requestResourceRequest( data.size() * algorithms.size() ); requestResourceRequest( data.size() * algorithms.size() );
stop(); stop();
} }
//! @brief Function realizing packages of data
void packData(); void packData();
//! @brief Function reconstituting packages of data
void unpackData(); void unpackData();
//! @brief Function which executes the algorithm
void execute(); void execute();
//! @brief Function realizing packages of the result
void packResult(); void packResult();
//! @brief Function reconstituting packages of result
void unpackResult(); void unpackResult();
//! @brief Function notifySendingData
void notifySendingData(); void notifySendingData();
//! @brief Function notifySendingAllResourceRequests
void notifySendingAllResourceRequests(); void notifySendingAllResourceRequests();
private: private:
//! @param AbstractAlgorithm* singularAlgorithm
//! @param std::vector< AbstractAlgorithm* > algorithms
//! @param AbstractAggregationAlgorithm* aggregationFunction
//! @param EntityType entityTypeInstance
//! @param std::vector< AbstractDataType* > data
//! @param unsigned idx
//! @param unsigned num_term
//! @param unsigned dataIndex
//! @param unsigned functionIndex
template < typename Type > struct DataType; template < typename Type > struct DataType;
struct AbstractDataType struct AbstractDataType
{ {
virtual ~AbstractDataType() virtual ~AbstractDataType()
{ } { }
template < typename Type > operator Type& () template < typename Type > operator Type& ()
{ {
return ( dynamic_cast< DataType< Type >& >( *this ) ).data; return ( dynamic_cast< DataType< Type >& >( *this ) ).data;
} }
}; };
template < typename Type > struct DataType : public AbstractDataType template < typename Type > struct DataType : public AbstractDataType
{ {
DataType( Type& externalData ) : data( externalData ) DataType( Type& externalData ) : data( externalData )
{ } { }
Type& data; Type& data;
}; };
struct AbstractAlgorithm struct AbstractAlgorithm
{ {
virtual ~AbstractAlgorithm() virtual ~AbstractAlgorithm()
{ } { }
virtual void operator()( AbstractDataType& dataTypeInstance ) virtual void operator()( AbstractDataType& dataTypeInstance )
{} {}
}; };
template < typename AlgorithmType > struct Algorithm : public AbstractAlgorithm template < typename AlgorithmType > struct Algorithm : public AbstractAlgorithm
{ {
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm ) Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm )
{ } { }
void operator()( AbstractDataType& dataTypeInstance ) void operator()( AbstractDataType& dataTypeInstance )
{ {
algorithm( dataTypeInstance ); algorithm( dataTypeInstance );
} }
AlgorithmType& algorithm; AlgorithmType& algorithm;
}; };
template < typename AlgorithmReturnType, typename AlgorithmDataType > struct FunctionAlgorithm : public AbstractAlgorithm template < typename AlgorithmReturnType, typename AlgorithmDataType > struct FunctionAlgorithm : public AbstractAlgorithm
{ {
FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) ) : algorithm( externalAlgorithm ) FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) ) : algorithm( externalAlgorithm )
{ } { }
void operator()( AbstractDataType& dataTypeInstance ) void operator()( AbstractDataType& dataTypeInstance )
{ {
algorithm( dataTypeInstance ); algorithm( dataTypeInstance );
} }
AlgorithmReturnType (*algorithm)( AlgorithmDataType& ); AlgorithmReturnType (*algorithm)( AlgorithmDataType& );
}; };
struct AbstractAggregationAlgorithm struct AbstractAggregationAlgorithm
{ {
virtual ~AbstractAggregationAlgorithm() virtual ~AbstractAggregationAlgorithm()
{ } { }
virtual void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) virtual void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
{}; {};
}; };
template < typename AggregationAlgorithmType > struct AggregationAlgorithm : public AbstractAggregationAlgorithm template < typename AggregationAlgorithmType > struct AggregationAlgorithm : public AbstractAggregationAlgorithm
{ {
AggregationAlgorithm( AggregationAlgorithmType& externalAggregationAlgorithm ) : aggregationAlgorithm( externalAggregationAlgorithm ) AggregationAlgorithm( AggregationAlgorithmType& externalAggregationAlgorithm ) : aggregationAlgorithm( externalAggregationAlgorithm )
{ } { }
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
{ {
aggregationAlgorithm( dataTypeInstanceA, dataTypeInstanceB ); aggregationAlgorithm( dataTypeInstanceA, dataTypeInstanceB );
} }
AggregationAlgorithmType& aggregationAlgorithm; AggregationAlgorithmType& aggregationAlgorithm;
}; };
struct NoAggregationFunction : public AbstractAggregationAlgorithm struct NoAggregationFunction : public AbstractAggregationAlgorithm
{ {
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
{ {
@ -246,17 +230,11 @@ template < typename EntityType > class peoMultiStart : public Service
} }
}; };
AbstractAlgorithm* singularAlgorithm; AbstractAlgorithm* singularAlgorithm;
std::vector< AbstractAlgorithm* > algorithms; std::vector< AbstractAlgorithm* > algorithms;
AbstractAggregationAlgorithm* aggregationFunction; AbstractAggregationAlgorithm* aggregationFunction;
EntityType entityTypeInstance; EntityType entityTypeInstance;
std::vector< AbstractDataType* > data; std::vector< AbstractDataType* > data;
unsigned idx; unsigned idx;
unsigned num_term; unsigned num_term;
unsigned dataIndex; unsigned dataIndex;

View file

@ -1,9 +1,9 @@
/* /*
* <peoNoAggEvalFunc.h> * <peoNoAggEvalFunc.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2008
* *
* Sebastien Cahon, Alexandru-Adrian Tantar * Sebastien Cahon, Alexandru-Adrian Tantar, Clive Canape
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -50,6 +50,8 @@ template< class EOT > class peoNoAggEvalFunc : public peoAggEvalFunc< EOT >
public : public :
//! Operator which sets as fitness the <b>__fit</b> value for the <b>__sol</b> individual //! Operator which sets as fitness the <b>__fit</b> value for the <b>__sol</b> individual
//! @param EOT& __sol
//! @param typename EOT :: Fitness& __fit
void operator()( EOT& __sol, const typename EOT :: Fitness& __fit ); void operator()( EOT& __sol, const typename EOT :: Fitness& __fit );
}; };

View file

@ -39,21 +39,33 @@
#include <utils/eoRNG.h> #include <utils/eoRNG.h>
#include <eoSelectOne.h> #include <eoSelectOne.h>
//! @class peoPSOSelect
//! @brief Specific class for a selection of a population of a PSO
//! @see eoSelectOne
//! @version 1.1
//! @date october 2007
template <class POT> class peoPSOSelect: public eoSelectOne<POT> template <class POT> class peoPSOSelect: public eoSelectOne<POT>
{ {
public: public:
//! @brief Constructor
//! @param eoTopology < POT > & _topology
peoPSOSelect(eoTopology < POT > & _topology):topology(_topology) peoPSOSelect(eoTopology < POT > & _topology):topology(_topology)
{} {}
//! @brief typedef : creation of Fitness
typedef typename PO < POT >::Fitness Fitness; typedef typename PO < POT >::Fitness Fitness;
//! @brief Virtual operator
//! @param eoPop<POT>& _pop
//! @return POT&
virtual const POT& operator()(const eoPop<POT>& _pop) virtual const POT& operator()(const eoPop<POT>& _pop)
{ {
return topology.globalBest(_pop); return topology.globalBest(_pop);
} }
private: private:
//! @param eoTopology < POT > & topology
eoTopology < POT > & topology; eoTopology < POT > & topology;
}; };

View file

@ -1,9 +1,9 @@
/* /*
* <peoPopEval.h> * <peoPopEval.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2008
* *
* Sebastien Cahon, Alexandru-Adrian Tantar * Sebastien Cahon, Alexandru-Adrian Tantar, Clive Canape
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -45,12 +45,11 @@
#include "peoAggEvalFunc.h" #include "peoAggEvalFunc.h"
#include "peoNoAggEvalFunc.h" #include "peoNoAggEvalFunc.h"
//! @class peoPopEval
//! Parallel evaluation functor wrapper. //! @brief Parallel evaluation functor wrapper
//! @see Service eoPopEvalFunc
//! The peoPopEval represents a wrapper for creating a functor capable of applying in parallel //! @version 1.2
//! an EO-derived evaluation functor. The class offers the possibility of chosing between a single-function evaluation //! @date 2006
//! and an aggregate evaluation function, including several sub-evalution functions.
template< class EOT > class peoPopEval : public Service, public eoPopEvalFunc<EOT> template< class EOT > class peoPopEval : public Service, public eoPopEvalFunc<EOT>
{ {
@ -72,6 +71,10 @@ template< class EOT > class peoPopEval : public Service, public eoPopEvalFunc<EO
//! //!
//! @param eoPop< EOT >& __pop - population to be evaluated by applying the evaluation functor specified in the constructor. //! @param eoPop< EOT >& __pop - population to be evaluated by applying the evaluation functor specified in the constructor.
void operator()(eoPop< EOT >& __pop); void operator()(eoPop< EOT >& __pop);
//! @brief Operator ()( eoPop< EOT >& __dummy, eoPop< EOT >& __pop )
//! @param eoPop< EOT >& __dummy
//! @param eoPop< EOT >& __pop
void operator()( eoPop< EOT >& __dummy, eoPop< EOT >& __pop ); void operator()( eoPop< EOT >& __dummy, eoPop< EOT >& __pop );
//! Auxiliary function for transferring data between the process requesting an evaluation operation and the process that //! Auxiliary function for transferring data between the process requesting an evaluation operation and the process that
@ -103,23 +106,25 @@ template< class EOT > class peoPopEval : public Service, public eoPopEvalFunc<EO
private: private:
//! @param std :: vector< eoEvalFunc < EOT >* >& funcs
//! @param std :: vector< eoEvalFunc < EOT >* > one_func
//! @param peoAggEvalFunc< EOT >& merge_eval
//! @param peoNoAggEvalFunc< EOT > no_merge_eval
//! @param std :: queue< EOT* >tasks
//! @param std :: map< EOT*, std :: pair< unsigned, unsigned > > progression
//! @param unsigned num_func
//! @param EOT sol
//! @param EOT *ad_sol
//! @param unsigned total
const std :: vector< eoEvalFunc < EOT >* >& funcs; const std :: vector< eoEvalFunc < EOT >* >& funcs;
std :: vector< eoEvalFunc < EOT >* > one_func; std :: vector< eoEvalFunc < EOT >* > one_func;
peoAggEvalFunc< EOT >& merge_eval; peoAggEvalFunc< EOT >& merge_eval;
peoNoAggEvalFunc< EOT > no_merge_eval; peoNoAggEvalFunc< EOT > no_merge_eval;
std :: queue< EOT* >tasks; std :: queue< EOT* >tasks;
std :: map< EOT*, std :: pair< unsigned, unsigned > > progression; std :: map< EOT*, std :: pair< unsigned, unsigned > > progression;
unsigned num_func; unsigned num_func;
EOT sol; EOT sol;
EOT *ad_sol; EOT *ad_sol;
unsigned total; unsigned total;
}; };

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sebastien Cahon, Alexandru-Adrian Tantar * Sebastien Cahon, Alexandru-Adrian Tantar, Clive Canape
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -63,103 +63,23 @@
#include "rmc/mpi/synchron.h" #include "rmc/mpi/synchron.h"
//! Class providing the basis for the synchronous island migration model. //! @class peoSyncIslandMig
//! @brief Specific class for a synchronous migration
//! The peoSyncIslandMig class offers the elementary basis for implementating a //! @see Cooperative eoUpdater
//! synchronous island migration model - requires the specification of several basic //! @version 2.0
//! parameters, i.e. frequency of the migrations, selection and replacement strategies, //! @date january 2008
//! a topological model and the source and destination population for the migrating individuals.
//! The main difference as opposed to the asynchronous migration model is the synchronization step
//! performed after selecting and sending the emigrant individuals.
//!
//! The migration operator is called at the end of each generation of an evolutionary algorithms
//! as a checkpoint object - the following code exposes the structure of a classic evolutionary algorithm:
//!
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
//! <tr><td><b>do</b> { &nbsp;</td> <td> &nbsp; </td></tr>
//! <tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select( population, offsprings ); &nbsp;</td> <td>// select the offsprings from the current population</td></tr>
//! <tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transform( offsprings ); &nbsp;</td> <td>// crossover and mutation operators are applied on the selected offsprings</td></tr>
//! <tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; evaluate( offsprings ); &nbsp;</td> <td>// evaluation step of the resulting offspring</td></tr>
//! <tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; replace( population, offsprings ); &nbsp;</td> <td>// replace the individuals in the current population whith individuals from the offspring population, according to a specified replacement strategy</td></tr>
//! <tr><td>} <b>while</b> ( eaCheckpointContinue( population ) ); &nbsp;</td> <td>// checkpoint operators are applied on the current population, including the migration operator, if any specified </td></tr>
//! </table>
//!
//! Constructing a synchronous island migration model requires having defined (1) a topological migration model,
//! (2) the control parameters of the migration process, (3) a checkpoint object associated with an evolutionary algorithm,
//! and (4) an owner object must be set. The owner object must be derived from the <b>Runner</b> class (for example
//! a peoEA object represents a possible owner).
//! A simple example is offered bellow:
//!
//! <ol>
//! <li> topological model to be followed when performing migrations: <br/>
//! <br/>
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
//! <tr><td>RingTopology migTopology; &nbsp;</td> <td>// a simple ring topological model - each island communicates with two other islands</td></tr>
//! </table>
//! </li>
//!
//! <li> the continuation criterion, selection and replacement strategy etc. are defined: <br/>
//! <br/>
//! <table style="border:none; border-spacing:0px; font-size:8pt;" border="0">
//! <tr><td>eoPop< EOT > population( POP_SIZE, popInitializer ); &nbsp;</td> <td>// population of individuals to be used for the evolutionary algorithm</td></tr>
//! <tr><td> &nbsp; </td> <td> &nbsp; </td></tr>
//! <tr><td>eoRandomSelect< EOT > migSelectStrategy; &nbsp;</td> <td>// selection strategy - in this case a random selection is applied</td></tr>
//! <tr><td>eoSelectNumber< EOT > migSelect( migSelectStrategy, MIG_SIZE ); &nbsp;</td> <td>// number of individuals to be selected using the specified strategy</td></tr>
//! <tr><td>eoPlusReplacement< EOT > migReplace; &nbsp;</td> <td>// immigration strategy - the worse individuals in the destination population are replaced by the immigrant individuals</td></tr>
//! <tr><td> &nbsp; </td> <td> &nbsp; </td></tr>
//! <tr><td>peoSyncIslandMig< EOT > syncMigration(
//! <br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MIG_FREQ, migSelect, migReplace, migTopology,
//! <br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; population, population
//! <br/> ); &nbsp; </td>
//! <td>// synchronous migration object - the emigrant individuals are selected from the same from population in which the immigrant individuals are being integrated </td></tr>
//! </table>
//! </li>
//!
//! <li> creation of a checkpoint object as part of the definition of an evolutionary algoritm (details of th EA not given as being out of scope): <br/>
//! <br/>
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
//! <tr><td>... &nbsp;</td> <td> &nbsp; </td></tr>
//! <tr><td>eoGenContinue< EOT > eaCont( NUM_GEN ); &nbsp;</td> <td>// the evolutionary algorithm will stop after NUM_GEN generations</td></tr>
//! <tr><td>eoCheckPoint< EOT > eaCheckpointContinue( eaCont ); &nbsp;</td> <td>// number of individuals to be selected using the specified strategy</td></tr>
//! <tr><td>... &nbsp;</td> <td> &nbsp; </td></tr>
//! <tr><td>eaCheckpointContinue.add( syncMigration ); &nbsp;</td> <td>// adding the migration operator as checkpoint element</td></tr>
//! <tr><td>... &nbsp;</td> <td> &nbsp; </td></tr>
//! </table>
//! </li>
//!
//! <li> definition of an owner evolutionary algorithm (an object inheriting the <b>Runner</b> class): <br/>
//! <br/>
//! <table style="border:none; border-spacing:0px;text-align:left; vertical-align:top; font-size:8pt;" border="0">
//! <tr><td>peoEA< EOT > eaAlg( eaCheckpointContinue, eaPopEval, eaSelect, eaTransform, eaReplace); &nbsp;</td> <td>// evolutionary algorithm having as checkpoint the eaCheckpointContinue object defined above </td></tr>
//! <tr><td>syncMigration.setOwner( eaAlg ); &nbsp;</td> <td>// setting the evolutionary algorithm as owner of the migration object </td></tr>
//! <tr><td>eaAlg( population ); &nbsp;</td> <td>// applying the evolutionary algorithm on a given population </td></tr>
//! </table>
//! </li>
//! </ol>
//!
//! The source and the destination population for the migration object were specified as being the same, in step no. 2,
//! as we are usually interested in selecting the emigrants and integrating the immigrant individuals from and in, respectively, one unique
//! population, iteratively evolved by an evolutionary algorithm. There is no restriction in having two distinct populations
//! as source and destination for the emigrant and immigrant individuals respectively.
//!
//! The above steps only create a synchronous migration object associated to an evolutionary algorithm. The creation of several
//! islands requires the reiteration of the steps 2 through 4 for creating distinct algorithms, with distinct populations and
//! the associated distinctly parametrized migration objects. The interconnecting element is the underlying topology, defined at step 1
//! (the same C++ migTopology object has to be passed as parameter for all the migration objects, in order to interconnect them).
template< class EOT, class TYPE > class peoSyncIslandMig : public Cooperative, public eoUpdater template< class EOT, class TYPE > class peoSyncIslandMig : public Cooperative, public eoUpdater
{ {
public: public:
//! Constructor for the peoSyncIslandMig class; the characteristics of the migration model are defined //! @brief Constructor
//! through the specified parameters - out of the box objects provided in EO, etc., or custom, derived objects may be passed as parameters. //! @param unsigned __frequency
//! //! @param selector <TYPE> & __select
//! @param unsigned __frequency - frequency of the migrations - the migrations occur periodically; //! @param replacement <TYPE> & __replace
//! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of emigrant individuals out of the source population; //! @param Topology& __topology
//! @param eoReplacement< EOT >& __replace - replacement strategy used for integrating the immigrant individuals in the destination population; //! @param peoData & __source
//! @param Topology& __topology - topological model to be followed when performing migrations; //! @param eoData & __destination
//! @param eoPop< EOT >& __source - source population from which the emigrant individuals are selected;
//! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated.
peoSyncIslandMig( peoSyncIslandMig(
unsigned __frequency, unsigned __frequency,
selector <TYPE> & __select, selector <TYPE> & __select,
@ -169,32 +89,23 @@ template< class EOT, class TYPE > class peoSyncIslandMig : public Cooperative,
peoData & __destination peoData & __destination
); );
//! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected //! @brief operator
//! from the source population and sent to the next island (defined by the topology object) while the immigrant
//! individuals are integrated in the destination population. There is no need to explicitly call the function - the
//! wrapper checkpoint object (please refer to the above example) will perform the call when required.
void operator()(); void operator()();
//! @brief Function realizing packages
//! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function.
void pack(); void pack();
//! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function. //! @brief Function reconstituting packages
void unpack(); void unpack();
//! Auxiliary function dealing with the packing of synchronization requests. There is no need to explicitly call the function. //! @brief Function packSynchronizeReq
void packSynchronizeReq(); void packSynchronizeReq();
//! @brief Function notifySending
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
void notifySending(); void notifySending();
//! @brief Function notifyReceiving
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
void notifyReceiving(); void notifyReceiving();
//! @brief notifySendingSyncReq
//! Auxiliary function dealing with synchronizing runners for migrations. There is no need to explicitly call the function.
void notifySendingSyncReq(); void notifySendingSyncReq();
//! @brief notifySynchronized
//! Auxiliary function for notifying the synchronization of the runners involved in migration.
void notifySynchronized(); void notifySynchronized();
private: private:
void emigrate(); void emigrate();
@ -202,22 +113,32 @@ template< class EOT, class TYPE > class peoSyncIslandMig : public Cooperative,
private: private:
//! @param eoSyncContinue cont
eoSyncContinue cont; // continuator //! @param selector <TYPE> & select
selector <TYPE> & select; // the selection strategy //! @param replacement <TYPE> & replace
replacement <TYPE> & replace; // the replacement strategy //! @param Topology& topology
Topology& topology; // the neighboring topology //! @param peoData & source
//! @param peoData & destination
//! @param std :: queue< TYPE > imm
//! @param std :: queue< TYPE > em
//! @param std :: queue< Cooperative* > coop_em
//! @param sem_t sync
//! @param bool explicitPassive
//! @param bool standbyMigration
//! @param std :: vector< Cooperative* > in, out, all
//! @param unsigned nbMigrations
eoSyncContinue cont;
selector <TYPE> & select;
replacement <TYPE> & replace;
Topology& topology;
peoData & source; peoData & source;
peoData & destination; peoData & destination;
std :: queue< TYPE > imm; std :: queue< TYPE > imm;
std :: queue< TYPE > em; std :: queue< TYPE > em;
std :: queue< Cooperative* > coop_em; std :: queue< Cooperative* > coop_em;
sem_t sync; sem_t sync;
bool explicitPassive; bool explicitPassive;
bool standbyMigration; bool standbyMigration;
std :: vector< Cooperative* > in, out, all; std :: vector< Cooperative* > in, out, all;
unsigned nbMigrations; unsigned nbMigrations;
}; };

View file

@ -45,49 +45,63 @@
extern int getNodeRank(); extern int getNodeRank();
//! @class peoTransform
//! @brief Class for a parallel transform
//! @see Service eoTransform
//! @version 1.1
//! @date january 2008
template< class EOT > class peoTransform : public Service, public eoTransform< EOT > template< class EOT > class peoTransform : public Service, public eoTransform< EOT >
{ {
public: public:
//! @brief Constructor
//! @param eoQuadOp< EOT >& __cross
//! @param double __cross_rate
//! @param eoMonOp< EOT >& __mut
//! @param double __mut_rate
peoTransform( peoTransform(
eoQuadOp< EOT >& __cross, eoQuadOp< EOT >& __cross,
double __cross_rate, double __cross_rate,
eoMonOp< EOT >& __mut, eoMonOp< EOT >& __mut,
double __mut_rate double __mut_rate
); );
//! @brief Operator
//! @param eoPop< EOT >& __pop
void operator()( eoPop< EOT >& __pop ); void operator()( eoPop< EOT >& __pop );
//! @brief Function realizing packages of data
void packData(); void packData();
//! @brief Function reconstituting packages of data
void unpackData(); void unpackData();
//! @brief Function which executes the algorithm
void execute(); void execute();
//! @brief Function realizing packages of the result
void packResult(); void packResult();
//! @brief Function reconstituting packages of result
void unpackResult(); void unpackResult();
//! @brief Function notifySendingData
void notifySendingData(); void notifySendingData();
//! @brief Function notifySendingAllResourceRequests
void notifySendingAllResourceRequests(); void notifySendingAllResourceRequests();
private: private:
//! @param eoQuadOp< EOT >& cross
//! @param double cross_rate
//! @param eoMonOp< EOT >& mut
//! @param double mut_rate
//! @param unsigned idx
//! @param eoPop< EOT >* pop
//! @param EOT father
//! @param mother
//! @param unsigned num_term
eoQuadOp< EOT >& cross; eoQuadOp< EOT >& cross;
double cross_rate; double cross_rate;
eoMonOp< EOT >& mut; eoMonOp< EOT >& mut;
double mut_rate; double mut_rate;
unsigned idx; unsigned idx;
eoPop< EOT >* pop; eoPop< EOT >* pop;
EOT father, mother; EOT father, mother;
unsigned num_term; unsigned num_term;
}; };

View file

@ -45,13 +45,21 @@
#include <eoReplacement.h> #include <eoReplacement.h>
#include <utils/eoHowMany.h> #include <utils/eoHowMany.h>
template <class POT> //! @class peoWorstPositionReplacement
class peoWorstPositionReplacement : public eoReplacement<POT> //! @brief Specific class for a replacement of a population of a PSO
//! @see eoReplacement
//! @version 1.1
//! @date october 2007
template <class POT> class peoWorstPositionReplacement : public eoReplacement<POT>
{ {
public: public:
//! @brief constructor
peoWorstPositionReplacement() peoWorstPositionReplacement()
{} {}
//! @brief operator
//! @param eoPop<POT>& _dest
//! @param eoPop<POT>& _source
void operator()(eoPop<POT>& _dest, eoPop<POT>& _source) void operator()(eoPop<POT>& _dest, eoPop<POT>& _source)
{ {
unsigned ind=0; unsigned ind=0;

View file

@ -1,7 +1,7 @@
/* /*
* <peoWrapper.h> * <peoWrapper.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2008
* *
* Sebastien Cahon, Alexandru-Adrian Tantar * Sebastien Cahon, Alexandru-Adrian Tantar
* *
@ -41,36 +41,49 @@
#include "core/runner.h" #include "core/runner.h"
#include "core/peo_debug.h" #include "core/peo_debug.h"
//! @class peoWrapper
//! @brief Specific class for wrapping
//! @see Runner
//! @version 1.1
//! @date december 2007
class peoWrapper : public Runner class peoWrapper : public Runner
{ {
public: public:
//! @brief constructor
//! @param AlgorithmType& externalAlgorithm
template< typename AlgorithmType > peoWrapper( AlgorithmType& externalAlgorithm ) template< typename AlgorithmType > peoWrapper( AlgorithmType& externalAlgorithm )
: algorithm( new Algorithm< AlgorithmType, void >( externalAlgorithm ) ) : algorithm( new Algorithm< AlgorithmType, void >( externalAlgorithm ) )
{} {}
//! @brief constructor
//! @param AlgorithmType& externalAlgorithm
//! @param AlgorithmDataType& externalData
template< typename AlgorithmType, typename AlgorithmDataType > peoWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData ) template< typename AlgorithmType, typename AlgorithmDataType > peoWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
: algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) ) : algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) )
{} {}
//! @brief constructor
//! @param AlgorithmReturnType& (*externalAlgorithm)()
template< typename AlgorithmReturnType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)() ) template< typename AlgorithmReturnType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)() )
: algorithm( new FunctionAlgorithm< AlgorithmReturnType, void >( externalAlgorithm ) ) : algorithm( new FunctionAlgorithm< AlgorithmReturnType, void >( externalAlgorithm ) )
{} {}
//! @brief constructor
//! @param AlgorithmReturnType& (*externalAlgorithm)( AlgorithmDataType& )
//! @param AlgorithmDataType& externalData
template< typename AlgorithmReturnType, typename AlgorithmDataType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData ) template< typename AlgorithmReturnType, typename AlgorithmDataType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData )
: algorithm( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm, externalData ) ) : algorithm( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm, externalData ) )
{} {}
//! @brief destructor
~peoWrapper() ~peoWrapper()
{ {
delete algorithm; delete algorithm;
} }
//! @brief function run
void run() void run()
{ {
algorithm->operator()(); algorithm->operator()();
@ -153,7 +166,7 @@ class peoWrapper : public Runner
}; };
private: private:
//! @param AbstractAlgorithm* algorithm
AbstractAlgorithm* algorithm; AbstractAlgorithm* algorithm;
}; };