Skip to content
Open
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
29 changes: 29 additions & 0 deletions src/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,34 @@ function _concrete(
S,
)
end

# Dispatched assertion that mirrors `_concrete`: a bridge listed in
# `bridges(S)` must, per MOI's contract on `concrete_bridge_type`, support its
# source set before `concrete_bridge_type` (and the downstream
# `added_*_types`) can be called. We dispatch on the bridge supertype so the
# right `supports_*` method is queried.
function _supports(
bridge_type::Type{<:MOI.Bridges.Variable.AbstractBridge},
S::Type{<:MOI.AbstractSet},
)
return MOI.Bridges.Variable.supports_constrained_variable(bridge_type, S)
end
function _supports(
bridge_type::Type{<:MOI.Bridges.Constraint.AbstractBridge},
S::Type{<:MOI.AbstractSet},
)
return MOI.supports_constraint(bridge_type, MOI.VectorOfVariables, S)
end
function bridgeable(c::JuMP.AbstractConstraint, S::Type{<:MOI.AbstractSet})
bridge_types = bridges(S)
for bridge_type in bridge_types
BT, T = bridge_type
c = BridgeableConstraint(c, BT; coefficient_type = T)
# `concrete_bridge_type` documents that it may only be called when
# the bridge's `supports_*` predicate is `true`.
# Otherwise, it just return `BT{T}` for which `added_constrained_variable_types`
# is not implemented and that gives cryptic error.
@assert _supports(BT{T}, S)
concrete_bridge_type = _concrete(BT{T}, S)
for (ST,) in
MOI.Bridges.added_constrained_variable_types(concrete_bridge_type)
Expand Down Expand Up @@ -169,6 +192,12 @@ function bridgeable(
for bridge_type in bridge_types
BT, T = bridge_type
c = BridgeableConstraint(c, BT, coefficient_type = T)
# Same invariant as the variable version above: a bridge listed in
# `bridges(F, S)` must actually support `F`-in-`S` per MOI's contract
# on `concrete_bridge_type`. Failing this assertion means the call
# site listed a bridge in `bridges(F, S)` that does not bridge `F` in
# `S`.
@assert MOI.supports_constraint(BT{T}, F, S)
concrete_bridge_type =
MOI.Bridges.Constraint.concrete_bridge_type(BT{T}, F, S)
for (ST,) in
Expand Down
7 changes: 7 additions & 0 deletions test/testpolymodule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ function PolyJuMP.bridges(
PolyJuMP.coefficient_type_or_float(F),
)]
end
function MOI.supports_constraint(
::Type{<:DummyNonNegBridge},
::Type{<:MOI.AbstractVectorFunction},
::Type{<:NonNeg},
)
return true
end
function MOI.Bridges.added_constrained_variable_types(
::Type{<:DummyNonNegBridge},
)
Expand Down
2 changes: 1 addition & 1 deletion test/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function test_MonomialBasis(var)
@variable(m, p3[2:3], Poly(X))
@test isa(p3, JuMP.Containers.DenseAxisArray{PT,1,Tuple{UnitRange{Int}}})
_test_variable(m, p3[2], X)
@variable(m, p4[i=2:3, j=i:4], Poly(X), binary = true)
@variable(m, p4[i = 2:3, j = i:4], Poly(X), binary = true)
_test_variable(m, p4[2, 3], X, true)

X = [x^2, y^2]
Expand Down
Loading