Skip to content
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
5 changes: 3 additions & 2 deletions src/pyscipopt/reader.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ cdef SCIP_RETCODE PyReaderRead (SCIP* scip, SCIP_READER* reader, const char* fil
return SCIP_OKAY

cdef SCIP_RETCODE PyReaderWrite (SCIP* scip, SCIP_READER* reader, FILE* file,
const char* name, SCIP_PROBDATA* probdata, SCIP_Bool transformed,
SCIP_OBJSENSE objsense, SCIP_Real objscale, SCIP_Real objoffset,
const char* filename, const char* name, SCIP_PROBDATA* probdata, SCIP_Bool transformed,
SCIP_OBJSENSE objsense, SCIP_Real objoffset, SCIP_Real objscale,
SCIP_RATIONAL* objoffsetexact, SCIP_RATIONAL* objscaleexact,
SCIP_VAR** vars, int nvars, int nbinvars, int nintvars, int nimplvars, int ncontvars,
SCIP_VAR** fixedvars, int nfixedvars, int startnvars,
SCIP_CONS** conss, int nconss, int maxnconss, int startnconss,
Expand Down
10 changes: 6 additions & 4 deletions src/pyscipopt/scip.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ cdef extern from "scip/scip.h":
ctypedef struct SCIP_PROBDATA:
pass

ctypedef struct SCIP_RATIONAL:
pass

ctypedef struct SCIP_PRICER:
pass

Expand Down Expand Up @@ -957,8 +960,9 @@ cdef extern from "scip/scip.h":
SCIP_RETCODE (*readerfree) (SCIP* scip, SCIP_READER* reader),
SCIP_RETCODE (*readerread) (SCIP* scip, SCIP_READER* reader, const char* filename, SCIP_RESULT* result),
SCIP_RETCODE (*readerwrite) (SCIP* scip, SCIP_READER* reader, FILE* file,
const char* name, SCIP_PROBDATA* probdata, SCIP_Bool transformed,
SCIP_OBJSENSE objsense, SCIP_Real objscale, SCIP_Real objoffset,
const char* filename, const char* name, SCIP_PROBDATA* probdata, SCIP_Bool transformed,
SCIP_OBJSENSE objsense, SCIP_Real objoffset, SCIP_Real objscale,
SCIP_RATIONAL* objoffsetexact, SCIP_RATIONAL* objscaleexact,
SCIP_VAR** vars, int nvars, int nbinvars, int nintvars, int nimplvars, int ncontvars,
SCIP_VAR** fixedvars, int nfixedvars, int startnvars,
SCIP_CONS** conss, int nconss, int maxnconss, int startnconss,
Expand Down Expand Up @@ -1663,8 +1667,6 @@ cdef extern from "scip/cons_and.h":
SCIP_VAR* SCIPgetResultantAnd(SCIP* scip, SCIP_CONS* cons)
SCIP_Bool SCIPisAndConsSorted(SCIP* scip, SCIP_CONS* cons)
SCIP_RETCODE SCIPsortAndCons(SCIP* scip, SCIP_CONS* cons)
SCIP_RETCODE SCIPchgAndConsCheckFlagWhenUpgr(SCIP* scip, SCIP_CONS* cons, SCIP_Bool flag)
SCIP_RETCODE SCIPchgAndConsRemovableFlagWhenUpgr(SCIP* scip, SCIP_CONS* cons, SCIP_Bool flag)

cdef extern from "scip/cons_or.h":
SCIP_RETCODE SCIPcreateConsOr(SCIP* scip,
Expand Down
32 changes: 0 additions & 32 deletions src/pyscipopt/scip.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -6347,38 +6347,6 @@ cdef class Model:

PY_SCIP_CALL(SCIPsortAndCons(self._scip, and_cons.scip_cons))

def chgAndConsCheckFlagWhenUpgr(self, Constraint cons, flag):
"""
when 'upgrading' the given AND-constraint, should the check flag for the upgraded
constraint be set to TRUE, even if the check flag of this AND-constraint is set to FALSE?

Parameters
----------
cons : Constraint
The AND constraint to change.
flag : bool
The new value for the check flag.

"""

PY_SCIP_CALL(SCIPchgAndConsCheckFlagWhenUpgr(self._scip, cons.scip_cons, flag))

def chgAndConsRemovableFlagWhenUpgr(self, Constraint cons, flag):
"""
when 'upgrading' the given AND-constraint, should the removable flag for the upgraded
constraint be set to TRUE, even if the removable flag of this AND-constraint is set to FALSE?

Parameters
----------
cons : Constraint
The AND constraint to change.
flag : bool
The new value for the removable flag.

"""

PY_SCIP_CALL(SCIPchgAndConsRemovableFlagWhenUpgr(self._scip, cons.scip_cons, flag))

def printCons(self, Constraint constraint):
"""
Print the constraint
Expand Down
2 changes: 0 additions & 2 deletions src/pyscipopt/scip.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,6 @@ class Model:
def checkBendersSubproblemOptimality(self, *args, **kwargs): ...
def checkQuadraticNonlinear(self, *args, **kwargs): ...
def checkSol(self, *args, **kwargs): ...
def chgAndConsCheckFlagWhenUpgr(self, *args, **kwargs): ...
def chgAndConsRemovableFlagWhenUpgr(self, *args, **kwargs): ...
def chgCapacityKnapsack(self, *args, **kwargs): ...
def chgCoefLinear(self, *args, **kwargs): ...
def chgLhs(self, *args, **kwargs): ...
Expand Down
51 changes: 43 additions & 8 deletions tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,50 @@

calls = []


class MyEvent(Eventhdlr):

def eventinit(self):
calls.append('eventinit')
self.model.catchEvent(self.event_type, self)

self._tracked_vars = []
self._tracked_rows = []
if self.event_type & SCIP_EVENTTYPE.VARCHANGED:
vars = self.model.getVars(transformed=True)
if not vars:
vars = [self.model.getTransformedVar(var) for var in self.model.getVars()]
for var in vars:
self.model.catchVarEvent(var, self.event_type, self)
self._tracked_vars.append(var)
elif self.event_type & SCIP_EVENTTYPE.ROWCHANGED:
try:
if self.model.getNLPRows() == 0:
return
rows = self.model.getLPRowsData()
except Exception:
return
for row in rows:
self.model.catchRowEvent(row, self.event_type, self)
self._tracked_rows.append(row)
else:
self.model.catchEvent(self.event_type, self)

def eventexit(self):
# PR #828 fixes an error here, but the underlying cause might not be solved (self.model being deleted before dropEvent is called)
self.model.dropEvent(self.event_type, self)
if self.event_type & SCIP_EVENTTYPE.VARCHANGED:
for var in self._tracked_vars:
try:
self.model.dropVarEvent(var, self.event_type, self)
except ReferenceError:
pass
elif self.event_type & SCIP_EVENTTYPE.ROWCHANGED:
for row in self._tracked_rows:
try:
self.model.dropRowEvent(row, self.event_type, self)
except ReferenceError:
pass
else:
self.model.dropEvent(self.event_type, self)

def eventexec(self, event):
assert str(event) == event.getName()
Expand All @@ -32,19 +67,19 @@ def eventexec(self, event):
elif self.event_type == SCIP_EVENTTYPE.BOUNDRELAXED:
assert event.getType() in [SCIP_EVENTTYPE.LBRELAXED, SCIP_EVENTTYPE.UBRELAXED]
elif self.event_type == SCIP_EVENTTYPE.BOUNDCHANGED:
assert event.getType() in [SCIP_EVENTTYPE.LBCHANGED, SCIP_EVENTTYPE.UBCHANGED]
assert event.getType() & SCIP_EVENTTYPE.BOUNDCHANGED
elif self.event_type == SCIP_EVENTTYPE.GHOLECHANGED:
assert event.getType() in [SCIP_EVENTTYPE.GHOLEADDED, SCIP_EVENTTYPE.GHOLEREMOVED]
elif self.event_type == SCIP_EVENTTYPE.LHOLECHANGED:
assert event.getType() in [SCIP_EVENTTYPE.LHOLEADDED, SCIP_EVENTTYPE.LHOLEREMOVED]
elif self.event_type == SCIP_EVENTTYPE.HOLECHANGED:
assert event.getType() in [SCIP_EVENTTYPE.GHOLECHANGED, SCIP_EVENTTYPE.LHOLECHANGED]
elif self.event_type == SCIP_EVENTTYPE.DOMCHANGED:
assert event.getType() in [SCIP_EVENTTYPE.BOUNDCHANGED, SCIP_EVENTTYPE.HOLECHANGED]
assert event.getType() & SCIP_EVENTTYPE.DOMCHANGED
elif self.event_type == SCIP_EVENTTYPE.VARCHANGED:
assert event.getType() in [SCIP_EVENTTYPE.VARFIXED, SCIP_EVENTTYPE.VARUNLOCKED, SCIP_EVENTTYPE.OBJCHANGED, SCIP_EVENTTYPE.GBDCHANGED, SCIP_EVENTTYPE.DOMCHANGED, SCIP_EVENTTYPE.IMPLADDED, SCIP_EVENTTYPE.VARDELETED, SCIP_EVENTTYPE.TYPECHANGED]
assert event.getType() & SCIP_EVENTTYPE.VARCHANGED
elif self.event_type == SCIP_EVENTTYPE.VAREVENT:
assert event.getType() in [SCIP_EVENTTYPE.VARADDED, SCIP_EVENTTYPE.VARCHANGED, SCIP_EVENTTYPE.TYPECHANGED]
assert event.getType() & SCIP_EVENTTYPE.VAREVENT
elif self.event_type == SCIP_EVENTTYPE.NODESOLVED:
assert event.getType() in [SCIP_EVENTTYPE.NODEFEASIBLE, SCIP_EVENTTYPE.NODEINFEASIBLE, SCIP_EVENTTYPE.NODEBRANCHED]
elif self.event_type == SCIP_EVENTTYPE.NODEEVENT:
Expand All @@ -54,9 +89,9 @@ def eventexec(self, event):
elif self.event_type == SCIP_EVENTTYPE.SOLFOUND:
assert event.getType() in [SCIP_EVENTTYPE.POORSOLFOUND, SCIP_EVENTTYPE.BESTSOLFOUND]
elif self.event_type == SCIP_EVENTTYPE.ROWCHANGED:
assert event.getType() in [SCIP_EVENTTYPE.ROWCOEFCHANGED, SCIP_EVENTTYPE.ROWCONSTCHANGED, SCIP_EVENTTYPE.ROWSIDECHANGED]
assert event.getType() & SCIP_EVENTTYPE.ROWCHANGED
elif self.event_type == SCIP_EVENTTYPE.ROWEVENT:
assert event.getType() in [SCIP_EVENTTYPE.ROWADDEDSEPA, SCIP_EVENTTYPE.ROWDELETEDSEPA, SCIP_EVENTTYPE.ROWADDEDLP, SCIP_EVENTTYPE.ROWDELETEDLP, SCIP_EVENTTYPE.ROWCHANGED]
assert event.getType() & SCIP_EVENTTYPE.ROWEVENT
else:
assert event.getType() == self.event_type

Expand Down
4 changes: 3 additions & 1 deletion tests/test_pricer.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ def test_cuttingstock():

assert s.getObjVal() == 452.25
assert type(s.getNSols()) == int
assert s.getNSols() == s.data["nSols"]
# Additional primal solutions can be found after the pricer updated the data,
# so the stored value is a lower bound on the final solution count.
assert s.getNSols() >= s.data["nSols"]

# Testing freeTransform
s.freeTransform()
Expand Down
77 changes: 0 additions & 77 deletions tests/test_relax.py

This file was deleted.

4 changes: 2 additions & 2 deletions tests/test_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ def test_vtype():
assert x.vtype() == "CONTINUOUS"
assert y.vtype() == "INTEGER"
assert z.vtype() == "BINARY"
assert w.vtype() == "IMPLINT"
assert w.vtype() == "CONTINUOUS"

m.chgVarType(x, 'I')
assert x.vtype() == "INTEGER"

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

def test_markRelaxationOnly():
m = Model()
Expand Down
Loading