Blis 0.95.0
Loading...
Searching...
No Matches
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-2023, 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 "BlisConfig.h"
33#include "BlisModel.h"
34
35//#############################################################################
36
37class BLISLIB_EXPORT BlisBranchObjectInt : public BcpsBranchObject {
38
39 protected:
40
43 double down_[2];
44
47 double up_[2];
48
49 public:
50
53 :
54 BcpsBranchObject()
55 {
57 down_[0] = 0.0;
58 down_[1] = 0.0;
59 up_[0] = 0.0;
60 up_[1] = 0.0;
61 }
62
69 int varInd,
70 int direction,
71 double value)
72 :
73 BcpsBranchObject(model, varInd, direction, value)
74 {
76 int iColumn = model->getIntColIndices()[objectIndex_];
77 down_[0] = model->solver()->getColLower()[iColumn];
78 down_[1] = floor(value_);
79 up_[0] = ceil(value_);
80 up_[1] = model->getColUpper()[iColumn];
81 //start:sahar
82 if (up_[0]==down_[1]) {
83 if (up_[0]==floor(up_[1])) {
84 down_[1]-=1;
85 }
86 else {
87 up_[0]+=1;
88 }
89 }//end:sahar
90 }
91
100 int varInd,
101 int intScore,
102 double dblScore,
103 int direction,
104 double value)
105 :
106 BcpsBranchObject(model, varInd, intScore, dblScore, direction, value)
107 {
109 int iColumn = model->getIntColIndices()[objectIndex_];
110 down_[0] = model->solver()->getColLower()[iColumn];
111 down_[1] = floor(value_);
112 up_[0] = ceil(value_);
113 up_[1] = model->getColUpper()[iColumn];
114 //start:sahar
115 if (up_[0]==down_[1]) {
116 if (up_[0]==floor(up_[1])) {
117 down_[1]-=1;
118 }
119 else {
120 up_[0]+=1;
121 }
122 }//end:sahar
123 }
124
131 int varInd,
132 int direction,
133 double lowerValue,
134 double upperValue)
135 :
136 BcpsBranchObject(model, varInd, direction, lowerValue)
137 {
139 numBranchesLeft_ = 1;
140 down_[0] = lowerValue;
141 down_[1] = upperValue;
142 up_[0] = lowerValue;
143 up_[1] = upperValue;
144 }
145
148
150 BlisBranchObjectInt & operator = (const BlisBranchObjectInt& rhs);
151
153 virtual BcpsBranchObject * clone() const {
154 return (new BlisBranchObjectInt(*this));
155 }
156
159
163 virtual double branch(bool normalBranch = false);
164
166 virtual void print(bool normalBranch);
167
169 const double *getDown() const { return down_; }
170
172 const double *getUp() const { return up_; }
173
174 protected:
175
177 AlpsReturnStatus encodeBlis(AlpsEncoded *encoded) const {
178 assert(encoded);
179 AlpsReturnStatus status = AlpsReturnStatusOk;
180 int j;
181 // TODO: N-way.
182 for (j = 0; j < 2; ++j) {
183 encoded->writeRep(down_[j]);
184 }
185 for (j = 0; j < 2; ++j) {
186 encoded->writeRep(up_[j]);
187 }
188
189 return status;
190 }
191
193 AlpsReturnStatus decodeBlis(AlpsEncoded &encoded) {
194 AlpsReturnStatus status = AlpsReturnStatusOk;
195 int j;
196 // TODO: N-way.
197 for (j = 0; j < 2; ++j) {
198 encoded.readRep(down_[j]);
199 }
200 for (j = 0; j < 2; ++j) {
201 encoded.readRep(up_[j]);
202 }
203
204 return status;
205 }
206
207 public:
208
210 virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const {
211 AlpsReturnStatus status = AlpsReturnStatusOk;
212
213 status = encodeBcps(encoded);
214 status = encodeBlis(encoded);
215
216 return status;
217 }
218
220 virtual AlpsReturnStatus decode(AlpsEncoded &encoded) {
221
222 AlpsReturnStatus status = AlpsReturnStatusOk;
223
224 status = decodeBcps(encoded);
225 status = decodeBlis(encoded);
226
227 return status;
228 }
229
230};
231
@ BlisBranchingObjectTypeInt
Definition Blis.h:125
virtual void print(bool normalBranch)
Print something about branch - only if log level high.
virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const
Pack to an encoded object.
BlisBranchObjectInt(BlisModel *model, int varInd, int direction, double lowerValue, double upperValue)
Create a degenerate branching object.
AlpsReturnStatus decodeBlis(AlpsEncoded &encoded)
Unpack Blis portion from an encoded object.
const double * getDown() const
Get down arm bounds.
BlisBranchObjectInt(BlisModel *model, int varInd, int direction, double value)
Construct a branching object, which branching on variable varInd.
BlisBranchObjectInt(BlisModel *model, int varInd, int intScore, double dblScore, int direction, double value)
Construct a branching object, which branching on variable varInd.
AlpsReturnStatus encodeBlis(AlpsEncoded *encoded) const
Pack Blis portion to an encoded object.
BlisBranchObjectInt()
Default constructor.
double up_[2]
Up_[0]: the lower bound of upper arm; Up_[1]: the upper bound of upper arm;.
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...
virtual ~BlisBranchObjectInt()
Destructor.
double down_[2]
Down_[0]: the lower bound of down arm; Down_[1]: the upper bound of down arm;.
const double * getUp() const
Get upper arm bounds.
virtual AlpsReturnStatus decode(AlpsEncoded &encoded)
Unpack a branching object from an encoded object.
BlisBranchObjectInt(const BlisBranchObjectInt &)
Copy constructor.
virtual BcpsBranchObject * clone() const
Clone.
virtual OsiSolverInterface * solver()
Get lp solver.
Definition BlisModel.h:450
const double * getColUpper()
Get column upper bound.
Definition BlisModel.h:493
int * getIntColIndices() const
Get integers' column indices.
Definition BlisModel.h:661
#define BLISLIB_EXPORT
Definition config.h:5