// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- // "peoSyncMultiStart.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 __peoSyncMultiStart_h #define __peoSyncMultiStart_h #include #include #include #include #include #include "service.h" #include "mess.h" #include "peo_debug.h" extern int getNodeRank (); template class peoSyncMultiStart : public Service, public eoUpdater { public : /* Ctor */ peoSyncMultiStart (eoContinue & __cont, eoSelect & __select, eoReplacement & __replace, moAlgo & __ls, eoPop & __pop); void operator () (); void packData (); void unpackData (); void execute (); void packResult (); void unpackResult (); void notifySendingData (); void notifySendingAllResourceRequests (); private : eoContinue & cont; eoSelect & select; eoReplacement & replace; moAlgo & ls; eoPop & pop; eoPop sel; eoPop impr_sel; EOT sol; unsigned idx; unsigned num_term; }; template peoSyncMultiStart :: peoSyncMultiStart (eoContinue & __cont, eoSelect & __select, eoReplacement & __replace, moAlgo & __ls, eoPop & __pop ) : cont (__cont), select (__select), replace (__replace), ls (__ls), pop (__pop) { } template void peoSyncMultiStart :: packData () { :: pack (sel [idx ++]); } template void peoSyncMultiStart :: unpackData () { unpack (sol); } template void peoSyncMultiStart :: execute () { ls (sol); } template void peoSyncMultiStart :: packResult () { pack (sol); } template void peoSyncMultiStart :: unpackResult () { unpack (sol); impr_sel.push_back (sol); num_term ++; if (num_term == sel.size ()) { getOwner () -> setActive (); replace (pop, impr_sel); printDebugMessage ("replacing the improved individuals in the population."); resume (); } } template void peoSyncMultiStart :: operator () () { printDebugMessage ("performing the parallel multi-start hybridization."); select (pop, sel); impr_sel.clear (); idx = num_term = 0; requestResourceRequest (sel.size ()); stop (); } template void peoSyncMultiStart :: notifySendingData () { } template void peoSyncMultiStart :: notifySendingAllResourceRequests () { getOwner () -> setPassive (); } #endif