From a3b4caa29cc1b30e8e2066e744954af1d1388068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 16 Nov 2023 10:20:20 +0100 Subject: [PATCH] Add Parameters struct --- src/SDPLR.jl | 58 +++++++------ test/runtests.jl | 4 +- test/test_vibra.jl | 24 ++++++ test/vibra.jl | 198 +-------------------------------------------- 4 files changed, 59 insertions(+), 225 deletions(-) create mode 100644 test/test_vibra.jl diff --git a/src/SDPLR.jl b/src/SDPLR.jl index fe2213e..0a15b9f 100644 --- a/src/SDPLR.jl +++ b/src/SDPLR.jl @@ -6,6 +6,24 @@ function solve_sdpa_file(file) return run(`$(SDPLR_jll.sdplr()) $file`) end +# Default values taken from `SDPLR-1.03-beta/source/params.c` +@kwdef struct Parameters + #inputtype = 1 + rho_f::Cdouble = 1.0e-5 + rho_c::Cdouble = 1.0e-1 + sigmafac::Cdouble = 2.0 + rankreduce::Csize_t = 0 + timelim::Csize_t = 3600 + printlevel::Csize_t = 1 + dthresh_dim::Csize_t = 10 + dthresh_dens::Cdouble = 0.75 + numbfgsvecs::Csize_t = 4 + rankredtol::Cdouble = 2.2204460492503131e-16 + gaptol::Cdouble = 1.0e-3 + checkbd::Cptrdiff_t = -1 + typebd::Cptrdiff_t = 1 +end + function solve( blksz::Vector{Cptrdiff_t}, blktype::Vector{Cchar}, @@ -15,19 +33,7 @@ function solve( CAcol::Vector{Csize_t}, CAinfo_entptr::Vector{Csize_t}, CAinfo_type::Vector{Cchar}, - numbfgsvecs::Integer, - rho_f::Cdouble, - rho_c::Cdouble, - sigmafac::Cdouble, - rankreduce::Integer, - gaptol::Cdouble, - checkbd::Integer, - typebd::Integer, - dthresh_dim::Integer, - dthresh_dens::Cdouble, - timelim::Integer, - rankredtol::Cdouble, - printlevel::Integer, + params::Parameters, R::Vector{Cdouble}, lambda::Vector{Cdouble}, maxranks::Vector{Csize_t}, @@ -55,19 +61,19 @@ function solve( CAcol::Ptr{Csize_t}, CAinfo_entptr::Ptr{Csize_t}, CAinfo_type::Ptr{Cchar}, - numbfgsvecs::Csize_t, - rho_f::Cdouble, - rho_c::Cdouble, - sigmafac::Cdouble, - rankreduce::Csize_t, - gaptol::Cdouble, - checkbd::Cptrdiff_t, - typebd::Csize_t, - dthresh_dim::Csize_t, - dthresh_dens::Cdouble, - timelim::Csize_t, - rankredtol::Cdouble, - printlevel::Csize_t, + params.numbfgsvecs::Csize_t, + params.rho_f::Cdouble, + params.rho_c::Cdouble, + params.sigmafac::Cdouble, + params.rankreduce::Csize_t, + params.gaptol::Cdouble, + params.checkbd::Cptrdiff_t, + params.typebd::Csize_t, + params.dthresh_dim::Csize_t, + params.dthresh_dens::Cdouble, + params.timelim::Csize_t, + params.rankredtol::Cdouble, + params.printlevel::Csize_t, R::Ptr{Cdouble}, lambda::Ptr{Cdouble}, maxranks::Ptr{Csize_t}, diff --git a/test/runtests.jl b/test/runtests.jl index 2057a1d..b0eef8e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,3 +1 @@ -using SDPLR - -SDPLR.solve_sdpa_file("vibra1.dat-s") +include("test_vibra.jl") diff --git a/test/test_vibra.jl b/test/test_vibra.jl new file mode 100644 index 0000000..e4599a5 --- /dev/null +++ b/test/test_vibra.jl @@ -0,0 +1,24 @@ +using Test +import SDPLR +@testset "Solve vibra with sdplr executable" begin + SDPLR.solve_sdpa_file("vibra1.dat-s") +end +@testset "Solve vibra with sdplrlib" begin + ret = SDPLR.solve( + blksz, + blktype, + b, + CAent, + CArow, + CAcol, + CAinfo_entptr, + CAinfo_type, + SDPLR.Parameters(), + R, + lambda, + maxranks, + ranks, + pieces, + ) + @test iszero(ret) +end diff --git a/test/vibra.jl b/test/vibra.jl index 9937bbc..e93fcfe 100644 --- a/test/vibra.jl +++ b/test/vibra.jl @@ -1,6 +1,3 @@ -using Test -import SDPLR -ct = 449 m = 36 numblk = 3 blksz = Cptrdiff_t[24, 25, 36] @@ -1510,132 +1507,7 @@ CAcol = Csize_t[ 24, 36, ] -CAinfo_type = Cchar[ - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', - 's', - 's', - 'd', -] -numbfgsvecs = 4 -rho_f = 0.000010 -rho_c = 0.100000 -sigmafac = 2.000000 -rankreduce = 0 -gaptol = 0.001000 -checkbd = -1 -typebd = 1 -dthresh_dim = 10 -dthresh_dens = 0.750000 -timelim = 3600 -rankredtol = 0.000000 -printlevel = 1 +CAinfo_type = repeat(blktype, m + 1) R = Cdouble[ 0.409043, 0.849300, @@ -2115,44 +1987,7 @@ R = Cdouble[ -0.267370, -0.527711, ] -lambda = Cdouble[ - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, - 0.000000, -] +lambda = zeros(m) maxranks = Csize_t[9, 9, 1] ranks = Csize_t[9, 9, 1] pieces = Cdouble[ @@ -2165,32 +2000,3 @@ pieces = Cdouble[ 0.011765, 1.000000, ] -ret = SDPLR.solve( - blksz, - blktype, - b, - CAent, - CArow, - CAcol, - CAinfo_entptr, - CAinfo_type, - numbfgsvecs, - rho_f, - rho_c, - sigmafac, - rankreduce, - gaptol, - checkbd, - typebd, - dthresh_dim, - dthresh_dens, - timelim, - rankredtol, - printlevel, - R, - lambda, - maxranks, - ranks, - pieces, -) -@test iszero(ret)