|
397 | 397 | (MOI.VectorAffineFunction{Float64}, MOI.PositiveSemidefiniteConeTriangle, 0))) |
398 | 398 | end |
399 | 399 | end |
| 400 | + |
| 401 | +# We need to test this in a module at the top level because it can't be defined |
| 402 | +# in a testset. If it runs without error, then we're okay. |
| 403 | +module TestExternalBridge |
| 404 | + using MathOptInterface |
| 405 | + |
| 406 | + struct StrictlyGreaterThan <: MathOptInterface.AbstractScalarSet end |
| 407 | + struct StrictlyGreaterBridge{T} <: MathOptInterface.Bridges.AbstractBridge end |
| 408 | + |
| 409 | + function StrictlyGreaterBridge( |
| 410 | + model, |
| 411 | + func::MathOptInterface.SingleVariable, |
| 412 | + set::StrictlyGreaterThan) |
| 413 | + return StrictlyGreaterBridge{Float64}() |
| 414 | + end |
| 415 | + |
| 416 | + function MathOptInterface.supports_constraint( |
| 417 | + ::Type{StrictlyGreaterBridge{T}}, |
| 418 | + ::Type{MathOptInterface.SingleVariable}, |
| 419 | + ::Type{StrictlyGreaterThan}) where {T} |
| 420 | + return true |
| 421 | + end |
| 422 | + |
| 423 | + function MathOptInterface.Bridges.added_constraint_types( |
| 424 | + ::Type{StrictlyGreaterBridge{T}}, |
| 425 | + ::Type{MathOptInterface.SingleVariable}, |
| 426 | + ::Type{StrictlyGreaterThan}) where {T} |
| 427 | + return [( |
| 428 | + MathOptInterface.SingleVariable, |
| 429 | + MathOptInterface.GreaterThan{T} |
| 430 | + )] |
| 431 | + end |
| 432 | + |
| 433 | + MathOptInterface.Bridges.@bridge(StrictlyGreater, StrictlyGreaterBridge, |
| 434 | + (StrictlyGreaterThan, ), |
| 435 | + (), |
| 436 | + (), |
| 437 | + (), |
| 438 | + (MathOptInterface.SingleVariable, ), |
| 439 | + (), |
| 440 | + (), |
| 441 | + () |
| 442 | + ) |
| 443 | +end |
| 444 | + |
| 445 | +@testset "@bridge with external components" begin |
| 446 | + model = SimpleModel{Float64}(); |
| 447 | + @test MOI.supports_constraint(model, MOI.SingleVariable, MOI.GreaterThan{Float64}) |
| 448 | + @test !MOI.supports_constraint(model, MOI.SingleVariable, TestExternalBridge.StrictlyGreaterThan) |
| 449 | + |
| 450 | + bridge = TestExternalBridge.StrictlyGreater{Float64}(model); |
| 451 | + @test MOI.supports_constraint(bridge, MOI.SingleVariable, MOI.GreaterThan{Float64}) |
| 452 | + @test MOI.supports_constraint(bridge, MOI.SingleVariable, TestExternalBridge.StrictlyGreaterThan) |
| 453 | +end |
0 commit comments