Skip to content

Commit 67f2ad8

Browse files
authored
Merge pull request #689 from JuliaOpt/bl/noadded
Fix LazyBridgeOptimizer with bridge that add no constraints
2 parents 2bf97a6 + 5113de0 commit 67f2ad8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Bridges/lazybridgeoptimizer.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ function update_dist!(b::LazyBridgeOptimizer, constraints)
4545
for (F, S) in constraints
4646
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
48-
dist = 1 + sum(C -> _dist(b, C[1], C[2]), added_constraint_types(BT, F, S))
48+
dist = 1 + Compat.mapreduce(
49+
C -> _dist(b, C[1], C[2]), +,
50+
added_constraint_types(BT, F, S), init = 0)
4951
# Is it better that what can currently be done ?
5052
if dist < _dist(b, F, S)
5153
b.dist[(F, S)] = dist

test/bridge.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,29 @@ MOI.supports_constraint(::ModelNoVAFinSOC{Float64},
190190
# Model supporting nothing
191191
MOIU.@model NothingModel () () () () () () () ()
192192

193+
struct BridgeAddingNoConstraint{T} <: MOI.Bridges.AbstractBridge end
194+
MOIB.added_constraint_types(::Type{BridgeAddingNoConstraint{T}}) where {T} = []
195+
function MOI.supports_constraint(::Type{<:BridgeAddingNoConstraint},
196+
::Type{MOI.SingleVariable},
197+
::Type{MOI.Integer})
198+
return true
199+
end
200+
function MOIB.concrete_bridge_type(::Type{<:BridgeAddingNoConstraint{T}},
201+
::Type{MOI.SingleVariable},
202+
::Type{MOI.Integer}) where {T}
203+
return BridgeAddingNoConstraint{T}
204+
end
205+
193206
@testset "LazyBridgeOptimizer" begin
207+
@testset "Bridge adding no constraint" begin
208+
mock = MOIU.MockOptimizer(NothingModel{Int}())
209+
bridged = MOIB.LazyBridgeOptimizer(mock, NothingModel{Int}())
210+
MOI.Bridges.add_bridge(bridged, BridgeAddingNoConstraint{Float64})
211+
@test MOI.Bridges.supports_bridging_constraint(bridged,
212+
MOI.SingleVariable,
213+
MOI.Integer)
214+
end
215+
194216
@testset "Unsupported constraint with cycles" begin
195217
# Test that `supports_constraint` works correctly when it is not
196218
# supported but the bridges forms a cycle

0 commit comments

Comments
 (0)