Skip to content

Commit 02b6fa3

Browse files
committed
close #55
1 parent 2e9f250 commit 02b6fa3

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

Project.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ authors = ["hdavid16 <[email protected]>"]
44
version = "0.3.2"
55

66
[deps]
7-
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
87
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
9-
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
108
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
119

1210
[compat]
13-
IntervalArithmetic = "0.20"
1411
JuMP = "1.2"
15-
Suppressor = "0.2"
1612
Symbolics = "4"
1713
julia = "1.6"
1814

src/DisjunctiveProgramming.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module DisjunctiveProgramming
22

3-
using JuMP, IntervalArithmetic, Symbolics, Suppressor
3+
using JuMP, Symbolics
44

55
export add_disjunction!, add_proposition!
66
export @disjunction, @proposition

src/bigm.jl

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,35 @@ big_m_reformulation!(constr::AbstractArray{<:ConstraintRef}, bin_var, M, i, j, k
4343
Apply interval arithmetic on a constraint to infer the tightest Big-M value from the bounds on the constraint.
4444
"""
4545
function infer_bigm(constr::ConstraintRef)
46-
#convert constraints into Expr to replace variables with interval sets and determine bounds
47-
constr_type, constr_func_expr, constr_rhs = parse_constraint(constr)
46+
constr_obj = constraint_object(constr)
47+
constr_terms = constr_obj.func.terms
48+
constr_set = constr_obj.set
4849
#create a map of variables to their bounds
49-
interval_map = Dict()
50-
vars = all_variables(constr.model)#constr.model[:gdp_variable_constrs]
51-
obj_dict = object_dictionary(constr.model)
52-
bounds_dict = :variable_bounds_dict in keys(obj_dict) ? obj_dict[:variable_bounds_dict] : Dict() #NOTE: should pass as an keyword argument
53-
for var in vars
54-
LB, UB = get_bounds(var, bounds_dict)
55-
interval_map[string(var)] = LB..UB
50+
bounds_dict = :variable_bounds_dict in keys(constr.model.ext) ? constr.model.ext[:variable_bounds_dict] : Dict()
51+
bounds_map = Dict(
52+
var => get_bounds(var, bounds_dict)
53+
for var in get_constraint_variables(constr)
54+
)
55+
#apply interval arithmetic
56+
if constr_set isa MOI.LessThan
57+
M = -constr_set.upper
58+
for (var,coeff) in constr_terms
59+
if coeff > 0
60+
M += coeff*bounds_map[var][2]
61+
else
62+
M += coeff*bounds_map[var][1]
63+
end
64+
end
65+
elseif constr_set isa MOI.GreaterThan
66+
M = -constr_st.lower
67+
for (var,coeff) in constr_terms
68+
if coeff < 0
69+
M += coeff*bounds_map[var][2]
70+
else
71+
M += coeff*bounds_map[var][1]
72+
end
73+
end
5674
end
57-
constr_func_expr = replace_intevals!(constr_func_expr, interval_map)
58-
#get bounds on the entire expression
59-
func_bounds = eval(constr_func_expr)
60-
Mlo = func_bounds.lo - constr_rhs
61-
Mhi = func_bounds.hi - constr_rhs
62-
M = constr_type == :(<=) ? Mhi : Mlo
6375
isinf(M) && error("M parameter for $constr cannot be infered due to lack of variable bounds.")
6476
return M
6577
end

0 commit comments

Comments
 (0)