Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
- Raised an error when an expression is used when a variable is required
- Fixed some compile warnings
### Changed
- MatrixExpr.sum() now supports axis arguments and can return either a scalar or MatrixExpr depending on the result dimensions
- MatrixExpr.sum() now supports axis arguments and can return either a scalar or MatrixExpr, depending on the result dimensions.
- AddMatrixCons also accepts ExprCons.
### Removed

## 5.5.0 - 2025.05.06
Expand Down
21 changes: 13 additions & 8 deletions src/pyscipopt/scip.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
if rc == SCIP_OKAY:
pass
elif rc == SCIP_ERROR:
raise Exception('SCIP: unspecified error!')

Check failure on line 304 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / test-coverage (3.11)

SCIP: unspecified error!
elif rc == SCIP_NOMEMORY:
raise MemoryError('SCIP: insufficient memory error!')
elif rc == SCIP_READERROR:
Expand Down Expand Up @@ -5734,7 +5734,7 @@
return constraints

def addMatrixCons(self,
cons: MatrixExprCons,
cons: Union[ExprCons, MatrixExprCons],
name: Union[str, np.ndarray] ='',
initial: Union[bool, np.ndarray] = True,
separate: Union[bool, np.ndarray] = True,
Expand All @@ -5751,8 +5751,8 @@

Parameters
----------
cons : MatrixExprCons
The matrix expression constraint that is not yet an actual constraint
cons : ExprCons or MatrixExprCons
The matrix expression constraint or expression constraint
name : str or np.ndarray, optional
the name of the matrix constraint, generic name if empty (Default value = "")
initial : bool or np.ndarray, optional
Expand All @@ -5779,12 +5779,17 @@

Returns
-------
MatrixConstraint
The created and added MatrixConstraint object.

Constraint or MatrixConstraint
The created and added Constraint or MatrixConstraint object based on the input.
"""
assert isinstance(cons, MatrixExprCons), (
"given constraint is not MatrixExprCons but %s" % cons.__class__.__name__)
assert isinstance(cons, (ExprCons, MatrixExprCons)), (
"given constraint is not MatrixExprCons nor ExprCons but %s" % cons.__class__.__name__)

if isinstance(cons, ExprCons):
return self.addCons(cons, name=name, initial=initial, separate=separate,
enforce=enforce, check=check, propagate=propagate,
local=local, modifiable=modifiable, dynamic=dynamic,
removable=removable, stickingatnode=stickingatnode)

shape = cons.shape

Expand Down
4 changes: 2 additions & 2 deletions tests/test_matrix_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_catching_errors():
rhs = np.ones((2, 1))

with pytest.raises(Exception):
m.addMatrixCons(x <= 1)
m.addMatrixCons(x)

with pytest.raises(Exception):
m.addCons(y <= 3)
Expand Down Expand Up @@ -169,7 +169,7 @@ def test_matrix_sum_argument():

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

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