Skip to content

Commit 34e03a8

Browse files
add support for [get|set]HeurTiming (#940)
* add support for [get|set]HeurTiming * added test for heur timing * extend documentation * delete duplicate test, add CHANGELOG --------- Co-authored-by: Joao-Dionisio <[email protected]>
1 parent 6f51e81 commit 34e03a8

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
### Added
5+
- Added wrappers for setting and getting heuristic timing
56
- Added transformed option to getVarDict, updated test
67
- Added categorical data example
78
- Added printProblem to print problem to stdout

src/pyscipopt/scip.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,8 @@ cdef extern from "scip/scip.h":
11191119
SCIP_HEURDATA* heurdata)
11201120
SCIP_HEURDATA* SCIPheurGetData(SCIP_HEUR* heur)
11211121
SCIP_HEUR* SCIPfindHeur(SCIP* scip, const char* name)
1122+
SCIP_HEURTIMING SCIPheurGetTimingmask(SCIP_HEUR* heur)
1123+
void SCIPheurSetTimingmask(SCIP_HEUR* heur, SCIP_HEURTIMING timingmask)
11221124

11231125
#Relaxation plugin
11241126
SCIP_RETCODE SCIPincludeRelax(SCIP* scip,

src/pyscipopt/scip.pxi

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,6 +2887,43 @@ cdef class Model:
28872887
"""
28882888
PY_SCIP_CALL(SCIPsetHeuristics(self._scip, setting, True))
28892889

2890+
def setHeurTiming(self, heurname, heurtiming):
2891+
"""
2892+
Set the timing of a heuristic
2893+
2894+
Parameters
2895+
----------
2896+
heurname : string, name of the heuristic
2897+
heurtiming : PY_SCIP_HEURTIMING
2898+
positions in the node solving loop where heuristic should be executed
2899+
"""
2900+
cdef SCIP_HEUR* _heur
2901+
n = str_conversion(heurname)
2902+
_heur = SCIPfindHeur(self._scip, n)
2903+
if _heur == NULL:
2904+
raise ValueError("Could not find heuristic <%s>" % heurname)
2905+
SCIPheurSetTimingmask(_heur, heurtiming)
2906+
2907+
def getHeurTiming(self, heurname):
2908+
"""
2909+
Get the timing of a heuristic
2910+
2911+
Parameters
2912+
----------
2913+
heurname : string, name of the heuristic
2914+
2915+
Returns
2916+
-------
2917+
PY_SCIP_HEURTIMING
2918+
positions in the node solving loop where heuristic should be executed
2919+
"""
2920+
cdef SCIP_HEUR* _heur
2921+
n = str_conversion(heurname)
2922+
_heur = SCIPfindHeur(self._scip, n)
2923+
if _heur == NULL:
2924+
raise ValueError("Could not find heuristic <%s>" % heurname)
2925+
return SCIPheurGetTimingmask(_heur)
2926+
28902927
def disablePropagation(self, onlyroot=False):
28912928
"""
28922929
Disables propagation in SCIP to avoid modifying the original problem during transformation.

tests/test_heur.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,8 @@ def test_simple_round_heur():
130130
timingmask=SCIP_HEURTIMING.DURINGLPLOOP)
131131
# solve problem
132132
s.optimize()
133+
134+
def test_heurTiming():
135+
model = Model()
136+
model.setHeurTiming('rins', SCIP_HEURTIMING.BEFORENODE)
137+
print("timing of rins: %d\n" % model.getHeurTiming('rins'))

0 commit comments

Comments
 (0)