/home/coin/SVN-release/CoinAll-1.1.0/Alps/src/AlpsParams.h

Go to the documentation of this file.
00001 /*===========================================================================*
00002  * This file is part of the Abstract Library for Parallel Search (ALPS).     *
00003  *                                                                           *
00004  * ALPS is distributed under the Common Public License as part of the        *
00005  * COIN-OR repository (http://www.coin-or.org).                              *
00006  *                                                                           *
00007  * Authors:                                                                  *
00008  *                                                                           *
00009  *          Yan Xu, Lehigh University                                        *
00010  *          Ted Ralphs, Lehigh University                                    *
00011  *                                                                           *
00012  * Conceptual Design:                                                        *
00013  *                                                                           *
00014  *          Yan Xu, Lehigh University                                        *
00015  *          Ted Ralphs, Lehigh University                                    *
00016  *          Laszlo Ladanyi, IBM T.J. Watson Research Center                  *
00017  *          Matthew Saltzman, Clemson University                             *
00018  *                                                                           * 
00019  *                                                                           *
00020  * Copyright (C) 2001-2007, Lehigh University, Yan Xu, and Ted Ralphs.       *
00021  *===========================================================================*/
00022 
00023 #ifndef AlpsParams_h
00024 #define AlpsParams_h
00025 
00026 #include "AlpsKnowledge.h"
00027 #include "AlpsParameterBase.h"
00028 
00029 // TODO: remove largeSize, mediumSize, smallSize
00030 
00031 //#############################################################################
00032 
00033 //class AlpsEncoded;
00034 
00035 //** Parameters used in Alps. */
00036 class AlpsParams : public AlpsParameterSet {
00037  public:
00040   enum boolParams
00041   {
00044       checkMemory,
00047       deleteDeadNode,
00050       interClusterBalance,
00053       intraClusterBalance,
00057       printSolution,
00058       /***/
00059       endOfBoolParams
00060   };
00061 
00063   enum intParams
00064   {
00067       bufSpare,
00071       clockType,
00074       eliteSize,
00077       hubInitNodeNum,
00082       hubMsgLevel,
00085       hubNum,
00088       largeSize,
00092       logFileLevel,
00095       masterInitNodeNum,
00098       masterReportInterval,
00102       hubWorkClusterSizeLimit,
00105       mediumSize,
00110       msgLevel,
00113       nodeLimit,
00116       nodeLogInterval,
00120       processNum,
00125       staticBalanceScheme,
00134       searchStrategy,
00135       searchStrategyRampUp,
00138       smallSize, 
00141       solLimit,
00144       unitWorkNodes,
00149       workerMsgLevel,
00151       endOfIntParams
00152   };
00153   
00155   enum dblParams
00156   {
00160       changeWorkThreshold,
00165       donorThreshold,
00168       hubReportPeriod,
00171       masterBalancePeriod,
00174       needWorkThreshold,
00178       receiverThreshold,
00181       timeLimit,
00184       tolerance,
00187       unitWorkTime, 
00190       zeroLoad,
00191       /***/
00192       endOfDblParams
00193   };
00194 
00196   enum strParams
00197   {
00200       instance,
00203       logFile,
00205       endOfStrParams
00206   };
00207 
00209   enum strArrayParams
00210   {
00211       // The dummy is needed so the allocation won't try for 0 entries.
00212       strArrayDummy,
00214       endOfStrArrayParams
00215   };
00216 
00217  public:
00218 
00224   AlpsParams() :
00225       AlpsParameterSet(
00226           static_cast<int>(endOfBoolParams),
00227           static_cast<int>(endOfIntParams),
00228           static_cast<int>(endOfDblParams),
00229           static_cast<int>(endOfStrParams),
00230           static_cast<int>(endOfStrArrayParams)
00231           )
00232   {
00233       createKeywordList();
00234       setDefaultEntries();
00235   }
00238       virtual ~AlpsParams(){  }
00239       
00240   
00241       AlpsParams& operator=(const AlpsParams& x) {
00242           // no need to delete anything, since the size of (almost) everything is
00243           // the same, just copy over
00244           // -- The static_cast is needed to satisfy the more picky IBM Visual Age
00245           //    C++ compiler
00246           std::copy(x.bpar_, x.bpar_ + static_cast<int>(endOfBoolParams),
00247                     bpar_);
00248           std::copy(x.ipar_, x.ipar_ + static_cast<int>(endOfIntParams),
00249                     ipar_);
00250           std::copy(x.dpar_, x.dpar_ + static_cast<int>(endOfDblParams),
00251                     dpar_);
00252           std::copy(x.spar_, x.spar_ + static_cast<int>(endOfStrParams),
00253                     spar_);
00254           std::copy(x.sapar_,
00255                     x.sapar_ + static_cast<int>(endOfStrArrayParams),
00256                     sapar_);
00257           return *this;
00258       }
00259       
00262       virtual void createKeywordList();
00264       virtual void setDefaultEntries();
00265 
00266 public:
00267       //====================================================
00279       //====================================================
00280  
00281 
00289 
00290       inline bool entry(const boolParams key) const { return bpar_[key]; }
00292       inline int entry(const intParams key) const { return ipar_[key]; }
00294       inline double entry(const dblParams key) const { return dpar_[key]; }
00296       inline const std::string&
00297           entry(const strParams key) const { return spar_[key]; }
00299       inline const std::vector<std::string>&
00300           entry(const strArrayParams key) const { return sapar_[key]; }
00303       //----------------------------------------------------
00304 
00306       void setEntry(const boolParams key, const char * val) {
00307                   bpar_[key] = atoi(val) ? true : false; }
00309       void setEntry(const boolParams key, const char val) {
00310                   bpar_[key] = val ? true : false; }
00312       void setEntry(const boolParams key, const bool val) {
00313           bpar_[key] = val; }
00315       void setEntry(const intParams key, const char * val) {
00316           ipar_[key] = atoi(val); }
00318       void setEntry(const intParams key, const int val) {
00319           ipar_[key] = val; }
00321       void setEntry(const dblParams key, const char * val) {
00322           dpar_[key] = atof(val); }
00324       void setEntry(const dblParams key, const double val) {
00325           dpar_[key] = val; }
00327       void setEntry(const strParams key, const char * val) {
00328           spar_[key] = val; }
00330       void setEntry(const strArrayParams key, const char *val) {
00331           sapar_[key].push_back(val); }
00332       
00333       //----------------------------------------------------
00334 
00338       void pack(AlpsEncoded& buf) {
00339           buf.writeRep(bpar_, endOfBoolParams)
00340               .writeRep(ipar_, endOfIntParams)
00341               .writeRep(dpar_, endOfDblParams);
00342           for (int i = 0; i < endOfStrParams; ++i)
00343               buf.writeRep(spar_[i]);
00344           for (int i = 0; i < endOfStrArrayParams; ++i) {
00345               buf.writeRep(sapar_[i].size());
00346               for (size_t j = 0; j < sapar_[i].size(); ++j)
00347                   buf.writeRep(sapar_[i][j]);
00348           }
00349       }
00350 
00352       void unpack(AlpsEncoded& buf) {
00353           int dummy;
00354           // No need to allocate the arrays, they are of fixed length
00355           dummy = static_cast<int>(endOfBoolParams);
00356           buf.readRep(bpar_, dummy, false);
00357           dummy = static_cast<int>(endOfIntParams);
00358           buf.readRep(ipar_, dummy, false);
00359           dummy = static_cast<int>(endOfDblParams);
00360           buf.readRep(dpar_, dummy, false);
00361           for (int i = 0; i < endOfStrParams; ++i)
00362               buf.readRep(spar_[i]);
00363           for (int i = 0; i < endOfStrArrayParams; ++i) {
00364               size_t str_size;
00365               buf.readRep(str_size);
00366               sapar_[i].reserve(str_size);
00367               for (size_t j = 0; j < str_size; ++j){
00368                   //    sapar_[i].unchecked_push_back(std::string());
00369                   sapar_[i].push_back(std::string());
00370                   buf.readRep(sapar_[i].back());
00371               }
00372           }
00373       }
00375 };
00376 
00377 #endif
00378 

Generated on Sun Nov 14 14:06:28 2010 for Coin-All by  doxygen 1.4.7