Skip to content

Commit 87592d4

Browse files
committed
fix bug when only positive BigM is passed by user (make it negative)
1 parent d5937eb commit 87592d4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/bigm.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ Perform Big-M reformulaiton on a nonlinear constraint at index k of constraint j
1111
1212
Perform Big-M reformulation on a constraint at index k of constraint j in disjunct i.
1313
"""
14-
function big_m_reformulation!(constr::ConstraintRef, bin_var, M, i, j, k)
15-
M = get_reform_param(M, i, j, k; constr)
14+
function big_m_reformulation!(constr::ConstraintRef, bin_var, M0, i, j, k)
15+
M = get_reform_param(M0, i, j, k; constr)
16+
if !ismissing(M0) && constraint_object(constr).set isa MOI.GreaterThan && M > 0
17+
M = -M #if a positive bigM value was provided and constraint is GreaterThan, use the negative of this number (-M*(1-y) <= func)
18+
end
1619
add_to_function_constant(constr, -M)
17-
set_normalized_coefficient(constr, constr.model[bin_var][i] , M)
20+
set_normalized_coefficient(constr, constr.model[bin_var][i], M)
1821
end
19-
function big_m_reformulation!(constr::NonlinearConstraintRef, bin_var, M, i, j, k)
20-
M = get_reform_param(M, i, j, k; constr)
22+
function big_m_reformulation!(constr::NonlinearConstraintRef, bin_var, M0, i, j, k)
23+
M = get_reform_param(M0, i, j, k; constr)
2124
#create symbolic variables (using Symbolics.jl)
2225
for var_ref in get_constraint_variables(constr)
2326
symbolic_variable(var_ref)

0 commit comments

Comments
 (0)