Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Bridges/Constraint/bridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ Return a `Bool` indicating whether the bridges of type `BT` support bridging
constraint types that the bridge implements.
"""
function MOI.supports_constraint(
::Type{<:AbstractBridge},
::Type{<:MOI.AbstractFunction},
::Type{<:MOI.AbstractSet},
@nospecialize(BT::Type{<:AbstractBridge}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should be safe

@nospecialize(F::Type{<:MOI.AbstractFunction}),
@nospecialize(S::Type{<:MOI.AbstractSet}),
)
return false
end
Expand Down
6 changes: 3 additions & 3 deletions src/Bridges/Constraint/single_bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ function MOI.Bridges.supports_bridging_constrained_variable(
end

function MOI.Bridges.supports_bridging_constraint(
::SingleBridgeOptimizer{BT},
F::Type{<:MOI.AbstractFunction},
S::Type{<:MOI.AbstractSet},
@nospecialize(b::SingleBridgeOptimizer{BT}),
@nospecialize(F::Type{<:MOI.AbstractFunction}),
@nospecialize(S::Type{<:MOI.AbstractSet}),
) where {BT}
return MOI.supports_constraint(BT, F, S)
end
Expand Down
43 changes: 28 additions & 15 deletions src/Bridges/lazy_bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ end
Return the list of `VariableNode` that would be added if `BT` is used in `b`.
"""
function _variable_nodes(
b::LazyBridgeOptimizer,
::Type{BT},
) where {BT<:AbstractBridge}
@nospecialize(b::LazyBridgeOptimizer),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these shouldn't affect performance, it's a must do indeed

@nospecialize(BT),
)
return map(added_constrained_variable_types(BT)) do (S,)
return node(b, S)::VariableNode
end
Expand All @@ -169,9 +169,9 @@ end
Return the list of `ConstraintNode` that would be added if `BT` is used in `b`.
"""
function _constraint_nodes(
b::LazyBridgeOptimizer,
::Type{BT},
) where {BT<:AbstractBridge}
@nospecialize(b::LazyBridgeOptimizer),
@nospecialize(BT),
)
return ConstraintNode[
node(b, F, S) for (F, S) in added_constraint_types(BT)
]
Expand All @@ -183,7 +183,11 @@ end
Return the `Edge` or `ObjectiveEdge` in the hyper-graph associated with the
bridge `BT`, where `index` is the index of `BT` in the list of bridges.
"""
function _edge(b::LazyBridgeOptimizer, index::Int, BT::Type{<:AbstractBridge})
function _edge(
@nospecialize(b::LazyBridgeOptimizer),
@nospecialize(index::Int),
@nospecialize(BT::Type{<:AbstractBridge}),
)
return Edge(
index,
_variable_nodes(b, BT),
Expand Down Expand Up @@ -247,7 +251,10 @@ end

Return the `VariableNode` associated with set `S` in `b`.
"""
function node(b::LazyBridgeOptimizer, S::Type{<:MOI.AbstractSet})
function node(
@nospecialize(b::LazyBridgeOptimizer),
@nospecialize(S::Type{<:MOI.AbstractSet}),
)
# If we support the set, the node is 0.
if (
S <: MOI.AbstractScalarSet &&
Expand Down Expand Up @@ -304,9 +311,9 @@ end
Return the `ConstraintNode` associated with constraint `F`-in-`S` in `b`.
"""
function node(
b::LazyBridgeOptimizer,
F::Type{<:MOI.AbstractFunction},
S::Type{<:MOI.AbstractSet},
@nospecialize(b::LazyBridgeOptimizer),
@nospecialize(F::Type{<:MOI.AbstractFunction}),
@nospecialize(S::Type{<:MOI.AbstractSet}),
)
# If we support the constraint type, the node is 0.
if MOI.supports_constraint(b.model, F, S)
Expand Down Expand Up @@ -377,8 +384,8 @@ function _bridge_types(
end

function _bridge_types(
b::LazyBridgeOptimizer,
::Type{<:Constraint.AbstractBridge},
@nospecialize(b::LazyBridgeOptimizer),
@nospecialize(BT::Type{<:Constraint.AbstractBridge}),
)
return b.constraint_bridge_types
end
Expand All @@ -395,7 +402,10 @@ end

Enable the use of the bridges of type `BT` by `b`.
"""
function add_bridge(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
function add_bridge(
@nospecialize(b::LazyBridgeOptimizer),
@nospecialize(BT::Type{<:AbstractBridge}),
)
if !has_bridge(b, BT)
push!(_bridge_types(b, BT), BT)
_reset_bridge_graph(b)
Expand Down Expand Up @@ -427,7 +437,10 @@ end

Return a `Bool` indicating whether the bridges of type `BT` are used by `b`.
"""
function has_bridge(b::LazyBridgeOptimizer, BT::Type{<:AbstractBridge})
function has_bridge(
@nospecialize(b::LazyBridgeOptimizer),
@nospecialize(BT::Type{<:AbstractBridge}),
)::Bool
return findfirst(isequal(BT), _bridge_types(b, BT)) !== nothing
end

Expand Down
6 changes: 3 additions & 3 deletions src/Test/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,9 @@ function _test_attribute_value_type(
end

function _test_attribute_value_type(
model::MOI.ModelLike,
attribute::MOI.AbstractConstraintAttribute,
ci::MOI.ConstraintIndex,
@nospecialize(model::MOI.ModelLike),
@nospecialize(attribute::MOI.AbstractConstraintAttribute),
@nospecialize(ci::MOI.ConstraintIndex),
)
T = MOI.attribute_value_type(attribute)
@test @inferred(T, MOI.get(model, attribute, ci)) isa T
Expand Down
8 changes: 4 additions & 4 deletions src/Utilities/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ function MOI.is_valid(model::AbstractModel, ci::MOI.ConstraintIndex)
end

function MOI.supports_constraint(
model::AbstractModel,
::Type{F},
::Type{S},
) where {F<:MOI.AbstractFunction,S<:MOI.AbstractSet}
@nospecialize(model::AbstractModel),
@nospecialize(F::Type{<:MOI.AbstractFunction}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one may be more dangerous

@nospecialize(S::Type{<:MOI.AbstractSet}),
)
return MOI.supports_constraint(model.constraints, F, S)
end

Expand Down
6 changes: 3 additions & 3 deletions src/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ supported in specific circumstances, for example, `F`-in-`S` constraints cannot
combined with another type of constraint, it should still return `true`.
"""
function supports_constraint(
::ModelLike,
::Type{<:AbstractFunction},
::Type{<:AbstractSet},
@nospecialize(::ModelLike),
@nospecialize(F::Type{<:AbstractFunction}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's a fallback returning false, I don't believe it will affect the performance of bottleneck to looks good

@nospecialize(S::Type{<:AbstractSet}),
)
return false
end
Expand Down
Loading