Skip to content

Commit 591d71c

Browse files
committed
reduce allocations:
don't use variable_by_name, but store this in .ext Dict
1 parent 1b1b49e commit 591d71c

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DisjunctiveProgramming"
22
uuid = "0d27d021-0159-4c7d-b4a7-9ccb5d9366cf"
33
authors = ["hdavid16 <[email protected]>"]
4-
version = "0.3.4"
4+
version = "0.3.5"
55

66
[deps]
77
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"

src/hull.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function hull_reformulation!(constr::ConstraintRef{<:AbstractModel, MOI.Constrai
1919
#replace each variable with its disaggregated version
2020
for var_ref in get_constraint_variables(constr)
2121
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
22+
var_ref in values(m.ext[:disaggregated_variables]) && continue #disaggregated variables are not touched
2323
#get disaggregated variable reference
2424
var_name_i = name_disaggregated_variable(var_ref, bin_var, i)
2525
var_i_ref = variable_by_name(m, var_name_i)
@@ -85,7 +85,7 @@ function disaggregate_variables(m::Model, disj, bin_var)
8585
bounds_dict = :variable_bounds_dict in keys(obj_dict) ? obj_dict[:variable_bounds_dict] : Dict() #NOTE: should pass as an keyword argument
8686
for var in var_refs
8787
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
88+
var in values(m.ext[:disaggregated_variables]) && continue #skip already disaggregated variables
8989
#define UB and LB
9090
LB, UB = get_bounds(var, bounds_dict)
9191
#disaggregate variable and add bounding constraints
@@ -95,10 +95,7 @@ function disaggregate_variables(m::Model, disj, bin_var)
9595
var_name_i = Symbol(var_name_i_str)
9696
#create disaggregated variable
9797
var_i = add_disaggregated_variable(m, var, LB, UB, var_name_i_str)
98-
push!(
99-
m.ext[:disaggregated_variables],
100-
var_i
101-
)
98+
m.ext[:disaggregated_variables][var_name_i_str] = var_i
10299
#apply bounding constraints on disaggregated variable
103100
var_i_lb = "$(var_name_i)_lb"
104101
var_i_ub = "$(var_name_i)_ub"

src/reformulate.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function reformulate_disjunction(m::Model, disj...; bin_var, reformulation, para
1616
#run reformulation
1717
if reformulation == :hull
1818
if !in(:disaggregated_variables, keys(m.ext))
19-
m.ext[:disaggregated_variables] = Set([]) #record disaggregated variables to avoid duplicating disaggregation (nested disjunctions)
19+
m.ext[:disaggregated_variables] = Dict{String,VariableRef}() #record disaggregated variables to avoid duplicating disaggregation (nested disjunctions)
2020
end
2121
disaggregate_variables(m, disj, bin_var)
2222
end

0 commit comments

Comments
 (0)