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>
* 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
* abiding by the rules of distribution of free software. You can use,

View file

@ -1,7 +1,7 @@
/*
* <peo.h>
* 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
*

View file

@ -1,9 +1,9 @@
/*
* <peoAggEvalFunc.h>
* 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
* abiding by the rules of distribution of free software. You can use,

View file

@ -1,9 +1,9 @@
/*
* <peoAsyncIslandMig.h>
* 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
* abiding by the rules of distribution of free software. You can use,
@ -56,105 +56,24 @@
#include "core/peo_debug.h"
//! Class providing the basis for the asynchronous island migration model.
//! The peoAsyncIslandMig class offers the elementary basis for implementating an
//! asynchronous island migration model - requires the specification of several basic
//! parameters, i.e. continuation criterion, selection and replacement strategies,
//! 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).
//! @class peoAsyncIslandMig
//! @brief Specific class for a asynchronous migration
//! @see Cooperative eoUpdater
//! @version 2.0
//! @date january 2008
template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative, public eoUpdater
{
public:
//! Constructor for the peoAsyncIslandMig class; the characteristics of the migration model are defined
//! through the specified parameters - out of the box objects provided in EO, etc., or custom, derived objects may be passed as parameters.
//!
//! @param eoContinue< EOT >& __cont - continuation criterion specifying whether the migration is performed or not;
//! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of emigrant individuals out of the source population;
//! @param eoReplacement< EOT >& __replace - replacement strategy used for integrating the immigrant individuals in the destination population;
//! @param Topology& __topology - topological model to be followed when performing migrations;
//! @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.
peoAsyncIslandMig(
//! @brief Constructor
//! @param continuator & __cont
//! @param selector <TYPE> & __select
//! @param replacement <TYPE> & __replace
//! @param Topology& __topology
//! @param peoData & __source
//! @param eoData & __destination
peoAsyncIslandMig(
continuator & __cont,
selector <TYPE> & __select,
replacement <TYPE> & __replace,
@ -163,33 +82,35 @@ template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative,
peoData & __destination
);
//! 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.
//! @brief operator
void operator()();
//! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function.
//! @brief Function realizing packages
void pack();
//! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function.
//! @brief Function reconstituting packages
void unpack();
//! Auxiliary function dealing with the packing of synchronization requests - not the case.
//! @brief Function packSynchronizeReq
void packSynchronizeReq();
private:
//! @brief Function which sends some emigrants
void emigrate();
//! @brief Function which receives some immigrants
void immigrate();
private:
continuator & cont; // continuator
selector <TYPE> & select; // the selection strategy
replacement <TYPE> & replace; // the replacement strategy
Topology& topology; // the neighboring topology
//! @param continuator & cont
//! @param selector <TYPE> & select
//! @param replacement <TYPE> & replace
//! @param Topology& 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 & destination;
std :: queue< TYPE > imm;
@ -278,8 +199,8 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: operato
if (cont.check())
{
emigrate(); // sending emigrants
immigrate(); // receiving immigrants
emigrate();
immigrate();
}
}

View file

@ -1,7 +1,7 @@
/*
* <peoData.h>
* 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
*
@ -44,25 +44,35 @@
/************************** DEFINE A DATA ******************************************/
/**************************************************************************************/
//! @class peoData
//! @brief Abstract class for a data exchanged by migration
//! @version 1.0
//! @date january 2008
class peoData
{
public:
//! @brief Function realizing packages
virtual void pack ()
{}
//! @brief Function reconstituting packages
virtual void unpack ()
{}
};
// Specific implementation : migration of a population
//! @class peoPop
//! @brief Specific class for a migration of a population
//! @see peoData eoPop
//! @version 1.0
//! @date january 2008
template<class EOT>
class peoPop: public eoPop<EOT>, public peoData
{
public:
//! @brief Function realizing packages
virtual void pack ()
{
::pack ((unsigned) this->size ());
@ -70,6 +80,7 @@ class peoPop: public eoPop<EOT>, public peoData
::pack ((*this)[i]);
}
//! @brief Function reconstituting packages
virtual void unpack ()
{
unsigned n;
@ -86,28 +97,45 @@ class peoPop: public eoPop<EOT>, public peoData
/************************** 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
{
public:
//! @brief Virtual function of check
//! @return true if the algorithm must continue
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
{
public:
//! @brief Constructor
//! @param eoContinue<EOT> &
//! @param eoPop<EOT> &
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()
{
return cont(pop);
}
protected:
//! @param eoContinue<EOT> &
//! @param eoPop<EOT> &
eoContinue<EOT> & cont ;
const eoPop<EOT> & pop;
};
@ -117,23 +145,39 @@ template < class EOT> class eoContinuator : public continuator
/************************** 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
{
public:
//! @brief Virtual operator on the template type
//! @param TYPE &
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 >
{
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)
{}
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);
_dest.resize(target);
@ -142,6 +186,9 @@ template < class EOT, class TYPE> class eoSelector : public selector< TYPE >
}
protected:
//! @param eoSelectOne<EOT> &
//! @param unsigned nb_select
//! @param TYPE & source
eoSelectOne<EOT> & selector ;
unsigned nb_select;
const TYPE & source;
@ -152,27 +199,43 @@ template < class EOT, class TYPE> class eoSelector : public selector< TYPE >
/************************** 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
{
public:
//! @brief Virtual operator on the template type
//! @param TYPE &
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 >
{
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)
{}
//! @brief Virtual operator on the template type
//! @param TYPE & _source
virtual void operator()(TYPE & _source)
{
replace(destination, _source);
}
protected:
//! @param eoReplacement<EOT> &
//! @param TYPE & destination
eoReplacement<EOT> & replace;
TYPE & destination;
};
@ -182,14 +245,23 @@ template < class EOT, class TYPE> class eoReplace : public replacement< TYPE >
/************************ 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
{
public:
//! @brief Constructor
//! @param unsigned __period
//! @param unsigned __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()
{
return ((++ counter) % period) != 0 ;
@ -197,11 +269,10 @@ class eoSyncContinue: public continuator
private:
//! @param unsigned period
//! @param unsigned counter
unsigned period;
unsigned counter;
};

View file

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

View file

@ -46,19 +46,28 @@
#include <eoReplacement.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>
class peoGlobalBestVelocity : public eoReplacement<POT>
{
public:
//! @brief typedef : creation of VelocityType
typedef typename POT::ParticleVelocityType VelocityType;
peoGlobalBestVelocity( const double & _c3,
eoVelocity < POT > &_velocity):
c3 (_c3),
velocity (_velocity)
//! @brief Constructor
//! @param double & _c3
//! @param eoVelocity < POT > &_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)
{
@ -74,6 +83,8 @@ class peoGlobalBestVelocity : public eoReplacement<POT>
}
protected:
//! @param double & c3
//! @param eoVelocity < POT > & velocity
const double & c3;
eoVelocity < POT > & velocity;
};

View file

@ -1,9 +1,9 @@
/*
* <peoMoeoPopEval.h>
* 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
* abiding by the rules of distribution of free software. You can use,
@ -45,12 +45,11 @@
#include "peoAggEvalFunc.h"
#include "peoNoAggEvalFunc.h"
//! Parallel evaluation functor wrapper.
//! The peoMoeoPopEval represents a wrapper for creating a functor capable of applying in parallel
//! an EO-derived evaluation functor. The class offers the possibility of chosing between a single-function evaluation
//! and an aggregate evaluation function, including several sub-evalution functions.
//! @class peoPopEval
//! @brief Parallel evaluation functor wrapper with MOEO
//! @see Service eoPopEvalFunc
//! @version 1.0
//! @date 2008
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.
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 );
//! 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();
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;
std :: vector< eoEvalFunc < EOT >* > one_func;
peoAggEvalFunc< EOT >& merge_eval;
peoNoAggEvalFunc< EOT > no_merge_eval;
std :: queue< EOT* >tasks;
std :: map< EOT*, std :: pair< unsigned, unsigned > > progression;
unsigned num_func;
EOT sol;
EOT *ad_sol;
unsigned total;
};

View file

@ -1,9 +1,9 @@
/*
* <peoMultiStart.h>
* 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
* abiding by the rules of distribution of free software. You can use,
@ -41,204 +41,188 @@
#include "core/service.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
{
public:
//! @brief Constructor
//! @param AlgorithmType& externalAlgorithm
template < typename AlgorithmType > peoMultiStart( AlgorithmType& externalAlgorithm )
{
singularAlgorithm = new Algorithm< AlgorithmType >( externalAlgorithm );
algorithms.push_back( singularAlgorithm );
aggregationFunction = new NoAggregationFunction();
}
//! @brief Constructor
//! @param AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& )
template < typename AlgorithmReturnType, typename AlgorithmDataType > peoMultiStart( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) )
{
singularAlgorithm = new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm );
algorithms.push_back( singularAlgorithm );
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 )
{
for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ )
{
algorithms.push_back( new Algorithm< AlgorithmType >( *externalAlgorithms[ index ] ) );
}
aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction );
}
template < typename AlgorithmReturnType, typename AlgorithmDataType, typename AggregationFunctionType >
peoMultiStart( std::vector< AlgorithmReturnType (*)( AlgorithmDataType& ) >& externalAlgorithms,
AggregationFunctionType& externalAggregationFunction )
//! @brief Constructor
//! @param std::vector< AlgorithmReturnType (*)( AlgorithmDataType& ) >& externalAlgorithms
//! @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++ )
{
algorithms.push_back( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithms[ index ] ) );
}
aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction );
}
//! @brief Destructor
~peoMultiStart()
{
for ( unsigned int index = 0; index < data.size(); index++ ) delete data[ index ];
for ( unsigned int index = 0; index < algorithms.size(); index++ ) delete algorithms[ index ];
delete aggregationFunction;
for ( unsigned int index = 0; index < algorithms.size(); index++ ) delete algorithms[ index ];
delete aggregationFunction;
}
//! @brief operator on the template type
//! @param Type& externalData
template < typename Type > void operator()( Type& externalData )
{
for ( typename Type::iterator externalDataIterator = externalData.begin(); externalDataIterator != externalData.end(); externalDataIterator++ )
{
data.push_back( new DataType< EntityType >( *externalDataIterator ) );
}
functionIndex = dataIndex = idx = num_term = 0;
requestResourceRequest( data.size() * algorithms.size() );
stop();
}
//! @brief operator on the template type
//! @param Type& externalDataBegin
//! @param Type& externalDataEnd
template < typename Type > void operator()( const Type& externalDataBegin, const Type& externalDataEnd )
{
for ( Type externalDataIterator = externalDataBegin; externalDataIterator != externalDataEnd; externalDataIterator++ )
{
data.push_back( new DataType< EntityType >( *externalDataIterator ) );
}
functionIndex = dataIndex = idx = num_term = 0;
requestResourceRequest( data.size() * algorithms.size() );
stop();
}
//! @brief Function realizing packages of data
void packData();
//! @brief Function reconstituting packages of data
void unpackData();
//! @brief Function which executes the algorithm
void execute();
//! @brief Function realizing packages of the result
void packResult();
//! @brief Function reconstituting packages of result
void unpackResult();
//! @brief Function notifySendingData
void notifySendingData();
//! @brief Function notifySendingAllResourceRequests
void notifySendingAllResourceRequests();
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;
struct AbstractDataType
{
virtual ~AbstractDataType()
{ }
template < typename Type > operator Type& ()
{
return ( dynamic_cast< DataType< Type >& >( *this ) ).data;
}
};
template < typename Type > struct DataType : public AbstractDataType
{
DataType( Type& externalData ) : data( externalData )
{ }
Type& data;
};
struct AbstractAlgorithm
{
virtual ~AbstractAlgorithm()
{ }
virtual void operator()( AbstractDataType& dataTypeInstance )
{}
};
template < typename AlgorithmType > struct Algorithm : public AbstractAlgorithm
{
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm )
{ }
void operator()( AbstractDataType& dataTypeInstance )
{
algorithm( dataTypeInstance );
}
AlgorithmType& algorithm;
};
template < typename AlgorithmReturnType, typename AlgorithmDataType > struct FunctionAlgorithm : public AbstractAlgorithm
{
FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) ) : algorithm( externalAlgorithm )
{ }
void operator()( AbstractDataType& dataTypeInstance )
{
algorithm( dataTypeInstance );
}
AlgorithmReturnType (*algorithm)( AlgorithmDataType& );
};
struct AbstractAggregationAlgorithm
{
virtual ~AbstractAggregationAlgorithm()
{ }
virtual void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
{};
};
template < typename AggregationAlgorithmType > struct AggregationAlgorithm : public AbstractAggregationAlgorithm
{
AggregationAlgorithm( AggregationAlgorithmType& externalAggregationAlgorithm ) : aggregationAlgorithm( externalAggregationAlgorithm )
{ }
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
{
aggregationAlgorithm( dataTypeInstanceA, dataTypeInstanceB );
}
AggregationAlgorithmType& aggregationAlgorithm;
};
struct NoAggregationFunction : public AbstractAggregationAlgorithm
{
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
{
@ -246,17 +230,11 @@ template < typename EntityType > class peoMultiStart : public Service
}
};
AbstractAlgorithm* singularAlgorithm;
std::vector< AbstractAlgorithm* > algorithms;
AbstractAggregationAlgorithm* aggregationFunction;
EntityType entityTypeInstance;
std::vector< AbstractDataType* > data;
unsigned idx;
unsigned num_term;
unsigned dataIndex;

View file

@ -1,9 +1,9 @@
/*
* <peoNoAggEvalFunc.h>
* 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
* 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 :
//! 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 );
};

View file

@ -39,21 +39,33 @@
#include <utils/eoRNG.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>
{
public:
//! @brief Constructor
//! @param eoTopology < POT > & _topology
peoPSOSelect(eoTopology < POT > & _topology):topology(_topology)
{}
//! @brief typedef : creation of Fitness
typedef typename PO < POT >::Fitness Fitness;
//! @brief Virtual operator
//! @param eoPop<POT>& _pop
//! @return POT&
virtual const POT& operator()(const eoPop<POT>& _pop)
{
return topology.globalBest(_pop);
}
private:
//! @param eoTopology < POT > & topology
eoTopology < POT > & topology;
};

View file

@ -1,9 +1,9 @@
/*
* <peoPopEval.h>
* 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
* abiding by the rules of distribution of free software. You can use,
@ -45,12 +45,11 @@
#include "peoAggEvalFunc.h"
#include "peoNoAggEvalFunc.h"
//! Parallel evaluation functor wrapper.
//! The peoPopEval represents a wrapper for creating a functor capable of applying in parallel
//! an EO-derived evaluation functor. The class offers the possibility of chosing between a single-function evaluation
//! and an aggregate evaluation function, including several sub-evalution functions.
//! @class peoPopEval
//! @brief Parallel evaluation functor wrapper
//! @see Service eoPopEvalFunc
//! @version 1.2
//! @date 2006
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.
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 );
//! 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:
//! @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;
std :: vector< eoEvalFunc < EOT >* > one_func;
peoAggEvalFunc< EOT >& merge_eval;
peoNoAggEvalFunc< EOT > no_merge_eval;
std :: queue< EOT* >tasks;
std :: map< EOT*, std :: pair< unsigned, unsigned > > progression;
unsigned num_func;
EOT sol;
EOT *ad_sol;
unsigned total;
};

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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
* abiding by the rules of distribution of free software. You can use,
@ -63,103 +63,23 @@
#include "rmc/mpi/synchron.h"
//! Class providing the basis for the synchronous island migration model.
//! The peoSyncIslandMig class offers the elementary basis for implementating a
//! synchronous island migration model - requires the specification of several basic
//! parameters, i.e. frequency of the migrations, selection and replacement strategies,
//! 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).
//! @class peoSyncIslandMig
//! @brief Specific class for a synchronous migration
//! @see Cooperative eoUpdater
//! @version 2.0
//! @date january 2008
template< class EOT, class TYPE > class peoSyncIslandMig : public Cooperative, public eoUpdater
{
public:
//! Constructor for the peoSyncIslandMig class; the characteristics of the migration model are defined
//! 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 - frequency of the migrations - the migrations occur periodically;
//! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of emigrant individuals out of the source population;
//! @param eoReplacement< EOT >& __replace - replacement strategy used for integrating the immigrant individuals in the destination population;
//! @param Topology& __topology - topological model to be followed when performing migrations;
//! @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.
//! @brief Constructor
//! @param unsigned __frequency
//! @param selector <TYPE> & __select
//! @param replacement <TYPE> & __replace
//! @param Topology& __topology
//! @param peoData & __source
//! @param eoData & __destination
peoSyncIslandMig(
unsigned __frequency,
selector <TYPE> & __select,
@ -169,32 +89,23 @@ template< class EOT, class TYPE > class peoSyncIslandMig : public Cooperative,
peoData & __destination
);
//! 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.
//! @brief operator
void operator()();
//! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function.
//! @brief Function realizing packages
void pack();
//! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function.
//! @brief Function reconstituting packages
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();
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
//! @brief Function notifySending
void notifySending();
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
//! @brief Function notifyReceiving
void notifyReceiving();
//! Auxiliary function dealing with synchronizing runners for migrations. There is no need to explicitly call the function.
//! @brief notifySendingSyncReq
void notifySendingSyncReq();
//! Auxiliary function for notifying the synchronization of the runners involved in migration.
//! @brief notifySynchronized
void notifySynchronized();
private:
void emigrate();
@ -202,22 +113,32 @@ template< class EOT, class TYPE > class peoSyncIslandMig : public Cooperative,
private:
eoSyncContinue cont; // continuator
selector <TYPE> & select; // the selection strategy
replacement <TYPE> & replace; // the replacement strategy
Topology& topology; // the neighboring topology
//! @param eoSyncContinue cont
//! @param selector <TYPE> & select
//! @param replacement <TYPE> & replace
//! @param Topology& 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 & destination;
std :: queue< TYPE > imm;
std :: queue< TYPE > em;
std :: queue< Cooperative* > coop_em;
sem_t sync;
bool explicitPassive;
bool standbyMigration;
std :: vector< Cooperative* > in, out, all;
unsigned nbMigrations;
};

View file

@ -45,49 +45,63 @@
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 >
{
public:
//! @brief Constructor
//! @param eoQuadOp< EOT >& __cross
//! @param double __cross_rate
//! @param eoMonOp< EOT >& __mut
//! @param double __mut_rate
peoTransform(
eoQuadOp< EOT >& __cross,
double __cross_rate,
eoMonOp< EOT >& __mut,
double __mut_rate
);
//! @brief Operator
//! @param eoPop< EOT >& __pop
void operator()( eoPop< EOT >& __pop );
//! @brief Function realizing packages of data
void packData();
//! @brief Function reconstituting packages of data
void unpackData();
//! @brief Function which executes the algorithm
void execute();
//! @brief Function realizing packages of the result
void packResult();
//! @brief Function reconstituting packages of result
void unpackResult();
//! @brief Function notifySendingData
void notifySendingData();
//! @brief Function notifySendingAllResourceRequests
void notifySendingAllResourceRequests();
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;
double cross_rate;
eoMonOp< EOT >& mut;
double mut_rate;
unsigned idx;
eoPop< EOT >* pop;
EOT father, mother;
unsigned num_term;
};

View file

@ -45,13 +45,21 @@
#include <eoReplacement.h>
#include <utils/eoHowMany.h>
template <class POT>
class peoWorstPositionReplacement : public eoReplacement<POT>
//! @class peoWorstPositionReplacement
//! @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:
//! @brief constructor
peoWorstPositionReplacement()
{}
//! @brief operator
//! @param eoPop<POT>& _dest
//! @param eoPop<POT>& _source
void operator()(eoPop<POT>& _dest, eoPop<POT>& _source)
{
unsigned ind=0;

View file

@ -1,7 +1,7 @@
/*
* <peoWrapper.h>
* 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
*
@ -41,36 +41,49 @@
#include "core/runner.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
{
public:
//! @brief constructor
//! @param AlgorithmType& externalAlgorithm
template< typename AlgorithmType > peoWrapper( AlgorithmType& 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 )
: algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) )
{}
//! @brief constructor
//! @param AlgorithmReturnType& (*externalAlgorithm)()
template< typename AlgorithmReturnType > peoWrapper( AlgorithmReturnType& (*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 )
: algorithm( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm, externalData ) )
{}
//! @brief destructor
~peoWrapper()
{
delete algorithm;
}
//! @brief function run
void run()
{
algorithm->operator()();
@ -153,7 +166,7 @@ class peoWrapper : public Runner
};
private:
//! @param AbstractAlgorithm* algorithm
AbstractAlgorithm* algorithm;
};