00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef __peoPopEval_h
00038 #define __peoPopEval_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
00053 template< class EOT > class peoPopEval : public Service, public eoPopEvalFunc<EOT>
00054 {
00055
00056 public:
00057
00062 peoPopEval( eoEvalFunc< EOT >& __eval_func );
00063
00068 peoPopEval( const std :: vector< eoEvalFunc < EOT >* >& __funcs, peoAggEvalFunc< EOT >& __merge_eval );
00069
00073 void operator()(eoPop< EOT >& __pop);
00074
00078 void operator()( eoPop< EOT >& __dummy, 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
00119 const std :: vector< eoEvalFunc < EOT >* >& funcs;
00120 std :: vector< eoEvalFunc < EOT >* > one_func;
00121 peoAggEvalFunc< EOT >& merge_eval;
00122 peoNoAggEvalFunc< EOT > no_merge_eval;
00123 std :: queue< EOT* >tasks;
00124 std :: map< EOT*, std :: pair< unsigned, unsigned > > progression;
00125 unsigned num_func;
00126 EOT sol;
00127 EOT *ad_sol;
00128 unsigned total;
00129 };
00130
00131
00132 template< class EOT > peoPopEval< EOT > :: peoPopEval( eoEvalFunc< EOT >& __eval_func ) :
00133
00134 funcs( one_func ), merge_eval( no_merge_eval )
00135 {
00136
00137 one_func.push_back( &__eval_func );
00138 }
00139
00140
00141 template< class EOT > peoPopEval< EOT > :: peoPopEval(
00142
00143 const std :: vector< eoEvalFunc< EOT >* >& __funcs,
00144 peoAggEvalFunc< EOT >& __merge_eval
00145
00146 ) : funcs( __funcs ), merge_eval( __merge_eval )
00147 {}
00148
00149 template< class EOT > void peoPopEval< EOT >::operator()(eoPop< EOT >& __dummy, eoPop< EOT >& __pop )
00150 {
00151 this->operator()(__pop);
00152 }
00153
00154 template< class EOT > void peoPopEval< EOT >::operator()(eoPop< EOT >& __pop )
00155 {
00156 if ( __pop.size() && (funcs.size() * __pop.size()) )
00157 {
00158 for ( unsigned i = 0; i < __pop.size(); i++ )
00159 {
00160 __pop[ i ].fitness(typename EOT :: Fitness() );
00161 progression[ &__pop[ i ] ].first = funcs.size() - 1;
00162 progression[ &__pop[ i ] ].second = funcs.size();
00163 for ( unsigned j = 0; j < funcs.size(); j++ )
00164 {
00165
00166 tasks.push( &__pop[ i ] );
00167 }
00168 }
00169 total = funcs.size() * __pop.size();
00170 requestResourceRequest( funcs.size() * __pop.size() );
00171 stop();
00172 }
00173 }
00174
00175
00176 template< class EOT > void peoPopEval< EOT > :: packData()
00177 {
00178
00179 pack( progression[ tasks.front() ].first-- );
00180
00181
00182 pack( *tasks.front() );
00183
00184
00185 pack( tasks.front() );
00186 tasks.pop( );
00187 }
00188
00189
00190 template< class EOT > void peoPopEval< EOT > :: unpackData()
00191 {
00192 unpack( num_func );
00193
00194 unpack( sol );
00195
00196 unpack( ad_sol );
00197 }
00198
00199
00200 template< class EOT > void peoPopEval< EOT > :: execute()
00201 {
00202
00203
00204 funcs[ num_func ]->operator()( sol );
00205 }
00206
00207
00208 template< class EOT > void peoPopEval< EOT > :: packResult()
00209 {
00210
00211 pack( sol.fitness() );
00212
00213 pack( ad_sol );
00214 }
00215
00216
00217 template< class EOT > void peoPopEval< EOT > :: unpackResult()
00218 {
00219 typename EOT :: Fitness fit;
00220
00221
00222 unpack( fit );
00223
00224
00225 unpack( ad_sol );
00226
00227
00228
00229 merge_eval( *ad_sol, fit );
00230
00231 progression[ ad_sol ].second--;
00232
00233
00234 if ( !progression[ ad_sol ].second )
00235 {
00236
00237 progression.erase( ad_sol );
00238 }
00239
00240 total--;
00241 if ( !total )
00242 {
00243
00244 getOwner()->setActive();
00245 resume();
00246 }
00247 }
00248
00249
00250 template< class EOT > void peoPopEval< EOT > :: notifySendingData()
00251 {}
00252
00253
00254 template< class EOT > void peoPopEval< EOT > :: notifySendingAllResourceRequests()
00255 {
00256 getOwner()->setPassive();
00257 }
00258
00259
00260 #endif