Skip to content

Commit 48f97ed

Browse files
Update reading of QPSData (#22)
update reading with QPSData * update qps.jl and tests * add NLPModels 0.13 compat
1 parent 379fa7e commit 48f97ed

File tree

9 files changed

+96
-14
lines changed

9 files changed

+96
-14
lines changed

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1414
[compat]
1515
FastClosures = "0.2.1, 0.3.0"
1616
LinearOperators = "0.7.0, 1"
17-
NLPModels = "0.12"
17+
NLPModels = "0.13"
1818
Requires = "0.3, 0.4, 0.5"
1919
julia = "^1.0.0"
2020

2121
[extras]
2222
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
23+
QPSReader = "10f199a5-22af-520b-b891-7ce84a7b1bd0"
2324
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2425

2526
[targets]
26-
test = ["Printf", "Test"]
27+
test = ["Printf", "Test", "QPSReader"]

src/QuadraticModels.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export QuadraticModel
2020
include("qpmodel.jl")
2121

2222
function __init__()
23-
@require QPSReader = "758ba83c-e923-11e8-036a-3f93d0cb3d0c" include("qps.jl")
23+
@require QPSReader = "10f199a5-22af-520b-b891-7ce84a7b1bd0" include("qps.jl")
2424
end
2525

2626
end # module

src/qps.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
function QuadraticModel(qps::QPSData)
2-
QuadraticModel(qps.c, qps.Q, opHermitian(qps.Q), qps.A,
3-
qps.lcon, qps.ucon, qps.lvar, qps.uvar, c0=qps.c0)
1+
using .QPSReader
2+
3+
function QuadraticModel(qps::QPSData, x0=zeros(qps.nvar))
4+
QuadraticModel(qps.c, qps.qrows, qps.qcols, qps.qvals, Arows=qps.arows,
5+
Acols=qps.acols, Avals=qps.avals, lcon=qps.lcon,
6+
ucon=qps.ucon, lvar=qps.lvar, uvar=qps.uvar, c0=qps.c0,
7+
x0=x0)
48
end

test/problems/bndqp.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function bndqp_autodiff()
66
uvar = [1.0; 1.0]
77
lvar = [0.0; 0.0]
88

9-
return ADNLPModel(f, x0, lvar=lvar, uvar=uvar, name="bndqp_autodiff")
9+
return ADNLPModel(f, x0, lvar, uvar, name="bndqp_autodiff")
1010
end
1111

1212
function bndqp_QP()
@@ -18,3 +18,17 @@ function bndqp_QP()
1818

1919
return QuadraticModel(c, H, lvar=lvar, uvar=uvar, x0=x0, name="bndqp_QP")
2020
end
21+
22+
function bndqp_QPSData()
23+
c = [1.0; 1.0]
24+
H = [-2.0 0.0; 3.0 4.0]
25+
uvar = [1.0; 1.0]
26+
lvar = [0.0; 0.0]
27+
x0 = [0.5; 0.5]
28+
qps = QPSData()
29+
qps.c = c
30+
qps.qrows, qps.qcols, qps.qvals = findnz(sparse(H))
31+
qps.lvar, qps.uvar = lvar, uvar
32+
qps.nvar = length(x0)
33+
return QuadraticModel(qps, x0)
34+
end

test/problems/eqconqp.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function eqconqp_autodiff()
88
lcon = [0.0]
99
ucon = [0.0]
1010

11-
return ADNLPModel(f, x0, c=c, lcon=lcon, ucon=ucon, name="eqconqp_autodiff")
11+
return ADNLPModel(f, x0, c, lcon, ucon, name="eqconqp_autodiff")
1212
end
1313

1414
function eqconqp_QP()
@@ -21,3 +21,22 @@ function eqconqp_QP()
2121

2222
return QuadraticModel(c, H, A=A, lcon=lcon, ucon=ucon, name="eqconqp_QP")
2323
end
24+
25+
function eqconqp_QPSData()
26+
n = 50
27+
c = zeros(n)
28+
H = spdiagm(0 => 1:n)
29+
A = ones(1, n)
30+
lcon = [1.0]
31+
ucon = [1.0]
32+
lvar = [-Inf for i=1:n]
33+
uvar = [Inf for i=1:n]
34+
qps = QPSData()
35+
qps.c = c
36+
qps.qrows, qps.qcols, qps.qvals = findnz(H)
37+
qps.arows, qps.acols, qps.avals = findnz(sparse(A))
38+
qps.lcon, qps.ucon = lcon, ucon
39+
qps.lvar, qps.uvar = lvar, uvar
40+
qps.nvar = length(c)
41+
return QuadraticModel(qps)
42+
end

test/problems/ineqconqp.jl

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function ineqconqp_autodiff()
77
lcon = [0.0; -Inf; -1.0]
88
ucon = [Inf; 0.0; 1.0]
99

10-
return ADNLPModel(f, x0, c=c, lcon=lcon, ucon=ucon, name="ineqconqp_autodiff")
10+
return ADNLPModel(f, x0, c, lcon, ucon, name="ineqconqp_autodiff")
1111
end
1212

1313
function ineqconqp_QP()
@@ -25,3 +25,28 @@ function ineqconqp_QP()
2525

2626
return QuadraticModel(c, Hrows, Hcols, Hvals, Arows=Arows, Acols=Acols, Avals=Avals, lcon=lcon, ucon=ucon, c0=c0, x0=x0, name="ineqconqp_QP")
2727
end
28+
29+
function ineqconqp_QPSData()
30+
c = -ones(2)
31+
Hrows = [1, 2]
32+
Hcols = [1, 2]
33+
Hvals = ones(2)
34+
Arows = [1, 1, 2, 2, 3, 3]
35+
Acols = [1, 2, 1, 2, 1, 2]
36+
Avals = [1.0; -1.0; -1.0; 1.0; 1.0; 1.0]
37+
c0 = 1.0
38+
lcon = [0.0; -Inf; -1.0]
39+
ucon = [Inf; 0.0; 1.0]
40+
x0 = ones(2)
41+
lvar = [-Inf; -Inf]
42+
uvar = [Inf; Inf]
43+
qps = QPSData()
44+
qps.c = c
45+
qps.c0 = c0
46+
qps.qrows, qps.qcols, qps.qvals = Hrows, Hcols, Hvals
47+
qps.arows, qps.acols, qps.avals = Arows, Acols, Avals
48+
qps.lcon, qps.ucon = lcon, ucon
49+
qps.lvar, qps.uvar = lvar, uvar
50+
qps.nvar = length(x0)
51+
return QuadraticModel(qps, x0)
52+
end

test/problems/uncqp.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,21 @@ function uncqp_QP()
1717

1818
return QuadraticModel(c, Hrows, Hcols, Hvals, c0=c0, x0=x0, name="uncqp_QP")
1919
end
20+
21+
function uncqp_QPSData()
22+
c = [3.0; -2.0]
23+
Hrows = [1, 2, 2]
24+
Hcols = [1, 1, 2]
25+
Hvals = [8.0; -1.0; 10.0]
26+
lvar = [-Inf; -Inf]
27+
uvar = [Inf; Inf]
28+
c0 = 1.0
29+
x0 = [-1.2; 1.0]
30+
qps = QPSData()
31+
qps.c = c
32+
qps.qrows, qps.qcols, qps.qvals = Hrows, Hcols, Hvals
33+
qps.c0 = c0
34+
qps.lvar, qps.uvar = lvar, uvar
35+
qps.nvar = length(x0)
36+
return QuadraticModel(qps, x0)
37+
end

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Printf, SparseArrays, Test
33

44
# our packages
5-
using LinearAlgebra, LinearOperators, NLPModels, QuadraticModels
5+
using LinearAlgebra, LinearOperators, NLPModels, QPSReader, QuadraticModels
66

77
nlpmodels_path = joinpath(dirname(pathof(NLPModels)), "..", "test")
88
nlpmodels_problems_path = joinpath(nlpmodels_path, "problems")

test/test_consistency.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ for problem in qp_problems
3434
@info "Checking consistency of problem $problem"
3535
nlp_ad = eval(Symbol(problem * "_autodiff"))()
3636
nlp_qm = eval(Symbol(problem * "_QP"))()
37-
nlps = [nlp_ad, nlp_qm]
37+
nlp_qps = eval(Symbol(problem * "_QPSData"))()
38+
nlps = [nlp_ad, nlp_qm, nlp_qps]
3839
consistent_nlps(nlps)
3940
@info " Consistency checks ✓"
4041
end
@@ -50,11 +51,11 @@ for problem in [:brownden, :hs5, :hs6, :hs10, :hs11, :hs14, :lincon]
5051
nlp_ad = if nlp.meta.ncon > 0
5152
cx, Ax = cons(nlp, x), jac(nlp, x)
5253
ADNLPModel(s -> fx + dot(gx, s) + dot(s, Hx * s) / 2, zeros(nlp.meta.nvar),
53-
lvar=nlp.meta.lvar - x, uvar=nlp.meta.uvar - x,
54-
c=s -> Ax * s, lcon=nlp.meta.lcon - cx, ucon=nlp.meta.ucon - cx)
54+
nlp.meta.lvar - x, nlp.meta.uvar - x,
55+
s -> Ax * s, nlp.meta.lcon - cx, nlp.meta.ucon - cx)
5556
else
5657
ADNLPModel(s -> fx + dot(gx, s) + dot(s, Hx * s) / 2, zeros(nlp.meta.nvar),
57-
lvar=nlp.meta.lvar - x, uvar=nlp.meta.uvar - x)
58+
nlp.meta.lvar - x, nlp.meta.uvar - x)
5859
end
5960
nlp_qm = QuadraticModel(nlp, x)
6061
nlps = [nlp_ad, nlp_qm]

0 commit comments

Comments
 (0)