Bcps 0.95.1
Loading...
Searching...
No Matches
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-2023, 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 "BcpsConfig.h"
33#include "BcpsModel.h"
34
35#include "Alps.h"
36#include "AlpsEncoded.h"
37
38
39//#############################################################################
40
41
47
49
50 protected:
51
53 int type_;
54
57
62
69
70 double upScore_;
71
73 double downScore_;
75
78
80
83 double value_;
84
88
89 public:
90
93 :
94 type_(0),
95 model_(NULL),
96 objectIndex_(-1),
97 upScore_(0),
98 downScore_(0),
99 direction_(0),
100 value_(0.0),
102 {}
103
106 :
107 type_(0),
108 model_(model),
109 objectIndex_(-1),
110 upScore_(0),
111 downScore_(0),
112 direction_(0),
113 value_(0.0),
115 {}
116
119 int objectIndex,
120 int direction ,
121 double value)
122 :
123 type_(0),
124 model_(model),
125 objectIndex_(objectIndex),
126 upScore_(0),
127 downScore_(0),
128 direction_(direction),
129 value_(value),
131 {}
132
135 int objectIndex,
136 double upScore,
137 double downScore,
138 int direction ,
139 double value)
140 :
141 type_(0),
142 model_(model),
143 objectIndex_(objectIndex),
144 upScore_(upScore),
145 downScore_(downScore),
146 direction_(direction),
147 value_(value),
149 {}
150
153
155 virtual ~BcpsBranchObject() { /* Do nothing */}
156
158 BcpsBranchObject & operator = ( const BcpsBranchObject& rhs);
159
161 virtual BcpsBranchObject * clone() const = 0;
162
164 int getType() { return type_; }
165
167 void setType(int t) { type_ = t; }
168
170 virtual int numBranches() const { return 2; }
171
173 virtual int numBranchesLeft() const { return numBranchesLeft_; }
174
177 // THINK: what's the use of normalBranch?
178 virtual double branch(bool normalBranch = false) = 0;
179
181 virtual void print(bool normalBranch) {}
182
184 virtual bool boundBranch() const { return true; }
185
187 inline int getObjectIndex() const { return objectIndex_; }
188
190 inline void setObjectIndex(int ind) { objectIndex_ = ind; }
191
193 inline double getUpScore() const { return upScore_; }
194
196 inline void setUpScore(double score) { upScore_ = score; }
197
199 inline double getDownScore() const { return downScore_; }
200
202 inline void setDownScore(double score) { downScore_ = score; }
203
205 inline int getDirection() const { return direction_; }
206
208 inline void setDirection(int direction) { direction_ = direction; }
209
211 inline double getValue() const { return value_; }
212
214 inline BcpsModel * model() const { return model_; }
215
216 protected:
217
219 AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const {
220 AlpsReturnStatus status = AlpsReturnStatusOk;
221 assert(encoded);
222 encoded->writeRep(objectIndex_);
223 encoded->writeRep(upScore_);
224 encoded->writeRep(downScore_);
225 encoded->writeRep(direction_);
226 encoded->writeRep(value_);
227 encoded->writeRep(numBranchesLeft_);
228
229 return status;
230 }
231
233 AlpsReturnStatus decodeBcps(AlpsEncoded &encoded) {
234 AlpsReturnStatus status = AlpsReturnStatusOk;
235
236 encoded.readRep(objectIndex_);
237 encoded.readRep(upScore_);
238 encoded.readRep(downScore_);
239 encoded.readRep(direction_);
240 encoded.readRep(value_);
241 encoded.readRep(numBranchesLeft_);
242
243 return status;
244 }
245
246 public:
247
249 virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const {
250 AlpsReturnStatus status = AlpsReturnStatusOk;
251 // Should never be called.
252 assert(0);
253 return status;
254 }
255
257 virtual AlpsReturnStatus decode(AlpsEncoded &encoded) {
258 AlpsReturnStatus status = AlpsReturnStatusOk;
259 // Should never be called.
260 assert(0);
261 return status;
262 }
263
264};
265
266#endif
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.
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.
#define BCPSLIB_EXPORT
Definition config.h:5