Skip to content

Commit 59de2af

Browse files
committed
bug fix for big m on nonlinear constraint
1 parent ccee564 commit 59de2af

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/reformulate.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ function BMR(m, constr, M, bin_var, i, k = missing)
6161
end
6262

6363
function apply_interval_arithmetic(ref)
64-
if ref isa ConstraintRef
64+
if ref isa NonlinearConstraintRef
65+
ref_str = string(ref)
66+
@assert length(findall(r"[<>]", ref_str)) <= 1 "$ref must be one of the following: GreaterThan, LessThan, or EqualTo."
67+
ref_func = replace(split(ref_str, r"[=<>]")[1], " " => "")
68+
ref_type = occursin(">", ref_str) ? :lower : :upper
69+
ref_rhs = parse(Float64,split(ref_str, " ")[end])
70+
elseif ref isa ConstraintRef
6571
ref_obj = constraint_object(ref)
6672
@assert ref_obj.set isa MOI.LessThan || ref_obj.set isa MOI.GreaterThan || ref_obj.set isa MOI.EqualTo "$ref must be one the following: GreaterThan, LessThan, or EqualTo."
6773
ref_func = string(ref_obj.func)
6874
ref_type = fieldnames(typeof(ref_obj.set))[1]
6975
ref_rhs = normalized_rhs(ref)
70-
elseif ref isa NonlinearConstraintRef
71-
ref_str = string(ref)
72-
@assert length(findall(r"[<>]", ref_str)) <= 1 "$ref must be one of the following: GreaterThan, LessThan, or EqualTo."
73-
ref_func = replace(split(ref_str, r"[=<>]")[1], " " => "")
74-
ref_type = occursin(">", ref_str) ? :lower : :upper
75-
ref_rhs = split(ref_str, " ")[end]
7676
end
7777
vars = all_variables(ref.model) #get all variable names
7878
for var in vars
@@ -125,11 +125,13 @@ function CHR(m, constr, M, bin_var, i, k = missing)
125125
error("Variable $var does not have an upper bound, an M value must be specified")
126126
end
127127
end
128+
#create disaggregated variable
128129
var_i = Symbol("$(var)_$i")
129130
if !(var_i in keys(m.obj_dict))
130131
eval(:(@variable($m, 0 <= $var_i <= $M)))
131132
eval(:(@constraint($m, $var_i <= $M * $bin_var_ref)))
132133
end
134+
#create convex hull constraint
133135
rhs = normalized_rhs(ref)
134136
set_normalized_rhs(ref,0)
135137
set_normalized_coefficient(ref, var, 0)

0 commit comments

Comments
 (0)