forked from scipopt/PySCIPOpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.pxi
88 lines (70 loc) · 2.73 KB
/
event.pxi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
##@file event.pxi
#@brief Base class of the Event Handler Plugin
cdef class Eventhdlr:
cdef public Model model
cdef public str name
def eventcopy(self):
'''sets copy callback for all events of this event handler '''
pass
def eventfree(self):
'''calls destructor and frees memory of event handler '''
pass
def eventinit(self):
'''initializes event handler'''
pass
def eventexit(self):
'''calls exit method of event handler'''
pass
def eventinitsol(self):
'''informs event handler that the branch and bound process is being started '''
pass
def eventexitsol(self):
'''informs event handler that the branch and bound process data is being freed '''
pass
def eventdelete(self):
'''sets callback to free specific event data'''
pass
def eventexec(self, event):
'''calls execution method of event handler '''
print("python error in eventexec: this method needs to be implemented")
return {}
# local helper functions for the interface
cdef Eventhdlr getPyEventhdlr(SCIP_EVENTHDLR* eventhdlr):
cdef SCIP_EVENTHDLRDATA* eventhdlrdata
eventhdlrdata = SCIPeventhdlrGetData(eventhdlr)
return <Eventhdlr>eventhdlrdata
cdef SCIP_RETCODE PyEventCopy (SCIP* scip, SCIP_EVENTHDLR* eventhdlr):
PyEventhdlr = getPyEventhdlr(eventhdlr)
PyEventhdlr.eventcopy()
return SCIP_OKAY
cdef SCIP_RETCODE PyEventFree (SCIP* scip, SCIP_EVENTHDLR* eventhdlr):
PyEventhdlr = getPyEventhdlr(eventhdlr)
PyEventhdlr.eventfree()
Py_DECREF(PyEventhdlr)
return SCIP_OKAY
cdef SCIP_RETCODE PyEventInit (SCIP* scip, SCIP_EVENTHDLR* eventhdlr):
PyEventhdlr = getPyEventhdlr(eventhdlr)
PyEventhdlr.eventinit()
return SCIP_OKAY
cdef SCIP_RETCODE PyEventExit (SCIP* scip, SCIP_EVENTHDLR* eventhdlr):
PyEventhdlr = getPyEventhdlr(eventhdlr)
PyEventhdlr.eventexit()
return SCIP_OKAY
cdef SCIP_RETCODE PyEventInitsol (SCIP* scip, SCIP_EVENTHDLR* eventhdlr):
PyEventhdlr = getPyEventhdlr(eventhdlr)
PyEventhdlr.eventinitsol()
return SCIP_OKAY
cdef SCIP_RETCODE PyEventExitsol (SCIP* scip, SCIP_EVENTHDLR* eventhdlr):
PyEventhdlr = getPyEventhdlr(eventhdlr)
PyEventhdlr.eventexitsol()
return SCIP_OKAY
cdef SCIP_RETCODE PyEventDelete (SCIP* scip, SCIP_EVENTHDLR* eventhdlr, SCIP_EVENTDATA** eventdata):
PyEventhdlr = getPyEventhdlr(eventhdlr)
PyEventhdlr.eventdelete()
return SCIP_OKAY
cdef SCIP_RETCODE PyEventExec (SCIP* scip, SCIP_EVENTHDLR* eventhdlr, SCIP_EVENT* event, SCIP_EVENTDATA* eventdata):
PyEventhdlr = getPyEventhdlr(eventhdlr)
PyEvent = Event()
PyEvent.event = event
PyEventhdlr.eventexec(PyEvent)
return SCIP_OKAY