- Main Page
- Namespaces
- Classes
- Files

- Search for |

# peoSyncMultiStart.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 // "peoSyncMultiStart.h"
    00004
    00005 // (c) OPAC Team, LIFL, August 2005
    00006
    00007 /* This library is free software; you can redistribute it and/or
    00008    modify it under the terms of the GNU Lesser General Public
    00009    License as published by the Free Software Foundation; either
    00010    version 2 of the License, or (at your option) any later version.
    00011
    00012    This library is distributed in the hope that it will be useful,
    00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015    Lesser General Public License for more details.
    00016
    00017    You should have received a copy of the GNU Lesser General Public
    00018    License along with this library; if not, write to the Free Software
    00019    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    00020
    00021    Contact: paradiseo-help@lists.gforge.inria.fr
    00022 */
    00023
    00024 #ifndef __peoSyncMultiStart_h
    00025 #define __peoSyncMultiStart_h
    00026
    00027 #include <utils/eoUpdater.h>
    00028 #include <moAlgo.h>
    00029
    00030 #include <eoSelect.h>
    00031 #include <eoReplacement.h>
    00032 #include <eoContinue.h>
    00033
    00034 #include "core/service.h"
    00035 #include "core/messaging.h"
    00036 #include "core/peo_debug.h"
    00037
    00038
    00039 extern int getNodeRank();
    00040
    00041
    00043
    00051 template< class EOT > class peoSyncMultiStart : public Service, public eoUpdater {
    00052
    00053 public:
    00054
    00062         peoSyncMultiStart(
    00063
    00064                                 eoContinue< EOT >& __cont,
    00065                                 eoSelect< EOT >& __select,
    00066                                 eoReplacement< EOT >& __replace,
    00067                                 moAlgo< EOT >& __ls,
    00068                                 eoPop< EOT >& __pop
    00069                 );
    00070
    00073         void operator()();
    00074
    00077         void packData();
    00078
    00081         void unpackData();
    00082
    00085         void execute();
    00086
    00089         void packResult();
    00090
    00093         void unpackResult();
    00094
    00097         void notifySendingData();
    00098
    00101         void notifySendingAllResourceRequests();
    00102
    00103 private:
    00104
    00105         eoContinue< EOT >& cont;
    00106         eoSelect< EOT >& select;
    00107         eoReplacement< EOT >& replace;
    00108
    00109         moAlgo< EOT >& ls;
    00110
    00111         eoPop< EOT >& pop;
    00112         eoPop< EOT > sel;
    00113         eoPop< EOT > impr_sel;
    00114
    00115         EOT sol;
    00116         unsigned idx;
    00117         unsigned num_term;
    00118 };
    00119
    00120
    00121 template< class EOT > peoSyncMultiStart< EOT > :: peoSyncMultiStart(
    00122
    00123                                 eoContinue < EOT >& __cont,
    00124                                 eoSelect< EOT >& __select,
    00125                                 eoReplacement< EOT >& __replace,
    00126                                 moAlgo < EOT >& __ls,
    00127                                 eoPop< EOT >& __pop
    00128
    00129                 ) : cont( __cont ), select( __select ), replace( __replace ), ls( __ls ), pop( __pop )
    00130 {
    00131
    00132 }
    00133
    00134
    00135 template< class EOT > void peoSyncMultiStart< EOT > :: packData() {
    00136
    00137          :: pack( sel[ idx++ ] );
    00138 }
    00139
    00140
    00141 template< class EOT > void peoSyncMultiStart< EOT > :: unpackData() {
    00142
    00143         unpack( sol );
    00144 }
    00145
    00146
    00147 template< class EOT > void peoSyncMultiStart< EOT > :: execute() {
    00148
    00149         ls( sol );
    00150 }
    00151
    00152
    00153 template< class EOT > void peoSyncMultiStart< EOT > :: packResult() {
    00154
    00155         pack( sol );
    00156 }
    00157
    00158
    00159 template< class EOT > void peoSyncMultiStart< EOT > :: unpackResult() {
    00160
    00161         unpack( sol );
    00162         impr_sel.push_back( sol );
    00163         num_term++;
    00164
    00165         if ( num_term == sel.size() ) {
    00166
    00167                 getOwner()->setActive();
    00168                 replace( pop, impr_sel );
    00169
    00170                 printDebugMessage( "replacing the improved individuals in the population." );
    00171                 resume();
    00172         }
    00173 }
    00174
    00175
    00176 template< class EOT > void peoSyncMultiStart< EOT > :: operator()() {
    00177
    00178         printDebugMessage( "performing the parallel multi-start hybridization." );
    00179         select( pop, sel );
    00180         impr_sel.clear();
    00181         idx = num_term = 0;
    00182         requestResourceRequest( sel.size() );
    00183         stop();
    00184 }
    00185
    00186
    00187 template< class EOT > void peoSyncMultiStart< EOT > :: notifySendingData() {
    00188
    00189 }
    00190
    00191
    00192 template< class EOT > void peoSyncMultiStart< EOT > :: notifySendingAllResourceRequests() {
    00193
    00194         getOwner()->setPassive();
    00195 }
    00196
    00197
    00198 #endif