VrpParams.h
Go to the documentation of this file.
1 /*===========================================================================*
2  * This file is part of a solver for the Vehicle Routing Problem *
3  * developed using the BiCePS Linear Integer Solver (BLIS). *
4  * *
5  * This solver is distributed under the Eclipse Public License as part of *
6  * the COIN-OR repository (http://www.coin-or.org). *
7  * *
8  * Authors: Yan Xu, Lehigh University *
9  * Ted Ralphs, Lehigh University *
10  * *
11  * Copyright (C) 2007 Yan Xu and Ted Ralphs. *
12  * All Rights Reserved. *
13  *===========================================================================*/
14 
15 #ifndef VrpParams_h
16 #define VrpParams_h
17 
18 #include "AlpsKnowledge.h"
19 #include "AlpsParameterBase.h"
20 
21 //#############################################################################
22 
23 //** Parameters used in Vrp. */
24 class VrpParams : public AlpsParameterSet {
25  public:
28  enum boolParams{
33  };
34 
36  enum intParams{
44  };
45 
47  enum dblParams{
50  };
51 
53  enum strParams{
55  //
57  };
58 
64  };
65 
66  public:
74  static_cast<int>(endOfBoolParams),
75  static_cast<int>(endOfIntParams),
76  static_cast<int>(endOfDblParams),
77  static_cast<int>(endOfStrParams),
78  static_cast<int>(endOfStrArrayParams)
79  )
80  {
83  }
88  virtual void createKeywordList();
90  virtual void setDefaultEntries();
94  public:
95  //===========================================================================
103  //===========================================================================
104 
105 
114  inline bool entry(const boolParams key) const { return bpar_[key]; }
117  inline int entry(const intParams key) const { return ipar_[key]; }
119  inline double entry(const dblParams key) const { return dpar_[key]; }
121  inline const std::string&
122  entry(const strParams key) const { return spar_[key]; }
124  inline const std::vector<std::string>&
125  entry(const strArrayParams key) const { return sapar_[key]; }
128  //---------------------------------------------------------------------------
130  void setEntry(const boolParams key, const char * val) {
131  bpar_[key] = atoi(val) ? true : false; }
133  void setEntry(const boolParams key, const char val) {
134  bpar_[key] = val ? true : false; }
136  void setEntry(const boolParams key, const bool val) {
137  bpar_[key] = val; }
139  void setEntry(const intParams key, const char * val) {
140  ipar_[key] = atoi(val); }
142  void setEntry(const intParams key, const int val) {
143  ipar_[key] = val; }
145  void setEntry(const dblParams key, const char * val) {
146  dpar_[key] = atof(val); }
148  void setEntry(const dblParams key, const double val) {
149  dpar_[key] = val; }
151  void setEntry(const strParams key, const char * val) {
152  spar_[key] = val; }
154  void setEntry(const strArrayParams key, const char *val) {
155  sapar_[key].push_back(val); }
156 
157  //---------------------------------------------------------------------------
158 
163  void pack(AlpsEncoded& buf) {
167  for (int i = 0; i < endOfStrParams; ++i)
168  buf.writeRep(spar_[i]);
169  for (int i = 0; i < endOfStrArrayParams; ++i) {
170  buf.writeRep(sapar_[i].size());
171  for (size_t j = 0; j < sapar_[i].size(); ++j)
172  buf.writeRep(sapar_[i][j]);
173  }
174  }
176  void unpack(AlpsEncoded& buf) {
177  int dummy;
178  // No need to allocate the arrays, they are of fixed length
179  dummy = static_cast<int>(endOfBoolParams);
180  buf.readRep(bpar_, dummy, false);
181  dummy = static_cast<int>(endOfIntParams);
182  buf.readRep(ipar_, dummy, false);
183  dummy = static_cast<int>(endOfDblParams);
184  buf.readRep(dpar_, dummy, false);
185  for (int i = 0; i < endOfStrParams; ++i)
186  buf.readRep(spar_[i]);
187  for (int i = 0; i < endOfStrArrayParams; ++i) {
188  size_t str_size;
189  buf.readRep(str_size);
190  sapar_[i].reserve(str_size);
191  for (size_t j = 0; j < str_size; ++j){
192  // sapar_[i].unchecked_push_back(std::string());
193  sapar_[i].push_back(std::string());
194  buf.readRep(sapar_[i].back());
195  }
196  }
197  }
200 };
201 
202 #endif
const std::string & entry(const strParams key) const
Definition: VrpParams.h:122
void setEntry(const boolParams key, const char val)
char is true(1) or false(0), not used
Definition: VrpParams.h:133
void setEntry(const boolParams key, const char *val)
char* is true(1) or false(0), not used
Definition: VrpParams.h:130
virtual void setDefaultEntries()
Method for setting the default values for the parameters.
AlpsEncoded & readRep(T &value)
Read a single object of type T from repsentation_ .
Definition: AlpsEncoded.h:173
intParams
Integer paramters.
Definition: VrpParams.h:36
AlpsEncoded & writeRep(const T &value)
Write a single object of type T in repsentation_ .
Definition: AlpsEncoded.h:163
double entry(const dblParams key) const
Definition: VrpParams.h:119
This is the class serves as a holder for a set of parameters.
void setEntry(const dblParams key, const double val)
Definition: VrpParams.h:148
void unpack(AlpsEncoded &buf)
Unpack the parameter set from the buffer.
Definition: VrpParams.h:176
void pack(AlpsEncoded &buf)
Pack the parameter set into the buffer (AlpsEncoded is used as buffer Here).
Definition: VrpParams.h:163
int * ipar_
The integer parameters.
void setEntry(const intParams key, const int val)
Definition: VrpParams.h:142
strArrayParams
There are no string array parameters.
Definition: VrpParams.h:60
VrpParams()
The default constructor creates a parameter set with from the template argument structure.
Definition: VrpParams.h:72
dblParams
Double parameters.
Definition: VrpParams.h:47
void setEntry(const intParams key, const char *val)
Definition: VrpParams.h:139
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
std::string * spar_
The string (actually, std::string) parameters.
boolParams
Character parameters.
Definition: VrpParams.h:28
void setEntry(const strArrayParams key, const char *val)
Definition: VrpParams.h:154
void setEntry(const strParams key, const char *val)
Definition: VrpParams.h:151
void setEntry(const boolParams key, const bool val)
This method is the one that ever been used.
Definition: VrpParams.h:136
std::vector< std::string > * sapar_
The keyword, parameter pairs.
const std::vector< std::string > & entry(const strArrayParams key) const
Definition: VrpParams.h:125
bool * bpar_
The bool parameters.
virtual void createKeywordList()
Method for creating the list of keyword looked for in the parameter file.
void setEntry(const dblParams key, const char *val)
Definition: VrpParams.h:145
bool entry(const boolParams key) const
Definition: VrpParams.h:115
double * dpar_
The double parameters.
int entry(const intParams key) const
Definition: VrpParams.h:117
strParams
String parameters.
Definition: VrpParams.h:53