Alps 1.5.11
Loading...
Searching...
No Matches
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-2019, 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. */
27 public:
31 // The dummy is needed so the allocation won't try for 0 entries.
33 //
35 };
36
43
50
57
64
65 public:
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 {
82 }
87 virtual void createKeywordList();
89 virtual void setDefaultEntries();
93 public:
94 //===========================================================================
102 //===========================================================================
103
104
114 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) {
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
This data structure is to contain the packed form of an encodable knowledge.
Definition AlpsEncoded.h:25
AlpsEncoded & readRep(T &value)
Read a single object of type T from repsentation_ .
AlpsEncoded & writeRep(const T &value)
Write a single object of type T in repsentation_ .
This is the class serves as a holder for a set of parameters.
std::vector< std::string > * sapar_
int * ipar_
The integer parameters.
bool * bpar_
The bool parameters.
double * dpar_
The double parameters.
std::string * spar_
The string (actually, std::string) parameters.
void setEntry(const chrParams key, const bool val)
This method is the one that ever been used.
Definition KnapParams.h:138
const std::vector< std::string > & entry(const strArrayParams key) const
Definition KnapParams.h:127
void setEntry(const dblParams key, const double val)
Definition KnapParams.h:150
void pack(AlpsEncoded &buf)
Pack the parameter set into the buffer (AlpsEncoded is used as buffer Here).
Definition KnapParams.h:165
void setEntry(const dblParams key, const char *val)
Definition KnapParams.h:147
void setEntry(const chrParams key, const char val)
char is true(1) or false(0), not used
Definition KnapParams.h:135
virtual void setDefaultEntries()
Method for setting the default values for the parameters.
void setEntry(const chrParams key, const char *val)
char* is true(1) or false(0), not used
Definition KnapParams.h:132
char entry(const chrParams key) const
Definition KnapParams.h:115
void setEntry(const strArrayParams key, const char *val)
Definition KnapParams.h:156
const std::string & entry(const strParams key) const
Definition KnapParams.h:124
void setEntry(const intParams key, const char *val)
Definition KnapParams.h:141
int entry(const intParams key) const
Definition KnapParams.h:118
virtual void createKeywordList()
Method for creating the list of keyword looked for in the parameter file.
strParams
String parameters.
Definition KnapParams.h:52
chrParams
Character parameters.
Definition KnapParams.h:30
strArrayParams
There are no string array parameters.
Definition KnapParams.h:59
@ endOfStrArrayParams
Definition KnapParams.h:62
void unpack(AlpsEncoded &buf)
Unpack the parameter set from the buffer.
Definition KnapParams.h:178
double entry(const dblParams key) const
Definition KnapParams.h:121
intParams
Integer paramters.
Definition KnapParams.h:38
void setEntry(const intParams key, const int val)
Definition KnapParams.h:144
KnapParams()
The default constructor creates a parameter set with from the template argument structure.
Definition KnapParams.h:71
dblParams
Double parameters.
Definition KnapParams.h:45
void setEntry(const strParams key, const char *val)
Definition KnapParams.h:153