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
52 changes: 52 additions & 0 deletions src/Test/test_attribute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,55 @@ function test_attribute_unsupported_constraint(model::MOI.ModelLike, ::Config)
end

version_added(::typeof(test_attribute_unsupported_constraint)) = v"1.9.0"

"""
test_attribute_VariableBridgingCost(model::MOI.ModelLike, config::Config)

Test that, for every set `S` that the model claims to support via
`supports_add_constrained_variable(s)`, the corresponding
[`MOI.VariableBridgingCost`](@ref) attribute returns a finite value.

This is the variable-side analog of the `ConstraintBridgingCost` check in
`_basic_constraint_test_helper`.

The fallback works for most model but it may need custom method for some MOI
layers (see https://github.com/jump-dev/MathOptInterface.jl/pull/3001#issuecomment-4468198935).

This test is here to catch that.
"""
function test_attribute_VariableBridgingCost(
model::MOI.ModelLike,
::Config{T},
) where {T}
for S in Any[
MOI.GreaterThan{T},
MOI.LessThan{T},
MOI.EqualTo{T},
MOI.Interval{T},
MOI.Integer,
MOI.ZeroOne,
MOI.Semicontinuous{T},
MOI.Semiinteger{T},
]
if MOI.supports_add_constrained_variable(model, S)
@test MOI.get(model, MOI.VariableBridgingCost{S}()) < Inf
end
end
for S in Any[
MOI.Reals,
MOI.Zeros,
MOI.Nonnegatives,
MOI.Nonpositives,
MOI.SecondOrderCone,
MOI.RotatedSecondOrderCone,
MOI.ExponentialCone,
MOI.PositiveSemidefiniteConeTriangle,
]
if MOI.supports_add_constrained_variables(model, S)
@test MOI.get(model, MOI.VariableBridgingCost{S}()) < Inf
end
end
return
end

version_added(::typeof(test_attribute_VariableBridgingCost)) = v"1.52.0"
10 changes: 10 additions & 0 deletions src/Test/test_basic_constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ function _basic_constraint_test_helper(
###
@requires MOI.supports_constraint(model, F, S)
###
### Test MOI.ConstraintBridgingCost
###
# If `supports_constraint(F, S)` returns `true`, then the model must be
# able to handle that pair (possibly via bridging), so the bridging cost
# must be finite. The fallback works for most model but it may need
# custom method for some MOI layer (see
# https://github.com/jump-dev/MathOptInterface.jl/pull/3001#issuecomment-4468198935)
# This test is here to catch that.
@test MOI.get(model, MOI.ConstraintBridgingCost{F,S}()) < Inf
###
### Test MOI.NumberOfConstraints
###
@test MOI.get(model, MOI.NumberOfConstraints{F,S}()) == 0
Expand Down
Loading