Skip to content

Commit

Permalink
Add getLinearConsIndicator (#961)
Browse files Browse the repository at this point in the history
* Add getLinearConsIndicator

* Add check for NULL return

* Update return type
  • Loading branch information
Opt-Mucca authored Mar 6, 2025
1 parent 1ad2f8e commit a230bd0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
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 @@ -6229,6 +6229,25 @@ cdef class Model:
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 @@ cdef class Model:
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

0 comments on commit a230bd0

Please sign in to comment.