Skip to content

Commit b99edcd

Browse files
authored
more 0.7 compat fixes (#209)
1 parent f2d9c55 commit b99edcd

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

src/SolverInterface/conic_to_lpqp.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mutable struct ConicToLPQPBridge <: AbstractLinearQuadraticModel
1818
vartypes::Vector{Symbol}
1919
end
2020

21-
ConicToLPQPBridge(s::AbstractConicModel) = ConicToLPQPBridge(s, sparse(Int[],Int[],Float64[]), Float64[], Float64[], Float64[], Float64[], Float64[], :Min, Int[], Array{Vector{Int}}(0),Array{Vector{Int}}(0), Symbol[])
21+
ConicToLPQPBridge(s::AbstractConicModel) = ConicToLPQPBridge(s, sparse(Int[],Int[],Float64[]), Float64[], Float64[], Float64[], Float64[], Float64[], :Min, Int[], Array{Vector{Int}}(undef, 0),Array{Vector{Int}}(undef, 0), Symbol[])
2222

2323
export ConicToLPQPBridge
2424

@@ -113,7 +113,7 @@ function optimize!(wrap::ConicToLPQPBridge)
113113
(nvar = length(collb)) == length(colub) || error("Unequal lengths for column bounds")
114114
(nrow = length(rowlb)) == length(rowub) || error("Unequal lengths for row bounds")
115115

116-
constr_cones = Array{Any}(0)
116+
constr_cones = []
117117
var_cones = [(:Free,1:nvar)]
118118

119119
# for each variable bound, create a new constraint
@@ -159,20 +159,20 @@ function optimize!(wrap::ConicToLPQPBridge)
159159
if rowlb[it] == rowub[it]
160160
# a'x = b ==> b - a'x = 0
161161
push!(b, rowlb[it])
162-
push!(constr_cones,(:Zero,it+(extrarows:extrarows)))
162+
push!(constr_cones,(:Zero,it.+(extrarows:extrarows)))
163163
# Range constraint - not supported
164164
elseif rowlb[it] != -Inf && rowub[it] != Inf
165165
error("Ranged constraints unsupported!")
166166
# Less-than constraint
167167
elseif rowlb[it] == -Inf
168168
# a'x <= b ==> b - a'x >= 0
169169
push!(b, rowub[it])
170-
push!(constr_cones,(:NonNeg,it+(extrarows:extrarows)))
170+
push!(constr_cones,(:NonNeg,it.+(extrarows:extrarows)))
171171
# Greater-than constraint
172172
else
173173
# a'x >= b ==> b - a'x <= 0
174174
push!(b, rowlb[it])
175-
push!(constr_cones,(:NonPos,it+(extrarows:extrarows)))
175+
push!(constr_cones,(:NonPos,it.+(extrarows:extrarows)))
176176
end
177177
end
178178

test/quadprog.jl

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using Base.Test
1+
using Compat.Test
2+
using Compat.LinearAlgebra
23
using MathProgBase
3-
using MathProgBase.SolverInterface
44

55
function quadprogtest(solver)
66
@testset "Testing quadprog with $solver" begin
@@ -10,30 +10,30 @@ function quadprogtest(solver)
1010
@test isapprox(norm(sol.sol[1:3] - [0.5714285714285715,0.4285714285714285,0.8571428571428572]), 0.0, atol=1e-6)
1111

1212
@testset "QP1" begin
13-
m = LinearQuadraticModel(solver)
14-
loadproblem!(m, [1. 2. 3.; 1. 1. 0.],[-Inf,-Inf,-Inf],[Inf,Inf,Inf],[0.,0.,0.],[4., 1.],[Inf,Inf], :Min)
13+
m = MathProgBase.LinearQuadraticModel(solver)
14+
MathProgBase.loadproblem!(m, [1. 2. 3.; 1. 1. 0.],[-Inf,-Inf,-Inf],[Inf,Inf,Inf],[0.,0.,0.],[4., 1.],[Inf,Inf], :Min)
1515

16-
setquadobj!(m,diagm([10.0,10.0,10.0]))
16+
MathProgBase.setquadobj!(m,diagm([10.0,10.0,10.0]))
1717
rows = [1, 2, 2, 2, 3, 3, 3]
1818
cols = [1, 1, 1, 2, 2, 3, 3]
1919
vals = Float64[2, 0.5, 0.5, 2, 1, 1, 1]
20-
setquadobj!(m,rows,cols,vals)
21-
optimize!(m)
22-
stat = status(m)
20+
MathProgBase.setquadobj!(m,rows,cols,vals)
21+
MathProgBase.optimize!(m)
22+
stat = MathProgBase.status(m)
2323
@test stat == :Optimal
24-
@test isapprox(getobjval(m), 130/70, atol=1e-6)
25-
@test isapprox(norm(getsolution(m) - [0.5714285714285715,0.4285714285714285,0.8571428571428572]), 0.0, atol=1e-6)
24+
@test isapprox(MathProgBase.getobjval(m), 130/70, atol=1e-6)
25+
@test isapprox(norm(MathProgBase.getsolution(m) - [0.5714285714285715,0.4285714285714285,0.8571428571428572]), 0.0, atol=1e-6)
2626
end
2727

2828
@testset "QP2" begin
29-
m = LinearQuadraticModel(solver)
30-
loadproblem!(m, [-1. 1.; 1. 1.], [0.,0.], [Inf,Inf], [1.,1.], [0.,0.], [Inf,Inf], :Max)
31-
addquadconstr!(m, [2], [1.], [1], [1], [1.], '<', 2)
32-
optimize!(m)
33-
stat = status(m)
29+
m = MathProgBase.LinearQuadraticModel(solver)
30+
MathProgBase.loadproblem!(m, [-1. 1.; 1. 1.], [0.,0.], [Inf,Inf], [1.,1.], [0.,0.], [Inf,Inf], :Max)
31+
MathProgBase.addquadconstr!(m, [2], [1.], [1], [1], [1.], '<', 2)
32+
MathProgBase.optimize!(m)
33+
stat = MathProgBase.status(m)
3434
@test stat == :Optimal
35-
@test isapprox(getobjval(m), 2.25, atol=1e-6)
36-
@test isapprox(norm(getsolution(m) - [0.5,1.75]), 0.0, atol=1e-3)
35+
@test isapprox(MathProgBase.getobjval(m), 2.25, atol=1e-6)
36+
@test isapprox(norm(MathProgBase.getsolution(m) - [0.5,1.75]), 0.0, atol=1e-3)
3737
end
3838
end
3939
end
@@ -43,37 +43,37 @@ function qpdualtest(solver)
4343
# max x
4444
# s.t. x^2 <= 2
4545
@testset "QP1" begin
46-
m = LinearQuadraticModel(solver)
47-
loadproblem!(m, Array{Float64}(0,1), [-Inf], [Inf], [1.0], Float64[], Float64[], :Max)
48-
addquadconstr!(m, [], [], [1], [1], [1.0], '<', 2.0)
49-
optimize!(m)
50-
stat = status(m)
46+
m = MathProgBase.LinearQuadraticModel(solver)
47+
MathProgBase.loadproblem!(m, Array{Float64}(0,1), [-Inf], [Inf], [1.0], Float64[], Float64[], :Max)
48+
MathProgBase.addquadconstr!(m, [], [], [1], [1], [1.0], '<', 2.0)
49+
MathProgBase.optimize!(m)
50+
stat = MathProgBase.status(m)
5151

52-
@test numlinconstr(m) == 0
53-
@test numquadconstr(m) == 1
54-
@test numconstr(m) == 1
52+
@test MathProgBase.numlinconstr(m) == 0
53+
@test MathProgBase.numquadconstr(m) == 1
54+
@test MathProgBase.numconstr(m) == 1
5555
@test stat == :Optimal
56-
@test isapprox(getobjval(m), sqrt(2), atol=1e-6)
57-
@test isapprox(getsolution(m)[1], sqrt(2), atol=1e-6)
58-
@test isapprox(getquadconstrduals(m)[1], 0.5/sqrt(2), atol=1e-6)
56+
@test isapprox(MathProgBase.getobjval(m), sqrt(2), atol=1e-6)
57+
@test isapprox(MathProgBase.getsolution(m)[1], sqrt(2), atol=1e-6)
58+
@test isapprox(MathProgBase.getquadconstrduals(m)[1], 0.5/sqrt(2), atol=1e-6)
5959
end
6060

6161
# min -x
6262
# s.t. x^2 <= 2
6363
@testset "QP2" begin
64-
m = LinearQuadraticModel(solver)
65-
loadproblem!(m, Array{Float64}(0,1), [-Inf], [Inf], [-1.0], Float64[], Float64[], :Min)
66-
addquadconstr!(m, [], [], [1], [1], [1.0], '<', 2.0)
67-
optimize!(m)
68-
stat = status(m)
64+
m = MathProgBase.LinearQuadraticModel(solver)
65+
MathProgBase.loadproblem!(m, Array{Float64}(0,1), [-Inf], [Inf], [-1.0], Float64[], Float64[], :Min)
66+
MathProgBase.addquadconstr!(m, [], [], [1], [1], [1.0], '<', 2.0)
67+
MathProgBase.optimize!(m)
68+
stat = MathProgBase.status(m)
6969

70-
@test numlinconstr(m) == 0
71-
@test numquadconstr(m) == 1
72-
@test numconstr(m) == 1
70+
@test MathProgBase.numlinconstr(m) == 0
71+
@test MathProgBase.numquadconstr(m) == 1
72+
@test MathProgBase.numconstr(m) == 1
7373
@test stat == :Optimal
74-
@test isapprox(getobjval(m), -sqrt(2), atol=1e-6)
75-
@test isapprox(getsolution(m)[1], sqrt(2), atol=1e-6)
76-
@test isapprox(getquadconstrduals(m)[1], -0.5/sqrt(2), atol=1e-6)
74+
@test isapprox(MathProgBase.getobjval(m), -sqrt(2), atol=1e-6)
75+
@test isapprox(MathProgBase.getsolution(m)[1], sqrt(2), atol=1e-6)
76+
@test isapprox(MathProgBase.getquadconstrduals(m)[1], -0.5/sqrt(2), atol=1e-6)
7777
end
7878
end
7979
end
@@ -84,14 +84,14 @@ function socptest(solver)
8484
# s.t. x + y >= 1
8585
# x^2 + y^2 <= t^2
8686
# t >= 0
87-
m = LinearQuadraticModel(solver)
88-
loadproblem!(m, [ 1.0 1.0 0.0 ], [-Inf,-Inf,0.0], [Inf,Inf,Inf], [0.0,0.0,1.0], [1.0],[Inf], :Min)
89-
addquadconstr!(m, [], [], [1,2,3], [1,2,3], [1.0,1.0,-1.0],'<',0.0)
90-
optimize!(m)
91-
stat = status(m)
87+
m = MathProgBase.LinearQuadraticModel(solver)
88+
MathProgBase.loadproblem!(m, [ 1.0 1.0 0.0 ], [-Inf,-Inf,0.0], [Inf,Inf,Inf], [0.0,0.0,1.0], [1.0],[Inf], :Min)
89+
MathProgBase.addquadconstr!(m, [], [], [1,2,3], [1,2,3], [1.0,1.0,-1.0],'<',0.0)
90+
MathProgBase.optimize!(m)
91+
stat = MathProgBase.status(m)
9292

9393
@test stat == :Optimal
94-
@test isapprox(getobjval(m), sqrt(1/2), atol=1e-6)
95-
@test isapprox(norm(getsolution(m) - [0.5,0.5,sqrt(1/2)]), 0.0, atol=1e-3)
94+
@test isapprox(MathProgBase.getobjval(m), sqrt(1/2), atol=1e-6)
95+
@test isapprox(norm(MathProgBase.getsolution(m) - [0.5,0.5,sqrt(1/2)]), 0.0, atol=1e-3)
9696
end
9797
end

0 commit comments

Comments
 (0)