Skip to content

Commit 9c45c7a

Browse files
committed
Add more complex test cases
1 parent 1f257bb commit 9c45c7a

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

tests/test_matrix_variable.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,26 @@ def test_expr_from_matrix_vars():
167167
def test_matrix_sum_argument():
168168
m = Model()
169169

170-
# sum with 2d array
171-
x = m.addMatrixVar((2, 3), "x", "I", ub=10)
172-
m.addMatrixCons(x.sum(axis=1) == np.zeros(2))
173-
174-
# sum with 3d array, set axis=2
175-
y = m.addMatrixVar((2, 3, 4), "y", "I", ub=10)
176-
m.addMatrixCons(y.sum(axis=2) == np.zeros((2, 3)))
177-
178-
m.setObjective(x.sum() + y.sum(), "maximize")
170+
# compare the result of summing 2d array to a scaler with a scaler
171+
x = m.addMatrixVar((2, 3), "x", "I", ub=4)
172+
m.addMatrixCons(x.sum() == 24)
173+
# to fix the element values
174+
m.addMatrixCons(x == np.full((2, 3), 4))
175+
176+
# compare the result of summing 2d array to 1d array
177+
y = m.addMatrixVar((2, 4), "y", "I", ub=4)
178+
m.addMatrixCons(x.sum(axis=1) == y.sum(axis=1))
179+
180+
# compare the result of summing 3d array to a 2d array with a 2d array
181+
z = m.addMatrixVar((2, 3, 4), "y", "I", ub=4)
182+
m.addMatrixCons(z.sum(axis=2) == x)
183+
m.addMatrixCons(z.sum(axis=1) == y)
184+
185+
m.setObjective(x.sum() + y.sum() + z.sum(), "maximize")
179186
m.optimize()
180187

181-
assert (m.getVal(x) == np.zeros((2, 3))).all().all()
182-
assert (m.getVal(y) == np.zeros((2, 3, 4))).all().all().all()
188+
assert (m.getVal(y) == np.full((2, 4), 3)).all().all()
189+
assert (m.getVal(z) == np.ones((2, 3, 4))).all().all().all()
183190

184191
def test_add_cons_matrixVar():
185192
m = Model()

0 commit comments

Comments
 (0)