generic island model OK !

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@892 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
legrand 2008-01-17 13:11:41 +00:00
commit f7dc43d35b
3 changed files with 44 additions and 60 deletions

View file

@ -24,7 +24,7 @@
* professionals having in-depth computer knowledge. Users are therefore * professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their * encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or * 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 * peoData to be ensured and, more generally, to use and operate it in the
* same conditions as regards security. * same conditions as regards security.
* The fact that you are presently reading this means that you have had * The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms. * knowledge of the CeCILL license and that you accept its terms.
@ -41,19 +41,18 @@
#include <queue> #include <queue>
#include <utils/eoUpdater.h> #include <utils/eoUpdater.h>
#include <eoContinue.h> #include <eoContinue.h>
#include <eoSelect.h> #include <eoSelect.h>
#include <eoReplacement.h> #include <eoReplacement.h>
#include <eoPop.h> #include <eoPop.h>
#include <data.h> #include <peoData.h>
#include <continuator.h> #include <continuator.h>
#include "core/messaging.h" #include "core/messaging.h"
#include "core/eoPop_mesg.h" #include "core/eoPop_mesg.h"
#include "core/eoVector_mesg.h" #include "core/eoVector_mesg.h"
#include "core/topology.h" #include "core/topology.h"
#include "core/thread.h" #include "core/thread.h"
#include "core/cooperative.h" #include "core/cooperative.h"
@ -159,13 +158,14 @@ template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative,
//! @param eoPop< EOT >& __source - source population from which the emigrant individuals are selected; //! @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. //! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated.
peoAsyncIslandMig( peoAsyncIslandMig(
//continuator< EOT, data < EOT >,bool > & __cont, continuator & __cont,
eoSelect< EOT >& __select, eoSelect< EOT >& __select,
eoReplacement< EOT >& __replace, eoReplacement< EOT >& __replace,
Topology& __topology, Topology& __topology,
data & __source, peoData & __source,
data & __destination peoData & __destination
); );
//! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected //! 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 //! from the source population and sent to the next island (defined by the topology object) while the immigrant
@ -189,18 +189,19 @@ template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative,
private: private:
//continuator< EOT, data < EOT >,bool> & cont; // continuator continuator & cont; // continuator
eoSelect< EOT >& select; // the selection strategy eoSelect< EOT >& select; // the selection strategy
eoReplacement< EOT >& replace; // the replacement strategy eoReplacement< EOT >& replace; // the replacement strategy
Topology& topology; // the neighboring topology Topology& topology; // the neighboring topology
// source and destination populations // source and destination populations
data & source; peoData & source;
data & destination; peoData & destination;
// immigrants & emigrants in the queue // immigrants & emigrants in the queue
std :: queue< data* > imm; std :: queue< peoData* > imm;
std :: queue< data* > em; std :: queue< peoData* > em;
std :: vector< TYPE > vect; std :: vector< TYPE > vect;
@ -210,14 +211,14 @@ template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative,
template< class EOT , class TYPE> peoAsyncIslandMig< EOT, TYPE > :: peoAsyncIslandMig( template< class EOT , class TYPE> peoAsyncIslandMig< EOT, TYPE > :: peoAsyncIslandMig(
// continuator< EOT, data < EOT >,bool> & __cont, continuator & __cont,
eoSelect< EOT >& __select, eoSelect< EOT >& __select,
eoReplacement< EOT >& __replace, eoReplacement< EOT >& __replace,
Topology& __topology, Topology& __topology,
data & __source, peoData & __source,
data & __destination peoData & __destination
) : select( __select ), replace( __replace ), topology( __topology ), source( __source ), destination( __destination ) ) : select( __select ), replace( __replace ), topology( __topology ), source( __source ), destination( __destination ), cont(__cont)
{ {
__topology.add( *this ); __topology.add( *this );
@ -250,7 +251,7 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: unpack(
lock (); lock ();
data mig; peoData mig;
//::unpack( mig ); //::unpack( mig );
mig.unpack(); mig.unpack();
imm.push( &mig ); imm.push( &mig );
@ -305,14 +306,21 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: immigra
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: operator()() template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: operator()()
{ {
/*
// if ( !cont( source ) ) if ( !cont( source ) && ! eocont(source) )
// { {
emigrate(); // sending emigrants emigrate(); // sending emigrants
immigrate(); // receiving immigrants immigrate(); // receiving immigrants
// } }
*/
if (cont.check())
{
emigrate(); // sending emigrants
immigrate(); // receiving immigrants
}
} }

View file

@ -25,6 +25,7 @@
#ifndef _peoPop_H #ifndef _peoPop_H
#define _peoPop_H #define _peoPop_H
#include <peoData.h>
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <iterator> // needed for GCC 3.2 #include <iterator> // needed for GCC 3.2
@ -36,60 +37,32 @@
#include <eoInit.h> #include <eoInit.h>
#include <utils/rnd_generators.h> // for shuffle method #include <utils/rnd_generators.h> // for shuffle method
#include <data.h>
//#include "core/eoPop_mesg.h"
#include "core/eoVector_mesg.h" #include "core/eoVector_mesg.h"
#include "core/messaging.h" #include "core/messaging.h"
template<class EOT> template<class EOT>
class peoPop: public data, public eoPop<EOT> class peoPop: public eoPop<EOT>, public peoData
{ {
public: public:
virtual void pack () virtual void pack ()
{ {
std::cout << "[peoPop][pack]" << std::endl;
//::pack((*this));
::pack ((unsigned) this->size ()); ::pack ((unsigned) this->size ());
for (unsigned i = 0; i < this->size (); i ++) for (unsigned i = 0; i < this->size (); i ++)
::pack ((*this)[i]); ::pack ((*this)[i]);
} }
virtual void unpack () virtual void unpack ()
{ {
// ::unpack((*this)); unsigned n;
::unpack (n);
unsigned n; this->resize (n);
for (unsigned i = 0; i < n; i ++)
::unpack (n); ::unpack ((*this)[i]);
this->resize (n);
for (unsigned i = 0; i < n; i ++)
::unpack ((*this)[i]);
} }
}; };
/*
template <class EOT> void pack (const peoPop <EOT> & __pop) {
pack ((unsigned) __pop.size ());
for (unsigned i = 0; i < __pop.size (); i ++)
pack (__pop [i]);
}
template <class EOT> void unpack (peoPop <EOT> & __pop) {
unsigned n;
unpack (n);
__pop.resize (n);
for (unsigned i = 0; i < n; i ++)
unpack (__pop [i]);
}
*/
#endif #endif

View file

@ -3,6 +3,8 @@
#include <peoPop.h> #include <peoPop.h>
#include <continuator.h>
typedef eoRealParticle < double >Indi; typedef eoRealParticle < double >Indi;
double f (const Indi & _indi) double f (const Indi & _indi)
@ -96,11 +98,12 @@ int main( int __argc, char** __argv )
// Island model // Island model
peoAsyncIslandMig< Indi, peoPop<Indi> > mig(mig_select, mig_replace, topologyMig, pop, pop); eoContinuator<Indi> cont(mig_cont, pop);
peoAsyncIslandMig< Indi, peoPop<Indi> > mig(cont,mig_select, mig_replace, topologyMig, pop, pop);
checkpoint.add( mig ); checkpoint.add( mig );
eoContinuator<Indi> cont2(mig_cont2,pop2);
peoAsyncIslandMig< Indi, peoPop<Indi> > mig2(mig_select2, mig_replace2, topologyMig, pop2, pop2); peoAsyncIslandMig< Indi, peoPop<Indi> > mig2(cont2,mig_select2, mig_replace2, topologyMig, pop2, pop2);
checkpoint2.add( mig2 ); checkpoint2.add( mig2 );