peoParaPopEval.h

00001 /* 
00002 * <peoParaPopEval.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 __peoParaPopEval_h
00038 #define __peoParaPopEval_h
00039 
00040 #include <queue>
00041 #include <eoEvalFunc.h>
00042 
00043 #include "core/messaging.h"
00044 #include "core/peo_debug.h"
00045 #include "peoAggEvalFunc.h"
00046 #include "peoNoAggEvalFunc.h"
00047 
00048 
00050 
00054 template< class EOT > class peoParaPopEval : public peoPopEval< EOT > {
00055 
00056 public:
00057 
00058         using peoPopEval< EOT > :: requestResourceRequest;
00059         using peoPopEval< EOT > :: resume;
00060         using peoPopEval< EOT > :: stop;
00061         using peoPopEval< EOT > :: getOwner;
00062         
00067         peoParaPopEval( eoEvalFunc< EOT >& __eval_func );
00068 
00073         peoParaPopEval( const std :: vector< eoEvalFunc < EOT >* >& __funcs, peoAggEvalFunc< EOT >& __merge_eval );
00074 
00078         void operator()( eoPop< EOT >& __pop );
00079 
00082         void packData();
00083         
00086         void unpackData();
00087 
00089         void execute();
00090         
00093         void packResult();
00094         
00097         void unpackResult();
00098         
00101         void notifySendingData();
00102 
00105         void notifySendingAllResourceRequests();
00106 
00107 private:
00108 
00109 
00110         const std :: vector< eoEvalFunc < EOT >* >& funcs;
00111         std :: vector< eoEvalFunc < EOT >* > one_func;
00112         
00113         peoAggEvalFunc< EOT >& merge_eval;
00114         peoNoAggEvalFunc< EOT > no_merge_eval;
00115         
00116         std :: queue< EOT* >tasks;
00117         
00118         std :: map< EOT*, std :: pair< unsigned, unsigned > > progression;
00119         
00120         unsigned num_func;
00121         
00122         EOT sol;
00123         
00124         EOT *ad_sol;
00125         
00126         unsigned total;
00127 };
00128 
00129 
00130 template< class EOT > peoParaPopEval< EOT > :: peoParaPopEval( eoEvalFunc< EOT >& __eval_func ) : 
00131 
00132                 funcs( one_func ), merge_eval( no_merge_eval )
00133 {
00134 
00135         one_func.push_back( &__eval_func );
00136 }
00137 
00138 
00139 template< class EOT > peoParaPopEval< EOT > :: peoParaPopEval( 
00140 
00141                                 const std :: vector< eoEvalFunc< EOT >* >& __funcs,
00142                                 peoAggEvalFunc< EOT >& __merge_eval 
00143 
00144                 ) : funcs( __funcs ), merge_eval( __merge_eval )
00145 {
00146 
00147 }
00148 
00149 
00150 template< class EOT > void peoParaPopEval< EOT >::operator()( eoPop< EOT >& __pop ) {
00151   for ( unsigned i = 0; i < __pop.size(); i++ ) {
00152     __pop[ i ].fitness(typename EOT :: Fitness() );     
00153                 progression[ &__pop[ i ] ].first = funcs.size() - 1;
00154                 progression[ &__pop[ i ] ].second = funcs.size();
00155                 for ( unsigned j = 0; j < funcs.size(); j++ ) {
00156                         /* Queuing the 'invalid' solution and its associated owner */
00157                         tasks.push( &__pop[ i ] );
00158                 }
00159         }
00160         total = funcs.size() * __pop.size();
00161         requestResourceRequest( funcs.size() * __pop.size() );
00162         stop();
00163 }
00164 
00165 
00166 template< class EOT > void peoParaPopEval< EOT > :: packData() {
00167         //  printDebugMessage ("debut pakc data");
00168         pack( progression[ tasks.front() ].first-- );
00169         
00170         /* Packing the contents :-) of the solution */
00171         pack( *tasks.front() );
00172         
00173         /* Packing the addresses of both the solution and the owner */
00174         pack( tasks.front() );
00175         tasks.pop(  );
00176 }
00177 
00178 
00179 template< class EOT > void peoParaPopEval< EOT > :: unpackData() {
00180         unpack( num_func );
00181         /* Unpacking the solution */
00182         unpack( sol );
00183         /* Unpacking the @ of that one */
00184         unpack( ad_sol );
00185 }
00186 
00187 
00188 template< class EOT > void peoParaPopEval< EOT > :: execute() {
00189         /* Computing the fitness of the solution */
00190   funcs[ num_func ]->operator()( sol );
00191 }
00192 
00193 
00194 template< class EOT > void peoParaPopEval< EOT > :: packResult() {
00195   /* Packing the fitness of the solution */
00196         pack( sol.fitness() );
00197         /* Packing the @ of the individual */
00198         pack( ad_sol );
00199 }
00200 
00201 
00202 template< class EOT > void peoParaPopEval< EOT > :: unpackResult() {
00203         typename EOT :: Fitness fit;
00204         
00205         /* Unpacking the computed fitness */
00206         unpack( fit );
00207                 
00208         /* Unpacking the @ of the associated individual */
00209         unpack( ad_sol );
00210         
00211         
00212         /* Associating the fitness the local solution */
00213         merge_eval( *ad_sol, fit );
00214 
00215         progression[ ad_sol ].second--;
00216 
00217         /* Notifying the container of the termination of the evaluation */
00218         if ( !progression[ ad_sol ].second ) {
00219 
00220                 progression.erase( ad_sol );
00221         }
00222         
00223         total--;
00224         if ( !total ) {
00225 
00226                 getOwner()->setActive();
00227                 resume();
00228         }
00229 }
00230 
00231 
00232 template< class EOT > void peoParaPopEval< EOT > :: notifySendingData() {
00233 }
00234 
00235 
00236 template< class EOT > void peoParaPopEval< EOT > :: notifySendingAllResourceRequests() {
00237         getOwner()->setPassive();
00238 }
00239 
00240 
00241 #endif

Generated on Fri Oct 12 15:19:19 2007 for ParadisEO-PEO:ParallelandDistributedEvolvingObjects by  doxygen 1.4.7