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

- File List
- File Members

BcpsBranchObject.h
Go to the documentation of this file.
1 /*===========================================================================*
2 * This file is part of the Branch, Constrain and Price Software (BiCePS) *
3 * *
4 * BiCePS is distributed under the Eclipse Public License as part of the *
5 * COIN-OR repository (http://www.coin-or.org). *
6 * *
7 * Authors: *
8 * *
9 * Yan Xu, Lehigh University *
10 * Ted Ralphs, Lehigh University *
11 * *
12 * Conceptual Design: *
13 * *
14 * Yan Xu, Lehigh University *
15 * Ted Ralphs, Lehigh University *
16 * Laszlo Ladanyi, IBM T.J. Watson Research Center *
17 * Matthew Saltzman, Clemson University *
18 * *
19 * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs. *
20 * All Rights Reserved. *
21 *===========================================================================*/
22
23
24 //#############################################################################
25 // Borrow ideas from COIN/Cbc
26 //#############################################################################
27
28
29 #ifndef BcpsBranchObject_h_
30 #define BcpsBranchObject_h_
31
32 #include "BcpsModel.h"
33
34 #include "Alps.h"
35 #include "AlpsEncoded.h"
36
37
38 //#############################################################################
39
40
47 class BcpsBranchObject {
48
49 protected:
50
52 int type_;
53
55 BcpsModel *model_;
56
60 int objectIndex_;
61
69 double upScore_;
70
72 double downScore_;
74
78 int direction_;
79
82 double value_;
83
85 int numBranchesLeft_;
87
88 public:
89
91 BcpsBranchObject()
92 :
93 type_(0),
94 model_(NULL),
95 objectIndex_(-1),
96 upScore_(0),
97 downScore_(0),
98 direction_(0),
99 value_(0.0),
100 numBranchesLeft_(0)
101 {}
102
104 BcpsBranchObject(BcpsModel * model)
105 :
106 type_(0),
107 model_(model),
108 objectIndex_(-1),
109 upScore_(0),
110 downScore_(0),
111 direction_(0),
112 value_(0.0),
113 numBranchesLeft_(2)
114 {}
115
117 BcpsBranchObject(BcpsModel * model,
118 int objectIndex,
119 int direction ,
120 double value)
121 :
122 type_(0),
123 model_(model),
124 objectIndex_(objectIndex),
125 upScore_(0),
126 downScore_(0),
127 direction_(direction),
128 value_(value),
129 numBranchesLeft_(2)
130 {}
131
133 BcpsBranchObject(BcpsModel * model,
134 int objectIndex,
135 int upScore,
136 double downScore,
137 int direction ,
138 double value)
139 :
140 type_(0),
141 model_(model),
142 objectIndex_(objectIndex),
143 upScore_(upScore),
144 downScore_(downScore),
145 direction_(direction),
146 value_(value),
147 numBranchesLeft_(2)
148 {}
149
151 BcpsBranchObject (const BcpsBranchObject &);
152
154 virtual ~BcpsBranchObject() { /* Do nothing */}
155
157 BcpsBranchObject & operator = ( const BcpsBranchObject& rhs);
158
160 virtual BcpsBranchObject * clone() const = 0;
161
163 int getType() { return type_; }
164
166 void setType(int t) { type_ = t; }
167
169 virtual int numBranches() const { return 2; }
170
172 virtual int numBranchesLeft() const { return numBranchesLeft_; }
173
176 // THINK: what's the use of normalBranch?
177 virtual double branch(bool normalBranch = false) = 0;
178
180 virtual void print(bool normalBranch) {}
181
183 virtual bool boundBranch() const { return true; }
184
186 inline int getObjectIndex() const { return objectIndex_; }
187
189 inline void setObjectIndex(int ind) { objectIndex_ = ind; }
190
192 inline double getUpScore() const { return upScore_; }
193
195 inline void setUpScore(double score) { upScore_ = score; }
196
198 inline double getDownScore() const { return downScore_; }
199
201 inline void setDownScore(double score) { downScore_ = score; }
202
204 inline int getDirection() const { return direction_; }
205
207 inline void setDirection(int direction) { direction_ = direction; }
208
210 inline double getValue() const { return value_; }
211
213 inline BcpsModel * model() const { return model_; }
214
215 protected:
216
218 AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const {
219 AlpsReturnStatus status = AlpsReturnStatusOk;
220 assert(encoded);
221 encoded->writeRep(objectIndex_);
222 encoded->writeRep(upScore_);
223 encoded->writeRep(downScore_);
224 encoded->writeRep(direction_);
225 encoded->writeRep(value_);
226 encoded->writeRep(numBranchesLeft_);
227
228 return status;
229 }
230
232 AlpsReturnStatus decodeBcps(AlpsEncoded &encoded) {
233 AlpsReturnStatus status = AlpsReturnStatusOk;
234
235 encoded.readRep(objectIndex_);
236 encoded.readRep(upScore_);
237 encoded.readRep(downScore_);
238 encoded.readRep(direction_);
239 encoded.readRep(value_);
240 encoded.readRep(numBranchesLeft_);
241
242 return status;
243 }
244
245 public:
246
248 virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const {
249 AlpsReturnStatus status = AlpsReturnStatusOk;
250 // Should never be called.
251 assert(0);
252 return status;
253 }
254
256 virtual AlpsReturnStatus decode(AlpsEncoded &encoded) {
257 AlpsReturnStatus status = AlpsReturnStatusOk;
258 // Should never be called.
259 assert(0);
260 return status;
261 }
262
263 };
264
265 #endif
BcpsBranchObject::BcpsBranchObject
BcpsBranchObject()
Default Constructor.
Definition: BcpsBranchObject.h:91
BcpsBranchObject::BcpsBranchObject
BcpsBranchObject(BcpsModel *model)
Useful constructor.
Definition: BcpsBranchObject.h:104
BcpsBranchObject::clone
virtual BcpsBranchObject * clone() const =0
Clone a object.
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
BcpsBranchObject::setType
void setType(int t)
Set type.
Definition: BcpsBranchObject.h:166
BcpsBranchObject::print
virtual void print(bool normalBranch)
Print information about this branching object.
Definition: BcpsBranchObject.h:180
AlpsReturnStatus
AlpsReturnStatus
Definition: Alps.h:118
BcpsBranchObject::numBranches
virtual int numBranches() const
The number of branch arms created for this branch object.
Definition: BcpsBranchObject.h:169
BcpsBranchObject::upScore_
double upScore_
Quality/Goodness of this object.
Definition: BcpsBranchObject.h:69
BcpsBranchObject::setDownScore
void setDownScore(double score)
Get double score.
Definition: BcpsBranchObject.h:201
BcpsBranchObject::BcpsBranchObject
BcpsBranchObject(BcpsModel *model, int objectIndex, int upScore, double downScore, int direction, double value)
Useful constructor.
Definition: BcpsBranchObject.h:133
BcpsBranchObject::setObjectIndex
void setObjectIndex(int ind)
Set object objectIndex.
Definition: BcpsBranchObject.h:189
BcpsBranchObject::branch
virtual double branch(bool normalBranch=false)=0
Perform branching as specified by the branching object.
BcpsBranchObject::getType
int getType()
Get type.
Definition: BcpsBranchObject.h:163
BcpsBranchObject::objectIndex_
int objectIndex_
Branch object index.
Definition: BcpsBranchObject.h:60
BcpsBranchObject::model_
BcpsModel * model_
The model that owns this branch object.
Definition: BcpsBranchObject.h:55
BcpsBranchObject::value_
double value_
Current branching value.
Definition: BcpsBranchObject.h:82
BcpsBranchObject
BcpsBranchObject contains the member data required when choosing branching entities and excuting actu...
Definition: BcpsBranchObject.h:47
BcpsBranchObject::getObjectIndex
int getObjectIndex() const
Object objectIndex.
Definition: BcpsBranchObject.h:186
BcpsBranchObject::model
BcpsModel * model() const
Return model.
Definition: BcpsBranchObject.h:213
AlpsEncoded
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
BcpsBranchObject::getUpScore
double getUpScore() const
Get integer score.
Definition: BcpsBranchObject.h:192
BcpsBranchObject::direction_
int direction_
Information required to do branching.
Definition: BcpsBranchObject.h:78
BcpsModel.h
AlpsReturnStatusOk
Definition: Alps.h:119
Alps.h
BcpsBranchObject::decode
virtual AlpsReturnStatus decode(AlpsEncoded &encoded)
Unpack a branching object from an encoded object.
Definition: BcpsBranchObject.h:256
BcpsBranchObject::setDirection
void setDirection(int direction)
Set the direction of the branching object.
Definition: BcpsBranchObject.h:207
BcpsBranchObject::numBranchesLeft
virtual int numBranchesLeft() const
The number of branch arms left to be evaluated.
Definition: BcpsBranchObject.h:172
BcpsBranchObject::decodeBcps
AlpsReturnStatus decodeBcps(AlpsEncoded &encoded)
Unpack Bcps portion from an encoded object.
Definition: BcpsBranchObject.h:232
BcpsBranchObject::downScore_
double downScore_
The score of branching down.
Definition: BcpsBranchObject.h:72
BcpsBranchObject::BcpsBranchObject
BcpsBranchObject(BcpsModel *model, int objectIndex, int direction, double value)
Useful constructor.
Definition: BcpsBranchObject.h:117
BcpsModel
Definition: BcpsModel.h:40
BcpsBranchObject::encode
virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const
Pack to an encoded object.
Definition: BcpsBranchObject.h:248
BcpsBranchObject::getDownScore
double getDownScore() const
Get double score.
Definition: BcpsBranchObject.h:198
BcpsBranchObject::getValue
double getValue() const
Return object branching value.
Definition: BcpsBranchObject.h:210
BcpsBranchObject::encodeBcps
AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const
Pack Bcps portion to an encoded object.
Definition: BcpsBranchObject.h:218
BcpsBranchObject::numBranchesLeft_
int numBranchesLeft_
Number of arms remaining to be evaluated.
Definition: BcpsBranchObject.h:85
AlpsEncoded.h
BcpsBranchObject::boundBranch
virtual bool boundBranch() const
Return true if branching should fix object bounds.
Definition: BcpsBranchObject.h:183
BcpsBranchObject::~BcpsBranchObject
virtual ~BcpsBranchObject()
Destructor.
Definition: BcpsBranchObject.h:154
BcpsBranchObject::setUpScore
void setUpScore(double score)
Set integer score.
Definition: BcpsBranchObject.h:195
BcpsBranchObject::type_
int type_
Type of branching.
Definition: BcpsBranchObject.h:52
BcpsBranchObject::getDirection
int getDirection() const
Returns a code indicating the active arm of the branching object.
Definition: BcpsBranchObject.h:204
BcpsBranchObject::operator=
BcpsBranchObject & operator=(const BcpsBranchObject &rhs)
Assignment operator.