Skip to content

Commit b11f39c

Browse files
committed
fix Interval arithmetic can't be applied to quadratic constraints to insert big M value #62
1 parent ee34be8 commit b11f39c

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

examples/ex1.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ print(m)
1919
# ┌ Warning: disj_y[2] : x in [5.0, 9.0] uses the `MOI.Interval` set. Each instance of the interval set has been split into two constraints, one for each bound.
2020
# Feasibility
2121
# Subject to
22-
# XOR(disj_y) : y[1] + y[2] == 1.0 <- XOR constraint
23-
# y[1] ∨ y[2] : y[1] + y[2] >= 1.0 <- reformulated logical proposition (name is the proposition)
22+
# XOR : y[1] + y[2] == 1.0 <- XOR constraint
23+
# prop : y[1] + y[2] >= 1.0 <- reformulated logical proposition (name is the proposition)
2424
# disj_y[1,lb] : -x + 5 y[1] <= 5.0 <- left-side of constraint in 1st disjunct (name is assigned to disj_y[1][lb])
2525
# disj_y[1,ub] : x + 7 y[1] <= 10.0 <- right-side of constraint in 1st disjunct (name is assigned to disj_y[1][ub])
2626
# disj_y[2,lb] : -x + 10 y[2] <= 5.0 <- left-side of constraint in 2nd disjunct (name is assigned to disj_y[2][lb])

examples/ex2.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ print(m)
2020

2121
# Feasibility
2222
# Subject to
23-
# XOR(disj_y) : y[1] + y[2] == 1.0 <- XOR constraint
23+
# XOR : y[1] + y[2] == 1.0 <- XOR constraint
2424
# con1[1,lb] : -x[1] + 5 y[1] <= 5.0 <- left-side of con1[1]
2525
# con1[1,ub] : x[1] + 7 y[1] <= 10.0 <- right-side of con1[1]
2626
# con1[2,lb] : -x[2] + 5 y[1] <= 5.0 <- left-side of con1[2]

src/bigm.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ big_m_reformulation!(constr::AbstractArray{<:ConstraintRef}, bin_var, M, i, j, k
4141
big_m_reformulation(constr[k], bin_var, M, i, j, k)
4242

4343
"""
44-
infer_bigm(constr)
44+
calculate_tight_M(constr::ConstraintRef{<:AbstractModel, MOI.ConstraintIndex{MOI.ScalarAffineFunction{T},V}}) where {T,V}
4545
46-
Apply interval arithmetic on a constraint to infer the tightest Big-M value from the bounds on the constraint.
46+
Apply interval arithmetic on a linear constraint to infer the tightest Big-M value from the bounds on the constraint.
4747
"""
48-
function infer_bigm(constr::ConstraintRef)
48+
function calculate_tight_M(constr::ConstraintRef{<:AbstractModel, MOI.ConstraintIndex{MOI.ScalarAffineFunction{T},V}}) where {T,V}
4949
constr_obj = constraint_object(constr)
5050
constr_terms = constr_obj.func.terms
5151
constr_set = constr_obj.set
@@ -78,4 +78,4 @@ function infer_bigm(constr::ConstraintRef)
7878
isinf(M) && error("M parameter for $constr cannot be infered due to lack of variable bounds.")
7979
return M
8080
end
81-
infer_bigm(constr::NonlinearConstraintRef) = error("$constr is a nonlinear constraint and a tight Big-M parameter cannot be inferred via interval arithmetic.")
81+
calculate_tight_M(constr::ConstraintRef) = error("$constr is a nonlinear or quadratic constraint and a tight Big-M parameter cannot be inferred via interval arithmetic.")

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ get_indices(arr) = Iterators.product(axes(arr)...)
1515
1616
Get M or ϵ parameter for reformulation.
1717
"""
18-
get_reform_param(param::Missing, args...; constr) = infer_bigm(constr) #if param is missing, infer bigM (ϵ does not pass a kwarg)
18+
get_reform_param(param::Missing, args...; constr) = calculate_tight_M(constr) #if param is missing, infer bigM (ϵ does not pass a kwarg)
1919
get_reform_param(param::Number, args...; kwargs...) = param #if param is a number return it
2020
get_reform_param(param::Union{Vector,Tuple}, idx::Int, args...; kwargs...) = #index param by next Integer arg (idx)
2121
get_reform_param(param[idx], args...; kwargs...)

0 commit comments

Comments
 (0)