00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef __peoAsyncIslandMig_h
00038 #define __peoAsyncIslandMig_h
00039
00040
00041 #include <queue>
00042
00043 #include <utils/eoUpdater.h>
00044
00045 #include <eoContinue.h>
00046 #include <eoSelect.h>
00047 #include <eoReplacement.h>
00048 #include <eoPop.h>
00049
00050 #include "core/topology.h"
00051 #include "core/cooperative.h"
00052 #include "core/eoPop_comm.h"
00053 #include "core/peo_debug.h"
00054
00055
00057
00140 template< class EOT > class peoAsyncIslandMig : public Cooperative, public eoUpdater {
00141
00142 public:
00143
00153 peoAsyncIslandMig(
00154 eoContinue< EOT >& __cont,
00155 eoSelect< EOT >& __select,
00156 eoReplacement< EOT >& __replace,
00157 Topology& __topology,
00158 eoPop< EOT >& __source,
00159 eoPop< EOT >& __destination
00160 );
00161
00166 void operator()();
00167
00169 void pack();
00171 void unpack();
00172
00173
00174 private:
00175
00176 void emigrate();
00177 void immigrate();
00178
00179
00180 private:
00181
00182 eoContinue< EOT >& cont;
00183 eoSelect< EOT >& select;
00184 eoReplacement< EOT >& replace;
00185 Topology& topology;
00186
00187
00188 eoPop< EOT >& source;
00189 eoPop< EOT >& destination;
00190
00191
00192 std :: queue< eoPop< EOT > > imm;
00193 std :: queue< eoPop< EOT > > em;
00194
00195 std :: queue< Cooperative* > coop_em;
00196 };
00197
00198
00199 template< class EOT > peoAsyncIslandMig< EOT > :: peoAsyncIslandMig(
00200
00201 eoContinue< EOT >& __cont,
00202 eoSelect< EOT >& __select,
00203 eoReplacement< EOT >& __replace,
00204 Topology& __topology,
00205 eoPop< EOT >& __source,
00206 eoPop< EOT >& __destination
00207
00208 ) : cont( __cont ), select( __select ), replace( __replace ), topology( __topology ), source( __source ), destination( __destination )
00209 {
00210
00211 __topology.add( *this );
00212 }
00213
00214
00215 template< class EOT > void peoAsyncIslandMig< EOT > :: pack()
00216 {
00217
00218 lock(); {
00219
00220 :: pack( coop_em.front()->getKey() );
00221 :: pack( em.front() );
00222 coop_em.pop();
00223 em.pop();
00224 }
00225 unlock();
00226 }
00227
00228
00229 template< class EOT > void peoAsyncIslandMig< EOT > :: unpack()
00230 {
00231
00232 lock(); {
00233
00234 eoPop< EOT > mig;
00235 :: unpack( mig );
00236 imm.push( mig );
00237 }
00238 unlock();
00239 }
00240
00241
00242 template< class EOT > void peoAsyncIslandMig< EOT > :: emigrate()
00243 {
00244
00245 std :: vector< Cooperative* >in, out;
00246 topology.setNeighbors( this, in, out );
00247
00248 for ( unsigned i = 0; i < out.size(); i++ ) {
00249
00250 eoPop< EOT > mig;
00251 select( source, mig );
00252 em.push( mig );
00253 coop_em.push( out[i] );
00254 send( out[i] );
00255 printDebugMessage( "sending some emigrants." );
00256 }
00257 }
00258
00259
00260 template< class EOT > void peoAsyncIslandMig< EOT > :: immigrate()
00261 {
00262
00263 lock(); {
00264
00265 while ( !imm.empty() ) {
00266
00267 replace( destination, imm.front() );
00268 imm.pop();
00269 printDebugMessage( "receiving some immigrants." );
00270 }
00271 }
00272 unlock();
00273 }
00274
00275
00276 template< class EOT > void peoAsyncIslandMig< EOT > :: operator()() {
00277
00278 if ( !cont( source ) ) {
00279
00280 emigrate();
00281 immigrate();
00282 }
00283 }
00284
00285
00286 #endif