Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Bridges/Bridges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module Bridges

import MathOptInterface as MOI
const MOIU = MOI.Utilities

using ..MathOptComplements:
ComplementsWithSetType,
AbstractComplementarityRelaxation,
Expand Down
8 changes: 4 additions & 4 deletions src/Bridges/ComplementsVectorizeBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ function _set_constant(
::ComplementsWithSetType{<:MOI.GreaterThan},
x2,
) where {T}
return MOIU.get_bounds(model, T, x2)[1]
return MOI.Utilities.get_bounds(model, T, x2)[1]
end
function _set_constant(
::Type{T},
model,
::ComplementsWithSetType{<:MOI.LessThan},
x2,
) where {T}
return MOIU.get_bounds(model, T, x2)[2]
return MOI.Utilities.get_bounds(model, T, x2)[2]
end
function _set_constant(
::Type{T},
model,
::ComplementsWithSetType{<:MOI.EqualTo},
x2,
) where {T}
return MOIU.get_bounds(model, T, x2)[1]
return MOI.Utilities.get_bounds(model, T, x2)[1]
end

function MOI.Bridges.Constraint.bridge_constraint(
Expand All @@ -86,7 +86,7 @@ function MOI.Bridges.Constraint.bridge_constraint(
x2 = func.variables[2]
c = _set_constant(T, model, set, x2)
# Shift only x2: [x1, x2] → [x1, x2 - c]
shifted = MOIU.operate(vcat, T, one(T) * x1, one(T) * x2 - c)
shifted = MOI.Utilities.operate(vcat, T, one(T) * x1, one(T) * x2 - c)
ci = MOI.add_constraint(model, shifted, ComplementsWithSetType{SV}(2))
return ComplementsVectorizeBridge{T,F,S,SV}(ci, c)
end
Expand Down
15 changes: 10 additions & 5 deletions src/Bridges/FlipSignBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ function MOI.Bridges.Constraint.bridge_constraint(
set::ComplementsWithSetType{S1},
) where {T,F,S1,S2,G<:MOI.AbstractVectorFunction}
@assert set.dimension == 2
scalars = MOIU.scalarize(func)
scalars = MOI.Utilities.scalarize(func)
# Negate only the first component (the activity)
neg_x = MOIU.operate(-, T, scalars[1])
new_func = MOIU.operate(vcat, T, neg_x, scalars[2])
neg_x = MOI.Utilities.operate(-, T, scalars[1])
new_func = MOI.Utilities.operate(vcat, T, neg_x, scalars[2])
ci = MOI.add_constraint(model, new_func, ComplementsWithSetType{S2}(2))
return FlipSignBridge{T,F,S1,S2,G}(ci, func)
end
Expand All @@ -82,8 +82,13 @@ function MOI.Bridges.Constraint.concrete_bridge_type(
G::Type{<:MOI.AbstractVectorFunction},
::Type{ComplementsWithSetType{S1}},
) where {T,S1<:_FlippableSets}
H = MOIU.promote_operation(-, T, MOIU.scalar_type(G))
F = MOIU.promote_operation(vcat, T, H, MOIU.scalar_type(G))
H = MOI.Utilities.promote_operation(-, T, MOI.Utilities.scalar_type(G))
F = MOI.Utilities.promote_operation(
vcat,
T,
H,
MOI.Utilities.scalar_type(G),
)
S2 = _flip_set_type(S1)
return FlipSignBridge{T,F,S1,S2,G}
end
Expand Down
24 changes: 12 additions & 12 deletions src/Bridges/NonlinearBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,23 @@ function _complementarity_bounds(
::Type{T},
x2,
) where {T}
return (MOIU.get_bounds(model, T, x2)[1], T(Inf))
return (MOI.Utilities.get_bounds(model, T, x2)[1], T(Inf))
end
function _complementarity_bounds(
::Type{<:MOI.LessThan},
model,
::Type{T},
x2,
) where {T}
return (T(-Inf), MOIU.get_bounds(model, T, x2)[2])
return (T(-Inf), MOI.Utilities.get_bounds(model, T, x2)[2])
end
function _complementarity_bounds(
::Type{<:MOI.Interval},
model,
::Type{T},
x2,
) where {T}
return MOIU.get_bounds(model, T, x2)
return MOI.Utilities.get_bounds(model, T, x2)
end

"""
Expand Down Expand Up @@ -275,7 +275,7 @@ function _relax_complementarity_lower_bound!(
lb2,
ub2,
)
lb1, _ = MOIU.get_bounds(model, Float64, x1)
lb1, _ = MOI.Utilities.get_bounds(model, Float64, x1)
if isinf(lb1)
MOI.add_constraint(model, x1, MOI.GreaterThan(0.0))
else
Expand All @@ -296,7 +296,7 @@ function _relax_complementarity_upper_bound!(
lb2,
ub2,
)
_, ub1 = MOIU.get_bounds(model, Float64, x1)
_, ub1 = MOI.Utilities.get_bounds(model, Float64, x1)
if isinf(ub1)
MOI.add_constraint(model, x1, MOI.LessThan(0.0))
else
Expand Down Expand Up @@ -369,7 +369,7 @@ function _relax_complementarity_lower_bound!(
lb2,
ub2,
)
lb1, ub1 = MOIU.get_bounds(model, Float64, x1)
lb1, ub1 = MOI.Utilities.get_bounds(model, Float64, x1)
if isinf(lb1)
MOI.add_constraint(model, x1, MOI.GreaterThan(0.0))
else
Expand All @@ -393,7 +393,7 @@ function _relax_complementarity_upper_bound!(
lb2,
ub2,
)
lb1, ub1 = MOIU.get_bounds(model, Float64, x1)
lb1, ub1 = MOI.Utilities.get_bounds(model, Float64, x1)
if isinf(ub1)
MOI.add_constraint(model, x1, MOI.LessThan(0.0))
else
Expand All @@ -417,7 +417,7 @@ function _relax_complementarity_range!(
lb2,
ub2,
)
lb1, ub1 = MOIU.get_bounds(model, Float64, x1)
lb1, ub1 = MOI.Utilities.get_bounds(model, Float64, x1)
idc1 = MOI.add_constraint(
model,
_min_eps(x1, x2 - lb2, relaxation.epsilon),
Expand Down Expand Up @@ -455,7 +455,7 @@ function _relax_complementarity_lower_bound!(
ub2,
)
# Ensure we respect MOI's specs
lb1, _ = MOIU.get_bounds(model, Float64, x1)
lb1, _ = MOI.Utilities.get_bounds(model, Float64, x1)
@assert isinf(lb1) || iszero(lb1)

idc1 = MOI.add_constraint(
Expand Down Expand Up @@ -488,7 +488,7 @@ function _relax_complementarity_upper_bound!(
ub2,
)
# Ensure we respect MOI's specs
_, ub1 = MOIU.get_bounds(model, Float64, x1)
_, ub1 = MOI.Utilities.get_bounds(model, Float64, x1)
@assert isinf(ub1) || iszero(ub1)

idc1 = MOI.add_constraint(
Expand Down Expand Up @@ -553,7 +553,7 @@ function _relax_complementarity_lower_bound!(
lb2,
ub2,
)
lb1, ub1 = MOIU.get_bounds(model, Float64, x1)
lb1, ub1 = MOI.Utilities.get_bounds(model, Float64, x1)
if isinf(lb1)
MOI.add_constraint(model, x1, MOI.GreaterThan(0.0))
else
Expand All @@ -577,7 +577,7 @@ function _relax_complementarity_upper_bound!(
lb2,
ub2,
)
lb1, ub1 = MOIU.get_bounds(model, Float64, x1)
lb1, ub1 = MOI.Utilities.get_bounds(model, Float64, x1)
if isinf(ub1)
MOI.add_constraint(model, x1, MOI.LessThan(0.0))
else
Expand Down
6 changes: 3 additions & 3 deletions src/Bridges/SpecifySetTypeBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function MOI.Bridges.final_touch(
end

function _specify_set_type_pair!(model, ::Type{T}, x1, x2, bounds) where {T}
lb2, ub2 = MOIU.get_bounds(model, T, x2)
lb2, ub2 = MOI.Utilities.get_bounds(model, T, x2)
if !isinf(lb2) && isinf(ub2)
return _specify_lower_bound!(model, T, x1, x2, lb2, bounds)
elseif isinf(lb2) && !isinf(ub2)
Expand All @@ -150,7 +150,7 @@ function _specify_set_type_pair!(model, ::Type{T}, x1, x2, bounds) where {T}
end

function _specify_lower_bound!(model, ::Type{T}, x1, x2, lb2, bounds) where {T}
lb1, _ = MOIU.get_bounds(model, T, x1)
lb1, _ = MOI.Utilities.get_bounds(model, T, x1)
if isinf(lb1)
push!(bounds, MOI.add_constraint(model, x1, MOI.GreaterThan(zero(T))))
end
Expand All @@ -163,7 +163,7 @@ function _specify_lower_bound!(model, ::Type{T}, x1, x2, lb2, bounds) where {T}
end

function _specify_upper_bound!(model, ::Type{T}, x1, x2, ub2, bounds) where {T}
_, ub1 = MOIU.get_bounds(model, T, x1)
_, ub1 = MOI.Utilities.get_bounds(model, T, x1)
if isinf(ub1)
push!(bounds, MOI.add_constraint(model, x1, MOI.LessThan(zero(T))))
end
Expand Down
17 changes: 10 additions & 7 deletions src/Bridges/SplitIntervalBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function MOI.Bridges.Constraint.bridge_constraint(
set::ComplementsWithSetType{MOI.Interval{T}},
) where {T,G,F<:MOI.AbstractVectorFunction}
@assert set.dimension == 2
scalars = MOIU.scalarize(func)
scalars = MOI.Utilities.scalarize(func)
x_func = scalars[1] # activity (may be an expression)
y = scalars[2] # slack (must be a variable)
# y must be a single variable
Expand All @@ -83,10 +83,13 @@ function MOI.Bridges.Constraint.bridge_constraint(
xp, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(zero(T)))
xn, _ = MOI.add_constrained_variable(model, MOI.LessThan(zero(T)))
# x == xp + xn
eq_func = MOIU.operate(-, T, x_func, xp)
eq_func = MOIU.operate!(-, T, eq_func, xn)
equality =
MOIU.normalize_and_add_constraint(model, eq_func, MOI.EqualTo(zero(T)))
eq_func = MOI.Utilities.operate(-, T, x_func, xp)
eq_func = MOI.Utilities.operate!(-, T, eq_func, xn)
equality = MOI.Utilities.normalize_and_add_constraint(
model,
eq_func,
MOI.EqualTo(zero(T)),
)
# [xp, y] in ComplementsWithSetType{GreaterThan{T}}
lower = MOI.add_constraint(
model,
Expand Down Expand Up @@ -123,9 +126,9 @@ function MOI.Bridges.Constraint.concrete_bridge_type(
F::Type{<:MOI.AbstractVectorFunction},
::Type{ComplementsWithSetType{MOI.Interval{T}}},
) where {T}
G = MOIU.scalar_type(F)
G = MOI.Utilities.scalar_type(F)
# After `operate(-, T, G, VariableIndex)`, the type may promote
H = MOIU.promote_operation(-, T, G, MOI.VariableIndex)
H = MOI.Utilities.promote_operation(-, T, G, MOI.VariableIndex)
return SplitIntervalBridge{T,H,F}
end

Expand Down
10 changes: 5 additions & 5 deletions src/Bridges/VerticalBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function _parse_complementarity_constraint(
fun::MOI.AbstractVectorFunction,
n_comp,
)
exprs = MOIU.scalarize(fun)
exprs = MOI.Utilities.scalarize(fun)
@assert length(exprs) == 2*n_comp

cc_lhs = MOI.AbstractScalarFunction[]
Expand Down Expand Up @@ -268,12 +268,12 @@ function reformulate_to_vertical!(
for (lhs, x2) in zip(cc_lhs, cc_rhs)
if set isa MOI.Complements
# Check if x2 is bounded.
lb, ub = MOIU.get_bounds(model, T, x2)
lb, ub = MOI.Utilities.get_bounds(model, T, x2)
if isinf(lb) && isinf(ub)
# If x2 is unbounded, the LHS is directly converted to an equality constraint.
push!(
equalities,
MOIU.normalize_and_add_constraint(
MOI.Utilities.normalize_and_add_constraint(
model,
lhs,
MOI.EqualTo{T}(zero(T)),
Expand All @@ -292,10 +292,10 @@ function reformulate_to_vertical!(
# Else, reformulate LHS using vertical form
x1 = MOI.add_variable(model)
push!(slacks, x1)
new_lhs = MOIU.operate!(-, T, lhs, x1)
new_lhs = MOI.Utilities.operate!(-, T, lhs, x1)
push!(
equalities,
MOIU.normalize_and_add_constraint(
MOI.Utilities.normalize_and_add_constraint(
model,
new_lhs,
MOI.EqualTo{T}(zero(T)),
Expand Down
1 change: 0 additions & 1 deletion src/MathOptComplements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
module MathOptComplements

import MathOptInterface as MOI
const MOIU = MOI.Utilities

include("utils.jl")
include("attributes.jl")
Expand Down
7 changes: 6 additions & 1 deletion test/Bridges/ComplementsVectorizeBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ using MathOptComplements
x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0))
y, _ =
MOI.add_constrained_variable(model, MOI.EqualTo(2.0))
f = MOIU.operate(vcat, Float64, 1.0 * x, 1.0 * y - 2.0)
f = MOI.Utilities.operate(
vcat,
Float64,
1.0 * x,
1.0 * y - 2.0,
)
MOI.add_constraint(
model,
f,
Expand Down
8 changes: 4 additions & 4 deletions test/Bridges/FlipSignBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using MathOptComplements
model,
MOI.GreaterThan(0.0),
)
f = MOIU.operate(vcat, Float64, -1.0 * x, 1.0 * y)
f = MOI.Utilities.operate(vcat, Float64, -1.0 * x, 1.0 * y)
MOI.add_constraint(
model,
f,
Expand Down Expand Up @@ -63,7 +63,7 @@ using MathOptComplements
x, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0))
y, _ =
MOI.add_constrained_variable(model, MOI.LessThan(0.0))
f = MOIU.operate(vcat, Float64, -1.0 * x, 1.0 * y)
f = MOI.Utilities.operate(vcat, Float64, -1.0 * x, 1.0 * y)
MOI.add_constraint(
model,
f,
Expand Down Expand Up @@ -101,7 +101,7 @@ using MathOptComplements
model,
MOI.GreaterThan(3.0),
)
f = MOIU.operate(vcat, Float64, -1.0 * x, 1.0 * y)
f = MOI.Utilities.operate(vcat, Float64, -1.0 * x, 1.0 * y)
MOI.add_constraint(
model,
f,
Expand Down Expand Up @@ -137,7 +137,7 @@ using MathOptComplements
x, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0))
y, _ =
MOI.add_constrained_variable(model, MOI.LessThan(-2.0))
f = MOIU.operate(vcat, Float64, -1.0 * x, 1.0 * y)
f = MOI.Utilities.operate(vcat, Float64, -1.0 * x, 1.0 * y)
MOI.add_constraint(
model,
f,
Expand Down
Loading