PySCIPOpt  5.1.1
Python Interface for the SCIP Optimization Suite
benders.pxi
Go to the documentation of this file.
1 
3 cdef class Benders:
4  cdef public Model model
5  cdef public str name
6  cdef SCIP_BENDERS* _benders
7 
8  def bendersfree(self):
9  '''calls destructor and frees memory of Benders decomposition '''
10  pass
11 
12  def bendersinit(self):
13  '''initializes Benders deconposition'''
14  pass
15 
16  def bendersexit(self):
17  '''calls exit method of Benders decomposition'''
18  pass
19 
20  def bendersinitpre(self):
21  '''informs the Benders decomposition that the presolving process is being started '''
22  pass
23 
24  def bendersexitpre(self):
25  '''informs the Benders decomposition that the presolving process has been completed'''
26  pass
27 
28  def bendersinitsol(self):
29  '''informs Benders decomposition that the branch and bound process is being started '''
30  pass
31 
32  def bendersexitsol(self):
33  '''informs Benders decomposition that the branch and bound process data is being freed'''
34  pass
35 
36  def benderscreatesub(self, probnumber):
37  '''creates the subproblems and registers it with the Benders decomposition struct '''
38  print("python error in benderscreatesub: this method needs to be implemented")
39  return {}
40 
41  def benderspresubsolve(self, solution, enfotype, checkint):
42  '''sets the pre subproblem solve callback of Benders decomposition '''
43  return {}
44 
45  def benderssolvesubconvex(self, solution, probnumber, onlyconvex):
46  '''sets convex solve callback of Benders decomposition'''
47  return {}
48 
49  def benderssolvesub(self, solution, probnumber):
50  '''sets solve callback of Benders decomposition '''
51  return {}
52 
53  def benderspostsolve(self, solution, enfotype, mergecandidates, npriomergecands, checkint, infeasible):
54  '''sets post-solve callback of Benders decomposition '''
55  return {}
56 
57  def bendersfreesub(self, probnumber):
58  '''frees the subproblems'''
59  pass
60 
61  def bendersgetvar(self, variable, probnumber):
62  '''Returns the corresponding master or subproblem variable for the given variable. This provides a call back for the variable mapping between the master and subproblems. '''
63  print("python error in bendersgetvar: this method needs to be implemented")
64  return {}
65 
66 # local helper functions for the interface
67 cdef Variable getPyVar(SCIP_VAR* var):
68  cdef SCIP_VARDATA* vardata
69  vardata = SCIPvarGetData(var)
70  return <Variable>vardata
71 
72 
73 cdef SCIP_RETCODE PyBendersCopy (SCIP* scip, SCIP_BENDERS* benders, SCIP_Bool threadsafe) noexcept with gil:
74  return SCIP_OKAY
75 
76 cdef SCIP_RETCODE PyBendersFree (SCIP* scip, SCIP_BENDERS* benders) noexcept with gil:
77  cdef SCIP_BENDERSDATA* bendersdata
78  bendersdata = SCIPbendersGetData(benders)
79  PyBenders = <Benders>bendersdata
80  PyBenders.bendersfree()
81  Py_DECREF(PyBenders)
82  return SCIP_OKAY
83 
84 cdef SCIP_RETCODE PyBendersInit (SCIP* scip, SCIP_BENDERS* benders) noexcept with gil:
85  cdef SCIP_BENDERSDATA* bendersdata
86  bendersdata = SCIPbendersGetData(benders)
87  PyBenders = <Benders>bendersdata
88  PyBenders.bendersinit()
89  return SCIP_OKAY
90 
91 cdef SCIP_RETCODE PyBendersExit (SCIP* scip, SCIP_BENDERS* benders) noexcept with gil:
92  cdef SCIP_BENDERSDATA* bendersdata
93  bendersdata = SCIPbendersGetData(benders)
94  PyBenders = <Benders>bendersdata
95  PyBenders.bendersexit()
96  return SCIP_OKAY
97 
98 cdef SCIP_RETCODE PyBendersInitpre (SCIP* scip, SCIP_BENDERS* benders) noexcept with gil:
99  cdef SCIP_BENDERSDATA* bendersdata
100  bendersdata = SCIPbendersGetData(benders)
101  PyBenders = <Benders>bendersdata
102  PyBenders.bendersinitpre()
103  return SCIP_OKAY
104 
105 cdef SCIP_RETCODE PyBendersExitpre (SCIP* scip, SCIP_BENDERS* benders) noexcept with gil:
106  cdef SCIP_BENDERSDATA* bendersdata
107  bendersdata = SCIPbendersGetData(benders)
108  PyBenders = <Benders>bendersdata
109  PyBenders.bendersexitpre()
110  return SCIP_OKAY
111 
112 cdef SCIP_RETCODE PyBendersInitsol (SCIP* scip, SCIP_BENDERS* benders) noexcept with gil:
113  cdef SCIP_BENDERSDATA* bendersdata
114  bendersdata = SCIPbendersGetData(benders)
115  PyBenders = <Benders>bendersdata
116  PyBenders.bendersinitsol()
117  return SCIP_OKAY
118 
119 cdef SCIP_RETCODE PyBendersExitsol (SCIP* scip, SCIP_BENDERS* benders) noexcept with gil:
120  cdef SCIP_BENDERSDATA* bendersdata
121  bendersdata = SCIPbendersGetData(benders)
122  PyBenders = <Benders>bendersdata
123  PyBenders.bendersexitsol()
124  return SCIP_OKAY
125 
126 cdef SCIP_RETCODE PyBendersCreatesub (SCIP* scip, SCIP_BENDERS* benders, int probnumber) noexcept with gil:
127  cdef SCIP_BENDERSDATA* bendersdata
128  bendersdata = SCIPbendersGetData(benders)
129  PyBenders = <Benders>bendersdata
130  PyBenders.benderscreatesub(probnumber)
131  return SCIP_OKAY
132 
133 cdef SCIP_RETCODE PyBendersPresubsolve (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL* sol, SCIP_BENDERSENFOTYPE type, SCIP_Bool checkint, SCIP_Bool* infeasible, SCIP_Bool* auxviol, SCIP_Bool* skipsolve, SCIP_RESULT* result) noexcept with gil:
134  cdef SCIP_BENDERSDATA* bendersdata
135  bendersdata = SCIPbendersGetData(benders)
136  PyBenders = <Benders>bendersdata
137  if sol == NULL:
138  solution = None
139  else:
140  solution = Solution.create(scip, sol)
141  enfotype = type
142  result_dict = PyBenders.benderspresubsolve(solution, enfotype, checkint)
143  infeasible[0] = result_dict.get("infeasible", False)
144  auxviol[0] = result_dict.get("auxviol", False)
145  skipsolve[0] = result_dict.get("skipsolve", False)
146  result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
147  return SCIP_OKAY
148 
149 cdef SCIP_RETCODE PyBendersSolvesubconvex (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL* sol, int probnumber, SCIP_Bool onlyconvex, SCIP_Real* objective, SCIP_RESULT* result) noexcept with gil:
150  cdef SCIP_BENDERSDATA* bendersdata
151  bendersdata = SCIPbendersGetData(benders)
152  PyBenders = <Benders>bendersdata
153  if sol == NULL:
154  solution = None
155  else:
156  solution = Solution.create(scip, sol)
157  result_dict = PyBenders.benderssolvesubconvex(solution, probnumber, onlyconvex)
158  objective[0] = result_dict.get("objective", 1e+20)
159  result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
160  return SCIP_OKAY
161 
162 cdef SCIP_RETCODE PyBendersSolvesub (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL* sol, int probnumber, SCIP_Real* objective, SCIP_RESULT* result) noexcept with gil:
163  cdef SCIP_BENDERSDATA* bendersdata
164  bendersdata = SCIPbendersGetData(benders)
165  PyBenders = <Benders>bendersdata
166  if sol == NULL:
167  solution = None
168  else:
169  solution = Solution.create(scip, sol)
170  result_dict = PyBenders.benderssolvesub(solution, probnumber)
171  objective[0] = result_dict.get("objective", 1e+20)
172  result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
173  return SCIP_OKAY
174 
175 cdef SCIP_RETCODE PyBendersPostsolve (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL* sol,
176  SCIP_BENDERSENFOTYPE type, int* mergecands, int npriomergecands, int nmergecands, SCIP_Bool checkint,
177  SCIP_Bool infeasible, SCIP_Bool* merged) noexcept with gil:
178  cdef SCIP_BENDERSDATA* bendersdata
179  bendersdata = SCIPbendersGetData(benders)
180  PyBenders = <Benders>bendersdata
181  if sol == NULL:
182  solution = None
183  else:
184  solution = Solution.create(scip, sol)
185  enfotype = type
186  mergecandidates = []
187  for i in range(nmergecands):
188  mergecandidates.append(mergecands[i])
189  result_dict = PyBenders.benderspostsolve(solution, enfotype, mergecandidates, npriomergecands, checkint, infeasible)
190  merged[0] = result_dict.get("merged", False)
191  return SCIP_OKAY
192 
193 cdef SCIP_RETCODE PyBendersFreesub (SCIP* scip, SCIP_BENDERS* benders, int probnumber) noexcept with gil:
194  cdef SCIP_BENDERSDATA* bendersdata
195  bendersdata = SCIPbendersGetData(benders)
196  PyBenders = <Benders>bendersdata
197  PyBenders.bendersfreesub(probnumber)
198  return SCIP_OKAY
199 
200 #TODO: Really need to ask about the passing and returning of variables
201 cdef SCIP_RETCODE PyBendersGetvar (SCIP* scip, SCIP_BENDERS* benders, SCIP_VAR* var, SCIP_VAR** mappedvar, int probnumber) noexcept with gil:
202  cdef SCIP_BENDERSDATA* bendersdata
203  bendersdata = SCIPbendersGetData(benders)
204  PyBenders = <Benders>bendersdata
205  PyVar = getPyVar(var)
206  result_dict = PyBenders.bendersgetvar(PyVar, probnumber)
207  mappedvariable = <Variable>(result_dict.get("mappedvar", None))
208  if mappedvariable is None:
209  mappedvar[0] = NULL
210  else:
211  mappedvar[0] = mappedvariable.scip_var
212  return SCIP_OKAY
pyscipopt.benders.Benders.bendersexit
def bendersexit(self)
Definition: benders.pxi:16
pyscipopt.benders.Benders.bendersgetvar
def bendersgetvar(self, variable, probnumber)
Definition: benders.pxi:61
pyscipopt.benders.Benders.bendersfreesub
def bendersfreesub(self, probnumber)
Definition: benders.pxi:57
pyscipopt.benders.Benders.bendersfree
def bendersfree(self)
Definition: benders.pxi:8
pyscipopt.benders.Benders.bendersinitsol
def bendersinitsol(self)
Definition: benders.pxi:28
pyscipopt.benders.Benders.benderssolvesubconvex
def benderssolvesubconvex(self, solution, probnumber, onlyconvex)
Definition: benders.pxi:45
SCIPvarGetData
SCIP_VARDATA * SCIPvarGetData(SCIP_VAR *var)
pyscipopt.benders.Benders.bendersinit
def bendersinit(self)
Definition: benders.pxi:12
pyscipopt.benders.Benders.benderssolvesub
def benderssolvesub(self, solution, probnumber)
Definition: benders.pxi:49
pyscipopt.benders.Benders.bendersinitpre
def bendersinitpre(self)
Definition: benders.pxi:20
pyscipopt.benders.Benders.benderspostsolve
def benderspostsolve(self, solution, enfotype, mergecandidates, npriomergecands, checkint, infeasible)
Definition: benders.pxi:53
pyscipopt.benders.Benders.benderscreatesub
def benderscreatesub(self, probnumber)
Definition: benders.pxi:36
SCIPbendersGetData
SCIP_BENDERSDATA * SCIPbendersGetData(SCIP_BENDERS *benders)
pyscipopt.benders.Benders
Definition: benders.pxi:3
pyscipopt.benders.Benders.benderspresubsolve
def benderspresubsolve(self, solution, enfotype, checkint)
Definition: benders.pxi:41
pyscipopt.benders.Benders.bendersexitpre
def bendersexitpre(self)
Definition: benders.pxi:24
pyscipopt.benders.Benders.bendersexitsol
def bendersexitsol(self)
Definition: benders.pxi:32