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 27 commits into
base: master
Choose a base branch
from
Draft

SCIP 10 #1009

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6a4140b
Add printStatisticsJson
Joao-Dionisio May 28, 2025
3c50d40
Implied integer stuff
Joao-Dionisio May 31, 2025
45933b9
Add extra event types
Joao-Dionisio May 31, 2025
af1645d
minor fixes in relax.pxi
Joao-Dionisio May 31, 2025
a310db6
start of iisfinder plugin
Joao-Dionisio May 31, 2025
2fe7680
compilation, left iis for later
Joao-Dionisio Jun 3, 2025
a29aa5c
fix issues with exact scip. still no support
Joao-Dionisio Jun 3, 2025
15afb8e
Merge remote-tracking branch 'origin/master' into SCIP10
Joao-Dionisio Jun 5, 2025
6c126f7
fixed some tests
Joao-Dionisio Jun 5, 2025
b841b95
fix minor typos
Joao-Dionisio Jun 5, 2025
79c88a1
changelog so I don't forget
Joao-Dionisio Jun 5, 2025
703fd34
variable type tests
Joao-Dionisio Jun 5, 2025
f352c30
fix test_pricer bug
Joao-Dionisio Jun 11, 2025
97434b5
Merge branch 'master' into SCIP10
Joao-Dionisio Jun 17, 2025
81395b2
typo
Joao-Dionisio Jun 17, 2025
ae60d7e
IISfinder progress
Joao-Dionisio Jun 17, 2025
be3022e
Start of support for exact scip
Joao-Dionisio Jun 17, 2025
dc08654
Fix reader write (#1015)
DominikKamp Jul 2, 2025
ffcf001
Fix most compilation issues and warnings
Joao-Dionisio Jul 11, 2025
b417a92
Update IIS method and remove redeclaration
Joao-Dionisio Jul 11, 2025
5d2f440
Merge branch 'master' into SCIP10
Joao-Dionisio Jul 24, 2025
389ac74
Fix build error
Joao-Dionisio Jul 24, 2025
e2d9038
little IIS progress
Joao-Dionisio Jul 24, 2025
55c99bb
iis compilation
Joao-Dionisio Jul 24, 2025
3914760
some iis methods
Joao-Dionisio Jul 24, 2025
e9238a1
remove semicolons
Joao-Dionisio Jul 24, 2025
f9a781d
Change IIS methods imported
Joao-Dionisio Jul 26, 2025
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 @@ -9,6 +9,11 @@
- Added addMatrixConsIndicator(), and tests
- Added SCIPvarMarkRelaxationOnly, SCIPvarIsRelaxationOnly, SCIPvarMarkDeletable, SCIPvarIsDeletable, and tests
- Wrapped SCIPgetNLPBranchCands
- 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
2 changes: 1 addition & 1 deletion src/pyscipopt/event.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ cdef class Eventhdlr:


# local helper functions for the interface
cdef Eventhdlr getPyEventhdlr(SCIP_EVENTHDLR* eventhdlr) noexcept with gil:
cdef Eventhdlr getPyEventhdlr(SCIP_EVENTHDLR* eventhdlr):
cdef SCIP_EVENTHDLRDATA* eventhdlrdata
eventhdlrdata = SCIPeventhdlrGetData(eventhdlr)
return <Eventhdlr>eventhdlrdata
Expand Down
38 changes: 38 additions & 0 deletions src/pyscipopt/iisfinder.pxi
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
##@file iisfinder.pxi
#@brief Base class of the IIS finder Plugin
cdef class IISfinder:
cdef public Model model
cdef public str name
cdef SCIP_IIS* _iisfinder

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
120 changes: 98 additions & 22 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_ROWEXACT:
pass

ctypedef struct SCIP_NLROW:
pass

ctypedef struct SCIP_COL:
pass

ctypedef struct SCIP_COLEXACT:
pass

ctypedef struct SCIP_SOL:
pass
Expand Down Expand Up @@ -408,12 +427,6 @@ cdef extern from "scip/scip.h":
ctypedef struct SCIP_PROPDATA:
pass

ctypedef struct SCIP_PROPTIMING:
pass

ctypedef struct SCIP_PRESOLTIMING:
pass

ctypedef struct SCIP_PRESOL:
pass

Expand All @@ -426,6 +439,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 @@ -456,9 +478,6 @@ cdef extern from "scip/scip.h":
ctypedef struct SCIP_PRESOL:
pass

ctypedef struct SCIP_HEURTIMING:
pass

ctypedef struct SCIP_SEPA:
pass

Expand Down Expand Up @@ -507,10 +526,10 @@ cdef extern from "scip/scip.h":
ctypedef struct SCIP_LPI:
pass

ctypedef struct BMS_BLKMEM:
ctypedef struct SCIP_LPEXACT:
pass

ctypedef struct SCIP_EXPR:
ctypedef struct BMS_BLKMEM:
pass

ctypedef struct SCIP_EXPRHDLR:
Expand Down Expand Up @@ -707,7 +726,6 @@ cdef extern from "scip/scip.h":
SCIP_Real SCIPgetLocalTransEstimate(SCIP* scip)

# Solve Methods
SCIP_RETCODE SCIPsolve(SCIP* scip)
SCIP_RETCODE SCIPsolve(SCIP* scip) noexcept nogil
SCIP_RETCODE SCIPsolveConcurrent(SCIP* scip)
SCIP_RETCODE SCIPfreeTransform(SCIP* scip)
Expand Down Expand Up @@ -802,6 +820,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 @@ -965,9 +988,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 @@ -1160,6 +1184,23 @@ 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 SCIPgenerateIIS(SCIP* scip)
SCIP_RETCODE SCIPiisGreedyMakeIrreducible(SCIP_IIS* iis)
SCIP_Bool SCIPiisIsSubscipInfeasible(SCIP_IIS* iis)
SCIP_Bool SCIPiisIsSubscipIrreducible(SCIP_IIS* iis)
SCIP* SCIPiisGetSubscip(SCIP_IIS* iis)

#Relaxation plugin
SCIP_RETCODE SCIPincludeRelax(SCIP* scip,
const char* name,
Expand Down Expand Up @@ -1359,8 +1400,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 @@ -1433,11 +1499,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 @@ -1595,7 +1656,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 @@ -1700,6 +1760,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 @@ -1854,7 +1915,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 @@ -2027,6 +2087,14 @@ cdef class Column:
@staticmethod
cdef create(SCIP_COL* scipcol)

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

@staticmethod
cdef create(SCIP_COLEXACT* scip_col_exact)

cdef class Row:
cdef SCIP_ROW* scip_row
# can be used to store problem data
Expand All @@ -2035,6 +2103,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* scip_row_exact)

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