diff --git a/src/Bridges/Bridges.jl b/src/Bridges/Bridges.jl index f0ddaa8..5193581 100644 --- a/src/Bridges/Bridges.jl +++ b/src/Bridges/Bridges.jl @@ -6,7 +6,7 @@ module Bridges import MathOptInterface as MOI -const MOIU = MOI.Utilities + using ..MathOptComplements: ComplementsWithSetType, AbstractComplementarityRelaxation, diff --git a/src/Bridges/ComplementsVectorizeBridge.jl b/src/Bridges/ComplementsVectorizeBridge.jl index d16dd61..6a243e1 100644 --- a/src/Bridges/ComplementsVectorizeBridge.jl +++ b/src/Bridges/ComplementsVectorizeBridge.jl @@ -56,7 +56,7 @@ 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}, @@ -64,7 +64,7 @@ function _set_constant( ::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}, @@ -72,7 +72,7 @@ function _set_constant( ::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( @@ -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 diff --git a/src/Bridges/FlipSignBridge.jl b/src/Bridges/FlipSignBridge.jl index 33570dc..03cde16 100644 --- a/src/Bridges/FlipSignBridge.jl +++ b/src/Bridges/FlipSignBridge.jl @@ -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 @@ -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 diff --git a/src/Bridges/NonlinearBridge.jl b/src/Bridges/NonlinearBridge.jl index 4cc79df..7df4ed2 100644 --- a/src/Bridges/NonlinearBridge.jl +++ b/src/Bridges/NonlinearBridge.jl @@ -177,7 +177,7 @@ 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}, @@ -185,7 +185,7 @@ function _complementarity_bounds( ::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}, @@ -193,7 +193,7 @@ function _complementarity_bounds( ::Type{T}, x2, ) where {T} - return MOIU.get_bounds(model, T, x2) + return MOI.Utilities.get_bounds(model, T, x2) end """ @@ -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 @@ -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 @@ -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 @@ -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 @@ -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), @@ -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( @@ -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( @@ -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 @@ -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 diff --git a/src/Bridges/SpecifySetTypeBridge.jl b/src/Bridges/SpecifySetTypeBridge.jl index b5ba62d..ebac832 100644 --- a/src/Bridges/SpecifySetTypeBridge.jl +++ b/src/Bridges/SpecifySetTypeBridge.jl @@ -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) @@ -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 @@ -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 diff --git a/src/Bridges/SplitIntervalBridge.jl b/src/Bridges/SplitIntervalBridge.jl index 4084be7..150eb13 100644 --- a/src/Bridges/SplitIntervalBridge.jl +++ b/src/Bridges/SplitIntervalBridge.jl @@ -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 @@ -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, @@ -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 diff --git a/src/Bridges/VerticalBridge.jl b/src/Bridges/VerticalBridge.jl index d2ffa4a..203ea1a 100644 --- a/src/Bridges/VerticalBridge.jl +++ b/src/Bridges/VerticalBridge.jl @@ -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[] @@ -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)), @@ -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)), diff --git a/src/MathOptComplements.jl b/src/MathOptComplements.jl index 17f65e2..ea156d7 100644 --- a/src/MathOptComplements.jl +++ b/src/MathOptComplements.jl @@ -6,7 +6,6 @@ module MathOptComplements import MathOptInterface as MOI -const MOIU = MOI.Utilities include("utils.jl") include("attributes.jl") diff --git a/test/Bridges/ComplementsVectorizeBridge.jl b/test/Bridges/ComplementsVectorizeBridge.jl index 9f0ae12..313deb0 100644 --- a/test/Bridges/ComplementsVectorizeBridge.jl +++ b/test/Bridges/ComplementsVectorizeBridge.jl @@ -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, diff --git a/test/Bridges/FlipSignBridge.jl b/test/Bridges/FlipSignBridge.jl index 2d316ee..9d92684 100644 --- a/test/Bridges/FlipSignBridge.jl +++ b/test/Bridges/FlipSignBridge.jl @@ -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, @@ -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, @@ -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, @@ -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,