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

- File List
- File Members

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
36 AlpsReturnStatus encodeVrp(AlpsEncoded *encoded) {
37 AlpsReturnStatus status = AlpsReturnStatusOk;
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
49 AlpsReturnStatus decodeVrp(AlpsEncoded &encoded) {
50 AlpsReturnStatus status = AlpsReturnStatusOk;
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
64 VrpVariable() {
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
103 virtual AlpsReturnStatus encode(AlpsEncoded *encoded){
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 {
115 AlpsReturnStatus status = AlpsReturnStatusOk;
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
BcpsObject::setUbHard
void setUbHard(double ub)
Set the appropriate property.
Definition: BcpsObject.h:206
VrpVariable::ends_
int ends_[2]
Definition: VrpVariable.h:30
AlpsEncoded::readRep
AlpsEncoded & readRep(T &value)
Read a single object of type T from repsentation_ .
Definition: AlpsEncoded.h:173
AlpsEncoded::writeRep
AlpsEncoded & writeRep(const T &value)
Write a single object of type T in repsentation_ .
Definition: AlpsEncoded.h:163
VrpVariable::~VrpVariable
virtual ~VrpVariable()
Destructor.
Definition: VrpVariable.h:87
AlpsReturnStatus
AlpsReturnStatus
Definition: Alps.h:118
BlisVariable::decodeBlis
AlpsReturnStatus decodeBlis(AlpsEncoded &encoded)
Unpack Blis part from a encode object.
Definition: BlisVariable.h:117
VrpVariable::encode
virtual AlpsReturnStatus encode(AlpsEncoded *encoded)
Pack to a encode object.
Definition: VrpVariable.h:103
VrpVariable::getv1
int getv1()
Get data.
Definition: VrpVariable.h:95
VrpVariable
Variable class for VRP.
Definition: VrpVariable.h:25
AlpsEncoded
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
VrpVariable::uind_
int uind_
Definition: VrpVariable.h:31
VrpVariable::VrpVariable
VrpVariable(int v1, int v2, int cost, int ub)
Useful constructor.
Definition: VrpVariable.h:70
AlpsReturnStatusOk
Definition: Alps.h:119
VrpVariable::decodeVrp
AlpsReturnStatus decodeVrp(AlpsEncoded &encoded)
Unpack Vrp part from a encode object.
Definition: VrpVariable.h:49
VrpVariable::printDesc
virtual void printDesc()
Definition: VrpVariable.h:98
BlisVariable::setObjCoef
void setObjCoef(double coef)
Set data.
Definition: BlisVariable.h:100
VrpVariable::decode
virtual AlpsKnowledge * decode(AlpsEncoded &encoded) const
Decode a variable from an encoded object.
Definition: VrpVariable.h:114
BlisVariable::encodeBlis
AlpsReturnStatus encodeBlis(AlpsEncoded *encoded)
Pack Blis part into an encoded object.
Definition: BlisVariable.h:106
BcpsObject::encodeBcpsObject
AlpsReturnStatus encodeBcpsObject(AlpsEncoded *encoded) const
Pack Bcps part to a encode object.
Definition: BcpsObject.h:294
BlisVariable::setData
void setData(int s, const int *ind, const double *val)
Set data.
Definition: BlisVariable.h:90
AlpsKnowledge
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::VrpVariable
VrpVariable()
Default constructor.
Definition: VrpVariable.h:64
BcpsObject::setIntType
void setIntType(BcpsIntegral_t it)
Set the appropriate property.
Definition: BcpsObject.h:202
VrpVariable::encodeVrp
AlpsReturnStatus encodeVrp(AlpsEncoded *encoded)
Pack Vrp part into an encoded object.
Definition: VrpVariable.h:36
CoinError
Error Class thrown by an exception.
Definition: CoinError.hpp:42
VrpVariable::getIndex
int getIndex()
Get data.
Definition: VrpVariable.h:93
VrpVariable::getv0
int getv0()
Get data.
Definition: VrpVariable.h:94
BcpsObject::decodeBcpsObject
AlpsReturnStatus decodeBcpsObject(AlpsEncoded &encoded)
Unpack Bcps part from a encode object.
Definition: BcpsObject.h:310
BcpsObject::setLbHard
void setLbHard(double lb)
Set the appropriate property.
Definition: BcpsObject.h:205
BlisVariable
Definition: BlisVariable.h:31