- Main Page
- Namespaces
- Classes
- Files

- Search for |

# peoParaSGATransform.h

    00001 // "peoParaSGATransform.h"
    00002
    00003 //(c) OPAC Team, LIFL, August 2005
    00004
    00005 /*
    00006    Contact: paradiseo-help@lists.gforge.inria.fr
    00007 */
    00008
    00009 #ifndef __peoParaSGATransform_h
    00010 #define __peoParaSGATransform_h
    00011
    00012 #include "peoTransform.h"
    00013 #include "core/thread.h"
    00014 #include "core/messaging.h"
    00015 #include "core/peo_debug.h"
    00016
    00017
    00018 extern int getNodeRank();
    00019
    00020
    00021 template< class EOT > class peoParaSGATransform : public peoTransform< EOT > {
    00022
    00023 public:
    00024
    00025         using peoTransform< EOT > :: requestResourceRequest;
    00026         using peoTransform< EOT > :: resume;
    00027         using peoTransform< EOT > :: stop;
    00028         using peoTransform< EOT > :: getOwner;
    00029
    00030         peoParaSGATransform(
    00031
    00032                                 eoQuadOp< EOT >& __cross,
    00033                                 double __cross_rate,
    00034                                 eoMonOp< EOT >& __mut,
    00035                                 double __mut_rate
    00036         );
    00037
    00038         void operator()( eoPop< EOT >& __pop );
    00039
    00040         void packData();
    00041
    00042         void unpackData();
    00043
    00044         void execute();
    00045
    00046         void packResult();
    00047
    00048         void unpackResult();
    00049
    00050         void notifySendingData();
    00051         void notifySendingAllResourceRequests();
    00052
    00053 private:
    00054
    00055     eoQuadOp< EOT >& cross;
    00056     double cross_rate;
    00057
    00058     eoMonOp< EOT >& mut;
    00059     double mut_rate;
    00060
    00061     unsigned idx;
    00062
    00063     eoPop< EOT >* pop;
    00064
    00065     EOT father, mother;
    00066
    00067     unsigned num_term;
    00068 };
    00069
    00070 template< class EOT > peoParaSGATransform< EOT > :: peoParaSGATransform(
    00071
    00072                                 eoQuadOp< EOT >& __cross,
    00073                                 double __cross_rate,
    00074                                 eoMonOp < EOT >& __mut,
    00075                                 double __mut_rate
    00076
    00077                 ) : cross( __cross ), cross_rate( __cross_rate ), mut( __mut ), mut_rate( __mut_rate )
    00078 {
    00079
    00080 }
    00081
    00082
    00083 template< class EOT > void peoParaSGATransform< EOT > :: packData() {
    00084
    00085         pack( idx );
    00086          :: pack( pop->operator[]( idx++ ) );
    00087          :: pack( pop->operator[]( idx++ ) );
    00088 }
    00089
    00090
    00091 template< class EOT > void peoParaSGATransform< EOT > :: unpackData() {
    00092
    00093         unpack( idx );
    00094          :: unpack( father );
    00095          :: unpack( mother );
    00096 }
    00097
    00098
    00099 template< class EOT > void peoParaSGATransform< EOT > :: execute() {
    00100
    00101         if( rng.uniform() < cross_rate ) cross( mother, father );
    00102
    00103         if( rng.uniform() < mut_rate ) mut( mother );
    00104         if( rng.uniform() < mut_rate ) mut( father );
    00105 }
    00106
    00107
    00108 template< class EOT > void peoParaSGATransform< EOT > :: packResult() {
    00109
    00110         pack( idx );
    00111          :: pack( father );
    00112          :: pack( mother );
    00113 }
    00114
    00115
    00116 template< class EOT > void peoParaSGATransform< EOT > :: unpackResult() {
    00117
    00118         unsigned sidx;
    00119
    00120         unpack( sidx );
    00121          :: unpack( pop->operator[]( sidx++ ) );
    00122          :: unpack( pop->operator[]( sidx ) );
    00123         num_term += 2;
    00124
    00125         if( num_term == pop->size() ) {
    00126
    00127                 getOwner()->setActive();
    00128                 resume();
    00129         }
    00130 }
    00131
    00132
    00133 template< class EOT > void peoParaSGATransform< EOT > :: operator()( eoPop < EOT >& __pop ) {
    00134
    00135         printDebugMessage( "performing the parallel transformation step." );
    00136         pop = &__pop;
    00137         idx = 0;
    00138         num_term = 0;
    00139         requestResourceRequest( __pop.size() / 2 );
    00140         stop();
    00141 }
    00142
    00143
    00144 template< class EOT > void peoParaSGATransform< EOT > :: notifySendingData() {
    00145
    00146 }
    00147
    00148
    00149 template< class EOT > void peoParaSGATransform< EOT > :: notifySendingAllResourceRequests() {
    00150
    00151         getOwner()->setPassive();
    00152 }
    00153
    00154
    00155 #endif