Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4a6f29c
Adds cutsel plugin
Opt-Mucca Oct 1, 2020
b7e802e
Adds basic test_cutsel
Opt-Mucca Oct 6, 2020
7c73906
Makes test_cutsel more difficult, and actually use the cut-selector
Opt-Mucca Oct 6, 2020
5a05149
Adds intsupport and objparal getter functions
Opt-Mucca Oct 6, 2020
d808fd7
Removed bug with sorting forcedcuts
Opt-Mucca Oct 19, 2020
d2ad633
Adds getRowParallelism function to scip calls
Opt-Mucca Nov 25, 2020
541d059
Adds SCIP(rowIsLocal,rowIsInGlobalCutPool,getCutLPSolCutoffDistance)
Opt-Mucca Nov 25, 2020
3d026fd
Removes PY_SCIP_CALL wrapper in getRowNumIntCols
Opt-Mucca Nov 26, 2020
0898b8f
Solution is now mandatorz for getCutLPSolCutoffDistance call
Opt-Mucca Nov 26, 2020
fea2e2c
Merge branch 'master' into mt/cut_selector_plugin
Opt-Mucca Nov 26, 2020
cfcb6b3
Corrects the sorting order of the test_cutsel
Opt-Mucca Mar 2, 2021
10a5185
Fixed misspelling of parallel and adds getRowLinear()
Opt-Mucca Mar 2, 2021
39e47b0
Fixes error with misses arg in PySepaExecSol
Opt-Mucca Mar 2, 2021
a5a80f6
Merge branch 'mt/cut_selector_plugin' of https://github.com/scipopt/P…
Opt-Mucca Mar 2, 2021
dd4ddd2
Adds missing depth argument to PySepaExecsol
Opt-Mucca Mar 2, 2021
012503c
Adds getdualsolval functionality
Opt-Mucca Mar 2, 2021
420cc38
merge error with partial fix from ZIB PC
Opt-Mucca Mar 2, 2021
3f08951
Should look more cloesly at the conflict....
Opt-Mucca Mar 2, 2021
2e1a3cb
Adds wrapper method for retrieval of dual sol of a row
Opt-Mucca Mar 3, 2021
4c0c1ff
Adds wrapped functions for objective coefficient retrieval and norm o…
Opt-Mucca Mar 3, 2021
8eef240
Adds scipGetNSepaRounds call
Opt-Mucca Jun 14, 2021
8b315f2
Adds writing of best transformed solution
Opt-Mucca Sep 16, 2021
8cf54c1
Adds writeTransSol method
Opt-Mucca Sep 17, 2021
89dc54c
Merges master for SCIP 8.0 into branch
Opt-Mucca Jan 18, 2022
4056247
Adds gil calls to cutsel functions
Opt-Mucca Jan 31, 2022
4fe2734
Updates CHANGELOG
Opt-Mucca Feb 22, 2022
d48441c
merge master into branch
Opt-Mucca Feb 22, 2022
62ea745
Merge branch 'master' into mt/cut_selector_plugin
Opt-Mucca Feb 22, 2022
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
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@

## Unreleased
### Added
- Interface to include custom cut selector plugins
- New test for cut selector plugin
- Add SCIP function SCIPgetCutLPSolCutoffDistance and wrapper getCutLPSolCutoffDistance
- Add SCIP function SCIPprintBestTransSol and wrapper writeBestTransSol
- Add SCIP function SCIPprintTransSol and wrapper writeTransSol
- Add SCIP function SCIPgetRowNumIntCols and wrapper getRowNumIntCols
- Add SCIP function SCIProwGetNNonz and wrapper rowGetNNonz
- Add SCIP function SCIPgetRowObjParallelism and wrapper getRowObjParallelism
- Add SCIP function SCIPgetNSepaRounds and wrapper getNSepaRounds
- Add SCIP function SCIPgetRowLinear and wrapper getRowLinear
- Add SCIP function SCIProwIsInGlobalCutpool and wrapper isInGlobalCutpool
- Add SCIP function SCIProwGetParallelism and wrapper getRowParallelism
- Add getObjCoeff call to Column
- Add isLocal call to Row
- Add getNorm call to Row
- Add getRowDualSol to Row
- Add getDualSolVal to Model
- added activeone parameter of addConsIndicator() allows to activate the constraint if the binary (indicator) variable is 1 or 0.
- added function getSlackVarIndicator(), returns the slack variable of the indicator constraint.
### Fixed
- cmake / make install works from build directory
### Changed

### Removed

## 4.0.0 - 2021-12-15
Expand Down
99 changes: 99 additions & 0 deletions src/pyscipopt/cutsel.pxi
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
##@file cutsel.pxi
#@brief Base class of the Cutsel Plugin
cdef class Cutsel:
cdef public Model model

def cutselfree(self):
'''frees memory of cut selector'''
pass

def cutselinit(self):
''' executed after the problem is transformed. use this call to initialize cut selector data.'''
pass

def cutselexit(self):
'''executed before the transformed problem is freed'''
pass

def cutselinitsol(self):
'''executed when the presolving is finished and the branch-and-bound process is about to begin'''
pass

def cutselexitsol(self):
'''executed before the branch-and-bound process is freed'''
pass

def cutselselect(self, cuts, forcedcuts, root, maxnselectedcuts):
'''first method called in each iteration in the main solving loop. '''
# this method needs to be implemented by the user
return {}


cdef SCIP_RETCODE PyCutselCopy (SCIP* scip, SCIP_CUTSEL* cutsel) with gil:
return SCIP_OKAY

cdef SCIP_RETCODE PyCutselFree (SCIP* scip, SCIP_CUTSEL* cutsel) with gil:
cdef SCIP_CUTSELDATA* cutseldata
cutseldata = SCIPcutselGetData(cutsel)
PyCutsel = <Cutsel>cutseldata
PyCutsel.cutselfree()
Py_DECREF(PyCutsel)
return SCIP_OKAY

cdef SCIP_RETCODE PyCutselInit (SCIP* scip, SCIP_CUTSEL* cutsel) with gil:
cdef SCIP_CUTSELDATA* cutseldata
cutseldata = SCIPcutselGetData(cutsel)
PyCutsel = <Cutsel>cutseldata
PyCutsel.cutselinit()
return SCIP_OKAY


cdef SCIP_RETCODE PyCutselExit (SCIP* scip, SCIP_CUTSEL* cutsel) with gil:
cdef SCIP_CUTSELDATA* cutseldata
cutseldata = SCIPcutselGetData(cutsel)
PyCutsel = <Cutsel>cutseldata
PyCutsel.cutselexit()
return SCIP_OKAY

cdef SCIP_RETCODE PyCutselInitsol (SCIP* scip, SCIP_CUTSEL* cutsel) with gil:
cdef SCIP_CUTSELDATA* cutseldata
cutseldata = SCIPcutselGetData(cutsel)
PyCutsel = <Cutsel>cutseldata
PyCutsel.cutselinitsol()
return SCIP_OKAY

cdef SCIP_RETCODE PyCutselExitsol (SCIP* scip, SCIP_CUTSEL* cutsel) with gil:
cdef SCIP_CUTSELDATA* cutseldata
cutseldata = SCIPcutselGetData(cutsel)
PyCutsel = <Cutsel>cutseldata
PyCutsel.cutselexitsol()
return SCIP_OKAY

cdef SCIP_RETCODE PyCutselSelect (SCIP* scip, SCIP_CUTSEL* cutsel, SCIP_ROW** cuts, int ncuts,
SCIP_ROW** forcedcuts, int nforcedcuts, SCIP_Bool root, int maxnselectedcuts,
int* nselectedcuts, SCIP_RESULT* result) with gil:
cdef SCIP_CUTSELDATA* cutseldata
cdef SCIP_ROW* scip_row
cutseldata = SCIPcutselGetData(cutsel)
PyCutsel = <Cutsel>cutseldata

# translate cuts to python
pycuts = [Row.create(cuts[i]) for i in range(ncuts)]
pyforcedcuts = [Row.create(forcedcuts[i]) for i in range(nforcedcuts)]
result_dict = PyCutsel.cutselselect(pycuts, pyforcedcuts, root, maxnselectedcuts)

# Retrieve the sorted cuts. Note that these do not need to be returned explicitly in result_dict.
# Pycuts could have been sorted in place in cutselselect()
pycuts = result_dict.get('cuts', pycuts)

assert len(pycuts) == ncuts
assert len(pyforcedcuts) == nforcedcuts

#sort cuts
for i,cut in enumerate(pycuts):
cuts[i] = <SCIP_ROW *>((<Row>cut).scip_row)

nselectedcuts[0] = result_dict.get('nselectedcuts', 0)
result[0] = result_dict.get('result', <SCIP_RESULT>result[0])

return SCIP_OKAY
34 changes: 34 additions & 0 deletions src/pyscipopt/scip.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ cdef extern from "scip/scip.h":
ctypedef struct SCIP_BRANCHRULEDATA:
pass

ctypedef struct SCIP_CUTSEL:
pass

ctypedef struct SCIP_CUTSELDATA:
pass

ctypedef struct SCIP_PRESOL:
pass

Expand Down Expand Up @@ -736,6 +742,7 @@ cdef extern from "scip/scip.h":
SCIP_RETCODE SCIPaddPoolCut(SCIP* scip, SCIP_ROW* row)
SCIP_Real SCIPgetCutEfficacy(SCIP* scip, SCIP_SOL* sol, SCIP_ROW* cut)
SCIP_Bool SCIPisCutEfficacious(SCIP* scip, SCIP_SOL* sol, SCIP_ROW* cut)
SCIP_Real SCIPgetCutLPSolCutoffDistance(SCIP* scip, SCIP_SOL* sol, SCIP_ROW* cut)
int SCIPgetNCuts(SCIP* scip)
int SCIPgetNCutsApplied(SCIP* scip)
SCIP_RETCODE SCIPseparateSol(SCIP* scip, SCIP_SOL* sol, SCIP_Bool pretendroot, SCIP_Bool allowlocal, SCIP_Bool onlydelayed, SCIP_Bool* delayed, SCIP_Bool* cutoff)
Expand Down Expand Up @@ -789,7 +796,9 @@ cdef extern from "scip/scip.h":
SCIP_RETCODE SCIPtrySol(SCIP* scip, SCIP_SOL* sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool* stored)
SCIP_RETCODE SCIPfreeSol(SCIP* scip, SCIP_SOL** sol)
SCIP_RETCODE SCIPprintBestSol(SCIP* scip, FILE* outfile, SCIP_Bool printzeros)
SCIP_RETCODE SCIPprintBestTransSol(SCIP* scip, FILE* outfile, SCIP_Bool printzeros)
SCIP_RETCODE SCIPprintSol(SCIP* scip, SCIP_SOL* sol, FILE* outfile, SCIP_Bool printzeros)
SCIP_RETCODE SCIPprintTransSol(SCIP* scip, SCIP_SOL* sol, FILE* outfile, SCIP_Bool printzeros)
SCIP_Real SCIPgetPrimalbound(SCIP* scip)
SCIP_Real SCIPgetGap(SCIP* scip)
int SCIPgetDepth(SCIP* scip)
Expand All @@ -815,6 +824,9 @@ cdef extern from "scip/scip.h":
SCIP_RETCODE SCIPflushRowExtensions(SCIP* scip, SCIP_ROW* row)
SCIP_RETCODE SCIPaddVarToRow(SCIP* scip, SCIP_ROW* row, SCIP_VAR* var, SCIP_Real val)
SCIP_RETCODE SCIPprintRow(SCIP* scip, SCIP_ROW* row, FILE* file)
int SCIPgetRowNumIntCols(SCIP* scip, SCIP_ROW* row)
int SCIProwGetNNonz(SCIP_ROW* row)
SCIP_Real SCIPgetRowObjParallelism(SCIP* scip, SCIP_ROW* row)

# Column Methods
SCIP_Real SCIPgetColRedcost(SCIP* scip, SCIP_COL* col)
Expand Down Expand Up @@ -1081,6 +1093,24 @@ cdef extern from "scip/scip.h":
const char* SCIPbranchruleGetName(SCIP_BRANCHRULE* branchrule)
SCIP_BRANCHRULE* SCIPfindBranchrule(SCIP* scip, const char* name)

# cut selector plugin
SCIP_RETCODE SCIPincludeCutsel(SCIP* scip,
const char* name,
const char* desc,
int priority,
SCIP_RETCODE (*cutselcopy) (SCIP* scip, SCIP_CUTSEL* cutsel),
SCIP_RETCODE (*cutselfree) (SCIP* scip, SCIP_CUTSEL* cutsel),
SCIP_RETCODE (*cutselinit) (SCIP* scip, SCIP_CUTSEL* cutsel),
SCIP_RETCODE (*cutselexit) (SCIP* scip, SCIP_CUTSEL* cutsel),
SCIP_RETCODE (*cutselinitsol) (SCIP* scip, SCIP_CUTSEL* cutsel),
SCIP_RETCODE (*cutselexitsol) (SCIP* scip, SCIP_CUTSEL* cutsel),
SCIP_RETCODE (*cutselselect) (SCIP* scip, SCIP_CUTSEL* cutsel, SCIP_ROW** cuts,
int ncuts, SCIP_ROW** forcedcuts, int nforcedcuts,
SCIP_Bool root, int maxnselectedcuts,
int* nselectedcuts, SCIP_RESULT* result),
SCIP_CUTSELDATA* cutseldata)
SCIP_CUTSELDATA* SCIPcutselGetData(SCIP_CUTSEL* cutsel)

# Benders' decomposition plugin
SCIP_RETCODE SCIPincludeBenders(SCIP* scip,
const char* name,
Expand Down Expand Up @@ -1198,6 +1228,7 @@ cdef extern from "scip/scip.h":
SCIP_Longint SCIPgetNInfeasibleLeaves(SCIP* scip)
SCIP_Longint SCIPgetNLPs(SCIP* scip)
SCIP_Longint SCIPgetNLPIterations(SCIP* scip)
int SCIPgetNSepaRounds(SCIP* scip)

# Parameter Functions
SCIP_RETCODE SCIPsetBoolParam(SCIP* scip, char* name, SCIP_Bool value)
Expand Down Expand Up @@ -1301,6 +1332,7 @@ cdef extern from "scip/cons_linear.h":
SCIP_VAR** SCIPgetVarsLinear(SCIP* scip, SCIP_CONS* cons)
int SCIPgetNVarsLinear(SCIP* scip, SCIP_CONS* cons)
SCIP_Real* SCIPgetValsLinear(SCIP* scip, SCIP_CONS* cons)
SCIP_ROW* SCIPgetRowLinear(SCIP* scip, SCIP_CONS* cons)

cdef extern from "scip/cons_nonlinear.h":
SCIP_EXPR* SCIPgetExprNonlinear(SCIP_CONS* cons)
Expand Down Expand Up @@ -1690,12 +1722,14 @@ cdef extern from "scip/pub_lp.h":
SCIP_Bool SCIProwIsLocal(SCIP_ROW* row)
SCIP_Bool SCIProwIsModifiable(SCIP_ROW* row)
SCIP_Bool SCIProwIsRemovable(SCIP_ROW* row)
SCIP_Bool SCIProwIsInGlobalCutpool(SCIP_ROW* row)
int SCIProwGetNNonz(SCIP_ROW* row)
int SCIProwGetNLPNonz(SCIP_ROW* row)
SCIP_COL** SCIProwGetCols(SCIP_ROW* row)
SCIP_Real* SCIProwGetVals(SCIP_ROW* row)
SCIP_Real SCIProwGetNorm(SCIP_ROW* row)
SCIP_Real SCIProwGetDualsol(SCIP_ROW* row)
SCIP_Real SCIProwGetParallelism(SCIP_ROW* row1, SCIP_ROW* row2, const char orthofunc)
int SCIProwGetAge(SCIP_ROW* row)
SCIP_Bool SCIProwIsRemovable(SCIP_ROW* row)
SCIP_ROWORIGINTYPE SCIProwGetOrigintype(SCIP_ROW* row)
Expand Down
Loading