@@ -5770,6 +5770,165 @@ function setup_test(
57705770 return
57715771end
57725772
5773+ """
5774+ The goal is to find the maximum lower bound `γ` for the polynomial `x^2 - 2x`.
5775+ Using samples `-1` and `1`, the polynomial `x^2 - 2x - γ` evaluates at `-γ`
5776+ and `2 - γ` respectively.
5777+ The dot product with the gram matrix is the evaluation of `[1; x] * [1 x]` hence
5778+ `[1; -1] * [1 -1]` and `[1; 1] * [1 1]` respectively.
5779+
5780+ The polynomial version is:
5781+ max γ
5782+ s.t. [-γ, 2 - γ] in SetDotProducts(
5783+ PSD(2),
5784+ [[1; -1] * [1 -1], [1; 1] * [1 1]],
5785+ )
5786+ Its dual (moment version) is:
5787+ min -y[1] - y[2]
5788+ s.t. [-γ, 2 - γ] in LinearCombinationInSet(
5789+ PSD(2),
5790+ [[1; -1] * [1 -1], [1; 1] * [1 1]],
5791+ )
5792+ """
5793+ function test_conic_PositiveSemidefinite_RankOne_polynomial (
5794+ model:: MOI.ModelLike ,
5795+ config:: Config{T} ,
5796+ ) where {T}
5797+ set = MOI. SetDotProducts (
5798+ MOI. PositiveSemidefiniteConeTriangle (2 ),
5799+ MOI. TriangleVectorization .([
5800+ MOI. PositiveSemidefiniteFactorization (T[1 , - 1 ]),
5801+ MOI. PositiveSemidefiniteFactorization (T[1 , 1 ]),
5802+ ]),
5803+ )
5804+ @requires MOI. supports_constraint (model, MOI. VectorAffineFunction{T}, typeof (set))
5805+ @requires MOI. supports_incremental_interface (model)
5806+ @requires MOI. supports (model, MOI. ObjectiveSense ())
5807+ @requires MOI. supports (model, MOI. ObjectiveFunction {MOI.VariableIndex} ())
5808+ γ = MOI. add_variable (model)
5809+ c = MOI. add_constraint (
5810+ model,
5811+ MOI. Utilities. operate (vcat, T, T (3 ) - T (1 ) * γ, T (- 1 ) - T (1 ) * γ),
5812+ set,
5813+ )
5814+ MOI. set (model, MOI. ObjectiveSense (), MOI. MAX_SENSE)
5815+ MOI. set (model, MOI. ObjectiveFunction {MOI.VariableIndex} (), γ)
5816+ if _supports (config, MOI. optimize!)
5817+ @test MOI. get (model, MOI. TerminationStatus ()) == MOI. OPTIMIZE_NOT_CALLED
5818+ MOI. optimize! (model)
5819+ @test MOI. get (model, MOI. TerminationStatus ()) == config. optimal_status
5820+ @test MOI. get (model, MOI. PrimalStatus ()) == MOI. FEASIBLE_POINT
5821+ if _supports (config, MOI. ConstraintDual)
5822+ @test MOI. get (model, MOI. DualStatus ()) == MOI. FEASIBLE_POINT
5823+ end
5824+ @test ≈ (MOI. get (model, MOI. ObjectiveValue ()), T (- 1 ), config)
5825+ if _supports (config, MOI. DualObjectiveValue)
5826+ @test ≈ (MOI. get (model, MOI. DualObjectiveValue ()), T (- 1 ), config)
5827+ end
5828+ @test ≈ (MOI. get (model, MOI. VariablePrimal (), γ), T (- 1 ), config)
5829+ @test ≈ (MOI. get (model, MOI. ConstraintPrimal (), c), T[4 , 0 ], config)
5830+ if _supports (config, MOI. ConstraintDual)
5831+ @test ≈ (MOI. get (model, MOI. ConstraintDual (), c), T[0 , 1 ], config)
5832+ end
5833+ end
5834+ return
5835+ end
5836+
5837+ function setup_test (
5838+ :: typeof (test_conic_PositiveSemidefinite_RankOne_polynomial),
5839+ model:: MOIU.MockOptimizer ,
5840+ :: Config{T} ,
5841+ ) where {T<: Real }
5842+ A = MOI. TriangleVectorization{T,MOI. PositiveSemidefiniteFactorization{T,Vector{T}}}
5843+ MOIU. set_mock_optimize! (
5844+ model,
5845+ (mock:: MOIU.MockOptimizer ) -> MOIU. mock_optimize! (
5846+ mock,
5847+ T[- 1 ],
5848+ (MOI. VectorAffineFunction{T}, MOI. SetDotProducts{
5849+ MOI. PositiveSemidefiniteConeTriangle,
5850+ A,
5851+ Vector{A},
5852+ }) => [T[0 , 1 ]],
5853+ ),
5854+ )
5855+ return
5856+ end
5857+
5858+ """
5859+ The moment version of `test_conic_PositiveSemidefinite_RankOne_polynomial`
5860+
5861+ We look for a measure `μ = y1 * δ_{-1} + y2 * δ_{1}` where `δ_{c}` is the Dirac
5862+ measure centered at `c`. The objective is
5863+ `⟨μ, x^2 - 2x⟩ = y1 * ⟨δ_{-1}, x^2 - 2x⟩ + y2 * ⟨δ_{1}, x^2 - 2x⟩ = 3y1 - y2`.
5864+ We want `μ` to be a probability measure so `1 = ⟨μ, 1⟩ = y1 + y2`.
5865+ """
5866+ function test_conic_PositiveSemidefinite_RankOne_moment (
5867+ model:: MOI.ModelLike ,
5868+ config:: Config{T} ,
5869+ ) where {T}
5870+ set = MOI. LinearCombinationInSet (
5871+ MOI. PositiveSemidefiniteConeTriangle (2 ),
5872+ MOI. TriangleVectorization .([
5873+ MOI. PositiveSemidefiniteFactorization (T[1 , - 1 ]),
5874+ MOI. PositiveSemidefiniteFactorization (T[1 , 1 ]),
5875+ ]),
5876+ )
5877+ @requires MOI. supports_add_constrained_variables (model, typeof (set))
5878+ @requires MOI. supports_incremental_interface (model)
5879+ @requires MOI. supports (model, MOI. ObjectiveSense ())
5880+ @requires MOI. supports (model, MOI. ObjectiveFunction {MOI.ScalarAffineFunction{T}} ())
5881+ y, cy = MOI. add_constrained_variables (
5882+ model,
5883+ set,
5884+ )
5885+ c = MOI. add_constraint (model, T (1 ) * y[1 ] + T (1 ) * y[2 ], MOI. EqualTo (T (1 )))
5886+ MOI. set (model, MOI. ObjectiveSense (), MOI. MIN_SENSE)
5887+ MOI. set (model, MOI. ObjectiveFunction {MOI.ScalarAffineFunction{T}} (), T (3 ) * y[1 ] - T (1 ) * y[2 ])
5888+ if _supports (config, MOI. optimize!)
5889+ @test MOI. get (model, MOI. TerminationStatus ()) == MOI. OPTIMIZE_NOT_CALLED
5890+ MOI. optimize! (model)
5891+ @test MOI. get (model, MOI. TerminationStatus ()) == config. optimal_status
5892+ @test MOI. get (model, MOI. PrimalStatus ()) == MOI. FEASIBLE_POINT
5893+ if _supports (config, MOI. ConstraintDual)
5894+ @test MOI. get (model, MOI. DualStatus ()) == MOI. FEASIBLE_POINT
5895+ end
5896+ @test ≈ (MOI. get (model, MOI. ObjectiveValue ()), T (- 1 ), config)
5897+ if _supports (config, MOI. DualObjectiveValue)
5898+ @test ≈ (MOI. get (model, MOI. DualObjectiveValue ()), T (- 1 ), config)
5899+ end
5900+ @test ≈ (MOI. get (model, MOI. VariablePrimal (), y), T[0 , 1 ], config)
5901+ @test ≈ (MOI. get (model, MOI. ConstraintPrimal (), c), T (1 ), config)
5902+ if _supports (config, MOI. ConstraintDual)
5903+ @test ≈ (MOI. get (model, MOI. ConstraintDual (), cy), T[4 , 0 ], config)
5904+ @test ≈ (MOI. get (model, MOI. ConstraintDual (), c), T (- 1 ), config)
5905+ end
5906+ end
5907+ return
5908+ end
5909+
5910+ function setup_test (
5911+ :: typeof (test_conic_PositiveSemidefinite_RankOne_moment),
5912+ model:: MOIU.MockOptimizer ,
5913+ :: Config{T} ,
5914+ ) where {T<: Real }
5915+ A = MOI. TriangleVectorization{T,MOI. PositiveSemidefiniteFactorization{T,Vector{T}}}
5916+ MOIU. set_mock_optimize! (
5917+ model,
5918+ (mock:: MOIU.MockOptimizer ) -> MOIU. mock_optimize! (
5919+ mock,
5920+ T[0 , 1 ],
5921+ (MOI. ScalarAffineFunction{T}, MOI. EqualTo{T}) => [T (- 1 )],
5922+ (MOI. VectorOfVariables, MOI. LinearCombinationInSet{
5923+ MOI. PositiveSemidefiniteConeTriangle,
5924+ A,
5925+ Vector{A},
5926+ }) => [T[4 , 0 ]],
5927+ ),
5928+ )
5929+ return
5930+ end
5931+
57735932"""
57745933 _test_det_cone_helper_ellipsoid(
57755934 model::MOI.ModelLike,
0 commit comments