peoParaSGATransform.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 // "peoParaSGATransform.h"
00004 
00005 //(c) OPAC Team, LIFL, August 2005
00006 
00007 /* This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011    
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016    
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with this library; if not, write to the Free Software
00019    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020    
00021    Contact: paradiseo-help@lists.gforge.inria.fr
00022 */
00023 
00024 #ifndef __peoParaSGATransform_h
00025 #define __peoParaSGATransform_h
00026 
00027 #include "peoTransform.h"
00028 #include "core/thread.h"
00029 #include "core/messaging.h"
00030 #include "core/peo_debug.h"
00031 
00032 
00033 extern int getNodeRank();
00034 
00035 
00036 template< class EOT > class peoParaSGATransform : public peoTransform< EOT > {
00037 
00038 public:
00039 
00040         using peoTransform< EOT > :: requestResourceRequest;
00041         using peoTransform< EOT > :: resume;
00042         using peoTransform< EOT > :: stop;
00043         using peoTransform< EOT > :: getOwner;
00044 
00045         peoParaSGATransform( 
00046 
00047                                 eoQuadOp< EOT >& __cross,
00048                                 double __cross_rate,
00049                                 eoMonOp< EOT >& __mut, 
00050                                 double __mut_rate 
00051         );
00052 
00053         void operator()( eoPop< EOT >& __pop );
00054         
00055         void packData();
00056         
00057         void unpackData();
00058         
00059         void execute();
00060         
00061         void packResult();
00062         
00063         void unpackResult();
00064         
00065         void notifySendingData();
00066         void notifySendingAllResourceRequests();
00067 
00068 private:
00069 
00070     eoQuadOp< EOT >& cross;
00071     double cross_rate;
00072 
00073     eoMonOp< EOT >& mut;
00074     double mut_rate;
00075 
00076     unsigned idx;
00077 
00078     eoPop< EOT >* pop;
00079 
00080     EOT father, mother;
00081 
00082     unsigned num_term;
00083 };
00084 
00085 template< class EOT > peoParaSGATransform< EOT > :: peoParaSGATransform( 
00086 
00087                                 eoQuadOp< EOT >& __cross,
00088                                 double __cross_rate,
00089                                 eoMonOp < EOT >& __mut,
00090                                 double __mut_rate 
00091 
00092                 ) : cross( __cross ), cross_rate( __cross_rate ), mut( __mut ), mut_rate( __mut_rate )
00093 {
00094 
00095 }
00096 
00097 
00098 template< class EOT > void peoParaSGATransform< EOT > :: packData() {
00099 
00100         pack( idx );
00101          :: pack( pop->operator[]( idx++ ) );
00102          :: pack( pop->operator[]( idx++ ) );
00103 }
00104 
00105 
00106 template< class EOT > void peoParaSGATransform< EOT > :: unpackData() {
00107 
00108         unpack( idx );
00109          :: unpack( father );
00110          :: unpack( mother );
00111 }
00112 
00113 
00114 template< class EOT > void peoParaSGATransform< EOT > :: execute() {
00115 
00116         if( rng.uniform() < cross_rate ) cross( mother, father );
00117 
00118         if( rng.uniform() < mut_rate ) mut( mother );
00119         if( rng.uniform() < mut_rate ) mut( father );
00120 }
00121 
00122 
00123 template< class EOT > void peoParaSGATransform< EOT > :: packResult() {
00124 
00125         pack( idx );
00126          :: pack( father );
00127          :: pack( mother );
00128 }
00129 
00130 
00131 template< class EOT > void peoParaSGATransform< EOT > :: unpackResult() {
00132 
00133         unsigned sidx;
00134         
00135         unpack( sidx );
00136          :: unpack( pop->operator[]( sidx++ ) );
00137          :: unpack( pop->operator[]( sidx ) );
00138         num_term += 2;
00139         
00140         if( num_term == pop->size() ) {
00141 
00142                 getOwner()->setActive();
00143                 resume();
00144         }
00145 }
00146 
00147 
00148 template< class EOT > void peoParaSGATransform< EOT > :: operator()( eoPop < EOT >& __pop ) {
00149 
00150         printDebugMessage( "performing the parallel transformation step." );
00151         pop = &__pop;
00152         idx = 0;
00153         num_term = 0;
00154         requestResourceRequest( __pop.size() / 2 );
00155         stop();
00156 }
00157 
00158 
00159 template< class EOT > void peoParaSGATransform< EOT > :: notifySendingData() {
00160 
00161 }
00162 
00163 
00164 template< class EOT > void peoParaSGATransform< EOT > :: notifySendingAllResourceRequests() {
00165 
00166         getOwner()->setPassive();
00167 }
00168 
00169 
00170 #endif

Generated on Sun Jan 7 18:35:23 2007 for ParadisEO-PEO by  doxygen 1.4.7