diff --git a/CHANGELOG.md b/CHANGELOG.md index cc662cc45..b323dd31d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased ### Added +- Added wrappers for setting and getting heuristic timing - Added transformed option to getVarDict, updated test - Added categorical data example - Added printProblem to print problem to stdout diff --git a/src/pyscipopt/scip.pxd b/src/pyscipopt/scip.pxd index 2b629053c..013faf9d0 100644 --- a/src/pyscipopt/scip.pxd +++ b/src/pyscipopt/scip.pxd @@ -1119,6 +1119,8 @@ cdef extern from "scip/scip.h": SCIP_HEURDATA* heurdata) SCIP_HEURDATA* SCIPheurGetData(SCIP_HEUR* heur) SCIP_HEUR* SCIPfindHeur(SCIP* scip, const char* name) + SCIP_HEURTIMING SCIPheurGetTimingmask(SCIP_HEUR* heur) + void SCIPheurSetTimingmask(SCIP_HEUR* heur, SCIP_HEURTIMING timingmask) #Relaxation plugin SCIP_RETCODE SCIPincludeRelax(SCIP* scip, diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index d95e45ea2..e7bb98955 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -2887,6 +2887,43 @@ cdef class Model: """ PY_SCIP_CALL(SCIPsetHeuristics(self._scip, setting, True)) + def setHeurTiming(self, heurname, heurtiming): + """ + Set the timing of a heuristic + + Parameters + ---------- + heurname : string, name of the heuristic + heurtiming : PY_SCIP_HEURTIMING + positions in the node solving loop where heuristic should be executed + """ + cdef SCIP_HEUR* _heur + n = str_conversion(heurname) + _heur = SCIPfindHeur(self._scip, n) + if _heur == NULL: + raise ValueError("Could not find heuristic <%s>" % heurname) + SCIPheurSetTimingmask(_heur, heurtiming) + + def getHeurTiming(self, heurname): + """ + Get the timing of a heuristic + + Parameters + ---------- + heurname : string, name of the heuristic + + Returns + ------- + PY_SCIP_HEURTIMING + positions in the node solving loop where heuristic should be executed + """ + cdef SCIP_HEUR* _heur + n = str_conversion(heurname) + _heur = SCIPfindHeur(self._scip, n) + if _heur == NULL: + raise ValueError("Could not find heuristic <%s>" % heurname) + return SCIPheurGetTimingmask(_heur) + def disablePropagation(self, onlyroot=False): """ Disables propagation in SCIP to avoid modifying the original problem during transformation. diff --git a/tests/test_heur.py b/tests/test_heur.py index 454f11c74..a625475a7 100644 --- a/tests/test_heur.py +++ b/tests/test_heur.py @@ -130,3 +130,8 @@ def test_simple_round_heur(): timingmask=SCIP_HEURTIMING.DURINGLPLOOP) # solve problem s.optimize() + +def test_heurTiming(): + model = Model() + model.setHeurTiming('rins', SCIP_HEURTIMING.BEFORENODE) + print("timing of rins: %d\n" % model.getHeurTiming('rins'))