Skip to content

Commit 8af4258

Browse files
committed
move input checking from macro to add_disjunction
1 parent 550ec85 commit 8af4258

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/disjunction.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
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)
22
@assert m isa Model "A valid JuMP Model must be provided."
33
@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."
55
#create binary indicator variables for each disjunction
66
disj_name = ismissing(name) ? Symbol("disj",gensym()) : name
77
@assert isnothing(variable_by_name(m,string(disj_name))) "Name for disjunction binary cannot be the same as an existing variable."
88
eval(:(@variable($m, $disj_name[i = 1:length($disj)], Bin)))
99
#enforce exclussive OR
1010
eval(:(@constraint($m,sum($disj_name[i] for i = 1:length($disj)) == 1)))
1111
#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)
1714
end

src/macro.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ macro disjunction(args...)
55
reformulation = filter(i -> i.args[1] == :reformulation, kw_args)
66
if !isempty(reformulation)
77
reformulation = reformulation[1].args[2]
8-
if length(pos_args[2:end]) < 2
9-
throw(DomainError(args, "At least 2 constraints expected"))
10-
end
118
else
129
throw(UndefKeywordError(:reformulation))
1310
end

0 commit comments

Comments
 (0)