File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed
Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -1664,7 +1664,9 @@ queried using the [`ParametricObjectiveFunction{P}`](@ref) attribute. The type
16641664struct ParametricObjectiveType <: MOI.AbstractModelAttribute end
16651665
16661666function MOI. get (model:: Optimizer{T} , :: ParametricObjectiveType ) where {T}
1667- if model. quadratic_objective_cache != = nothing
1667+ if model. cubic_objective_cache != = nothing
1668+ return ParametricCubicFunction{T}
1669+ elseif model. quadratic_objective_cache != = nothing
16681670 return ParametricQuadraticFunction{T}
16691671 elseif model. affine_objective_cache != = nothing
16701672 return ParametricAffineFunction{T}
@@ -1704,6 +1706,18 @@ function MOI.get(
17041706 return model. affine_objective_cache
17051707end
17061708
1709+ function MOI. get (
1710+ model:: Optimizer{T} ,
1711+ :: ParametricObjectiveFunction{ParametricCubicFunction{T}} ,
1712+ ) where {T}
1713+ if model. cubic_objective_cache === nothing
1714+ error ("
1715+ There is no parametric cubic objective function in the model.
1716+ " )
1717+ end
1718+ return model. cubic_objective_cache
1719+ end
1720+
17071721"""
17081722 ListOfParametricConstraintTypesPresent()
17091723
Original file line number Diff line number Diff line change @@ -1623,6 +1623,40 @@ function test_jump_cubic_direct_model_ppp()
16231623 return
16241624end
16251625
1626+ function test_parametric_objective_type_cubic ()
1627+ model = Model (() -> POI. Optimizer (HiGHS. Optimizer ()))
1628+ set_silent (model)
1629+ @variable (model, x)
1630+ @variable (model, p in MOI. Parameter (2.0 ))
1631+ @variable (model, q in MOI. Parameter (3.0 ))
1632+ @constraint (model, x >= 1 )
1633+ @objective (model, Min, x + p * q^ 2 )
1634+ optimize! (model)
1635+ inner = unsafe_backend (model)
1636+ @test MOI. get (inner, POI. ParametricObjectiveType ()) ==
1637+ POI. ParametricCubicFunction{Float64}
1638+ pf = MOI. get (
1639+ inner,
1640+ POI. ParametricObjectiveFunction {POI.ParametricCubicFunction{Float64}} (),
1641+ )
1642+ @test pf isa POI. ParametricCubicFunction{Float64}
1643+ return
1644+ end
1645+
1646+ function test_parametric_objective_type_cubic_error ()
1647+ model = Model (() -> POI. Optimizer (HiGHS. Optimizer ()))
1648+ set_silent (model)
1649+ @variable (model, x >= 1 )
1650+ @objective (model, Min, x)
1651+ optimize! (model)
1652+ inner = unsafe_backend (model)
1653+ @test_throws ErrorException MOI. get (
1654+ inner,
1655+ POI. ParametricObjectiveFunction {POI.ParametricCubicFunction{Float64}} (),
1656+ )
1657+ return
1658+ end
1659+
16261660end # module
16271661
16281662TestCubic. runtests ()
You can’t perform that action at this time.
0 commit comments