Skip to content

Commit de74887

Browse files
authored
[Bridges] Use conversion cost for Objective bridge (#2309)
1 parent eb0d3c1 commit de74887

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Bridges/Objective/bridges/conversion.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ function supports_objective_function(
4848
return isfinite(MOI.Bridges.Constraint.conversion_cost(F, G))
4949
end
5050

51+
function MOI.Bridges.bridging_cost(
52+
::Type{FunctionConversionBridge{T,F,G}},
53+
) where {T,F,G}
54+
return MOI.Bridges.Constraint.conversion_cost(F, G)
55+
end
56+
5157
function MOI.Bridges.added_constrained_variable_types(
5258
::Type{<:FunctionConversionBridge},
5359
)

test/Bridges/lazy_bridge_optimizer.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,35 @@ function test_ToScalarQuadraticBridge_variable_bounds()
21362136
return
21372137
end
21382138

2139+
MOI.Utilities.@model(
2140+
ModelQuadObj,
2141+
(),
2142+
(),
2143+
(MOI.Nonnegatives, MOI.Zeros),
2144+
(),
2145+
(),
2146+
(),
2147+
(MOI.VectorOfVariables,),
2148+
(MOI.VectorAffineFunction,),
2149+
)
2150+
2151+
function MOI.supports(
2152+
::ModelQuadObj{T},
2153+
::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}},
2154+
) where {T}
2155+
return false
2156+
end
2157+
2158+
function test_objective_conversion_cost(T = Float64)
2159+
model = ModelQuadObj{T}()
2160+
bridged = MOI.Bridges.full_bridge_optimizer(model, T)
2161+
x = MOI.add_variable(bridged)
2162+
MOI.set(bridged, MOI.ObjectiveSense(), MOI.MIN_SENSE)
2163+
MOI.set(bridged, MOI.ObjectiveFunction{typeof(x)}(), one(T) * x)
2164+
@test MOI.get(model, MOI.ObjectiveFunctionType()) == MOI.VariableIndex
2165+
return
2166+
end
2167+
21392168
end # module
21402169

21412170
TestBridgesLazyBridgeOptimizer.runtests()

0 commit comments

Comments
 (0)