Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use conversion cost for Objective bridge #2309

Merged
merged 3 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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: 6 additions & 0 deletions src/Bridges/Objective/bridges/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ function supports_objective_function(
return isfinite(MOI.Bridges.Constraint.conversion_cost(F, G))
end

function MOI.Bridges.bridging_cost(
::Type{FunctionConversionBridge{T,F,G}},
) where {T,F,G}
return MOI.Bridges.Constraint.conversion_cost(F, G)
end

function MOI.Bridges.added_constrained_variable_types(
::Type{<:FunctionConversionBridge},
)
Expand Down
28 changes: 28 additions & 0 deletions test/Bridges/lazy_bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,34 @@ function test_ToScalarQuadraticBridge_variable_bounds()
return
end

MOI.Utilities.@model(
ModelQuadObj,
(),
(),
(MOI.Nonnegatives, MOI.Zeros),
(),
(),
(),
(MOI.VectorOfVariables,),
(MOI.VectorAffineFunction,),
)

function MOI.supports(
::ModelQuadObj{T},
::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}},
) where {T}
return false
end

function test_objective_conversion_cost(T = Float64)
model = ModelQuadObj{T}()
bridged = MOI.Bridges.full_bridge_optimizer(model, T)
x = MOI.add_variable(bridged)
MOI.set(bridged, MOI.ObjectiveSense(), MOI.MIN_SENSE)
MOI.set(bridged, MOI.ObjectiveFunction{typeof(x)}(), one(T) * x)
@test MOI.get(model, MOI.ObjectiveFunctionType()) == MOI.VariableIndex
odow marked this conversation as resolved.
Show resolved Hide resolved
end

end # module

TestBridgesLazyBridgeOptimizer.runtests()
Loading