Skip to content

Add enableDebugSol following discussion on mailing list #1013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
- Added enableDebugSol() and disableDebugSol() for controlling the debug solution mechanism if DEBUGSOL=true
- More support for AND-Constraints
- Added support for knapsack constraints
- Added isPositive(), isNegative(), isFeasLE(), isFeasLT(), isFeasGE(), isFeasGT(), isHugeValue(), and tests
Expand Down
6 changes: 4 additions & 2 deletions docs/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ Build with Debug
To use debug information in PySCIPOpt you need to build it with the following command:

.. code-block::
python -m pip install --install-option="--debug" .
export CFLAGS="-UNDEBUG"
export CXXFLAGS="-UNDEBUG"
python -m pip install .
.. note:: Be aware that you will need the debug library of the SCIP Optimization Suite for this to work
(cmake .. -DCMAKE_BUILD_TYPE=Debug).
Expand Down
2 changes: 2 additions & 0 deletions src/pyscipopt/scip.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,8 @@ cdef extern from "scip/scip.h":
SCIP_Real SCIPgetSolTime(SCIP* scip, SCIP_SOL* sol)

SCIP_RETCODE SCIPsetRelaxSolVal(SCIP* scip, SCIP_RELAX* relax, SCIP_VAR* var, SCIP_Real val)
void SCIPenableDebugSol(SCIP* scip)
void SCIPdisableDebugSol(SCIP* scip)

# Row Methods
SCIP_RETCODE SCIPcreateRow(SCIP* scip, SCIP_ROW** row, const char* name, int len, SCIP_COL** cols, SCIP_Real* vals,
Expand Down
29 changes: 26 additions & 3 deletions src/pyscipopt/scip.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
_SCIP_BOUNDTYPE_TO_STRING = {SCIP_BOUNDTYPE_UPPER: '<=',
SCIP_BOUNDTYPE_LOWER: '>='}

cdef extern from "scip/config.h":
"""
#ifndef WITH_DEBUG_SOLUTION
#define WITH_DEBUG_SOLUTION 0
#endif
"""
bint WITH_DEBUG_SOLUTION

# Mapping the SCIP_RESULT enum to a python class
# This is required to return SCIP_RESULT in the python code
# In __init__.py this is imported as SCIP_RESULT to keep the
Expand Down Expand Up @@ -141,7 +149,6 @@
INFORUNBD = SCIP_STATUS_INFORUNBD

StageNames = {}

cdef class PY_SCIP_STAGE:
INIT = SCIP_STAGE_INIT
PROBLEM = SCIP_STAGE_PROBLEM
Expand Down Expand Up @@ -171,7 +178,6 @@
SUBROOT = SCIP_NODETYPE_SUBROOT
REFOCUSNODE = SCIP_NODETYPE_REFOCUSNODE


cdef class PY_SCIP_PROPTIMING:
BEFORELP = SCIP_PROPTIMING_BEFORELP
DURINGLPLOOP = SCIP_PROPTIMING_DURINGLPLOOP
Expand All @@ -198,7 +204,6 @@
AFTERPROPLOOP = SCIP_HEURTIMING_AFTERPROPLOOP

EventNames = {}

cdef class PY_SCIP_EVENTTYPE:
DISABLED = SCIP_EVENTTYPE_DISABLED
VARADDED = SCIP_EVENTTYPE_VARADDED
Expand Down Expand Up @@ -301,7 +306,7 @@
if rc == SCIP_OKAY:
pass
elif rc == SCIP_ERROR:
raise Exception('SCIP: unspecified error!')

Check failure on line 309 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / test-coverage (3.11)

SCIP: unspecified error!
elif rc == SCIP_NOMEMORY:
raise MemoryError('SCIP: insufficient memory error!')
elif rc == SCIP_READERROR:
Expand Down Expand Up @@ -7495,6 +7500,24 @@
"""
PY_SCIP_CALL(SCIPsetRelaxSolVal(self._scip, NULL, var.scip_var, val))

def enableDebugSol(self):
"""
Enables the debug solution mechanism, which allows tracing back the invalidation of
a debug solution during the solution process of SCIP. It must be explicitly
enabled for the SCIP data structure.
"""
if not WITH_DEBUG_SOLUTION:
raise RuntimeError("SCIP must be built with `DEBUGSOL=true` to enable the debug solution mechanism.")
SCIPenableDebugSol(self._scip)

def disableDebugSol(self):
"""
Disables the debug solution mechanism.
"""
if not WITH_DEBUG_SOLUTION:
raise RuntimeError("SCIP must be built with `DEBUGSOL=true` to disable the debug solution mechanism.")
SCIPdisableDebugSol(self._scip)

def getConss(self, transformed=True):
"""
Retrieve all constraints.
Expand Down