Skip to content
Merged
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 @@ -7,6 +7,7 @@
- Added isPositive(), isNegative(), isFeasLE(), isFeasLT(), isFeasGE(), isFeasGT(), isHugeValue(), and tests
- Added SCIP_LOCKTYPE, addVarLocksType(), getNLocksDown(), getNLocksUp(), getNLocksDownType(), getNLocksUpType(), and tests
- Added addMatrixConsIndicator(), and tests
- Added SCIPvarMarkRelaxationOnly, SCIPvarIsRelaxationOnly, SCIPvarMarkDeletable, SCIPvarIsDeletable, and tests
### Fixed
- Raised an error when an expression is used when a variable is required
### Changed
Expand Down
4 changes: 4 additions & 0 deletions src/pyscipopt/scip.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,10 @@ 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_Bool SCIPvarIsRelaxationOnly(SCIP_VAR* var)
void SCIPvarMarkDeletable(SCIP_VAR* var)
SCIP_Bool SCIPvarIsDeletable(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)
Expand Down
48 changes: 47 additions & 1 deletion src/pyscipopt/scip.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
if rc == SCIP_OKAY:
pass
elif rc == SCIP_ERROR:
raise Exception('SCIP: unspecified error!')

Check failure on line 304 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 @@ -1677,6 +1677,49 @@
"""
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

"""
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 isDeletable(self):
"""
Returns whether variable is allowed to be deleted completely from the problem.

Returns
-------
bool

"""
return SCIPvarIsDeletable(self.scip_var)

def getNLocksDown(self):
"""
Returns the number of locks for rounding down.
Expand Down Expand Up @@ -3745,7 +3788,7 @@

# Variable Functions

def addVar(self, name='', vtype='C', lb=0.0, ub=None, obj=0.0, pricedVar=False, pricedVarScore=1.0):
def addVar(self, name='', vtype='C', lb=0.0, ub=None, obj=0.0, pricedVar=False, pricedVarScore=1.0, deletable=False):
"""
Create a new variable. Default variable is non-negative and continuous.

Expand Down Expand Up @@ -3801,6 +3844,9 @@
else:
raise Warning("unrecognized variable type")

if deletable:
SCIPvarMarkDeletable(scip_var)

if pricedVar:
PY_SCIP_CALL(SCIPaddPricedVar(self._scip, scip_var, pricedVarScore))
else:
Expand Down
17 changes: 16 additions & 1 deletion tests/test_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,19 @@ def test_vtype():
assert x.vtype() == "INTEGER"

m.chgVarType(y, 'M')
assert y.vtype() == "IMPLINT"
assert y.vtype() == "IMPLINT"

def test_markRelaxationOnly():
m = Model()

x = m.addVar(vtype='C', lb=-5.5, ub=8, deletable=True)
y = m.addVar(vtype='I', lb=-5.2, ub=8)

assert not x.isRelaxationOnly()
assert not y.isRelaxationOnly()

x.markRelaxationOnly()
assert x.isRelaxationOnly()
assert x.isDeletable()
assert not y.isRelaxationOnly()
assert not y.isDeletable()