PySCIPOpt  5.1.1
Python Interface for the SCIP Optimization Suite
cutsel.pxi
Go to the documentation of this file.
1 
3 cdef class Cutsel:
4  cdef public Model model
5 
6  def cutselfree(self):
7  '''frees memory of cut selector'''
8  pass
9 
10  def cutselinit(self):
11  ''' executed after the problem is transformed. use this call to initialize cut selector data.'''
12  pass
13 
14  def cutselexit(self):
15  '''executed before the transformed problem is freed'''
16  pass
17 
18  def cutselinitsol(self):
19  '''executed when the presolving is finished and the branch-and-bound process is about to begin'''
20  pass
21 
22  def cutselexitsol(self):
23  '''executed before the branch-and-bound process is freed'''
24  pass
25 
26  def cutselselect(self, cuts, forcedcuts, root, maxnselectedcuts):
27  '''first method called in each iteration in the main solving loop. '''
28  # this method needs to be implemented by the user
29  return {}
30 
31 
32 cdef SCIP_RETCODE PyCutselCopy (SCIP* scip, SCIP_CUTSEL* cutsel) noexcept with gil:
33  return SCIP_OKAY
34 
35 cdef SCIP_RETCODE PyCutselFree (SCIP* scip, SCIP_CUTSEL* cutsel) noexcept with gil:
36  cdef SCIP_CUTSELDATA* cutseldata
37  cutseldata = SCIPcutselGetData(cutsel)
38  PyCutsel = <Cutsel>cutseldata
39  PyCutsel.cutselfree()
40  Py_DECREF(PyCutsel)
41  return SCIP_OKAY
42 
43 cdef SCIP_RETCODE PyCutselInit (SCIP* scip, SCIP_CUTSEL* cutsel) noexcept with gil:
44  cdef SCIP_CUTSELDATA* cutseldata
45  cutseldata = SCIPcutselGetData(cutsel)
46  PyCutsel = <Cutsel>cutseldata
47  PyCutsel.cutselinit()
48  return SCIP_OKAY
49 
50 
51 cdef SCIP_RETCODE PyCutselExit (SCIP* scip, SCIP_CUTSEL* cutsel) noexcept with gil:
52  cdef SCIP_CUTSELDATA* cutseldata
53  cutseldata = SCIPcutselGetData(cutsel)
54  PyCutsel = <Cutsel>cutseldata
55  PyCutsel.cutselexit()
56  return SCIP_OKAY
57 
58 cdef SCIP_RETCODE PyCutselInitsol (SCIP* scip, SCIP_CUTSEL* cutsel) noexcept with gil:
59  cdef SCIP_CUTSELDATA* cutseldata
60  cutseldata = SCIPcutselGetData(cutsel)
61  PyCutsel = <Cutsel>cutseldata
62  PyCutsel.cutselinitsol()
63  return SCIP_OKAY
64 
65 cdef SCIP_RETCODE PyCutselExitsol (SCIP* scip, SCIP_CUTSEL* cutsel) noexcept with gil:
66  cdef SCIP_CUTSELDATA* cutseldata
67  cutseldata = SCIPcutselGetData(cutsel)
68  PyCutsel = <Cutsel>cutseldata
69  PyCutsel.cutselexitsol()
70  return SCIP_OKAY
71 
72 cdef SCIP_RETCODE PyCutselSelect (SCIP* scip, SCIP_CUTSEL* cutsel, SCIP_ROW** cuts, int ncuts,
73  SCIP_ROW** forcedcuts, int nforcedcuts, SCIP_Bool root, int maxnselectedcuts,
74  int* nselectedcuts, SCIP_RESULT* result) noexcept with gil:
75  cdef SCIP_CUTSELDATA* cutseldata
76  cdef SCIP_ROW* scip_row
77  cutseldata = SCIPcutselGetData(cutsel)
78  PyCutsel = <Cutsel>cutseldata
79 
80  # translate cuts to python
81  pycuts = [Row.create(cuts[i]) for i in range(ncuts)]
82  pyforcedcuts = [Row.create(forcedcuts[i]) for i in range(nforcedcuts)]
83  result_dict = PyCutsel.cutselselect(pycuts, pyforcedcuts, root, maxnselectedcuts)
84 
85  # Retrieve the sorted cuts. Note that these do not need to be returned explicitly in result_dict.
86  # Pycuts could have been sorted in place in cutselselect()
87  pycuts = result_dict.get('cuts', pycuts)
88 
89  assert len(pycuts) == ncuts
90  assert len(pyforcedcuts) == nforcedcuts
91 
92  #sort cuts
93  for i,cut in enumerate(pycuts):
94  cuts[i] = <SCIP_ROW *>((<Row>cut).scip_row)
95 
96  nselectedcuts[0] = result_dict.get('nselectedcuts', 0)
97  result[0] = result_dict.get('result', <SCIP_RESULT>result[0])
98 
99  return SCIP_OKAY
pyscipopt.cutsel.cutselinitsol
def cutselinitsol(self)
Definition: cutsel.pxi:18
pyscipopt.cutsel.cutselexitsol
def cutselexitsol(self)
Definition: cutsel.pxi:22
pyscipopt.cutsel.cutselselect
def cutselselect(self, cuts, forcedcuts, root, maxnselectedcuts)
Definition: cutsel.pxi:26
SCIPcutselGetData
SCIP_CUTSELDATA * SCIPcutselGetData(SCIP_CUTSEL *cutsel)
pyscipopt.cutsel.cutselexit
def cutselexit(self)
Definition: cutsel.pxi:14
pyscipopt.cutsel.Cutsel
Definition: cutsel.pxi:3
pyscipopt.cutsel.cutselinit
def cutselinit(self)
Definition: cutsel.pxi:10
pyscipopt.cutsel.cutselfree
def cutselfree(self)
Definition: cutsel.pxi:6