Skip to content

Commit 5640b20

Browse files
committed
Update LazyBridgeOptimizer
1 parent 76bd42e commit 5640b20

File tree

1 file changed

+7
-50
lines changed

1 file changed

+7
-50
lines changed

src/Bridges/lazybridgeoptimizer.jl

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ function addbridge!(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
3737
i = 0
3838
for BT in b.bridgetypes
3939
i += 1
40-
@show i
41-
for (F, S) in supportedconstraints(BT)
42-
if all(MOI.supportsconstraint, addedconstraints(BT, F, S))
40+
for (F, S) in supportedconstrainttypes(BT)
41+
if all(C -> MOI.supportsconstraint(b, C...), addedconstrainttypes(BT, F, S))
4342
# Number of bridges needed using BT
44-
dist = sum(C -> _dist(b, C...), addedconstraints(BT, F, S))
43+
dist = sum(C -> _dist(b, C...), addedconstrainttypes(BT, F, S))
4544
# Is it better that what can currently be done ?
4645
if dist < _dist(b, F, S)
4746
b.dist[(F, S)] = dist
@@ -54,51 +53,9 @@ function addbridge!(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
5453
end
5554
end
5655

57-
function MOI.get(b::LazyBridgeOptimizer, attr::InstanceConstraintAttribute, ci::CI{F, S}) where {F, S}
58-
if MOI.supportsconstraint(b.model, F, S)
59-
MOI.get(b.model, attr, ci)
60-
else
61-
MOI.get(b.bridged, attr, ci)
62-
end
63-
end
64-
function MOI.get(b::LazyBridgeOptimizer, attr::SolverConstraintAttribute, ci::CI{F, S}) where {F, S}
65-
if MOI.supportsconstraint(b.model, F, S)
66-
MOI.get(b.model, attr, ci)
67-
else
68-
MOI.get(b.model, attr, bridge(b, ci))
69-
end
70-
end
71-
7256
# It only bridges when the constraint is not supporting, hence the name "Lazy"
73-
isbridged(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet}) = MOI.supportsconstraint(b.model, F, S)
74-
bridgetype(b::LazyBridgeOptimizer{BT}, ::Type{<:MOI.AbstractFunction}, ::Type{<:MOI.AbstractSet}) where BT = b.best[(typeof(f), typeof(s))]
75-
76-
# Constraints
77-
function MOI.supportsconstraint(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})
78-
|| (F, S) in keys(b.dist)
79-
end
80-
function MOI.canaddconstraint(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})
81-
MOI.canaddconstraint(b.model, F, S) || ((F, S) in b.best && all(C -> MOI.canaddconstraint(b, C...), addedconstraints(b.best[(F, S)], F, S)))
82-
end
83-
function MOI.addconstraint!(b::LazyBridgeOptimizer{T}, f::MOI.AbstractFunction, s::MOI.AbstractSet) where T
84-
if MOI.supportsconstraint(b.model, typeof(f), typeof(s))
85-
MOI.addconstraint!(b.model, f, s)
86-
else
87-
ci = MOI.addconstraint!(b.bridged, f, s)
88-
@assert !haskey(b.bridges, ci)
89-
b.bridges[ci] = (b.model, f, s)
90-
ci
91-
end
92-
end
93-
94-
for f in (:canmodifyconstraint, :modifyconstraint!)
95-
@eval begin
96-
function MOI.$f(b::LazyBridgeOptimizer, ci::CI{F, S}, change) where {F, S}
97-
if MOI.supportsconstraint(b.model, F, S)
98-
MOI.$f(b.model, ci, change)
99-
else
100-
$f(b, ci, change)
101-
end
102-
end
103-
end
57+
function isbridged(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})
58+
!MOI.supportsconstraint(b.model, F, S)
10459
end
60+
supportsbridgingconstraint(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet}) = (F, S) in keys(b.best)
61+
bridgetype(b::LazyBridgeOptimizer{BT}, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet}) where BT = b.best[(F, S)]

0 commit comments

Comments
 (0)