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 __peoParaSGATransform_h
00038 #define __peoParaSGATransform_h
00039
00040 #include "peoTransform.h"
00041 #include "core/thread.h"
00042 #include "core/messaging.h"
00043 #include "core/peo_debug.h"
00044
00045
00046 extern int getNodeRank();
00047
00048
00049 template< class EOT > class peoParaSGATransform : public peoTransform< EOT > {
00050
00051 public:
00052
00053 using peoTransform< EOT > :: requestResourceRequest;
00054 using peoTransform< EOT > :: resume;
00055 using peoTransform< EOT > :: stop;
00056 using peoTransform< EOT > :: getOwner;
00057
00058 peoParaSGATransform(
00059
00060 eoQuadOp< EOT >& __cross,
00061 double __cross_rate,
00062 eoMonOp< EOT >& __mut,
00063 double __mut_rate
00064 );
00065
00066 void operator()( eoPop< EOT >& __pop );
00067
00068 void packData();
00069
00070 void unpackData();
00071
00072 void execute();
00073
00074 void packResult();
00075
00076 void unpackResult();
00077
00078 void notifySendingData();
00079 void notifySendingAllResourceRequests();
00080
00081 private:
00082
00083 eoQuadOp< EOT >& cross;
00084 double cross_rate;
00085
00086 eoMonOp< EOT >& mut;
00087 double mut_rate;
00088
00089 unsigned idx;
00090
00091 eoPop< EOT >* pop;
00092
00093 EOT father, mother;
00094
00095 unsigned num_term;
00096 };
00097
00098 template< class EOT > peoParaSGATransform< EOT > :: peoParaSGATransform(
00099
00100 eoQuadOp< EOT >& __cross,
00101 double __cross_rate,
00102 eoMonOp < EOT >& __mut,
00103 double __mut_rate
00104
00105 ) : cross( __cross ), cross_rate( __cross_rate ), mut( __mut ), mut_rate( __mut_rate )
00106 {
00107
00108 }
00109
00110
00111 template< class EOT > void peoParaSGATransform< EOT > :: packData() {
00112
00113 pack( idx );
00114 :: pack( pop->operator[]( idx++ ) );
00115 :: pack( pop->operator[]( idx++ ) );
00116 }
00117
00118
00119 template< class EOT > void peoParaSGATransform< EOT > :: unpackData() {
00120
00121 unpack( idx );
00122 :: unpack( father );
00123 :: unpack( mother );
00124 }
00125
00126
00127 template< class EOT > void peoParaSGATransform< EOT > :: execute() {
00128
00129 if( rng.uniform() < cross_rate ) cross( mother, father );
00130
00131 if( rng.uniform() < mut_rate ) mut( mother );
00132 if( rng.uniform() < mut_rate ) mut( father );
00133 }
00134
00135
00136 template< class EOT > void peoParaSGATransform< EOT > :: packResult() {
00137
00138 pack( idx );
00139 :: pack( father );
00140 :: pack( mother );
00141 }
00142
00143
00144 template< class EOT > void peoParaSGATransform< EOT > :: unpackResult() {
00145
00146 unsigned sidx;
00147
00148 unpack( sidx );
00149 :: unpack( pop->operator[]( sidx++ ) );
00150 :: unpack( pop->operator[]( sidx ) );
00151 num_term += 2;
00152
00153 if( num_term == pop->size() ) {
00154
00155 getOwner()->setActive();
00156 resume();
00157 }
00158 }
00159
00160
00161 template< class EOT > void peoParaSGATransform< EOT > :: operator()( eoPop < EOT >& __pop ) {
00162
00163 printDebugMessage( "performing the parallel transformation step." );
00164 pop = &__pop;
00165 idx = 0;
00166 num_term = 0;
00167 requestResourceRequest( __pop.size() / 2 );
00168 stop();
00169 }
00170
00171
00172 template< class EOT > void peoParaSGATransform< EOT > :: notifySendingData() {
00173
00174 }
00175
00176
00177 template< class EOT > void peoParaSGATransform< EOT > :: notifySendingAllResourceRequests() {
00178
00179 getOwner()->setPassive();
00180 }
00181
00182
00183 #endif