2
2
# BIG-M VALUE
3
3
# ###############################################################################
4
4
# Get Big-M value for a particular constraint
5
- function _get_M_value (func:: JuMP. AbstractJuMPScalar , set:: _MOI.AbstractSet , method:: BigM )
5
+ function _get_M_value (func:: AbstractJuMPScalar , set:: _MOI.AbstractSet , method:: BigM )
6
6
if method. tighten
7
7
M = _get_tight_M (func, set, method)
8
8
else
@@ -12,7 +12,7 @@ function _get_M_value(func::JuMP.AbstractJuMPScalar, set::_MOI.AbstractSet, meth
12
12
end
13
13
14
14
# Get the tightest Big-M value for a particular constraint
15
- function _get_tight_M (func:: JuMP. AbstractJuMPScalar , set:: _MOI.AbstractSet , method:: BigM )
15
+ function _get_tight_M (func:: AbstractJuMPScalar , set:: _MOI.AbstractSet , method:: BigM )
16
16
M = min .(method. value, _calculate_tight_M (func, set, method)) # broadcast for when S <: MOI.Interval or MOI.EqualTo or MOI.Zeros
17
17
if any (isinf .(M))
18
18
error (" A finite Big-M value must be used. The value obtained was $M ." )
@@ -21,14 +21,14 @@ function _get_tight_M(func::JuMP.AbstractJuMPScalar, set::_MOI.AbstractSet, meth
21
21
end
22
22
23
23
# Get user-specified Big-M value
24
- function _get_M (:: JuMP. AbstractJuMPScalar , :: Union{_MOI.LessThan, _MOI.GreaterThan, _MOI.Nonnegatives, _MOI.Nonpositives} , method:: BigM )
24
+ function _get_M (:: AbstractJuMPScalar , :: Union{_MOI.LessThan, _MOI.GreaterThan, _MOI.Nonnegatives, _MOI.Nonpositives} , method:: BigM )
25
25
M = method. value
26
26
if isinf (M)
27
27
error (" A finite Big-M value must be used. The value given was $M ." )
28
28
end
29
29
return M
30
30
end
31
- function _get_M (:: JuMP. AbstractJuMPScalar , :: Union{_MOI.Interval, _MOI.EqualTo, _MOI.Zeros} , method:: BigM )
31
+ function _get_M (:: AbstractJuMPScalar , :: Union{_MOI.Interval, _MOI.EqualTo, _MOI.Zeros} , method:: BigM )
32
32
M = method. value
33
33
if isinf (M)
34
34
error (" A finite Big-M value must be used. The value given was $M ." )
@@ -37,64 +37,64 @@ function _get_M(::JuMP.AbstractJuMPScalar, ::Union{_MOI.Interval, _MOI.EqualTo,
37
37
end
38
38
39
39
# Apply interval arithmetic on a linear constraint to infer the tightest Big-M value from the bounds on the constraint.
40
- function _calculate_tight_M (func:: JuMP. AffExpr , set:: _MOI.LessThan , method:: BigM )
40
+ function _calculate_tight_M (func:: AffExpr , set:: _MOI.LessThan , method:: BigM )
41
41
return _interval_arithmetic_LessThan (func, - set. upper, method)
42
42
end
43
- function _calculate_tight_M (func:: JuMP. AffExpr , set:: _MOI.GreaterThan , method:: BigM )
43
+ function _calculate_tight_M (func:: AffExpr , set:: _MOI.GreaterThan , method:: BigM )
44
44
return _interval_arithmetic_GreaterThan (func, - set. lower, method)
45
45
end
46
- function _calculate_tight_M (func:: JuMP. AffExpr , :: _MOI.Nonpositives , method:: BigM )
46
+ function _calculate_tight_M (func:: AffExpr , :: _MOI.Nonpositives , method:: BigM )
47
47
return _interval_arithmetic_LessThan (func, 0.0 , method)
48
48
end
49
- function _calculate_tight_M (func:: JuMP. AffExpr , :: _MOI.Nonnegatives , method:: BigM )
49
+ function _calculate_tight_M (func:: AffExpr , :: _MOI.Nonnegatives , method:: BigM )
50
50
return _interval_arithmetic_GreaterThan (func, 0.0 , method)
51
51
end
52
- function _calculate_tight_M (func:: JuMP. AffExpr , set:: _MOI.Interval , method:: BigM )
52
+ function _calculate_tight_M (func:: AffExpr , set:: _MOI.Interval , method:: BigM )
53
53
return (
54
54
_interval_arithmetic_GreaterThan (func, - set. lower, method),
55
55
_interval_arithmetic_LessThan (func, - set. upper, method)
56
56
)
57
57
end
58
- function _calculate_tight_M (func:: JuMP. AffExpr , set:: _MOI.EqualTo , method:: BigM )
58
+ function _calculate_tight_M (func:: AffExpr , set:: _MOI.EqualTo , method:: BigM )
59
59
return (
60
60
_interval_arithmetic_GreaterThan (func, - set. value, method),
61
61
_interval_arithmetic_LessThan (func, - set. value, method)
62
62
)
63
63
end
64
- function _calculate_tight_M (func:: JuMP. AffExpr , :: _MOI.Zeros , method:: BigM )
64
+ function _calculate_tight_M (func:: AffExpr , :: _MOI.Zeros , method:: BigM )
65
65
return (
66
66
_interval_arithmetic_GreaterThan (func, 0.0 , method),
67
67
_interval_arithmetic_LessThan (func, 0.0 , method)
68
68
)
69
69
end
70
70
# fallbacks for other scalar constraints
71
- _calculate_tight_M (func:: Union{JuMP. QuadExpr, JuMP. NonlinearExpr} , set:: Union{_MOI.Interval, _MOI.EqualTo, _MOI.Zeros} , method:: BigM ) = (Inf , Inf )
72
- _calculate_tight_M (func:: Union{JuMP. QuadExpr, JuMP. NonlinearExpr} , set:: Union{_MOI.LessThan, _MOI.GreaterThan, _MOI.Nonnegatives, _MOI.Nonpositives} , method:: BigM ) = Inf
71
+ _calculate_tight_M (func:: Union{QuadExpr, NonlinearExpr} , set:: Union{_MOI.Interval, _MOI.EqualTo, _MOI.Zeros} , method:: BigM ) = (Inf , Inf )
72
+ _calculate_tight_M (func:: Union{QuadExpr, NonlinearExpr} , set:: Union{_MOI.LessThan, _MOI.GreaterThan, _MOI.Nonnegatives, _MOI.Nonpositives} , method:: BigM ) = Inf
73
73
_calculate_tight_M (func, set, method:: BigM ) = error (" BigM method not implemented for constraint type $(typeof (func)) in $(typeof (set)) " )
74
74
75
75
# get variable bounds for interval arithmetic
76
- function _update_variable_bounds (vref:: JuMP. VariableRef , method:: BigM )
77
- if JuMP . is_binary (vref)
76
+ function _update_variable_bounds (vref:: VariableRef , method:: BigM )
77
+ if is_binary (vref)
78
78
lb = 0
79
- elseif ! JuMP . has_lower_bound (vref)
79
+ elseif ! has_lower_bound (vref)
80
80
lb = - Inf
81
81
else
82
- lb = JuMP . lower_bound (vref)
82
+ lb = lower_bound (vref)
83
83
end
84
- if JuMP . is_binary (vref)
84
+ if is_binary (vref)
85
85
ub = 1
86
- elseif ! JuMP . has_upper_bound (vref)
86
+ elseif ! has_upper_bound (vref)
87
87
ub = Inf
88
88
else
89
- ub = JuMP . upper_bound (vref)
89
+ ub = upper_bound (vref)
90
90
end
91
91
return lb, ub
92
92
end
93
93
94
94
# perform interval arithmetic to update the initial M value
95
- function _interval_arithmetic_LessThan (func:: JuMP. AffExpr , M:: Float64 , method:: BigM )
95
+ function _interval_arithmetic_LessThan (func:: AffExpr , M:: Float64 , method:: BigM )
96
96
for (var,coeff) in func. terms
97
- JuMP . is_binary (var) && continue # skip binary variables
97
+ is_binary (var) && continue # skip binary variables
98
98
if coeff > 0
99
99
M += coeff* method. variable_bounds[var][2 ]
100
100
else
@@ -103,9 +103,9 @@ function _interval_arithmetic_LessThan(func::JuMP.AffExpr, M::Float64, method::B
103
103
end
104
104
return M + func. constant
105
105
end
106
- function _interval_arithmetic_GreaterThan (func:: JuMP. AffExpr , M:: Float64 , method:: BigM )
106
+ function _interval_arithmetic_GreaterThan (func:: AffExpr , M:: Float64 , method:: BigM )
107
107
for (var,coeff) in func. terms
108
- JuMP . is_binary (var) && continue # skip binary variables
108
+ is_binary (var) && continue # skip binary variables
109
109
if coeff < 0
110
110
M += coeff* method. variable_bounds[var][2 ]
111
111
else
@@ -119,81 +119,81 @@ end
119
119
# BIG-M REFORMULATION
120
120
# ###############################################################################
121
121
function reformulate_disjunct_constraint (
122
- model:: JuMP. Model ,
123
- con:: JuMP. ScalarConstraint{T, S} ,
124
- bvref:: JuMP. VariableRef ,
122
+ model:: Model ,
123
+ con:: ScalarConstraint{T, S} ,
124
+ bvref:: VariableRef ,
125
125
method:: BigM
126
126
) where {T, S <: _MOI.LessThan }
127
127
M = _get_M_value (con. func, con. set, method)
128
- new_func = JuMP . @expression (model, con. func - M* (1 - bvref))
129
- reform_con = JuMP . build_constraint (error, new_func, con. set)
128
+ new_func = @expression (model, con. func - M* (1 - bvref))
129
+ reform_con = build_constraint (error, new_func, con. set)
130
130
return [reform_con]
131
131
end
132
132
function reformulate_disjunct_constraint (
133
- model:: JuMP. Model ,
134
- con:: JuMP. VectorConstraint{T, S, R} ,
135
- bvref:: JuMP. VariableRef ,
133
+ model:: Model ,
134
+ con:: VectorConstraint{T, S, R} ,
135
+ bvref:: VariableRef ,
136
136
method:: BigM
137
137
) where {T, S <: _MOI.Nonpositives , R}
138
138
M = [_get_M_value (func, con. set, method) for func in con. func]
139
- new_func = JuMP . @expression (model, [i= 1 : con. set. dimension],
139
+ new_func = @expression (model, [i= 1 : con. set. dimension],
140
140
con. func[i] - M[i]* (1 - bvref)
141
141
)
142
- reform_con = JuMP . build_constraint (error, new_func, con. set)
142
+ reform_con = build_constraint (error, new_func, con. set)
143
143
return [reform_con]
144
144
end
145
145
function reformulate_disjunct_constraint (
146
- model:: JuMP. Model ,
147
- con:: JuMP. ScalarConstraint{T, S} ,
148
- bvref:: JuMP. VariableRef ,
146
+ model:: Model ,
147
+ con:: ScalarConstraint{T, S} ,
148
+ bvref:: VariableRef ,
149
149
method:: BigM
150
150
) where {T, S <: _MOI.GreaterThan }
151
151
M = _get_M_value (con. func, con. set, method)
152
- new_func = JuMP . @expression (model, con. func + M* (1 - bvref))
153
- reform_con = JuMP . build_constraint (error, new_func, con. set)
152
+ new_func = @expression (model, con. func + M* (1 - bvref))
153
+ reform_con = build_constraint (error, new_func, con. set)
154
154
return [reform_con]
155
155
end
156
156
function reformulate_disjunct_constraint (
157
- model:: JuMP. Model ,
158
- con:: JuMP. VectorConstraint{T, S, R} ,
159
- bvref:: JuMP. VariableRef ,
157
+ model:: Model ,
158
+ con:: VectorConstraint{T, S, R} ,
159
+ bvref:: VariableRef ,
160
160
method:: BigM
161
161
) where {T, S <: _MOI.Nonnegatives , R}
162
162
M = [_get_M_value (func, con. set, method) for func in con. func]
163
- new_func = JuMP . @expression (model, [i= 1 : con. set. dimension],
163
+ new_func = @expression (model, [i= 1 : con. set. dimension],
164
164
con. func[i] + M[i]* (1 - bvref)
165
165
)
166
- reform_con = JuMP . build_constraint (error, new_func, con. set)
166
+ reform_con = build_constraint (error, new_func, con. set)
167
167
return [reform_con]
168
168
end
169
169
function reformulate_disjunct_constraint (
170
- model:: JuMP. Model ,
171
- con:: JuMP. ScalarConstraint{T, S} ,
172
- bvref:: JuMP. VariableRef ,
170
+ model:: Model ,
171
+ con:: ScalarConstraint{T, S} ,
172
+ bvref:: VariableRef ,
173
173
method:: BigM
174
174
) where {T, S <: Union{_MOI.Interval, _MOI.EqualTo} }
175
175
M = _get_M_value (con. func, con. set, method)
176
- new_func_gt = JuMP . @expression (model, con. func + M[1 ]* (1 - bvref))
177
- new_func_lt = JuMP . @expression (model, con. func - M[2 ]* (1 - bvref))
176
+ new_func_gt = @expression (model, con. func + M[1 ]* (1 - bvref))
177
+ new_func_lt = @expression (model, con. func - M[2 ]* (1 - bvref))
178
178
set_values = _set_values (con. set)
179
- reform_con_gt = JuMP . build_constraint (error, new_func_gt, _MOI. GreaterThan (set_values[1 ]))
180
- reform_con_lt = JuMP . build_constraint (error, new_func_lt, _MOI. LessThan (set_values[2 ]))
179
+ reform_con_gt = build_constraint (error, new_func_gt, _MOI. GreaterThan (set_values[1 ]))
180
+ reform_con_lt = build_constraint (error, new_func_lt, _MOI. LessThan (set_values[2 ]))
181
181
return [reform_con_gt, reform_con_lt]
182
182
end
183
183
function reformulate_disjunct_constraint (
184
- model:: JuMP. Model ,
185
- con:: JuMP. VectorConstraint{T, S, R} ,
186
- bvref:: JuMP. VariableRef ,
184
+ model:: Model ,
185
+ con:: VectorConstraint{T, S, R} ,
186
+ bvref:: VariableRef ,
187
187
method:: BigM
188
188
) where {T, S <: _MOI.Zeros , R}
189
189
M = [_get_M_value (func, con. set, method) for func in con. func]
190
- new_func_nn = JuMP . @expression (model, [i= 1 : con. set. dimension],
190
+ new_func_nn = @expression (model, [i= 1 : con. set. dimension],
191
191
con. func[i] + M[i][1 ]* (1 - bvref)
192
192
)
193
- new_func_np = JuMP . @expression (model, [i= 1 : con. set. dimension],
193
+ new_func_np = @expression (model, [i= 1 : con. set. dimension],
194
194
con. func[i] - M[i][2 ]* (1 - bvref)
195
195
)
196
- reform_con_nn = JuMP . build_constraint (error, new_func_nn, _MOI. Nonnegatives (con. set. dimension))
197
- reform_con_np = JuMP . build_constraint (error, new_func_np, _MOI. Nonpositives (con. set. dimension))
196
+ reform_con_nn = build_constraint (error, new_func_nn, _MOI. Nonnegatives (con. set. dimension))
197
+ reform_con_np = build_constraint (error, new_func_np, _MOI. Nonpositives (con. set. dimension))
198
198
return [reform_con_nn, reform_con_np]
199
199
end
0 commit comments