Skip to content

Commit b4a70f5

Browse files
Add SCIPvarMarkRelaxationOnly (#1023)
* Add SCIPvarMarkRelaxationOnly * Fix and add isRelaxationOnly * remove debug flag * varDeletable functions
1 parent 3544861 commit b4a70f5

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Added isPositive(), isNegative(), isFeasLE(), isFeasLT(), isFeasGE(), isFeasGT(), isHugeValue(), and tests
88
- Added SCIP_LOCKTYPE, addVarLocksType(), getNLocksDown(), getNLocksUp(), getNLocksDownType(), getNLocksUpType(), and tests
99
- Added addMatrixConsIndicator(), and tests
10+
- Added SCIPvarMarkRelaxationOnly, SCIPvarIsRelaxationOnly, SCIPvarMarkDeletable, SCIPvarIsDeletable, and tests
1011
### Fixed
1112
- Raised an error when an expression is used when a variable is required
1213
### Changed

src/pyscipopt/scip.pxd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,10 @@ cdef extern from "scip/scip.h":
817817
void SCIPvarSetData(SCIP_VAR* var, SCIP_VARDATA* vardata)
818818
SCIP_VARDATA* SCIPvarGetData(SCIP_VAR* var)
819819
SCIP_Real SCIPvarGetAvgSol(SCIP_VAR* var)
820+
void SCIPvarMarkRelaxationOnly(SCIP_VAR* var)
821+
SCIP_Bool SCIPvarIsRelaxationOnly(SCIP_VAR* var)
822+
void SCIPvarMarkDeletable(SCIP_VAR* var)
823+
SCIP_Bool SCIPvarIsDeletable(SCIP_VAR* var)
820824
SCIP_Real SCIPgetVarPseudocost(SCIP* scip, SCIP_VAR* var, SCIP_BRANCHDIR dir)
821825
SCIP_Real SCIPvarGetCutoffSum(SCIP_VAR* var, SCIP_BRANCHDIR dir)
822826
SCIP_Longint SCIPvarGetNBranchings(SCIP_VAR* var, SCIP_BRANCHDIR dir)

src/pyscipopt/scip.pxi

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,49 @@ cdef class Variable(Expr):
16771677
"""
16781678
return SCIPvarGetAvgSol(self.scip_var)
16791679

1680+
def markRelaxationOnly(self):
1681+
"""
1682+
marks that this variable has only been introduced to define a relaxation
1683+
1684+
The variable must not have a coefficient in the objective and must be deletable.
1685+
If it is not marked deletable, it will be marked as deletable, which is only possible before
1686+
the variable is added to a problem.
1687+
1688+
Returns
1689+
-------
1690+
None
1691+
1692+
"""
1693+
SCIPvarMarkRelaxationOnly(self.scip_var)
1694+
1695+
def isRelaxationOnly(self):
1696+
"""
1697+
returns whether a variable has been introduced to define a relaxation
1698+
1699+
These variables are only valid for the current SCIP solve round, they are not contained in any (checked)
1700+
constraints, but may be used in cutting planes, for example. Relaxation-only variables are not copied
1701+
by SCIPcopyVars and cuts that contain these variables are not added as linear constraints when
1702+
restarting or transferring information from a copied SCIP to a SCIP. Also conflicts with relaxation-only
1703+
variables are not generated at the moment. Relaxation-only variables do not appear in the objective.
1704+
1705+
Returns
1706+
-------
1707+
bool
1708+
1709+
"""
1710+
return SCIPvarIsRelaxationOnly(self.scip_var)
1711+
1712+
def isDeletable(self):
1713+
"""
1714+
Returns whether variable is allowed to be deleted completely from the problem.
1715+
1716+
Returns
1717+
-------
1718+
bool
1719+
1720+
"""
1721+
return SCIPvarIsDeletable(self.scip_var)
1722+
16801723
def getNLocksDown(self):
16811724
"""
16821725
Returns the number of locks for rounding down.
@@ -3745,7 +3788,7 @@ cdef class Model:
37453788

37463789
# Variable Functions
37473790

3748-
def addVar(self, name='', vtype='C', lb=0.0, ub=None, obj=0.0, pricedVar=False, pricedVarScore=1.0):
3791+
def addVar(self, name='', vtype='C', lb=0.0, ub=None, obj=0.0, pricedVar=False, pricedVarScore=1.0, deletable=False):
37493792
"""
37503793
Create a new variable. Default variable is non-negative and continuous.
37513794
@@ -3801,6 +3844,9 @@ cdef class Model:
38013844
else:
38023845
raise Warning("unrecognized variable type")
38033846

3847+
if deletable:
3848+
SCIPvarMarkDeletable(scip_var)
3849+
38043850
if pricedVar:
38053851
PY_SCIP_CALL(SCIPaddPricedVar(self._scip, scip_var, pricedVarScore))
38063852
else:

tests/test_vars.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,19 @@ def test_vtype():
6464
assert x.vtype() == "INTEGER"
6565

6666
m.chgVarType(y, 'M')
67-
assert y.vtype() == "IMPLINT"
67+
assert y.vtype() == "IMPLINT"
68+
69+
def test_markRelaxationOnly():
70+
m = Model()
71+
72+
x = m.addVar(vtype='C', lb=-5.5, ub=8, deletable=True)
73+
y = m.addVar(vtype='I', lb=-5.2, ub=8)
74+
75+
assert not x.isRelaxationOnly()
76+
assert not y.isRelaxationOnly()
77+
78+
x.markRelaxationOnly()
79+
assert x.isRelaxationOnly()
80+
assert x.isDeletable()
81+
assert not y.isRelaxationOnly()
82+
assert not y.isDeletable()

0 commit comments

Comments
 (0)