Skip to content

Commit cd19d92

Browse files
committed
bug fix in add_disjunction function
1 parent 651a216 commit cd19d92

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/macros.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,22 @@ function add_disjunction!(m::Model,disj...;reformulation::Symbol,M=missing,ϵ=1e
132132
@assert reformulation in [:big_m, :convex_hull] "Invalid reformulation method passed to keyword argument `:reformulation`. Valid options are :big_m (Big-M Reformulation) and :convex_hull (Convex-Hull Reormulation)."
133133
@assert length(disj) > 1 "At least 2 disjuncts must be included. If there is an empty disjunct, use `nothing`."
134134

135-
#create binary indicator variables for each disjunction
135+
#get kw_args and set defaults if missing
136+
param = reformulation == :big_m ? M : ϵ
136137
bin_var = ismissing(name) ? Symbol("disj",gensym()) : name
137-
@assert !in(bin_var, keys(object_dictionary(m))) "The disjunction name $bin_var is already registered in the model. Specify new name."
138+
disj_name = ismissing(name) ? bin_var : Symbol("disj_",name)
138139

139-
#create indicator variable
140-
m[bin_var] = @variable(m, [eachindex(disj)], Bin, base_name = string(bin_var))
140+
#XOR constraint name
141+
xor_con = "XOR($disj_name)"
141142

143+
#apply reformulation
144+
@assert !in(bin_var, keys(object_dictionary(m))) "The disjunction name $bin_var is already registered in the model. Specify new name."
145+
#create indicator variable
146+
m[bin_var] = @variable(m, [eachindex(disj)], Bin, base_name = string(bin_var), lower_bound = 0, upper_bound = 1)
142147
#add xor constraint on binary variable
143-
xor_con = "XOR($bin_var)"
144148
m[Symbol(xor_con)] = @constraint(m, sum(m[bin_var]) == 1, base_name = xor_con)
145-
146-
#apply reformulation
147-
param = reformulation == :big_m ? M : ϵ
148-
reformulate_disjunction(m, disj; bin_var, reformulation, param)
149+
#reformulate disjunction
150+
reformulate_disjunction(m, disj...; bin_var, reformulation, param)
149151
end
150152

151153
macro proposition(m, expr)

0 commit comments

Comments
 (0)