Skip to content

Commit dafcffb

Browse files
authored
Fix test depreciations (#44)
* Update compat * Fix test depreciations
1 parent 96808b5 commit dafcffb

File tree

2 files changed

+51
-54
lines changed

2 files changed

+51
-54
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1111

1212
[compat]
1313
Cbc = "≥ 0.6.0"
14-
JuMP = "~0.19, ~0.20, 0.21"
15-
MathOptInterface = "~0.8, ~0.9"
14+
JuMP = "~0.22"
15+
MathOptInterface = "~0.10"
1616
julia = "1"
1717

1818
[extras]

test/runtests.jl

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ using Cbc
22
using Test
33
using LinearAlgebra
44

5-
# using Gurobi
6-
# solver = GurobiSolver(OutputFlag=0)
7-
8-
# using CPLEX
9-
# solver = CplexSolver(CPX_PARAM_SCRIND=0)
10-
11-
125
import JuMP
136
import MathOptInterface
147
const MOI = MathOptInterface
@@ -22,58 +15,62 @@ methods_1D = (:CC,:MC,:Logarithmic,:LogarithmicIB,:ZigZag,:ZigZagInteger,:Genera
2215
methods_2D = (:CC,:Logarithmic,:LogarithmicIB,:ZigZag,:ZigZagInteger,:GeneralizedCelaya,:SymmetricCelaya,:DisaggLogarithmic)
2316
patterns_2D = (:Upper,:Lower,:BestFit,:UnionJack,:K1,:Random) # :OptimalTriangleSelection and :Stencil not supported currently
2417

25-
println("\nunivariate tests")
26-
@testset "1D: $method" for method in methods_1D
27-
model = JuMP.Model(JuMP.with_optimizer(Cbc.Optimizer))
28-
JuMP.@variable(model, x)
29-
z = piecewiselinear(model, x, range(1,stop=2π, length=8), sin, method=method)
30-
JuMP.@objective(model, Max, z)
18+
optimizer=JuMP.optimizer_with_attributes(Cbc.Optimizer, MOI.Silent() => true)
19+
20+
@testset "Univariate tests" begin
21+
@testset "1D: $method" for method in methods_1D
22+
model = JuMP.Model(optimizer)
23+
JuMP.@variable(model, x)
24+
z = piecewiselinear(model, x, range(1,stop=2π, length=8), sin, method=method)
25+
JuMP.@objective(model, Max, z)
3126

32-
JuMP.optimize!(model)
27+
JuMP.optimize!(model)
3328

34-
@test JuMP.termination_status(model) == MOI.OPTIMAL
35-
@test JuMP.value(x) 1.75474 rtol=1e-4
36-
@test JuMP.value(z) 0.98313 rtol=1e-4
29+
@test JuMP.termination_status(model) == MOI.OPTIMAL
30+
@test JuMP.value(x) 1.75474 rtol=1e-4
31+
@test JuMP.value(z) 0.98313 rtol=1e-4
3732

38-
JuMP.@constraint(model, x 1.5z)
33+
JuMP.@constraint(model, x 1.5z)
3934

40-
JuMP.optimize!(model)
35+
JuMP.optimize!(model)
4136

42-
@test JuMP.termination_status(model) == MOI.OPTIMAL
43-
@test JuMP.value(x) 1.36495 rtol=1e-4
44-
@test JuMP.value(z) 0.90997 rtol=1e-4
45-
@test JuMP.objective_value(model) 0.90997 rtol=1e-4
46-
@test JuMP.objective_value(model) JuMP.value(z) rtol=1e-4
37+
@test JuMP.termination_status(model) == MOI.OPTIMAL
38+
@test JuMP.value(x) 1.36495 rtol=1e-4
39+
@test JuMP.value(z) 0.90997 rtol=1e-4
40+
@test JuMP.objective_value(model) 0.90997 rtol=1e-4
41+
@test JuMP.objective_value(model) JuMP.value(z) rtol=1e-4
42+
end
4743
end
4844

49-
println("\nbivariate tests")
50-
@testset "2D: $method, $pattern" for method in methods_2D, pattern in patterns_2D
51-
model = JuMP.Model(JuMP.with_optimizer(Cbc.Optimizer))
52-
JuMP.@variable(model, x[1:2])
53-
d = range(0,stop=1,length=8)
54-
f = (x1,x2) -> 2*(x1-1/3)^2 + 3*(x2-4/7)^4
55-
z = piecewiselinear(model, x[1], x[2], BivariatePWLFunction(d, d, f, pattern=pattern), method=method)
56-
JuMP.@objective(model, Min, z)
57-
58-
JuMP.optimize!(model)
59-
60-
@test JuMP.termination_status(model) == MOI.OPTIMAL
61-
@test JuMP.value(x[1]) 0.285714 rtol=1e-4
62-
@test JuMP.value(x[2]) 0.571429 rtol=1e-4
63-
@test JuMP.value(z) 0.004535 rtol=1e-3
64-
@test JuMP.objective_value(model) 0.004535 rtol=1e-3
65-
@test JuMP.objective_value(model) JuMP.value(z) rtol=1e-3
66-
67-
JuMP.@constraint(model, x[1] 0.6)
68-
69-
JuMP.optimize!(model)
70-
71-
@test JuMP.termination_status(model) == MOI.OPTIMAL
72-
@test JuMP.value(x[1]) 0.6 rtol=1e-4
73-
@test JuMP.value(x[2]) 0.571428 rtol=1e-4
74-
@test JuMP.value(z) 0.148753 rtol=1e-4
75-
@test JuMP.objective_value(model) 0.148753 rtol=1e-3
76-
@test JuMP.objective_value(model) JuMP.value(z) rtol=1e-3
45+
@testset "Bivariate tests " begin
46+
@testset "2D: $method, $pattern" for method in methods_2D, pattern in patterns_2D
47+
model = JuMP.Model(optimizer)
48+
JuMP.@variable(model, x[1:2])
49+
d = range(0,stop=1,length=8)
50+
f = (x1,x2) -> 2*(x1-1/3)^2 + 3*(x2-4/7)^4
51+
z = piecewiselinear(model, x[1], x[2], BivariatePWLFunction(d, d, f, pattern=pattern), method=method)
52+
JuMP.@objective(model, Min, z)
53+
54+
JuMP.optimize!(model)
55+
56+
@test JuMP.termination_status(model) == MOI.OPTIMAL
57+
@test JuMP.value(x[1]) 0.285714 rtol=1e-4
58+
@test JuMP.value(x[2]) 0.571429 rtol=1e-4
59+
@test JuMP.value(z) 0.004535 rtol=1e-3
60+
@test JuMP.objective_value(model) 0.004535 rtol=1e-3
61+
@test JuMP.objective_value(model) JuMP.value(z) rtol=1e-3
62+
63+
JuMP.@constraint(model, x[1] 0.6)
64+
65+
JuMP.optimize!(model)
66+
67+
@test JuMP.termination_status(model) == MOI.OPTIMAL
68+
@test JuMP.value(x[1]) 0.6 rtol=1e-4
69+
@test JuMP.value(x[2]) 0.571428 rtol=1e-4
70+
@test JuMP.value(z) 0.148753 rtol=1e-4
71+
@test JuMP.objective_value(model) 0.148753 rtol=1e-3
72+
@test JuMP.objective_value(model) JuMP.value(z) rtol=1e-3
73+
end
7774
end
7875
#
7976
# println("\nbivariate optimal IB scheme tests")

0 commit comments

Comments
 (0)