Alps  2.0.2
KnapParams.h
Go to the documentation of this file.
1 /*===========================================================================*
2  * This file is part of the Abstract Library for Parallel Search (ALPS). *
3  * *
4  * ALPS is distributed under the Eclipse Public License as part of the *
5  * COIN-OR repository (http://www.coin-or.org). *
6  * *
7  * Authors: *
8  * *
9  * Yan Xu, Lehigh University *
10  * Aykut Bulut, Lehigh University *
11  * Ted Ralphs, Lehigh University *
12  * *
13  * Conceptual Design: *
14  * *
15  * Yan Xu, Lehigh University *
16  * Ted Ralphs, Lehigh University *
17  * Laszlo Ladanyi, IBM T.J. Watson Research Center *
18  * Matthew Saltzman, Clemson University *
19  * *
20  * *
21  * Copyright (C) 2001-2019, Lehigh University, Yan Xu, Aykut Bulut, and *
22  * Ted Ralphs. *
23  * All Rights Reserved. *
24  *===========================================================================*/
25 
26 
27 #ifndef KnapParams_h
28 #define KnapParams_h
29 
30 #include "AlpsKnowledge.h"
31 #include "AlpsParameterBase.h"
32 
33 
34 //#############################################################################
35 //#############################################################################
36 //** Parameters used in Knap. */
37 class KnapParams : public AlpsParameterSet {
38  public:
41  enum chrParams{
42  // The dummy is needed so the allocation won't try for 0 entries.
44  //
46  };
47 
49  enum intParams{
51  //
53  };
54 
56  enum dblParams{
58  //
60  };
61 
63  enum strParams{
65  //
67  };
68 
72  //
74  };
75 
76  public:
84  static_cast<int>(endOfChrParams),
85  static_cast<int>(endOfIntParams),
86  static_cast<int>(endOfDblParams),
87  static_cast<int>(endOfStrParams),
88  static_cast<int>(endOfStrArrayParams)
89  )
90  {
93  }
98  virtual void createKeywordList();
100  virtual void setDefaultEntries();
104  public:
105  //===========================================================================
113  //===========================================================================
114 
115 
124  inline char
126  entry(const chrParams key) const { return bpar_[key]; }
128  inline int
129  entry(const intParams key) const { return ipar_[key]; }
131  inline double
132  entry(const dblParams key) const { return dpar_[key]; }
134  inline const std::string&
135  entry(const strParams key) const { return spar_[key]; }
137  inline const std::vector<std::string>&
138  entry(const strArrayParams key) const { return sapar_[key]; }
141  //---------------------------------------------------------------------------
143  void setEntry(const chrParams key, const char * val) {
144  bpar_[key] = atoi(val) ? true : false; }
146  void setEntry(const chrParams key, const char val) {
147  bpar_[key] = val ? true : false; }
149  void setEntry(const chrParams key, const bool val) {
150  bpar_[key] = val; }
152  void setEntry(const intParams key, const char * val) {
153  ipar_[key] = atoi(val); }
155  void setEntry(const intParams key, const int val) {
156  ipar_[key] = val; }
158  void setEntry(const dblParams key, const char * val) {
159  dpar_[key] = atof(val); }
161  void setEntry(const dblParams key, const double val) {
162  dpar_[key] = val; }
164  void setEntry(const strParams key, const char * val) {
165  spar_[key] = val; }
167  void setEntry(const strArrayParams key, const char *val) {
168  sapar_[key].push_back(val); }
169 
170  //---------------------------------------------------------------------------
171 
176  void pack(AlpsEncoded& buf) {
180  for (int i = 0; i < endOfStrParams; ++i)
181  buf.writeRep(spar_[i]);
182  for (int i = 0; i < endOfStrArrayParams; ++i) {
183  buf.writeRep(sapar_[i].size());
184  for (size_t j = 0; j < sapar_[i].size(); ++j)
185  buf.writeRep(sapar_[i][j]);
186  }
187  }
189  void unpack(AlpsEncoded& buf) {
190  int dummy;
191  // No need to allocate the arrays, they are of fixed length
192  dummy = static_cast<int>(endOfChrParams);
193  buf.readRep(bpar_, dummy, false);
194  dummy = static_cast<int>(endOfIntParams);
195  buf.readRep(ipar_, dummy, false);
196  dummy = static_cast<int>(endOfDblParams);
197  buf.readRep(dpar_, dummy, false);
198  for (int i = 0; i < endOfStrParams; ++i)
199  buf.readRep(spar_[i]);
200  for (int i = 0; i < endOfStrArrayParams; ++i) {
201  size_t str_size;
202  buf.readRep(str_size);
203  sapar_[i].reserve(str_size);
204  for (size_t j = 0; j < str_size; ++j){
205  // sapar_[i].unchecked_push_back(std::string());
206  sapar_[i].push_back(std::string());
207  buf.readRep(sapar_[i].back());
208  }
209  }
210  }
213 };
214 
215 #endif
AlpsParameterSet::dpar_
double * dpar_
The double parameters.
Definition: AlpsParameterBase.h:161
AlpsParameterSet
This is the class serves as a holder for a set of parameters.
Definition: AlpsParameterBase.h:138
AlpsKnowledge.h
KnapParams::setEntry
void setEntry(const chrParams key, const char val)
char is true(1) or false(0), not used
Definition: KnapParams.h:146
KnapParams::entry
const std::vector< std::string > & entry(const strArrayParams key) const
Definition: KnapParams.h:138
KnapParams::endOfDblParams
@ endOfDblParams
Definition: KnapParams.h:59
KnapParams::entry
const std::string & entry(const strParams key) const
Definition: KnapParams.h:135
KnapParams::setEntry
void setEntry(const strParams key, const char *val)
Definition: KnapParams.h:164
KnapParams::endOfIntParams
@ endOfIntParams
Definition: KnapParams.h:52
KnapParams::KnapParams
KnapParams()
The default constructor creates a parameter set with from the template argument structure.
Definition: KnapParams.h:82
AlpsParameterSet::spar_
std::string * spar_
The string (actually, std::string) parameters.
Definition: AlpsParameterBase.h:164
KnapParams::strArrayParams
strArrayParams
There are no string array parameters.
Definition: KnapParams.h:70
AlpsParameterBase.h
KnapParams::setEntry
void setEntry(const strArrayParams key, const char *val)
Definition: KnapParams.h:167
KnapParams::unpack
void unpack(AlpsEncoded &buf)
Unpack the parameter set from the buffer.
Definition: KnapParams.h:189
KnapParams::entry
char entry(const chrParams key) const
Definition: KnapParams.h:126
AlpsEncoded
Definition: AlpsEncoded.h:64
KnapParams::setEntry
void setEntry(const dblParams key, const char *val)
Definition: KnapParams.h:158
KnapParams::strArrayDummy
@ strArrayDummy
Definition: KnapParams.h:71
KnapParams::entry
int entry(const intParams key) const
Definition: KnapParams.h:129
KnapParams::setEntry
void setEntry(const dblParams key, const double val)
Definition: KnapParams.h:161
KnapParams::chrParams
chrParams
Character parameters.
Definition: KnapParams.h:41
KnapParams::intParams
intParams
Integer paramters.
Definition: KnapParams.h:49
AlpsEncoded::writeRep
AlpsEncoded & writeRep(const T &value)
Write a single object of type T in repsentation_ .
Definition: AlpsEncoded.h:201
AlpsParameterSet::ipar_
int * ipar_
The integer parameters.
Definition: AlpsParameterBase.h:158
AlpsEncoded::readRep
AlpsEncoded & readRep(T &value)
Read a single object of type T from repsentation_ .
Definition: AlpsEncoded.h:211
KnapParams::strParams
strParams
String parameters.
Definition: KnapParams.h:63
KnapParams::createKeywordList
virtual void createKeywordList()
Method for creating the list of keyword looked for in the parameter file.
KnapParams::entry
double entry(const dblParams key) const
Definition: KnapParams.h:132
KnapParams
Definition: KnapParams.h:37
KnapParams::endOfStrArrayParams
@ endOfStrArrayParams
Definition: KnapParams.h:73
AlpsParameterSet::bpar_
bool * bpar_
The bool parameters.
Definition: AlpsParameterBase.h:155
KnapParams::chrDummy
@ chrDummy
Definition: KnapParams.h:43
KnapParams::pack
void pack(AlpsEncoded &buf)
Pack the parameter set into the buffer (AlpsEncoded is used as buffer Here).
Definition: KnapParams.h:176
KnapParams::setEntry
void setEntry(const chrParams key, const char *val)
char* is true(1) or false(0), not used
Definition: KnapParams.h:143
KnapParams::strDummy
@ strDummy
Definition: KnapParams.h:64
KnapParams::dblParams
dblParams
Double parameters.
Definition: KnapParams.h:56
KnapParams::endOfStrParams
@ endOfStrParams
Definition: KnapParams.h:66
KnapParams::intDummy
@ intDummy
Definition: KnapParams.h:50
KnapParams::setDefaultEntries
virtual void setDefaultEntries()
Method for setting the default values for the parameters.
KnapParams::dblDummy
@ dblDummy
Definition: KnapParams.h:57
KnapParams::setEntry
void setEntry(const intParams key, const int val)
Definition: KnapParams.h:155
KnapParams::endOfChrParams
@ endOfChrParams
Definition: KnapParams.h:45
AlpsParameterSet::sapar_
std::vector< std::string > * sapar_
Definition: AlpsParameterBase.h:168
KnapParams::setEntry
void setEntry(const chrParams key, const bool val)
This method is the one that ever been used.
Definition: KnapParams.h:149
KnapParams::setEntry
void setEntry(const intParams key, const char *val)
Definition: KnapParams.h:152