Skip to content

Commit 590fd8b

Browse files
committed
remove JuMP prefix
1 parent 469c1f7 commit 590fd8b

File tree

12 files changed

+369
-369
lines changed

12 files changed

+369
-369
lines changed

examples/ex5.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# https://arxiv.org/pdf/2303.04375.pdf
1+
# Nested GDP: https://arxiv.org/pdf/2303.04375.pdf
22
using DisjunctiveProgramming
33

44
##

examples/ex6.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using DisjunctiveProgramming
22

3-
##
3+
## Multi-level Nested GDP
44
m = GDPModel()
55
@variable(m, -5 <= x[1:3] <= 5)
66

src/bigm.jl

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# BIG-M VALUE
33
################################################################################
44
# Get Big-M value for a particular constraint
5-
function _get_M_value(func::JuMP.AbstractJuMPScalar, set::_MOI.AbstractSet, method::BigM)
5+
function _get_M_value(func::AbstractJuMPScalar, set::_MOI.AbstractSet, method::BigM)
66
if method.tighten
77
M = _get_tight_M(func, set, method)
88
else
@@ -12,7 +12,7 @@ function _get_M_value(func::JuMP.AbstractJuMPScalar, set::_MOI.AbstractSet, meth
1212
end
1313

1414
# Get the tightest Big-M value for a particular constraint
15-
function _get_tight_M(func::JuMP.AbstractJuMPScalar, set::_MOI.AbstractSet, method::BigM)
15+
function _get_tight_M(func::AbstractJuMPScalar, set::_MOI.AbstractSet, method::BigM)
1616
M = min.(method.value, _calculate_tight_M(func, set, method)) #broadcast for when S <: MOI.Interval or MOI.EqualTo or MOI.Zeros
1717
if any(isinf.(M))
1818
error("A finite Big-M value must be used. The value obtained was $M.")
@@ -21,14 +21,14 @@ function _get_tight_M(func::JuMP.AbstractJuMPScalar, set::_MOI.AbstractSet, meth
2121
end
2222

2323
# Get user-specified Big-M value
24-
function _get_M(::JuMP.AbstractJuMPScalar, ::Union{_MOI.LessThan, _MOI.GreaterThan, _MOI.Nonnegatives, _MOI.Nonpositives}, method::BigM)
24+
function _get_M(::AbstractJuMPScalar, ::Union{_MOI.LessThan, _MOI.GreaterThan, _MOI.Nonnegatives, _MOI.Nonpositives}, method::BigM)
2525
M = method.value
2626
if isinf(M)
2727
error("A finite Big-M value must be used. The value given was $M.")
2828
end
2929
return M
3030
end
31-
function _get_M(::JuMP.AbstractJuMPScalar, ::Union{_MOI.Interval, _MOI.EqualTo, _MOI.Zeros}, method::BigM)
31+
function _get_M(::AbstractJuMPScalar, ::Union{_MOI.Interval, _MOI.EqualTo, _MOI.Zeros}, method::BigM)
3232
M = method.value
3333
if isinf(M)
3434
error("A finite Big-M value must be used. The value given was $M.")
@@ -37,64 +37,64 @@ function _get_M(::JuMP.AbstractJuMPScalar, ::Union{_MOI.Interval, _MOI.EqualTo,
3737
end
3838

3939
# Apply interval arithmetic on a linear constraint to infer the tightest Big-M value from the bounds on the constraint.
40-
function _calculate_tight_M(func::JuMP.AffExpr, set::_MOI.LessThan, method::BigM)
40+
function _calculate_tight_M(func::AffExpr, set::_MOI.LessThan, method::BigM)
4141
return _interval_arithmetic_LessThan(func, -set.upper, method)
4242
end
43-
function _calculate_tight_M(func::JuMP.AffExpr, set::_MOI.GreaterThan, method::BigM)
43+
function _calculate_tight_M(func::AffExpr, set::_MOI.GreaterThan, method::BigM)
4444
return _interval_arithmetic_GreaterThan(func, -set.lower, method)
4545
end
46-
function _calculate_tight_M(func::JuMP.AffExpr, ::_MOI.Nonpositives, method::BigM)
46+
function _calculate_tight_M(func::AffExpr, ::_MOI.Nonpositives, method::BigM)
4747
return _interval_arithmetic_LessThan(func, 0.0, method)
4848
end
49-
function _calculate_tight_M(func::JuMP.AffExpr, ::_MOI.Nonnegatives, method::BigM)
49+
function _calculate_tight_M(func::AffExpr, ::_MOI.Nonnegatives, method::BigM)
5050
return _interval_arithmetic_GreaterThan(func, 0.0, method)
5151
end
52-
function _calculate_tight_M(func::JuMP.AffExpr, set::_MOI.Interval, method::BigM)
52+
function _calculate_tight_M(func::AffExpr, set::_MOI.Interval, method::BigM)
5353
return (
5454
_interval_arithmetic_GreaterThan(func, -set.lower, method),
5555
_interval_arithmetic_LessThan(func, -set.upper, method)
5656
)
5757
end
58-
function _calculate_tight_M(func::JuMP.AffExpr, set::_MOI.EqualTo, method::BigM)
58+
function _calculate_tight_M(func::AffExpr, set::_MOI.EqualTo, method::BigM)
5959
return (
6060
_interval_arithmetic_GreaterThan(func, -set.value, method),
6161
_interval_arithmetic_LessThan(func, -set.value, method)
6262
)
6363
end
64-
function _calculate_tight_M(func::JuMP.AffExpr, ::_MOI.Zeros, method::BigM)
64+
function _calculate_tight_M(func::AffExpr, ::_MOI.Zeros, method::BigM)
6565
return (
6666
_interval_arithmetic_GreaterThan(func, 0.0, method),
6767
_interval_arithmetic_LessThan(func, 0.0, method)
6868
)
6969
end
7070
# fallbacks for other scalar constraints
71-
_calculate_tight_M(func::Union{JuMP.QuadExpr, JuMP.NonlinearExpr}, set::Union{_MOI.Interval, _MOI.EqualTo, _MOI.Zeros}, method::BigM) = (Inf, Inf)
72-
_calculate_tight_M(func::Union{JuMP.QuadExpr, JuMP.NonlinearExpr}, set::Union{_MOI.LessThan, _MOI.GreaterThan, _MOI.Nonnegatives, _MOI.Nonpositives}, method::BigM) = Inf
71+
_calculate_tight_M(func::Union{QuadExpr, NonlinearExpr}, set::Union{_MOI.Interval, _MOI.EqualTo, _MOI.Zeros}, method::BigM) = (Inf, Inf)
72+
_calculate_tight_M(func::Union{QuadExpr, NonlinearExpr}, set::Union{_MOI.LessThan, _MOI.GreaterThan, _MOI.Nonnegatives, _MOI.Nonpositives}, method::BigM) = Inf
7373
_calculate_tight_M(func, set, method::BigM) = error("BigM method not implemented for constraint type $(typeof(func)) in $(typeof(set))")
7474

7575
# get variable bounds for interval arithmetic
76-
function _update_variable_bounds(vref::JuMP.VariableRef, method::BigM)
77-
if JuMP.is_binary(vref)
76+
function _update_variable_bounds(vref::VariableRef, method::BigM)
77+
if is_binary(vref)
7878
lb = 0
79-
elseif !JuMP.has_lower_bound(vref)
79+
elseif !has_lower_bound(vref)
8080
lb = -Inf
8181
else
82-
lb = JuMP.lower_bound(vref)
82+
lb = lower_bound(vref)
8383
end
84-
if JuMP.is_binary(vref)
84+
if is_binary(vref)
8585
ub = 1
86-
elseif !JuMP.has_upper_bound(vref)
86+
elseif !has_upper_bound(vref)
8787
ub = Inf
8888
else
89-
ub = JuMP.upper_bound(vref)
89+
ub = upper_bound(vref)
9090
end
9191
return lb, ub
9292
end
9393

9494
# perform interval arithmetic to update the initial M value
95-
function _interval_arithmetic_LessThan(func::JuMP.AffExpr, M::Float64, method::BigM)
95+
function _interval_arithmetic_LessThan(func::AffExpr, M::Float64, method::BigM)
9696
for (var,coeff) in func.terms
97-
JuMP.is_binary(var) && continue #skip binary variables
97+
is_binary(var) && continue #skip binary variables
9898
if coeff > 0
9999
M += coeff*method.variable_bounds[var][2]
100100
else
@@ -103,9 +103,9 @@ function _interval_arithmetic_LessThan(func::JuMP.AffExpr, M::Float64, method::B
103103
end
104104
return M + func.constant
105105
end
106-
function _interval_arithmetic_GreaterThan(func::JuMP.AffExpr, M::Float64, method::BigM)
106+
function _interval_arithmetic_GreaterThan(func::AffExpr, M::Float64, method::BigM)
107107
for (var,coeff) in func.terms
108-
JuMP.is_binary(var) && continue #skip binary variables
108+
is_binary(var) && continue #skip binary variables
109109
if coeff < 0
110110
M += coeff*method.variable_bounds[var][2]
111111
else
@@ -119,81 +119,81 @@ end
119119
# BIG-M REFORMULATION
120120
################################################################################
121121
function reformulate_disjunct_constraint(
122-
model::JuMP.Model,
123-
con::JuMP.ScalarConstraint{T, S},
124-
bvref::JuMP.VariableRef,
122+
model::Model,
123+
con::ScalarConstraint{T, S},
124+
bvref::VariableRef,
125125
method::BigM
126126
) where {T, S <: _MOI.LessThan}
127127
M = _get_M_value(con.func, con.set, method)
128-
new_func = JuMP.@expression(model, con.func - M*(1-bvref))
129-
reform_con = JuMP.build_constraint(error, new_func, con.set)
128+
new_func = @expression(model, con.func - M*(1-bvref))
129+
reform_con = build_constraint(error, new_func, con.set)
130130
return [reform_con]
131131
end
132132
function reformulate_disjunct_constraint(
133-
model::JuMP.Model,
134-
con::JuMP.VectorConstraint{T, S, R},
135-
bvref::JuMP.VariableRef,
133+
model::Model,
134+
con::VectorConstraint{T, S, R},
135+
bvref::VariableRef,
136136
method::BigM
137137
) where {T, S <: _MOI.Nonpositives, R}
138138
M = [_get_M_value(func, con.set, method) for func in con.func]
139-
new_func = JuMP.@expression(model, [i=1:con.set.dimension],
139+
new_func = @expression(model, [i=1:con.set.dimension],
140140
con.func[i] - M[i]*(1-bvref)
141141
)
142-
reform_con = JuMP.build_constraint(error, new_func, con.set)
142+
reform_con = build_constraint(error, new_func, con.set)
143143
return [reform_con]
144144
end
145145
function reformulate_disjunct_constraint(
146-
model::JuMP.Model,
147-
con::JuMP.ScalarConstraint{T, S},
148-
bvref::JuMP.VariableRef,
146+
model::Model,
147+
con::ScalarConstraint{T, S},
148+
bvref::VariableRef,
149149
method::BigM
150150
) where {T, S <: _MOI.GreaterThan}
151151
M = _get_M_value(con.func, con.set, method)
152-
new_func = JuMP.@expression(model, con.func + M*(1-bvref))
153-
reform_con = JuMP.build_constraint(error, new_func, con.set)
152+
new_func = @expression(model, con.func + M*(1-bvref))
153+
reform_con = build_constraint(error, new_func, con.set)
154154
return [reform_con]
155155
end
156156
function reformulate_disjunct_constraint(
157-
model::JuMP.Model,
158-
con::JuMP.VectorConstraint{T, S, R},
159-
bvref::JuMP.VariableRef,
157+
model::Model,
158+
con::VectorConstraint{T, S, R},
159+
bvref::VariableRef,
160160
method::BigM
161161
) where {T, S <: _MOI.Nonnegatives, R}
162162
M = [_get_M_value(func, con.set, method) for func in con.func]
163-
new_func = JuMP.@expression(model, [i=1:con.set.dimension],
163+
new_func = @expression(model, [i=1:con.set.dimension],
164164
con.func[i] + M[i]*(1-bvref)
165165
)
166-
reform_con = JuMP.build_constraint(error, new_func, con.set)
166+
reform_con = build_constraint(error, new_func, con.set)
167167
return [reform_con]
168168
end
169169
function reformulate_disjunct_constraint(
170-
model::JuMP.Model,
171-
con::JuMP.ScalarConstraint{T, S},
172-
bvref::JuMP.VariableRef,
170+
model::Model,
171+
con::ScalarConstraint{T, S},
172+
bvref::VariableRef,
173173
method::BigM
174174
) where {T, S <: Union{_MOI.Interval, _MOI.EqualTo}}
175175
M = _get_M_value(con.func, con.set, method)
176-
new_func_gt = JuMP.@expression(model, con.func + M[1]*(1-bvref))
177-
new_func_lt = JuMP.@expression(model, con.func - M[2]*(1-bvref))
176+
new_func_gt = @expression(model, con.func + M[1]*(1-bvref))
177+
new_func_lt = @expression(model, con.func - M[2]*(1-bvref))
178178
set_values = _set_values(con.set)
179-
reform_con_gt = JuMP.build_constraint(error, new_func_gt, _MOI.GreaterThan(set_values[1]))
180-
reform_con_lt = JuMP.build_constraint(error, new_func_lt, _MOI.LessThan(set_values[2]))
179+
reform_con_gt = build_constraint(error, new_func_gt, _MOI.GreaterThan(set_values[1]))
180+
reform_con_lt = build_constraint(error, new_func_lt, _MOI.LessThan(set_values[2]))
181181
return [reform_con_gt, reform_con_lt]
182182
end
183183
function reformulate_disjunct_constraint(
184-
model::JuMP.Model,
185-
con::JuMP.VectorConstraint{T, S, R},
186-
bvref::JuMP.VariableRef,
184+
model::Model,
185+
con::VectorConstraint{T, S, R},
186+
bvref::VariableRef,
187187
method::BigM
188188
) where {T, S <: _MOI.Zeros, R}
189189
M = [_get_M_value(func, con.set, method) for func in con.func]
190-
new_func_nn = JuMP.@expression(model, [i=1:con.set.dimension],
190+
new_func_nn = @expression(model, [i=1:con.set.dimension],
191191
con.func[i] + M[i][1]*(1-bvref)
192192
)
193-
new_func_np = JuMP.@expression(model, [i=1:con.set.dimension],
193+
new_func_np = @expression(model, [i=1:con.set.dimension],
194194
con.func[i] - M[i][2]*(1-bvref)
195195
)
196-
reform_con_nn = JuMP.build_constraint(error, new_func_nn, _MOI.Nonnegatives(con.set.dimension))
197-
reform_con_np = JuMP.build_constraint(error, new_func_np, _MOI.Nonpositives(con.set.dimension))
196+
reform_con_nn = build_constraint(error, new_func_nn, _MOI.Nonnegatives(con.set.dimension))
197+
reform_con_np = build_constraint(error, new_func_np, _MOI.Nonpositives(con.set.dimension))
198198
return [reform_con_nn, reform_con_np]
199199
end

0 commit comments

Comments
 (0)