Skip to content

Commit 6f1f160

Browse files
committed
✨ Add RequiredBridges attribute
1 parent 66d3754 commit 6f1f160

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/Bridges/lazybridgeoptimizer.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ struct LazyBridgeOptimizer{OT<:MOI.ModelLike, MT<:MOI.ModelLike} <: AbstractBrid
1919
best::Dict{Tuple{DataType, DataType}, DataType} # (F, S) -> Bridge to be used for an `F`-in-`S` constraint
2020
end
2121
function LazyBridgeOptimizer(model::MOI.ModelLike, bridged::MOI.ModelLike)
22-
LazyBridgeOptimizer{typeof(model),
23-
typeof(bridged)}(model, bridged,
24-
Dict{CI, AbstractBridge}(),
25-
Any[],
26-
Dict{Tuple{DataType, DataType}, Int}(),
27-
Dict{Tuple{DataType, DataType}, DataType}())
22+
optimizer = LazyBridgeOptimizer{typeof(model), typeof(bridged)}(
23+
model, bridged, Dict{CI, AbstractBridge}(), Any[],
24+
Dict{Tuple{DataType, DataType}, Int}(),
25+
Dict{Tuple{DataType, DataType}, DataType}())
26+
for bridge in MOI.get(model, MOI.RequiredBridges())
27+
add_bridge(model, bridge)
28+
end
29+
return optimizer
2830
end
2931

3032
function _dist(b::LazyBridgeOptimizer, F::Type{<:MOI.AbstractFunction}, S::Type{<:MOI.AbstractSet})

src/attributes.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,18 @@ An optimizer attribute for the string identifying the solver/optimizer.
332332
"""
333333
struct SolverName <: AbstractOptimizerAttribute end
334334

335+
"""
336+
RequiredBridges()
337+
338+
A list of bridges that are required when using the optimizer. For instance, if
339+
an optimizer uses a different representation of a set, it can defined a custom
340+
set with a bridge that transforms the MOI set into the custom set and return
341+
this bridge as value of this attribute.
342+
"""
343+
struct RequiredBridges <: AbstractOptimizerAttribute end
344+
345+
get(model::ModelLike, ::RequiredBridges) = []
346+
335347
## Model attributes
336348

337349
"""
@@ -900,7 +912,8 @@ method should be defined for attibutes which are copied indirectly during
900912
* [`ListOfOptimizerAttributesSet`](@ref), [`ListOfModelAttributesSet`](@ref),
901913
[`ListOfConstraintAttributesSet`](@ref) and
902914
[`ListOfVariableAttributesSet`](@ref).
903-
* [`SolverName`](@ref) and [`RawSolver`](@ref): these attributes cannot be set.
915+
* [`SolverName`](@ref), [`RequiredBridges`](@ref) and [`RawSolver`](@ref): these
916+
attributes cannot be set.
904917
* [`NumberOfVariables`](@ref) and [`ListOfVariableIndices`](@ref): these
905918
attributes are set indirectly by [`add_variable`](@ref) and
906919
[`add_variables`](@ref).
@@ -919,6 +932,7 @@ function is_copyable(::Union{ListOfOptimizerAttributesSet,
919932
ListOfConstraintAttributesSet,
920933
ListOfVariableAttributesSet,
921934
SolverName,
935+
RequiredBridges,
922936
RawSolver,
923937
NumberOfVariables,
924938
ListOfVariableIndices,

0 commit comments

Comments
 (0)