From 4072d0b8f43a784d7921b59f41e7867bcd34d62b Mon Sep 17 00:00:00 2001 From: Adam Jemielita Date: Wed, 11 Nov 2026 11:59:41 +0100 Subject: [PATCH] fix varMayRound and add a regression test --- CHANGELOG.md | 1 + src/pyscipopt/scip.pxi | 2 +- tests/test_matrix_variable.py | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8cf9fe0b..fa5abc167 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Added tests for `getObjVal()` and `getVal()` - Added `addConsLinear()` to add linear constraints from variables and coefficients without building an expression ### Fixed +- Fixed `MatrixVariable.varMayRound()` rounding direction - Fixed `lotsizing_lazy` example: lock the handler's variables in `conslock` so presolve cannot aggregate them away (#1252) - Dual and Farkas getters for linear, knapsack, and logicor constraints now return zero when presolving has removed them. - Fixed incorrect `getObjVal()` result when called before `getBestSol()` (e.g., in event handlers). diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index 2fffa2dd2..841eed6c7 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -2186,7 +2186,7 @@ class MatrixVariable(MatrixExpr): """ mayround = np.empty(self.shape, dtype=bool) for idx in np.ndindex(self.shape): - mayround[idx] = self[idx].varMayRound() + mayround[idx] = self[idx].varMayRound(direction) return mayround cdef class Constraint: diff --git a/tests/test_matrix_variable.py b/tests/test_matrix_variable.py index 5a8d450b3..0aa022e29 100644 --- a/tests/test_matrix_variable.py +++ b/tests/test_matrix_variable.py @@ -481,6 +481,20 @@ def test_MatrixVariable_attributes(): assert x.getAvgSol().tolist() == [[5, 6], [2, 8]] assert x.varMayRound().tolist() == [[True, True], [True, True]] + +def test_matrix_var_may_round_direction(): + m = Model() + x = m.addMatrixVar((2,), vtype="I") + # downward rounding is blocked; upward rounding is allowed + m.addVarLocks(x[0], nlocksdown=1, nlocksup=0) + # downward rounding is allowed; upward rounding is blocked + m.addVarLocks(x[1], nlocksdown=0, nlocksup=1) + + assert x.varMayRound().tolist() == [False, True] + assert x.varMayRound("down").tolist() == [False, True] + assert x.varMayRound("up").tolist() == [True, False] + + @pytest.mark.skip(reason="Performance test") def test_add_cons_performance(): start_orig = time()