Skip to content

SCIP 10 #1009

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

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft

SCIP 10 #1009

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: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
- 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
- Wrapped SCIPprintStatisticsJson
- Added 4 new events: TYPECHANGED, IMPLTYPECHANGED, DUALBOUNDIMPROVED, GAPUPDATED.
- Support for new implied integrality
- Wrapped varIsBinary(), varIsIntegral(), varIsImpliedIntegral(), varIsNonImpliedIntegral(), varGetImplType()
- Added support for IISFinder
### Fixed
- Raised an error when an expression is used when a variable is required
### Changed
Expand Down
37 changes: 37 additions & 0 deletions src/pyscipopt/iisfinder.pxi
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
##@file iisfinder.pxi
#@brief Base class of the IIS finder Plugin
cdef class IISfinder:
cdef public Model model
cdef public str name

def iisfinderfree(self):
'''calls destructor and frees memory of iis finder'''
pass

def iisfinderexec(self):
'''calls execution method of iis finder'''
raise NotImplementedError("iisfinderexec() is a fundamental callback and should be implemented in the derived class")


cdef SCIP_RETCODE PyiisfinderCopy (SCIP* scip, SCIP_IISFINDER* iisfinder) noexcept with gil:
return SCIP_OKAY

cdef SCIP_RETCODE PyiisfinderFree (SCIP* scip, SCIP_IISFINDER* iisfinder) noexcept with gil:
cdef SCIP_IISFINDERDATA* iisfinderdata
iisfinderdata = SCIPiisfinderGetData(iisfinder)
PyIIS = <IISfinder>iisfinderdata
PyIIS.iisfinderfree()
Py_DECREF(PyIIS)
return SCIP_OKAY

cdef SCIP_RETCODE PyiisfinderExec (SCIP_IIS* iis, SCIP_IISFINDER* iisfinder, SCIP_Real timelim, SCIP_Longint nodelim, SCIP_Bool removebounds, SCIP_Bool silent, SCIP_RESULT* result) noexcept with gil:
cdef SCIP_IISFINDERDATA* iisfinderdata
iisfinderdata = SCIPiisfinderGetData(iisfinder)
PyIIS = <IISfinder>iisfinderdata
result_dict = PyIIS.iisfinderexec()
assert isinstance(result_dict, dict), "iisfinderexec() must return a dictionary."
#TODO
assert False
# lowerbound[0] = result_dict.get("lowerbound", <SCIP_Real>lowerbound[0])
# result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
# return SCIP_OKAY
12 changes: 7 additions & 5 deletions src/pyscipopt/reader.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cdef class Reader:
'''calls read method of reader'''
return {}

def readerwrite(self, file, name, transformed, objsense, objscale, objoffset, binvars, intvars,
def readerwrite(self, file, name, transformed, objsense, objoffset, objscale, binvars, intvars,
implvars, contvars, fixedvars, startnvars, conss, maxnconss, startnconss, genericnames):
'''calls write method of reader'''
return {}
Expand Down Expand Up @@ -40,9 +40,10 @@ cdef SCIP_RETCODE PyReaderRead (SCIP* scip, SCIP_READER* reader, const char* fil

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,
SCIP_VAR** vars, int nvars, int nbinvars, int nintvars, int nimplvars, int ncontvars,
SCIP_VAR** fixedvars, int nfixedvars, int startnvars,
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,
SCIP_Bool genericnames, SCIP_RESULT* result) noexcept with gil:
cdef SCIP_READERDATA* readerdata = SCIPreaderGetData(reader)
Expand All @@ -58,7 +59,8 @@ cdef SCIP_RETCODE PyReaderWrite (SCIP* scip, SCIP_READER* reader, FILE* file,
PyFixedVars = [Variable.create(fixedvars[i]) for i in range(nfixedvars)]
PyConss = [Constraint.create(conss[i]) for i in range(nconss)]
PyReader = <Reader>readerdata
result_dict = PyReader.readerwrite(PyFile, PyName, transformed, objsense, objscale, objoffset,
#TODO: provide rational objoffsetexact and objscaleexact
result_dict = PyReader.readerwrite(PyFile, PyName, transformed, objsense, objoffset, objscale,
PyBinVars, PyIntVars, PyImplVars, PyContVars, PyFixedVars, startnvars,
PyConss, maxnconss, startnconss, genericnames)
result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
Expand Down
7 changes: 3 additions & 4 deletions src/pyscipopt/relax.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ cdef class Relax:
pass

def relaxexec(self):
'''callls execution method of relaxation handler'''
print("python error in relaxexec: this method needs to be implemented")
return{}

'''calls execution method of relaxation handler'''
print("relaxexec() is a fundamental callback and should be implemented in the derived class")
return {}

cdef SCIP_RETCODE PyRelaxCopy (SCIP* scip, SCIP_RELAX* relax) noexcept with gil:
return SCIP_OKAY
Expand Down
103 changes: 93 additions & 10 deletions src/pyscipopt/scip.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,15 @@ cdef extern from "scip/scip.h":
SCIP_EVENTTYPE SCIP_EVENTTYPE_LHOLEADDED
SCIP_EVENTTYPE SCIP_EVENTTYPE_LHOLEREMOVED
SCIP_EVENTTYPE SCIP_EVENTTYPE_IMPLADDED
SCIP_EVENTTYPE SCIP_EVENTTYPE_TYPECHANGED
SCIP_EVENTTYPE SCIP_EVENTTYPE_IMPLTYPECHANGED
SCIP_EVENTTYPE SCIP_EVENTTYPE_PRESOLVEROUND
SCIP_EVENTTYPE SCIP_EVENTTYPE_NODEFOCUSED
SCIP_EVENTTYPE SCIP_EVENTTYPE_NODEFEASIBLE
SCIP_EVENTTYPE SCIP_EVENTTYPE_NODEINFEASIBLE
SCIP_EVENTTYPE SCIP_EVENTTYPE_NODEBRANCHED
SCIP_EVENTTYPE SCIP_EVENTTYPE_NODEDELETE
SCIP_EVENTTYPE SCIP_EVENTTYPE_DUALBOUNDIMPROVED
SCIP_EVENTTYPE SCIP_EVENTTYPE_FIRSTLPSOLVED
SCIP_EVENTTYPE SCIP_EVENTTYPE_LPSOLVED
SCIP_EVENTTYPE SCIP_EVENTTYPE_POORSOLFOUND
Expand Down Expand Up @@ -292,6 +295,7 @@ cdef extern from "scip/scip.h":
SCIP_EVENTTYPE SCIP_EVENTTYPE_LPEVENT
SCIP_EVENTTYPE SCIP_EVENTTYPE_SOLFOUND
SCIP_EVENTTYPE SCIP_EVENTTYPE_SOLEVENT
SCIP_EVENTTYPE SCIP_EVENTTYPE_GAPUPDATED
SCIP_EVENTTYPE SCIP_EVENTTYPE_ROWCHANGED
SCIP_EVENTTYPE SCIP_EVENTTYPE_ROWEVENT

Expand All @@ -304,6 +308,12 @@ cdef extern from "scip/scip.h":
cdef extern from "scip/type_var.h":
SCIP_LOCKTYPE SCIP_LOCKTYPE_MODEL
SCIP_LOCKTYPE SCIP_LOCKTYPE_CONFLICT

ctypedef int SCIP_IMPLINTTYPE
cdef extern from "scip/type_var.h":
SCIP_IMPLINTTYPE SCIP_IMPLINTTYPE_NONE
SCIP_IMPLINTTYPE SCIP_IMPLINTTYPE_WEAK
SCIP_IMPLINTTYPE SCIP_IMPLINTTYPE_STRONG

ctypedef int SCIP_BENDERSENFOTYPE
cdef extern from "scip/type_benders.h":
Expand Down Expand Up @@ -360,6 +370,9 @@ cdef extern from "scip/scip.h":

ctypedef double SCIP_Real

ctypedef struct SCIP_RATIONAL:
pass

ctypedef struct SCIP:
pass

Expand All @@ -371,12 +384,18 @@ cdef extern from "scip/scip.h":

ctypedef struct SCIP_ROW:
pass

ctypedef struct SCIP_ROW_EXACT:
pass

ctypedef struct SCIP_NLROW:
pass

ctypedef struct SCIP_COL:
pass

ctypedef struct SCIP_COL_EXACT:
pass

ctypedef struct SCIP_SOL:
pass
Expand Down Expand Up @@ -426,6 +445,15 @@ cdef extern from "scip/scip.h":
ctypedef struct SCIP_HEURDATA:
pass

ctypedef struct SCIP_IISFINDER:
pass

ctypedef struct SCIP_IISFINDERDATA:
pass

ctypedef struct SCIP_IIS:
pass

ctypedef struct SCIP_RELAX:
pass

Expand Down Expand Up @@ -802,6 +830,11 @@ cdef extern from "scip/scip.h":
int SCIPgetNImplVars(SCIP* scip)
int SCIPgetNContVars(SCIP* scip)
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR* var)
SCIP_Bool SCIPvarIsBinary(SCIP_VAR* var)
SCIP_Bool SCIPvarIsIntegral(SCIP_VAR* var)
SCIP_Bool SCIPvarIsImpliedIntegral(SCIP_VAR* var)
SCIP_Bool SCIPvarIsNonimpliedIntegral(SCIP_VAR* var)
SCIP_IMPLINTTYPE SCIPvarGetImplType(SCIP_VAR* var)
SCIP_Bool SCIPvarIsOriginal(SCIP_VAR* var)
SCIP_Bool SCIPvarIsTransformed(SCIP_VAR* var)
SCIP_COL* SCIPvarGetCol(SCIP_VAR* var)
Expand Down Expand Up @@ -961,9 +994,10 @@ cdef extern from "scip/scip.h":
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,
SCIP_VAR** vars, int nvars, int nbinvars, int nintvars, int nimplvars, int ncontvars,
SCIP_VAR** fixedvars, int nfixedvars, int startnvars,
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,
SCIP_Bool genericnames, SCIP_RESULT* result),
SCIP_READERDATA* readerdata)
Expand Down Expand Up @@ -1156,6 +1190,20 @@ cdef extern from "scip/scip.h":
SCIP_HEURTIMING SCIPheurGetTimingmask(SCIP_HEUR* heur)
void SCIPheurSetTimingmask(SCIP_HEUR* heur, SCIP_HEURTIMING timingmask)

#IIS finder plugin
SCIP_RETCODE SCIPincludeIISfinder(SCIP* scip,
const char* name,
const char* desc,
int priority,
SCIP_RETCODE (*iisfindercopy) (SCIP* scip, SCIP_IISFINDER* iisfinder),
SCIP_RETCODE (*iisfinderfree) (SCIP* scip, SCIP_IISFINDER* iisfinder),
SCIP_RETCODE (*iisfinderexec) (SCIP_IIS* iis, SCIP_IISFINDER* iisfinder, SCIP_Real timelim, SCIP_Longint nodelim, SCIP_Bool removebounds, SCIP_Bool silent, SCIP_RESULT* result),
SCIP_IISFINDERDATA* iisfinderdata)

SCIP_IISFINDERDATA* SCIPiisfinderGetData(SCIP_IISFINDER* iisfinder)
SCIP_RETCODE SCIPincludeIISfinderGreedy(SCIP* scip)
SCIP_RETCODE SCIPiisGreedyMinimize(SCIP_IIS* iis);

#Relaxation plugin
SCIP_RETCODE SCIPincludeRelax(SCIP* scip,
const char* name,
Expand Down Expand Up @@ -1355,8 +1403,33 @@ cdef extern from "scip/scip.h":
SCIP_Bool SCIPisIntegral(SCIP* scip, SCIP_Real val)
SCIP_Real SCIPgetTreesizeEstimation(SCIP* scip)

# Exact SCIP methods
SCIP_RETCODE SCIPenableExactSolving(SCIP* scip, SCIP_Bool enable);
SCIP_Bool SCIPisExact(SCIP* scip);
SCIP_Bool SCIPallowNegSlack(SCIP* scip);
SCIP_RETCODE SCIPbranchLPExact(SCIP* scip, SCIP_RESULT* result);
SCIP_RETCODE SCIPaddRowExact(SCIP* scip, SCIP_ROWEXACT* rowexact);

# Exact LP SCIP methods
SCIP_VAR* SCIPcolExactGetVar(SCIP_COLEXACT* col);
SCIP_RATIONAL* SCIProwExactGetLhs(SCIP_ROWEXACT* row);
SCIP_RATIONAL* SCIProwExactGetRhs(SCIP_ROWEXACT* row);
SCIP_RATIONAL* SCIProwExactGetConstant(SCIP_ROWEXACT* row);
int SCIProwExactGetNNonz(SCIP_ROWEXACT* row);
SCIP_RATIONAL** SCIProwExactGetVals(SCIP_ROWEXACT* row);
SCIP_Bool SCIProwExactIsInLP(SCIP_ROWEXACT* row);
void SCIProwExactSort(SCIP_ROWEXACT* row);
SCIP_COLEXACT** SCIProwExactGetCols(SCIP_ROWEXACT* row);
void SCIProwExactLock(SCIP_ROWEXACT* row);
void SCIProwExactUnlock(SCIP_ROWEXACT* row);
SCIP_ROW* SCIProwExactGetRow(SCIP_ROWEXACT* row);
SCIP_ROW* SCIProwExactGetRowRhs(SCIP_ROWEXACT* row);
SCIP_Bool SCIProwExactHasFpRelax(SCIP_ROWEXACT* row);
SCIP_Bool SCIPlpExactDiving(SCIP_LPEXACT* lpexact);

# Statistic Methods
SCIP_RETCODE SCIPprintStatistics(SCIP* scip, FILE* outfile)
SCIP_RETCODE SCIPprintStatisticsJson(SCIP* scip, FILE* file)
SCIP_Longint SCIPgetNNodes(SCIP* scip)
SCIP_Longint SCIPgetNTotalNodes(SCIP* scip)
SCIP_Longint SCIPgetNFeasibleLeaves(SCIP* scip)
Expand Down Expand Up @@ -1429,11 +1502,6 @@ cdef extern from "scip/scip.h":

BMS_BLKMEM* SCIPblkmem(SCIP* scip)

# pub_misc.h
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP** hashmap, BMS_BLKMEM* blkmem, int mapsize)
void SCIPhashmapFree(SCIP_HASHMAP** hashmap)


cdef extern from "scip/tree.h":
int SCIPnodeGetNAddedConss(SCIP_NODE* node)

Expand Down Expand Up @@ -1591,7 +1659,6 @@ cdef extern from "scip/cons_sos1.h":
SCIP_CONS* cons,
SCIP_VAR* var)


cdef extern from "scip/cons_sos2.h":
SCIP_RETCODE SCIPcreateConsSOS2(SCIP* scip,
SCIP_CONS** cons,
Expand Down Expand Up @@ -1689,6 +1756,7 @@ cdef extern from "scip/cons_xor.h":
SCIP_Bool dynamic,
SCIP_Bool removable,
SCIP_Bool stickingatnode)

cdef extern from "scip/scip_cons.h":
SCIP_RETCODE SCIPprintCons(SCIP* scip,
SCIP_CONS* cons,
Expand Down Expand Up @@ -1843,7 +1911,6 @@ cdef extern from "scip/scip_nlp.h":
SCIP_RETCODE SCIPgetNlRowActivityBounds(SCIP* scip, SCIP_NLROW* nlrow, SCIP_Real* minactivity, SCIP_Real* maxactivity)
SCIP_RETCODE SCIPprintNlRow(SCIP* scip, SCIP_NLROW* nlrow, FILE* file)


cdef extern from "scip/cons_cardinality.h":
SCIP_RETCODE SCIPcreateConsCardinality(SCIP* scip,
SCIP_CONS** cons,
Expand Down Expand Up @@ -2016,6 +2083,14 @@ cdef class Column:
@staticmethod
cdef create(SCIP_COL* scipcol)

cdef class Column:
cdef SCIP_COLEXACT* scip_col_exact
# can be used to store problem data
cdef public object data

@staticmethod
cdef create(SCIP_COLEXACT* scipcol_exact)

cdef class Row:
cdef SCIP_ROW* scip_row
# can be used to store problem data
Expand All @@ -2024,6 +2099,14 @@ cdef class Row:
@staticmethod
cdef create(SCIP_ROW* sciprow)

cdef class RowExact:
cdef SCIP_ROWEXACT* scip_row_exact
# can be used to store problem data
cdef public object data

@staticmethod
cdef create(SCIP_ROWEXACT* sciprow_exact)

cdef class NLRow:
cdef SCIP_NLROW* scip_nlrow
# can be used to store problem data
Expand Down
Loading