9
9
# This software is distributed under the 3-clause BSD License.
10
10
# ___________________________________________________________________________
11
11
12
- from pyomo .common .dependencies import numpy as numpy , numpy_available
13
-
14
- if numpy_available :
15
- from numpy .testing import assert_array_almost_equal
16
- from pyomo .common .dependencies import attempt_import
17
-
18
- gurobipy , gurobipy_available = attempt_import ("gurobipy" )
19
-
20
12
from collections import Counter
21
13
22
- import pyomo .environ as pe
14
+ from pyomo .common . dependencies import numpy as np , numpy_available
23
15
from pyomo .common import unittest
24
-
25
16
from pyomo .contrib .alternative_solutions import gurobi_generate_solutions
17
+ from pyomo .contrib .appsi .solvers import Gurobi
18
+
26
19
import pyomo .contrib .alternative_solutions .tests .test_cases as tc
20
+ import pyomo .environ as pe
21
+
22
+ gurobipy_available = Gurobi ().available ()
27
23
28
24
29
25
@unittest .skipIf (not gurobipy_available , "Gurobi MIP solver not available" )
@@ -51,7 +47,7 @@ def test_ip_feasibility(self):
51
47
objectives = [round (result .objective [1 ], 2 ) for result in results ]
52
48
actual_solns_by_obj = m .num_ranked_solns
53
49
unique_solns_by_obj = [val for val in Counter (objectives ).values ()]
54
- assert_array_almost_equal (unique_solns_by_obj , actual_solns_by_obj )
50
+ np . testing . assert_array_almost_equal (unique_solns_by_obj , actual_solns_by_obj )
55
51
56
52
@unittest .skipIf (not numpy_available , "Numpy not installed" )
57
53
def test_ip_num_solutions (self ):
@@ -66,7 +62,7 @@ def test_ip_num_solutions(self):
66
62
objectives = [round (result .objective [1 ], 2 ) for result in results ]
67
63
actual_solns_by_obj = [6 , 2 ]
68
64
unique_solns_by_obj = [val for val in Counter (objectives ).values ()]
69
- assert_array_almost_equal (unique_solns_by_obj , actual_solns_by_obj )
65
+ np . testing . assert_array_almost_equal (unique_solns_by_obj , actual_solns_by_obj )
70
66
71
67
@unittest .skipIf (not numpy_available , "Numpy not installed" )
72
68
def test_mip_feasibility (self ):
@@ -80,7 +76,7 @@ def test_mip_feasibility(self):
80
76
objectives = [round (result .objective [1 ], 2 ) for result in results ]
81
77
actual_solns_by_obj = m .num_ranked_solns
82
78
unique_solns_by_obj = [val for val in Counter (objectives ).values ()]
83
- assert_array_almost_equal (unique_solns_by_obj , actual_solns_by_obj )
79
+ np . testing . assert_array_almost_equal (unique_solns_by_obj , actual_solns_by_obj )
84
80
85
81
@unittest .skipIf (not numpy_available , "Numpy not installed" )
86
82
def test_mip_rel_feasibility (self ):
@@ -95,7 +91,7 @@ def test_mip_rel_feasibility(self):
95
91
objectives = [round (result .objective [1 ], 2 ) for result in results ]
96
92
actual_solns_by_obj = m .num_ranked_solns [0 :2 ]
97
93
unique_solns_by_obj = [val for val in Counter (objectives ).values ()]
98
- assert_array_almost_equal (unique_solns_by_obj , actual_solns_by_obj )
94
+ np . testing . assert_array_almost_equal (unique_solns_by_obj , actual_solns_by_obj )
99
95
100
96
@unittest .skipIf (not numpy_available , "Numpy not installed" )
101
97
def test_mip_rel_feasibility_options (self ):
@@ -112,7 +108,7 @@ def test_mip_rel_feasibility_options(self):
112
108
objectives = [round (result .objective [1 ], 2 ) for result in results ]
113
109
actual_solns_by_obj = m .num_ranked_solns [0 :2 ]
114
110
unique_solns_by_obj = [val for val in Counter (objectives ).values ()]
115
- assert_array_almost_equal (unique_solns_by_obj , actual_solns_by_obj )
111
+ np . testing . assert_array_almost_equal (unique_solns_by_obj , actual_solns_by_obj )
116
112
117
113
@unittest .skipIf (not numpy_available , "Numpy not installed" )
118
114
def test_mip_abs_feasibility (self ):
@@ -127,7 +123,7 @@ def test_mip_abs_feasibility(self):
127
123
objectives = [round (result .objective [1 ], 2 ) for result in results ]
128
124
actual_solns_by_obj = m .num_ranked_solns [0 :3 ]
129
125
unique_solns_by_obj = [val for val in Counter (objectives ).values ()]
130
- assert_array_almost_equal (unique_solns_by_obj , actual_solns_by_obj )
126
+ np . testing . assert_array_almost_equal (unique_solns_by_obj , actual_solns_by_obj )
131
127
132
128
@unittest .skipIf (True , "Ignoring fragile test for solver timeout." )
133
129
def test_mip_no_time (self ):
0 commit comments