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