- Main Page
- Namespaces
- Classes
- Files

- Search for |

# peoParaPopEval.h

    00001 // "peoParaPopEval.h"
    00002
    00003 // (c) OPAC Team, LIFL, August 2005
    00004
    00005 /*
    00006    Contact: paradiseo-help@lists.gforge.inria.fr
    00007 */
    00008
    00009 #ifndef __peoParaPopEval_h
    00010 #define __peoParaPopEval_h
    00011
    00012 #include <queue>
    00013 #include <eoEvalFunc.h>
    00014
    00015 #include "core/messaging.h"
    00016 #include "core/peo_debug.h"
    00017 #include "peoAggEvalFunc.h"
    00018 #include "peoNoAggEvalFunc.h"
    00019
    00020
    00022
    00026 template< class EOT > class peoParaPopEval : public peoPopEval< EOT > {
    00027
    00028 public:
    00029
    00030         using peoPopEval< EOT > :: requestResourceRequest;
    00031         using peoPopEval< EOT > :: resume;
    00032         using peoPopEval< EOT > :: stop;
    00033         using peoPopEval< EOT > :: getOwner;
    00034
    00039         peoParaPopEval( eoEvalFunc< EOT >& __eval_func );
    00040
    00045         peoParaPopEval( const std :: vector< eoEvalFunc < EOT >* >& __funcs, peoAggEvalFunc< EOT >& __merge_eval );
    00046
    00050         void operator()( eoPop< EOT >& __pop );
    00051
    00054         void packData();
    00055
    00058         void unpackData();
    00059
    00061         void execute();
    00062
    00065         void packResult();
    00066
    00069         void unpackResult();
    00070
    00073         void notifySendingData();
    00074
    00077         void notifySendingAllResourceRequests();
    00078
    00079 private:
    00080
    00081
    00082         const std :: vector< eoEvalFunc < EOT >* >& funcs;
    00083         std :: vector< eoEvalFunc < EOT >* > one_func;
    00084
    00085         peoAggEvalFunc< EOT >& merge_eval;
    00086         peoNoAggEvalFunc< EOT > no_merge_eval;
    00087
    00088         std :: queue< EOT* >tasks;
    00089
    00090         std :: map< EOT*, std :: pair< unsigned, unsigned > > progression;
    00091
    00092         unsigned num_func;
    00093
    00094         EOT sol;
    00095
    00096         EOT *ad_sol;
    00097
    00098         unsigned total;
    00099 };
    00100
    00101
    00102 template< class EOT > peoParaPopEval< EOT > :: peoParaPopEval( eoEvalFunc< EOT >& __eval_func ) :
    00103
    00104                 funcs( one_func ), merge_eval( no_merge_eval )
    00105 {
    00106
    00107         one_func.push_back( &__eval_func );
    00108 }
    00109
    00110
    00111 template< class EOT > peoParaPopEval< EOT > :: peoParaPopEval(
    00112
    00113                                 const std :: vector< eoEvalFunc< EOT >* >& __funcs,
    00114                                 peoAggEvalFunc< EOT >& __merge_eval
    00115
    00116                 ) : funcs( __funcs ), merge_eval( __merge_eval )
    00117 {
    00118
    00119 }
    00120
    00121
    00122 template< class EOT > void peoParaPopEval< EOT >::operator()( eoPop< EOT >& __pop ) {
    00123
    00124         for ( unsigned i = 0; i < __pop.size(); i++ ) {
    00125
    00126                 __pop[ i ].fitness( typename EOT :: Fitness() );
    00127
    00128                 progression[ &__pop[ i ] ].first = funcs.size() - 1;
    00129                 progression[ &__pop[ i ] ].second = funcs.size();
    00130
    00131                 for ( unsigned j = 0; j < funcs.size(); j++ ) {
    00132                         /* Queuing the 'invalid' solution and its associated owner */
    00133                         tasks.push( &__pop[ i ] );
    00134                 }
    00135         }
    00136
    00137         total = funcs.size() * __pop.size();
    00138         requestResourceRequest( funcs.size() * __pop.size() );
    00139         stop();
    00140 }
    00141
    00142
    00143 template< class EOT > void peoParaPopEval< EOT > :: packData() {
    00144
    00145         //  printDebugMessage ("debut pakc data");
    00146         pack( progression[ tasks.front() ].first-- );
    00147
    00148         /* Packing the contents :-) of the solution */
    00149         pack( *tasks.front() );
    00150
    00151         /* Packing the addresses of both the solution and the owner */
    00152         pack( tasks.front() );
    00153         tasks.pop(  );
    00154 }
    00155
    00156
    00157 template< class EOT > void peoParaPopEval< EOT > :: unpackData() {
    00158
    00159         unpack( num_func );
    00160         /* Unpacking the solution */
    00161         unpack( sol );
    00162         /* Unpacking the @ of that one */
    00163         unpack( ad_sol );
    00164 }
    00165
    00166
    00167 template< class EOT > void peoParaPopEval< EOT > :: execute() {
    00168
    00169         /* Computing the fitness of the solution */
    00170         funcs[ num_func ]->operator()( sol );
    00171 }
    00172
    00173
    00174 template< class EOT > void peoParaPopEval< EOT > :: packResult() {
    00175
    00176         /* Packing the fitness of the solution */
    00177         pack( sol.fitness() );
    00178         /* Packing the @ of the individual */
    00179         pack( ad_sol );
    00180 }
    00181
    00182
    00183 template< class EOT > void peoParaPopEval< EOT > :: unpackResult() {
    00184
    00185         typename EOT :: Fitness fit;
    00186
    00187         /* Unpacking the computed fitness */
    00188         unpack( fit );
    00189
    00190         /* Unpacking the @ of the associated individual */
    00191         unpack( ad_sol );
    00192
    00193
    00194         /* Associating the fitness the local solution */
    00195         merge_eval( *ad_sol, fit );
    00196
    00197         progression[ ad_sol ].second--;
    00198
    00199         /* Notifying the container of the termination of the evaluation */
    00200         if ( !progression[ ad_sol ].second ) {
    00201
    00202                 progression.erase( ad_sol );
    00203         }
    00204
    00205         total--;
    00206         if ( !total ) {
    00207
    00208                 getOwner()->setActive();
    00209                 resume();
    00210         }
    00211 }
    00212
    00213
    00214 template< class EOT > void peoParaPopEval< EOT > :: notifySendingData() {
    00215
    00216 }
    00217
    00218
    00219 template< class EOT > void peoParaPopEval< EOT > :: notifySendingAllResourceRequests() {
    00220
    00221         getOwner()->setPassive();
    00222 }
    00223
    00224
    00225 #endif