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

- File List
- File Members

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: Yan Xu, Lehigh University *
8 * Ted Ralphs, Lehigh University *
9 * Laszlo Ladanyi, IBM T.J. Watson Research Center *
10 * Matthew Saltzman, Clemson University *
11 * *
12 * *
13 * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs. *
14 *===========================================================================*/
15
16 #ifndef KnapParams_h
17 #define KnapParams_h
18
19 #include "AlpsKnowledge.h"
20 #include "AlpsParameterBase.h"
21
22
23 //#############################################################################
24 //#############################################################################
25 //** Parameters used in Knap. */
26 class KnapParams : public AlpsParameterSet {
27 public:
30 enum chrParams{
31 // The dummy is needed so the allocation won't try for 0 entries.
32 chrDummy,
33 //
34 endOfChrParams
35 };
36
38 enum intParams{
39 intDummy,
40 //
41 endOfIntParams
42 };
43
45 enum dblParams{
46 dblDummy,
47 //
48 endOfDblParams
49 };
50
52 enum strParams{
53 strDummy,
54 //
55 endOfStrParams
56 };
57
59 enum strArrayParams{
60 strArrayDummy,
61 //
62 endOfStrArrayParams
63 };
64
65 public:
71 KnapParams() :
72 AlpsParameterSet(
73 static_cast<int>(endOfChrParams),
74 static_cast<int>(endOfIntParams),
75 static_cast<int>(endOfDblParams),
76 static_cast<int>(endOfStrParams),
77 static_cast<int>(endOfStrArrayParams)
78 )
79 {
80 createKeywordList();
81 setDefaultEntries();
82 }
87 virtual void createKeywordList();
89 virtual void setDefaultEntries();
93 public:
94 //===========================================================================
102 //===========================================================================
103
104
113 inline char
115 entry(const chrParams key) const { return bpar_[key]; }
117 inline int
118 entry(const intParams key) const { return ipar_[key]; }
120 inline double
121 entry(const dblParams key) const { return dpar_[key]; }
123 inline const std::string&
124 entry(const strParams key) const { return spar_[key]; }
126 inline const std::vector<std::string>&
127 entry(const strArrayParams key) const { return sapar_[key]; }
130 //---------------------------------------------------------------------------
132 void setEntry(const chrParams key, const char * val) {
133 bpar_[key] = atoi(val) ? true : false; }
135 void setEntry(const chrParams key, const char val) {
136 bpar_[key] = val ? true : false; }
138 void setEntry(const chrParams key, const bool val) {
139 bpar_[key] = val; }
141 void setEntry(const intParams key, const char * val) {
142 ipar_[key] = atoi(val); }
144 void setEntry(const intParams key, const int val) {
145 ipar_[key] = val; }
147 void setEntry(const dblParams key, const char * val) {
148 dpar_[key] = atof(val); }
150 void setEntry(const dblParams key, const double val) {
151 dpar_[key] = val; }
153 void setEntry(const strParams key, const char * val) {
154 spar_[key] = val; }
156 void setEntry(const strArrayParams key, const char *val) {
157 sapar_[key].push_back(val); }
158
159 //---------------------------------------------------------------------------
160
165 void pack(AlpsEncoded& buf) {
166 buf.writeRep(bpar_, endOfChrParams)
167 .writeRep(ipar_, endOfIntParams)
168 .writeRep(dpar_, endOfDblParams);
169 for (int i = 0; i < endOfStrParams; ++i)
170 buf.writeRep(spar_[i]);
171 for (int i = 0; i < endOfStrArrayParams; ++i) {
172 buf.writeRep(sapar_[i].size());
173 for (size_t j = 0; j < sapar_[i].size(); ++j)
174 buf.writeRep(sapar_[i][j]);
175 }
176 }
178 void unpack(AlpsEncoded& buf) {
179 int dummy;
180 // No need to allocate the arrays, they are of fixed length
181 dummy = static_cast<int>(endOfChrParams);
182 buf.readRep(bpar_, dummy, false);
183 dummy = static_cast<int>(endOfIntParams);
184 buf.readRep(ipar_, dummy, false);
185 dummy = static_cast<int>(endOfDblParams);
186 buf.readRep(dpar_, dummy, false);
187 for (int i = 0; i < endOfStrParams; ++i)
188 buf.readRep(spar_[i]);
189 for (int i = 0; i < endOfStrArrayParams; ++i) {
190 size_t str_size;
191 buf.readRep(str_size);
192 sapar_[i].reserve(str_size);
193 for (size_t j = 0; j < str_size; ++j){
194 // sapar_[i].unchecked_push_back(std::string());
195 sapar_[i].push_back(std::string());
196 buf.readRep(sapar_[i].back());
197 }
198 }
199 }
202 };
203
204 #endif
KnapParams::createKeywordList
virtual void createKeywordList()
Method for creating the list of keyword looked for in the parameter file.
AlpsEncoded::readRep
AlpsEncoded & readRep(T &value)
Read a single object of type T from repsentation_ .
Definition: AlpsEncoded.h:173
KnapParams::setEntry
void setEntry(const chrParams key, const char val)
char is true(1) or false(0), not used
Definition: KnapParams.h:135
KnapParams::strDummy
Definition: KnapParams.h:53
AlpsEncoded::writeRep
AlpsEncoded & writeRep(const T &value)
Write a single object of type T in repsentation_ .
Definition: AlpsEncoded.h:163
KnapParams::dblParams
dblParams
Double parameters.
Definition: KnapParams.h:45
AlpsParameterBase.h
KnapParams::unpack
void unpack(AlpsEncoded &buf)
Unpack the parameter set from the buffer.
Definition: KnapParams.h:178
AlpsParameterSet
This is the class serves as a holder for a set of parameters.
Definition: AlpsParameterBase.h:134
KnapParams::setDefaultEntries
virtual void setDefaultEntries()
Method for setting the default values for the parameters.
AlpsParameterSet::ipar_
int * ipar_
The integer parameters.
Definition: AlpsParameterBase.h:150
KnapParams::endOfDblParams
Definition: KnapParams.h:48
KnapParams::setEntry
void setEntry(const strArrayParams key, const char *val)
Definition: KnapParams.h:156
KnapParams::pack
void pack(AlpsEncoded &buf)
Pack the parameter set into the buffer (AlpsEncoded is used as buffer Here).
Definition: KnapParams.h:165
KnapParams::entry
int entry(const intParams key) const
Definition: KnapParams.h:118
KnapParams::setEntry
void setEntry(const intParams key, const char *val)
Definition: KnapParams.h:141
KnapParams::entry
double entry(const dblParams key) const
Definition: KnapParams.h:121
AlpsEncoded
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
KnapParams::chrDummy
Definition: KnapParams.h:32
KnapParams::entry
const std::string & entry(const strParams key) const
Definition: KnapParams.h:124
KnapParams::intDummy
Definition: KnapParams.h:39
AlpsParameterSet::spar_
std::string * spar_
The string (actually, std::string) parameters.
Definition: AlpsParameterBase.h:156
KnapParams::endOfStrArrayParams
Definition: KnapParams.h:62
KnapParams::strParams
strParams
String parameters.
Definition: KnapParams.h:52
KnapParams::dblDummy
Definition: KnapParams.h:46
KnapParams::setEntry
void setEntry(const dblParams key, const char *val)
Definition: KnapParams.h:147
AlpsKnowledge.h
AlpsParameterSet::sapar_
std::vector< std::string > * sapar_
The keyword, parameter pairs.
Definition: AlpsParameterBase.h:160
KnapParams::endOfStrParams
Definition: KnapParams.h:55
KnapParams::chrParams
chrParams
Character parameters.
Definition: KnapParams.h:30
KnapParams::setEntry
void setEntry(const chrParams key, const bool val)
This method is the one that ever been used.
Definition: KnapParams.h:138
KnapParams::setEntry
void setEntry(const strParams key, const char *val)
Definition: KnapParams.h:153
AlpsParameterSet::bpar_
bool * bpar_
The bool parameters.
Definition: AlpsParameterBase.h:147
KnapParams::entry
const std::vector< std::string > & entry(const strArrayParams key) const
Definition: KnapParams.h:127
KnapParams::setEntry
void setEntry(const chrParams key, const char *val)
char* is true(1) or false(0), not used
Definition: KnapParams.h:132
KnapParams::KnapParams
KnapParams()
The default constructor creates a parameter set with from the template argument structure.
Definition: KnapParams.h:71
AlpsParameterSet::dpar_
double * dpar_
The double parameters.
Definition: AlpsParameterBase.h:153
KnapParams::strArrayParams
strArrayParams
There are no string array parameters.
Definition: KnapParams.h:59
KnapParams::endOfIntParams
Definition: KnapParams.h:41
KnapParams::setEntry
void setEntry(const intParams key, const int val)
Definition: KnapParams.h:144
KnapParams::setEntry
void setEntry(const dblParams key, const double val)
Definition: KnapParams.h:150
KnapParams::strArrayDummy
Definition: KnapParams.h:60
KnapParams::intParams
intParams
Integer paramters.
Definition: KnapParams.h:38
KnapParams
Definition: KnapParams.h:26
KnapParams::entry
char entry(const chrParams key) const
Definition: KnapParams.h:115
KnapParams::endOfChrParams
Definition: KnapParams.h:34