VrpVariable.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 VrpVariable_h_
16 #define VrpVariable_h_
17 
18 //#############################################################################
19 
20 #include "BlisVariable.h"
21 
22 //#############################################################################
23 
25 class VrpVariable : public BlisVariable
26 {
27 private:
28 
29  /* The endpoints of the edge */
30  int ends_[2];
31  int uind_;
32 
33 protected:
34 
38 
39  //std::cout << "****** encodeVrp var: size_ = " << size_ << std::endl;
40 
41  encoded->writeRep(ends_[0]);
42  encoded->writeRep(ends_[1]);
43  encoded->writeRep(uind_);
44 
45  return status;
46  }
47 
51 
52  encoded.readRep(ends_[0]);
53  encoded.readRep(ends_[1]);
54  encoded.readRep(uind_);
55 
56  //std::cout << "****** decodeVrp var: size_ = " << size_ << std::endl;
57 
58  return status;
59  }
60 
61 public:
62 
65  ends_[0] = 0;
66  ends_[1] = 0;
67  }
68 
70  VrpVariable(int v1, int v2, int cost, int ub) {
71  ends_[0] = v1 < v2 ? v1 : v2;
72  ends_[1] = v1 < v2 ? v2 : v1;
73  uind_ = ends_[1]*(ends_[1] - 1)/2 + ends_[0];
74  int indices [2];
75  double values [2];
76  indices[0] = ends_[0];
77  indices[1] = ends_[1];
78  values[0] = values[1] = 1.0;
79  setData(2, indices, values);
80  setIntType('B');
81  setLbHard(0.0);
82  setUbHard((double) ub);
83  setObjCoef((double) cost);
84  }
85 
87  virtual ~VrpVariable() {
88  //std::cout << "delete a vrp variable " << std::endl;
89  }
90 
93  inline int getIndex() { return uind_; }
94  inline int getv0() { return ends_[0]; }
95  inline int getv1() { return ends_[1]; }
98  virtual void printDesc() {
99  std::cout << "(" << getv0() << ", " << getv1() << ")";
100  }
101 
104  AlpsReturnStatus status;
105 
106  status = encodeBcpsObject(encoded);
107  status = encodeBlis(encoded);
108  status = encodeVrp(encoded);
109 
110  return status;
111  }
112 
114  virtual AlpsKnowledge* decode(AlpsEncoded &encoded) const {
116  VrpVariable * var = new VrpVariable();
117 
118  // Unpack Bcps part.
119  status = var->decodeBcpsObject(encoded);
120  if (status) {
121  throw CoinError("Failed to decode Bcps part of var",
122  "decode",
123  "BlisObject");
124  }
125 
126  // Unpack Blis part.
127  status = var->decodeBlis(encoded);
128  if (status) {
129  throw CoinError("Failed to decode Blis part of var",
130  "decode",
131  "BlisObject");
132  }
133 
134  // Unpack Vrp part.
135  status = var->decodeVrp(encoded);
136  if (status) {
137  throw CoinError("Failed to decode Vrp part of var",
138  "decode",
139  "BlisObject");
140  }
141  return var;
142  }
143 
144 };
145 
146 //#############################################################################
147 
148 #endif
void setUbHard(double ub)
Set the appropriate property.
Definition: BcpsObject.h:206
int ends_[2]
Definition: VrpVariable.h:30
AlpsEncoded & readRep(T &value)
Read a single object of type T from repsentation_ .
Definition: AlpsEncoded.h:173
AlpsEncoded & writeRep(const T &value)
Write a single object of type T in repsentation_ .
Definition: AlpsEncoded.h:163
virtual ~VrpVariable()
Destructor.
Definition: VrpVariable.h:87
AlpsReturnStatus
Definition: Alps.h:118
AlpsReturnStatus decodeBlis(AlpsEncoded &encoded)
Unpack Blis part from a encode object.
Definition: BlisVariable.h:117
virtual AlpsReturnStatus encode(AlpsEncoded *encoded)
Pack to a encode object.
Definition: VrpVariable.h:103
int getv1()
Get data.
Definition: VrpVariable.h:95
Variable class for VRP.
Definition: VrpVariable.h:25
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
VrpVariable(int v1, int v2, int cost, int ub)
Useful constructor.
Definition: VrpVariable.h:70
AlpsReturnStatus decodeVrp(AlpsEncoded &encoded)
Unpack Vrp part from a encode object.
Definition: VrpVariable.h:49
virtual void printDesc()
Definition: VrpVariable.h:98
void setObjCoef(double coef)
Set data.
Definition: BlisVariable.h:100
virtual AlpsKnowledge * decode(AlpsEncoded &encoded) const
Decode a variable from an encoded object.
Definition: VrpVariable.h:114
AlpsReturnStatus encodeBlis(AlpsEncoded *encoded)
Pack Blis part into an encoded object.
Definition: BlisVariable.h:106
AlpsReturnStatus encodeBcpsObject(AlpsEncoded *encoded) const
Pack Bcps part to a encode object.
Definition: BcpsObject.h:294
void setData(int s, const int *ind, const double *val)
Set data.
Definition: BlisVariable.h:90
The abstract base class of any user-defined class that Alps has to know about in order to encode/deco...
Definition: AlpsKnowledge.h:51
VrpVariable()
Default constructor.
Definition: VrpVariable.h:64
void setIntType(BcpsIntegral_t it)
Set the appropriate property.
Definition: BcpsObject.h:202
AlpsReturnStatus encodeVrp(AlpsEncoded *encoded)
Pack Vrp part into an encoded object.
Definition: VrpVariable.h:36
Error Class thrown by an exception.
Definition: CoinError.hpp:42
int getIndex()
Get data.
Definition: VrpVariable.h:93
int getv0()
Get data.
Definition: VrpVariable.h:94
AlpsReturnStatus decodeBcpsObject(AlpsEncoded &encoded)
Unpack Bcps part from a encode object.
Definition: BcpsObject.h:310
void setLbHard(double lb)
Set the appropriate property.
Definition: BcpsObject.h:205