Skip to content
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

add support for [get|set]HeurTiming #940

Merged
merged 4 commits into from
Dec 16, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/pyscipopt/scip.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
37 changes: 37 additions & 0 deletions src/pyscipopt/scip.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
if rc == SCIP_OKAY:
pass
elif rc == SCIP_ERROR:
raise Exception('SCIP: unspecified error!')

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.8)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / test-coverage (3.11)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.8)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.9)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.9)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.10)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.10)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.11)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.12)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.11)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.12)

SCIP: unspecified error!
elif rc == SCIP_NOMEMORY:
raise MemoryError('SCIP: insufficient memory error!')
elif rc == SCIP_READERROR:
Expand Down Expand Up @@ -2887,6 +2887,43 @@
"""
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.
Expand Down
5 changes: 5 additions & 0 deletions tests/test_heur.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Loading