Skip to content

Commit 8fc900c

Browse files
Merge branch 'master' into fix/1043
2 parents 5580e12 + 8267aa4 commit 8fc900c

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
- Fixed some compile warnings
2020
- _VarArray can accept MatrixVariable now
2121
### Changed
22-
- MatrixExpr.sum() now supports axis arguments and can return either a scalar or MatrixExpr depending on the result dimensions
22+
- MatrixExpr.sum() now supports axis arguments and can return either a scalar or MatrixExpr, depending on the result dimensions.
23+
- AddMatrixCons() also accepts ExprCons.
2324
### Removed
2425

2526
## 5.5.0 - 2025.05.06

src/pyscipopt/scip.pxi

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5772,7 +5772,7 @@ cdef class Model:
57725772
return constraints
57735773

57745774
def addMatrixCons(self,
5775-
cons: MatrixExprCons,
5775+
cons: Union[ExprCons, MatrixExprCons],
57765776
name: Union[str, np.ndarray] ='',
57775777
initial: Union[bool, np.ndarray] = True,
57785778
separate: Union[bool, np.ndarray] = True,
@@ -5789,8 +5789,8 @@ cdef class Model:
57895789
57905790
Parameters
57915791
----------
5792-
cons : MatrixExprCons
5793-
The matrix expression constraint that is not yet an actual constraint
5792+
cons : ExprCons or MatrixExprCons
5793+
The matrix expression constraint or expression constraint, that are not yet an actual constraint
57945794
name : str or np.ndarray, optional
57955795
the name of the matrix constraint, generic name if empty (Default value = "")
57965796
initial : bool or np.ndarray, optional
@@ -5817,12 +5817,17 @@ cdef class Model:
58175817
58185818
Returns
58195819
-------
5820-
MatrixConstraint
5821-
The created and added MatrixConstraint object.
5822-
5820+
Constraint or MatrixConstraint
5821+
The created and added Constraint or MatrixConstraint.
58235822
"""
5824-
assert isinstance(cons, MatrixExprCons), (
5825-
"given constraint is not MatrixExprCons but %s" % cons.__class__.__name__)
5823+
if not isinstance(cons, (ExprCons, MatrixExprCons)):
5824+
raise TypeError("given constraint is not MatrixExprCons nor ExprCons but %s" % cons.__class__.__name__)
5825+
5826+
if isinstance(cons, ExprCons):
5827+
return self.addCons(cons, name=name, initial=initial, separate=separate,
5828+
enforce=enforce, check=check, propagate=propagate,
5829+
local=local, modifiable=modifiable, dynamic=dynamic,
5830+
removable=removable, stickingatnode=stickingatnode)
58265831

58275832
shape = cons.shape
58285833

tests/test_matrix_variable.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ def test_catching_errors():
1515
y = m.addMatrixVar(shape=(3, 3))
1616
rhs = np.ones((2, 1))
1717

18+
# require ExprCons
1819
with pytest.raises(Exception):
19-
m.addMatrixCons(x <= 1)
20+
m.addCons(y <= 3)
2021

22+
# require MatrixExprCons or ExprCons
2123
with pytest.raises(Exception):
22-
m.addCons(y <= 3)
24+
m.addMatrixCons(x)
2325

26+
# test shape mismatch
2427
with pytest.raises(Exception):
2528
m.addMatrixCons(y <= rhs)
2629

@@ -169,7 +172,7 @@ def test_matrix_sum_argument():
169172

170173
# compare the result of summing 2d array to a scalar with a scalar
171174
x = m.addMatrixVar((2, 3), "x", "I", ub=4)
172-
m.addCons(x.sum() == 24)
175+
m.addMatrixCons(x.sum() == 24)
173176

174177
# compare the result of summing 2d array to 1d array
175178
y = m.addMatrixVar((2, 4), "y", "I", ub=4)

0 commit comments

Comments
 (0)