Add to AsyncMig with peoData

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@897 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
canape 2008-01-21 10:24:37 +00:00
commit 8c8751f367
4 changed files with 172 additions and 33 deletions

View file

@ -333,9 +333,9 @@
#include "peoPopEval.h"
#include "peoMoeoPopEval.h"
/* Cooperative island model */
#include "core/ring_topo.h"
#include "peoData.h"
#include "peoSyncIslandMig.h"
#include "peoAsyncIslandMig.h"

View file

@ -46,9 +46,6 @@
#include <eoReplacement.h>
#include <eoPop.h>
#include <peoData.h>
#include <continuator.h>
#include "core/messaging.h"
#include "core/eoPop_mesg.h"
@ -159,8 +156,8 @@ template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative,
//! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated.
peoAsyncIslandMig(
continuator & __cont,
eoSelect< EOT >& __select,
eoReplacement< EOT >& __replace,
selector <TYPE> & __select,
replacement <TYPE> & __replace,
Topology& __topology,
peoData & __source,
peoData & __destination
@ -190,8 +187,8 @@ template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative,
private:
continuator & cont; // continuator
eoSelect< EOT >& select; // the selection strategy
eoReplacement< EOT >& replace; // the replacement strategy
selector <TYPE> & select; // the selection strategy
replacement <TYPE> & replace; // the replacement strategy
Topology& topology; // the neighboring topology
peoData & source;
peoData & destination;
@ -204,8 +201,8 @@ template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative,
template< class EOT , class TYPE> peoAsyncIslandMig< EOT, TYPE > :: peoAsyncIslandMig(
continuator & __cont,
eoSelect< EOT >& __select,
eoReplacement< EOT >& __replace,
selector <TYPE> & __select,
replacement <TYPE> & __replace,
Topology& __topology,
peoData & __source,
peoData & __destination
@ -249,7 +246,7 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: emigrat
{
TYPE mig;
//select( source, mig );
select(mig);
em.push( mig );
coop_em.push( out[i] );
send( out[i] );
@ -266,8 +263,7 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: immigra
while ( !imm.empty() )
{
// replace( destination, imm.front() );
replace(imm.front() );
imm.pop();
printDebugMessage( "receiving some immigrants." );
}
@ -278,14 +274,6 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: immigra
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: operator()()
{
/*
if ( !cont( source ) && ! eocont(source) )
{
emigrate(); // sending emigrants
immigrate(); // receiving immigrants
}
*/
if (cont.check())
{

View file

@ -0,0 +1,153 @@
/*
* <peoData.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Clive Canape, Thomas Legrand
*
* 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
* peoData 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 _PEODATA_H
#define _PEODATA_H
#include "core/eoVector_mesg.h"
#include "core/messaging.h"
/************************** DEFINE A DATA ******************************************/
class peoData {
public:
virtual void pack () {}
virtual void unpack () {}
};
template<class EOT>
class peoPop: public eoPop<EOT>, public peoData
{
public:
virtual void pack ()
{
::pack ((unsigned) this->size ());
for (unsigned i = 0; i < this->size (); i ++)
::pack ((*this)[i]);
}
virtual void unpack ()
{
unsigned n;
::unpack (n);
this->resize (n);
for (unsigned i = 0; i < n; i ++)
::unpack ((*this)[i]);
}
};
/************************** DEFINE A CONTINUATOR ******************************************/
class continuator
{
public:
virtual bool check()=0;
};
template < class EOT> class eoContinuator : public continuator{
public:
eoContinuator(eoContinue<EOT> & _cont, const eoPop<EOT> & _pop): cont (_cont), pop(_pop){}
virtual bool check(){
return cont(pop);
}
protected:
eoContinue<EOT> & cont ;
const eoPop<EOT> & pop;
};
/************************** DEFINE A SELECTOR ******************************************/
template < class TYPE> class selector
{
public:
virtual void operator()(TYPE &)=0;
};
template < class EOT, class TYPE> class eoSelector : public selector< TYPE >{
public:
eoSelector(eoSelectOne<EOT> & _select, unsigned _nb_select, const TYPE & _source): selector (_select), nb_select(_nb_select), source(_source){}
virtual void operator()(TYPE & _dest)
{
size_t target = static_cast<size_t>(nb_select);
_dest.resize(target);
for (size_t i = 0; i < _dest.size(); ++i)
_dest[i] = selector(source);
}
protected:
eoSelectOne<EOT> & selector ;
unsigned nb_select;
const TYPE & source;
};
/************************** DEFINE A REPLACEMENT ******************************************/
template < class TYPE> class replacement
{
public:
virtual void operator()(TYPE &)=0;
};
template < class EOT, class TYPE> class eoReplace : public replacement< TYPE >{
public:
eoReplace(eoReplacement<EOT> & _replace, TYPE & _destination): replace(_replace), destination(_destination){}
virtual void operator()(TYPE & _source)
{
replace(destination, _source);
}
protected:
eoReplacement<EOT> & replace;
TYPE & destination;
};
#endif

View file

@ -1,9 +1,6 @@
#include <peo>
#include <es.h>
#include <peoPop.h>
#include <continuator.h>
typedef eoRealParticle < double >Indi;
@ -62,8 +59,11 @@ int main( int __argc, char** __argv )
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
peoPSOSelect<Indi> mig_selec(topology);
eoSelectNumber< Indi > mig_select(mig_selec);
peoWorstPositionReplacement<Indi> mig_replace;
peoWorstPositionReplacement<Indi> mig_replac;
eoContinuator<Indi> cont(mig_cont, pop);
eoSelector <Indi, peoPop<Indi> > mig_select (mig_selec,1,pop);
eoReplace <Indi, peoPop<Indi> > mig_replace (mig_replac,pop);
// Second
@ -89,20 +89,18 @@ int main( int __argc, char** __argv )
// Island model
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
eoContinuator<Indi> cont2(mig_cont2,pop2);
peoPSOSelect<Indi> mig_selec2(topology2);
eoSelectNumber< Indi > mig_select2(mig_selec2);
peoWorstPositionReplacement<Indi> mig_replace2;
eoSelector <Indi, peoPop<Indi> > mig_select2 (mig_selec2,1,pop2);
peoWorstPositionReplacement<Indi> mig_replac2;
eoReplace <Indi, peoPop<Indi> > mig_replace2 (mig_replac2,pop2);
// Island model
eoContinuator<Indi> cont(mig_cont, pop);
peoAsyncIslandMig< Indi, peoPop<Indi> > mig(cont,mig_select, mig_replace, topologyMig, pop, pop);
checkpoint.add( mig );
eoContinuator<Indi> cont2(mig_cont2,pop2);
peoAsyncIslandMig< Indi, peoPop<Indi> > mig2(cont2,mig_select2, mig_replace2, topologyMig, pop2, pop2);
checkpoint2.add( mig2 );