added generic island mig tests (DEV)

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@890 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
legrand 2008-01-17 08:43:35 +00:00
commit 5859f77d9f
4 changed files with 86 additions and 61 deletions

View file

@ -37,19 +37,19 @@
#ifndef __eoPop_mesg_h
#define __eoPop_mesg_h
#include <eoPop.h>
#include "peoPop.h"
#include "messaging.h"
template <class EOT> void pack (const eoPop <EOT> & __pop) {
/*
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 (eoPop <EOT> & __pop) {
template <class EOT> void unpack (peoPop <EOT> & __pop) {
unsigned n;
@ -58,5 +58,5 @@ template <class EOT> void unpack (eoPop <EOT> & __pop) {
for (unsigned i = 0; i < n; i ++)
unpack (__pop [i]);
}
*/
#endif

View file

@ -47,6 +47,9 @@
#include <eoReplacement.h>
#include <eoPop.h>
#include <data.h>
#include <continuator.h>
#include "core/messaging.h"
#include "core/eoPop_mesg.h"
#include "core/eoVector_mesg.h"
@ -141,7 +144,7 @@
//! islands requires the reiteration of the steps 2 through 4 for creating distinct algorithms, with distinct populations and
//! the associated distinctly parametrized migration objects. The interconnecting element is the underlying topology, defined at step 1
//! (the same C++ migTopology object has to be passed as parameter for all the migration objects, in order to interconnect them).
template< class EOT > class peoAsyncIslandMig : public Cooperative, public eoUpdater
template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative, public eoUpdater
{
public:
@ -156,12 +159,12 @@ template< class EOT > class peoAsyncIslandMig : public Cooperative, public eoUpd
//! @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.
peoAsyncIslandMig(
eoContinue< EOT >& __cont,
//continuator< EOT, data < EOT >,bool > & __cont,
eoSelect< EOT >& __select,
eoReplacement< EOT >& __replace,
Topology& __topology,
eoPop< EOT >& __source,
eoPop< EOT >& __destination
data & __source,
data & __destination
);
//! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected
@ -186,88 +189,103 @@ template< class EOT > class peoAsyncIslandMig : public Cooperative, public eoUpd
private:
eoContinue< EOT >& cont; // continuator
//continuator< EOT, data < EOT >,bool> & cont; // continuator
eoSelect< EOT >& select; // the selection strategy
eoReplacement< EOT >& replace; // the replacement strategy
Topology& topology; // the neighboring topology
// source and destination populations
eoPop< EOT >& source;
eoPop< EOT >& destination;
data & source;
data & destination;
// immigrants & emigrants in the queue
std :: queue< eoPop< EOT > > imm;
std :: queue< eoPop< EOT > > em;
std :: queue< data* > imm;
std :: queue< data* > em;
std :: vector< TYPE > vect;
std :: queue< Cooperative* > coop_em;
};
template< class EOT > peoAsyncIslandMig< EOT > :: peoAsyncIslandMig(
template< class EOT , class TYPE> peoAsyncIslandMig< EOT, TYPE > :: peoAsyncIslandMig(
eoContinue< EOT >& __cont,
// continuator< EOT, data < EOT >,bool> & __cont,
eoSelect< EOT >& __select,
eoReplacement< EOT >& __replace,
Topology& __topology,
eoPop< EOT >& __source,
eoPop< EOT >& __destination
data & __source,
data & __destination
) : cont( __cont ), select( __select ), replace( __replace ), topology( __topology ), source( __source ), destination( __destination )
) : select( __select ), replace( __replace ), topology( __topology ), source( __source ), destination( __destination )
{
__topology.add( *this );
}
template< class EOT > void peoAsyncIslandMig< EOT > :: pack()
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: pack()
{
std::cout << "[peoAsyncIslandMig] [pack] [begin]" << std::endl ;
lock ();
::pack( coop_em.front()->getKey() );
::pack( em.front() );
//::pack(em.front());
//coop_em.front()->getKey().pack();
//std::cout << em.front() << std::endl ;
em.front()->pack();
coop_em.pop();
em.pop();
unlock();
std::cout << "[peoAsyncIslandMig] [pack] [end]" << std::endl ;
}
template< class EOT > void peoAsyncIslandMig< EOT > :: unpack()
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: unpack()
{
lock ();
eoPop< EOT > mig;
::unpack( mig );
imm.push( mig );
data mig;
//::unpack( mig );
mig.unpack();
imm.push( &mig );
unlock();
}
template< class EOT > void peoAsyncIslandMig< EOT > :: packSynchronizeReq() {
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: packSynchronizeReq() {
}
template< class EOT > void peoAsyncIslandMig< EOT > :: emigrate()
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: emigrate()
{
std::cout << "[peoAsyncIslandMig] [emigrate] [begin]" << std::endl ;
std :: vector< Cooperative* >in, out;
topology.setNeighbors( this, in, out );
for ( unsigned i = 0; i < out.size(); i++ )
{
eoPop< EOT > mig;
select( source, mig );
em.push( mig );
TYPE mig;
vect.push_back(mig);
//select( source, mig );
//em.push( &mig );
em.push(&(vect[vect.size()-1]));
coop_em.push( out[i] );
send( out[i] );
printDebugMessage( "sending some emigrants." );
}
std::cout << "[peoAsyncIslandMig] [emigrate] [end]" << std::endl ;
}
template< class EOT > void peoAsyncIslandMig< EOT > :: immigrate()
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: immigrate()
{
lock ();
@ -276,7 +294,7 @@ template< class EOT > void peoAsyncIslandMig< EOT > :: immigrate()
while ( !imm.empty() )
{
replace( destination, imm.front() );
// replace( destination, imm.front() );
imm.pop();
printDebugMessage( "receiving some immigrants." );
}
@ -285,15 +303,16 @@ template< class EOT > void peoAsyncIslandMig< EOT > :: immigrate()
}
template< class EOT > void peoAsyncIslandMig< EOT > :: operator()()
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: operator()()
{
if ( !cont( source ) )
{
// if ( !cont( source ) )
// {
emigrate(); // sending emigrants
immigrate(); // receiving immigrants
}
// }
}

View file

@ -54,20 +54,21 @@ ENDIF(WIN32 AND NOT CYGWIN)
### 3) Define your target(s): just an executable here
######################################################################################
ADD_EXECUTABLE(example1 main1.cpp)
ADD_DEPENDENCIES(example1 peo rmc_mpi)
ADD_EXECUTABLE(example2 main2.cpp)
ADD_DEPENDENCIES(example2 peo rmc_mpi)
ADD_EXECUTABLE(example3 main3.cpp)
ADD_DEPENDENCIES(example3 peo rmc_mpi)
#ADD_EXECUTABLE(example1 main1.cpp)
#ADD_DEPENDENCIES(example1 peo rmc_mpi)
#ADD_EXECUTABLE(example2 main2.cpp)
#ADD_DEPENDENCIES(example2 peo rmc_mpi)
#ADD_EXECUTABLE(example3 main3.cpp)
#ADD_DEPENDENCIES(example3 peo rmc_mpi)
ADD_EXECUTABLE(example4 main4.cpp)
ADD_DEPENDENCIES(example4 peo rmc_mpi)
ADD_EXECUTABLE(example5 main5.cpp)
ADD_DEPENDENCIES(example5 tsp peo rmc_mpi)
ADD_EXECUTABLE(example6 main6.cpp)
ADD_DEPENDENCIES(example6 tsp peo rmc_mpi)
ADD_EXECUTABLE(example7 main7.cpp)
ADD_DEPENDENCIES(example7 peo rmc_mpi)
#ADD_EXECUTABLE(example5 main5.cpp)
#ADD_DEPENDENCIES(example5 tsp peo rmc_mpi)
#ADD_EXECUTABLE(example6 main6.cpp)
#ADD_DEPENDENCIES(example6 tsp peo rmc_mpi)
#ADD_EXECUTABLE(example7 main7.cpp)
#ADD_DEPENDENCIES(example7 peo rmc_mpi)
######################################################################################
@ -84,12 +85,12 @@ ADD_DEPENDENCIES(example7 peo rmc_mpi)
### 5) Link the librairies
######################################################################################
TARGET_LINK_LIBRARIES(example1 ${XML2_LIBS} peo rmc_mpi eo eoutils)
TARGET_LINK_LIBRARIES(example2 ${XML2_LIBS} peo rmc_mpi eo eoutils)
TARGET_LINK_LIBRARIES(example3 ${XML2_LIBS} peo rmc_mpi eo eoutils)
#TARGET_LINK_LIBRARIES(example1 ${XML2_LIBS} peo rmc_mpi eo eoutils)
#TARGET_LINK_LIBRARIES(example2 ${XML2_LIBS} peo rmc_mpi eo eoutils)
#TARGET_LINK_LIBRARIES(example3 ${XML2_LIBS} peo rmc_mpi eo eoutils)
TARGET_LINK_LIBRARIES(example4 ${XML2_LIBS} peo rmc_mpi eo eoutils)
TARGET_LINK_LIBRARIES(example5 ${XML2_LIBS} tsp peo rmc_mpi eo eoutils)
TARGET_LINK_LIBRARIES(example6 ${XML2_LIBS} tsp peo rmc_mpi eo eoutils)
TARGET_LINK_LIBRARIES(example7 ${XML2_LIBS} tsp peo rmc_mpi eo eoutils)
#TARGET_LINK_LIBRARIES(example5 ${XML2_LIBS} tsp peo rmc_mpi eo eoutils)
#TARGET_LINK_LIBRARIES(example6 ${XML2_LIBS} tsp peo rmc_mpi eo eoutils)
#TARGET_LINK_LIBRARIES(example7 ${XML2_LIBS} tsp peo rmc_mpi eo eoutils)
######################################################################################

View file

@ -1,6 +1,8 @@
#include <peo>
#include <es.h>
#include <peoPop.h>
typedef eoRealParticle < double >Indi;
double f (const Indi & _indi)
@ -47,7 +49,7 @@ int main( int __argc, char** __argv )
eoFirstIsBestInit < Indi > localInit;
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
eoStandardFlight < Indi > flight(bndsFlight);
eoPop < Indi > pop;
peoPop < Indi > pop;
pop.append (POP_SIZE, random);
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
@ -76,7 +78,7 @@ int main( int __argc, char** __argv )
eoFirstIsBestInit < Indi > localInit2;
eoRealVectorBounds bndsFlight2(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
eoStandardFlight < Indi > flight2(bndsFlight2);
eoPop < Indi > pop2;
peoPop < Indi > pop2;
pop2.append (POP_SIZE, random2);
eoLinearTopology<Indi> topology2(NEIGHBORHOOD_SIZE);
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
@ -85,6 +87,7 @@ int main( int __argc, char** __argv )
// Island model
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
peoPSOSelect<Indi> mig_selec2(topology2);
eoSelectNumber< Indi > mig_select2(mig_selec2);
@ -93,10 +96,11 @@ int main( int __argc, char** __argv )
// Island model
peoAsyncIslandMig< Indi > mig( mig_cont, mig_select, mig_replace, topologyMig, pop, pop);
peoAsyncIslandMig< Indi, peoPop<Indi> > mig(mig_select, mig_replace, topologyMig, pop, pop);
checkpoint.add( mig );
peoAsyncIslandMig< Indi > mig2( mig_cont2, mig_select2, mig_replace2, topologyMig, pop2, pop2);
peoAsyncIslandMig< Indi, peoPop<Indi> > mig2(mig_select2, mig_replace2, topologyMig, pop2, pop2);
checkpoint2.add( mig2 );
@ -117,4 +121,5 @@ int main( int __argc, char** __argv )
std::cout << "Final population :\n" << pop << std::endl;
std::cout << "Final population :\n" << pop2 << std::endl;
}
}