PySCIPOpt
Python Interface to the SCIP Optimization Suite
propagator.pxi
Go to the documentation of this file.
1 ##@file propagator.pxi
2 #@brief Base class of the Propagators Plugin
3 cdef class Prop:
4  cdef public Model model
5 
6  def propfree(self):
7  '''calls destructor and frees memory of propagator'''
8  pass
9 
10  def propinit(self):
11  '''initializes propagator'''
12  pass
13 
14  def propexit(self):
15  '''calls exit method of propagator'''
16  pass
17 
18  def propinitsol(self):
19  '''informs propagator that the prop and bound process is being started'''
20  pass
21 
22  def propexitsol(self, restart):
23  '''informs propagator that the prop and bound process data is being freed'''
24  pass
25 
26  def propinitpre(self):
27  '''informs propagator that the presolving process is being started'''
28  pass
29 
30  def propexitpre(self):
31  '''informs propagator that the presolving process is finished'''
32  pass
33 
34  def proppresol(self, nrounds, presoltiming, result_dict):
35  '''executes presolving method of propagator'''
36  pass
37 
38  def propexec(self, proptiming):
39  '''calls execution method of propagator'''
40  print("python error in propexec: this method needs to be implemented")
41  return {}
42 
43  def propresprop(self, confvar, inferinfo, bdtype, relaxedbd):
44  '''resolves the given conflicting bound, that was reduced by the given propagator'''
45  print("python error in propresprop: this method needs to be implemented")
46  return {}
47 
48 
49 
50 cdef SCIP_RETCODE PyPropCopy (SCIP* scip, SCIP_PROP* prop):
51  return SCIP_OKAY
52 
53 cdef SCIP_RETCODE PyPropFree (SCIP* scip, SCIP_PROP* prop):
54  cdef SCIP_PROPDATA* propdata
55  propdata = SCIPpropGetData(prop)
56  PyProp = <Prop>propdata
57  PyProp.propfree()
58  Py_DECREF(PyProp)
59  return SCIP_OKAY
60 
61 cdef SCIP_RETCODE PyPropInit (SCIP* scip, SCIP_PROP* prop):
62  cdef SCIP_PROPDATA* propdata
63  propdata = SCIPpropGetData(prop)
64  PyProp = <Prop>propdata
65  PyProp.propinit()
66  return SCIP_OKAY
67 
68 cdef SCIP_RETCODE PyPropExit (SCIP* scip, SCIP_PROP* prop):
69  cdef SCIP_PROPDATA* propdata
70  propdata = SCIPpropGetData(prop)
71  PyProp = <Prop>propdata
72  PyProp.propexit()
73  return SCIP_OKAY
74 
75 cdef SCIP_RETCODE PyPropInitpre (SCIP* scip, SCIP_PROP* prop):
76  cdef SCIP_PROPDATA* propdata
77  propdata = SCIPpropGetData(prop)
78  PyProp = <Prop>propdata
79  PyProp.propinitpre()
80  return SCIP_OKAY
81 
82 cdef SCIP_RETCODE PyPropExitpre (SCIP* scip, SCIP_PROP* prop):
83  cdef SCIP_PROPDATA* propdata
84  propdata = SCIPpropGetData(prop)
85  PyProp = <Prop>propdata
86  PyProp.propexitpre()
87  return SCIP_OKAY
88 
89 cdef SCIP_RETCODE PyPropInitsol (SCIP* scip, SCIP_PROP* prop):
90  cdef SCIP_PROPDATA* propdata
91  propdata = SCIPpropGetData(prop)
92  PyProp = <Prop>propdata
93  PyProp.propinitsol()
94  return SCIP_OKAY
95 
96 cdef SCIP_RETCODE PyPropExitsol (SCIP* scip, SCIP_PROP* prop, SCIP_Bool restart):
97  cdef SCIP_PROPDATA* propdata
98  propdata = SCIPpropGetData(prop)
99  PyProp = <Prop>propdata
100  PyProp.propexitsol(restart)
101  return SCIP_OKAY
102 
103 cdef SCIP_RETCODE PyPropPresol (SCIP* scip, SCIP_PROP* prop, int nrounds, SCIP_PRESOLTIMING presoltiming,
104  int nnewfixedvars, int nnewaggrvars, int nnewchgvartypes, int nnewchgbds, int nnewholes,
105  int nnewdelconss, int nnewaddconss, int nnewupgdconss, int nnewchgcoefs, int nnewchgsides,
106  int* nfixedvars, int* naggrvars, int* nchgvartypes, int* nchgbds, int* naddholes,
107  int* ndelconss, int* naddconss, int* nupgdconss, int* nchgcoefs, int* nchgsides, SCIP_RESULT* result):
108  cdef SCIP_PROPDATA* propdata
109  propdata = SCIPpropGetData(prop)
110  PyProp = <Prop>propdata
111  # dictionary for input/output parameters
112  result_dict = {}
113  result_dict["nfixedvars"] = nfixedvars[0]
114  result_dict["naggrvars"] = naggrvars[0]
115  result_dict["nchgvartypes"] = nchgvartypes[0]
116  result_dict["nchgbds"] = nchgbds[0]
117  result_dict["naddholes"] = naddholes[0]
118  result_dict["ndelconss"] = ndelconss[0]
119  result_dict["naddconss"] = naddconss[0]
120  result_dict["nupgdconss"] = nupgdconss[0]
121  result_dict["nchgcoefs"] = nchgcoefs[0]
122  result_dict["nchgsides"] = nchgsides[0]
123  result_dict["result"] = result[0]
124  PyProp.proppresol(nrounds, presoltiming,
125  nnewfixedvars, nnewaggrvars, nnewchgvartypes, nnewchgbds, nnewholes,
126  nnewdelconss, nnewaddconss, nnewupgdconss, nnewchgcoefs, nnewchgsides, result_dict)
127  result[0] = result_dict["result"]
128  nfixedvars[0] = result_dict["nfixedvars"]
129  naggrvars[0] = result_dict["naggrvars"]
130  nchgvartypes[0] = result_dict["nchgvartypes"]
131  nchgbds[0] = result_dict["nchgbds"]
132  naddholes[0] = result_dict["naddholes"]
133  ndelconss[0] = result_dict["ndelconss"]
134  naddconss[0] = result_dict["naddconss"]
135  nupgdconss[0] = result_dict["nupgdconss"]
136  nchgcoefs[0] = result_dict["nchgcoefs"]
137  nchgsides[0] = result_dict["nchgsides"]
138  return SCIP_OKAY
139 
140 cdef SCIP_RETCODE PyPropExec (SCIP* scip, SCIP_PROP* prop, SCIP_PROPTIMING proptiming, SCIP_RESULT* result):
141  cdef SCIP_PROPDATA* propdata
142  propdata = SCIPpropGetData(prop)
143  PyProp = <Prop>propdata
144  returnvalues = PyProp.propexec(proptiming)
145  result_dict = returnvalues
146  result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
147  return SCIP_OKAY
148 
149 cdef SCIP_RETCODE PyPropResProp (SCIP* scip, SCIP_PROP* prop, SCIP_VAR* infervar, int inferinfo,
150  SCIP_BOUNDTYPE boundtype, SCIP_BDCHGIDX* bdchgidx, SCIP_Real relaxedbd, SCIP_RESULT* result):
151  cdef SCIP_PROPDATA* propdata
152  cdef SCIP_VAR* tmp
153  tmp = infervar
154  propdata = SCIPpropGetData(prop)
155  confvar = Variable.create(tmp)
156 
157  #TODO: parse bdchgidx?
158 
159  PyProp = <Prop>propdata
160  returnvalues = PyProp.propresprop(confvar, inferinfo, boundtype, relaxedbd)
161  result_dict = returnvalues
162  result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
163  return SCIP_OKAY
SCIP_PROPDATA * SCIPpropGetData(SCIP_PROP *prop)