From d938ef9591961a3ea31d9ba0aeb896a7a0a76100 Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Sat, 12 Jul 2025 11:45:47 +0100 Subject: [PATCH 1/6] Add SCIPvarMarkRelaxationOnly --- CHANGELOG.md | 1 + src/pyscipopt/scip.pxd | 1 + src/pyscipopt/scip.pxi | 15 +++++++++++++++ 3 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f917ec92..288a33c7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Added support for knapsack constraints - Added isPositive(), isNegative(), isFeasLE(), isFeasLT(), isFeasGE(), isFeasGT(), isHugeValue(), and tests - Added SCIP_LOCKTYPE, addVarLocksType(), getNLocksDown(), getNLocksUp(), getNLocksDownType(), getNLocksUpType(), and tests +- Added SCIPvarMarkRelaxationOnly ### Fixed - Raised an error when an expression is used when a variable is required ### Changed diff --git a/src/pyscipopt/scip.pxd b/src/pyscipopt/scip.pxd index b198b221d..a620db624 100644 --- a/src/pyscipopt/scip.pxd +++ b/src/pyscipopt/scip.pxd @@ -817,6 +817,7 @@ cdef extern from "scip/scip.h": void SCIPvarSetData(SCIP_VAR* var, SCIP_VARDATA* vardata) SCIP_VARDATA* SCIPvarGetData(SCIP_VAR* var) SCIP_Real SCIPvarGetAvgSol(SCIP_VAR* var) + void SCIPvarMarkRelaxationOnly(SCIP_VAR* var) SCIP_Real SCIPgetVarPseudocost(SCIP* scip, SCIP_VAR* var, SCIP_BRANCHDIR dir) SCIP_Real SCIPvarGetCutoffSum(SCIP_VAR* var, SCIP_BRANCHDIR dir) SCIP_Longint SCIPvarGetNBranchings(SCIP_VAR* var, SCIP_BRANCHDIR dir) diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index 7c7216c83..11c3f3a2f 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -1676,6 +1676,21 @@ cdef class Variable(Expr): """ return SCIPvarGetAvgSol(self.scip_var) + + def markRelaxationOnly(self): + """ + marks that this variable has only been introduced to define a relaxation + + The variable must not have a coefficient in the objective and must be deletable. + If it is not marked deletable, it will be marked as deletable, which is only possible before + the variable is added to a problem. + + Returns + ------- + None + + """ + PY_SCIP_CALL(SCIPvarMarkRelaxationOnly(self.scip_var)) def getNLocksDown(self): """ From e7026d3d960d6a92f22bea3106094a4d6e528df5 Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Tue, 15 Jul 2025 08:44:58 +0100 Subject: [PATCH 2/6] Fix and add isRelaxationOnly --- CHANGELOG.md | 2 +- src/pyscipopt/scip.pxd | 1 + src/pyscipopt/scip.pxi | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 288a33c7d..d24ac9508 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Added support for knapsack constraints - Added isPositive(), isNegative(), isFeasLE(), isFeasLT(), isFeasGE(), isFeasGT(), isHugeValue(), and tests - Added SCIP_LOCKTYPE, addVarLocksType(), getNLocksDown(), getNLocksUp(), getNLocksDownType(), getNLocksUpType(), and tests -- Added SCIPvarMarkRelaxationOnly +- Added SCIPvarMarkRelaxationOnly, SCIPvarIsRelaxationOnly ### Fixed - Raised an error when an expression is used when a variable is required ### Changed diff --git a/src/pyscipopt/scip.pxd b/src/pyscipopt/scip.pxd index a620db624..0d3a22657 100644 --- a/src/pyscipopt/scip.pxd +++ b/src/pyscipopt/scip.pxd @@ -818,6 +818,7 @@ cdef extern from "scip/scip.h": SCIP_VARDATA* SCIPvarGetData(SCIP_VAR* var) SCIP_Real SCIPvarGetAvgSol(SCIP_VAR* var) void SCIPvarMarkRelaxationOnly(SCIP_VAR* var) + SCIP_Bool SCIPvarIsRelaxationOnly(SCIP_VAR* var) SCIP_Real SCIPgetVarPseudocost(SCIP* scip, SCIP_VAR* var, SCIP_BRANCHDIR dir) SCIP_Real SCIPvarGetCutoffSum(SCIP_VAR* var, SCIP_BRANCHDIR dir) SCIP_Longint SCIPvarGetNBranchings(SCIP_VAR* var, SCIP_BRANCHDIR dir) diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index 11c3f3a2f..98b8a408d 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -1690,7 +1690,24 @@ cdef class Variable(Expr): None """ - PY_SCIP_CALL(SCIPvarMarkRelaxationOnly(self.scip_var)) + SCIPvarMarkRelaxationOnly(self.scip_var) + + def isRelaxationOnly(self): + """ + returns whether a variable has been introduced to define a relaxation + + These variables are only valid for the current SCIP solve round, they are not contained in any (checked) + constraints, but may be used in cutting planes, for example. Relaxation-only variables are not copied + by SCIPcopyVars and cuts that contain these variables are not added as linear constraints when + restarting or transferring information from a copied SCIP to a SCIP. Also conflicts with relaxation-only + variables are not generated at the moment. Relaxation-only variables do not appear in the objective. + + Returns + ------- + bool + + """ + return SCIPvarIsRelaxationOnly(self.scip_var) def getNLocksDown(self): """ From bbd7e5da98489db28097f2e1011bb4a91bc6fd2e Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Thu, 17 Jul 2025 15:35:49 +0100 Subject: [PATCH 3/6] remove debug flag --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 90ec9cba3..abebcc5d4 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ # look for environment variable that specifies path to SCIP scipoptdir = os.environ.get("SCIPOPTDIR", "").strip('"') -extra_compile_args = ["-UNDEBUG"] +extra_compile_args = [] extra_link_args = [] # if SCIPOPTDIR is not set, we assume that SCIP is installed globally From 3c8ce93d3ff097f802299212356fe638110efd1e Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Thu, 17 Jul 2025 15:45:12 +0100 Subject: [PATCH 4/6] Change activation of debug mode --- docs/build.rst | 3 ++- setup.py | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/build.rst b/docs/build.rst index ad8f74356..55bfe9a19 100644 --- a/docs/build.rst +++ b/docs/build.rst @@ -160,7 +160,8 @@ To use debug information in PySCIPOpt you need to build it with the following co .. code-block:: - python -m pip install --install-option="--debug" . + export PYSCIPOPT_DEBUG=True + 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). diff --git a/setup.py b/setup.py index abebcc5d4..6e087e86a 100644 --- a/setup.py +++ b/setup.py @@ -62,9 +62,8 @@ extra_link_args.append(f"-Wl,-rpath,{libdir}") # enable debug mode if requested -if "--debug" in sys.argv: +if os.environ.get("PYSCIPOPT_DEBUG")==True: extra_compile_args.append("-UNDEBUG") - sys.argv.remove("--debug") use_cython = True From 2536bfb499a94006c013e991ed1dc2a6e24b52f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dion=C3=ADsio?= <57299939+Joao-Dionisio@users.noreply.github.com> Date: Thu, 31 Jul 2025 07:34:10 +0100 Subject: [PATCH 5/6] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6e087e86a..b9f9f1991 100644 --- a/setup.py +++ b/setup.py @@ -62,7 +62,7 @@ extra_link_args.append(f"-Wl,-rpath,{libdir}") # enable debug mode if requested -if os.environ.get("PYSCIPOPT_DEBUG")==True: +if os.environ.get("PYSCIPOPT_DEBUG")=="True": extra_compile_args.append("-UNDEBUG") use_cython = True From a0878f092ae4d34258df2d96de74e083956be198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dion=C3=ADsio?= <57299939+Joao-Dionisio@users.noreply.github.com> Date: Thu, 31 Jul 2025 07:35:37 +0100 Subject: [PATCH 6/6] Update build.rst --- docs/build.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/build.rst b/docs/build.rst index de9e6ad92..0b27ef4d2 100644 --- a/docs/build.rst +++ b/docs/build.rst @@ -168,7 +168,7 @@ Build with Debug To use debug information in PySCIPOpt you need to build it with the following command: .. code-block:: - export PYSCIPOPT_DEBUG=True + export PYSCIPOPT_DEBUG=True # With Windows CMD: set PYSCIPOPT_DEBUG=True python -m pip install . .. note:: Be aware that you will need the debug library of the SCIP Optimization Suite for this to work