|
1 |
| -function add_disjunction(m::Model,disj...;reformulation=:BMR,M=missing,eps=1e-6,name=missing) |
| 1 | +function add_disjunction(m::Model,disj...;reformulation,M=missing,eps=1e-6,name=missing) |
2 | 2 | @assert m isa Model "A valid JuMP Model must be provided."
|
3 | 3 | @assert reformulation in [:BMR, :CHR] "Invalid reformulation method passed to keyword argument `:reformulation`. Valid options are :BMR (Big-M Reformulation) and :CHR (Convex-Hull Reormulation)."
|
4 |
| - |
| 4 | + @assert length(disj) > 1 "At least 2 disjuncts must be included." |
5 | 5 | #create binary indicator variables for each disjunction
|
6 | 6 | disj_name = ismissing(name) ? Symbol("disj",gensym()) : name
|
7 | 7 | @assert isnothing(variable_by_name(m,string(disj_name))) "Name for disjunction binary cannot be the same as an existing variable."
|
8 | 8 | eval(:(@variable($m, $disj_name[i = 1:length($disj)], Bin)))
|
9 | 9 | #enforce exclussive OR
|
10 | 10 | eval(:(@constraint($m,sum($disj_name[i] for i = 1:length($disj)) == 1)))
|
11 | 11 | #apply reformulation
|
12 |
| - if reformulation == :BMR |
13 |
| - reformulate(m, disj, disj_name, reformulation, M) |
14 |
| - elseif reformulation == :CHR |
15 |
| - reformulate(m, disj, disj_name, reformulation, eps) |
16 |
| - end |
| 12 | + param = reformulation == :BMR ? M : eps |
| 13 | + reformulate(m, disj, disj_name, reformulation, param) |
17 | 14 | end
|
0 commit comments