forked from scipopt/PySCIPOpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
propagator.pxi
163 lines (138 loc) · 5.93 KB
/
propagator.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
##@file propagator.pxi
#@brief Base class of the Propagators Plugin
cdef class Prop:
cdef public Model model
def propfree(self):
'''calls destructor and frees memory of propagator'''
pass
def propinit(self):
'''initializes propagator'''
pass
def propexit(self):
'''calls exit method of propagator'''
pass
def propinitsol(self):
'''informs propagator that the prop and bound process is being started'''
pass
def propexitsol(self, restart):
'''informs propagator that the prop and bound process data is being freed'''
pass
def propinitpre(self):
'''informs propagator that the presolving process is being started'''
pass
def propexitpre(self):
'''informs propagator that the presolving process is finished'''
pass
def proppresol(self, nrounds, presoltiming, result_dict):
'''executes presolving method of propagator'''
pass
def propexec(self, proptiming):
'''calls execution method of propagator'''
print("python error in propexec: this method needs to be implemented")
return {}
def propresprop(self, confvar, inferinfo, bdtype, relaxedbd):
'''resolves the given conflicting bound, that was reduced by the given propagator'''
print("python error in propresprop: this method needs to be implemented")
return {}
cdef SCIP_RETCODE PyPropCopy (SCIP* scip, SCIP_PROP* prop):
return SCIP_OKAY
cdef SCIP_RETCODE PyPropFree (SCIP* scip, SCIP_PROP* prop):
cdef SCIP_PROPDATA* propdata
propdata = SCIPpropGetData(prop)
PyProp = <Prop>propdata
PyProp.propfree()
Py_DECREF(PyProp)
return SCIP_OKAY
cdef SCIP_RETCODE PyPropInit (SCIP* scip, SCIP_PROP* prop):
cdef SCIP_PROPDATA* propdata
propdata = SCIPpropGetData(prop)
PyProp = <Prop>propdata
PyProp.propinit()
return SCIP_OKAY
cdef SCIP_RETCODE PyPropExit (SCIP* scip, SCIP_PROP* prop):
cdef SCIP_PROPDATA* propdata
propdata = SCIPpropGetData(prop)
PyProp = <Prop>propdata
PyProp.propexit()
return SCIP_OKAY
cdef SCIP_RETCODE PyPropInitpre (SCIP* scip, SCIP_PROP* prop):
cdef SCIP_PROPDATA* propdata
propdata = SCIPpropGetData(prop)
PyProp = <Prop>propdata
PyProp.propinitpre()
return SCIP_OKAY
cdef SCIP_RETCODE PyPropExitpre (SCIP* scip, SCIP_PROP* prop):
cdef SCIP_PROPDATA* propdata
propdata = SCIPpropGetData(prop)
PyProp = <Prop>propdata
PyProp.propexitpre()
return SCIP_OKAY
cdef SCIP_RETCODE PyPropInitsol (SCIP* scip, SCIP_PROP* prop):
cdef SCIP_PROPDATA* propdata
propdata = SCIPpropGetData(prop)
PyProp = <Prop>propdata
PyProp.propinitsol()
return SCIP_OKAY
cdef SCIP_RETCODE PyPropExitsol (SCIP* scip, SCIP_PROP* prop, SCIP_Bool restart):
cdef SCIP_PROPDATA* propdata
propdata = SCIPpropGetData(prop)
PyProp = <Prop>propdata
PyProp.propexitsol(restart)
return SCIP_OKAY
cdef SCIP_RETCODE PyPropPresol (SCIP* scip, SCIP_PROP* prop, int nrounds, SCIP_PRESOLTIMING presoltiming,
int nnewfixedvars, int nnewaggrvars, int nnewchgvartypes, int nnewchgbds, int nnewholes,
int nnewdelconss, int nnewaddconss, int nnewupgdconss, int nnewchgcoefs, int nnewchgsides,
int* nfixedvars, int* naggrvars, int* nchgvartypes, int* nchgbds, int* naddholes,
int* ndelconss, int* naddconss, int* nupgdconss, int* nchgcoefs, int* nchgsides, SCIP_RESULT* result):
cdef SCIP_PROPDATA* propdata
propdata = SCIPpropGetData(prop)
PyProp = <Prop>propdata
# dictionary for input/output parameters
result_dict = {}
result_dict["nfixedvars"] = nfixedvars[0]
result_dict["naggrvars"] = naggrvars[0]
result_dict["nchgvartypes"] = nchgvartypes[0]
result_dict["nchgbds"] = nchgbds[0]
result_dict["naddholes"] = naddholes[0]
result_dict["ndelconss"] = ndelconss[0]
result_dict["naddconss"] = naddconss[0]
result_dict["nupgdconss"] = nupgdconss[0]
result_dict["nchgcoefs"] = nchgcoefs[0]
result_dict["nchgsides"] = nchgsides[0]
result_dict["result"] = result[0]
PyProp.proppresol(nrounds, presoltiming,
nnewfixedvars, nnewaggrvars, nnewchgvartypes, nnewchgbds, nnewholes,
nnewdelconss, nnewaddconss, nnewupgdconss, nnewchgcoefs, nnewchgsides, result_dict)
result[0] = result_dict["result"]
nfixedvars[0] = result_dict["nfixedvars"]
naggrvars[0] = result_dict["naggrvars"]
nchgvartypes[0] = result_dict["nchgvartypes"]
nchgbds[0] = result_dict["nchgbds"]
naddholes[0] = result_dict["naddholes"]
ndelconss[0] = result_dict["ndelconss"]
naddconss[0] = result_dict["naddconss"]
nupgdconss[0] = result_dict["nupgdconss"]
nchgcoefs[0] = result_dict["nchgcoefs"]
nchgsides[0] = result_dict["nchgsides"]
return SCIP_OKAY
cdef SCIP_RETCODE PyPropExec (SCIP* scip, SCIP_PROP* prop, SCIP_PROPTIMING proptiming, SCIP_RESULT* result):
cdef SCIP_PROPDATA* propdata
propdata = SCIPpropGetData(prop)
PyProp = <Prop>propdata
returnvalues = PyProp.propexec(proptiming)
result_dict = returnvalues
result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
return SCIP_OKAY
cdef SCIP_RETCODE PyPropResProp (SCIP* scip, SCIP_PROP* prop, SCIP_VAR* infervar, int inferinfo,
SCIP_BOUNDTYPE boundtype, SCIP_BDCHGIDX* bdchgidx, SCIP_Real relaxedbd, SCIP_RESULT* result):
cdef SCIP_PROPDATA* propdata
cdef SCIP_VAR* tmp
tmp = infervar
propdata = SCIPpropGetData(prop)
confvar = Variable.create(tmp)
#TODO: parse bdchgidx?
PyProp = <Prop>propdata
returnvalues = PyProp.propresprop(confvar, inferinfo, boundtype, relaxedbd)
result_dict = returnvalues
result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
return SCIP_OKAY