Rename peoParaPopEval to peoPopEval
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@845 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
6d7154a723
commit
fd8d648fd9
7 changed files with 259 additions and 7 deletions
|
|
@ -329,7 +329,7 @@
|
||||||
/* <------- components for parallel algorithms -------> */
|
/* <------- components for parallel algorithms -------> */
|
||||||
#include "peoParaSGATransform.h"
|
#include "peoParaSGATransform.h"
|
||||||
#include "peoEvalFunc.h"
|
#include "peoEvalFunc.h"
|
||||||
#include "peoParaPopEval.h"
|
#include "peoPopEval.h"
|
||||||
|
|
||||||
/* Cooperative island model */
|
/* Cooperative island model */
|
||||||
#include "core/ring_topo.h"
|
#include "core/ring_topo.h"
|
||||||
|
|
|
||||||
252
trunk/paradiseo-peo/src/peoPopEval.h
Normal file
252
trunk/paradiseo-peo/src/peoPopEval.h
Normal file
|
|
@ -0,0 +1,252 @@
|
||||||
|
/*
|
||||||
|
* <peoPopEval.h>
|
||||||
|
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||||
|
* (C) OPAC Team, LIFL, 2002-2007
|
||||||
|
*
|
||||||
|
* Sebastien Cahon, Alexandru-Adrian Tantar
|
||||||
|
*
|
||||||
|
* This software is governed by the CeCILL license under French law and
|
||||||
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
|
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
* "http://www.cecill.info".
|
||||||
|
*
|
||||||
|
* As a counterpart to the access to the source code and rights to copy,
|
||||||
|
* modify and redistribute granted by the license, users are provided only
|
||||||
|
* with a limited warranty and the software's author, the holder of the
|
||||||
|
* economic rights, and the successive licensors have only limited liability.
|
||||||
|
*
|
||||||
|
* In this respect, the user's attention is drawn to the risks associated
|
||||||
|
* with loading, using, modifying and/or developing or reproducing the
|
||||||
|
* software by the user in light of its specific status of free software,
|
||||||
|
* that may mean that it is complicated to manipulate, and that also
|
||||||
|
* therefore means that it is reserved for developers and experienced
|
||||||
|
* professionals having in-depth computer knowledge. Users are therefore
|
||||||
|
* encouraged to load and test the software's suitability as regards their
|
||||||
|
* requirements in conditions enabling the security of their systems and/or
|
||||||
|
* data to be ensured and, more generally, to use and operate it in the
|
||||||
|
* same conditions as regards security.
|
||||||
|
* The fact that you are presently reading this means that you have had
|
||||||
|
* knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
*
|
||||||
|
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
|
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __peoPopEval_h
|
||||||
|
#define __peoPopEval_h
|
||||||
|
|
||||||
|
#include <queue>
|
||||||
|
#include <eoEvalFunc.h>
|
||||||
|
|
||||||
|
#include "core/messaging.h"
|
||||||
|
#include "core/peo_debug.h"
|
||||||
|
#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.
|
||||||
|
template< class EOT > class peoPopEval : public Service, public eoPopEvalFunc<EOT>
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Constructor function - an EO-derived evaluation functor has to be specified; an internal reference
|
||||||
|
//! is set towards the specified evaluation functor.
|
||||||
|
//!
|
||||||
|
//! @param eoEvalFunc< EOT >& __eval_func - EO-derived evaluation functor to be applied in parallel on each individual of a specified population
|
||||||
|
peoPopEval( eoEvalFunc< EOT >& __eval_func );
|
||||||
|
|
||||||
|
//! Constructor function - a vector of EO-derived evaluation functors has to be specified as well as an aggregation function.
|
||||||
|
//!
|
||||||
|
//! @param const std :: vector< eoEvalFunc < EOT >* >& __funcs - vector of EO-derived partial evaluation functors;
|
||||||
|
//! @param peoAggEvalFunc< EOT >& __merge_eval - aggregation functor for creating a fitness value out of the partial fitness values.
|
||||||
|
peoPopEval( const std :: vector< eoEvalFunc < EOT >* >& __funcs, peoAggEvalFunc< EOT >& __merge_eval );
|
||||||
|
|
||||||
|
//! Operator for applying the evaluation functor (direct or aggregate) for each individual of the specified population.
|
||||||
|
//!
|
||||||
|
//! @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 >& __dummy, eoPop< EOT >& __pop );
|
||||||
|
|
||||||
|
//! Auxiliary function for transferring data between the process requesting an evaluation operation and the process that
|
||||||
|
//! performs the actual evaluation phase. There is no need to explicitly call the function.
|
||||||
|
void packData();
|
||||||
|
|
||||||
|
//! Auxiliary function for transferring data between the process requesting an evaluation operation and the process that
|
||||||
|
//! performs the actual evaluation phase. There is no need to explicitly call the function.
|
||||||
|
void unpackData();
|
||||||
|
|
||||||
|
//! Auxiliary function - it calls the specified evaluation functor(s). There is no need to explicitly call the function.
|
||||||
|
void execute();
|
||||||
|
|
||||||
|
//! Auxiliary function for transferring data between the process requesting an evaluation operation and the process that
|
||||||
|
//! performs the actual evaluation phase. There is no need to explicitly call the function.
|
||||||
|
void packResult();
|
||||||
|
|
||||||
|
//! Auxiliary function for transferring data between the process requesting an evaluation operation and the process that
|
||||||
|
//! performs the actual evaluation phase. There is no need to explicitly call the function.
|
||||||
|
void unpackResult();
|
||||||
|
|
||||||
|
//! Auxiliary function for notifications between the process requesting an evaluation operation and the processes that
|
||||||
|
//! performs the actual evaluation phase. There is no need to explicitly call the function.
|
||||||
|
void notifySendingData();
|
||||||
|
|
||||||
|
//! Auxiliary function for notifications between the process requesting an evaluation operation and the processes that
|
||||||
|
//! performs the actual evaluation phase. There is no need to explicitly call the function.
|
||||||
|
void notifySendingAllResourceRequests();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template< class EOT > peoPopEval< EOT > :: peoPopEval( eoEvalFunc< EOT >& __eval_func ) :
|
||||||
|
|
||||||
|
funcs( one_func ), merge_eval( no_merge_eval )
|
||||||
|
{
|
||||||
|
|
||||||
|
one_func.push_back( &__eval_func );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template< class EOT > peoPopEval< EOT > :: peoPopEval(
|
||||||
|
|
||||||
|
const std :: vector< eoEvalFunc< EOT >* >& __funcs,
|
||||||
|
peoAggEvalFunc< EOT >& __merge_eval
|
||||||
|
|
||||||
|
) : funcs( __funcs ), merge_eval( __merge_eval )
|
||||||
|
{}
|
||||||
|
|
||||||
|
template< class EOT > void peoPopEval< EOT >::operator()(eoPop< EOT >& __dummy, eoPop< EOT >& __pop )
|
||||||
|
{
|
||||||
|
this->operator()(__pop);
|
||||||
|
}
|
||||||
|
|
||||||
|
template< class EOT > void peoPopEval< EOT >::operator()(eoPop< EOT >& __pop )
|
||||||
|
{
|
||||||
|
for ( unsigned i = 0; i < __pop.size(); i++ )
|
||||||
|
{
|
||||||
|
__pop[ i ].fitness(typename EOT :: Fitness() );
|
||||||
|
progression[ &__pop[ i ] ].first = funcs.size() - 1;
|
||||||
|
progression[ &__pop[ i ] ].second = funcs.size();
|
||||||
|
for ( unsigned j = 0; j < funcs.size(); j++ )
|
||||||
|
{
|
||||||
|
/* Queuing the 'invalid' solution and its associated owner */
|
||||||
|
tasks.push( &__pop[ i ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
total = funcs.size() * __pop.size();
|
||||||
|
requestResourceRequest( funcs.size() * __pop.size() );
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template< class EOT > void peoPopEval< EOT > :: packData()
|
||||||
|
{
|
||||||
|
// printDebugMessage ("debut pakc data");
|
||||||
|
pack( progression[ tasks.front() ].first-- );
|
||||||
|
|
||||||
|
/* Packing the contents :-) of the solution */
|
||||||
|
pack( *tasks.front() );
|
||||||
|
|
||||||
|
/* Packing the addresses of both the solution and the owner */
|
||||||
|
pack( tasks.front() );
|
||||||
|
tasks.pop( );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template< class EOT > void peoPopEval< EOT > :: unpackData()
|
||||||
|
{
|
||||||
|
unpack( num_func );
|
||||||
|
/* Unpacking the solution */
|
||||||
|
unpack( sol );
|
||||||
|
/* Unpacking the @ of that one */
|
||||||
|
unpack( ad_sol );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template< class EOT > void peoPopEval< EOT > :: execute()
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Computing the fitness of the solution */
|
||||||
|
funcs[ num_func ]->operator()( sol );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template< class EOT > void peoPopEval< EOT > :: packResult()
|
||||||
|
{
|
||||||
|
/* Packing the fitness of the solution */
|
||||||
|
pack( sol.fitness() );
|
||||||
|
/* Packing the @ of the individual */
|
||||||
|
pack( ad_sol );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template< class EOT > void peoPopEval< EOT > :: unpackResult()
|
||||||
|
{
|
||||||
|
typename EOT :: Fitness fit;
|
||||||
|
|
||||||
|
/* Unpacking the computed fitness */
|
||||||
|
unpack( fit );
|
||||||
|
|
||||||
|
/* Unpacking the @ of the associated individual */
|
||||||
|
unpack( ad_sol );
|
||||||
|
|
||||||
|
|
||||||
|
/* Associating the fitness the local solution */
|
||||||
|
merge_eval( *ad_sol, fit );
|
||||||
|
|
||||||
|
progression[ ad_sol ].second--;
|
||||||
|
|
||||||
|
/* Notifying the container of the termination of the evaluation */
|
||||||
|
if ( !progression[ ad_sol ].second )
|
||||||
|
{
|
||||||
|
|
||||||
|
progression.erase( ad_sol );
|
||||||
|
}
|
||||||
|
|
||||||
|
total--;
|
||||||
|
if ( !total )
|
||||||
|
{
|
||||||
|
|
||||||
|
getOwner()->setActive();
|
||||||
|
resume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template< class EOT > void peoPopEval< EOT > :: notifySendingData()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template< class EOT > void peoPopEval< EOT > :: notifySendingAllResourceRequests()
|
||||||
|
{
|
||||||
|
getOwner()->setPassive();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -35,7 +35,7 @@ int main( int __argc, char** __argv )
|
||||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||||
peoEvalFunc<Indi> mainEval( f );
|
peoEvalFunc<Indi> mainEval( f );
|
||||||
peoParaPopEval <Indi> eval(mainEval);
|
peoPopEval <Indi> eval(mainEval);
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
eoRankingSelect<Indi> selectionStrategy;
|
eoRankingSelect<Indi> selectionStrategy;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ int main( int __argc, char** __argv )
|
||||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||||
|
|
||||||
peoEvalFunc<Indi> mainEval( f );
|
peoEvalFunc<Indi> mainEval( f );
|
||||||
peoParaPopEval <Indi> eval(mainEval);
|
peoPopEval <Indi> eval(mainEval);
|
||||||
|
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ int main( int __argc, char** __argv )
|
||||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||||
|
|
||||||
peoEvalFunc<Indi, double, const Indi& > plainEval(f);
|
peoEvalFunc<Indi, double, const Indi& > plainEval(f);
|
||||||
peoParaPopEval< Indi > eval(plainEval);
|
peoPopEval< Indi > eval(plainEval);
|
||||||
|
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ int main( int __argc, char** __argv )
|
||||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||||
peoEvalFunc<Indi, double, const Indi& > plainEval(f);
|
peoEvalFunc<Indi, double, const Indi& > plainEval(f);
|
||||||
peoParaPopEval< Indi > eval(plainEval);
|
peoPopEval< Indi > eval(plainEval);
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
|
|
@ -67,7 +67,7 @@ int main( int __argc, char** __argv )
|
||||||
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
||||||
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
||||||
peoEvalFunc<Indi, double, const Indi& > plainEval2(f);
|
peoEvalFunc<Indi, double, const Indi& > plainEval2(f);
|
||||||
peoParaPopEval< Indi > eval2(plainEval2);
|
peoPopEval< Indi > eval2(plainEval2);
|
||||||
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
|
||||||
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ int main( int __argc, char** __argv )
|
||||||
|
|
||||||
peo :: init (__argc, __argv);
|
peo :: init (__argc, __argv);
|
||||||
peoEvalFunc<Indi, double, const Indi& > plainEval(f);
|
peoEvalFunc<Indi, double, const Indi& > plainEval(f);
|
||||||
peoParaPopEval< Indi > eval(plainEval);
|
peoPopEval< Indi > eval(plainEval);
|
||||||
eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop);
|
eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop);
|
||||||
eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight);
|
eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight);
|
||||||
peoWrapper parallelPSO( psa, pop);
|
peoWrapper parallelPSO( psa, pop);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue