Bcps  0.94.2
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 
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),
100  numBranchesLeft_(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),
113  numBranchesLeft_(2)
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),
129  numBranchesLeft_(2)
130  {}
131 
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 
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 
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
int getDirection() const
Returns a code indicating the active arm of the branching object.
virtual AlpsReturnStatus decode(AlpsEncoded &encoded)
Unpack a branching object from an encoded object.
int direction_
Information required to do branching.
virtual void print(bool normalBranch)
Print information about this branching object.
int numBranchesLeft_
Number of arms remaining to be evaluated.
BcpsBranchObject & operator=(const BcpsBranchObject &rhs)
Assignment operator.
double getUpScore() const
Get integer score.
virtual int numBranches() const
The number of branch arms created for this branch object.
void setType(int t)
Set type.
double value_
Current branching value.
BcpsModel * model_
The model that owns this branch object.
void setObjectIndex(int ind)
Set object objectIndex.
virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const
Pack to an encoded object.
virtual double branch(bool normalBranch=false)=0
Perform branching as specified by the branching object.
virtual BcpsBranchObject * clone() const =0
Clone a object.
virtual int numBranchesLeft() const
The number of branch arms left to be evaluated.
int type_
Type of branching.
BcpsBranchObject(BcpsModel *model, int objectIndex, int direction, double value)
Useful constructor.
double getDownScore() const
Get double score.
AlpsReturnStatus decodeBcps(AlpsEncoded &encoded)
Unpack Bcps portion from an encoded object.
BcpsBranchObject(BcpsModel *model, int objectIndex, int upScore, double downScore, int direction, double value)
Useful constructor.
int objectIndex_
Branch object index.
virtual ~BcpsBranchObject()
Destructor.
double upScore_
Quality/Goodness of this object.
virtual bool boundBranch() const
Return true if branching should fix object bounds.
BcpsBranchObject contains the member data required when choosing branching entities and excuting actu...
BcpsBranchObject()
Default Constructor.
double downScore_
The score of branching down.
void setDownScore(double score)
Get double score.
double getValue() const
Return object branching value.
BcpsModel * model() const
Return model.
int getObjectIndex() const
Object objectIndex.
AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const
Pack Bcps portion to an encoded object.
BcpsBranchObject(BcpsModel *model)
Useful constructor.
void setUpScore(double score)
Set integer score.
void setDirection(int direction)
Set the direction of the branching object.
int getType()
Get type.