Skip to content

Commit 0e2a79f

Browse files
Add getPrimalDualIntegral() from C API (#1174)
* Expose SCIPgetPrimalDualIntegral * Add test * Update CHANGELOG.md
1 parent 1fdc6ca commit 0e2a79f

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Added pre-commit hook for automatic stub regeneration (see .pre-commit-config.yaml)
99
- Wrapped isObjIntegral() and test
1010
- Added structured_optimization_trace recipe for structured optimization progress tracking
11+
- Added methods: getPrimalDualIntegral()
1112
### Fixed
1213
- getBestSol() now returns None for infeasible problems instead of a Solution with NULL pointer
1314
- all fundamental callbacks now raise an error if not implemented

src/pyscipopt/scip.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,7 @@ cdef extern from "scip/scip.h":
14731473
int SCIPgetPlungeDepth(SCIP* scip)
14741474
SCIP_Longint SCIPgetNNodeLPIterations(SCIP* scip)
14751475
SCIP_Longint SCIPgetNStrongbranchLPIterations(SCIP* scip)
1476+
SCIP_Real SCIPgetPrimalDualIntegral(SCIP* scip)
14761477

14771478
# Parameter Functions
14781479
SCIP_RETCODE SCIPsetBoolParam(SCIP* scip, char* name, SCIP_Bool value)

src/pyscipopt/scip.pxi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3385,6 +3385,16 @@ cdef class Model:
33853385
"""
33863386
return SCIPgetNStrongbranchLPIterations(self._scip)
33873387

3388+
def getPrimalDualIntegral(self):
3389+
"""
3390+
Recomputes and returns the primal dual gap stored in the stats
3391+
3392+
Returns
3393+
------
3394+
float
3395+
"""
3396+
return SCIPgetPrimalDualIntegral(self._scip)
3397+
33883398
def cutoffNode(self, Node node):
33893399
"""
33903400
marks node and whole subtree to be cut off from the branch and bound tree.

src/pyscipopt/scip.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,7 @@ class Model:
11291129
def getNSols(self) -> Incomplete: ...
11301130
def getNSolsFound(self) -> Incomplete: ...
11311131
def getNStrongbranchLPIterations(self) -> Incomplete: ...
1132+
def getPrimalDualIntegral(self) -> Incomplete: ...
11321133
def getNTotalNodes(self) -> Incomplete: ...
11331134
def getNVars(self, transformed: Incomplete = ...) -> Incomplete: ...
11341135
def getNVarsAnd(self, and_cons: Incomplete) -> Incomplete: ...

tests/test_statistics.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ def test_statistics_json():
1212
assert data["origprob"]["problem_name"] == "model"
1313

1414
os.remove("statistics.json")
15+
16+
def test_getPrimalDualIntegral():
17+
model = random_mip_1(small=True)
18+
model.optimize()
19+
primal_dual_integral = model.getPrimalDualIntegral()
20+
21+
assert isinstance(primal_dual_integral, float)

0 commit comments

Comments
 (0)