Skip to content

Commit 2bc5044

Browse files
authored
Merge pull request #647 from JuliaOpt/bl/supports_constraint_no_update
🐛 Fix lazy bridge check for supported constraints
2 parents cd1958c + 2930ffc commit 2bc5044

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/Bridges/lazybridgeoptimizer.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function update_dist!(b::LazyBridgeOptimizer, constraints)
4343
changed = false
4444
for BT in b.bridgetypes
4545
for (F, S) in constraints
46-
if MOI.supports_constraint(BT, F, S) && all(C -> MOI.supports_constraint(b, C[1], C[2]), added_constraint_types(BT, F, S))
46+
if MOI.supports_constraint(BT, F, S) && all(C -> supports_constraint_no_update(b, C[1], C[2]), added_constraint_types(BT, F, S))
4747
# Number of bridges needed using BT
4848
dist = 1 + sum(C -> _dist(b, C[1], C[2]), added_constraint_types(BT, F, S))
4949
# Is it better that what can currently be done ?
@@ -59,7 +59,7 @@ function update_dist!(b::LazyBridgeOptimizer, constraints)
5959
end
6060

6161
function fill_required_constraints!(required::Set{Tuple{DataType, DataType}}, b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})
62-
if MOI.supports_constraint(b.model, F, S) || (F, S) in keys(b.best)
62+
if supports_constraint_no_update(b, F, S)
6363
return # The constraint is supported
6464
end
6565
if (F, S) in required
@@ -99,6 +99,11 @@ end
9999
function is_bridged(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})
100100
!MOI.supports_constraint(b.model, F, S)
101101
end
102+
# Same as supports_constraint but do not trigger `update_constraint!`. This is
103+
# used inside `update_constraint!`.
104+
function supports_constraint_no_update(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})
105+
return MOI.supports_constraint(b.model, F, S) || (F, S) in keys(b.best)
106+
end
102107
function supports_bridging_constraint(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})
103108
update_constraint!(b, F, S)
104109
return (F, S) in keys(b.best)

test/bridge.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,21 @@ MOI.supports_constraint(::ModelNoVAFinSOC{Float64},
167167
::Type{MOI.VectorAffineFunction{Float64}},
168168
::Type{MOI.SecondOrderCone}) = false
169169

170+
# Model supporting nothing
171+
MOIU.@model NothingModel () () () () () () () ()
172+
170173
@testset "LazyBridgeOptimizer" begin
174+
@testset "Unsupported constraint with cycles" begin
175+
# Test that `supports_constraint` works correctly when it is not
176+
# supported but the bridges forms a cycle
177+
mock = MOIU.MockOptimizer(NothingModel{Float64}())
178+
bridged = MOIB.full_bridge_optimizer(mock, Float64)
179+
@test !MOI.supports_constraint(
180+
bridged, MOI.SingleVariable, MOI.GreaterThan{Float64})
181+
@test !MOI.supports_constraint(
182+
bridged, MOI.VectorAffineFunction{Float64}, MOI.Nonpositives)
183+
end
184+
171185
mock = MOIU.MockOptimizer(NoRSOCModel{Float64}())
172186
bridged_mock = MOIB.LazyBridgeOptimizer(
173187
mock, MOIB.AllBridgedConstraints{Float64}())

0 commit comments

Comments
 (0)