for tag
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1096 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
0499c8a022
commit
4c394ff220
14 changed files with 1 additions and 1493 deletions
|
|
@ -1,211 +0,0 @@
|
|||
#if !defined __peoAbstractDefs_h
|
||||
#define __peoAbstractDefs_h
|
||||
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "core/messaging.h"
|
||||
|
||||
|
||||
|
||||
template < typename Type > struct Entity;
|
||||
|
||||
struct AbstractEntity {
|
||||
|
||||
virtual ~AbstractEntity() {}
|
||||
|
||||
template < typename EntityType > operator EntityType& () {
|
||||
|
||||
return ( dynamic_cast< Entity< EntityType >& >( *this ) ).entity;
|
||||
}
|
||||
};
|
||||
|
||||
struct AbstractFunctor : virtual public AbstractEntity {
|
||||
|
||||
virtual ~AbstractFunctor() {}
|
||||
|
||||
virtual void operator()() {}
|
||||
};
|
||||
|
||||
struct AbstractUnaryFunctor : virtual public AbstractEntity {
|
||||
|
||||
virtual ~AbstractUnaryFunctor() {}
|
||||
|
||||
virtual void operator()( AbstractEntity& dataEntity ) {}
|
||||
};
|
||||
|
||||
struct AbstractBinaryFunctor : virtual public AbstractEntity {
|
||||
|
||||
virtual ~AbstractBinaryFunctor() {}
|
||||
|
||||
virtual void operator()( AbstractEntity& dataEntityA, AbstractEntity& dataEntityB ) {};
|
||||
};
|
||||
|
||||
|
||||
|
||||
template < typename EntityType > struct Entity : virtual public AbstractEntity {
|
||||
|
||||
Entity( EntityType& externalEntityRef ) : entity( externalEntityRef ) {}
|
||||
|
||||
EntityType& entity;
|
||||
};
|
||||
|
||||
template < typename FunctorType, typename DataType > struct FunctorEx : public Entity< DataType >, public AbstractFunctor {
|
||||
|
||||
FunctorEx( FunctorType& externalFunctorRef, DataType& externalDataRef )
|
||||
: externalFunctor( externalFunctorRef ), Entity< DataType >( externalDataRef ) {}
|
||||
|
||||
void operator()() {
|
||||
|
||||
externalFunctor( Entity< DataType > :: entity );
|
||||
}
|
||||
|
||||
FunctorType& externalFunctor;
|
||||
};
|
||||
|
||||
template < typename FunctorType > struct FunctorEx< FunctorType, void > : public Entity< AbstractEntity >, public AbstractFunctor {
|
||||
|
||||
FunctorEx( FunctorType& externalFunctorRef )
|
||||
: externalFunctor( externalFunctorRef ), Entity< AbstractEntity >( *this ) {}
|
||||
|
||||
void operator()() {
|
||||
|
||||
externalFunctor();
|
||||
}
|
||||
|
||||
FunctorType& externalFunctor;
|
||||
};
|
||||
|
||||
template < typename ReturnType, typename DataType > struct FnFunctorEx
|
||||
: public Entity< DataType >, public AbstractFunctor {
|
||||
|
||||
FnFunctorEx( ReturnType (*externalFunctorRef)( DataType& ), DataType& externalDataRef )
|
||||
: externalFunctor( externalFunctorRef ), Entity< DataType >( externalDataRef ) {}
|
||||
|
||||
void operator()() {
|
||||
|
||||
externalFunctor( Entity< DataType > :: entity );
|
||||
}
|
||||
|
||||
ReturnType (*externalFunctor)( DataType& );
|
||||
};
|
||||
|
||||
template < typename ReturnType > struct FnFunctorEx< ReturnType, void >
|
||||
: public Entity< AbstractEntity >, public AbstractFunctor {
|
||||
|
||||
FnFunctorEx( ReturnType (*externalFunctorRef)() )
|
||||
: externalFunctor( externalFunctorRef ), Entity< AbstractEntity >( *this ) {}
|
||||
|
||||
void operator()() {
|
||||
|
||||
externalFunctor();
|
||||
}
|
||||
|
||||
ReturnType (*externalFunctor)();
|
||||
};
|
||||
|
||||
|
||||
|
||||
template < typename FunctorType > struct UnaryFunctor : public Entity< FunctorType >, public AbstractUnaryFunctor {
|
||||
|
||||
UnaryFunctor( FunctorType& externalFunctorRef ) : Entity< FunctorType >( externalFunctorRef ) {}
|
||||
|
||||
void operator()( AbstractEntity& dataEntity ) {
|
||||
|
||||
Entity< FunctorType > :: entity( dataEntity );
|
||||
}
|
||||
};
|
||||
|
||||
template < typename ReturnType, typename DataType > struct UnaryFnFunctor
|
||||
: public Entity< AbstractEntity >, public AbstractUnaryFunctor {
|
||||
|
||||
UnaryFnFunctor( ReturnType (*externalFnRef)( DataType& ) ) : Entity< AbstractEntity >( *this ), externalFn( externalFnRef ) {
|
||||
}
|
||||
|
||||
void operator()( AbstractEntity& dataEntity ) {
|
||||
|
||||
externalFn( dataEntity );
|
||||
}
|
||||
|
||||
ReturnType (*externalFn)( DataType& );
|
||||
};
|
||||
|
||||
template < typename FunctorType > struct BinaryFunctor : public Entity< FunctorType >, public AbstractBinaryFunctor {
|
||||
|
||||
BinaryFunctor( FunctorType& externalFunctorRef ) : Entity< FunctorType >( externalFunctorRef ) {}
|
||||
|
||||
void operator()( AbstractEntity& dataEntityA, AbstractEntity& dataEntityB ) {
|
||||
|
||||
Entity< FunctorType > :: entity( dataEntityA, dataEntityB );
|
||||
}
|
||||
};
|
||||
|
||||
struct AbstractMsgTransferQueue : virtual public AbstractEntity {
|
||||
|
||||
virtual ~AbstractMsgTransferQueue() {}
|
||||
|
||||
virtual void pushMessage() {}
|
||||
virtual void popMessage() {}
|
||||
|
||||
virtual bool empty() { return true; }
|
||||
|
||||
virtual void packMessage() {}
|
||||
virtual void unpackMessage() {}
|
||||
};
|
||||
|
||||
template < typename EntityType > struct MsgTransferQueue : public Entity< EntityType >, public AbstractMsgTransferQueue {
|
||||
|
||||
MsgTransferQueue( EntityType& externalDataRef )
|
||||
: Entity< EntityType >( externalDataRef ) {
|
||||
|
||||
aggregationFunctor = new BinaryFunctor< AssignmentFunctor >( assignmentFunctor );
|
||||
}
|
||||
|
||||
template < typename FunctorType >
|
||||
MsgTransferQueue( EntityType& externalDataRef, FunctorType& externalFunctorRef )
|
||||
: Entity< EntityType >( externalDataRef ) {
|
||||
|
||||
aggregationFunctor = new BinaryFunctor< FunctorType >( externalFunctorRef );
|
||||
}
|
||||
|
||||
~MsgTransferQueue() { delete aggregationFunctor; }
|
||||
|
||||
void pushMessage() {
|
||||
|
||||
transferQueue.push( Entity< EntityType > :: entity );
|
||||
}
|
||||
|
||||
void popMessage() {
|
||||
|
||||
Entity< EntityType > message( transferQueue.front() );
|
||||
aggregationFunctor->operator()( *this, message );
|
||||
|
||||
transferQueue.pop();
|
||||
}
|
||||
|
||||
bool empty() { return transferQueue.empty(); }
|
||||
|
||||
void packMessage() {
|
||||
|
||||
pack( transferQueue.front() );
|
||||
transferQueue.pop();
|
||||
}
|
||||
|
||||
void unpackMessage() {
|
||||
|
||||
EntityType transferredData;
|
||||
unpack( transferredData );
|
||||
transferQueue.push( transferredData );
|
||||
}
|
||||
|
||||
struct AssignmentFunctor {
|
||||
void operator()( EntityType& A, EntityType& B ) { A = B; }
|
||||
} assignmentFunctor;
|
||||
|
||||
std::queue< EntityType > transferQueue;
|
||||
AbstractBinaryFunctor* aggregationFunctor;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -331,7 +331,6 @@
|
|||
#include "peoTransform.h"
|
||||
#include "peoEvalFunc.h"
|
||||
#include "peoPopEval.h"
|
||||
#include "peoMoeoPopEval.h"
|
||||
|
||||
/* Cooperative island model */
|
||||
#include "core/ring_topo.h"
|
||||
|
|
@ -341,8 +340,6 @@
|
|||
#include "peoData.h"
|
||||
#include "peoSyncIslandMig.h"
|
||||
#include "peoAsyncIslandMig.h"
|
||||
#include "peoAsyncDataTransfer.h"
|
||||
#include "peoSyncDataTransfer.h"
|
||||
|
||||
/* Synchronous multi-start model */
|
||||
#include "peoMultiStart.h"
|
||||
|
|
|
|||
|
|
@ -1,175 +0,0 @@
|
|||
#ifndef __peoAsyncDataTransfer_h
|
||||
#define __peoAsyncDataTransfer_h
|
||||
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include <utils/eoUpdater.h>
|
||||
|
||||
#include "core/peoAbstractDefs.h"
|
||||
|
||||
#include "core/messaging.h"
|
||||
|
||||
#include "core/topology.h"
|
||||
#include "core/thread.h"
|
||||
#include "core/cooperative.h"
|
||||
#include "core/peo_debug.h"
|
||||
|
||||
|
||||
class peoAsyncDataTransfer : public Cooperative, public eoUpdater {
|
||||
|
||||
public:
|
||||
|
||||
template< typename EndPointType >
|
||||
peoAsyncDataTransfer(
|
||||
|
||||
EndPointType& __endPoint,
|
||||
Topology& __topology
|
||||
|
||||
) : topology( __topology )
|
||||
{
|
||||
|
||||
source = new MsgTransferQueue< EndPointType >( __endPoint );
|
||||
destination = new MsgTransferQueue< EndPointType >( __endPoint );
|
||||
__topology.add( *this );
|
||||
}
|
||||
|
||||
template< typename EndPointType, typename FunctorType >
|
||||
peoAsyncDataTransfer(
|
||||
|
||||
EndPointType& __endPoint,
|
||||
Topology& __topology,
|
||||
FunctorType& externalFunctorRef
|
||||
|
||||
) : topology( __topology )
|
||||
{
|
||||
|
||||
source = new MsgTransferQueue< EndPointType >( __endPoint, externalFunctorRef );
|
||||
destination = new MsgTransferQueue< EndPointType >( __endPoint, externalFunctorRef );
|
||||
__topology.add( *this );
|
||||
}
|
||||
|
||||
template< typename SourceEndPointType, typename DestinationEndPointType >
|
||||
peoAsyncDataTransfer(
|
||||
|
||||
SourceEndPointType& __source,
|
||||
DestinationEndPointType& __destination,
|
||||
Topology& __topology
|
||||
|
||||
) : topology( __topology )
|
||||
{
|
||||
|
||||
source = new MsgTransferQueue< SourceEndPointType >( __source );
|
||||
destination = new MsgTransferQueue< DestinationEndPointType >( __destination );
|
||||
__topology.add( *this );
|
||||
}
|
||||
|
||||
template< typename SourceEndPointType, typename DestinationEndPointType, typename FunctorType >
|
||||
peoAsyncDataTransfer(
|
||||
|
||||
SourceEndPointType& __source,
|
||||
DestinationEndPointType& __destination,
|
||||
Topology& __topology,
|
||||
FunctorType& externalFunctorRef
|
||||
|
||||
) : topology( __topology )
|
||||
{
|
||||
|
||||
source = new MsgTransferQueue< SourceEndPointType >( __source, externalFunctorRef );
|
||||
destination = new MsgTransferQueue< DestinationEndPointType >( __destination, externalFunctorRef );
|
||||
__topology.add( *this );
|
||||
}
|
||||
|
||||
~peoAsyncDataTransfer() {
|
||||
delete source;
|
||||
delete destination;
|
||||
}
|
||||
|
||||
|
||||
void operator()();
|
||||
|
||||
void pack();
|
||||
void unpack();
|
||||
|
||||
void packSynchronizeReq();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void sendData();
|
||||
void receiveData();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// the neighboring topology
|
||||
Topology& topology;
|
||||
|
||||
// source and destination end-points
|
||||
AbstractMsgTransferQueue* source;
|
||||
AbstractMsgTransferQueue* destination;
|
||||
|
||||
std :: queue< Cooperative* > coop_em;
|
||||
};
|
||||
|
||||
|
||||
void peoAsyncDataTransfer :: pack() {
|
||||
|
||||
lock ();
|
||||
|
||||
::pack( coop_em.front()->getKey() );
|
||||
source->packMessage();
|
||||
coop_em.pop();
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
void peoAsyncDataTransfer :: unpack() {
|
||||
|
||||
lock ();
|
||||
destination->unpackMessage();
|
||||
unlock();
|
||||
}
|
||||
|
||||
void peoAsyncDataTransfer :: packSynchronizeReq() {
|
||||
}
|
||||
|
||||
void peoAsyncDataTransfer :: sendData() {
|
||||
|
||||
std :: vector< Cooperative* > in, out;
|
||||
topology.setNeighbors( this, in, out );
|
||||
|
||||
for ( unsigned i = 0; i < out.size(); i++ ) {
|
||||
|
||||
source->pushMessage();
|
||||
|
||||
coop_em.push( out[i] );
|
||||
send( out[i] );
|
||||
|
||||
printDebugMessage( "peoAsyncDataTransfer: sending data." );
|
||||
}
|
||||
}
|
||||
|
||||
void peoAsyncDataTransfer :: receiveData() {
|
||||
|
||||
lock ();
|
||||
{
|
||||
|
||||
while ( !( destination->empty() ) ) {
|
||||
|
||||
printDebugMessage( "peoAsyncDataTransfer: received data." );
|
||||
destination->popMessage();
|
||||
printDebugMessage( "peoAsyncDataTransfer: done reading data." );
|
||||
}
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
|
||||
void peoAsyncDataTransfer :: operator()() {
|
||||
|
||||
sendData(); // sending data
|
||||
receiveData(); // receiving data
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,265 +0,0 @@
|
|||
/*
|
||||
* <peoMoeoPopEval.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
|
||||
* (C) OPAC Team, LIFL, 2002-2008
|
||||
*
|
||||
* 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,
|
||||
* 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 __peoMoeoPopEval_h
|
||||
#define __peoMoeoPopEval_h
|
||||
|
||||
#include <queue>
|
||||
#include <eoEvalFunc.h>
|
||||
|
||||
#include "core/messaging.h"
|
||||
#include "core/peo_debug.h"
|
||||
#include "peoAggEvalFunc.h"
|
||||
#include "peoNoAggEvalFunc.h"
|
||||
|
||||
//! @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>
|
||||
{
|
||||
|
||||
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
|
||||
peoMoeoPopEval( 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.
|
||||
peoMoeoPopEval( 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);
|
||||
|
||||
//! @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
|
||||
//! 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:
|
||||
//! @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;
|
||||
};
|
||||
|
||||
|
||||
template< class EOT > peoMoeoPopEval< EOT > :: peoMoeoPopEval( eoEvalFunc< EOT >& __eval_func ) :
|
||||
|
||||
funcs( one_func ), merge_eval( no_merge_eval )
|
||||
{
|
||||
|
||||
one_func.push_back( &__eval_func );
|
||||
}
|
||||
|
||||
|
||||
template< class EOT > peoMoeoPopEval< EOT > :: peoMoeoPopEval(
|
||||
|
||||
const std :: vector< eoEvalFunc< EOT >* >& __funcs,
|
||||
peoAggEvalFunc< EOT >& __merge_eval
|
||||
|
||||
) : funcs( __funcs ), merge_eval( __merge_eval )
|
||||
{}
|
||||
|
||||
template< class EOT > void peoMoeoPopEval< EOT >::operator()(eoPop< EOT >& __dummy, eoPop< EOT >& __pop )
|
||||
{
|
||||
this->operator()(__pop);
|
||||
}
|
||||
|
||||
template< class EOT > void peoMoeoPopEval< 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 peoMoeoPopEval< EOT > :: packData()
|
||||
{
|
||||
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 peoMoeoPopEval< EOT > :: unpackData()
|
||||
{
|
||||
unpack( num_func );
|
||||
/* Unpacking the solution */
|
||||
unpack( sol );
|
||||
/* Unpacking the @ of that one */
|
||||
unpack( ad_sol );
|
||||
}
|
||||
|
||||
|
||||
template< class EOT > void peoMoeoPopEval< EOT > :: execute()
|
||||
{
|
||||
|
||||
/* Computing the fitness of the solution */
|
||||
funcs[ num_func ]->operator()( sol );
|
||||
}
|
||||
|
||||
|
||||
template< class EOT > void peoMoeoPopEval< EOT > :: packResult()
|
||||
{
|
||||
/* Packing the fitness of the solution */
|
||||
std::vector < double > object;
|
||||
unsigned len;
|
||||
object=sol.objectiveVector();
|
||||
len=object.size();
|
||||
pack (len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
pack (object[i]);
|
||||
|
||||
/* Packing the @ of the individual */
|
||||
pack( ad_sol );
|
||||
}
|
||||
|
||||
|
||||
template< class EOT > void peoMoeoPopEval< EOT > :: unpackResult()
|
||||
{
|
||||
/* Unpacking the computed fitness */
|
||||
unsigned len;
|
||||
std::vector < double > object;
|
||||
|
||||
unpack(len);
|
||||
object.resize(len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
unpack (object[i]);
|
||||
/* Unpacking the @ of the associated individual */
|
||||
unpack( ad_sol );
|
||||
|
||||
|
||||
/* Associating the fitness the local solution */
|
||||
ad_sol->objectiveVector(object);
|
||||
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 peoMoeoPopEval< EOT > :: notifySendingData()
|
||||
{}
|
||||
|
||||
|
||||
template< class EOT > void peoMoeoPopEval< EOT > :: notifySendingAllResourceRequests()
|
||||
{
|
||||
getOwner()->setPassive();
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,249 +0,0 @@
|
|||
#ifndef __peoSyncDataTransfer_h
|
||||
#define __peoSyncDataTransfer_h
|
||||
|
||||
|
||||
#include <queue>
|
||||
#include <cassert>
|
||||
|
||||
#include <utils/eoUpdater.h>
|
||||
|
||||
#include "core/peoAbstractDefs.h"
|
||||
|
||||
#include "core/messaging.h"
|
||||
#include "core/eoPop_mesg.h"
|
||||
#include "core/eoVector_mesg.h"
|
||||
|
||||
#include "core/topology.h"
|
||||
#include "core/thread.h"
|
||||
#include "core/cooperative.h"
|
||||
#include "core/peo_debug.h"
|
||||
|
||||
#include "rmc/mpi/synchron.h"
|
||||
|
||||
|
||||
class peoSyncDataTransfer : public Cooperative, public eoUpdater
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
template< typename EndPointType >
|
||||
peoSyncDataTransfer(
|
||||
|
||||
EndPointType& __endPoint,
|
||||
Topology& __topology
|
||||
|
||||
) : topology( __topology )
|
||||
{
|
||||
|
||||
source = new MsgTransferQueue< EndPointType >( __endPoint );
|
||||
destination = new MsgTransferQueue< EndPointType >( __endPoint );
|
||||
__topology.add( *this );
|
||||
|
||||
sem_init( &sync, 0, 0 );
|
||||
}
|
||||
|
||||
template< typename EndPointType, typename FunctorType >
|
||||
peoSyncDataTransfer(
|
||||
|
||||
EndPointType& __endPoint,
|
||||
Topology& __topology,
|
||||
FunctorType& externalFunctorRef
|
||||
|
||||
) : topology( __topology )
|
||||
{
|
||||
|
||||
source = new MsgTransferQueue< EndPointType >( __endPoint, externalFunctorRef );
|
||||
destination = new MsgTransferQueue< EndPointType >( __endPoint, externalFunctorRef );
|
||||
__topology.add( *this );
|
||||
|
||||
sem_init( &sync, 0, 0 );
|
||||
}
|
||||
|
||||
template< typename SourceEndPointType, typename DestinationEndPointType >
|
||||
peoSyncDataTransfer(
|
||||
|
||||
SourceEndPointType& __source,
|
||||
DestinationEndPointType& __destination,
|
||||
Topology& __topology
|
||||
|
||||
) : topology( __topology )
|
||||
{
|
||||
|
||||
source = new MsgTransferQueue< SourceEndPointType >( __source );
|
||||
destination = new MsgTransferQueue< DestinationEndPointType >( __destination );
|
||||
__topology.add( *this );
|
||||
|
||||
sem_init( &sync, 0, 0 );
|
||||
}
|
||||
|
||||
template< typename SourceEndPointType, typename DestinationEndPointType, typename FunctorType >
|
||||
peoSyncDataTransfer(
|
||||
|
||||
SourceEndPointType& __source,
|
||||
DestinationEndPointType& __destination,
|
||||
Topology& __topology,
|
||||
FunctorType& externalFunctorRef
|
||||
|
||||
) : topology( __topology )
|
||||
{
|
||||
|
||||
source = new MsgTransferQueue< SourceEndPointType >( __source, externalFunctorRef );
|
||||
destination = new MsgTransferQueue< DestinationEndPointType >( __destination, externalFunctorRef );
|
||||
__topology.add( *this );
|
||||
|
||||
sem_init( &sync, 0, 0 );
|
||||
}
|
||||
|
||||
|
||||
void operator()();
|
||||
|
||||
void pack();
|
||||
|
||||
void unpack();
|
||||
|
||||
void packSynchronizeReq();
|
||||
|
||||
void notifySending();
|
||||
|
||||
void notifyReceiving();
|
||||
|
||||
void notifySendingSyncReq();
|
||||
|
||||
void notifySynchronized();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void sendData();
|
||||
void receiveData();
|
||||
|
||||
Topology& topology; // neighboring topology
|
||||
|
||||
// source and destination end-points
|
||||
AbstractMsgTransferQueue* source;
|
||||
AbstractMsgTransferQueue* destination;
|
||||
|
||||
std :: queue< Cooperative* > coop_em;
|
||||
|
||||
sem_t sync;
|
||||
|
||||
bool standbyTransfer;
|
||||
|
||||
std :: vector< Cooperative* > in, out, all;
|
||||
unsigned nbTransfersIn, nbTransfersOut;
|
||||
};
|
||||
|
||||
|
||||
void peoSyncDataTransfer :: pack() {
|
||||
|
||||
::pack( coop_em.front()->getKey() );
|
||||
source->packMessage();
|
||||
coop_em.pop();
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: unpack() {
|
||||
|
||||
destination->unpackMessage();
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: packSynchronizeReq() {
|
||||
|
||||
packSynchronRequest( all );
|
||||
}
|
||||
|
||||
extern void wakeUpCommunicator();
|
||||
extern int getNodeRank();
|
||||
|
||||
void peoSyncDataTransfer :: sendData() {
|
||||
|
||||
for ( unsigned i = 0; i < out.size(); i ++ ) {
|
||||
|
||||
source->pushMessage();
|
||||
|
||||
coop_em.push( out[ i ] );
|
||||
send( out[ i ]);
|
||||
|
||||
printDebugMessage( "peoSyncDataTransfer: sending data." );
|
||||
}
|
||||
|
||||
wakeUpCommunicator();
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: receiveData() {
|
||||
|
||||
assert( !( destination->empty() ) );
|
||||
|
||||
while ( !( destination->empty() ) ) {
|
||||
|
||||
printDebugMessage( "peoSyncDataTransfer: received data." );
|
||||
destination->popMessage();
|
||||
printDebugMessage( "peoSyncDataTransfer: done extracting received data." );
|
||||
}
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: operator()() {
|
||||
|
||||
standbyTransfer = false;
|
||||
nbTransfersIn = nbTransfersOut = 0;
|
||||
|
||||
topology.setNeighbors( this, in, out ); all = topology;
|
||||
|
||||
synchronizeCoopEx(); stop();
|
||||
|
||||
// sending data out
|
||||
sendData();
|
||||
// synchronizing
|
||||
sem_wait( &sync );
|
||||
// receiving data in
|
||||
receiveData();
|
||||
|
||||
synchronizeCoopEx(); stop();
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: notifySending() {
|
||||
|
||||
nbTransfersOut++;
|
||||
|
||||
printDebugMessage( "peoSyncDataTransfer: notified of the completion of a transfer round." );
|
||||
|
||||
getOwner()->setActive();
|
||||
if ( nbTransfersOut == out.size() && nbTransfersIn < in.size() ) {
|
||||
getOwner()->setPassive();
|
||||
}
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: notifyReceiving() {
|
||||
|
||||
nbTransfersIn++;
|
||||
printDebugMessage( "peoSyncIslandMig: notified of incoming data." );
|
||||
|
||||
if ( standbyTransfer ) {
|
||||
getOwner()->setActive();
|
||||
if ( nbTransfersOut == out.size() && nbTransfersIn < in.size() )
|
||||
getOwner()->setPassive();
|
||||
}
|
||||
|
||||
if ( nbTransfersIn == in.size() ) {
|
||||
|
||||
printDebugMessage( "peoSyncIslandMig: finished collecting incoming data." );
|
||||
sem_post( &sync );
|
||||
}
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: notifySendingSyncReq () {
|
||||
|
||||
getOwner()->setPassive();
|
||||
printDebugMessage( "peoSyncIslandMig: synchronization request sent." );
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: notifySynchronized () {
|
||||
|
||||
printDebugMessage( "peoSyncIslandMig: cooperators synchronized." );
|
||||
|
||||
standbyTransfer = true;
|
||||
getOwner()->setActive();
|
||||
resume();
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -14,6 +14,6 @@ SET(FLOWSHOP_BIN_DIR "${MOEO_BIN_DIR}/tutorial/examples/flowshop" CACHE PATH "Fl
|
|||
### 2) Where must cmake go now ?
|
||||
######################################################################################
|
||||
|
||||
SUBDIRS(examples Lesson1 Lesson2 Lesson3 Lesson4 Lesson5 Lesson6)
|
||||
SUBDIRS(examples Lesson1 Lesson2 Lesson3 Lesson4)
|
||||
|
||||
######################################################################################
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
|
||||
######################################################################################
|
||||
### 0) Set the compiler and define targets to easily run the lessons
|
||||
######################################################################################
|
||||
|
||||
SET (CMAKE_CXX_COMPILER mpicxx)
|
||||
|
||||
ADD_CUSTOM_TARGET(install DEPENDS ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson5/param ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson5/schema.xml)
|
||||
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET install
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS -E copy_if_different
|
||||
${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson5/param
|
||||
${ParadisEO-PEO_BINARY_DIR}/tutorial/Lesson5)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET install
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS -E copy_if_different
|
||||
${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson5/schema.xml
|
||||
${ParadisEO-PEO_BINARY_DIR}/tutorial/Lesson5)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src ${MOEO_SRC_DIR}/src ${MO_SRC_DIR}/src ${ParadisEO-PEO_SOURCE_DIR}/src)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
LINK_DIRECTORIES(${EO_BIN_DIR}/lib ${ParadisEO-PEO_BINARY_DIR}/lib)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your target(s): just an executable here
|
||||
######################################################################################
|
||||
|
||||
ADD_EXECUTABLE(ea main.cpp)
|
||||
ADD_DEPENDENCIES(ea peo rmc_mpi)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 4) Optionnal: define properties
|
||||
######################################################################################
|
||||
|
||||
SET(Lesson5_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(ea PROPERTIES VERSION "${Lesson5_VERSION}")
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 5) Link the librairies
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(ea ${XML2_LIBS} peo rmc_mpi eo eoutils peo)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
|
@ -1,253 +0,0 @@
|
|||
#include <peo>
|
||||
#include <peoAsyncDataTransfer.h>
|
||||
#include <peoSyncDataTransfer.h>
|
||||
#define SIZE 10
|
||||
#define DEF_DOMAIN 100
|
||||
#define POP_SIZE 100
|
||||
#define SELECT_RATE 0.8
|
||||
#define NB_GEN 1
|
||||
#define XOVER_P 0.75
|
||||
#define MUT_P 0.05
|
||||
#define MIGRATIONS_AT_N_GENERATIONS 5
|
||||
#define NUMBER_OF_MIGRANTS 10
|
||||
|
||||
struct Representation : public eoVector< eoMinimizingFitness, double > {
|
||||
|
||||
Representation() { resize( SIZE ); }
|
||||
};
|
||||
|
||||
struct Init : public eoInit< Representation > {
|
||||
|
||||
void operator()( Representation& rep ) {
|
||||
|
||||
for ( int i = 0; i < SIZE; i++ ) {
|
||||
rep[ i ] = (rng.uniform() - 0.5) * DEF_DOMAIN;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct Eval : public eoEvalFunc< Representation > {
|
||||
|
||||
void operator()( Representation& rep ) {
|
||||
|
||||
double fitnessValue = 0.0;
|
||||
for ( int i = 0; i < SIZE; i++ ) {
|
||||
|
||||
fitnessValue += pow( rep[ i ], 2.0 );
|
||||
}
|
||||
|
||||
rep.fitness( fitnessValue );
|
||||
}
|
||||
};
|
||||
|
||||
struct MutationOp : public eoMonOp< Representation > {
|
||||
|
||||
bool operator()( Representation& rep ) {
|
||||
|
||||
unsigned int pos = (unsigned int)( rng.uniform() * SIZE );
|
||||
rep[ pos ] = (rng.uniform() - 0.5) * DEF_DOMAIN;
|
||||
|
||||
rep.invalidate();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct XoverOp : public eoQuadOp< Representation > {
|
||||
|
||||
bool operator()( Representation& repA, Representation& repB ) {
|
||||
|
||||
static Representation offA, offB;
|
||||
double lambda = rng.uniform();
|
||||
|
||||
for ( int i = 0; i < SIZE; i++ ) {
|
||||
|
||||
offA[ i ] = lambda * repA[ i ] + ( 1.0 - lambda ) * repB[ i ];
|
||||
offB[ i ] = lambda * repB[ i ] + ( 1.0 - lambda ) * repA[ i ];
|
||||
}
|
||||
|
||||
repA = offA; repB = offB;
|
||||
|
||||
repA.invalidate();
|
||||
repB.invalidate();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
void pack( const Representation& rep ) {
|
||||
|
||||
if ( rep.invalid() ) ::pack( (unsigned int)0 );
|
||||
else {
|
||||
::pack( (unsigned int)1 );
|
||||
::pack( (double)(rep.fitness()) );
|
||||
}
|
||||
|
||||
for ( unsigned int index = 0; index < SIZE; index++ ) {
|
||||
::pack( (double)rep[ index ] );
|
||||
}
|
||||
}
|
||||
|
||||
void unpack( Representation& rep ) {
|
||||
|
||||
eoScalarFitness<double, std::greater<double> > fitness;
|
||||
unsigned int validFitness;
|
||||
|
||||
unpack( validFitness );
|
||||
if ( validFitness ) {
|
||||
|
||||
double fitnessValue; ::unpack( fitnessValue );
|
||||
rep.fitness( fitnessValue );
|
||||
}
|
||||
else {
|
||||
rep.invalidate();
|
||||
}
|
||||
|
||||
double value;
|
||||
for ( unsigned int index = 0; index < SIZE; index++ ) {
|
||||
::unpack( value );
|
||||
rep[ index ] = value;
|
||||
}
|
||||
}
|
||||
|
||||
int main( int __argc, char** __argv ) {
|
||||
|
||||
|
||||
rng.reseed( time( NULL ) );
|
||||
srand( time( NULL ) );
|
||||
|
||||
peo::init( __argc, __argv );
|
||||
|
||||
|
||||
eoParser parser ( __argc, __argv );
|
||||
|
||||
eoValueParam < unsigned int > nbGenerations( NB_GEN, "maxGen");
|
||||
parser.processParam ( nbGenerations );
|
||||
|
||||
eoValueParam < double > selectionRate( SELECT_RATE, "select");
|
||||
parser.processParam ( selectionRate );
|
||||
|
||||
|
||||
RingTopology ring,topo;
|
||||
unsigned int dataA, dataB, dataC;
|
||||
|
||||
dataA = 1;
|
||||
dataB = 5;
|
||||
dataC = 10;
|
||||
|
||||
peoSyncDataTransfer dataTransfer( dataA, ring );
|
||||
peoSyncDataTransfer dataTransferb( dataB, ring );
|
||||
peoSyncDataTransfer dataTransferc( dataC, ring );
|
||||
|
||||
|
||||
Init init;
|
||||
Eval eval;
|
||||
eoPop< Representation > pop( POP_SIZE, init );
|
||||
MutationOp mut;
|
||||
XoverOp xover;
|
||||
eoSGATransform< Representation > transform( xover, XOVER_P, mut, MUT_P );
|
||||
eoStochTournamentSelect< Representation > select;
|
||||
eoSelectMany< Representation > selectN( select, selectionRate.value() );
|
||||
eoSSGAStochTournamentReplacement< Representation > replace( 1.0 );
|
||||
eoWeakElitistReplacement< Representation > elitReplace( replace );
|
||||
eoGenContinue< Representation > cont( nbGenerations.value() );
|
||||
eoCheckPoint< Representation > checkpoint( cont );
|
||||
eoEasyEA< Representation > algo( checkpoint, eval, selectN, transform, elitReplace );
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------
|
||||
// MIGRATION CONTEXT DEFINITION
|
||||
|
||||
eoPeriodicContinue< Representation > mig_conti( MIGRATIONS_AT_N_GENERATIONS );
|
||||
eoContinuator<Representation> mig_cont(mig_conti,pop);
|
||||
eoRandomSelect<Representation> mig_select_one;
|
||||
eoSelector <Representation, eoPop<Representation> > mig_select (mig_select_one,NUMBER_OF_MIGRANTS,pop);
|
||||
eoPlusReplacement<Representation> replace_one;
|
||||
eoReplace <Representation, eoPop<Representation> > mig_replace (replace_one,pop);
|
||||
// peoSyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig(MIGRATIONS_AT_N_GENERATIONS,mig_select,mig_replace,topo);
|
||||
peoAsyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig(mig_cont,mig_select,mig_replace,topo);
|
||||
checkpoint.add( mig );
|
||||
//-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
eoPop< Representation > pop2( POP_SIZE, init );
|
||||
eoSGATransform< Representation > transform2( xover, XOVER_P, mut, MUT_P );
|
||||
eoStochTournamentSelect< Representation > select2;
|
||||
eoSelectMany< Representation > selectN2( select2, selectionRate.value() );
|
||||
eoSSGAStochTournamentReplacement< Representation > replace2( 1.0 );
|
||||
eoWeakElitistReplacement< Representation > elitReplace2( replace2 );
|
||||
eoGenContinue< Representation > cont2( nbGenerations.value() );
|
||||
eoCheckPoint< Representation > checkpoint2( cont2 );
|
||||
eoEasyEA< Representation > algo2( checkpoint2, eval, selectN2, transform2, elitReplace2 );
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------
|
||||
// MIGRATION CONTEXT DEFINITION
|
||||
|
||||
eoPeriodicContinue< Representation > mig_conti2( MIGRATIONS_AT_N_GENERATIONS );
|
||||
eoContinuator<Representation> mig_cont2(mig_conti2,pop2);
|
||||
eoRandomSelect<Representation> mig_select_one2;
|
||||
eoSelector <Representation, eoPop<Representation> > mig_select2 (mig_select_one2,NUMBER_OF_MIGRANTS,pop2);
|
||||
eoPlusReplacement<Representation> replace_one2;
|
||||
eoReplace <Representation, eoPop<Representation> > mig_replace2 (replace_one2,pop2);
|
||||
// peoSyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig2(MIGRATIONS_AT_N_GENERATIONS,mig_select2,mig_replace2,topo);
|
||||
peoAsyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig2(mig_cont2,mig_select2,mig_replace2,topo);
|
||||
checkpoint2.add( mig2 );
|
||||
//-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
eoPop< Representation > pop3( POP_SIZE, init );
|
||||
eoSGATransform< Representation > transform3( xover, XOVER_P, mut, MUT_P );
|
||||
eoStochTournamentSelect< Representation > select3;
|
||||
eoSelectMany< Representation > selectN3( select3, selectionRate.value() );
|
||||
eoSSGAStochTournamentReplacement< Representation > replace3( 1.0 );
|
||||
eoWeakElitistReplacement< Representation > elitReplace3( replace3 );
|
||||
eoGenContinue< Representation > cont3( nbGenerations.value() );
|
||||
eoCheckPoint< Representation > checkpoint3( cont3 );
|
||||
eoEasyEA< Representation > algo3( checkpoint3, eval, selectN3, transform3, elitReplace3 );
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------
|
||||
// MIGRATION CONTEXT DEFINITION
|
||||
|
||||
eoPeriodicContinue< Representation > mig_conti3( MIGRATIONS_AT_N_GENERATIONS );
|
||||
eoContinuator<Representation> mig_cont3(mig_conti3,pop3);
|
||||
eoRandomSelect<Representation> mig_select_one3;
|
||||
eoSelector <Representation, eoPop<Representation> > mig_select3 (mig_select_one3,NUMBER_OF_MIGRANTS,pop3);
|
||||
eoPlusReplacement<Representation> replace_one3;
|
||||
eoReplace <Representation, eoPop<Representation> > mig_replace3 (replace_one3,pop3);
|
||||
// peoSyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig3(MIGRATIONS_AT_N_GENERATIONS,mig_select3,mig_replace3,topo);
|
||||
peoAsyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig3(mig_cont3,mig_select3,mig_replace3,topo);
|
||||
|
||||
checkpoint3.add( mig3 );
|
||||
//-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
peoWrapper algoPar( algo, pop );
|
||||
mig.setOwner( algoPar );
|
||||
checkpoint.add( dataTransfer );
|
||||
dataTransfer.setOwner( algoPar );
|
||||
|
||||
|
||||
peoWrapper algoPar2( algo2, pop2 );
|
||||
mig2.setOwner( algoPar2 );
|
||||
checkpoint2.add( dataTransferb );
|
||||
dataTransferb.setOwner( algoPar2 );
|
||||
|
||||
|
||||
peoWrapper algoPar3( algo3, pop3 );
|
||||
mig3.setOwner( algoPar3 );
|
||||
checkpoint3.add( dataTransferc );
|
||||
dataTransferc.setOwner( algoPar3 );
|
||||
|
||||
peo::run();
|
||||
peo::finalize();
|
||||
|
||||
if ( getNodeRank() == 1 )
|
||||
std::cout << "A: " << dataA << std::endl;
|
||||
if ( getNodeRank() == 2 )
|
||||
std::cout << "B: " << dataB << std::endl;
|
||||
if ( getNodeRank() == 3 )
|
||||
std::cout << "C: " << dataC << std::endl;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
###### Param ######
|
||||
--maxGen=1
|
||||
--select=0.8
|
||||
|
||||
## miscallenous parameters
|
||||
|
||||
--debug=false
|
||||
|
||||
## deployment schema
|
||||
|
||||
--schema=schema.xml
|
||||
|
||||
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<schema>
|
||||
<group scheduler="0">
|
||||
<node name="0" num_workers="0">
|
||||
</node>
|
||||
|
||||
<node name="1" num_workers="0">
|
||||
<runner>1</runner>
|
||||
|
||||
|
||||
</node>
|
||||
|
||||
<node name="2" num_workers="1">
|
||||
<runner>2</runner>
|
||||
</node>
|
||||
<node name="3" num_workers="1">
|
||||
<runner>3</runner>
|
||||
</node>
|
||||
|
||||
</group>
|
||||
</schema>
|
||||
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
|
||||
######################################################################################
|
||||
### 0) Set the compiler and define targets to easily run the lessons
|
||||
######################################################################################
|
||||
|
||||
SET (CMAKE_CXX_COMPILER mpicxx)
|
||||
|
||||
ADD_CUSTOM_TARGET(install DEPENDS ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson6/param ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson6/schema.xml)
|
||||
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET install
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS -E copy_if_different
|
||||
${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson6/param
|
||||
${ParadisEO-PEO_BINARY_DIR}/tutorial/Lesson6)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET install
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS -E copy_if_different
|
||||
${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson6/schema.xml
|
||||
${ParadisEO-PEO_BINARY_DIR}/tutorial/Lesson6)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src ${MOEO_SRC_DIR}/src ${MO_SRC_DIR}/src ${ParadisEO-PEO_SOURCE_DIR}/src ${TSP_SRC_DIR})
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
LINK_DIRECTORIES(${EO_BIN_DIR}/lib ${ParadisEO-PEO_BINARY_DIR}/lib ${TSP_BINARY_DIR}/lib)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your target(s): just an executable here
|
||||
######################################################################################
|
||||
|
||||
ADD_EXECUTABLE(ea main.cpp)
|
||||
ADD_DEPENDENCIES(ea peo rmc_mpi)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 4) Optionnal: define properties
|
||||
######################################################################################
|
||||
|
||||
SET(Lesson6_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(ea PROPERTIES VERSION "${Lesson6_VERSION}")
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 5) Link the librairies
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(ea ${XML2_LIBS} tsp peo rmc_mpi eo eoutils peo)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
#include <peo>
|
||||
|
||||
#include <peoAsyncDataTransfer.h>
|
||||
#include <peoSyncDataTransfer.h>
|
||||
|
||||
#include "route.h"
|
||||
#include "route_init.h"
|
||||
#include "route_eval.h"
|
||||
#include "order_xover.h"
|
||||
#include "city_swap.h"
|
||||
#include "param.h"
|
||||
|
||||
|
||||
|
||||
#define POP_SIZE 10
|
||||
#define NUM_GEN 100
|
||||
#define CROSS_RATE 1.0
|
||||
#define MUT_RATE 0.01
|
||||
|
||||
|
||||
struct CoSearch
|
||||
{
|
||||
|
||||
CoSearch(
|
||||
eoPop< Route >& A, eoPop< Route >& B,
|
||||
peoAsyncDataTransfer& asyncTransferA, peoAsyncDataTransfer& asyncTransferB
|
||||
)
|
||||
: transferA( A ), transferB( B ),
|
||||
asyncDataTransferA( asyncTransferA ), asyncDataTransferB( asyncTransferB ) {
|
||||
}
|
||||
|
||||
void operator()() {
|
||||
|
||||
for ( unsigned int index = 0; index < 100; index++ ) {
|
||||
|
||||
asyncDataTransferA();
|
||||
asyncDataTransferB();
|
||||
|
||||
eoPop< Route > intermed;
|
||||
intermed = transferA;
|
||||
transferA = transferB;
|
||||
transferB = intermed;
|
||||
}
|
||||
}
|
||||
|
||||
eoPop< Route >& transferA;
|
||||
eoPop< Route >& transferB;
|
||||
|
||||
peoAsyncDataTransfer& asyncDataTransferA;
|
||||
peoAsyncDataTransfer& asyncDataTransferB;
|
||||
};
|
||||
|
||||
|
||||
struct PushBackAggregation {
|
||||
|
||||
void operator()( eoPop< Route >& A, eoPop< Route >& B ) {
|
||||
|
||||
for ( unsigned int index = 0; index < B.size(); index++ ) {
|
||||
|
||||
A.push_back( B[ index ] );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main( int __argc, char** __argv ) {
|
||||
|
||||
peo :: init( __argc, __argv );
|
||||
|
||||
loadParameters( __argc, __argv );
|
||||
|
||||
RouteInit route_init;
|
||||
RouteEval full_eval;
|
||||
OrderXover crossover;
|
||||
CitySwap mutation;
|
||||
eoPop< Route > population( POP_SIZE, route_init );
|
||||
eoGenContinue< Route > eaCont( NUM_GEN );
|
||||
eoCheckPoint< Route > eaCheckpointContinue( eaCont );
|
||||
eoRankingSelect< Route > selectionStrategy;
|
||||
eoSelectNumber< Route > eaSelect( selectionStrategy, POP_SIZE );
|
||||
eoSGATransform< Route > transformA( crossover, CROSS_RATE, mutation, MUT_RATE );
|
||||
eoPlusReplacement< Route > eaReplace;
|
||||
RingTopology ring;
|
||||
eoPlusReplacement< Route > transferReplace;
|
||||
peoAsyncDataTransfer asyncEAEndPoint( population, population, ring, transferReplace );
|
||||
eaCheckpointContinue.add( asyncEAEndPoint );
|
||||
eoEasyEA< Route > eaAlg( eaCheckpointContinue, full_eval, eaSelect, transformA, eaReplace );
|
||||
peoWrapper paraEAAlg( eaAlg, population );
|
||||
asyncEAEndPoint.setOwner( paraEAAlg );
|
||||
|
||||
eoPop< Route > populationB( POP_SIZE, route_init );
|
||||
eoGenContinue< Route > eaContB( NUM_GEN );
|
||||
eoCheckPoint< Route > eaCheckpointContinueB( eaContB );
|
||||
eoRankingSelect< Route > selectionStrategyB;
|
||||
eoSelectNumber< Route > eaSelectB( selectionStrategyB, POP_SIZE );
|
||||
RingTopology ringB;
|
||||
eoPlusReplacement< Route > transferReplaceB;
|
||||
peoAsyncDataTransfer asyncEAEndPointB( populationB, populationB, ringB, transferReplaceB );
|
||||
eaCheckpointContinueB.add( asyncEAEndPointB );
|
||||
eoSGATransform< Route > transformB ( crossover, CROSS_RATE, mutation, MUT_RATE );
|
||||
eoEasyEA< Route > eaAlgB( eaCheckpointContinueB, full_eval, eaSelectB, transformB, eaReplace );
|
||||
peoWrapper paraEAAlgB( eaAlgB, populationB );
|
||||
asyncEAEndPointB.setOwner( paraEAAlgB );
|
||||
|
||||
|
||||
eoPop< Route > A, B;
|
||||
PushBackAggregation pushBackA, pushBackB;
|
||||
|
||||
peoAsyncDataTransfer coSearchEndPointA( A, A, ring, pushBackA );
|
||||
peoAsyncDataTransfer coSearchEndPointB( B, B, ringB, pushBackB );
|
||||
|
||||
CoSearch coSearch( A, B, coSearchEndPointA, coSearchEndPointB );
|
||||
peoWrapper paraCoSearch( coSearch );
|
||||
coSearchEndPointA.setOwner( paraCoSearch );
|
||||
coSearchEndPointB.setOwner( paraCoSearch );
|
||||
|
||||
|
||||
|
||||
peo::run();
|
||||
peo::finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
###### Param ######
|
||||
--maxGen=1
|
||||
--select=0.8
|
||||
|
||||
## miscallenous parameters
|
||||
|
||||
--debug=false
|
||||
|
||||
## deployment schema
|
||||
|
||||
--schema=schema.xml
|
||||
|
||||
## parameters
|
||||
|
||||
--inst=../examples/tsp/benchs/eil101.tsp
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<schema>
|
||||
<group scheduler="0">
|
||||
<node name="0" num_workers="0">
|
||||
</node>
|
||||
<node name="1" num_workers="0">
|
||||
<runner>1</runner>
|
||||
</node>
|
||||
<node name="2" num_workers="1">
|
||||
<runner>2</runner>
|
||||
</node>
|
||||
<node name="3" num_workers="1">
|
||||
<runner>3</runner>
|
||||
</node>
|
||||
|
||||
</group>
|
||||
</schema>
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue