peoParaSGATransform.h

00001 /* 
00002 * <peoParaSGATransform.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
00005 *
00006 * Sebastien Cahon, Alexandru-Adrian Tantar
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * data to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
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

Generated on Mon Oct 8 11:16:46 2007 for ParadisEO-PEOMovingObjects by  doxygen 1.4.7