BlisBranchObjectInt.h
Go to the documentation of this file.
1 /*===========================================================================*
2  * This file is part of the BiCePS Linear Integer Solver (BLIS). *
3  * *
4  * BLIS 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  * *
20  * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs. *
21  * All Rights Reserved. *
22  *===========================================================================*/
23 
24 
25 //#############################################################################
26 // Borrow ideas from COIN/Cbc
27 //#############################################################################
28 
29 
30 #include "BcpsBranchObject.h"
31 
32 #include "BlisModel.h"
33 
34 
35 //#############################################################################
36 
37 
39 
40  protected:
41 
44  double down_[2];
45 
48  double up_[2];
49 
50  public:
51 
54  :
56  {
58  down_[0] = 0.0;
59  down_[1] = 0.0;
60  up_[0] = 0.0;
61  up_[1] = 0.0;
62  }
63 
70  int varInd,
71  int direction,
72  double value)
73  :
74  BcpsBranchObject(model, varInd, direction, value)
75  {
77  int iColumn = model->getIntColIndices()[objectIndex_];
78  down_[0] = model->solver()->getColLower()[iColumn];
79  down_[1] = floor(value_);
80  up_[0] = ceil(value_);
81  up_[1] = model->getColUpper()[iColumn];
82  }
83 
92  int varInd,
93  int intScore,
94  double dblScore,
95  int direction,
96  double value)
97  :
98  BcpsBranchObject(model, varInd, intScore, dblScore, direction, value)
99  {
101  int iColumn = model->getIntColIndices()[objectIndex_];
102  down_[0] = model->solver()->getColLower()[iColumn];
103  down_[1] = floor(value_);
104  up_[0] = ceil(value_);
105  up_[1] = model->getColUpper()[iColumn];
106  }
107 
114  int varInd,
115  int direction,
116  double lowerValue,
117  double upperValue)
118  :
119  BcpsBranchObject(model, varInd, direction, lowerValue)
120  {
122  numBranchesLeft_ = 1;
123  down_[0] = lowerValue;
124  down_[1] = upperValue;
125  up_[0] = lowerValue;
126  up_[1] = upperValue;
127  }
128 
131 
134 
136  virtual BcpsBranchObject * clone() const {
137  return (new BlisBranchObjectInt(*this));
138  }
139 
141  virtual ~BlisBranchObjectInt() {}
142 
146  virtual double branch(bool normalBranch = false);
147 
149  virtual void print(bool normalBranch);
150 
152  const double *getDown() const { return down_; }
153 
155  const double *getUp() const { return up_; }
156 
157  protected:
158 
161  assert(encoded);
163  int j;
164  // TODO: N-way.
165  for (j = 0; j < 2; ++j) {
166  encoded->writeRep(down_[j]);
167  }
168  for (j = 0; j < 2; ++j) {
169  encoded->writeRep(up_[j]);
170  }
171 
172  return status;
173  }
174 
178  int j;
179  // TODO: N-way.
180  for (j = 0; j < 2; ++j) {
181  encoded.readRep(down_[j]);
182  }
183  for (j = 0; j < 2; ++j) {
184  encoded.readRep(up_[j]);
185  }
186 
187  return status;
188  }
189 
190  public:
191 
193  virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const {
195 
196  status = encodeBcps(encoded);
197  status = encodeBlis(encoded);
198 
199  return status;
200  }
201 
203  virtual AlpsReturnStatus decode(AlpsEncoded &encoded) {
204 
206 
207  status = decodeBcps(encoded);
208  status = decodeBlis(encoded);
209 
210  return status;
211  }
212 
213 };
214 
AlpsEncoded & readRep(T &value)
Read a single object of type T from repsentation_ .
Definition: AlpsEncoded.h:173
AlpsEncoded & writeRep(const T &value)
Write a single object of type T in repsentation_ .
Definition: AlpsEncoded.h:163
AlpsReturnStatus decodeBlis(AlpsEncoded &encoded)
Unpack Blis portion from an encoded object.
BlisBranchObjectInt(BlisModel *model, int varInd, int direction, double lowerValue, double upperValue)
Create a degenerate branching object.
double down_[2]
Down_[0]: the lower bound of down arm; Down_[1]: the upper bound of down arm;.
AlpsReturnStatus
Definition: Alps.h:118
const double * getColUpper()
Get column upper bound.
Definition: BlisModel.h:338
double up_[2]
Up_[0]: the lower bound of upper arm; Up_[1]: the upper bound of upper arm;.
virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const
Pack to an encoded object.
virtual AlpsReturnStatus decode(AlpsEncoded &encoded)
Unpack a branching object from an encoded object.
int * getIntColIndices() const
Get integers&#39; column indices.
Definition: BlisModel.h:648
virtual ~BlisBranchObjectInt()
Destructor.
BlisBranchObjectInt(BlisModel *model, int varInd, int direction, double value)
Construct a branching object, which branching on variable varInd.
BlisBranchObjectInt & operator=(const BlisBranchObjectInt &rhs)
Assignment operator.
int objectIndex_
Branch object index.
double value_
Current branching value.
BcpsBranchObject contains the member data required when choosing branching entities and excuting actu...
BcpsModel * model() const
Return model.
const double * getDown() const
Get down arm bounds.
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
const double * getUp() const
Get upper arm bounds.
virtual void print(bool normalBranch)
Print something about branch - only if log level high.
BlisBranchObjectInt()
Default constructor.
AlpsReturnStatus decodeBcps(AlpsEncoded &encoded)
Unpack Bcps portion from an encoded object.
virtual OsiSolverInterface * solver()
Get lp solver.
Definition: BlisModel.h:310
virtual const double * getColLower() const =0
Get a pointer to an array[getNumCols()] of column lower bounds.
AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const
Pack Bcps portion to an encoded object.
BlisBranchObjectInt(BlisModel *model, int varInd, int intScore, double dblScore, int direction, double value)
Construct a branching object, which branching on variable varInd.
int numBranchesLeft_
Number of arms remaining to be evaluated.
virtual BcpsBranchObject * clone() const
Clone.
AlpsReturnStatus encodeBlis(AlpsEncoded *encoded) const
Pack Blis portion to an encoded object.
virtual double branch(bool normalBranch=false)
Set the bounds for the variable according to the current arm of the branch and advances the object st...
int type_
Type of branching.