diff --git a/trunk/paradiseo-peo/src/core/eoPop_mesg.h b/trunk/paradiseo-peo/src/core/eoPop_mesg.h index 948e17ae2..e5c7d0d70 100644 --- a/trunk/paradiseo-peo/src/core/eoPop_mesg.h +++ b/trunk/paradiseo-peo/src/core/eoPop_mesg.h @@ -37,19 +37,19 @@ #ifndef __eoPop_mesg_h #define __eoPop_mesg_h -#include +#include "peoPop.h" #include "messaging.h" - -template void pack (const eoPop & __pop) { +/* +template void pack (const peoPop & __pop) { pack ((unsigned) __pop.size ()); for (unsigned i = 0; i < __pop.size (); i ++) pack (__pop [i]); } -template void unpack (eoPop & __pop) { +template void unpack (peoPop & __pop) { unsigned n; @@ -58,5 +58,5 @@ template void unpack (eoPop & __pop) { for (unsigned i = 0; i < n; i ++) unpack (__pop [i]); } - +*/ #endif diff --git a/trunk/paradiseo-peo/src/peoAsyncIslandMig.h b/trunk/paradiseo-peo/src/peoAsyncIslandMig.h index 96a4db782..cef9c7c2a 100644 --- a/trunk/paradiseo-peo/src/peoAsyncIslandMig.h +++ b/trunk/paradiseo-peo/src/peoAsyncIslandMig.h @@ -47,6 +47,9 @@ #include #include +#include +#include + #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 - } + // } + } diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/CMakeLists.txt b/trunk/paradiseo-peo/tutorial/Wrapper/CMakeLists.txt index f34c8fcbc..8ee575c65 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/CMakeLists.txt +++ b/trunk/paradiseo-peo/tutorial/Wrapper/CMakeLists.txt @@ -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) ###################################################################################### diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp b/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp index 491e8f863..f5f335334 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp +++ b/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp @@ -1,6 +1,8 @@ #include #include +#include + 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 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 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 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 > 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 > 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; } + }