- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/svn-release/Blis-0.93.2/Alps/examples/Knap/KnapParams.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 Eclipse Public License as part of the       *
    00005  * COIN-OR repository (http://www.coin-or.org).                              *
    00006  *                                                                           *
    00007  * Authors: Yan Xu, Lehigh University                                       *
    00008  *          Ted Ralphs, Lehigh University                                    *
    00009  *          Laszlo Ladanyi, IBM T.J. Watson Research Center                  *
    00010  *          Matthew Saltzman, Clemson University                             *
    00011  *                                                                           *
    00012  *                                                                           *
    00013  * Copyright (C) 2001-2011, Lehigh University, Yan Xu, and Ted Ralphs.       *
    00014  *===========================================================================*/
    00015
    00016 #ifndef KnapParams_h
    00017 #define KnapParams_h
    00018
    00019 #include "AlpsKnowledge.h"
    00020 #include "AlpsParameterBase.h"
    00021
    00022
    00023 //#############################################################################
    00024 //#############################################################################
    00025 //** Parameters used in Knap. */
    00026 class KnapParams : public AlpsParameterSet {
    00027  public:
    00030   enum chrParams{
    00031     // The dummy is needed so the allocation won't try for 0 entries.
    00032     chrDummy,
    00033     //
    00034     endOfChrParams
    00035   };
    00036
    00038   enum intParams{
    00039     intDummy,
    00040     //
    00041     endOfIntParams
    00042   };
    00043
    00045   enum dblParams{
    00046     dblDummy,
    00047     //
    00048     endOfDblParams
    00049   };
    00050
    00052   enum strParams{
    00053     strDummy,
    00054     //
    00055     endOfStrParams
    00056   };
    00057
    00059   enum strArrayParams{
    00060     strArrayDummy,
    00061     //
    00062     endOfStrArrayParams
    00063   };
    00064
    00065  public:
    00071   KnapParams() :
    00072     AlpsParameterSet(
    00073     static_cast<int>(endOfChrParams),
    00074     static_cast<int>(endOfIntParams),
    00075     static_cast<int>(endOfDblParams),
    00076     static_cast<int>(endOfStrParams),
    00077     static_cast<int>(endOfStrArrayParams)
    00078     )
    00079     {
    00080       createKeywordList();
    00081       setDefaultEntries();
    00082     }
    00087   virtual void createKeywordList();
    00089   virtual void setDefaultEntries();
    00093  public:
    00094   //===========================================================================
    00102   //===========================================================================
    00103
    00104
    00113
    00114   inline char
    00115     entry(const chrParams key) const { return bpar_[key]; }
    00117   inline int
    00118     entry(const intParams key) const { return ipar_[key]; }
    00120   inline double
    00121     entry(const dblParams key) const { return dpar_[key]; }
    00123   inline const std::string&
    00124     entry(const strParams key) const { return spar_[key]; }
    00126   inline const std::vector<std::string>&
    00127     entry(const strArrayParams key) const { return sapar_[key]; }
    00130   //---------------------------------------------------------------------------
    00132   void setEntry(const chrParams key, const char * val) {
    00133           bpar_[key] = atoi(val) ? true : false; }
    00135   void setEntry(const chrParams key, const char val) {
    00136           bpar_[key] = val ? true : false; }
    00138   void setEntry(const chrParams key, const bool val) {
    00139     bpar_[key] = val; }
    00141   void setEntry(const intParams key, const char * val) {
    00142     ipar_[key] = atoi(val); }
    00144   void setEntry(const intParams key, const int val) {
    00145     ipar_[key] = val; }
    00147   void setEntry(const dblParams key, const char * val) {
    00148     dpar_[key] = atof(val); }
    00150   void setEntry(const dblParams key, const double val) {
    00151     dpar_[key] = val; }
    00153   void setEntry(const strParams key, const char * val) {
    00154     spar_[key] = val; }
    00156   void setEntry(const strArrayParams key, const char *val) {
    00157     sapar_[key].push_back(val); }
    00158
    00159   //---------------------------------------------------------------------------
    00160
    00165   void pack(AlpsEncoded& buf) {
    00166     buf.writeRep(bpar_, endOfChrParams)
    00167       .writeRep(ipar_, endOfIntParams)
    00168       .writeRep(dpar_, endOfDblParams);
    00169     for (int i = 0; i < endOfStrParams; ++i)
    00170       buf.writeRep(spar_[i]);
    00171     for (int i = 0; i < endOfStrArrayParams; ++i) {
    00172       buf.writeRep(sapar_[i].size());
    00173       for (size_t j = 0; j < sapar_[i].size(); ++j)
    00174         buf.writeRep(sapar_[i][j]);
    00175     }
    00176   }
    00178   void unpack(AlpsEncoded& buf) {
    00179     int dummy;
    00180     // No need to allocate the arrays, they are of fixed length
    00181     dummy = static_cast<int>(endOfChrParams);
    00182     buf.readRep(bpar_, dummy, false);
    00183     dummy = static_cast<int>(endOfIntParams);
    00184     buf.readRep(ipar_, dummy, false);
    00185     dummy = static_cast<int>(endOfDblParams);
    00186     buf.readRep(dpar_, dummy, false);
    00187     for (int i = 0; i < endOfStrParams; ++i)
    00188       buf.readRep(spar_[i]);
    00189     for (int i = 0; i < endOfStrArrayParams; ++i) {
    00190       size_t str_size;
    00191       buf.readRep(str_size);
    00192       sapar_[i].reserve(str_size);
    00193       for (size_t j = 0; j < str_size; ++j){
    00194         //      sapar_[i].unchecked_push_back(std::string());
    00195         sapar_[i].push_back(std::string());
    00196         buf.readRep(sapar_[i].back());
    00197       }
    00198     }
    00199   }
    00202 };
    00203
    00204 #endif