Skip to content

Commit a230bd0

Browse files
authored
Add getLinearConsIndicator (#961)
* Add getLinearConsIndicator * Add check for NULL return * Update return type
1 parent 1ad2f8e commit a230bd0

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
### Added
5+
- Added getLinearConsIndicator
56
### Fixed
67
### Changed
78
### Removed

src/pyscipopt/scip.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,7 @@ cdef extern from "scip/cons_indicator.h":
18281828
SCIP_Real val)
18291829

18301830
SCIP_VAR* SCIPgetSlackVarIndicator(SCIP_CONS* cons)
1831+
SCIP_CONS* SCIPgetLinearConsIndicator(SCIP_CONS* cons)
18311832

18321833
cdef extern from "scip/misc.h":
18331834
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP** hashmap, BMS_BLKMEM* blkmem, int mapsize)

src/pyscipopt/scip.pxi

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6229,6 +6229,25 @@ cdef class Model:
62296229
PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons))
62306230

62316231
return pyCons
6232+
6233+
def getLinearConsIndicator(self, Constraint cons):
6234+
"""
6235+
Get the linear constraint corresponding to the indicator constraint.
6236+
6237+
Parameters
6238+
----------
6239+
cons : Constraint
6240+
The indicator constraint
6241+
6242+
Returns
6243+
-------
6244+
Constraint or None
6245+
"""
6246+
6247+
cdef SCIP_CONS* lincons = SCIPgetLinearConsIndicator(cons.scip_cons)
6248+
if lincons == NULL:
6249+
return None
6250+
return Constraint.create(lincons)
62326251

62336252
def getSlackVarIndicator(self, Constraint cons):
62346253
"""
@@ -6245,7 +6264,7 @@ cdef class Model:
62456264
Variable
62466265
62476266
"""
6248-
cdef SCIP_VAR* var = SCIPgetSlackVarIndicator(cons.scip_cons);
6267+
cdef SCIP_VAR* var = SCIPgetSlackVarIndicator(cons.scip_cons)
62496268
return Variable.create(var)
62506269

62516270
def addPyCons(self, Constraint cons):

tests/test_cons.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def test_cons_indicator():
118118

119119
slack = m.getSlackVarIndicator(c1)
120120

121+
lin_cons = m.getLinearConsIndicator(c1)
122+
121123
m.optimize()
122124

123125
assert m.getNConss(transformed=False) == 5

0 commit comments

Comments
 (0)