1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
// $Id: CbcSimpleInteger.hpp 1943 2013-07-21 09:05:45Z forrest $
// Copyright (C) 2002, International Business Machines
// Corporation and others. All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).
// Edwin 11/9/2009-- carved out of CbcBranchActual
#ifndef CbcSimpleInteger_H
#define CbcSimpleInteger_H
#include "CbcBranchingObject.hpp"
/** Simple branching object for an integer variable
This object can specify a two-way branch on an integer variable. For each
arm of the branch, the upper and lower bounds on the variable can be
independently specified.
Variable_ holds the index of the integer variable in the integerVariable_
array of the model.
*/
class CbcIntegerBranchingObject : public CbcBranchingObject {
public:
/// Default constructor
CbcIntegerBranchingObject ();
/** Create a standard floor/ceiling branch object
Specifies a simple two-way branch. Let \p value = x*. One arm of the
branch will be lb <= x <= floor(x*), the other ceil(x*) <= x <= ub.
Specify way = -1 to set the object state to perform the down arm first,
way = 1 for the up arm.
*/
CbcIntegerBranchingObject (CbcModel *model, int variable,
int way , double value) ;
/** Create a degenerate branch object
Specifies a `one-way branch'. Calling branch() for this object will
always result in lowerValue <= x <= upperValue. Used to fix a variable
when lowerValue = upperValue.
*/
CbcIntegerBranchingObject (CbcModel *model, int variable, int way,
double lowerValue, double upperValue) ;
/// Copy constructor
CbcIntegerBranchingObject ( const CbcIntegerBranchingObject &);
/// Assignment operator
CbcIntegerBranchingObject & operator= (const CbcIntegerBranchingObject& rhs);
/// Clone
virtual CbcBranchingObject * clone() const;
/// Destructor
virtual ~CbcIntegerBranchingObject ();
/// Does part of constructor
void fillPart ( int variable, int way , double value) ;
using CbcBranchingObject::branch ;
/** \brief Sets the bounds for the variable according to the current arm
of the branch and advances the object state to the next arm.
Returns change in guessed objective on next branch
*/
virtual double branch();
/** Update bounds in solver as in 'branch' and update given bounds.
branchState is -1 for 'down' +1 for 'up' */
virtual void fix(OsiSolverInterface * solver,
double * lower, double * upper,
int branchState) const ;
/** Change (tighten) bounds in object to reflect bounds in solver.
Return true if now fixed */
virtual bool tighten(OsiSolverInterface * ) ;
#ifdef JJF_ZERO
// No need to override. Default works fine.
/** Reset every information so that the branching object appears to point to
the previous child. This method does not need to modify anything in any
solver. */
virtual void previousBranch();
#endif
using CbcBranchingObject::print ;
/** \brief Print something about branch - only if log level high
*/
virtual void print();
/// Lower and upper bounds for down branch
inline const double * downBounds() const {
return down_;
}
/// Lower and upper bounds for up branch
inline const double * upBounds() const {
return up_;
}
/// Set lower and upper bounds for down branch
inline void setDownBounds(const double bounds[2]) {
memcpy(down_, bounds, 2*sizeof(double));
}
/// Set lower and upper bounds for up branch
inline void setUpBounds(const double bounds[2]) {
memcpy(up_, bounds, 2*sizeof(double));
}
#ifdef FUNNY_BRANCHING
/** Which variable (top bit if upper bound changing,
next bit if on down branch */
inline const int * variables() const {
return variables_;
}
// New bound
inline const double * newBounds() const {
return newBounds_;
}
/// Number of bound changes
inline int numberExtraChangedBounds() const {
return numberExtraChangedBounds_;
}
/// Just apply extra bounds to one variable - COIN_DBL_MAX ignore
int applyExtraBounds(int iColumn, double lower, double upper, int way) ;
/// Deactivate bounds for branching
void deactivate();
/// Are active bounds for branching
inline bool active() const {
return (down_[1] != -COIN_DBL_MAX);
}
#endif
/** Return the type (an integer identifier) of \c this */
virtual CbcBranchObjType type() const {
return SimpleIntegerBranchObj;
}
/** Compare the \c this with \c brObj. \c this and \c brObj must be os the
same type and must have the same original object, but they may have
different feasible regions.
Return the appropriate CbcRangeCompare value (first argument being the
sub/superset if that's the case). In case of overlap (and if \c
replaceIfOverlap is true) replace the current branching object with one
whose feasible region is the overlap.
*/
virtual CbcRangeCompare compareBranchingObject
(const CbcBranchingObject* brObj, const bool replaceIfOverlap = false);
protected:
/// Lower [0] and upper [1] bounds for the down arm (way_ = -1)
double down_[2];
/// Lower [0] and upper [1] bounds for the up arm (way_ = 1)
double up_[2];
#ifdef FUNNY_BRANCHING
/** Which variable (top bit if upper bound changing)
next bit if changing on down branch only */
int * variables_;
// New bound
double * newBounds_;
/// Number of Extra bound changes
int numberExtraChangedBounds_;
#endif
};
/// Define a single integer class
class CbcSimpleInteger : public CbcObject {
public:
// Default Constructor
CbcSimpleInteger ();
// Useful constructor - passed model and index
CbcSimpleInteger (CbcModel * model, int iColumn, double breakEven = 0.5);
// Useful constructor - passed model and Osi object
CbcSimpleInteger (CbcModel * model, const OsiSimpleInteger * object);
// Copy constructor
CbcSimpleInteger ( const CbcSimpleInteger &);
/// Clone
virtual CbcObject * clone() const;
// Assignment operator
CbcSimpleInteger & operator=( const CbcSimpleInteger& rhs);
// Destructor
virtual ~CbcSimpleInteger ();
/// Construct an OsiSimpleInteger object
OsiSimpleInteger * osiObject() const;
/// Infeasibility - large is 0.5
virtual double infeasibility(const OsiBranchingInformation * info,
int &preferredWay) const;
using CbcObject::feasibleRegion ;
/** Set bounds to fix the variable at the current (integer) value.
Given an integer value, set the lower and upper bounds to fix the
variable. Returns amount it had to move variable.
*/
virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
/** Create a branching object and indicate which way to branch first.
The branching object has to know how to create branches (fix
variables, etc.)
*/
virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) ;
/// Fills in a created branching object
/*virtual*/ void fillCreateBranch(CbcIntegerBranchingObject * branching, const OsiBranchingInformation * info, int way) ;
using CbcObject::solverBranch ;
/** Create an OsiSolverBranch object
This returns NULL if branch not represented by bound changes
*/
virtual OsiSolverBranch * solverBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
/** Set bounds to fix the variable at the current (integer) value.
Given an integer value, set the lower and upper bounds to fix the
variable. The algorithm takes a bit of care in order to compensate for
minor numerical inaccuracy.
*/
virtual void feasibleRegion();
/** Column number if single column object -1 otherwise,
so returns >= 0
Used by heuristics
*/
virtual int columnNumber() const;
/// Set column number
inline void setColumnNumber(int value) {
columnNumber_ = value;
}
/** Reset variable bounds to their original values.
Bounds may be tightened, so it may be good to be able to set this info in object.
*/
virtual void resetBounds(const OsiSolverInterface * solver) ;
/** Change column numbers after preprocessing
*/
virtual void resetSequenceEtc(int numberColumns, const int * originalColumns) ;
/// Original bounds
inline double originalLowerBound() const {
return originalLower_;
}
inline void setOriginalLowerBound(double value) {
originalLower_ = value;
}
inline double originalUpperBound() const {
return originalUpper_;
}
inline void setOriginalUpperBound(double value) {
originalUpper_ = value;
}
/// Breakeven e.g 0.7 -> >= 0.7 go up first
inline double breakEven() const {
return breakEven_;
}
/// Set breakeven e.g 0.7 -> >= 0.7 go up first
inline void setBreakEven(double value) {
breakEven_ = value;
}
protected:
/// data
/// Original lower bound
double originalLower_;
/// Original upper bound
double originalUpper_;
/// Breakeven i.e. >= this preferred is up
double breakEven_;
/// Column number in model
int columnNumber_;
/// If -1 down always chosen first, +1 up always, 0 normal
int preferredWay_;
};
#endif
|