Skip to content

Commit 5a03217

Browse files
committed
reduce allocaitons
1 parent 8fc934f commit 5a03217

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/hull.jl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ function hull_reformulation!(constr::ConstraintRef{<:AbstractModel, MOI.Constrai
1717
i = args[2] #get disjunct index
1818
bin_var_ref = m[bin_var][i]
1919
#replace each variable with its disaggregated version
20-
var_refs = setdiff(
21-
get_constraint_variables(constr),
22-
m.ext[:disaggregated_variables],
23-
m.ext[:boolean_variables]
24-
)
25-
for var_ref in var_refs
20+
for var_ref in get_constraint_variables(constr)
2621
is_binary(var_ref) && continue #NOTE: binaries from nested disjunctions are not disaggregated and don't need to be swapped out
22+
var_ref in m.ext[:disaggregated_variables] && continue #disaggregated variables are not touched
2723
#get disaggregated variable reference
2824
var_name_i = name_disaggregated_variable(var_ref, bin_var, i)
2925
var_i_ref = variable_by_name(m, var_name_i)
@@ -82,17 +78,14 @@ Disaggregate all variables in the model and tag them with the disjunction name.
8278
"""
8379
function disaggregate_variables(m::Model, disj, bin_var)
8480
#check that variables are bounded
85-
var_refs = setdiff(
86-
get_constraint_variables(disj),
87-
m.ext[:disaggregated_variables],
88-
m.ext[:boolean_variables]
89-
)
81+
var_refs = get_constraint_variables(disj)
9082
@assert all((has_upper_bound.(var_refs) .&& has_lower_bound.(var_refs)) .|| is_binary.(var_refs)) "All variables must be bounded to perform the Hull reformulation."
9183
#reformulate variables
9284
obj_dict = object_dictionary(m)
9385
bounds_dict = :variable_bounds_dict in keys(obj_dict) ? obj_dict[:variable_bounds_dict] : Dict() #NOTE: should pass as an keyword argument
9486
for var in var_refs
9587
is_binary(var) && continue #NOTE: don't disaggregate binary variables from nested disjunctions
88+
var in m.ext[:disaggregated_variables] && continue #skip already disaggregated variables
9689
#define UB and LB
9790
LB, UB = get_bounds(var, bounds_dict)
9891
#disaggregate variable and add bounding constraints

0 commit comments

Comments
 (0)