diff --git a/trunk/paradiseo-peo/src/peo.h b/trunk/paradiseo-peo/src/peo.h index 59c274c0a..c219609c4 100644 --- a/trunk/paradiseo-peo/src/peo.h +++ b/trunk/paradiseo-peo/src/peo.h @@ -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" diff --git a/trunk/paradiseo-peo/src/peoAsyncIslandMig.h b/trunk/paradiseo-peo/src/peoAsyncIslandMig.h index f32f6ef93..5d5e2a983 100644 --- a/trunk/paradiseo-peo/src/peoAsyncIslandMig.h +++ b/trunk/paradiseo-peo/src/peoAsyncIslandMig.h @@ -46,9 +46,6 @@ #include #include -#include -#include - #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 & __select, + replacement & __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 & select; // the selection strategy + replacement & 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 & __select, + replacement & __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()) { diff --git a/trunk/paradiseo-peo/src/peoData.h b/trunk/paradiseo-peo/src/peoData.h new file mode 100644 index 000000000..7d5c199c5 --- /dev/null +++ b/trunk/paradiseo-peo/src/peoData.h @@ -0,0 +1,153 @@ +/* +* +* 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 peoPop: public eoPop, 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 & _cont, const eoPop & _pop): cont (_cont), pop(_pop){} + + virtual bool check(){ + return cont(pop); + } + +protected: + eoContinue & cont ; + const eoPop & 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 & _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(nb_select); + _dest.resize(target); + for (size_t i = 0; i < _dest.size(); ++i) + _dest[i] = selector(source); + } + +protected: + eoSelectOne & 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 & _replace, TYPE & _destination): replace(_replace), destination(_destination){} + + virtual void operator()(TYPE & _source) + { + replace(destination, _source); + } + +protected: + eoReplacement & replace; + TYPE & destination; +}; + +#endif diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp b/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp index 8f03a2135..6e7bd3c99 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp +++ b/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp @@ -1,9 +1,6 @@ #include #include -#include - -#include typedef eoRealParticle < double >Indi; @@ -62,8 +59,11 @@ int main( int __argc, char** __argv ) eoPeriodicContinue< Indi > mig_cont( MIG_FREQ ); peoPSOSelect mig_selec(topology); - eoSelectNumber< Indi > mig_select(mig_selec); - peoWorstPositionReplacement mig_replace; + peoWorstPositionReplacement mig_replac; + + eoContinuator cont(mig_cont, pop); + eoSelector > mig_select (mig_selec,1,pop); + eoReplace > 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 cont2(mig_cont2,pop2); peoPSOSelect mig_selec2(topology2); - eoSelectNumber< Indi > mig_select2(mig_selec2); - peoWorstPositionReplacement mig_replace2; - + eoSelector > mig_select2 (mig_selec2,1,pop2); + peoWorstPositionReplacement mig_replac2; + eoReplace > mig_replace2 (mig_replac2,pop2); // Island model - eoContinuator cont(mig_cont, pop); + peoAsyncIslandMig< Indi, peoPop > mig(cont,mig_select, mig_replace, topologyMig, pop, pop); checkpoint.add( mig ); - - eoContinuator cont2(mig_cont2,pop2); peoAsyncIslandMig< Indi, peoPop > mig2(cont2,mig_select2, mig_replace2, topologyMig, pop2, pop2); checkpoint2.add( mig2 );