-
Notifications
You must be signed in to change notification settings - Fork 279
Expand file tree
/
Copy pathnodesel.pxi
More file actions
104 lines (84 loc) · 3.26 KB
/
nodesel.pxi
File metadata and controls
104 lines (84 loc) · 3.26 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
##@file nodesel.pxi
#@brief Base class of the Nodesel Plugin
cdef class Nodesel:
cdef public Model model
def nodefree(self):
'''frees memory of node selector'''
pass
def nodeinit(self):
''' executed after the problem is transformed. use this call to initialize node selector data.'''
pass
def nodeexit(self):
'''executed before the transformed problem is freed'''
pass
def nodeinitsol(self):
'''executed when the presolving is finished and the branch-and-bound process is about to begin'''
pass
def nodeexitsol(self):
'''executed before the branch-and-bound process is freed'''
pass
def nodeselect(self):
'''first method called in each iteration in the main solving loop. '''
# this method needs to be implemented by the user
return {}
def nodecomp(self, node1, node2):
'''
compare two leaves of the current branching tree
It should return the following values:
value < 0, if node 1 comes before (is better than) node 2
value = 0, if both nodes are equally good
value > 0, if node 1 comes after (is worse than) node 2.
'''
# this method needs to be implemented by the user
return 0
cdef SCIP_RETCODE PyNodeselCopy (SCIP* scip, SCIP_NODESEL* nodesel) noexcept with gil:
return SCIP_OKAY
cdef SCIP_RETCODE PyNodeselFree (SCIP* scip, SCIP_NODESEL* nodesel) noexcept with gil:
cdef SCIP_NODESELDATA* nodeseldata
nodeseldata = SCIPnodeselGetData(nodesel)
PyNodesel = <Nodesel>nodeseldata
PyNodesel.nodefree()
return SCIP_OKAY
cdef SCIP_RETCODE PyNodeselInit (SCIP* scip, SCIP_NODESEL* nodesel) noexcept with gil:
cdef SCIP_NODESELDATA* nodeseldata
nodeseldata = SCIPnodeselGetData(nodesel)
PyNodesel = <Nodesel>nodeseldata
PyNodesel.nodeinit()
return SCIP_OKAY
cdef SCIP_RETCODE PyNodeselExit (SCIP* scip, SCIP_NODESEL* nodesel) noexcept with gil:
cdef SCIP_NODESELDATA* nodeseldata
nodeseldata = SCIPnodeselGetData(nodesel)
PyNodesel = <Nodesel>nodeseldata
PyNodesel.nodeexit()
return SCIP_OKAY
cdef SCIP_RETCODE PyNodeselInitsol (SCIP* scip, SCIP_NODESEL* nodesel) noexcept with gil:
cdef SCIP_NODESELDATA* nodeseldata
nodeseldata = SCIPnodeselGetData(nodesel)
PyNodesel = <Nodesel>nodeseldata
PyNodesel.nodeinitsol()
return SCIP_OKAY
cdef SCIP_RETCODE PyNodeselExitsol (SCIP* scip, SCIP_NODESEL* nodesel) noexcept with gil:
cdef SCIP_NODESELDATA* nodeseldata
nodeseldata = SCIPnodeselGetData(nodesel)
PyNodesel = <Nodesel>nodeseldata
PyNodesel.nodeexitsol()
return SCIP_OKAY
cdef SCIP_RETCODE PyNodeselSelect (SCIP* scip, SCIP_NODESEL* nodesel, SCIP_NODE** selnode) noexcept with gil:
cdef SCIP_NODESELDATA* nodeseldata
nodeseldata = SCIPnodeselGetData(nodesel)
PyNodesel = <Nodesel>nodeseldata
result_dict = PyNodesel.nodeselect()
selected_node = <Node>result_dict.get("selnode", None)
if selected_node == None:
selnode[0] = NULL
else:
selnode[0] = selected_node.scip_node
return SCIP_OKAY
cdef int PyNodeselComp (SCIP* scip, SCIP_NODESEL* nodesel, SCIP_NODE* node1, SCIP_NODE* node2) noexcept with gil:
cdef SCIP_NODESELDATA* nodeseldata
nodeseldata = SCIPnodeselGetData(nodesel)
PyNodesel = <Nodesel>nodeseldata
n1 = Node.create(node1)
n2 = Node.create(node2)
result = PyNodesel.nodecomp(n1, n2) #
return result