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 __peoSyncMultiStart_h
00038 #define __peoSyncMultiStart_h
00039
00040 #include <utils/eoUpdater.h>
00041 #include <moAlgo.h>
00042
00043 #include <eoSelect.h>
00044 #include <eoReplacement.h>
00045 #include <eoContinue.h>
00046
00047 #include "core/service.h"
00048 #include "core/messaging.h"
00049 #include "core/peo_debug.h"
00050
00051
00052 extern int getNodeRank();
00053
00054
00056
00064 template< class EOT > class peoSyncMultiStart : public Service, public eoUpdater {
00065
00066 public:
00067
00075 peoSyncMultiStart(
00076
00077 eoContinue< EOT >& __cont,
00078 eoSelect< EOT >& __select,
00079 eoReplacement< EOT >& __replace,
00080 moAlgo< EOT >& __ls,
00081 eoPop< EOT >& __pop
00082 );
00083
00086 void operator()();
00087
00090 void packData();
00091
00094 void unpackData();
00095
00098 void execute();
00099
00102 void packResult();
00103
00106 void unpackResult();
00107
00110 void notifySendingData();
00111
00114 void notifySendingAllResourceRequests();
00115
00116 private:
00117
00118 eoContinue< EOT >& cont;
00119 eoSelect< EOT >& select;
00120 eoReplacement< EOT >& replace;
00121
00122 moAlgo< EOT >& ls;
00123
00124 eoPop< EOT >& pop;
00125 eoPop< EOT > sel;
00126 eoPop< EOT > impr_sel;
00127
00128 EOT sol;
00129 unsigned idx;
00130 unsigned num_term;
00131 };
00132
00133
00134 template< class EOT > peoSyncMultiStart< EOT > :: peoSyncMultiStart(
00135
00136 eoContinue < EOT >& __cont,
00137 eoSelect< EOT >& __select,
00138 eoReplacement< EOT >& __replace,
00139 moAlgo < EOT >& __ls,
00140 eoPop< EOT >& __pop
00141
00142 ) : cont( __cont ), select( __select ), replace( __replace ), ls( __ls ), pop( __pop )
00143 {
00144
00145 }
00146
00147
00148 template< class EOT > void peoSyncMultiStart< EOT > :: packData() {
00149
00150 :: pack( sel[ idx++ ] );
00151 }
00152
00153
00154 template< class EOT > void peoSyncMultiStart< EOT > :: unpackData() {
00155
00156 unpack( sol );
00157 }
00158
00159
00160 template< class EOT > void peoSyncMultiStart< EOT > :: execute() {
00161
00162 ls( sol );
00163 }
00164
00165
00166 template< class EOT > void peoSyncMultiStart< EOT > :: packResult() {
00167
00168 pack( sol );
00169 }
00170
00171
00172 template< class EOT > void peoSyncMultiStart< EOT > :: unpackResult() {
00173
00174 unpack( sol );
00175 impr_sel.push_back( sol );
00176 num_term++;
00177
00178 if ( num_term == sel.size() ) {
00179
00180 getOwner()->setActive();
00181 replace( pop, impr_sel );
00182
00183 printDebugMessage( "replacing the improved individuals in the population." );
00184 resume();
00185 }
00186 }
00187
00188
00189 template< class EOT > void peoSyncMultiStart< EOT > :: operator()() {
00190
00191 printDebugMessage( "performing the parallel multi-start hybridization." );
00192 select( pop, sel );
00193 impr_sel.clear();
00194 idx = num_term = 0;
00195 requestResourceRequest( sel.size() );
00196 stop();
00197 }
00198
00199
00200 template< class EOT > void peoSyncMultiStart< EOT > :: notifySendingData() {
00201
00202 }
00203
00204
00205 template< class EOT > void peoSyncMultiStart< EOT > :: notifySendingAllResourceRequests() {
00206
00207 getOwner()->setPassive();
00208 }
00209
00210
00211 #endif