00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef __peoTransform_h
00038 #define __peoTransform_h
00039
00040 #include "core/thread.h"
00041 #include "core/messaging.h"
00042 #include "core/peo_debug.h"
00043 #include "core/service.h"
00044
00045
00046 extern int getNodeRank();
00047
00053 template< class EOT > class peoTransform : public Service, public eoTransform< EOT >
00054 {
00055
00056 public:
00057
00063 peoTransform(
00064 eoQuadOp< EOT >& __cross,
00065 double __cross_rate,
00066 eoMonOp< EOT >& __mut,
00067 double __mut_rate
00068 );
00069
00072 void operator()( eoPop< EOT >& __pop );
00074 void packData();
00076 void unpackData();
00078 void execute();
00080 void packResult();
00082 void unpackResult();
00084 void notifySendingData();
00086 void notifySendingAllResourceRequests();
00087
00088 private:
00098 eoQuadOp< EOT >& cross;
00099 double cross_rate;
00100 eoMonOp< EOT >& mut;
00101 double mut_rate;
00102 unsigned idx;
00103 eoPop< EOT >* pop;
00104 EOT father, mother;
00105 unsigned num_term;
00106 };
00107
00108 template< class EOT > peoTransform< EOT > :: peoTransform(
00109
00110 eoQuadOp< EOT >& __cross,
00111 double __cross_rate,
00112 eoMonOp < EOT >& __mut,
00113 double __mut_rate
00114
00115 ) : cross( __cross ), cross_rate( __cross_rate ), mut( __mut ), mut_rate( __mut_rate )
00116 {}
00117
00118
00119 template< class EOT > void peoTransform< EOT > :: packData()
00120 {
00121
00122 pack( idx );
00123 pack( pop->operator[]( idx++ ) );
00124 pack( pop->operator[]( idx++ ) );
00125 }
00126
00127
00128 template< class EOT > void peoTransform< EOT > :: unpackData()
00129 {
00130
00131 unpack( idx );
00132 unpack( father );
00133 unpack( mother );
00134 }
00135
00136
00137 template< class EOT > void peoTransform< EOT > :: execute()
00138 {
00139
00140 if ( rng.uniform() < cross_rate ) cross( mother, father );
00141
00142 if ( rng.uniform() < mut_rate ) mut( mother );
00143 if ( rng.uniform() < mut_rate ) mut( father );
00144 }
00145
00146
00147 template< class EOT > void peoTransform< EOT > :: packResult()
00148 {
00149
00150 pack( idx );
00151 pack( father );
00152 pack( mother );
00153 }
00154
00155
00156 template< class EOT > void peoTransform< EOT > :: unpackResult()
00157 {
00158
00159 unsigned sidx;
00160
00161 unpack( sidx );
00162 unpack( pop->operator[]( sidx++ ) );
00163 unpack( pop->operator[]( sidx ) );
00164 num_term += 2;
00165
00166
00167 if ( num_term == 2*(pop->size()/2) )
00168 {
00169
00170 getOwner()->setActive();
00171 resume();
00172 }
00173 }
00174
00175
00176 template< class EOT > void peoTransform< EOT > :: operator()( eoPop < EOT >& __pop )
00177 {
00178
00179 printDebugMessage( "peoTransform: performing the parallel transformation step." );
00180 pop = &__pop;
00181 idx = 0;
00182 num_term = 0;
00183 requestResourceRequest( __pop.size() / 2 );
00184 stop();
00185 }
00186
00187
00188 template< class EOT > void peoTransform< EOT > :: notifySendingData()
00189 {}
00190
00191
00192 template< class EOT > void peoTransform< EOT > :: notifySendingAllResourceRequests()
00193 {
00194
00195 getOwner()->setPassive();
00196 }
00197
00198
00199 #endif