|
3 | 3 | # Section 3.7 of SOSTOOLS User's Manual
|
4 | 4 |
|
5 | 5 | @testset "SOSDEMO7 with $solver" for solver in sdp_solvers
|
6 |
| - if !isscs(solver) |
7 |
| - ndeg = 8 # Degree of Chebyshev polynomial |
| 6 | + isscs(solver) && continue |
8 | 7 |
|
9 |
| - @polyvar x |
| 8 | + ndeg = 8 # Degree of Chebyshev polynomial |
10 | 9 |
|
11 |
| - Z = monomials((x,), 0:ndeg-1) |
| 10 | + @polyvar x |
12 | 11 |
|
13 |
| - m = SOSModel(solver = solver) |
| 12 | + Z = monomials((x,), 0:ndeg-1) |
14 | 13 |
|
15 |
| - @variable m γ |
16 |
| - @variable m p1 Poly(Z) |
| 14 | + m = SOSModel(solver = solver) |
17 | 15 |
|
18 |
| - p = p1 + γ * x^ndeg # the leading coeff of p is γ |
| 16 | + @variable m γ |
| 17 | + @variable m p1 Poly(Z) |
19 | 18 |
|
20 |
| - dom = @set x >= -1 && x <= 1 |
21 |
| - @constraint(m, p <= 1, domain = dom) |
22 |
| - @constraint(m, p >= -1, domain = dom) |
| 19 | + p = p1 + γ * x^ndeg # the leading coeff of p is γ |
23 | 20 |
|
24 |
| - @objective m Max γ |
| 21 | + dom = @set x >= -1 && x <= 1 |
| 22 | + @constraint(m, p <= 1, domain = dom) |
| 23 | + @constraint(m, p >= -1, domain = dom) |
25 | 24 |
|
26 |
| - status = solve(m) |
| 25 | + @objective m Max γ |
27 | 26 |
|
28 |
| - @test status == :Optimal |
| 27 | + status = solve(m) |
29 | 28 |
|
30 |
| - @test isapprox(getvalue(p), 128x^8 - 256x^6 + 160x^4 - 32x^2 + 1, ztol=1e-7, atol=1e-7) |
31 |
| - @test isapprox(getvalue(γ), 128) |
32 |
| - end |
| 29 | + @test status == :Optimal |
| 30 | + |
| 31 | + @test isapprox(getvalue(p), 128x^8 - 256x^6 + 160x^4 - 32x^2 + 1, ztol=1e-7, atol=1e-7) |
| 32 | + @test isapprox(getvalue(γ), 128) |
33 | 33 | end
|
0 commit comments