Skip to content

Commit

Permalink
Rename cost to bridging_cost
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Aug 14, 2023
1 parent 7a6a547 commit c61f54c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
3 changes: 1 addition & 2 deletions docs/src/submodules/Bridges/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ get(::Bridges.AbstractBridge, ::NumberOfConstraints)
get(::Bridges.AbstractBridge, ::ListOfConstraintIndices)
Bridges.needs_final_touch
Bridges.final_touch
Bridges.cost
Bridges.bridging_cost
```

## Constraint bridge API
Expand Down Expand Up @@ -74,7 +74,6 @@ Bridges.unbridged_variable_function
Bridges.bridged_function
Bridges.supports_constraint_bridges
Bridges.recursive_model
Bridges.bridging_cost
```

## LazyBridgeOptimizer API
Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/Constraint/bridges/functionize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ end
conversion_cost(
F::Type{<:MOI.AbstractFunction},
G::Type{<:MOI.AbstractFunction},
)::Int
)::Union{Int,Nothing}
Return an `Int` returning the cost of converting any function of type `G`
to a function of type `F` with `convert`.
Expand Down Expand Up @@ -273,7 +273,7 @@ function concrete_bridge_type(
return FunctionConversionBridge{T,F,G,S}
end

function MOI.Bridges.cost(
function MOI.Bridges.bridging_cost(
::Type{<:FunctionConversionBridge{T,F,G}},
) where {T,F,G}
return conversion_cost(F, G)
Expand Down
31 changes: 15 additions & 16 deletions src/Bridges/bridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,13 @@ If you implement this method, you must also implement
function final_touch end

"""
cost(BT::Type{<:AbstractBridge})::Int
bridging_cost(BT::Type{<:AbstractBridge})::Int
Return the *cost* a bridge of type `BT`.
Return the cost of adding a bridge of type `BT`.
This cost is used to compute the [`bridging_cost`](@ref).
There is a default implementation for any [`AbstractBridge`](@ref) returning
`1` so this should only be implemented for bridges returning a distance
different from `1`.
The default implementation for any [`AbstractBridge`](@ref) returns `1`, so this
method should only be implemented for bridges returning a cost different from
`1`.
## Example
Expand All @@ -302,22 +300,23 @@ constraints from a given function type to a function type to a wider one,
we want it to have lower priority.
For example, we want to prioritize bridging a
[`MOI.ScalarAffineFunction`](@ref)-in-[`MOI.LessThan`](@ref) constraint into
a [`MOI.VectorAffineFunction`](@ref)-in-[`MOI.Nonnegatives`](@ref) constraint
over bridging it to a [`MOI.ScalarQuadraticFunction`](@ref)-in-[`MOI.LessThan`](@ref) constraint.
[`MOI.ScalarAffineFunction`](@ref)-in-[`MOI.LessThan`](@ref) constraint into a
[`MOI.VectorAffineFunction`](@ref)-in-[`MOI.Nonnegatives`](@ref) constraint
over bridging it to a [`MOI.ScalarQuadraticFunction`](@ref)-in-[`MOI.LessThan`](@ref)
constraint.
For this reason, the [`Bridges.Constraint.FunctionConversionBridge`](@ref) is
given a cost of `10`:
```jldoctest; setup=(import MathOptInterface as MOI)
julia> T = Float64;
julia> F = MOI.ScalarQuadraticFunction{T};
julia> F = MOI.ScalarQuadraticFunction{Float64};
julia> G = MOI.ScalarAffineFunction{T};
julia> G = MOI.ScalarAffineFunction{Float64};
julia> MOI.Bridges.cost(MOI.Bridges.Constraint.FunctionConversionBridge{T,F,G})
julia> MOI.Bridges.bridging_cost(
MOI.Bridges.Constraint.FunctionConversionBridge{Float64,F,G},
)
10
```
"""
cost(::Type{<:AbstractBridge}) = 1
bridging_cost(::Type{<:AbstractBridge}) = 1
4 changes: 2 additions & 2 deletions src/Bridges/lazy_bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function _edge(b::LazyBridgeOptimizer, index::Int, BT::Type{<:AbstractBridge})
index,
_variable_nodes(b, BT),
_constraint_nodes(b, BT),
cost(BT),
bridging_cost(BT),
)
end

Expand All @@ -171,7 +171,7 @@ function _edge(
_variable_nodes(b, BT),
_constraint_nodes(b, BT),
node(b, set_objective_function_type(BT)),
cost(BT),
bridging_cost(BT),
)
end

Expand Down

0 comments on commit c61f54c

Please sign in to comment.