Skip to content

Commit

Permalink
Add sdp test (#30)
Browse files Browse the repository at this point in the history
* Add sdp test

* Fixes

* Fix

* Debug

* Fix

* Remove debug log
  • Loading branch information
blegat authored May 15, 2024
1 parent 6eabe72 commit f106018
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using DSDP
using Test

include("maxcut.jl")
include("build.jl")
include("options.jl")
include("MOI_wrapper.jl")
include("sdp.jl")
#include("build.jl")
#include("options.jl")
#include("MOI_wrapper.jl")
37 changes: 37 additions & 0 deletions test/sdp.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Test, DSDP

function test_sdp(tol)
dsdp = DSDP.Create(1)
sdpcone = DSDP.CreateSDPCone(dsdp, 1)
DSDP.SDPCone.SetBlockSize(sdpcone, 0, 2)
DSDP.SDPCone.SetSparsity(sdpcone, 0, 0)
DSDP.SDPCone.SetStorageFormat(sdpcone, 0, UInt8('U'))
DSDP.SetY0(dsdp, 1, 0.0)
DSDP.SetDualObjective(dsdp, 1, 1.0)
DSDP.SDPCone.SetASparseVecMat(sdpcone, 0, 1, 2, 1.0, 0, Int32[2], [0.5], 1)
DSDP.SDPCone.SetASparseVecMat(sdpcone, 0, 0, 2, 1.0, 0, Int32[0, 3], [0.5, 0.5], 2)
DSDP.Setup(dsdp)
DSDP.Solve(dsdp)
DSDP.ComputeX(dsdp)
@test DSDP.GetIts(dsdp) == 11
derr = DSDP.GetFinalErrors(dsdp)
@test derr != zeros(Cdouble, 6) # To check that it's not just the allocated vector and we actually got the errors
@test derr zeros(Cdouble, 6) atol = tol

# P Infeasible: derr[1]
# D Infeasible: derr[3]
# Minimal P Eigenvalue: derr[2]
# Minimal D Eigenvalue: 0.00, see `DSDP` source in `examples/readsdpa.c`
# Relative P - D Objective values: derr[5]
# Relative X Dot S: %4.2e: derr[6]

@test DSDP.StopReason(dsdp) == 1
@test DSDP.GetSolutionType(dsdp) == 1
@test DSDP.GetDObjective(dsdp) 1 rtol = 1e-6
@test DSDP.GetPObjective(dsdp) 1 rtol = 1e-6
@test DSDP.SDPCone.GetXArray(sdpcone, 0) [1, 0, 1, 1] rtol = 1e-6
return
end
@testset "SDP example" begin
test_sdp(1e-6)
end

0 comments on commit f106018

Please sign in to comment.