Skip to content

Commit

Permalink
[GALAHAD.jl] Test the pakages bllsb, clls and presolve
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Feb 12, 2024
1 parent 4cbae35 commit cfb52e4
Show file tree
Hide file tree
Showing 5 changed files with 406 additions and 299 deletions.
10 changes: 6 additions & 4 deletions GALAHAD.jl/gen/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@ function examples(package::String, example::String)
text = replace(text, "} #" => "] #")
for var in ("A_val", "A_dense", "b", "c", "c_l", "c_u", "x_l", "x_u", "y_l", "y_u", "z_l", "z_u", "g", "x_0",
"w", "x", "y", "z", "val", "dense", "rhs", "rhst", "sol", "H_val", "H_dense", "C_val",
"C_dense", "H_diag", "C_diag", "H_scid", "C_scid", "Ao_val")
"C_dense", "H_diag", "C_diag", "H_scid", "C_scid", "Ao_val", "r")
text = replace(text, "real_wp_ $var[] = {" => "$var = Float64[")
end
for var in ("f", "power", "weight", "shift", "radius", "half_radius", "x_l", "x_u")
for var in ("f", "power", "weight", "shift", "radius", "half_radius", "x_l", "x_u", "sigma")
text = replace(text, "real_wp_ $var =" => "$var =")
end
for var in ("n", "ne", "m", "A_ne", "A_dense_ne", "H_ne", "H_dense_ne", "C_dense_ne", "C_ne", "dense_ne")
for var in ("n", "ne", "m", "A_ne", "A_dense_ne", "H_ne", "H_dense_ne", "C_dense_ne",
"C_ne", "dense_ne", "o", "Ao_ne", "Ao_ptr_ne", "A_ptr_ne")
text = replace(text, "int $var =" => "$var =")
end
for var in ("A_row", "A_col", "A_ptr", "row", "col", "ptr", "c_stat", "x_stat", "H_row", "H_col", "H_ptr",
"C_row", "C_col", "C_ptr", "Ao_col", "Ao_ptr")
"C_row", "C_col", "C_ptr", "Ao_col", "Ao_ptr", "Ao_row")
text = replace(text, "int $var[] = {" => "$var = Cint[")
end
for val in ("1", "3", "5", "6", "7", "n", "n+m")
Expand All @@ -62,6 +63,7 @@ function examples(package::String, example::String)
for val in ("c", "g", "u", "v", "x", "r", "vector", "h_vector", "error")
text = replace(text, "real_wp_ $val[n]" => "$val = zeros(Float64, n)")
text = replace(text, "real_wp_ $val[m]" => "$val = zeros(Float64, m)")
text = replace(text, "real_wp_ $val[o]" => "$val = zeros(Float64, o)")
end
for val in ("x_stat", "c_stat", "index_nz_u", "index_nz_v", "depen")
text = replace(text, "int $val[n]" => "$val = zeros(Cint, n)")
Expand Down
8 changes: 3 additions & 5 deletions GALAHAD.jl/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ include("test_structures.jl")
# include("test_blls.jl")
include("test_bllsb.jl")
# include("test_bqp.jl")
if !Sys.iswindows()
include("test_bqpb.jl")
end
include("test_bqpb.jl")
include("test_bsc.jl")
include("test_ccqp.jl")
# include("test_clls.jl")
include("test_clls.jl")
include("test_convert.jl")
# include("test_cqp.jl")
# include("test_cro.jl")
Expand All @@ -39,7 +37,7 @@ include("test_lsqp.jl")
include("test_lsrt.jl")
include("test_lstr.jl")
# include("test_nls.jl")
# include("test_presolve.jl")
include("test_presolve.jl")
include("test_psls.jl")
# include("test_qpa.jl")
# include("test_qpb.jl")
Expand Down
1 change: 1 addition & 0 deletions GALAHAD.jl/test/test_bllsb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function test_bllsb()
sigma, x_l, x_u, x, r, z, x_stat, w)
end

# sparse by columns
if d == 3
st = "SC"
Ao_ne = 7 # objective Jacobian elements
Expand Down
311 changes: 195 additions & 116 deletions GALAHAD.jl/test/test_clls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,124 +2,203 @@
# Simple code to test the Julia interface to CLLS

using GALAHAD
using Test
using Printf

# Derived types
data = [Ptr{Ptr{Cvoid}}()]
control = clls_control_type{Float64}()
inform = clls_inform_type{Float64}()

# Set problem data
n = 3 # dimension
o = 4 # number of observations
m = 2 # number of general constraints
Ao_ne = 7 # design matrix elements
Ao_row = Cint[1, 1, 2, 2, 3, 3, 4] # row indices
Ao_col = Cint[1, 2, 2, 1, 3, 2] # column indices
Ao_ptr_ne = o + 1 # row pointer length
Ao_ptr = Cint[1, 3, 5, 7, 8] # row pointers
Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # values
b = Float64[2.0, 2.0, 3.0, 1.0] # observations
A_ne = 4 # Jacobian elements
A_row = Cint[1, 1, 2, 2] # row indices
A_col = Cint[1, 2, 2, 3] # column indices
Ao_ptr_ne = m + 1 # row pointer length
A_ptr = Cint[1, 3, 5] # row pointers
A_val = Float64[2.0, 1.0, 1.0, 1.0] # values
c_l = Float64[1.0, 2.0] # constraint lower bound
c_u = Float64[2.0, 2.0] # constraint upper bound
x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound
x_u = Float64[1.0, Inf, 2.0] # variable upper bound
sigma = 1.0 # regularization weight
w = Float64[1.0, 1.0, 1.0, 2.0] # values

# Set output storage
c = zeros(Float64, m) # constraint values
x_stat = zeros(Cint, n) # variable status
c_stat = zeros(Cint, m) # constraint status
st = ' '
status = Ref{Cint}()

@printf(" Fortran sparse matrix indexing\n\n")
@printf(" basic tests of clls storage formats\n\n")

for d = 1:3

# Initialize CLLS
clls_initialize( data, control, status )

# Set user-defined control options
control.f_indexing = true # Fortran sparse matrix indexing

# Start from 0
x = Float64[0.0,0.0,0.0]
y = Float64[0.0,0.0]
z = Float64[0.0,0.0,0.0]

# sparse co-ordinate storage
if d == 1
global st = 'C'

clls_import( control, data, status, n, o, m,
"coordinate", Ao_ne, Ao_row, Ao_col, 0, Cint[],
"coordinate", A_ne, A_row, A_col, 0, Cint[] )

clls_solve_clls( data, status, n, o, m, Ao_ne, Ao_val, b, sigma,
A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z,
x_stat, c_stat, w )
using Accessors

function test_clls()
# Derived types
data = Ref{Ptr{Cvoid}}()
control = Ref{clls_control_type{Float64}}()
inform = Ref{clls_inform_type{Float64}}()

# Set problem data
n = 3 # dimension
o = 4 # number of observations
m = 2 # number of general constraints
sigma = 1.0 # regularization weight
b = Float64[2.0, 2.0, 3.0, 1.0] # observations
c_l = Float64[1.0, 2.0] # constraint lower bound
c_u = Float64[2.0, 2.0] # constraint upper bound
x_l = Float64[-1.0, -Inf, -Inf] # variable lower bound
x_u = Float64[1.0, Inf, 2.0] # variable upper bound
w = Float64[1.0, 1.0, 1.0, 2.0] # weights

# Set output storage
r = zeros(Float64, o) # residual values
c = zeros(Float64, m) # constraint values
x_stat = zeros(Cint, n) # variable status
c_stat = zeros(Cint, m) # constraint status
st = ""
status = Ref{Cint}()

@printf(" Fortran sparse matrix indexing\n\n")
@printf(" basic tests of clls storage formats\n\n")

for d in 1:5
# Initialize CLLS
clls_initialize(data, control, status)

# Set user-defined control options
@reset control[].f_indexing = true # Fortran sparse matrix indexing
@reset control[].symmetric_linear_solver = convert(NTuple{31,Int8},
(112, 111, 116, 114, 32,
32, 32,
32, 32, 32, 32, 32, 32,
32, 32,
32, 32, 32, 32, 32, 32,
32, 32,
32, 32, 32, 32, 32, 32,
32, 0))

@reset control[].fdc_control.symmetric_linear_solver = convert(NTuple{31,Int8},
(112, 111, 116, 114, 32,
32, 32,
32, 32, 32, 32, 32, 32,
32, 32,
32, 32, 32, 32, 32, 32,
32, 32,
32, 32, 32, 32, 32, 32,
32, 0))
@reset control[].fdc_control.use_sls = true

# Start from 0
x = Float64[0.0, 0.0, 0.0]
y = Float64[0.0, 0.0]
z = Float64[0.0, 0.0, 0.0]

# sparse co-ordinate storage
if d == 1
st = "CO"
Ao_ne = 7 # objective Jacobian elements
Ao_row = Cint[1, 1, 2, 2, 3, 3, 4] # row indices
Ao_col = Cint[1, 2, 2, 3, 1, 3, 2] # column indices
Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals
A_ne = 4 # constraint Jacobian elements
A_row = Cint[1, 1, 2, 2] # row indices
A_col = Cint[1, 2, 2, 3] # column indices
A_val = Float64[2.0, 1.0, 1.0, 1.0] # values

clls_import(control, data, status, n, o, m,
"coordinate", Ao_ne, Ao_row, Ao_col, 0, Cint[],
"coordinate", A_ne, A_row, A_col, 0, Cint[])

clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_val, b,
sigma, A_ne, A_val, c_l, c_u, x_l, x_u,
x, r, c, y, z, x_stat, c_stat, w)
end

# sparse by rows
if d == 2
st = "SR"
Ao_ne = 7 # objective Jacobian elements
Ao_col = Cint[1, 2, 2, 3, 1, 3, 2] # column indices
Ao_ptr_ne = o + 1 # number of row pointers
Ao_ptr = Cint[1, 3, 5, 7, 8] # row pointers
Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals
A_ne = 4 # constraint Jacobian elements
A_col = Cint[1, 2, 2, 3] # column indices
A_ptr_ne = m + 1 # number of row pointers
A_ptr = Cint[1, 3, 5] # row pointers
A_val = Float64[2.0, 1.0, 1.0, 1.0] # values

clls_import(control, data, status, n, o, m,
"sparse_by_rows", Ao_ne, Cint[], Ao_col,
Ao_ptr_ne, Ao_ptr,
"sparse_by_rows", A_ne, Cint[], A_col,
A_ptr_ne, A_ptr)

clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_val, b,
sigma, A_ne, A_val, c_l, c_u, x_l, x_u,
x, r, c, y, z, x_stat, c_stat, w)
end

# sparse by columns
if d == 3
st = "SC"
Ao_ne = 7 # objective Jacobian elements
Ao_row = Cint[1, 3, 1, 2, 4, 2, 3] # row indices
Ao_ptr_ne = n + 1 # number of column pointers
Ao_ptr = Cint[1, 3, 6, 8] # column pointers
Ao_val = Float64[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # vals
A_ne = 4 # constraint Jacobian elements
A_row = Cint[1, 1, 2, 2] # row indices
A_ptr_ne = n + 1 # number of column pointers
A_ptr = Cint[1, 2, 4, 5] # column pointers
A_val = Float64[2.0, 1.0, 1.0, 1.0] # values

clls_import(control, data, status, n, o, m,
"sparse_by_columns", Ao_ne, Ao_row, Cint[],
Ao_ptr_ne, Ao_ptr,
"sparse_by_columns", A_ne, A_row, Cint[],
A_ptr_ne, A_ptr)

clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_val, b,
sigma, A_ne, A_val, c_l, c_u, x_l, x_u,
x, r, c, y, z, x_stat, c_stat, w)
end

# dense by rows
if d == 4
st = "DR"
Ao_ne = 12 # objective Jacobian elements
Ao_dense = Float64[1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0]
A_ne = 6 # constraint Jacobian elements
A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0]

clls_import(control, data, status, n, o, m,
"dense", Ao_ne, Cint[], Cint[], 0, Cint[],
"dense", A_ne, Cint[], Cint[], 0, Cint[])

clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_dense, b,
sigma, A_ne, A_dense, c_l, c_u, x_l, x_u,
x, r, c, y, z, x_stat, c_stat, w)
end

# dense by cols
if d == 5
st = "DC"
Ao_ne = 12 # objective Jacobian elements
Ao_dense = Float64[1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0]
A_ne = 6 # constraint Jacobian elements
A_dense = Float64[2.0, 0.0, 1.0, 1.0, 0.0, 1.0]

clls_import(control, data, status, n, o, m,
"dense_by_columns", Ao_ne, Cint[], Cint[], 0, Cint[],
"dense_by_columns", A_ne, Cint[], Cint[], 0, Cint[])

clls_solve_clls(data, status, n, o, m, Ao_ne, Ao_dense, b,
sigma, A_ne, A_dense, c_l, c_u, x_l, x_u,
x, r, c, y, z, x_stat, c_stat, w)
end

clls_information(data, inform, status)

if inform[].status == 0
@printf("%s:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st,
inform[].iter, inform[].obj, inform[].status)
else
@printf("%s: CLLS_solve exit status = %1i\n", st, inform[].status)
end

# @printf("x: ")
# for i = 1:n
# @printf("%f ", x[i])
# end
# @printf("\n")
# @printf("gradient: ")
# for i = 1:n
# @printf("%f ", g[i])
# end
# @printf("\n")

# Delete internal workspace
clls_terminate(data, control, inform)
end

# sparse by rows
if d == 2
global st = 'R'

clls_import( control, data, status, n, o, m,
"sparse_by_rows", Ao_ne, Cint[], Ao_col, Ao_ptr_ne, Ao_ptr,
"sparse_by_rows", A_ne, Cint[], A_col, A_ptr_ne, A_ptr )

clls_solve_clls( data, status, n, o, m, Ao_ne, Ao_val, b, sigma,
A_ne, A_val, c_l, c_u, x_l, x_u, x, c, y, z,
x_stat, c_stat, w )
end

# dense
if d == 3
global st = 'D'

Ao_dense_ne = 12 # number of elements of Ao
A_dense_ne = 6 # number of elements of A
Ao_dense = Float64[1.0, 1.0, 0.0, 0.0, 1.0, 1.0,
1.0, 0.0, 1.0, 0.0, 1.0, 0.0]
A_dense = Float64[2.0, 1.0, 0.0, 0.0, 1.0, 1.0]

clls_import( control, data, status, n, o, m,
"dense", Ao_ne, Cint[], Cint[], 0, Cint[],
"dense", A_ne, Cint[], Cint[], 0, Cint[] )

clls_solve_clls( data, status, n, o, m, Ao_dense_ne, Ao_dense, b, sigma,
A_dense_ne, A_dense, c_l, c_u, x_l, x_u,
x, c, y, z, x_stat, c_stat, w )
end

clls_information( data, inform, status )

if inform.status == 0
@printf("%c:%6i iterations. Optimal objective value = %5.2f status = %1i\n", st, inform.iter, inform.obj, inform.status)
else
@printf("%c: CLLS_solve exit status = %1i\n", st, inform.status)
end
return 0
end

# @printf("x: ")
# for i = 1:n
# @printf("%f ", x[i])
# end
# @printf("\n")
# @printf("gradient: ")
# for i = 1:n
# @printf("%f ", g[i])
# end
# @printf("\n")

# Delete internal workspace
clls_terminate( data, control, inform )
@testset "CLLS" begin
@test test_clls() == 0
end
Loading

0 comments on commit cfb52e4

Please sign in to comment.