From c61f54cefa50dffb3a53fa0f14e0b18ad72acb91 Mon Sep 17 00:00:00 2001 From: odow Date: Mon, 14 Aug 2023 13:38:17 +1200 Subject: [PATCH] Rename cost to bridging_cost --- docs/src/submodules/Bridges/reference.md | 3 +- src/Bridges/Constraint/bridges/functionize.jl | 4 +-- src/Bridges/bridge.jl | 31 +++++++++---------- src/Bridges/lazy_bridge_optimizer.jl | 4 +-- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/docs/src/submodules/Bridges/reference.md b/docs/src/submodules/Bridges/reference.md index 2cf3df3a9c..44d9a1855e 100644 --- a/docs/src/submodules/Bridges/reference.md +++ b/docs/src/submodules/Bridges/reference.md @@ -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 @@ -74,7 +74,6 @@ Bridges.unbridged_variable_function Bridges.bridged_function Bridges.supports_constraint_bridges Bridges.recursive_model -Bridges.bridging_cost ``` ## LazyBridgeOptimizer API diff --git a/src/Bridges/Constraint/bridges/functionize.jl b/src/Bridges/Constraint/bridges/functionize.jl index c517b8df13..9c4fcc1c02 100644 --- a/src/Bridges/Constraint/bridges/functionize.jl +++ b/src/Bridges/Constraint/bridges/functionize.jl @@ -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`. @@ -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) diff --git a/src/Bridges/bridge.jl b/src/Bridges/bridge.jl index 5c44800e6d..54d2cfb8a5 100644 --- a/src/Bridges/bridge.jl +++ b/src/Bridges/bridge.jl @@ -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 @@ -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 diff --git a/src/Bridges/lazy_bridge_optimizer.jl b/src/Bridges/lazy_bridge_optimizer.jl index 5b809f430e..daac29de41 100644 --- a/src/Bridges/lazy_bridge_optimizer.jl +++ b/src/Bridges/lazy_bridge_optimizer.jl @@ -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 @@ -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