|
| 1 | +using Test |
| 2 | +using SumOfSquares |
| 3 | +using DynamicPolynomials |
| 4 | + |
| 5 | +# Like `term_test` but with a variable `y` fixed to 1. |
| 6 | +function term_fixed_test( |
| 7 | + optimizer, config::MOIT.TestConfig, cone::SumOfSquares.PolyJuMP.PolynomialSet) |
| 8 | + atol = config.atol |
| 9 | + rtol = config.rtol |
| 10 | + |
| 11 | + model = _model(optimizer) |
| 12 | + |
| 13 | + @variable(model, α) |
| 14 | + |
| 15 | + @polyvar x y |
| 16 | + set = @set y == 1 |
| 17 | + cref = @constraint(model, (α - 1) * x^2 * y in cone, domain = set) |
| 18 | + |
| 19 | + @objective(model, Min, α) |
| 20 | + optimize!(model) |
| 21 | + |
| 22 | + @test termination_status(model) == MOI.OPTIMAL |
| 23 | + @test objective_value(model) ≈ 1.0 atol=atol rtol=rtol |
| 24 | + |
| 25 | + @test primal_status(model) == MOI.FEASIBLE_POINT |
| 26 | + @test value(α) ≈ 1.0 atol=atol rtol=rtol |
| 27 | + |
| 28 | + @test_throws SumOfSquares.ValueNotSupported value(cref) |
| 29 | + p = gram_matrix(cref) |
| 30 | + @test getmat(p) ≈ zeros(1, 1) atol=atol rtol=rtol |
| 31 | + @test p.x == [x] |
| 32 | + |
| 33 | + @test dual_status(model) == MOI.FEASIBLE_POINT |
| 34 | + for (m, μ) in [(x^2 * y, dual(cref)), (x^2, moments(cref))] |
| 35 | + @test μ isa AbstractMeasure{Float64} |
| 36 | + @test length(moments(μ)) == 1 |
| 37 | + @test moment_value(moments(μ)[1]) ≈ 1.0 atol=atol rtol=rtol |
| 38 | + @test monomial(moments(μ)[1]) == m |
| 39 | + end |
| 40 | + |
| 41 | + ν = moment_matrix(cref) |
| 42 | + @test getmat(ν) ≈ ones(1, 1) atol=atol rtol=rtol |
| 43 | + @test ν.x == [x] |
| 44 | + |
| 45 | + S = SumOfSquares.SOSPolynomialSet{ |
| 46 | + SumOfSquares.typeof(set), typeof(cone), SumOfSquares.MonomialBasis, |
| 47 | + Monomial{true},MonomialVector{true},Tuple{} |
| 48 | + } |
| 49 | + @test list_of_constraint_types(model) == [(Vector{JuMP.AffExpr}, S)] |
| 50 | + test_delete_bridge( |
| 51 | + model, cref, 1, |
| 52 | + ((MOI.VectorOfVariables, MOI.Nonnegatives, 0), |
| 53 | + (MOI.VectorAffineFunction{Float64}, |
| 54 | + SumOfSquares.PolyJuMP.ZeroPolynomialSet{ |
| 55 | + typeof(set), SumOfSquares.MonomialBasis, |
| 56 | + Monomial{true}, MonomialVector{true}}, |
| 57 | + 0))) |
| 58 | +end |
| 59 | +sos_term_fixed_test(optimizer, config) = term_fixed_test(optimizer, config, SOSCone()) |
| 60 | +sd_tests["sos_term_fixed"] = sos_term_fixed_test |
| 61 | +sdsos_term_fixed_test(optimizer, config) = term_fixed_test(optimizer, config, SDSOSCone()) |
| 62 | +soc_tests["sdsos_term_fixed"] = sdsos_term_fixed_test |
| 63 | +dsos_term_fixed_test(optimizer, config) = term_fixed_test(optimizer, config, DSOSCone()) |
| 64 | +linear_tests["dsos_term_fixed"] = dsos_term_fixed_test |
0 commit comments