Skip to content

Commit e52b08d

Browse files
authored
Merge pull request #970 from scipopt/fix-matrixvar-attributes
Fixed bug when accessing matrix variable attributes
2 parents 57da1a7 + 6065611 commit e52b08d

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Added SCIP_LPPARAM, setIntParam, setRealParam, getIntParam, getRealParam, isOptimal, getObjVal, getRedcost for lpi
77
- Added isFeasPositive
88
### Fixed
9+
- Fixed bug when accessing matrix variable attributes
910
### Changed
1011
### Removed
1112

src/pyscipopt/scip.pxi

+14-14
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ class MatrixVariable(MatrixExpr):
16851685
16861686
"""
16871687
vtypes = np.empty(self.shape, dtype=object)
1688-
for idx in np.ndindex(self):
1688+
for idx in np.ndindex(self.shape):
16891689
vtypes[idx] = self[idx].vtype()
16901690
return vtypes
16911691

@@ -1700,7 +1700,7 @@ class MatrixVariable(MatrixExpr):
17001700
17011701
"""
17021702
in_lp = np.empty(self.shape, dtype=bool)
1703-
for idx in np.ndindex(self):
1703+
for idx in np.ndindex(self.shape):
17041704
in_lp[idx] = self[idx].isInLP()
17051705
return in_lp
17061706

@@ -1715,7 +1715,7 @@ class MatrixVariable(MatrixExpr):
17151715
An array of integers. No two should be the same
17161716
"""
17171717
indices = np.empty(self.shape, dtype=int)
1718-
for idx in np.ndindex(self):
1718+
for idx in np.ndindex(self.shape):
17191719
indices[idx] = self[idx].getIndex()
17201720
return indices
17211721

@@ -1730,7 +1730,7 @@ class MatrixVariable(MatrixExpr):
17301730
"""
17311731

17321732
columns = np.empty(self.shape, dtype=object)
1733-
for idx in np.index(self):
1733+
for idx in np.ndindex(self.shape):
17341734
columns[idx] = self[idx].getCol()
17351735
return columns
17361736

@@ -1744,7 +1744,7 @@ class MatrixVariable(MatrixExpr):
17441744
17451745
"""
17461746
lbs = np.empty(self.shape, dtype=float)
1747-
for idx in np.ndindex(self):
1747+
for idx in np.ndindex(self.shape):
17481748
lbs[idx] = self[idx].getLbOriginal()
17491749
return lbs
17501750

@@ -1758,7 +1758,7 @@ class MatrixVariable(MatrixExpr):
17581758
17591759
"""
17601760
ubs = np.empty(self.shape, dtype=float)
1761-
for idx in np.ndindex(self):
1761+
for idx in np.ndindex(self.shape):
17621762
ubs[idx] = self[idx].getUbOriginal()
17631763
return ubs
17641764

@@ -1772,7 +1772,7 @@ class MatrixVariable(MatrixExpr):
17721772
17731773
"""
17741774
lbs = np.empty(self.shape, dtype=float)
1775-
for idx in np.ndindex(self):
1775+
for idx in np.ndindex(self.shape):
17761776
lbs[idx] = self[idx].getLbGlobal()
17771777
return lbs
17781778

@@ -1786,7 +1786,7 @@ class MatrixVariable(MatrixExpr):
17861786
17871787
"""
17881788
ubs = np.empty(self.shape, dtype=float)
1789-
for idx in np.ndindex(self):
1789+
for idx in np.ndindex(self.shape):
17901790
ubs[idx] = self[idx].getUbGlobal()
17911791
return ubs
17921792

@@ -1800,7 +1800,7 @@ class MatrixVariable(MatrixExpr):
18001800
18011801
"""
18021802
lbs = np.empty(self.shape, dtype=float)
1803-
for idx in np.ndindex(self):
1803+
for idx in np.ndindex(self.shape):
18041804
lbs[idx] = self[idx].getLbLocal()
18051805
return lbs
18061806

@@ -1814,7 +1814,7 @@ class MatrixVariable(MatrixExpr):
18141814
18151815
"""
18161816
ubs = np.empty(self.shape, dtype=float)
1817-
for idx in np.ndindex(self):
1817+
for idx in np.ndindex(self.shape):
18181818
ubs[idx] = self[idx].getUbLocal()
18191819
return ubs
18201820

@@ -1828,7 +1828,7 @@ class MatrixVariable(MatrixExpr):
18281828
18291829
"""
18301830
objs = np.empty(self.shape, dtype=float)
1831-
for idx in np.ndindex(self):
1831+
for idx in np.ndindex(self.shape):
18321832
objs[idx] = self[idx].getObj()
18331833
return objs
18341834

@@ -1842,7 +1842,7 @@ class MatrixVariable(MatrixExpr):
18421842
18431843
"""
18441844
lpsols = np.empty(self.shape, dtype=float)
1845-
for idx in np.ndindex(self):
1845+
for idx in np.ndindex(self.shape):
18461846
lpsols[idx] = self[idx].getLPSol()
18471847
return lpsols
18481848

@@ -1856,7 +1856,7 @@ class MatrixVariable(MatrixExpr):
18561856
18571857
"""
18581858
avgsols = np.empty(self.shape, dtype=float)
1859-
for idx in np.ndindex(self):
1859+
for idx in np.ndindex(self.shape):
18601860
avgsols[idx] = self[idx].getAvgSol()
18611861
return avgsols
18621862

@@ -1876,7 +1876,7 @@ class MatrixVariable(MatrixExpr):
18761876
18771877
"""
18781878
mayround = np.empty(self.shape, dtype=bool)
1879-
for idx in np.ndindex(self):
1879+
for idx in np.ndindex(self.shape):
18801880
mayround[idx] = self[idx].varMayRound()
18811881
return mayround
18821882

tests/test_matrix_variable.py

+16
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,22 @@ def test_documentation():
294294
assert (isinstance(cons, MatrixExprCons))
295295
assert (isinstance(cons[0][0], ExprCons))
296296

297+
def test_MatrixVariable_attributes():
298+
m = Model()
299+
x = m.addMatrixVar(shape=(2,2), vtype='C', name='x', ub=np.array([[5, 6], [2, 8]]), obj=1)
300+
assert x.vtype().tolist() == [['CONTINUOUS', 'CONTINUOUS'], ['CONTINUOUS', 'CONTINUOUS']]
301+
assert x.isInLP().tolist() == [[False, False], [False, False]]
302+
assert x.getIndex().tolist() == [[0, 1], [2, 3]]
303+
assert x.getLbGlobal().tolist() == [[0, 0], [0, 0]]
304+
assert x.getUbGlobal().tolist() == [[5, 6], [2, 8]]
305+
assert x.getObj().tolist() == [[1, 1], [1, 1]]
306+
m.setMaximize()
307+
m.optimize()
308+
assert x.getUbLocal().tolist() == [[5, 6], [2, 8]]
309+
assert x.getLbLocal().tolist() == [[5, 6], [2, 8]]
310+
assert x.getLPSol().tolist() == [[5, 6], [2, 8]]
311+
assert x.getAvgSol().tolist() == [[5, 6], [2, 8]]
312+
assert x.varMayRound().tolist() == [[True, True], [True, True]]
297313

298314
@pytest.mark.skip(reason="Performance test")
299315
def test_performance():

0 commit comments

Comments
 (0)