Skip to content

Commit

Permalink
Merge pull request #764 from scipopt/mt/add_getconshdlrname
Browse files Browse the repository at this point in the history
Mt/add getconshdlrname
  • Loading branch information
mmghannam authored Dec 8, 2023
2 parents 0b6bb13 + 95d5245 commit 2321839
Show file tree
Hide file tree
Showing 3 changed files with 10 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
- Add getConshdlrName to class Constraint
### Fixed
### Changed
### Removed
Expand Down
7 changes: 6 additions & 1 deletion src/pyscipopt/scip.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,11 @@ cdef class Constraint:
constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(self.scip_cons))).decode('UTF-8')
return constype == 'nonlinear'

def getConshdlrName(self):
"""Return the constraint handler's name"""
constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(self.scip_cons))).decode('UTF-8')
return constype

def __hash__(self):
return hash(<size_t>self.scip_cons)

Expand Down Expand Up @@ -5142,4 +5147,4 @@ def is_memory_freed():
return BMSgetMemoryUsed() == 0

def print_memory_in_use():
BMScheckEmptyMemory()
BMScheckEmptyMemory()
3 changes: 3 additions & 0 deletions tests/test_cons.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def test_SOScons():
assert m.isEQ(m.getVal(x[3]), 1)
assert m.isEQ(m.getVal(x[4]), 1)
assert m.isEQ(m.getVal(x[5]), 1)
assert c1.getConshdlrName() == "SOS1"
assert c2.getConshdlrName() == "SOS2"


def test_cons_indicator():
Expand All @@ -112,6 +114,7 @@ def test_cons_indicator():
assert m.isEQ(m.getVal(slack), 0)
assert m.isEQ(m.getVal(binvar), 1)
assert m.isEQ(m.getVal(x), 1)
assert c.getConshdlrName() == "indicator"


@pytest.mark.xfail(reason="addConsIndicator doesn't behave as expected when binary variable is False. See Issue #717.")
Expand Down

0 comments on commit 2321839

Please sign in to comment.