Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
### Added
- Added getLinearConsIndicator
### Fixed
### Changed
### Removed
Expand Down
1 change: 1 addition & 0 deletions src/pyscipopt/scip.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,7 @@ cdef extern from "scip/cons_indicator.h":
SCIP_Real val)

SCIP_VAR* SCIPgetSlackVarIndicator(SCIP_CONS* cons)
SCIP_CONS* SCIPgetLinearConsIndicator(SCIP_CONS* cons)

cdef extern from "scip/misc.h":
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP** hashmap, BMS_BLKMEM* blkmem, int mapsize)
Expand Down
21 changes: 20 additions & 1 deletion src/pyscipopt/scip.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
if rc == SCIP_OKAY:
pass
elif rc == SCIP_ERROR:
raise Exception('SCIP: unspecified error!')

Check failure on line 279 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 @@ -6229,6 +6229,25 @@
PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons))

return pyCons

def getLinearConsIndicator(self, Constraint cons):
"""
Get the linear constraint corresponding to the indicator constraint.

Parameters
----------
cons : Constraint
The indicator constraint

Returns
-------
Constraint or None
"""

cdef SCIP_CONS* lincons = SCIPgetLinearConsIndicator(cons.scip_cons)
if lincons == NULL:
return None
return Constraint.create(lincons)

def getSlackVarIndicator(self, Constraint cons):
"""
Expand All @@ -6245,7 +6264,7 @@
Variable

"""
cdef SCIP_VAR* var = SCIPgetSlackVarIndicator(cons.scip_cons);
cdef SCIP_VAR* var = SCIPgetSlackVarIndicator(cons.scip_cons)
return Variable.create(var)

def addPyCons(self, Constraint cons):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cons.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def test_cons_indicator():

slack = m.getSlackVarIndicator(c1)

lin_cons = m.getLinearConsIndicator(c1)

m.optimize()

assert m.getNConss(transformed=False) == 5
Expand Down
Loading