Skip to content

Commit ce8dc33

Browse files
committed
Remove supportedconstrainttypes
1 parent 92c76cc commit ce8dc33

File tree

7 files changed

+49
-27
lines changed

7 files changed

+49
-27
lines changed

src/Bridges/bridge.jl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,13 @@ type `F`-in`S` created by the bride `b` in the model (i.e., of length equal to t
3030
"""
3131
MOI.get(b::AbstractBridge, ::MOI.ListOfConstraintIndices{F, S}) where {F, S} = CI{F, S}[]
3232

33-
# TODO supportsconstraint and supports constraint should maybe be on the type of the model in MOI too
34-
# that would clarify the fact that it does not depend on the current state of the model
3533
"""
3634
MOI.supportsconstraint(BT::Type{<:AbstractBridge}, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})::Bool
3735
3836
Return a `Bool` indicating whether the bridges of type `BT` support bridging `F`-in-`S` constraints.
3937
"""
4038
MOI.supportsconstraint(::Type{<:AbstractBridge}, ::Type{<:MOI.AbstractFunction}, ::Type{<:MOI.AbstractSet}) = false
4139

42-
"""
43-
supportedconstrainttypes(BT::Type{<:AbstractBridge})::Bool
44-
45-
Return a list of the types of constraints that can be bridged with a bridge of type `BT`.
46-
"""
47-
function supportedconstrainttypes end
48-
4940
"""
5041
addedconstrainttypes(BT::Type{<:AbstractBridge}, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})::Bool
5142

src/Bridges/detbridge.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ function LogDetBridge{T}(model, f::MOI.VectorAffineFunction{T}, s::MOI.LogDetCon
8686
end
8787

8888
MOI.supportsconstraint(::Type{LogDetBridge{T}}, ::Type{<:Union{MOI.VectorOfVariables, MOI.VectorAffineFunction{T}}}, ::Type{MOI.LogDetConeTriangle}) where T = true
89-
supportedconstrainttypes(::Type{LogDetBridge{T}}) where T = [(MOI.VectorOfVariables, MOI.LogDetConeTriangle), (MOI.VectorAffineFunction{T}, MOI.LogDetConeTriangle)]
9089
addedconstrainttypes(::Type{LogDetBridge{T}}, ::Type{<:Union{MOI.VectorOfVariables, MOI.VectorAffineFunction{T}}}, ::Type{MOI.LogDetConeTriangle}) where T = [(MOI.VectorAffineFunction{T}, MOI.PositiveSemidefiniteConeTriangle), (MOI.VectorAffineFunction{T}, MOI.ExponentialCone), (MOI.ScalarAffineFunction{T}, MOI.LessThan{T})]
9190

9291
"""
@@ -179,7 +178,6 @@ function RootDetBridge{T}(model, f::MOI.VectorAffineFunction{T}, s::MOI.RootDetC
179178
end
180179

181180
MOI.supportsconstraint(::Type{RootDetBridge{T}}, ::Type{<:Union{MOI.VectorOfVariables, MOI.VectorAffineFunction{T}}}, ::Type{MOI.RootDetConeTriangle}) where T = true
182-
supportedconstrainttypes(::Type{RootDetBridge{T}}) where T = [(MOI.VectorOfVariables, MOI.RootDetConeTriangle), (MOI.VectorAffineFunction{T}, MOI.RootDetConeTriangle)]
183181
addedconstrainttypes(::Type{RootDetBridge{T}}, ::Type{<:Union{MOI.VectorOfVariables, MOI.VectorAffineFunction{T}}}, ::Type{MOI.RootDetConeTriangle}) where T = [(MOI.VectorAffineFunction{T}, MOI.PositiveSemidefiniteConeTriangle), (MOI.VectorAffineFunction{T}, MOI.GeometricMeanCone)]
184182

185183
# Attributes, Bridge acting as an model

src/Bridges/geomeanbridge.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ function GeoMeanBridge{T}(model, f::MOI.VectorAffineFunction{T}, s::MOI.Geometri
9292
end
9393

9494
MOI.supportsconstraint(::Type{GeoMeanBridge{T}}, ::Type{<:Union{MOI.VectorOfVariables, MOI.VectorAffineFunction{T}}}, ::Type{MOI.GeometricMeanCone}) where T = true
95-
supportedconstrainttypes(::Type{GeoMeanBridge{T}}) where T = [(MOI.VectorOfVariables, MOI.GeometricMeanCone), (MOI.VectorAffineFunction{T}, MOI.GeometricMeanCone)]
9695
addedconstrainttypes(::Type{GeoMeanBridge{T}}, ::Type{<:Union{MOI.VectorOfVariables, MOI.VectorAffineFunction{T}}}, ::Type{MOI.GeometricMeanCone}) where T = [(MOI.ScalarAffineFunction{T}, MOI.LessThan{T}), (MOI.VectorAffineFunction{T}, MOI.RotatedSecondOrderCone)]
9796

9897
# Attributes, Bridge acting as an model

src/Bridges/intervalbridge.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ function SplitIntervalBridge{T}(model, f::MOI.ScalarAffineFunction{T}, s::MOI.In
1414
end
1515

1616
MOI.supportsconstraint(::Type{SplitIntervalBridge{T}}, ::Type{MOI.ScalarAffineFunction{T}}, ::Type{MOI.Interval{T}}) where T = true
17-
supportedconstrainttypes(::Type{SplitIntervalBridge{T}}) where T = [(MOI.ScalarAffineFunction{T}, MOI.Interval{T})]
1817
addedconstrainttypes(::Type{SplitIntervalBridge{T}}, ::Type{MOI.ScalarAffineFunction{T}}, ::Type{MOI.Interval{T}}) where T = [(MOI.ScalarAffineFunction{T}, MOI.GreaterThan{T}), (MOI.ScalarAffineFunction{T}, MOI.LessThan{T})]
1918

2019
# Attributes, Bridge acting as an model

src/Bridges/lazybridgeoptimizer.jl

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,15 @@ function _dist(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{
3535
end
3636
end
3737

38-
"""
39-
addbridge!(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
40-
41-
Enable the use of the bridges of type `BT` by `b`.
42-
"""
43-
function addbridge!(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
44-
push!(b.bridgetypes, BT)
38+
# Update `b.dist` and `b.dest` for constraint types in `constraints`
39+
function update_dist!(b::LazyBridgeOptimizer, constraints)
4540
# Bellman-Ford algorithm
4641
changed = true # Has b.dist changed in the last iteration ?
4742
while changed
4843
changed = false
4944
for BT in b.bridgetypes
50-
for (F, S) in supportedconstrainttypes(BT)
51-
if all(C -> MOI.supportsconstraint(b, C[1], C[2]), addedconstrainttypes(BT, F, S))
45+
for (F, S) in constraints
46+
if MOI.supportsconstraint(BT, F, S) && all(C -> MOI.supportsconstraint(b, C[1], C[2]), addedconstrainttypes(BT, F, S))
5247
# Number of bridges needed using BT
5348
dist = sum(C -> _dist(b, C[1], C[2]), addedconstrainttypes(BT, F, S))
5449
# Is it better that what can currently be done ?
@@ -63,9 +58,52 @@ function addbridge!(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
6358
end
6459
end
6560

61+
function fill_required_constraints!(required::Set{Tuple{DataType, DataType}}, b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})
62+
if MOI.supportsconstraint(b.model, F, S) || (F, S) in keys(b.best)
63+
return # The constraint is supported
64+
end
65+
if (F, S) in required
66+
return # The requirements for this constraint have already been added or are being added
67+
end
68+
# The constraint is not supported yet, add in `required` the required constraint types to bridge it
69+
push!(required, (F, S))
70+
for BT in b.bridgetypes
71+
if MOI.supportsconstraint(BT, F, S)
72+
for C in addedconstrainttypes(BT, F, S)
73+
fill_required_constraints!(required, b, C[1], C[2])
74+
end
75+
end
76+
end
77+
end
78+
79+
# Compute dist[(F, S)] and best[(F, S)]
80+
function update_constraint!(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})
81+
required = Set{Tuple{DataType, DataType}}()
82+
fill_required_constraints!(required, b, F, S)
83+
update_dist!(b, required)
84+
end
85+
86+
"""
87+
addbridge!(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
88+
89+
Enable the use of the bridges of type `BT` by `b`.
90+
"""
91+
function addbridge!(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
92+
push!(b.bridgetypes, BT)
93+
# Some constraints (F, S) in keys(b.best) may now be bridged
94+
# with a less briges than `b.dist[(F, S)] using `BT`
95+
update_dist!(b, keys(b.best))
96+
end
97+
6698
# It only bridges when the constraint is not supporting, hence the name "Lazy"
6799
function isbridged(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})
68100
!MOI.supportsconstraint(b.model, F, S)
69101
end
70-
supportsbridgingconstraint(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet}) = (F, S) in keys(b.best)
71-
bridgetype(b::LazyBridgeOptimizer{BT}, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet}) where BT = b.best[(F, S)]
102+
function supportsbridgingconstraint(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})
103+
update_constraint!(b, F, S)
104+
(F, S) in keys(b.best)
105+
end
106+
function bridgetype(b::LazyBridgeOptimizer{BT}, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet}) where BT
107+
update_constraint!(b, F, S)
108+
b.best[(F, S)]
109+
end

src/Bridges/rsocbridge.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ function RSOCBridge{T}(model, f::MOI.VectorAffineFunction{T}, s::MOI.RotatedSeco
3636
end
3737

3838
MOI.supportsconstraint(::Type{RSOCBridge{T}}, ::Type{<:Union{MOI.VectorOfVariables, MOI.VectorAffineFunction{T}}}, ::Type{MOI.RotatedSecondOrderCone}) where T = true
39-
supportedconstrainttypes(::Type{RSOCBridge{T}}) where T = [(MOI.VectorOfVariables, MOI.RotatedSecondOrderCone), (MOI.VectorAffineFunction{T}, MOI.RotatedSecondOrderCone)]
4039
addedconstrainttypes(::Type{RSOCBridge{T}}, ::Type{<:Union{MOI.VectorOfVariables, MOI.VectorAffineFunction{T}}}, ::Type{MOI.RotatedSecondOrderCone}) where T = [(MOI.VectorAffineFunction{T}, MOI.SecondOrderCone)]
4140

4241
# Attributes, Bridge acting as an model

src/Bridges/soctopsdbridge.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ _SOCtoPSDCaff(f::MOI.VectorOfVariables, ::Type{T}) where T = _SOCtoPSDCaff(MOI.V
6565
_SOCtoPSDCaff(f::MOI.VectorAffineFunction, ::Type) = _SOCtoPSDCaff(f, MOIU.eachscalar(f)[1])
6666

6767
MOI.supportsconstraint(::Type{SOCtoPSDCBridge{T}}, ::Type{<:Union{MOI.VectorOfVariables, MOI.VectorAffineFunction{T}}}, ::Type{MOI.SecondOrderCone}) where T = true
68-
supportedconstrainttypes(::Type{SOCtoPSDCBridge{T}}) where T = [(MOI.VectorOfVariables, MOI.SecondOrderCone), (MOI.VectorAffineFunction{T}, MOI.SecondOrderCone)]
6968
addedconstrainttypes(::Type{SOCtoPSDCBridge{T}}, ::Type{<:Union{MOI.VectorOfVariables, MOI.VectorAffineFunction{T}}}, ::Type{MOI.SecondOrderCone}) where T = [(MOI.VectorAffineFunction{T}, MOI.PositiveSemidefiniteConeTriangle)]
7069

7170
function MOI.canget(instance::MOI.AbstractOptimizer, a::Union{MOI.ConstraintPrimal, MOI.ConstraintDual}, ::Type{SOCtoPSDCBridge{T}}) where T
@@ -117,7 +116,6 @@ struct RSOCtoPSDCBridge{T} <: AbstractBridge
117116
cr::CI{MOI.VectorAffineFunction{T}, MOI.PositiveSemidefiniteConeTriangle}
118117
end
119118
MOI.supportsconstraint(::Type{RSOCtoPSDCBridge{T}}, ::Type{<:Union{MOI.VectorOfVariables, MOI.VectorAffineFunction{T}}}, ::Type{MOI.RotatedSecondOrderCone}) where T = true
120-
supportedconstrainttypes(::Type{RSOCtoPSDCBridge{T}}) where T = [(MOI.VectorOfVariables, MOI.RotatedSecondOrderCone), (MOI.VectorAffineFunction{T}, MOI.RotatedSecondOrderCone)]
121119
addedconstrainttypes(::Type{RSOCtoPSDCBridge{T}}, ::Type{<:Union{MOI.VectorOfVariables, MOI.VectorAffineFunction{T}}}, ::Type{MOI.RotatedSecondOrderCone}) where T = [(MOI.VectorAffineFunction{T}, MOI.PositiveSemidefiniteConeTriangle)]
122120
function RSOCtoPSDCBridge{T}(instance, f, s::MOI.RotatedSecondOrderCone) where T
123121
d = MOI.dimension(s)-1

0 commit comments

Comments
 (0)