Skip to content

Commit 7a8aebf

Browse files
committed
compact add_disjunction!
1 parent 2502562 commit 7a8aebf

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/macros.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,18 @@ function add_disjunction!(m::Model,disj...;reformulation::Symbol,M=missing,ϵ=1e
8686
#run checks
8787
@assert reformulation in [:big_m, :hull] "Invalid reformulation method passed to keyword argument `:reformulation`. Valid options are :big_m (Big-M Reformulation) and :hull (Hull Reformulation)."
8888
@assert length(disj) > 1 "At least 2 disjuncts must be included. If there is an empty disjunct, use `nothing`."
89-
90-
#get kwargs and set defaults if missing
91-
param = reformulation == :big_m ? M : ϵ
92-
bin_var = ismissing(name) ? Symbol("disj",gensym()) : name
9389

94-
#apply reformulation
90+
#create indicator variable
91+
bin_var = ismissing(name) ? Symbol("disj_",gensym()) : name
9592
if bin_var in keys(object_dictionary(m))
96-
@assert m[bin_var] isa Vector{VariableRef} "The binary variable $bin_var is already registered in the model and is not of type Vector{VariableRef}. Specify a new name for the disjunction."
97-
@assert length(disj) <= length(m[bin_var]) "The binary variable $bin_var is already registered in the model and its size is smaller than the number of disjunts. Specify a new name for the disjunction."
93+
@assert m[bin_var] isa AbstractArray{VariableRef} "The binary variable $bin_var is already registered in the model and is not of type AbstractArray{VariableRef}. Specify a new name for the disjunction."
94+
@assert length(disj) <= prod(size(m[bin_var])) "The binary variable $bin_var is already registered in the model and its size is smaller than the number of disjunts. Specify a new name for the disjunction."
9895
else
99-
#create indicator variable
10096
m[bin_var] = @variable(m, [eachindex(disj)], Bin, base_name = string(bin_var))
10197
end
10298

10399
#reformulate disjunction
100+
param = reformulation == :big_m ? M : ϵ
104101
reformulate_disjunction(m, disj...; bin_var, reformulation, param)
105102
end
106103

0 commit comments

Comments
 (0)