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 00152 for ( unsigned i = 0; i < __pop.size(); i++ ) { 00153 00154 __pop[ i ].fitness( typename EOT :: Fitness() ); 00155 00156 progression[ &__pop[ i ] ].first = funcs.size() - 1; 00157 progression[ &__pop[ i ] ].second = funcs.size(); 00158 00159 for ( unsigned j = 0; j < funcs.size(); j++ ) { 00160 /* Queuing the 'invalid' solution and its associated owner */ 00161 tasks.push( &__pop[ i ] ); 00162 } 00163 } 00164 00165 total = funcs.size() * __pop.size(); 00166 requestResourceRequest( funcs.size() * __pop.size() ); 00167 stop(); 00168 } 00169 00170 00171 template< class EOT > void peoParaPopEval< EOT > :: packData() { 00172 00173 // printDebugMessage ("debut pakc data"); 00174 pack( progression[ tasks.front() ].first-- ); 00175 00176 /* Packing the contents :-) of the solution */ 00177 pack( *tasks.front() ); 00178 00179 /* Packing the addresses of both the solution and the owner */ 00180 pack( tasks.front() ); 00181 tasks.pop( ); 00182 } 00183 00184 00185 template< class EOT > void peoParaPopEval< EOT > :: unpackData() { 00186 00187 unpack( num_func ); 00188 /* Unpacking the solution */ 00189 unpack( sol ); 00190 /* Unpacking the @ of that one */ 00191 unpack( ad_sol ); 00192 } 00193 00194 00195 template< class EOT > void peoParaPopEval< EOT > :: execute() { 00196 00197 /* Computing the fitness of the solution */ 00198 funcs[ num_func ]->operator()( sol ); 00199 } 00200 00201 00202 template< class EOT > void peoParaPopEval< EOT > :: packResult() { 00203 00204 /* Packing the fitness of the solution */ 00205 pack( sol.fitness() ); 00206 /* Packing the @ of the individual */ 00207 pack( ad_sol ); 00208 } 00209 00210 00211 template< class EOT > void peoParaPopEval< EOT > :: unpackResult() { 00212 00213 typename EOT :: Fitness fit; 00214 00215 /* Unpacking the computed fitness */ 00216 unpack( fit ); 00217 00218 /* Unpacking the @ of the associated individual */ 00219 unpack( ad_sol ); 00220 00221 00222 /* Associating the fitness the local solution */ 00223 merge_eval( *ad_sol, fit ); 00224 00225 progression[ ad_sol ].second--; 00226 00227 /* Notifying the container of the termination of the evaluation */ 00228 if ( !progression[ ad_sol ].second ) { 00229 00230 progression.erase( ad_sol ); 00231 } 00232 00233 total--; 00234 if ( !total ) { 00235 00236 getOwner()->setActive(); 00237 resume(); 00238 } 00239 } 00240 00241 00242 template< class EOT > void peoParaPopEval< EOT > :: notifySendingData() { 00243 00244 } 00245 00246 00247 template< class EOT > void peoParaPopEval< EOT > :: notifySendingAllResourceRequests() { 00248 00249 getOwner()->setPassive(); 00250 } 00251 00252 00253 #endif