1
- using Base. Test
1
+ using Compat. Test
2
+ using Compat. LinearAlgebra
2
3
using MathProgBase
3
- using MathProgBase. SolverInterface
4
4
5
5
function quadprogtest (solver)
6
6
@testset " Testing quadprog with $solver " begin
@@ -10,30 +10,30 @@ function quadprogtest(solver)
10
10
@test isapprox (norm (sol. sol[1 : 3 ] - [0.5714285714285715 ,0.4285714285714285 ,0.8571428571428572 ]), 0.0 , atol= 1e-6 )
11
11
12
12
@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 )
15
15
16
- setquadobj! (m,diagm ([10.0 ,10.0 ,10.0 ]))
16
+ MathProgBase . setquadobj! (m,diagm ([10.0 ,10.0 ,10.0 ]))
17
17
rows = [1 , 2 , 2 , 2 , 3 , 3 , 3 ]
18
18
cols = [1 , 1 , 1 , 2 , 2 , 3 , 3 ]
19
19
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)
23
23
@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 )
26
26
end
27
27
28
28
@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)
34
34
@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 )
37
37
end
38
38
end
39
39
end
@@ -43,37 +43,37 @@ function qpdualtest(solver)
43
43
# max x
44
44
# s.t. x^2 <= 2
45
45
@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)
51
51
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
55
55
@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 )
59
59
end
60
60
61
61
# min -x
62
62
# s.t. x^2 <= 2
63
63
@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)
69
69
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
73
73
@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 )
77
77
end
78
78
end
79
79
end
@@ -84,14 +84,14 @@ function socptest(solver)
84
84
# s.t. x + y >= 1
85
85
# x^2 + y^2 <= t^2
86
86
# 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)
92
92
93
93
@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 )
96
96
end
97
97
end
0 commit comments