diff --git a/CHANGELOG.md b/CHANGELOG.md index 5453b1faa..342e8735b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased ### Added +- Add getConshdlrName to class Constraint ### Fixed ### Changed ### Removed diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index 52ced2d3b..0c80107be 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -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(self.scip_cons) @@ -5142,4 +5147,4 @@ def is_memory_freed(): return BMSgetMemoryUsed() == 0 def print_memory_in_use(): - BMScheckEmptyMemory() \ No newline at end of file + BMScheckEmptyMemory() diff --git a/tests/test_cons.py b/tests/test_cons.py index 19c0551d1..c3f1f1978 100644 --- a/tests/test_cons.py +++ b/tests/test_cons.py @@ -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(): @@ -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.")