Skip to content

Commit 2321839

Browse files
authored
Merge pull request #764 from scipopt/mt/add_getconshdlrname
Mt/add getconshdlrname
2 parents 0b6bb13 + 95d5245 commit 2321839

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-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+
- Add getConshdlrName to class Constraint
56
### Fixed
67
### Changed
78
### Removed

src/pyscipopt/scip.pxi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,11 @@ cdef class Constraint:
941941
constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(self.scip_cons))).decode('UTF-8')
942942
return constype == 'nonlinear'
943943

944+
def getConshdlrName(self):
945+
"""Return the constraint handler's name"""
946+
constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(self.scip_cons))).decode('UTF-8')
947+
return constype
948+
944949
def __hash__(self):
945950
return hash(<size_t>self.scip_cons)
946951

@@ -5142,4 +5147,4 @@ def is_memory_freed():
51425147
return BMSgetMemoryUsed() == 0
51435148

51445149
def print_memory_in_use():
5145-
BMScheckEmptyMemory()
5150+
BMScheckEmptyMemory()

tests/test_cons.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def test_SOScons():
9696
assert m.isEQ(m.getVal(x[3]), 1)
9797
assert m.isEQ(m.getVal(x[4]), 1)
9898
assert m.isEQ(m.getVal(x[5]), 1)
99+
assert c1.getConshdlrName() == "SOS1"
100+
assert c2.getConshdlrName() == "SOS2"
99101

100102

101103
def test_cons_indicator():
@@ -112,6 +114,7 @@ def test_cons_indicator():
112114
assert m.isEQ(m.getVal(slack), 0)
113115
assert m.isEQ(m.getVal(binvar), 1)
114116
assert m.isEQ(m.getVal(x), 1)
117+
assert c.getConshdlrName() == "indicator"
115118

116119

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

0 commit comments

Comments
 (0)