peoTransform.h

00001 /*
00002 * <peoTransform.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
00004 * (C) OPAC Team, LIFL, 2002-2008
00005 *
00006 * Sebastien Cahon, Alexandru-Adrian Tantar, Clive Canape
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 __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   // Can be used with an odd size
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

Generated on Thu Mar 13 15:55:03 2008 for ParadisEO-PEO-ParallelanddistributedEvolvingObjects by  doxygen 1.4.7