/
conictest.jl
140 lines (108 loc) · 5.43 KB
/
conictest.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Copyright 2016, Los Alamos National Laboratory, LANS LLC.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
function runconicdefaulttests(mip_solver_drives)
facts("Default solvers test") do
context("With $(mip_solver_drives ? "BC" : "OA"), defaulting to $(typeof(MathProgBase.defaultMIPsolver)) and $(typeof(MathProgBase.defaultConicsolver))") do
x = Convex.Variable(1,:Int)
problem = Convex.maximize(3x,
x <= 10,
x^2 <= 9)
Convex.solve!(problem, PajaritoSolver(mip_solver_drives=mip_solver_drives,log_level=0))
@fact problem.optval --> roughly(9.0, TOL)
@fact problem.status --> :Optimal
end
end
end
function runconictests(mip_solver_drives, mip_solver, conic_solver)
algorithm = mip_solver_drives ? "BC" : "OA"
facts("Infeasible conic problem") do
context("With $algorithm, $(typeof(mip_solver)) and $(typeof(conic_solver))") do
x = Convex.Variable(1,:Int)
problem = Convex.maximize(3x,
x >= 4,
x^2 <= 9)
Convex.solve!(problem, PajaritoSolver(mip_solver_drives=mip_solver_drives, mip_solver=mip_solver, cont_solver=conic_solver,log_level=0))
@fact problem.status --> :Infeasible
end
end
facts("Univariate maximization problem") do
context("With $algorithm, $(typeof(mip_solver)) and $(typeof(conic_solver))") do
x = Convex.Variable(1,:Int)
problem = Convex.maximize(3x,
x <= 10,
x^2 <= 9)
Convex.solve!(problem, PajaritoSolver(mip_solver_drives=mip_solver_drives, mip_solver=mip_solver, cont_solver=conic_solver,log_level=0))
@fact problem.optval --> roughly(9.0, TOL)
@fact problem.status --> :Optimal
end
end
facts("Continuous problem") do
context("With $algorithm, $(typeof(mip_solver)) and $(typeof(conic_solver))") do
x = Convex.Variable(1)
y = Convex.Variable(1, Convex.Positive())
problem = Convex.maximize(3x + y,
x >= 0,
3x + 2y <= 10,
exp(x) <= 10)
@fact_throws ErrorException Convex.solve!(problem, PajaritoSolver(mip_solver_drives=mip_solver_drives, mip_solver=mip_solver, cont_solver=conic_solver,log_level=0))
end
end
facts("Maximization problem") do
context("With $algorithm, $(typeof(mip_solver)) and $(typeof(conic_solver))") do
x = Convex.Variable(1,:Int)
y = Convex.Variable(1, Convex.Positive())
problem = Convex.maximize(3x + y,
x >= 0,
3x + 2y <= 10,
exp(x) <= 10)
Convex.solve!(problem, PajaritoSolver(mip_solver_drives=mip_solver_drives, mip_solver=mip_solver, cont_solver=conic_solver,log_level=0))
@fact problem.optval --> roughly(8.0, TOL)
@fact problem.status --> :Optimal
end
end
facts("Solver test") do
context("With $algorithm, $(typeof(mip_solver)) and $(typeof(conic_solver))") do
x = Convex.Variable(1,:Int)
y = Convex.Variable(1)
problem = Convex.minimize(-3x - y,
x >= 1,
y >= 0,
3x + 2y <= 10,
x^2 <= 5,
exp(y) + x <= 7)
Convex.solve!(problem, PajaritoSolver(mip_solver_drives=mip_solver_drives, mip_solver=mip_solver, cont_solver=conic_solver,log_level=0))
@fact problem.status --> :Optimal
@fact Convex.evaluate(x) --> roughly(2.0, TOL)
end
end
facts("No SOC disaggregation test") do
context("With $algorithm, $(typeof(mip_solver)) and $(typeof(conic_solver))") do
x = Convex.Variable(1,:Int)
y = Convex.Variable(1)
problem = Convex.minimize(-3x - y,
x >= 1,
y >= 0,
3x + 2y <= 10,
x^2 <= 5,
exp(y) + x <= 7)
Convex.solve!(problem, PajaritoSolver(mip_solver_drives=mip_solver_drives, disagg_soc=false, mip_solver=mip_solver, cont_solver=conic_solver,log_level=0))
@fact problem.status --> :Optimal
@fact Convex.evaluate(x) --> roughly(2.0, TOL)
end
end
facts("Solver test 2") do
context("With $algorithm, $(typeof(mip_solver)) and $(typeof(conic_solver))") do
x = Convex.Variable(1,:Int)
y = Convex.Variable(1, Convex.Positive())
problem = Convex.minimize(-3x - y,
x >= 1,
3x + 2y <= 30,
exp(y^2) + x <= 7)
Convex.solve!(problem, PajaritoSolver(mip_solver_drives=mip_solver_drives, mip_solver=mip_solver, cont_solver=conic_solver,log_level=0,rel_gap=1e-4))
@fact problem.status --> :Optimal
@fact Convex.evaluate(x) --> roughly(6.0, TOL)
end
end
end