@@ -5770,185 +5770,6 @@ 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 (
5805- model,
5806- MOI. VectorAffineFunction{T},
5807- typeof (set),
5808- )
5809- @requires MOI. supports_incremental_interface (model)
5810- @requires MOI. supports (model, MOI. ObjectiveSense ())
5811- @requires MOI. supports (model, MOI. ObjectiveFunction {MOI.VariableIndex} ())
5812- γ = MOI. add_variable (model)
5813- c = MOI. add_constraint (
5814- model,
5815- MOI. Utilities. operate (vcat, T, T (3 ) - T (1 ) * γ, T (- 1 ) - T (1 ) * γ),
5816- set,
5817- )
5818- MOI. set (model, MOI. ObjectiveSense (), MOI. MAX_SENSE)
5819- MOI. set (model, MOI. ObjectiveFunction {MOI.VariableIndex} (), γ)
5820- if _supports (config, MOI. optimize!)
5821- @test MOI. get (model, MOI. TerminationStatus ()) == MOI. OPTIMIZE_NOT_CALLED
5822- MOI. optimize! (model)
5823- @test MOI. get (model, MOI. TerminationStatus ()) == config. optimal_status
5824- @test MOI. get (model, MOI. PrimalStatus ()) == MOI. FEASIBLE_POINT
5825- if _supports (config, MOI. ConstraintDual)
5826- @test MOI. get (model, MOI. DualStatus ()) == MOI. FEASIBLE_POINT
5827- end
5828- @test ≈ (MOI. get (model, MOI. ObjectiveValue ()), T (- 1 ), config)
5829- if _supports (config, MOI. DualObjectiveValue)
5830- @test ≈ (MOI. get (model, MOI. DualObjectiveValue ()), T (- 1 ), config)
5831- end
5832- @test ≈ (MOI. get (model, MOI. VariablePrimal (), γ), T (- 1 ), config)
5833- @test ≈ (MOI. get (model, MOI. ConstraintPrimal (), c), T[4 , 0 ], config)
5834- if _supports (config, MOI. ConstraintDual)
5835- @test ≈ (MOI. get (model, MOI. ConstraintDual (), c), T[0 , 1 ], config)
5836- end
5837- end
5838- return
5839- end
5840-
5841- function setup_test (
5842- :: typeof (test_conic_PositiveSemidefinite_RankOne_polynomial),
5843- model:: MOIU.MockOptimizer ,
5844- :: Config{T} ,
5845- ) where {T<: Real }
5846- A = MOI. TriangleVectorization{
5847- T,
5848- MOI. PositiveSemidefiniteFactorization{T,Vector{T}},
5849- }
5850- MOIU. set_mock_optimize! (
5851- model,
5852- (mock:: MOIU.MockOptimizer ) -> MOIU. mock_optimize! (
5853- mock,
5854- T[- 1 ],
5855- (
5856- MOI. VectorAffineFunction{T},
5857- MOI. SetDotProducts{
5858- MOI. PositiveSemidefiniteConeTriangle,
5859- A,
5860- Vector{A},
5861- },
5862- ) => [T[0 , 1 ]],
5863- ),
5864- )
5865- return
5866- end
5867-
5868- """
5869- The moment version of `test_conic_PositiveSemidefinite_RankOne_polynomial`
5870-
5871- We look for a measure `μ = y1 * δ_{-1} + y2 * δ_{1}` where `δ_{c}` is the Dirac
5872- measure centered at `c`. The objective is
5873- `⟨μ, x^2 - 2x⟩ = y1 * ⟨δ_{-1}, x^2 - 2x⟩ + y2 * ⟨δ_{1}, x^2 - 2x⟩ = 3y1 - y2`.
5874- We want `μ` to be a probability measure so `1 = ⟨μ, 1⟩ = y1 + y2`.
5875- """
5876- function test_conic_PositiveSemidefinite_RankOne_moment (
5877- model:: MOI.ModelLike ,
5878- config:: Config{T} ,
5879- ) where {T}
5880- set = MOI. LinearCombinationInSet (
5881- MOI. PositiveSemidefiniteConeTriangle (2 ),
5882- MOI. TriangleVectorization .([
5883- MOI. PositiveSemidefiniteFactorization (T[1 , - 1 ]),
5884- MOI. PositiveSemidefiniteFactorization (T[1 , 1 ]),
5885- ]),
5886- )
5887- @requires MOI. supports_add_constrained_variables (model, typeof (set))
5888- @requires MOI. supports_incremental_interface (model)
5889- @requires MOI. supports (model, MOI. ObjectiveSense ())
5890- @requires MOI. supports (
5891- model,
5892- MOI. ObjectiveFunction {MOI.ScalarAffineFunction{T}} (),
5893- )
5894- y, cy = MOI. add_constrained_variables (model, set)
5895- c = MOI. add_constraint (model, T (1 ) * y[1 ] + T (1 ) * y[2 ], MOI. EqualTo (T (1 )))
5896- MOI. set (model, MOI. ObjectiveSense (), MOI. MIN_SENSE)
5897- MOI. set (
5898- model,
5899- MOI. ObjectiveFunction {MOI.ScalarAffineFunction{T}} (),
5900- T (3 ) * y[1 ] - T (1 ) * y[2 ],
5901- )
5902- if _supports (config, MOI. optimize!)
5903- @test MOI. get (model, MOI. TerminationStatus ()) == MOI. OPTIMIZE_NOT_CALLED
5904- MOI. optimize! (model)
5905- @test MOI. get (model, MOI. TerminationStatus ()) == config. optimal_status
5906- @test MOI. get (model, MOI. PrimalStatus ()) == MOI. FEASIBLE_POINT
5907- if _supports (config, MOI. ConstraintDual)
5908- @test MOI. get (model, MOI. DualStatus ()) == MOI. FEASIBLE_POINT
5909- end
5910- @test ≈ (MOI. get (model, MOI. ObjectiveValue ()), T (- 1 ), config)
5911- if _supports (config, MOI. DualObjectiveValue)
5912- @test ≈ (MOI. get (model, MOI. DualObjectiveValue ()), T (- 1 ), config)
5913- end
5914- @test ≈ (MOI. get (model, MOI. VariablePrimal (), y), T[0 , 1 ], config)
5915- @test ≈ (MOI. get (model, MOI. ConstraintPrimal (), c), T (1 ), config)
5916- if _supports (config, MOI. ConstraintDual)
5917- @test ≈ (MOI. get (model, MOI. ConstraintDual (), cy), T[4 , 0 ], config)
5918- @test ≈ (MOI. get (model, MOI. ConstraintDual (), c), T (- 1 ), config)
5919- end
5920- end
5921- return
5922- end
5923-
5924- function setup_test (
5925- :: typeof (test_conic_PositiveSemidefinite_RankOne_moment),
5926- model:: MOIU.MockOptimizer ,
5927- :: Config{T} ,
5928- ) where {T<: Real }
5929- A = MOI. TriangleVectorization{
5930- T,
5931- MOI. PositiveSemidefiniteFactorization{T,Vector{T}},
5932- }
5933- MOIU. set_mock_optimize! (
5934- model,
5935- (mock:: MOIU.MockOptimizer ) -> MOIU. mock_optimize! (
5936- mock,
5937- T[0 , 1 ],
5938- (MOI. ScalarAffineFunction{T}, MOI. EqualTo{T}) => [T (- 1 )],
5939- (
5940- MOI. VectorOfVariables,
5941- MOI. LinearCombinationInSet{
5942- MOI. PositiveSemidefiniteConeTriangle,
5943- A,
5944- Vector{A},
5945- },
5946- ) => [T[4 , 0 ]],
5947- ),
5948- )
5949- return
5950- end
5951-
59525773"""
59535774 _test_det_cone_helper_ellipsoid(
59545775 model::MOI.ModelLike,
0 commit comments