Skip to content

Commit f106018

Browse files
authored
Add sdp test (#30)
* Add sdp test * Fixes * Fix * Debug * Fix * Remove debug log
1 parent 6eabe72 commit f106018

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

test/runtests.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using DSDP
22
using Test
33

44
include("maxcut.jl")
5-
include("build.jl")
6-
include("options.jl")
7-
include("MOI_wrapper.jl")
5+
include("sdp.jl")
6+
#include("build.jl")
7+
#include("options.jl")
8+
#include("MOI_wrapper.jl")

test/sdp.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Test, DSDP
2+
3+
function test_sdp(tol)
4+
dsdp = DSDP.Create(1)
5+
sdpcone = DSDP.CreateSDPCone(dsdp, 1)
6+
DSDP.SDPCone.SetBlockSize(sdpcone, 0, 2)
7+
DSDP.SDPCone.SetSparsity(sdpcone, 0, 0)
8+
DSDP.SDPCone.SetStorageFormat(sdpcone, 0, UInt8('U'))
9+
DSDP.SetY0(dsdp, 1, 0.0)
10+
DSDP.SetDualObjective(dsdp, 1, 1.0)
11+
DSDP.SDPCone.SetASparseVecMat(sdpcone, 0, 1, 2, 1.0, 0, Int32[2], [0.5], 1)
12+
DSDP.SDPCone.SetASparseVecMat(sdpcone, 0, 0, 2, 1.0, 0, Int32[0, 3], [0.5, 0.5], 2)
13+
DSDP.Setup(dsdp)
14+
DSDP.Solve(dsdp)
15+
DSDP.ComputeX(dsdp)
16+
@test DSDP.GetIts(dsdp) == 11
17+
derr = DSDP.GetFinalErrors(dsdp)
18+
@test derr != zeros(Cdouble, 6) # To check that it's not just the allocated vector and we actually got the errors
19+
@test derr zeros(Cdouble, 6) atol = tol
20+
21+
# P Infeasible: derr[1]
22+
# D Infeasible: derr[3]
23+
# Minimal P Eigenvalue: derr[2]
24+
# Minimal D Eigenvalue: 0.00, see `DSDP` source in `examples/readsdpa.c`
25+
# Relative P - D Objective values: derr[5]
26+
# Relative X Dot S: %4.2e: derr[6]
27+
28+
@test DSDP.StopReason(dsdp) == 1
29+
@test DSDP.GetSolutionType(dsdp) == 1
30+
@test DSDP.GetDObjective(dsdp) 1 rtol = 1e-6
31+
@test DSDP.GetPObjective(dsdp) 1 rtol = 1e-6
32+
@test DSDP.SDPCone.GetXArray(sdpcone, 0) [1, 0, 1, 1] rtol = 1e-6
33+
return
34+
end
35+
@testset "SDP example" begin
36+
test_sdp(1e-6)
37+
end

0 commit comments

Comments
 (0)