Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
53 changes: 53 additions & 0 deletions src/Test/test_attribute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,57 @@
return
end

"""
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 analogue of the

Check warning on line 402 in src/Test/test_attribute.jl

View workflow job for this annotation

GitHub Actions / build

[vale] reported by reviewdog 🐶 [Google.Spelling] In general, use American spelling instead of 'analogue'. Raw Output: {"message": "[Google.Spelling] In general, use American spelling instead of 'analogue'.", "location": {"path": "src/Test/test_attribute.jl", "range": {"start": {"line": 402, "column": 27}}}, "severity": "WARNING"}
`ConstraintBridgingCost` check in `_basic_constraint_test_helper`.
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.
"""
function test_attribute_VariableBridgingCost(
model::MOI.ModelLike,
::Config{T},
) where {T}
scalar_sets = Type{<:MOI.AbstractScalarSet}[
MOI.GreaterThan{T},
MOI.LessThan{T},
MOI.EqualTo{T},
MOI.Interval{T},
MOI.Integer,
MOI.ZeroOne,
MOI.Semicontinuous{T},
MOI.Semiinteger{T},
]
vector_sets = Type{<:MOI.AbstractVectorSet}[
MOI.Reals,
MOI.Zeros,
MOI.Nonnegatives,
MOI.Nonpositives,
MOI.SecondOrderCone,
MOI.RotatedSecondOrderCone,
MOI.ExponentialCone,
MOI.PositiveSemidefiniteConeTriangle,
]
for S in scalar_sets
if MOI.supports_add_constrained_variable(model, S)
@test MOI.get(model, MOI.VariableBridgingCost{S}()) < Inf
end
end
for S in vector_sets
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"

version_added(::typeof(test_attribute_unsupported_constraint)) = v"1.9.0"
Comment thread
odow marked this conversation as resolved.
Outdated
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