From 2d8815b06a1b7ff9d035e875188365aed524103e Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Thu, 7 Dec 2023 13:47:09 +0100 Subject: [PATCH 1/3] Add function getconshdlrname --- CHANGELOG.md | 1 + src/pyscipopt/scip.pxi | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca1ff959a..5293f6a4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Add convenience methods relax and getVarDict - Add SCIP functions hasPrimalRay, getPrimalRay, getPrimalRayVal - Add multiple tests for constraints and for solutions +- Add getConshdlrName to class Constraint ### Fixed - Correctly set result, lowerbound in PyRelaxExec - Fixed typo in documentation of chgRhs diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index 707586581..9a6d6d052 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -923,6 +923,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) @@ -5117,4 +5122,4 @@ def is_memory_freed(): return BMSgetMemoryUsed() == 0 def print_memory_in_use(): - BMScheckEmptyMemory() \ No newline at end of file + BMScheckEmptyMemory() From 3cfe3661a365a5c5633e25b282cea1ad73808ee5 Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Fri, 8 Dec 2023 14:24:54 +0100 Subject: [PATCH 2/3] Add check to test_cons --- tests/test_cons.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_cons.py b/tests/test_cons.py index 19c0551d1..74cb57472 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() == "SOS1" 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.") From 95d52450645a7e2915974693c7daa52a91ecfc4d Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Fri, 8 Dec 2023 14:33:11 +0100 Subject: [PATCH 3/3] Change assert to SOS2 --- tests/test_cons.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cons.py b/tests/test_cons.py index 74cb57472..c3f1f1978 100644 --- a/tests/test_cons.py +++ b/tests/test_cons.py @@ -97,7 +97,7 @@ def test_SOScons(): assert m.isEQ(m.getVal(x[4]), 1) assert m.isEQ(m.getVal(x[5]), 1) assert c1.getConshdlrName() == "SOS1" - assert c2.getConshdlrName() == "SOS1" + assert c2.getConshdlrName() == "SOS2" def test_cons_indicator():