@@ -2,13 +2,6 @@ using Cbc
2
2
using Test
3
3
using LinearAlgebra
4
4
5
- # using Gurobi
6
- # solver = GurobiSolver(OutputFlag=0)
7
-
8
- # using CPLEX
9
- # solver = CplexSolver(CPX_PARAM_SCRIND=0)
10
-
11
-
12
5
import JuMP
13
6
import MathOptInterface
14
7
const MOI = MathOptInterface
@@ -22,58 +15,62 @@ methods_1D = (:CC,:MC,:Logarithmic,:LogarithmicIB,:ZigZag,:ZigZagInteger,:Genera
22
15
methods_2D = (:CC ,:Logarithmic ,:LogarithmicIB ,:ZigZag ,:ZigZagInteger ,:GeneralizedCelaya ,:SymmetricCelaya ,:DisaggLogarithmic )
23
16
patterns_2D = (:Upper ,:Lower ,:BestFit ,:UnionJack ,:K1 ,:Random ) # :OptimalTriangleSelection and :Stencil not supported currently
24
17
25
- println (" \n univariate 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)
31
26
32
- JuMP. optimize! (model)
27
+ JuMP. optimize! (model)
33
28
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
37
32
38
- JuMP. @constraint (model, x ≤ 1.5 z)
33
+ JuMP. @constraint (model, x ≤ 1.5 z)
39
34
40
- JuMP. optimize! (model)
35
+ JuMP. optimize! (model)
41
36
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
47
43
end
48
44
49
- println (" \n bivariate 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
77
74
end
78
75
#
79
76
# println("\nbivariate optimal IB scheme tests")
0 commit comments