/
constraint.jl
33 lines (31 loc) · 1.76 KB
/
constraint.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import SemialgebraicSets
import PolyJuMP
@testset "Non-symmetric matrix SOS constraint" begin
@polyvar x
model = SOSModel()
path = joinpath(dirname(dirname(pathof(SumOfSquares))), "test", "constraint.jl")
err = ErrorException("At $path:9: `@constraint(model, [1 x; -x 0] in SOSMatrixCone())`: The polynomial matrix constrained to be SOS must be symmetric.")
@test_throws err @constraint(model, [1 x; -x 0] in SOSMatrixCone())
end
@testset "Printing" begin
@polyvar x
model = SOSModel()
@variable(model, a)
cref = @constraint(model, a * x^2 >= 1)
@test sprint(show, MIME"text/plain"(), cref) == "(a)x² + (-1) is SOS"
@test sprint(show, MIME"text/latex"(), cref) == "\$ (a)x^{2} + (-1) \\text{ is SOS} \$"
sdref = @constraint(model, a * x^2 in SDSOSCone())
@test sprint(show, MIME"text/plain"(), sdref) == "(a)x² is SDSOS"
@test sprint(show, MIME"text/latex"(), sdref) == "\$ (a)x^{2} \\text{ is SDSOS} \$"
dref = @constraint(model, a * x^2 in DSOSCone())
@test sprint(show, MIME"text/plain"(), dref) == "(a)x² is DSOS"
@test sprint(show, MIME"text/latex"(), dref) == "\$ (a)x^{2} \\text{ is DSOS} \$"
for sparsity in [NoSparsity(), VariableSparsity()]
cref_fix = @constraint(model, a * x^2 >= 1, domain = (@set x == 1), sparsity = sparsity)
@test sprint(show, MIME"text/plain"(), cref_fix) == "(a)x² + (-1) is SOS"
@test sprint(show, MIME"text/latex"(), cref_fix) == "\$ (a)x^{2} + (-1) \\text{ is SOS} \$"
cref_fix = @constraint(model, a * x^2 >= 1, domain = (@set x >= 1), sparsity = sparsity)
@test sprint(show, MIME"text/plain"(), cref_fix) == "(a)x² + (-1) is SOS"
@test sprint(show, MIME"text/latex"(), cref_fix) == "\$ (a)x^{2} + (-1) \\text{ is SOS} \$"
end
end