PySCIPOpt
Python Interface to the SCIP Optimization Suite
heuristic.pxi
Go to the documentation of this file.
1 ##@file heuristic.pxi
2 #@brief Base class of the Heuristics Plugin
3 cdef class Heur:
4  cdef public Model model
5  cdef public str name
6 
7  def heurfree(self):
8  '''calls destructor and frees memory of primal heuristic'''
9  pass
10 
11  def heurinit(self):
12  '''initializes primal heuristic'''
13  pass
14 
15  def heurexit(self):
16  '''calls exit method of primal heuristic'''
17  pass
18 
19  def heurinitsol(self):
20  '''informs primal heuristic that the branch and bound process is being started'''
21  pass
22 
23  def heurexitsol(self):
24  '''informs primal heuristic that the branch and bound process data is being freed'''
25  pass
26 
27  def heurexec(self, heurtiming, nodeinfeasible):
28  '''should the heuristic the executed at the given depth, frequency, timing,...'''
29  print("python error in heurexec: this method needs to be implemented")
30  return {}
31 
32 
33 
34 cdef SCIP_RETCODE PyHeurCopy (SCIP* scip, SCIP_HEUR* heur):
35  return SCIP_OKAY
36 
37 cdef SCIP_RETCODE PyHeurFree (SCIP* scip, SCIP_HEUR* heur):
38  cdef SCIP_HEURDATA* heurdata
39  heurdata = SCIPheurGetData(heur)
40  PyHeur = <Heur>heurdata
41  PyHeur.heurfree()
42  Py_DECREF(PyHeur)
43  return SCIP_OKAY
44 
45 cdef SCIP_RETCODE PyHeurInit (SCIP* scip, SCIP_HEUR* heur):
46  cdef SCIP_HEURDATA* heurdata
47  heurdata = SCIPheurGetData(heur)
48  PyHeur = <Heur>heurdata
49  PyHeur.heurinit()
50  return SCIP_OKAY
51 
52 cdef SCIP_RETCODE PyHeurExit (SCIP* scip, SCIP_HEUR* heur):
53  cdef SCIP_HEURDATA* heurdata
54  heurdata = SCIPheurGetData(heur)
55  PyHeur = <Heur>heurdata
56  PyHeur.heurexit()
57  return SCIP_OKAY
58 
59 cdef SCIP_RETCODE PyHeurInitsol (SCIP* scip, SCIP_HEUR* heur):
60  cdef SCIP_HEURDATA* heurdata
61  heurdata = SCIPheurGetData(heur)
62  PyHeur = <Heur>heurdata
63  PyHeur.heurinitsol()
64  return SCIP_OKAY
65 
66 cdef SCIP_RETCODE PyHeurExitsol (SCIP* scip, SCIP_HEUR* heur):
67  cdef SCIP_HEURDATA* heurdata
68  heurdata = SCIPheurGetData(heur)
69  PyHeur = <Heur>heurdata
70  PyHeur.heurexitsol()
71  return SCIP_OKAY
72 
73 cdef SCIP_RETCODE PyHeurExec (SCIP* scip, SCIP_HEUR* heur, SCIP_HEURTIMING heurtiming, SCIP_Bool nodeinfeasible, SCIP_RESULT* result):
74  cdef SCIP_HEURDATA* heurdata
75  heurdata = SCIPheurGetData(heur)
76  PyHeur = <Heur>heurdata
77  result_dict = PyHeur.heurexec(heurtiming, nodeinfeasible)
78  result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
79  return SCIP_OKAY
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)