// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- // "peoAsyncIslandMig.h" // (c) OPAC Team, LIFL, August 2005 /* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: cahon@lifl.fr */ #ifndef __peoAsyncIslandMig_h #define __peoAsyncIslandMig_h #include #include #include #include #include #include #include "topo.h" #include "coop.h" #include "eoPop_comm.h" #include "peo_debug.h" template class peoAsyncIslandMig : public Cooperative, public eoUpdater { public : /* Ctor */ peoAsyncIslandMig (eoContinue & __cont, eoSelect & __select, eoReplacement & __replace, Topology & __topo, eoPop & __from, eoPop & __to); void operator () (); void pack (); void unpack (); private : void emigrate (); void immigrate (); eoContinue & cont; /* Continuator */ eoSelect & select; /* The selection strategy */ eoReplacement & replace; /* The replacement strategy */ Topology & topo; /* The neighboring topology */ /* Source and target populations */ eoPop & from, & to; /* Immigrants & emigrants in the queue */ std :: queue > imm, em; std :: queue coop_em; }; template peoAsyncIslandMig :: peoAsyncIslandMig (eoContinue & __cont, eoSelect & __select, eoReplacement & __replace, Topology & __topo, eoPop & __from, eoPop & __to ) : cont (__cont), select (__select), replace (__replace), topo (__topo), from (__from), to (__to) { __topo.add (* this); } template void peoAsyncIslandMig :: pack () { lock (); :: pack (coop_em.front () -> getKey ()); :: pack (em.front ()); coop_em.pop (); em.pop (); unlock (); } template void peoAsyncIslandMig :: unpack () { lock (); eoPop mig; :: unpack (mig); imm.push (mig); unlock (); } template void peoAsyncIslandMig :: emigrate () { std :: vector in, out ; topo.setNeighbors (this, in, out) ; for (unsigned i = 0; i < out.size (); i ++) { eoPop mig; select (from, mig); em.push (mig); coop_em.push (out [i]); send (out [i]); printDebugMessage ("sending some emigrants."); } } template void peoAsyncIslandMig :: immigrate () { lock (); while (! imm.empty ()) { replace (to, imm.front ()) ; imm.pop (); printDebugMessage ("receiving some immigrants."); } unlock (); } template void peoAsyncIslandMig :: operator () () { if (! cont (from)) { /* Sending emigrants */ emigrate (); /* Immigrants */ immigrate (); } } #endif