// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- // "peoParaSGATransform.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 __peoParaSGATransform_h #define __peoParaSGATransform_h #include "peoTransform.h" #include "thread.h" #include "mess.h" #include "peo_debug.h" extern int getNodeRank (); template class peoParaSGATransform : public peoTransform { public : using peoTransform :: requestResourceRequest; using peoTransform :: resume; using peoTransform :: stop; using peoTransform :: getOwner; /* Ctor */ peoParaSGATransform (eoQuadOp & __cross, double __cross_rate, eoMonOp & __mut, double __mut_rate); void operator () (eoPop & __pop); void packData (); void unpackData (); void execute (); void packResult (); void unpackResult (); void notifySendingData (); void notifySendingAllResourceRequests (); private : eoQuadOp & cross; double cross_rate; eoMonOp & mut; double mut_rate; unsigned idx; eoPop * pop; EOT father, mother; unsigned num_term; }; template peoParaSGATransform :: peoParaSGATransform (eoQuadOp & __cross, double __cross_rate, eoMonOp & __mut, double __mut_rate ) : cross (__cross), cross_rate (__cross_rate), mut (__mut), mut_rate (__mut_rate) { } template void peoParaSGATransform :: packData () { pack (idx); :: pack (pop -> operator [] (idx ++)); :: pack (pop -> operator [] (idx ++)); } template void peoParaSGATransform :: unpackData () { unpack (idx); :: unpack (father); :: unpack (mother); } template void peoParaSGATransform :: execute () { if (rng.uniform () < cross_rate) cross (father, father); if (rng.uniform () < mut_rate) mut (father); if (rng.uniform () < mut_rate) mut (mother); } template void peoParaSGATransform :: packResult () { pack (idx); :: pack (father); :: pack (mother); } template void peoParaSGATransform :: unpackResult () { unsigned sidx; unpack (sidx); :: unpack (pop -> operator [] (sidx ++)); :: unpack (pop -> operator [] (sidx)); num_term += 2; if (num_term == pop -> size ()) { getOwner () -> setActive (); resume (); } } template void peoParaSGATransform :: operator () (eoPop & __pop) { printDebugMessage ("performing the parallel transformation step."); pop = & __pop; idx = 0; num_term = 0; requestResourceRequest (__pop.size () / 2); stop (); } template void peoParaSGATransform :: notifySendingData () { } template void peoParaSGATransform :: notifySendingAllResourceRequests () { getOwner () -> setPassive (); } #endif