Bcps 0.94.5
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-2017, 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
48
49 protected:
50
52 int type_;
53
56
61
69 double upScore_;
70
72 double downScore_;
74
79
82 double value_;
83
87
88 public:
89
92 :
93 type_(0),
94 model_(NULL),
95 objectIndex_(-1),
96 upScore_(0),
97 downScore_(0),
98 direction_(0),
99 value_(0.0),
101 {}
102
105 :
106 type_(0),
107 model_(model),
108 objectIndex_(-1),
109 upScore_(0),
110 downScore_(0),
111 direction_(0),
112 value_(0.0),
114 {}
115
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),
130 {}
131
134 int objectIndex,
135 double 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),
148 {}
149
152
154 virtual ~BcpsBranchObject() { /* Do nothing */}
155
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
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
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 {
250 // Should never be called.
251 assert(0);
252 return status;
253 }
254
258 // Should never be called.
259 assert(0);
260 return status;
261 }
262
263};
264
265#endif
AlpsReturnStatus
AlpsReturnStatusOk
AlpsEncoded & readRep(T &value)
AlpsEncoded & writeRep(const T &value)
BcpsBranchObject contains the member data required when choosing branching entities and excuting actu...
double value_
Current branching value.
BcpsBranchObject(const BcpsBranchObject &)
Copy constructor.
virtual AlpsReturnStatus decode(AlpsEncoded &encoded)
Unpack a branching object from an encoded object.
BcpsBranchObject(BcpsModel *model)
Useful constructor.
virtual void print(bool normalBranch)
Print information about this branching object.
double getDownScore() const
Get double score.
void setUpScore(double score)
Set integer score.
int objectIndex_
Branch object index.
BcpsBranchObject()
Default Constructor.
virtual int numBranches() const
The number of branch arms created for this branch object.
int getType()
Get type.
int getObjectIndex() const
Object objectIndex.
virtual int numBranchesLeft() const
The number of branch arms left to be evaluated.
int type_
Type of branching.
BcpsModel * model() const
Return model.
BcpsBranchObject & operator=(const BcpsBranchObject &rhs)
Assignment operator.
void setObjectIndex(int ind)
Set object objectIndex.
double downScore_
The score of branching down.
void setDownScore(double score)
Get double score.
virtual ~BcpsBranchObject()
Destructor.
virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const
Pack to an encoded object.
BcpsBranchObject(BcpsModel *model, int objectIndex, int direction, double value)
Useful constructor.
int numBranchesLeft_
Number of arms remaining to be evaluated.
int getDirection() const
Returns a code indicating the active arm of the branching object.
virtual double branch(bool normalBranch=false)=0
Perform branching as specified by the branching object.
AlpsReturnStatus decodeBcps(AlpsEncoded &encoded)
Unpack Bcps portion from an encoded object.
double upScore_
Quality/Goodness of this object.
int direction_
Information required to do branching.
double getUpScore() const
Get integer score.
double getValue() const
Return object branching value.
void setDirection(int direction)
Set the direction of the branching object.
AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const
Pack Bcps portion to an encoded object.
virtual BcpsBranchObject * clone() const =0
Clone a object.
BcpsModel * model_
The model that owns this branch object.
BcpsBranchObject(BcpsModel *model, int objectIndex, double upScore, double downScore, int direction, double value)
Useful constructor.
void setType(int t)
Set type.
virtual bool boundBranch() const
Return true if branching should fix object bounds.