@@ -42,6 +42,23 @@ def test_linear_model(self):
42
42
self .assertTrue (np .all (repn .c == np .array ([0 , 0 , 0 ])))
43
43
self .assertTrue (np .all (repn .A == np .array ([[- 1 , - 2 , 0 ], [0 , 1 , 4 ]])))
44
44
self .assertTrue (np .all (repn .rhs == np .array ([- 3 , 5 ])))
45
+ self .assertEqual (repn .rows , [(m .c , - 1 ), (m .d , 1 )])
46
+ self .assertEqual (repn .columns , [m .x , m .y [1 ], m .y [3 ]])
47
+
48
+ def test_almost_dense_linear_model (self ):
49
+ m = pyo .ConcreteModel ()
50
+ m .x = pyo .Var ()
51
+ m .y = pyo .Var ([1 , 2 , 3 ])
52
+ m .c = pyo .Constraint (expr = m .x + 2 * m .y [1 ] + 4 * m .y [3 ] >= 10 )
53
+ m .d = pyo .Constraint (expr = 5 * m .x + 6 * m .y [1 ] + 8 * m .y [3 ] <= 20 )
54
+
55
+ repn = LinearStandardFormCompiler ().write (m )
56
+
57
+ self .assertTrue (np .all (repn .c == np .array ([0 , 0 , 0 ])))
58
+ self .assertTrue (np .all (repn .A == np .array ([[- 1 , - 2 , - 4 ], [5 , 6 , 8 ]])))
59
+ self .assertTrue (np .all (repn .rhs == np .array ([- 10 , 20 ])))
60
+ self .assertEqual (repn .rows , [(m .c , - 1 ), (m .d , 1 )])
61
+ self .assertEqual (repn .columns , [m .x , m .y [1 ], m .y [3 ]])
45
62
46
63
def test_linear_model_row_col_order (self ):
47
64
m = pyo .ConcreteModel ()
@@ -57,6 +74,8 @@ def test_linear_model_row_col_order(self):
57
74
self .assertTrue (np .all (repn .c == np .array ([0 , 0 , 0 ])))
58
75
self .assertTrue (np .all (repn .A == np .array ([[4 , 0 , 1 ], [0 , - 1 , - 2 ]])))
59
76
self .assertTrue (np .all (repn .rhs == np .array ([5 , - 3 ])))
77
+ self .assertEqual (repn .rows , [(m .d , 1 ), (m .c , - 1 )])
78
+ self .assertEqual (repn .columns , [m .y [3 ], m .x , m .y [1 ]])
60
79
61
80
def test_suffix_warning (self ):
62
81
m = pyo .ConcreteModel ()
@@ -222,6 +241,28 @@ def test_alternative_forms(self):
222
241
)
223
242
self ._verify_solution (soln , repn , True )
224
243
244
+ repn = LinearStandardFormCompiler ().write (
245
+ m , mixed_form = True , column_order = col_order
246
+ )
247
+
248
+ self .assertEqual (
249
+ repn .rows , [(m .c , - 1 ), (m .d , 1 ), (m .e , 1 ), (m .e , - 1 ), (m .f , 0 )]
250
+ )
251
+ self .assertEqual (list (map (str , repn .x )), ['x' , 'y[0]' , 'y[1]' , 'y[3]' ])
252
+ self .assertEqual (
253
+ list (v .bounds for v in repn .x ), [(None , None ), (0 , 10 ), (- 5 , 10 ), (- 5 , - 2 )]
254
+ )
255
+ ref = np .array (
256
+ [[1 , 0 , 2 , 0 ], [0 , 0 , 1 , 4 ], [0 , 1 , 6 , 0 ], [0 , 1 , 6 , 0 ], [1 , 1 , 0 , 0 ]]
257
+ )
258
+ self .assertTrue (np .all (repn .A == ref ))
259
+ self .assertTrue (np .all (repn .b == np .array ([3 , 5 , 6 , - 3 , 8 ])))
260
+ self .assertTrue (np .all (repn .c == np .array ([[- 1 , 0 , - 5 , 0 ], [1 , 0 , 0 , 15 ]])))
261
+ # Note that the mixed_form solution is a mix of inequality and
262
+ # equality constraints, so we cannot (easily) reuse the
263
+ # _verify_solutions helper (as in the above cases):
264
+ # self._verify_solution(soln, repn, False)
265
+
225
266
repn = LinearStandardFormCompiler ().write (
226
267
m , slack_form = True , nonnegative_vars = True , column_order = col_order
227
268
)
0 commit comments