Skip to content
Merged
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
16 changes: 15 additions & 1 deletion src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,9 @@ queried using the [`ParametricObjectiveFunction{P}`](@ref) attribute. The type
struct ParametricObjectiveType <: MOI.AbstractModelAttribute end

function MOI.get(model::Optimizer{T}, ::ParametricObjectiveType) where {T}
if model.quadratic_objective_cache !== nothing
if model.cubic_objective_cache !== nothing
return ParametricCubicFunction{T}
elseif model.quadratic_objective_cache !== nothing
return ParametricQuadraticFunction{T}
elseif model.affine_objective_cache !== nothing
return ParametricAffineFunction{T}
Expand Down Expand Up @@ -1704,6 +1706,18 @@ function MOI.get(
return model.affine_objective_cache
end

function MOI.get(
model::Optimizer{T},
::ParametricObjectiveFunction{ParametricCubicFunction{T}},
) where {T}
if model.cubic_objective_cache === nothing
error("
There is no parametric cubic objective function in the model.
")
end
return model.cubic_objective_cache
end

"""
ListOfParametricConstraintTypesPresent()

Expand Down
34 changes: 34 additions & 0 deletions test/test_cubic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,40 @@ function test_jump_cubic_direct_model_ppp()
return
end

function test_parametric_objective_type_cubic()
model = Model(() -> POI.Optimizer(HiGHS.Optimizer()))
set_silent(model)
@variable(model, x)
@variable(model, p in MOI.Parameter(2.0))
@variable(model, q in MOI.Parameter(3.0))
@constraint(model, x >= 1)
@objective(model, Min, x + p * q^2)
optimize!(model)
inner = unsafe_backend(model)
@test MOI.get(inner, POI.ParametricObjectiveType()) ==
POI.ParametricCubicFunction{Float64}
pf = MOI.get(
inner,
POI.ParametricObjectiveFunction{POI.ParametricCubicFunction{Float64}}(),
)
@test pf isa POI.ParametricCubicFunction{Float64}
return
end

function test_parametric_objective_type_cubic_error()
model = Model(() -> POI.Optimizer(HiGHS.Optimizer()))
set_silent(model)
@variable(model, x >= 1)
@objective(model, Min, x)
optimize!(model)
inner = unsafe_backend(model)
@test_throws ErrorException MOI.get(
inner,
POI.ParametricObjectiveFunction{POI.ParametricCubicFunction{Float64}}(),
)
return
end

end # module

TestCubic.runtests()
Loading