00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __peoSyncMultiStart_h
00010 #define __peoSyncMultiStart_h
00011
00012 #include <utils/eoUpdater.h>
00013 #include <moAlgo.h>
00014
00015 #include <eoSelect.h>
00016 #include <eoReplacement.h>
00017 #include <eoContinue.h>
00018
00019 #include "core/service.h"
00020 #include "core/messaging.h"
00021 #include "core/peo_debug.h"
00022
00023
00024 extern int getNodeRank();
00025
00026
00028
00036 template< class EOT > class peoSyncMultiStart : public Service, public eoUpdater {
00037
00038 public:
00039
00047 peoSyncMultiStart(
00048
00049 eoContinue< EOT >& __cont,
00050 eoSelect< EOT >& __select,
00051 eoReplacement< EOT >& __replace,
00052 moAlgo< EOT >& __ls,
00053 eoPop< EOT >& __pop
00054 );
00055
00058 void operator()();
00059
00062 void packData();
00063
00066 void unpackData();
00067
00070 void execute();
00071
00074 void packResult();
00075
00078 void unpackResult();
00079
00082 void notifySendingData();
00083
00086 void notifySendingAllResourceRequests();
00087
00088 private:
00089
00090 eoContinue< EOT >& cont;
00091 eoSelect< EOT >& select;
00092 eoReplacement< EOT >& replace;
00093
00094 moAlgo< EOT >& ls;
00095
00096 eoPop< EOT >& pop;
00097 eoPop< EOT > sel;
00098 eoPop< EOT > impr_sel;
00099
00100 EOT sol;
00101 unsigned idx;
00102 unsigned num_term;
00103 };
00104
00105
00106 template< class EOT > peoSyncMultiStart< EOT > :: peoSyncMultiStart(
00107
00108 eoContinue < EOT >& __cont,
00109 eoSelect< EOT >& __select,
00110 eoReplacement< EOT >& __replace,
00111 moAlgo < EOT >& __ls,
00112 eoPop< EOT >& __pop
00113
00114 ) : cont( __cont ), select( __select ), replace( __replace ), ls( __ls ), pop( __pop )
00115 {
00116
00117 }
00118
00119
00120 template< class EOT > void peoSyncMultiStart< EOT > :: packData() {
00121
00122 :: pack( sel[ idx++ ] );
00123 }
00124
00125
00126 template< class EOT > void peoSyncMultiStart< EOT > :: unpackData() {
00127
00128 unpack( sol );
00129 }
00130
00131
00132 template< class EOT > void peoSyncMultiStart< EOT > :: execute() {
00133
00134 ls( sol );
00135 }
00136
00137
00138 template< class EOT > void peoSyncMultiStart< EOT > :: packResult() {
00139
00140 pack( sol );
00141 }
00142
00143
00144 template< class EOT > void peoSyncMultiStart< EOT > :: unpackResult() {
00145
00146 unpack( sol );
00147 impr_sel.push_back( sol );
00148 num_term++;
00149
00150 if ( num_term == sel.size() ) {
00151
00152 getOwner()->setActive();
00153 replace( pop, impr_sel );
00154
00155 printDebugMessage( "replacing the improved individuals in the population." );
00156 resume();
00157 }
00158 }
00159
00160
00161 template< class EOT > void peoSyncMultiStart< EOT > :: operator()() {
00162
00163 printDebugMessage( "performing the parallel multi-start hybridization." );
00164 select( pop, sel );
00165 impr_sel.clear();
00166 idx = num_term = 0;
00167 requestResourceRequest( sel.size() );
00168 stop();
00169 }
00170
00171
00172 template< class EOT > void peoSyncMultiStart< EOT > :: notifySendingData() {
00173
00174 }
00175
00176
00177 template< class EOT > void peoSyncMultiStart< EOT > :: notifySendingAllResourceRequests() {
00178
00179 getOwner()->setPassive();
00180 }
00181
00182
00183 #endif