Skip to content

Commit e206bf8

Browse files
blegatodow
andauthored
Add tests for bridging cost attributes (#3002)
Co-authored-by: Oscar Dowson <odow@users.noreply.github.com>
1 parent c2ecb7f commit e206bf8

3 files changed

Lines changed: 63 additions & 1 deletion

File tree

src/Test/test_attribute.jl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,55 @@ function test_attribute_unsupported_constraint(model::MOI.ModelLike, ::Config)
393393
end
394394

395395
version_added(::typeof(test_attribute_unsupported_constraint)) = v"1.9.0"
396+
397+
"""
398+
test_attribute_VariableBridgingCost(model::MOI.ModelLike, config::Config)
399+
400+
Test that, for every set `S` that the model claims to support via
401+
`supports_add_constrained_variable(s)`, the corresponding
402+
[`MOI.VariableBridgingCost`](@ref) attribute returns a finite value.
403+
404+
This is the variable-side analog of the `ConstraintBridgingCost` check in
405+
`_basic_constraint_test_helper`.
406+
407+
The fallback works for most model but it may need custom method for some MOI
408+
layers (see https://github.com/jump-dev/MathOptInterface.jl/pull/3001#issuecomment-4468198935).
409+
410+
This test is here to catch that.
411+
"""
412+
function test_attribute_VariableBridgingCost(
413+
model::MOI.ModelLike,
414+
::Config{T},
415+
) where {T}
416+
for S in Any[
417+
MOI.GreaterThan{T},
418+
MOI.LessThan{T},
419+
MOI.EqualTo{T},
420+
MOI.Interval{T},
421+
MOI.Integer,
422+
MOI.ZeroOne,
423+
MOI.Semicontinuous{T},
424+
MOI.Semiinteger{T},
425+
]
426+
if MOI.supports_add_constrained_variable(model, S)
427+
@test MOI.get(model, MOI.VariableBridgingCost{S}()) < Inf
428+
end
429+
end
430+
for S in Any[
431+
MOI.Reals,
432+
MOI.Zeros,
433+
MOI.Nonnegatives,
434+
MOI.Nonpositives,
435+
MOI.SecondOrderCone,
436+
MOI.RotatedSecondOrderCone,
437+
MOI.ExponentialCone,
438+
MOI.PositiveSemidefiniteConeTriangle,
439+
]
440+
if MOI.supports_add_constrained_variables(model, S)
441+
@test MOI.get(model, MOI.VariableBridgingCost{S}()) < Inf
442+
end
443+
end
444+
return
445+
end
446+
447+
version_added(::typeof(test_attribute_VariableBridgingCost)) = v"1.52.0"

src/Test/test_basic_constraint.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ function _basic_constraint_test_helper(
253253
###
254254
@requires MOI.supports_constraint(model, F, S)
255255
###
256+
### Test MOI.ConstraintBridgingCost
257+
###
258+
# If `supports_constraint(F, S)` returns `true`, then the model must be
259+
# able to handle that pair (possibly via bridging), so the bridging cost
260+
# must be finite. The fallback works for most model but it may need
261+
# custom method for some MOI layer (see
262+
# https://github.com/jump-dev/MathOptInterface.jl/pull/3001#issuecomment-4468198935)
263+
# This test is here to catch that.
264+
@test MOI.get(model, MOI.ConstraintBridgingCost{F,S}()) < Inf
265+
###
256266
### Test MOI.NumberOfConstraints
257267
###
258268
@test MOI.get(model, MOI.NumberOfConstraints{F,S}()) == 0

test/Bridges/Constraint/test_IntervalToHyperRectangleBridge.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function test_basic(T)
3838
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{T}()),
3939
)
4040
bridged_mock = MOI.Bridges.Constraint.IntervalToHyperRectangle{T}(mock)
41-
config = MOI.Test.Config()
41+
config = MOI.Test.Config(T)
4242
MOI.Test.runtests(
4343
bridged_mock,
4444
config,

0 commit comments

Comments
 (0)