PySCIPOpt  4.3.0
Python Interface for the SCIP Optimization Suite
scip.pyx
Go to the documentation of this file.
1 
3 import weakref
4 from os.path import abspath
5 from os.path import splitext
6 import os
7 import sys
8 import warnings
9 
10 cimport cython
11 from cpython cimport Py_INCREF, Py_DECREF
12 from cpython.pycapsule cimport PyCapsule_New, PyCapsule_IsValid, PyCapsule_GetPointer
13 from libc.stdlib cimport malloc, free
14 from libc.stdio cimport fdopen, fclose
15 from posix.stdio cimport fileno
16 
17 from collections.abc import Iterable
18 from itertools import repeat
19 
20 include "expr.pxi"
21 include "lp.pxi"
22 include "benders.pxi"
23 include "benderscut.pxi"
24 include "branchrule.pxi"
25 include "conshdlr.pxi"
26 include "cutsel.pxi"
27 include "event.pxi"
28 include "heuristic.pxi"
29 include "presol.pxi"
30 include "pricer.pxi"
31 include "propagator.pxi"
32 include "sepa.pxi"
33 include "reader.pxi"
34 include "relax.pxi"
35 include "nodesel.pxi"
36 
37 # recommended SCIP version; major version is required
38 MAJOR = 8
39 MINOR = 0
40 PATCH = 0
41 
42 # for external user functions use def; for functions used only inside the interface (starting with _) use cdef
43 # todo: check whether this is currently done like this
44 
45 if sys.version_info >= (3, 0):
46  str_conversion = lambda x:bytes(x,'utf-8')
47 else:
48  str_conversion = lambda x:x
49 
50 _SCIP_BOUNDTYPE_TO_STRING = {SCIP_BOUNDTYPE_UPPER: '<=',
51  SCIP_BOUNDTYPE_LOWER: '>='}
52 
53 # Mapping the SCIP_RESULT enum to a python class
54 # This is required to return SCIP_RESULT in the python code
55 # In __init__.py this is imported as SCIP_RESULT to keep the
56 # original naming scheme using capital letters
57 cdef class PY_SCIP_RESULT:
58  DIDNOTRUN = SCIP_DIDNOTRUN
59  DELAYED = SCIP_DELAYED
60  DIDNOTFIND = SCIP_DIDNOTFIND
61  FEASIBLE = SCIP_FEASIBLE
62  INFEASIBLE = SCIP_INFEASIBLE
63  UNBOUNDED = SCIP_UNBOUNDED
64  CUTOFF = SCIP_CUTOFF
65  SEPARATED = SCIP_SEPARATED
66  NEWROUND = SCIP_NEWROUND
67  REDUCEDDOM = SCIP_REDUCEDDOM
68  CONSADDED = SCIP_CONSADDED
69  CONSCHANGED = SCIP_CONSCHANGED
70  BRANCHED = SCIP_BRANCHED
71  SOLVELP = SCIP_SOLVELP
72  FOUNDSOL = SCIP_FOUNDSOL
73  SUSPENDED = SCIP_SUSPENDED
74  SUCCESS = SCIP_SUCCESS
75 
76 cdef class PY_SCIP_PARAMSETTING:
77  DEFAULT = SCIP_PARAMSETTING_DEFAULT
78  AGGRESSIVE = SCIP_PARAMSETTING_AGGRESSIVE
79  FAST = SCIP_PARAMSETTING_FAST
80  OFF = SCIP_PARAMSETTING_OFF
81 
82 cdef class PY_SCIP_PARAMEMPHASIS:
83  DEFAULT = SCIP_PARAMEMPHASIS_DEFAULT
84  CPSOLVER = SCIP_PARAMEMPHASIS_CPSOLVER
85  EASYCIP = SCIP_PARAMEMPHASIS_EASYCIP
86  FEASIBILITY = SCIP_PARAMEMPHASIS_FEASIBILITY
87  HARDLP = SCIP_PARAMEMPHASIS_HARDLP
88  OPTIMALITY = SCIP_PARAMEMPHASIS_OPTIMALITY
89  COUNTER = SCIP_PARAMEMPHASIS_COUNTER
90  PHASEFEAS = SCIP_PARAMEMPHASIS_PHASEFEAS
91  PHASEIMPROVE = SCIP_PARAMEMPHASIS_PHASEIMPROVE
92  PHASEPROOF = SCIP_PARAMEMPHASIS_PHASEPROOF
93 
94 cdef class PY_SCIP_STATUS:
95  UNKNOWN = SCIP_STATUS_UNKNOWN
96  USERINTERRUPT = SCIP_STATUS_USERINTERRUPT
97  NODELIMIT = SCIP_STATUS_NODELIMIT
98  TOTALNODELIMIT = SCIP_STATUS_TOTALNODELIMIT
99  STALLNODELIMIT = SCIP_STATUS_STALLNODELIMIT
100  TIMELIMIT = SCIP_STATUS_TIMELIMIT
101  MEMLIMIT = SCIP_STATUS_MEMLIMIT
102  GAPLIMIT = SCIP_STATUS_GAPLIMIT
103  SOLLIMIT = SCIP_STATUS_SOLLIMIT
104  BESTSOLLIMIT = SCIP_STATUS_BESTSOLLIMIT
105  RESTARTLIMIT = SCIP_STATUS_RESTARTLIMIT
106  OPTIMAL = SCIP_STATUS_OPTIMAL
107  INFEASIBLE = SCIP_STATUS_INFEASIBLE
108  UNBOUNDED = SCIP_STATUS_UNBOUNDED
109  INFORUNBD = SCIP_STATUS_INFORUNBD
110 
111 cdef class PY_SCIP_STAGE:
112  INIT = SCIP_STAGE_INIT
113  PROBLEM = SCIP_STAGE_PROBLEM
114  TRANSFORMING = SCIP_STAGE_TRANSFORMING
115  TRANSFORMED = SCIP_STAGE_TRANSFORMED
116  INITPRESOLVE = SCIP_STAGE_INITPRESOLVE
117  PRESOLVING = SCIP_STAGE_PRESOLVING
118  EXITPRESOLVE = SCIP_STAGE_EXITPRESOLVE
119  PRESOLVED = SCIP_STAGE_PRESOLVED
120  INITSOLVE = SCIP_STAGE_INITSOLVE
121  SOLVING = SCIP_STAGE_SOLVING
122  SOLVED = SCIP_STAGE_SOLVED
123  EXITSOLVE = SCIP_STAGE_EXITSOLVE
124  FREETRANS = SCIP_STAGE_FREETRANS
125  FREE = SCIP_STAGE_FREE
126 
127 cdef class PY_SCIP_NODETYPE:
128  FOCUSNODE = SCIP_NODETYPE_FOCUSNODE
129  PROBINGNODE = SCIP_NODETYPE_PROBINGNODE
130  SIBLING = SCIP_NODETYPE_SIBLING
131  CHILD = SCIP_NODETYPE_CHILD
132  LEAF = SCIP_NODETYPE_LEAF
133  DEADEND = SCIP_NODETYPE_DEADEND
134  JUNCTION = SCIP_NODETYPE_JUNCTION
135  PSEUDOFORK = SCIP_NODETYPE_PSEUDOFORK
136  FORK = SCIP_NODETYPE_FORK
137  SUBROOT = SCIP_NODETYPE_SUBROOT
138  REFOCUSNODE = SCIP_NODETYPE_REFOCUSNODE
139 
140 
141 cdef class PY_SCIP_PROPTIMING:
142  BEFORELP = SCIP_PROPTIMING_BEFORELP
143  DURINGLPLOOP = SCIP_PROPTIMING_DURINGLPLOOP
144  AFTERLPLOOP = SCIP_PROPTIMING_AFTERLPLOOP
145  AFTERLPNODE = SCIP_PROPTIMING_AFTERLPNODE
146 
147 cdef class PY_SCIP_PRESOLTIMING:
148  NONE = SCIP_PRESOLTIMING_NONE
149  FAST = SCIP_PRESOLTIMING_FAST
150  MEDIUM = SCIP_PRESOLTIMING_MEDIUM
151  EXHAUSTIVE = SCIP_PRESOLTIMING_EXHAUSTIVE
152 
153 cdef class PY_SCIP_HEURTIMING:
154  BEFORENODE = SCIP_HEURTIMING_BEFORENODE
155  DURINGLPLOOP = SCIP_HEURTIMING_DURINGLPLOOP
156  AFTERLPLOOP = SCIP_HEURTIMING_AFTERLPLOOP
157  AFTERLPNODE = SCIP_HEURTIMING_AFTERLPNODE
158  AFTERPSEUDONODE = SCIP_HEURTIMING_AFTERPSEUDONODE
159  AFTERLPPLUNGE = SCIP_HEURTIMING_AFTERLPPLUNGE
160  AFTERPSEUDOPLUNGE = SCIP_HEURTIMING_AFTERPSEUDOPLUNGE
161  DURINGPRICINGLOOP = SCIP_HEURTIMING_DURINGPRICINGLOOP
162  BEFOREPRESOL = SCIP_HEURTIMING_BEFOREPRESOL
163  DURINGPRESOLLOOP = SCIP_HEURTIMING_DURINGPRESOLLOOP
164  AFTERPROPLOOP = SCIP_HEURTIMING_AFTERPROPLOOP
165 
166 cdef class PY_SCIP_EVENTTYPE:
167  DISABLED = SCIP_EVENTTYPE_DISABLED
168  VARADDED = SCIP_EVENTTYPE_VARADDED
169  VARDELETED = SCIP_EVENTTYPE_VARDELETED
170  VARFIXED = SCIP_EVENTTYPE_VARFIXED
171  VARUNLOCKED = SCIP_EVENTTYPE_VARUNLOCKED
172  OBJCHANGED = SCIP_EVENTTYPE_OBJCHANGED
173  GLBCHANGED = SCIP_EVENTTYPE_GLBCHANGED
174  GUBCHANGED = SCIP_EVENTTYPE_GUBCHANGED
175  LBTIGHTENED = SCIP_EVENTTYPE_LBTIGHTENED
176  LBRELAXED = SCIP_EVENTTYPE_LBRELAXED
177  UBTIGHTENED = SCIP_EVENTTYPE_UBTIGHTENED
178  UBRELAXED = SCIP_EVENTTYPE_UBRELAXED
179  GHOLEADDED = SCIP_EVENTTYPE_GHOLEADDED
180  GHOLEREMOVED = SCIP_EVENTTYPE_GHOLEREMOVED
181  LHOLEADDED = SCIP_EVENTTYPE_LHOLEADDED
182  LHOLEREMOVED = SCIP_EVENTTYPE_LHOLEREMOVED
183  IMPLADDED = SCIP_EVENTTYPE_IMPLADDED
184  PRESOLVEROUND = SCIP_EVENTTYPE_PRESOLVEROUND
185  NODEFOCUSED = SCIP_EVENTTYPE_NODEFOCUSED
186  NODEFEASIBLE = SCIP_EVENTTYPE_NODEFEASIBLE
187  NODEINFEASIBLE = SCIP_EVENTTYPE_NODEINFEASIBLE
188  NODEBRANCHED = SCIP_EVENTTYPE_NODEBRANCHED
189  FIRSTLPSOLVED = SCIP_EVENTTYPE_FIRSTLPSOLVED
190  LPSOLVED = SCIP_EVENTTYPE_LPSOLVED
191  LPEVENT = SCIP_EVENTTYPE_LPEVENT
192  POORSOLFOUND = SCIP_EVENTTYPE_POORSOLFOUND
193  BESTSOLFOUND = SCIP_EVENTTYPE_BESTSOLFOUND
194  ROWADDEDSEPA = SCIP_EVENTTYPE_ROWADDEDSEPA
195  ROWDELETEDSEPA = SCIP_EVENTTYPE_ROWDELETEDSEPA
196  ROWADDEDLP = SCIP_EVENTTYPE_ROWADDEDLP
197  ROWDELETEDLP = SCIP_EVENTTYPE_ROWDELETEDLP
198  ROWCOEFCHANGED = SCIP_EVENTTYPE_ROWCOEFCHANGED
199  ROWCONSTCHANGED = SCIP_EVENTTYPE_ROWCONSTCHANGED
200  ROWSIDECHANGED = SCIP_EVENTTYPE_ROWSIDECHANGED
201  SYNC = SCIP_EVENTTYPE_SYNC
202  NODESOLVED = SCIP_EVENTTYPE_NODEFEASIBLE | SCIP_EVENTTYPE_NODEINFEASIBLE | SCIP_EVENTTYPE_NODEBRANCHED
203 
204 cdef class PY_SCIP_LPSOLSTAT:
205  NOTSOLVED = SCIP_LPSOLSTAT_NOTSOLVED
206  OPTIMAL = SCIP_LPSOLSTAT_OPTIMAL
207  INFEASIBLE = SCIP_LPSOLSTAT_INFEASIBLE
208  UNBOUNDEDRAY = SCIP_LPSOLSTAT_UNBOUNDEDRAY
209  OBJLIMIT = SCIP_LPSOLSTAT_OBJLIMIT
210  ITERLIMIT = SCIP_LPSOLSTAT_ITERLIMIT
211  TIMELIMIT = SCIP_LPSOLSTAT_TIMELIMIT
212  ERROR = SCIP_LPSOLSTAT_ERROR
213 
214 cdef class PY_SCIP_BRANCHDIR:
215  DOWNWARDS = SCIP_BRANCHDIR_DOWNWARDS
216  UPWARDS = SCIP_BRANCHDIR_UPWARDS
217  FIXED = SCIP_BRANCHDIR_FIXED
218  AUTO = SCIP_BRANCHDIR_AUTO
219 
220 cdef class PY_SCIP_BENDERSENFOTYPE:
221  LP = SCIP_BENDERSENFOTYPE_LP
222  RELAX = SCIP_BENDERSENFOTYPE_RELAX
223  PSEUDO = SCIP_BENDERSENFOTYPE_PSEUDO
224  CHECK = SCIP_BENDERSENFOTYPE_CHECK
225 
226 cdef class PY_SCIP_ROWORIGINTYPE:
227  UNSPEC = SCIP_ROWORIGINTYPE_UNSPEC
228  CONS = SCIP_ROWORIGINTYPE_CONS
229  SEPA = SCIP_ROWORIGINTYPE_SEPA
230  REOPT = SCIP_ROWORIGINTYPE_REOPT
231 
232 def PY_SCIP_CALL(SCIP_RETCODE rc):
233  if rc == SCIP_OKAY:
234  pass
235  elif rc == SCIP_ERROR:
236  raise Exception('SCIP: unspecified error!')
237  elif rc == SCIP_NOMEMORY:
238  raise MemoryError('SCIP: insufficient memory error!')
239  elif rc == SCIP_READERROR:
240  raise IOError('SCIP: read error!')
241  elif rc == SCIP_WRITEERROR:
242  raise IOError('SCIP: write error!')
243  elif rc == SCIP_NOFILE:
244  raise IOError('SCIP: file not found error!')
245  elif rc == SCIP_FILECREATEERROR:
246  raise IOError('SCIP: cannot create file!')
247  elif rc == SCIP_LPERROR:
248  raise Exception('SCIP: error in LP solver!')
249  elif rc == SCIP_NOPROBLEM:
250  raise Exception('SCIP: no problem exists!')
251  elif rc == SCIP_INVALIDCALL:
252  raise Exception('SCIP: method cannot be called at this time'
253  + ' in solution process!')
254  elif rc == SCIP_INVALIDDATA:
255  raise Exception('SCIP: error in input data!')
256  elif rc == SCIP_INVALIDRESULT:
257  raise Exception('SCIP: method returned an invalid result code!')
258  elif rc == SCIP_PLUGINNOTFOUND:
259  raise Exception('SCIP: a required plugin was not found !')
260  elif rc == SCIP_PARAMETERUNKNOWN:
261  raise KeyError('SCIP: the parameter with the given name was not found!')
262  elif rc == SCIP_PARAMETERWRONGTYPE:
263  raise LookupError('SCIP: the parameter is not of the expected type!')
264  elif rc == SCIP_PARAMETERWRONGVAL:
265  raise ValueError('SCIP: the value is invalid for the given parameter!')
266  elif rc == SCIP_KEYALREADYEXISTING:
267  raise KeyError('SCIP: the given key is already existing in table!')
268  elif rc == SCIP_MAXDEPTHLEVEL:
269  raise Exception('SCIP: maximal branching depth level exceeded!')
270  else:
271  raise Exception('SCIP: unknown return code!')
272 
273 cdef class Event:
274  """Base class holding a pointer to corresponding SCIP_EVENT"""
275 
276  @staticmethod
277  cdef create(SCIP_EVENT* scip_event):
278  if scip_event == NULL:
279  raise Warning("cannot create Event with SCIP_EVENT* == NULL")
280  event = Event()
281  event.event = scip_event
282  return event
283 
284  def getType(self):
285  """gets type of event"""
286  return SCIPeventGetType(self.event)
287 
288  def __repr__(self):
289  return self.getType()
290 
291  def getNewBound(self):
292  """gets new bound for a bound change event"""
293  return SCIPeventGetNewbound(self.event)
294 
295  def getOldBound(self):
296  """gets old bound for a bound change event"""
297  return SCIPeventGetOldbound(self.event)
298 
299  def getVar(self):
300  """gets variable for a variable event (var added, var deleted, var fixed, objective value or domain change, domain hole added or removed)"""
301  cdef SCIP_VAR* var = SCIPeventGetVar(self.event)
302  return Variable.create(var)
303 
304  def getNode(self):
305  """gets node for a node or LP event"""
306  cdef SCIP_NODE* node = SCIPeventGetNode(self.event)
307  return Node.create(node)
308 
309  def getRow(self):
310  """gets row for a row event"""
311  cdef SCIP_ROW* row = SCIPeventGetRow(self.event)
312  return Row.create(row)
313 
314  def __hash__(self):
315  return hash(<size_t>self.event)
316 
317  def __eq__(self, other):
318  return (self.__class__ == other.__class__
319  and self.event == (<Event>other).event)
320 
321 cdef class Column:
322  """Base class holding a pointer to corresponding SCIP_COL"""
323 
324  @staticmethod
325  cdef create(SCIP_COL* scipcol):
326  if scipcol == NULL:
327  raise Warning("cannot create Column with SCIP_COL* == NULL")
328  col = Column()
329  col.scip_col = scipcol
330  return col
331 
332  def getLPPos(self):
333  """gets position of column in current LP, or -1 if it is not in LP"""
334  return SCIPcolGetLPPos(self.scip_col)
335 
336  def getBasisStatus(self):
337  """gets the basis status of a column in the LP solution, Note: returns basis status `zero` for columns not in the current SCIP LP"""
338  cdef SCIP_BASESTAT stat = SCIPcolGetBasisStatus(self.scip_col)
339  if stat == SCIP_BASESTAT_LOWER:
340  return "lower"
341  elif stat == SCIP_BASESTAT_BASIC:
342  return "basic"
343  elif stat == SCIP_BASESTAT_UPPER:
344  return "upper"
345  elif stat == SCIP_BASESTAT_ZERO:
346  return "zero"
347  else:
348  raise Exception('SCIP returned unknown base status!')
349 
350  def isIntegral(self):
351  """returns whether the associated variable is of integral type (binary, integer, implicit integer)"""
352  return SCIPcolIsIntegral(self.scip_col)
353 
354  def getVar(self):
355  """gets variable this column represents"""
356  cdef SCIP_VAR* var = SCIPcolGetVar(self.scip_col)
357  return Variable.create(var)
358 
359  def getPrimsol(self):
360  """gets the primal LP solution of a column"""
361  return SCIPcolGetPrimsol(self.scip_col)
362 
363  def getLb(self):
364  """gets lower bound of column"""
365  return SCIPcolGetLb(self.scip_col)
366 
367  def getUb(self):
368  """gets upper bound of column"""
369  return SCIPcolGetUb(self.scip_col)
370 
371  def getObjCoeff(self):
372  """gets objective value coefficient of a column"""
373  return SCIPcolGetObj(self.scip_col)
374 
375  def __hash__(self):
376  return hash(<size_t>self.scip_col)
377 
378  def __eq__(self, other):
379  return (self.__class__ == other.__class__
380  and self.scip_col == (<Column>other).scip_col)
381 
382 cdef class Row:
383  """Base class holding a pointer to corresponding SCIP_ROW"""
384 
385  @staticmethod
386  cdef create(SCIP_ROW* sciprow):
387  if sciprow == NULL:
388  raise Warning("cannot create Row with SCIP_ROW* == NULL")
389  row = Row()
390  row.scip_row = sciprow
391  return row
392 
393  property name:
394  def __get__(self):
395  cname = bytes( SCIProwGetName(self.scip_row) )
396  return cname.decode('utf-8')
397 
398  def getLhs(self):
399  """returns the left hand side of row"""
400  return SCIProwGetLhs(self.scip_row)
401 
402  def getRhs(self):
403  """returns the right hand side of row"""
404  return SCIProwGetRhs(self.scip_row)
405 
406  def getConstant(self):
407  """gets constant shift of row"""
408  return SCIProwGetConstant(self.scip_row)
409 
410  def getLPPos(self):
411  """gets position of row in current LP, or -1 if it is not in LP"""
412  return SCIProwGetLPPos(self.scip_row)
413 
414  def getBasisStatus(self):
415  """gets the basis status of a row in the LP solution, Note: returns basis status `basic` for rows not in the current SCIP LP"""
416  cdef SCIP_BASESTAT stat = SCIProwGetBasisStatus(self.scip_row)
417  if stat == SCIP_BASESTAT_LOWER:
418  return "lower"
419  elif stat == SCIP_BASESTAT_BASIC:
420  return "basic"
421  elif stat == SCIP_BASESTAT_UPPER:
422  return "upper"
423  elif stat == SCIP_BASESTAT_ZERO:
424  # this shouldn't happen!
425  raise Exception('SCIP returned base status zero for a row!')
426  else:
427  raise Exception('SCIP returned unknown base status!')
428 
429  def isIntegral(self):
430  """returns TRUE iff the activity of the row (without the row's constant) is always integral in a feasible solution """
431  return SCIProwIsIntegral(self.scip_row)
432 
433  def isLocal(self):
434  """returns TRUE iff the row is only valid locally """
435  return SCIProwIsLocal(self.scip_row)
436 
437  def isModifiable(self):
438  """returns TRUE iff row is modifiable during node processing (subject to column generation) """
439  return SCIProwIsModifiable(self.scip_row)
440 
441  def isRemovable(self):
442  """returns TRUE iff row is removable from the LP (due to aging or cleanup)"""
443  return SCIProwIsRemovable(self.scip_row)
444 
445  def isInGlobalCutpool(self):
446  """return TRUE iff row is a member of the global cut pool"""
448 
449  def getOrigintype(self):
450  """returns type of origin that created the row"""
451  return SCIProwGetOrigintype(self.scip_row)
452 
454  """returns type of constraint handler that created the row"""
455  cdef SCIP_CONS* scip_con = SCIProwGetOriginCons(self.scip_row)
456  return bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(scip_con))).decode('UTF-8')
457 
458  def getNNonz(self):
459  """get number of nonzero entries in row vector"""
460  return SCIProwGetNNonz(self.scip_row)
461 
462  def getNLPNonz(self):
463  """get number of nonzero entries in row vector that correspond to columns currently in the SCIP LP"""
464  return SCIProwGetNLPNonz(self.scip_row)
465 
466  def getCols(self):
467  """gets list with columns of nonzero entries"""
468  cdef SCIP_COL** cols = SCIProwGetCols(self.scip_row)
469  return [Column.create(cols[i]) for i in range(self.getNNonz())]
470 
471  def getVals(self):
472  """gets list with coefficients of nonzero entries"""
473  cdef SCIP_Real* vals = SCIProwGetVals(self.scip_row)
474  return [vals[i] for i in range(self.getNNonz())]
475 
476  def getNorm(self):
477  """gets Euclidean norm of row vector """
478  return SCIProwGetNorm(self.scip_row)
479 
480  def __hash__(self):
481  return hash(<size_t>self.scip_row)
482 
483  def __eq__(self, other):
484  return (self.__class__ == other.__class__
485  and self.scip_row == (<Row>other).scip_row)
486 
487 cdef class NLRow:
488  """Base class holding a pointer to corresponding SCIP_NLROW"""
489 
490  @staticmethod
491  cdef create(SCIP_NLROW* scipnlrow):
492  if scipnlrow == NULL:
493  raise Warning("cannot create NLRow with SCIP_NLROW* == NULL")
494  nlrow = NLRow()
495  nlrow.scip_nlrow = scipnlrow
496  return nlrow
497 
498  property name:
499  def __get__(self):
500  cname = bytes( SCIPnlrowGetName(self.scip_nlrow) )
501  return cname.decode('utf-8')
502 
503  def getConstant(self):
504  """returns the constant of a nonlinear row"""
505  return SCIPnlrowGetConstant(self.scip_nlrow)
506 
507  def getLinearTerms(self):
508  """returns a list of tuples (var, coef) representing the linear part of a nonlinear row"""
509  cdef SCIP_VAR** linvars = SCIPnlrowGetLinearVars(self.scip_nlrow)
510  cdef SCIP_Real* lincoefs = SCIPnlrowGetLinearCoefs(self.scip_nlrow)
511  cdef int nlinvars = SCIPnlrowGetNLinearVars(self.scip_nlrow)
512  return [(Variable.create(linvars[i]), lincoefs[i]) for i in range(nlinvars)]
513 
514  def getLhs(self):
515  """returns the left hand side of a nonlinear row"""
516  return SCIPnlrowGetLhs(self.scip_nlrow)
517 
518  def getRhs(self):
519  """returns the right hand side of a nonlinear row"""
520  return SCIPnlrowGetRhs(self.scip_nlrow)
521 
522  def getDualsol(self):
523  """gets the dual NLP solution of a nonlinear row"""
524  return SCIPnlrowGetDualsol(self.scip_nlrow)
525 
526  def __hash__(self):
527  return hash(<size_t>self.scip_nlrow)
528 
529  def __eq__(self, other):
530  return (self.__class__ == other.__class__
531  and self.scip_nlrow == (<NLRow>other).scip_nlrow)
532 
533 cdef class Solution:
534  """Base class holding a pointer to corresponding SCIP_SOL"""
535 
536  @staticmethod
537  cdef create(SCIP* scip, SCIP_SOL* scip_sol):
538  if scip == NULL:
539  raise Warning("cannot create Solution with SCIP* == NULL")
540  sol = Solution()
541  sol.sol = scip_sol
542  sol.scip = scip
543  return sol
544 
545  def __getitem__(self, Expr expr):
546  # fast track for Variable
547  if isinstance(expr, Variable):
548  self._checkStage("SCIPgetSolVal")
549  var = <Variable> expr
550  return SCIPgetSolVal(self.scip, self.sol, var.scip_var)
551  return sum(self._evaluate(term)*coeff for term, coeff in expr.terms.items() if coeff != 0)
552 
553  def _evaluate(self, term):
554  self._checkStage("SCIPgetSolVal")
555  result = 1
556  for var in term.vartuple:
557  result *= SCIPgetSolVal(self.scip, self.sol, (<Variable> var).scip_var)
558  return result
559 
560  def __setitem__(self, Variable var, value):
561  PY_SCIP_CALL(SCIPsetSolVal(self.scip, self.sol, var.scip_var, value))
562 
563  def __repr__(self):
564  cdef SCIP_VAR* scip_var
565 
566  vals = {}
567  self._checkStage("SCIPgetSolVal")
568  for i in range(SCIPgetNVars(self.scip)):
569  scip_var = SCIPgetVars(self.scip)[i]
570 
571  # extract name
572  cname = bytes(SCIPvarGetName(scip_var))
573  name = cname.decode('utf-8')
574 
575  vals[name] = SCIPgetSolVal(self.scip, self.sol, scip_var)
576  return str(vals)
577 
578  def _checkStage(self, method):
579  if method in ["SCIPgetSolVal", "getSolObjVal"]:
580  if self.sol == NULL and not SCIPgetStage(self.scip) == SCIP_STAGE_SOLVING:
581  raise Warning(f"{method} can only be called in stage SOLVING with a valid solution (current stage: {SCIPgetStage(self.scip)})")
582 
583 
584 cdef class BoundChange:
585  """Bound change."""
586 
587  @staticmethod
588  cdef create(SCIP_BOUNDCHG* scip_boundchg):
589  if scip_boundchg == NULL:
590  raise Warning("cannot create BoundChange with SCIP_BOUNDCHG* == NULL")
591  boundchg = BoundChange()
592  boundchg.scip_boundchg = scip_boundchg
593  return boundchg
594 
595  def getNewBound(self):
596  """Returns the new value of the bound in the bound change."""
598 
599  def getVar(self):
600  """Returns the variable of the bound change."""
601  return Variable.create(SCIPboundchgGetVar(self.scip_boundchg))
602 
603  def getBoundchgtype(self):
604  """Returns the bound change type of the bound change."""
606 
607  def getBoundtype(self):
608  """Returns the bound type of the bound change."""
610 
611  def isRedundant(self):
612  """Returns whether the bound change is redundant due to a more global bound that is at least as strong."""
614 
615  def __repr__(self):
616  return "{} {} {}".format(self.getVar(),
617  _SCIP_BOUNDTYPE_TO_STRING[self.getBoundtype()],
618  self.getNewBound())
619 
620 cdef class DomainChanges:
621  """Set of domain changes."""
622 
623  @staticmethod
624  cdef create(SCIP_DOMCHG* scip_domchg):
625  if scip_domchg == NULL:
626  raise Warning("cannot create DomainChanges with SCIP_DOMCHG* == NULL")
627  domchg = DomainChanges()
628  domchg.scip_domchg = scip_domchg
629  return domchg
630 
631  def getBoundchgs(self):
632  """Returns the bound changes in the domain change."""
633  nboundchgs = SCIPdomchgGetNBoundchgs(self.scip_domchg)
634  return [BoundChange.create(SCIPdomchgGetBoundchg(self.scip_domchg, i))
635  for i in range(nboundchgs)]
636 
637 cdef class Node:
638  """Base class holding a pointer to corresponding SCIP_NODE"""
639 
640  @staticmethod
641  cdef create(SCIP_NODE* scipnode):
642  if scipnode == NULL:
643  return None
644  node = Node()
645  node.scip_node = scipnode
646  return node
647 
648  def getParent(self):
649  """Retrieve parent node (or None if the node has no parent node)."""
650  return Node.create(SCIPnodeGetParent(self.scip_node))
651 
652  def getNumber(self):
653  """Retrieve number of node."""
654  return SCIPnodeGetNumber(self.scip_node)
655 
656  def getDepth(self):
657  """Retrieve depth of node."""
658  return SCIPnodeGetDepth(self.scip_node)
659 
660  def getType(self):
661  """Retrieve type of node."""
662  return SCIPnodeGetType(self.scip_node)
663 
664  def getLowerbound(self):
665  """Retrieve lower bound of node."""
666  return SCIPnodeGetLowerbound(self.scip_node)
667 
668  def getEstimate(self):
669  """Retrieve the estimated value of the best feasible solution in subtree of the node"""
670  return SCIPnodeGetEstimate(self.scip_node)
671 
672  def getAddedConss(self):
673  """Retrieve all constraints added at this node."""
674  cdef int addedconsssize = SCIPnodeGetNAddedConss(self.scip_node)
675  if addedconsssize == 0:
676  return []
677  cdef SCIP_CONS** addedconss = <SCIP_CONS**> malloc(addedconsssize * sizeof(SCIP_CONS*))
678  cdef int nconss
679  SCIPnodeGetAddedConss(self.scip_node, addedconss, &nconss, addedconsssize)
680  assert nconss == addedconsssize
681  constraints = [Constraint.create(addedconss[i]) for i in range(nconss)]
682  free(addedconss)
683  return constraints
684 
685  def getNAddedConss(self):
686  """Retrieve number of added constraints at this node"""
687  return SCIPnodeGetNAddedConss(self.scip_node)
688 
689  def isActive(self):
690  """Is the node in the path to the current node?"""
691  return SCIPnodeIsActive(self.scip_node)
692 
693  def isPropagatedAgain(self):
694  """Is the node marked to be propagated again?"""
696 
698  """Retrieve the number of variable branchings that were performed in the parent node to create this node."""
699  cdef SCIP_VAR* dummy_branchvars
700  cdef SCIP_Real dummy_branchbounds
701  cdef SCIP_BOUNDTYPE dummy_boundtypes
702  cdef int nbranchvars
703  # This is a hack: the SCIP interface has no function to directly get the
704  # number of parent branchings, i.e., SCIPnodeGetNParentBranchings() does
705  # not exist.
706  SCIPnodeGetParentBranchings(self.scip_node, &dummy_branchvars,
707  &dummy_branchbounds, &dummy_boundtypes,
708  &nbranchvars, 0)
709  return nbranchvars
710 
712  """Retrieve the set of variable branchings that were performed in the parent node to create this node."""
713  cdef int nbranchvars = self.getNParentBranchings()
714  if nbranchvars == 0:
715  return None
716 
717  cdef SCIP_VAR** branchvars = <SCIP_VAR**> malloc(nbranchvars * sizeof(SCIP_VAR*))
718  cdef SCIP_Real* branchbounds = <SCIP_Real*> malloc(nbranchvars * sizeof(SCIP_Real))
719  cdef SCIP_BOUNDTYPE* boundtypes = <SCIP_BOUNDTYPE*> malloc(nbranchvars * sizeof(SCIP_BOUNDTYPE))
720 
721  SCIPnodeGetParentBranchings(self.scip_node, branchvars, branchbounds,
722  boundtypes, &nbranchvars, nbranchvars)
723 
724  py_variables = [Variable.create(branchvars[i]) for i in range(nbranchvars)]
725  py_branchbounds = [branchbounds[i] for i in range(nbranchvars)]
726  py_boundtypes = [boundtypes[i] for i in range(nbranchvars)]
727 
728  free(boundtypes)
729  free(branchbounds)
730  free(branchvars)
731  return py_variables, py_branchbounds, py_boundtypes
732 
733  def getNDomchg(self):
734  """Retrieve the number of bound changes due to branching, constraint propagation, and propagation."""
735  cdef int nbranchings
736  cdef int nconsprop
737  cdef int nprop
738  SCIPnodeGetNDomchg(self.scip_node, &nbranchings, &nconsprop, &nprop)
739  return nbranchings, nconsprop, nprop
740 
741  def getDomchg(self):
742  """Retrieve domain changes for this node."""
743  cdef SCIP_DOMCHG* domchg = SCIPnodeGetDomchg(self.scip_node)
744  if domchg == NULL:
745  return None
746  return DomainChanges.create(domchg)
747 
748  def __hash__(self):
749  return hash(<size_t>self.scip_node)
750 
751  def __eq__(self, other):
752  return (self.__class__ == other.__class__
753  and self.scip_node == (<Node>other).scip_node)
754 
755 cdef class Variable(Expr):
756  """Is a linear expression and has SCIP_VAR*"""
757 
758  @staticmethod
759  cdef create(SCIP_VAR* scipvar):
760  if scipvar == NULL:
761  raise Warning("cannot create Variable with SCIP_VAR* == NULL")
762  var = Variable()
763  var.scip_var = scipvar
764  Expr.__init__(var, {Term(var) : 1.0})
765  return var
766 
767  property name:
768  def __get__(self):
769  cname = bytes( SCIPvarGetName(self.scip_var) )
770  return cname.decode('utf-8')
771 
772  def ptr(self):
773  """ """
774  return <size_t>(self.scip_var)
775 
776  def __repr__(self):
777  return self.name
778 
779  def vtype(self):
780  """Retrieve the variables type (BINARY, INTEGER, IMPLINT or CONTINUOUS)"""
781  vartype = SCIPvarGetType(self.scip_var)
782  if vartype == SCIP_VARTYPE_BINARY:
783  return "BINARY"
784  elif vartype == SCIP_VARTYPE_INTEGER:
785  return "INTEGER"
786  elif vartype == SCIP_VARTYPE_CONTINUOUS:
787  return "CONTINUOUS"
788  elif vartype == SCIP_VARTYPE_IMPLINT:
789  return "IMPLINT"
790 
791  def isOriginal(self):
792  """Retrieve whether the variable belongs to the original problem"""
793  return SCIPvarIsOriginal(self.scip_var)
794 
795  def isInLP(self):
796  """Retrieve whether the variable is a COLUMN variable that is member of the current LP"""
797  return SCIPvarIsInLP(self.scip_var)
798 
799 
800  def getIndex(self):
801  """Retrieve the unique index of the variable."""
802  return SCIPvarGetIndex(self.scip_var)
803 
804  def getCol(self):
805  """Retrieve column of COLUMN variable"""
806  cdef SCIP_COL* scip_col
807  scip_col = SCIPvarGetCol(self.scip_var)
808  return Column.create(scip_col)
809 
810  def getLbOriginal(self):
811  """Retrieve original lower bound of variable"""
812  return SCIPvarGetLbOriginal(self.scip_var)
813 
814  def getUbOriginal(self):
815  """Retrieve original upper bound of variable"""
816  return SCIPvarGetUbOriginal(self.scip_var)
817 
818  def getLbGlobal(self):
819  """Retrieve global lower bound of variable"""
820  return SCIPvarGetLbGlobal(self.scip_var)
821 
822  def getUbGlobal(self):
823  """Retrieve global upper bound of variable"""
824  return SCIPvarGetUbGlobal(self.scip_var)
825 
826  def getLbLocal(self):
827  """Retrieve current lower bound of variable"""
828  return SCIPvarGetLbLocal(self.scip_var)
829 
830  def getUbLocal(self):
831  """Retrieve current upper bound of variable"""
832  return SCIPvarGetUbLocal(self.scip_var)
833 
834  def getObj(self):
835  """Retrieve current objective value of variable"""
836  return SCIPvarGetObj(self.scip_var)
837 
838  def getLPSol(self):
839  """Retrieve the current LP solution value of variable"""
840  return SCIPvarGetLPSol(self.scip_var)
841 
842 cdef class Constraint:
843  """Base class holding a pointer to corresponding SCIP_CONS"""
844 
845  @staticmethod
846  cdef create(SCIP_CONS* scipcons):
847  if scipcons == NULL:
848  raise Warning("cannot create Constraint with SCIP_CONS* == NULL")
849  cons = Constraint()
850  cons.scip_cons = scipcons
851  return cons
852 
853  property name:
854  def __get__(self):
855  cname = bytes( SCIPconsGetName(self.scip_cons) )
856  return cname.decode('utf-8')
857 
858  def __repr__(self):
859  return self.name
860 
861  def isOriginal(self):
862  """Retrieve whether the constraint belongs to the original problem"""
863  return SCIPconsIsOriginal(self.scip_cons)
864 
865  def isInitial(self):
866  """Retrieve True if the relaxation of the constraint should be in the initial LP"""
867  return SCIPconsIsInitial(self.scip_cons)
868 
869  def isSeparated(self):
870  """Retrieve True if constraint should be separated during LP processing"""
871  return SCIPconsIsSeparated(self.scip_cons)
872 
873  def isEnforced(self):
874  """Retrieve True if constraint should be enforced during node processing"""
875  return SCIPconsIsEnforced(self.scip_cons)
876 
877  def isChecked(self):
878  """Retrieve True if constraint should be checked for feasibility"""
879  return SCIPconsIsChecked(self.scip_cons)
880 
881  def isPropagated(self):
882  """Retrieve True if constraint should be propagated during node processing"""
883  return SCIPconsIsPropagated(self.scip_cons)
884 
885  def isLocal(self):
886  """Retrieve True if constraint is only locally valid or not added to any (sub)problem"""
887  return SCIPconsIsLocal(self.scip_cons)
888 
889  def isModifiable(self):
890  """Retrieve True if constraint is modifiable (subject to column generation)"""
891  return SCIPconsIsModifiable(self.scip_cons)
892 
893  def isDynamic(self):
894  """Retrieve True if constraint is subject to aging"""
895  return SCIPconsIsDynamic(self.scip_cons)
896 
897  def isRemovable(self):
898  """Retrieve True if constraint's relaxation should be removed from the LP due to aging or cleanup"""
899  return SCIPconsIsRemovable(self.scip_cons)
900 
901  def isStickingAtNode(self):
902  """Retrieve True if constraint is only locally valid or not added to any (sub)problem"""
904 
905  def isActive(self):
906  """returns True iff constraint is active in the current node"""
907  return SCIPconsIsActive(self.scip_cons)
908 
909  def isLinear(self):
910  """Retrieve True if constraint is linear"""
911  constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(self.scip_cons))).decode('UTF-8')
912  return constype == 'linear'
913 
914  def isNonlinear(self):
915  """Retrieve True if constraint is nonlinear"""
916  constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(self.scip_cons))).decode('UTF-8')
917  return constype == 'nonlinear'
918 
919  def __hash__(self):
920  return hash(<size_t>self.scip_cons)
921 
922  def __eq__(self, other):
923  return (self.__class__ == other.__class__
924  and self.scip_cons == (<Constraint>other).scip_cons)
925 
926 
927 cdef void relayMessage(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *msg):
928  sys.stdout.write(msg.decode('UTF-8'))
929 
930 cdef void relayErrorMessage(void *messagehdlr, FILE *file, const char *msg):
931  sys.stderr.write(msg.decode('UTF-8'))
932 
933 # - remove create(), includeDefaultPlugins(), createProbBasic() methods
934 # - replace free() by "destructor"
935 # - interface SCIPfreeProb()
936 
939 cdef class Model:
940  """Main class holding a pointer to SCIP for managing most interactions"""
941 
942  def __init__(self, problemName='model', defaultPlugins=True, Model sourceModel=None, origcopy=False, globalcopy=True, enablepricing=False, createscip=True, threadsafe=False):
943  """
944  :param problemName: name of the problem (default 'model')
945  :param defaultPlugins: use default plugins? (default True)
946  :param sourceModel: create a copy of the given Model instance (default None)
947  :param origcopy: whether to call copy or copyOrig (default False)
948  :param globalcopy: whether to create a global or a local copy (default True)
949  :param enablepricing: whether to enable pricing in copy (default False)
950  :param createscip: initialize the Model object and creates a SCIP instance
951  :param threadsafe: False if data can be safely shared between the source and target problem
952  """
953  if self.version() < MAJOR:
954  raise Exception("linked SCIP is not compatible to this version of PySCIPOpt - use at least version", MAJOR)
955  if self.version() < MAJOR + MINOR/10.0 + PATCH/100.0:
956  warnings.warn("linked SCIP {} is not recommended for this version of PySCIPOpt - use version {}.{}.{}".format(self.version(), MAJOR, MINOR, PATCH))
957 
958  self._freescip = True
959  self._modelvars = {}
960 
961  if not createscip:
962  # if no SCIP instance should be created, then an empty Model object is created.
963  self._scip = NULL
964  self._bestSol = None
965  self._freescip = False
966  elif sourceModel is None:
967  PY_SCIP_CALL(SCIPcreate(&self._scip))
968  self._bestSol = None
969  if defaultPlugins:
970  self.includeDefaultPlugins()
971  self.createProbBasic(problemName)
972  else:
973  PY_SCIP_CALL(SCIPcreate(&self._scip))
974  self._bestSol = <Solution> sourceModel._bestSol
975  n = str_conversion(problemName)
976  if origcopy:
977  PY_SCIP_CALL(SCIPcopyOrig(sourceModel._scip, self._scip, NULL, NULL, n, enablepricing, threadsafe, True, self._valid))
978  else:
979  PY_SCIP_CALL(SCIPcopy(sourceModel._scip, self._scip, NULL, NULL, n, globalcopy, enablepricing, threadsafe, True, self._valid))
980 
981  def __dealloc__(self):
982  # call C function directly, because we can no longer call this object's methods, according to
983  # http://docs.cython.org/src/reference/extension_types.html#finalization-dealloc
984  if self._scip is not NULL and self._freescip and PY_SCIP_CALL:
985  PY_SCIP_CALL( SCIPfree(&self._scip) )
986 
987  def __hash__(self):
988  return hash(<size_t>self._scip)
989 
990  def __eq__(self, other):
991  return (self.__class__ == other.__class__
992  and self._scip == (<Model>other)._scip)
993 
994  @staticmethod
995  cdef create(SCIP* scip):
996  """Creates a model and appropriately assigns the scip and bestsol parameters
997  """
998  if scip == NULL:
999  raise Warning("cannot create Model with SCIP* == NULL")
1000  model = Model(createscip=False)
1001  model._scip = scip
1002  model._bestSol = Solution.create(scip, SCIPgetBestSol(scip))
1003  return model
1004 
1005  @property
1006  def _freescip(self):
1007  """Return whether the underlying Scip pointer gets deallocted when the current
1008  object is deleted.
1009  """
1010  return self._freescip
1011 
1012  @_freescip.setter
1013  def _freescip(self, val):
1014  """Set whether the underlying Scip pointer gets deallocted when the current
1015  object is deleted.
1016  """
1017  self._freescip = val
1018 
1019  @cython.always_allow_keywords(True)
1020  @staticmethod
1021  def from_ptr(capsule, take_ownership):
1022  """Create a Model from a given pointer.
1023 
1024  :param cpasule: The PyCapsule containing the SCIP pointer under the name "scip".
1025  :param take_ownership: Whether the newly created Model assumes ownership of the
1026  underlying Scip pointer (see `_freescip`).
1027  """
1028  if not PyCapsule_IsValid(capsule, "scip"):
1029  raise ValueError("The given capsule does not contain a valid scip pointer")
1030  model = Model.create(<SCIP*>PyCapsule_GetPointer(capsule, "scip"))
1031  model._freescip = take_ownership
1032  return model
1033 
1034  @cython.always_allow_keywords(True)
1035  def to_ptr(self, give_ownership):
1036  """Return the underlying Scip pointer to the current Model.
1037 
1038  :param give_ownership: Whether the current Model gives away ownership of the
1039  underlying Scip pointer (see `_freescip`).
1040  :return capsule: The underlying pointer to the current Model, wrapped in a
1041  PyCapsule under the name "scip".
1042  """
1043  capsule = PyCapsule_New(<void*>self._scip, "scip", NULL)
1044  if give_ownership:
1045  self._freescip = False
1046  return capsule
1047 
1049  """Includes all default plug-ins into SCIP"""
1050  PY_SCIP_CALL(SCIPincludeDefaultPlugins(self._scip))
1051 
1052  def createProbBasic(self, problemName='model'):
1053  """Create new problem instance with given name
1054 
1055  :param problemName: name of model or problem (Default value = 'model')
1056 
1057  """
1058  n = str_conversion(problemName)
1059  PY_SCIP_CALL(SCIPcreateProbBasic(self._scip, n))
1060 
1061  def freeProb(self):
1062  """Frees problem and solution process data"""
1063  PY_SCIP_CALL(SCIPfreeProb(self._scip))
1064 
1065  def freeTransform(self):
1066  """Frees all solution process data including presolving and transformed problem, only original problem is kept"""
1067  PY_SCIP_CALL(SCIPfreeTransform(self._scip))
1068 
1069  def version(self):
1070  """Retrieve SCIP version"""
1071  return SCIPversion()
1072 
1073  def printVersion(self):
1074  """Print version, copyright information and compile mode"""
1075  SCIPprintVersion(self._scip, NULL)
1076 
1077  def getProbName(self):
1078  """Retrieve problem name"""
1079  return bytes(SCIPgetProbName(self._scip)).decode('UTF-8')
1080 
1081  def getTotalTime(self):
1082  """Retrieve the current total SCIP time in seconds, i.e. the total time since the SCIP instance has been created"""
1083  return SCIPgetTotalTime(self._scip)
1084 
1085  def getSolvingTime(self):
1086  """Retrieve the current solving time in seconds"""
1087  return SCIPgetSolvingTime(self._scip)
1088 
1089  def getReadingTime(self):
1090  """Retrieve the current reading time in seconds"""
1091  return SCIPgetReadingTime(self._scip)
1092 
1094  """Retrieve the curernt presolving time in seconds"""
1095  return SCIPgetPresolvingTime(self._scip)
1096 
1097  def getNLPIterations(self):
1098  """Retrieve the total number of LP iterations so far."""
1099  return SCIPgetNLPIterations(self._scip)
1100 
1101  def getNNodes(self):
1102  """gets number of processed nodes in current run, including the focus node."""
1103  return SCIPgetNNodes(self._scip)
1104 
1105  def getNTotalNodes(self):
1106  """gets number of processed nodes in all runs, including the focus node."""
1107  return SCIPgetNTotalNodes(self._scip)
1108 
1110  """Retrieve number of leaf nodes processed with feasible relaxation solution."""
1111  return SCIPgetNFeasibleLeaves(self._scip)
1112 
1114  """gets number of infeasible leaf nodes processed."""
1115  return SCIPgetNInfeasibleLeaves(self._scip)
1116 
1117  def getNLeaves(self):
1118  """gets number of leaves in the tree."""
1119  return SCIPgetNLeaves(self._scip)
1120 
1121  def getNChildren(self):
1122  """gets number of children of focus node."""
1123  return SCIPgetNChildren(self._scip)
1124 
1125  def getNSiblings(self):
1126  """gets number of siblings of focus node."""
1127  return SCIPgetNSiblings(self._scip)
1128 
1129  def getCurrentNode(self):
1130  """Retrieve current node."""
1131  return Node.create(SCIPgetCurrentNode(self._scip))
1132 
1133  def getGap(self):
1134  """Retrieve the gap, i.e. |(primalbound - dualbound)/min(|primalbound|,|dualbound|)|."""
1135  return SCIPgetGap(self._scip)
1136 
1137  def getDepth(self):
1138  """Retrieve the depth of the current node"""
1139  return SCIPgetDepth(self._scip)
1140 
1141  def infinity(self):
1142  """Retrieve SCIP's infinity value"""
1143  return SCIPinfinity(self._scip)
1144 
1145  def epsilon(self):
1146  """Retrieve epsilon for e.g. equality checks"""
1147  return SCIPepsilon(self._scip)
1148 
1149  def feastol(self):
1150  """Retrieve feasibility tolerance"""
1151  return SCIPfeastol(self._scip)
1152 
1153  def feasFrac(self, value):
1154  """returns fractional part of value, i.e. x - floor(x) in feasible tolerance: x - floor(x+feastol)"""
1155  return SCIPfeasFrac(self._scip, value)
1156 
1157  def frac(self, value):
1158  """returns fractional part of value, i.e. x - floor(x) in epsilon tolerance: x - floor(x+eps)"""
1159  return SCIPfrac(self._scip, value)
1160 
1161  def isZero(self, value):
1162  """returns whether abs(value) < eps"""
1163  return SCIPisZero(self._scip, value)
1164 
1165  def isFeasZero(self, value):
1166  """returns whether abs(value) < feastol"""
1167  return SCIPisFeasZero(self._scip, value)
1168 
1169  def isInfinity(self, value):
1170  """returns whether value is SCIP's infinity"""
1171  return SCIPisInfinity(self._scip, value)
1172 
1173  def isFeasNegative(self, value):
1174  """returns whether value < -feastol"""
1175  return SCIPisFeasNegative(self._scip, value)
1176 
1177  def isFeasIntegral(self, value):
1178  """returns whether value is integral within the LP feasibility bounds"""
1179  return SCIPisFeasIntegral(self._scip, value)
1180 
1181  def isEQ(self, val1, val2):
1182  """checks, if values are in range of epsilon"""
1183  return SCIPisEQ(self._scip, val1, val2)
1184 
1185  def isFeasEQ(self, val1, val2):
1186  """checks, if relative difference of values is in range of feasibility tolerance"""
1187  return SCIPisFeasEQ(self._scip, val1, val2)
1188 
1189  def isLE(self, val1, val2):
1190  """returns whether val1 <= val2 + eps"""
1191  return SCIPisLE(self._scip, val1, val2)
1192 
1193  def isLT(self, val1, val2):
1194  """returns whether val1 < val2 - eps"""
1195  return SCIPisLT(self._scip, val1, val2)
1196 
1197  def isGE(self, val1, val2):
1198  """returns whether val1 >= val2 - eps"""
1199  return SCIPisGE(self._scip, val1, val2)
1200 
1201  def isGT(self, val1, val2):
1202  """returns whether val1 > val2 + eps"""
1203  return SCIPisGT(self._scip, val1, val2)
1204 
1205  def getCondition(self, exact=False):
1206  """Get the current LP's condition number
1207 
1208  :param exact: whether to get an estimate or the exact value (Default value = False)
1209 
1210  """
1211  cdef SCIP_LPI* lpi
1212  PY_SCIP_CALL(SCIPgetLPI(self._scip, &lpi))
1213  cdef SCIP_Real quality = 0
1214  if exact:
1215  PY_SCIP_CALL(SCIPlpiGetRealSolQuality(lpi, SCIP_LPSOLQUALITY_EXACTCONDITION, &quality))
1216  else:
1217  PY_SCIP_CALL(SCIPlpiGetRealSolQuality(lpi, SCIP_LPSOLQUALITY_ESTIMCONDITION, &quality))
1218 
1219  return quality
1220 
1221  def enableReoptimization(self, enable=True):
1222  """include specific heuristics and branching rules for reoptimization"""
1223  PY_SCIP_CALL(SCIPenableReoptimization(self._scip, enable))
1224 
1225  def lpiGetIterations(self):
1226  """Get the iteration count of the last solved LP"""
1227  cdef SCIP_LPI* lpi
1228  PY_SCIP_CALL(SCIPgetLPI(self._scip, &lpi))
1229  cdef int iters = 0
1230  PY_SCIP_CALL(SCIPlpiGetIterations(lpi, &iters))
1231  return iters
1232 
1233  # Objective function
1234 
1235  def setMinimize(self):
1236  """Set the objective sense to minimization."""
1237  PY_SCIP_CALL(SCIPsetObjsense(self._scip, SCIP_OBJSENSE_MINIMIZE))
1238 
1239  def setMaximize(self):
1240  """Set the objective sense to maximization."""
1241  PY_SCIP_CALL(SCIPsetObjsense(self._scip, SCIP_OBJSENSE_MAXIMIZE))
1242 
1243  def setObjlimit(self, objlimit):
1244  """Set a limit on the objective function.
1245  Only solutions with objective value better than this limit are accepted.
1246 
1247  :param objlimit: limit on the objective function
1248 
1249  """
1250  PY_SCIP_CALL(SCIPsetObjlimit(self._scip, objlimit))
1251 
1252  def getObjlimit(self):
1253  """returns current limit on objective function."""
1254  return SCIPgetObjlimit(self._scip)
1255 
1256  def setObjective(self, coeffs, sense = 'minimize', clear = 'true'):
1257  """Establish the objective function as a linear expression.
1258 
1259  :param coeffs: the coefficients
1260  :param sense: the objective sense (Default value = 'minimize')
1261  :param clear: set all other variables objective coefficient to zero (Default value = 'true')
1262 
1263  """
1264  cdef SCIP_VAR** _vars
1265  cdef int _nvars
1266 
1267  # turn the constant value into an Expr instance for further processing
1268  if not isinstance(coeffs, Expr):
1269  assert(_is_number(coeffs)), "given coefficients are neither Expr or number but %s" % coeffs.__class__.__name__
1270  coeffs = Expr() + coeffs
1271 
1272  if coeffs.degree() > 1:
1273  raise ValueError("Nonlinear objective functions are not supported!")
1274 
1275  if clear:
1276  # clear existing objective function
1277  self.addObjoffset(-self.getObjoffset())
1278  _vars = SCIPgetOrigVars(self._scip)
1279  _nvars = SCIPgetNOrigVars(self._scip)
1280  for i in range(_nvars):
1281  PY_SCIP_CALL(SCIPchgVarObj(self._scip, _vars[i], 0.0))
1282 
1283  if coeffs[CONST] != 0.0:
1284  self.addObjoffset(coeffs[CONST])
1285 
1286  for term, coef in coeffs.terms.items():
1287  # avoid CONST term of Expr
1288  if term != CONST:
1289  assert len(term) == 1
1290  var = <Variable>term[0]
1291  PY_SCIP_CALL(SCIPchgVarObj(self._scip, var.scip_var, coef))
1292 
1293  if sense == "minimize":
1294  self.setMinimize()
1295  elif sense == "maximize":
1296  self.setMaximize()
1297  else:
1298  raise Warning("unrecognized optimization sense: %s" % sense)
1299 
1300  def getObjective(self):
1301  """Retrieve objective function as Expr"""
1302  variables = self.getVars()
1303  objective = Expr()
1304  for var in variables:
1305  coeff = var.getObj()
1306  if coeff != 0:
1307  objective += coeff * var
1308  objective.normalize()
1309  return objective
1310 
1311  def addObjoffset(self, offset, solutions = False):
1312  """Add constant offset to objective
1313 
1314  :param offset: offset to add
1315  :param solutions: add offset also to existing solutions (Default value = False)
1316 
1317  """
1318  if solutions:
1319  PY_SCIP_CALL(SCIPaddObjoffset(self._scip, offset))
1320  else:
1321  PY_SCIP_CALL(SCIPaddOrigObjoffset(self._scip, offset))
1322 
1323  def getObjoffset(self, original = True):
1324  """Retrieve constant objective offset
1325 
1326  :param original: offset of original or transformed problem (Default value = True)
1327 
1328  """
1329  if original:
1330  return SCIPgetOrigObjoffset(self._scip)
1331  else:
1332  return SCIPgetTransObjoffset(self._scip)
1333 
1334 
1335  def setObjIntegral(self):
1336  """informs SCIP that the objective value is always integral in every feasible solution
1337  Note: This function should be used to inform SCIP that the objective function is integral, helping to improve the
1338  performance. This is useful when using column generation. If no column generation (pricing) is used, SCIP
1339  automatically detects whether the objective function is integral or can be scaled to be integral. However, in
1340  any case, the user has to make sure that no variable is added during the solving process that destroys this
1341  property.
1342  """
1343  PY_SCIP_CALL(SCIPsetObjIntegral(self._scip))
1344 
1345  def getLocalEstimate(self, original = False):
1346  """gets estimate of best primal solution w.r.t. original or transformed problem contained in current subtree
1347 
1348  :param original: estimate of original or transformed problem (Default value = False)
1349  """
1350  if original:
1351  return SCIPgetLocalOrigEstimate(self._scip)
1352  else:
1353  return SCIPgetLocalTransEstimate(self._scip)
1354 
1355  # Setting parameters
1356  def setPresolve(self, setting):
1357  """Set presolving parameter settings.
1358 
1359  :param setting: the parameter settings (SCIP_PARAMSETTING)
1360 
1361  """
1362  PY_SCIP_CALL(SCIPsetPresolving(self._scip, setting, True))
1363 
1364  def setProbName(self, name):
1365  """Set problem name"""
1366  n = str_conversion(name)
1367  PY_SCIP_CALL(SCIPsetProbName(self._scip, n))
1368 
1369  def setSeparating(self, setting):
1370  """Set separating parameter settings.
1371 
1372  :param setting: the parameter settings (SCIP_PARAMSETTING)
1373 
1374  """
1375  PY_SCIP_CALL(SCIPsetSeparating(self._scip, setting, True))
1376 
1377  def setHeuristics(self, setting):
1378  """Set heuristics parameter settings.
1379 
1380  :param setting: the parameter setting (SCIP_PARAMSETTING)
1381 
1382  """
1383  PY_SCIP_CALL(SCIPsetHeuristics(self._scip, setting, True))
1384 
1385  def disablePropagation(self, onlyroot=False):
1386  """Disables propagation in SCIP to avoid modifying the original problem during transformation.
1387 
1388  :param onlyroot: use propagation when root processing is finished (Default value = False)
1389 
1390  """
1391  self.setIntParam("propagating/maxroundsroot", 0)
1392  if not onlyroot:
1393  self.setIntParam("propagating/maxrounds", 0)
1394 
1395  def writeProblem(self, filename='model.cip', trans=False, genericnames=False):
1396  """Write current model/problem to a file.
1397 
1398  :param filename: the name of the file to be used (Default value = 'model.cip'). Should have an extension corresponding to one of the readable file formats, described in https://www.scipopt.org/doc/html/group__FILEREADERS.php.
1399  :param trans: indicates whether the transformed problem is written to file (Default value = False)
1400  :param genericnames: indicates whether the problem should be written with generic variable and constraint names (Default value = False)
1401 
1402  """
1403  str_absfile = abspath(filename)
1404  absfile = str_conversion(str_absfile)
1405  fn, ext = splitext(absfile)
1406  if len(ext) == 0:
1407  ext = str_conversion('.cip')
1408  fn = fn + ext
1409  ext = ext[1:]
1410  if trans:
1411  PY_SCIP_CALL(SCIPwriteTransProblem(self._scip, fn, ext, genericnames))
1412  else:
1413  PY_SCIP_CALL(SCIPwriteOrigProblem(self._scip, fn, ext, genericnames))
1414  print('wrote problem to file ' + str_absfile)
1415 
1416  # Variable Functions
1417 
1418  def addVar(self, name='', vtype='C', lb=0.0, ub=None, obj=0.0, pricedVar=False, pricedVarScore=1.0):
1419  """Create a new variable. Default variable is non-negative and continuous.
1420 
1421  :param name: name of the variable, generic if empty (Default value = '')
1422  :param vtype: type of the variable: 'C' continuous, 'I' integer, 'B' binary, and 'M' implicit integer
1423  (see https://www.scipopt.org/doc/html/FAQ.php#implicitinteger) (Default value = 'C')
1424  :param lb: lower bound of the variable, use None for -infinity (Default value = 0.0)
1425  :param ub: upper bound of the variable, use None for +infinity (Default value = None)
1426  :param obj: objective value of variable (Default value = 0.0)
1427  :param pricedVar: is the variable a pricing candidate? (Default value = False)
1428  :param pricedVarScore: score of variable in case it is priced, the higher the better (Default value = 1.0)
1429 
1430  """
1431  cdef SCIP_VAR* scip_var
1432 
1433  # replace empty name with generic one
1434  if name == '':
1435  name = 'x'+str(SCIPgetNVars(self._scip)+1)
1436  cname = str_conversion(name)
1437 
1438  # replace None with corresponding infinity
1439  if lb is None:
1440  lb = -SCIPinfinity(self._scip)
1441  if ub is None:
1442  ub = SCIPinfinity(self._scip)
1443 
1444  vtype = vtype.upper()
1445  if vtype in ['C', 'CONTINUOUS']:
1446  PY_SCIP_CALL(SCIPcreateVarBasic(self._scip, &scip_var, cname, lb, ub, obj, SCIP_VARTYPE_CONTINUOUS))
1447  elif vtype in ['B', 'BINARY']:
1448  if ub > 1.0:
1449  ub = 1.0
1450  if lb < 0.0:
1451  lb = 0.0
1452  PY_SCIP_CALL(SCIPcreateVarBasic(self._scip, &scip_var, cname, lb, ub, obj, SCIP_VARTYPE_BINARY))
1453  elif vtype in ['I', 'INTEGER']:
1454  PY_SCIP_CALL(SCIPcreateVarBasic(self._scip, &scip_var, cname, lb, ub, obj, SCIP_VARTYPE_INTEGER))
1455  elif vtype in ['M', 'IMPLINT']:
1456  PY_SCIP_CALL(SCIPcreateVarBasic(self._scip, &scip_var, cname, lb, ub, obj, SCIP_VARTYPE_IMPLINT))
1457  else:
1458  raise Warning("unrecognized variable type")
1459 
1460  if pricedVar:
1461  PY_SCIP_CALL(SCIPaddPricedVar(self._scip, scip_var, pricedVarScore))
1462  else:
1463  PY_SCIP_CALL(SCIPaddVar(self._scip, scip_var))
1464 
1465  pyVar = Variable.create(scip_var)
1466 
1467  # store variable in the model to avoid creating new python variable objects in getVars()
1468  assert not pyVar.ptr() in self._modelvars
1469  self._modelvars[pyVar.ptr()] = pyVar
1470 
1471  #setting the variable data
1472  SCIPvarSetData(scip_var, <SCIP_VARDATA*>pyVar)
1473  PY_SCIP_CALL(SCIPreleaseVar(self._scip, &scip_var))
1474  return pyVar
1475 
1476  def getTransformedVar(self, Variable var):
1477  """Retrieve the transformed variable.
1478 
1479  :param Variable var: original variable to get the transformed of
1480 
1481  """
1482  cdef SCIP_VAR* _tvar
1483  PY_SCIP_CALL(SCIPgetTransformedVar(self._scip, var.scip_var, &_tvar))
1484 
1485  return Variable.create(_tvar)
1486 
1487  def addVarLocks(self, Variable var, nlocksdown, nlocksup):
1488  """adds given values to lock numbers of variable for rounding
1489 
1490  :param Variable var: variable to adjust the locks for
1491  :param nlocksdown: new number of down locks
1492  :param nlocksup: new number of up locks
1493 
1494  """
1495  PY_SCIP_CALL(SCIPaddVarLocks(self._scip, var.scip_var, nlocksdown, nlocksup))
1496 
1497  def fixVar(self, Variable var, val):
1498  """Fixes the variable var to the value val if possible.
1499 
1500  :param Variable var: variable to fix
1501  :param val: float, the fix value
1502  :return: tuple (infeasible, fixed) of booleans
1503 
1504  """
1505  cdef SCIP_Bool infeasible
1506  cdef SCIP_Bool fixed
1507  PY_SCIP_CALL(SCIPfixVar(self._scip, var.scip_var, val, &infeasible, &fixed))
1508  return infeasible, fixed
1509 
1510  def delVar(self, Variable var):
1511  """Delete a variable.
1512 
1513  :param var: the variable which shall be deleted
1514  :return: bool, was deleting succesful
1515 
1516  """
1517  cdef SCIP_Bool deleted
1518  if var.ptr() in self._modelvars:
1519  del self._modelvars[var.ptr()]
1520  PY_SCIP_CALL(SCIPdelVar(self._scip, var.scip_var, &deleted))
1521  return deleted
1522 
1523  def tightenVarLb(self, Variable var, lb, force=False):
1524  """Tighten the lower bound in preprocessing or current node, if the bound is tighter.
1525 
1526  :param var: SCIP variable
1527  :param lb: possible new lower bound
1528  :param force: force tightening even if below bound strengthening tolerance
1529  :return: tuple of bools, (infeasible, tightened)
1530  infeasible: whether new domain is empty
1531  tightened: whether the bound was tightened
1532 
1533  """
1534  cdef SCIP_Bool infeasible
1535  cdef SCIP_Bool tightened
1536  PY_SCIP_CALL(SCIPtightenVarLb(self._scip, var.scip_var, lb, force, &infeasible, &tightened))
1537  return infeasible, tightened
1538 
1539 
1540  def tightenVarUb(self, Variable var, ub, force=False):
1541  """Tighten the upper bound in preprocessing or current node, if the bound is tighter.
1542 
1543  :param var: SCIP variable
1544  :param ub: possible new upper bound
1545  :param force: force tightening even if below bound strengthening tolerance
1546  :return: tuple of bools, (infeasible, tightened)
1547  infeasible: whether new domain is empty
1548  tightened: whether the bound was tightened
1549 
1550  """
1551  cdef SCIP_Bool infeasible
1552  cdef SCIP_Bool tightened
1553  PY_SCIP_CALL(SCIPtightenVarUb(self._scip, var.scip_var, ub, force, &infeasible, &tightened))
1554  return infeasible, tightened
1555 
1556 
1557  def tightenVarUbGlobal(self, Variable var, ub, force=False):
1558  """Tighten the global upper bound, if the bound is tighter.
1559 
1560  :param var: SCIP variable
1561  :param ub: possible new upper bound
1562  :param force: force tightening even if below bound strengthening tolerance
1563  :return: tuple of bools, (infeasible, tightened)
1564  infeasible: whether new domain is empty
1565  tightened: whether the bound was tightened
1566 
1567  """
1568  cdef SCIP_Bool infeasible
1569  cdef SCIP_Bool tightened
1570  PY_SCIP_CALL(SCIPtightenVarUbGlobal(self._scip, var.scip_var, ub, force, &infeasible, &tightened))
1571  return infeasible, tightened
1572 
1573  def tightenVarLbGlobal(self, Variable var, lb, force=False):
1574  """Tighten the global upper bound, if the bound is tighter.
1575 
1576  :param var: SCIP variable
1577  :param lb: possible new upper bound
1578  :param force: force tightening even if below bound strengthening tolerance
1579  :return: tuple of bools, (infeasible, tightened)
1580  infeasible: whether new domain is empty
1581  tightened: whether the bound was tightened
1582 
1583  """
1584  cdef SCIP_Bool infeasible
1585  cdef SCIP_Bool tightened
1586  PY_SCIP_CALL(SCIPtightenVarLbGlobal(self._scip, var.scip_var, lb, force, &infeasible, &tightened))
1587  return infeasible, tightened
1588 
1589  def chgVarLb(self, Variable var, lb):
1590  """Changes the lower bound of the specified variable.
1591 
1592  :param Variable var: variable to change bound of
1593  :param lb: new lower bound (set to None for -infinity)
1594 
1595  """
1596  if lb is None:
1597  lb = -SCIPinfinity(self._scip)
1598  PY_SCIP_CALL(SCIPchgVarLb(self._scip, var.scip_var, lb))
1599 
1600  def chgVarUb(self, Variable var, ub):
1601  """Changes the upper bound of the specified variable.
1602 
1603  :param Variable var: variable to change bound of
1604  :param ub: new upper bound (set to None for +infinity)
1605 
1606  """
1607  if ub is None:
1608  ub = SCIPinfinity(self._scip)
1609  PY_SCIP_CALL(SCIPchgVarUb(self._scip, var.scip_var, ub))
1610 
1611 
1612  def chgVarLbGlobal(self, Variable var, lb):
1613  """Changes the global lower bound of the specified variable.
1614 
1615  :param Variable var: variable to change bound of
1616  :param lb: new lower bound (set to None for -infinity)
1617 
1618  """
1619  if lb is None:
1620  lb = -SCIPinfinity(self._scip)
1621  PY_SCIP_CALL(SCIPchgVarLbGlobal(self._scip, var.scip_var, lb))
1622 
1623  def chgVarUbGlobal(self, Variable var, ub):
1624  """Changes the global upper bound of the specified variable.
1625 
1626  :param Variable var: variable to change bound of
1627  :param ub: new upper bound (set to None for +infinity)
1628 
1629  """
1630  if ub is None:
1631  ub = SCIPinfinity(self._scip)
1632  PY_SCIP_CALL(SCIPchgVarUbGlobal(self._scip, var.scip_var, ub))
1633 
1634  def chgVarLbNode(self, Node node, Variable var, lb):
1635  """Changes the lower bound of the specified variable at the given node.
1636 
1637  :param Variable var: variable to change bound of
1638  :param lb: new lower bound (set to None for -infinity)
1639  """
1640 
1641  if lb is None:
1642  lb = -SCIPinfinity(self._scip)
1643  PY_SCIP_CALL(SCIPchgVarLbNode(self._scip, node.scip_node, var.scip_var, lb))
1644 
1645  def chgVarUbNode(self, Node node, Variable var, ub):
1646  """Changes the upper bound of the specified variable at the given node.
1647 
1648  :param Variable var: variable to change bound of
1649  :param ub: new upper bound (set to None for +infinity)
1650 
1651  """
1652  if ub is None:
1653  ub = SCIPinfinity(self._scip)
1654  PY_SCIP_CALL(SCIPchgVarUbNode(self._scip, node.scip_node, var.scip_var, ub))
1655 
1656  def chgVarType(self, Variable var, vtype):
1657  """Changes the type of a variable
1658 
1659  :param Variable var: variable to change type of
1660  :param vtype: new variable type
1661 
1662  """
1663  cdef SCIP_Bool infeasible
1664  if vtype in ['C', 'CONTINUOUS']:
1665  PY_SCIP_CALL(SCIPchgVarType(self._scip, var.scip_var, SCIP_VARTYPE_CONTINUOUS, &infeasible))
1666  elif vtype in ['B', 'BINARY']:
1667  PY_SCIP_CALL(SCIPchgVarType(self._scip, var.scip_var, SCIP_VARTYPE_BINARY, &infeasible))
1668  elif vtype in ['I', 'INTEGER']:
1669  PY_SCIP_CALL(SCIPchgVarType(self._scip, var.scip_var, SCIP_VARTYPE_INTEGER, &infeasible))
1670  elif vtype in ['M', 'IMPLINT']:
1671  PY_SCIP_CALL(SCIPchgVarType(self._scip, var.scip_var, SCIP_VARTYPE_IMPLINT, &infeasible))
1672  else:
1673  raise Warning("unrecognized variable type")
1674  if infeasible:
1675  print('could not change variable type of variable %s' % var)
1676 
1677  def getVars(self, transformed=False):
1678  """Retrieve all variables.
1679 
1680  :param transformed: get transformed variables instead of original (Default value = False)
1681 
1682  """
1683  cdef SCIP_VAR** _vars
1684  cdef SCIP_VAR* _var
1685  cdef int _nvars
1686  vars = []
1687 
1688  if transformed:
1689  _vars = SCIPgetVars(self._scip)
1690  _nvars = SCIPgetNVars(self._scip)
1691  else:
1692  _vars = SCIPgetOrigVars(self._scip)
1693  _nvars = SCIPgetNOrigVars(self._scip)
1694 
1695  for i in range(_nvars):
1696  ptr = <size_t>(_vars[i])
1697 
1698  # check whether the corresponding variable exists already
1699  if ptr in self._modelvars:
1700  vars.append(self._modelvars[ptr])
1701  else:
1702  # create a new variable
1703  var = Variable.create(_vars[i])
1704  assert var.ptr() == ptr
1705  self._modelvars[ptr] = var
1706  vars.append(var)
1707 
1708  return vars
1709 
1710  def getNVars(self):
1711  """Retrieve number of variables in the problems"""
1712  return SCIPgetNVars(self._scip)
1713 
1714  def getNConss(self):
1715  """Retrieve the number of constraints."""
1716  return SCIPgetNConss(self._scip)
1717 
1718  def getNIntVars(self):
1719  """gets number of integer active problem variables"""
1720  return SCIPgetNIntVars(self._scip)
1721 
1722  def getNBinVars(self):
1723  """gets number of binary active problem variables"""
1724  return SCIPgetNBinVars(self._scip)
1725 
1726  def updateNodeLowerbound(self, Node node, lb):
1727  """if given value is larger than the node's lower bound (in transformed problem),
1728  sets the node's lower bound to the new value
1729 
1730  :param node: Node, the node to update
1731  :param newbound: float, new bound (if greater) for the node
1732 
1733  """
1734  PY_SCIP_CALL(SCIPupdateNodeLowerbound(self._scip, node.scip_node, lb))
1735 
1736  # Node methods
1737  def getBestChild(self):
1738  """gets the best child of the focus node w.r.t. the node selection strategy."""
1739  return Node.create(SCIPgetBestChild(self._scip))
1740 
1741  def getBestSibling(self):
1742  """gets the best sibling of the focus node w.r.t. the node selection strategy."""
1743  return Node.create(SCIPgetBestSibling(self._scip))
1744 
1745  def getBestLeaf(self):
1746  """gets the best leaf from the node queue w.r.t. the node selection strategy."""
1747  return Node.create(SCIPgetBestLeaf(self._scip))
1748 
1749  def getBestNode(self):
1750  """gets the best node from the tree (child, sibling, or leaf) w.r.t. the node selection strategy."""
1751  return Node.create(SCIPgetBestNode(self._scip))
1752 
1753  def getBestboundNode(self):
1754  """gets the node with smallest lower bound from the tree (child, sibling, or leaf)."""
1755  return Node.create(SCIPgetBestboundNode(self._scip))
1756 
1757  def getOpenNodes(self):
1758  """access to all data of open nodes (leaves, children, and siblings)
1759 
1760  :return: three lists containing open leaves, children, siblings
1761  """
1762  cdef SCIP_NODE** _leaves
1763  cdef SCIP_NODE** _children
1764  cdef SCIP_NODE** _siblings
1765  cdef int _nleaves
1766  cdef int _nchildren
1767  cdef int _nsiblings
1768 
1769  PY_SCIP_CALL(SCIPgetOpenNodesData(self._scip, &_leaves, &_children, &_siblings, &_nleaves, &_nchildren, &_nsiblings))
1770 
1771  leaves = [Node.create(_leaves[i]) for i in range(_nleaves)]
1772  children = [Node.create(_children[i]) for i in range(_nchildren)]
1773  siblings = [Node.create(_siblings[i]) for i in range(_nsiblings)]
1774 
1775  return leaves, children, siblings
1776 
1777  def repropagateNode(self, Node node):
1778  """marks the given node to be propagated again the next time a node of its subtree is processed"""
1779  PY_SCIP_CALL(SCIPrepropagateNode(self._scip, node.scip_node))
1780 
1781 
1782  # LP Methods
1783  def getLPSolstat(self):
1784  """Gets solution status of current LP"""
1785  return SCIPgetLPSolstat(self._scip)
1786 
1787 
1788  def constructLP(self):
1789  """makes sure that the LP of the current node is loaded and
1790  may be accessed through the LP information methods
1791 
1792  :return: bool cutoff, i.e. can the node be cut off?
1793 
1794  """
1795  cdef SCIP_Bool cutoff
1796  PY_SCIP_CALL(SCIPconstructLP(self._scip, &cutoff))
1797  return cutoff
1798 
1799  def getLPObjVal(self):
1800  """gets objective value of current LP (which is the sum of column and loose objective value)"""
1801 
1802  return SCIPgetLPObjval(self._scip)
1803 
1804  def getLPColsData(self):
1805  """Retrieve current LP columns"""
1806  cdef SCIP_COL** cols
1807  cdef int ncols
1808 
1809  PY_SCIP_CALL(SCIPgetLPColsData(self._scip, &cols, &ncols))
1810  return [Column.create(cols[i]) for i in range(ncols)]
1811 
1812  def getLPRowsData(self):
1813  """Retrieve current LP rows"""
1814  cdef SCIP_ROW** rows
1815  cdef int nrows
1816 
1817  PY_SCIP_CALL(SCIPgetLPRowsData(self._scip, &rows, &nrows))
1818  return [Row.create(rows[i]) for i in range(nrows)]
1819 
1820  def getNLPRows(self):
1821  """Retrieve the number of rows currently in the LP"""
1822  return SCIPgetNLPRows(self._scip)
1823 
1824  def getNLPCols(self):
1825  """Retrieve the number of cols currently in the LP"""
1826  return SCIPgetNLPCols(self._scip)
1827 
1828  def getLPBasisInd(self):
1829  """Gets all indices of basic columns and rows: index i >= 0 corresponds to column i, index i < 0 to row -i-1"""
1830  cdef int nrows = SCIPgetNLPRows(self._scip)
1831  cdef int* inds = <int *> malloc(nrows * sizeof(int))
1832 
1833  PY_SCIP_CALL(SCIPgetLPBasisInd(self._scip, inds))
1834  result = [inds[i] for i in range(nrows)]
1835  free(inds)
1836  return result
1837 
1838  def getLPBInvRow(self, row):
1839  """gets a row from the inverse basis matrix B^-1"""
1840  # TODO: sparsity information
1841  cdef int nrows = SCIPgetNLPRows(self._scip)
1842  cdef SCIP_Real* coefs = <SCIP_Real*> malloc(nrows * sizeof(SCIP_Real))
1843 
1844  PY_SCIP_CALL(SCIPgetLPBInvRow(self._scip, row, coefs, NULL, NULL))
1845  result = [coefs[i] for i in range(nrows)]
1846  free(coefs)
1847  return result
1848 
1849  def getLPBInvARow(self, row):
1850  """gets a row from B^-1 * A"""
1851  # TODO: sparsity information
1852  cdef int ncols = SCIPgetNLPCols(self._scip)
1853  cdef SCIP_Real* coefs = <SCIP_Real*> malloc(ncols * sizeof(SCIP_Real))
1854 
1855  PY_SCIP_CALL(SCIPgetLPBInvARow(self._scip, row, NULL, coefs, NULL, NULL))
1856  result = [coefs[i] for i in range(ncols)]
1857  free(coefs)
1858  return result
1859 
1860  def isLPSolBasic(self):
1861  """returns whether the current LP solution is basic, i.e. is defined by a valid simplex basis"""
1862  return SCIPisLPSolBasic(self._scip)
1863 
1864  #TODO: documentation!!
1865  # LP Row Methods
1866  def createEmptyRowSepa(self, Sepa sepa, name="row", lhs = 0.0, rhs = None, local = True, modifiable = False, removable = True):
1867  """creates and captures an LP row without any coefficients from a separator
1868 
1869  :param sepa: separator that creates the row
1870  :param name: name of row (Default value = "row")
1871  :param lhs: left hand side of row (Default value = 0)
1872  :param rhs: right hand side of row (Default value = None)
1873  :param local: is row only valid locally? (Default value = True)
1874  :param modifiable: is row modifiable during node processing (subject to column generation)? (Default value = False)
1875  :param removable: should the row be removed from the LP due to aging or cleanup? (Default value = True)
1876  """
1877  cdef SCIP_ROW* row
1878  lhs = -SCIPinfinity(self._scip) if lhs is None else lhs
1879  rhs = SCIPinfinity(self._scip) if rhs is None else rhs
1880  scip_sepa = SCIPfindSepa(self._scip, str_conversion(sepa.name))
1881  PY_SCIP_CALL(SCIPcreateEmptyRowSepa(self._scip, &row, scip_sepa, str_conversion(name), lhs, rhs, local, modifiable, removable))
1882  PyRow = Row.create(row)
1883  return PyRow
1884 
1885  def createEmptyRowUnspec(self, name="row", lhs = 0.0, rhs = None, local = True, modifiable = False, removable = True):
1886  """creates and captures an LP row without any coefficients from an unspecified source
1887 
1888  :param name: name of row (Default value = "row")
1889  :param lhs: left hand side of row (Default value = 0)
1890  :param rhs: right hand side of row (Default value = None)
1891  :param local: is row only valid locally? (Default value = True)
1892  :param modifiable: is row modifiable during node processing (subject to column generation)? (Default value = False)
1893  :param removable: should the row be removed from the LP due to aging or cleanup? (Default value = True)
1894  """
1895  cdef SCIP_ROW* row
1896  lhs = -SCIPinfinity(self._scip) if lhs is None else lhs
1897  rhs = SCIPinfinity(self._scip) if rhs is None else rhs
1898  PY_SCIP_CALL(SCIPcreateEmptyRowUnspec(self._scip, &row, str_conversion(name), lhs, rhs, local, modifiable, removable))
1899  PyRow = Row.create(row)
1900  return PyRow
1901 
1902  def getRowActivity(self, Row row):
1903  """returns the activity of a row in the last LP or pseudo solution"""
1904  return SCIPgetRowActivity(self._scip, row.scip_row)
1905 
1906  def getRowLPActivity(self, Row row):
1907  """returns the activity of a row in the last LP solution"""
1908  return SCIPgetRowLPActivity(self._scip, row.scip_row)
1909 
1910  # TODO: do we need this? (also do we need release var??)
1911  def releaseRow(self, Row row not None):
1912  """decreases usage counter of LP row, and frees memory if necessary"""
1913  PY_SCIP_CALL(SCIPreleaseRow(self._scip, &row.scip_row))
1914 
1915  def cacheRowExtensions(self, Row row not None):
1916  """informs row, that all subsequent additions of variables to the row should be cached and not directly applied;
1917  after all additions were applied, flushRowExtensions() must be called;
1918  while the caching of row extensions is activated, information methods of the row give invalid results;
1919  caching should be used, if a row is build with addVarToRow() calls variable by variable to increase the performance"""
1920  PY_SCIP_CALL(SCIPcacheRowExtensions(self._scip, row.scip_row))
1921 
1922  def flushRowExtensions(self, Row row not None):
1923  """flushes all cached row extensions after a call of cacheRowExtensions() and merges coefficients with equal columns into a single coefficient"""
1924  PY_SCIP_CALL(SCIPflushRowExtensions(self._scip, row.scip_row))
1925 
1926  def addVarToRow(self, Row row not None, Variable var not None, value):
1927  """resolves variable to columns and adds them with the coefficient to the row"""
1928  PY_SCIP_CALL(SCIPaddVarToRow(self._scip, row.scip_row, var.scip_var, value))
1929 
1930  def printRow(self, Row row not None):
1931  """Prints row."""
1932  PY_SCIP_CALL(SCIPprintRow(self._scip, row.scip_row, NULL))
1933 
1934  def getRowNumIntCols(self, Row row):
1935  """Returns number of intergal columns in the row"""
1936  return SCIPgetRowNumIntCols(self._scip, row.scip_row)
1937 
1938  def getRowObjParallelism(self, Row row):
1939  """Returns 1 if the row is parallel, and 0 if orthogonal"""
1940  return SCIPgetRowObjParallelism(self._scip, row.scip_row)
1941 
1942  def getRowParallelism(self, Row row1, Row row2, orthofunc=101):
1943  """Returns the degree of parallelism between hyplerplanes. 1 if perfectly parallel, 0 if orthognal.
1944  101 in this case is an 'e' (euclidean) in ASCII. The other accpetable input is 100 (d for discrete)."""
1945  return SCIProwGetParallelism(row1.scip_row, row2.scip_row, orthofunc)
1946 
1947  def getRowDualSol(self, Row row):
1948  """Gets the dual LP solution of a row"""
1949  return SCIProwGetDualsol(row.scip_row)
1950 
1951  # Cutting Plane Methods
1952  def addPoolCut(self, Row row not None):
1953  """if not already existing, adds row to global cut pool"""
1954  PY_SCIP_CALL(SCIPaddPoolCut(self._scip, row.scip_row))
1955 
1956  def getCutEfficacy(self, Row cut not None, Solution sol = None):
1957  """returns efficacy of the cut with respect to the given primal solution or the current LP solution: e = -feasibility/norm"""
1958  return SCIPgetCutEfficacy(self._scip, NULL if sol is None else sol.sol, cut.scip_row)
1959 
1960  def isCutEfficacious(self, Row cut not None, Solution sol = None):
1961  """ returns whether the cut's efficacy with respect to the given primal solution or the current LP solution is greater than the minimal cut efficacy"""
1962  return SCIPisCutEfficacious(self._scip, NULL if sol is None else sol.sol, cut.scip_row)
1963 
1964  def getCutLPSolCutoffDistance(self, Row cut not None, Solution sol not None):
1965  """ returns row's cutoff distance in the direction of the given primal solution"""
1966  return SCIPgetCutLPSolCutoffDistance(self._scip, sol.sol, cut.scip_row)
1967 
1968  def addCut(self, Row cut not None, forcecut = False):
1969  """adds cut to separation storage and returns whether cut has been detected to be infeasible for local bounds"""
1970  cdef SCIP_Bool infeasible
1971  PY_SCIP_CALL(SCIPaddRow(self._scip, cut.scip_row, forcecut, &infeasible))
1972  return infeasible
1973 
1974  def getNCuts(self):
1975  """Retrieve total number of cuts in storage"""
1976  return SCIPgetNCuts(self._scip)
1977 
1978  def getNCutsApplied(self):
1979  """Retrieve number of currently applied cuts"""
1980  return SCIPgetNCutsApplied(self._scip)
1981 
1982  def getNSepaRounds(self):
1983  """Retrieve the number of separation rounds that have been performed
1984  at the current node"""
1985  return SCIPgetNSepaRounds(self._scip)
1986 
1987  def separateSol(self, Solution sol = None, pretendroot = False, allowlocal = True, onlydelayed = False):
1988  """separates the given primal solution or the current LP solution by calling the separators and constraint handlers'
1989  separation methods;
1990  the generated cuts are stored in the separation storage and can be accessed with the methods SCIPgetCuts() and
1991  SCIPgetNCuts();
1992  after evaluating the cuts, you have to call SCIPclearCuts() in order to remove the cuts from the
1993  separation storage;
1994  it is possible to call SCIPseparateSol() multiple times with different solutions and evaluate the found cuts
1995  afterwards
1996  :param Solution sol: solution to separate, None to use current lp solution (Default value = None)
1997  :param pretendroot: should the cut separators be called as if we are at the root node? (Default value = "False")
1998  :param allowlocal: should the separator be asked to separate local cuts (Default value = True)
1999  :param onlydelayed: should only separators be called that were delayed in the previous round? (Default value = False)
2000  returns
2001  delayed -- whether a separator was delayed
2002  cutoff -- whether the node can be cut off
2003  """
2004  cdef SCIP_Bool delayed
2005  cdef SCIP_Bool cutoff
2006 
2007  PY_SCIP_CALL( SCIPseparateSol(self._scip, NULL if sol is None else sol.sol, pretendroot, allowlocal, onlydelayed, &delayed, &cutoff) )
2008  return delayed, cutoff
2009 
2010  # Constraint functions
2011  def addCons(self, cons, name='', initial=True, separate=True,
2012  enforce=True, check=True, propagate=True, local=False,
2013  modifiable=False, dynamic=False, removable=False,
2014  stickingatnode=False):
2015  """Add a linear or nonlinear constraint.
2016 
2017  :param cons: constraint object
2018  :param name: the name of the constraint, generic name if empty (Default value = '')
2019  :param initial: should the LP relaxation of constraint be in the initial LP? (Default value = True)
2020  :param separate: should the constraint be separated during LP processing? (Default value = True)
2021  :param enforce: should the constraint be enforced during node processing? (Default value = True)
2022  :param check: should the constraint be checked for feasibility? (Default value = True)
2023  :param propagate: should the constraint be propagated during node processing? (Default value = True)
2024  :param local: is the constraint only valid locally? (Default value = False)
2025  :param modifiable: is the constraint modifiable (subject to column generation)? (Default value = False)
2026  :param dynamic: is the constraint subject to aging? (Default value = False)
2027  :param removable: should the relaxation be removed from the LP due to aging or cleanup? (Default value = False)
2028  :param stickingatnode: should the constraint always be kept at the node where it was added, even if it may be moved to a more global node? (Default value = False)
2029  :return The added @ref scip#Constraint "Constraint" object.
2030 
2031  """
2032  assert isinstance(cons, ExprCons), "given constraint is not ExprCons but %s" % cons.__class__.__name__
2033 
2034  # replace empty name with generic one
2035  if name == '':
2036  name = 'c'+str(SCIPgetNConss(self._scip)+1)
2037 
2038  kwargs = dict(name=name, initial=initial, separate=separate,
2039  enforce=enforce, check=check,
2040  propagate=propagate, local=local,
2041  modifiable=modifiable, dynamic=dynamic,
2042  removable=removable,
2043  stickingatnode=stickingatnode)
2044  kwargs['lhs'] = -SCIPinfinity(self._scip) if cons._lhs is None else cons._lhs
2045  kwargs['rhs'] = SCIPinfinity(self._scip) if cons._rhs is None else cons._rhs
2046 
2047  deg = cons.expr.degree()
2048  if deg <= 1:
2049  return self._addLinCons(cons, **kwargs)
2050  elif deg <= 2:
2051  return self._addQuadCons(cons, **kwargs)
2052  elif deg == float('inf'): # general nonlinear
2053  return self._addGenNonlinearCons(cons, **kwargs)
2054  else:
2055  return self._addNonlinearCons(cons, **kwargs)
2056 
2057  def addConss(self, conss, name='', initial=True, separate=True,
2058  enforce=True, check=True, propagate=True, local=False,
2059  modifiable=False, dynamic=False, removable=False,
2060  stickingatnode=False):
2061  """Adds multiple linear or quadratic constraints.
2062 
2063  Each of the constraints is added to the model using Model.addCons().
2064 
2065  For all parameters, except @p conss, this method behaves differently depending on the type of the passed argument:
2066  1. If the value is iterable, it must be of the same length as @p conss. For each constraint, Model.addCons() will be called with the value at the corresponding index.
2067  2. Else, the (default) value will be applied to all of the constraints.
2068 
2069  :param conss An iterable of constraint objects. Any iterable will be converted into a list before further processing.
2070  :param name: the names of the constraints, generic name if empty (Default value = ''). If a single string is passed, it will be suffixed by an underscore and the enumerated index of the constraint (starting with 0).
2071  :param initial: should the LP relaxation of constraints be in the initial LP? (Default value = True)
2072  :param separate: should the constraints be separated during LP processing? (Default value = True)
2073  :param enforce: should the constraints be enforced during node processing? (Default value = True)
2074  :param check: should the constraints be checked for feasibility? (Default value = True)
2075  :param propagate: should the constraints be propagated during node processing? (Default value = True)
2076  :param local: are the constraints only valid locally? (Default value = False)
2077  :param modifiable: are the constraints modifiable (subject to column generation)? (Default value = False)
2078  :param dynamic: are the constraints subject to aging? (Default value = False)
2079  :param removable: should the relaxation be removed from the LP due to aging or cleanup? (Default value = False)
2080  :param stickingatnode: should the constraints always be kept at the node where it was added, even if it may be @oved to a more global node? (Default value = False)
2081  :return A list of added @ref scip#Constraint "Constraint" objects.
2082 
2083  :see addCons()
2084  """
2085  def ensure_iterable(elem, length):
2086  if isinstance(elem, Iterable):
2087  return elem
2088  else:
2089  return list(repeat(elem, length))
2090 
2091  assert isinstance(conss, Iterable), "Given constraint list is not iterable."
2092 
2093  conss = list(conss)
2094  n_conss = len(conss)
2095 
2096  if isinstance(name, str):
2097  if name == "":
2098  name = ["" for idx in range(n_conss)]
2099  else:
2100  name = ["%s_%s" % (name, idx) for idx in range(n_conss)]
2101  initial = ensure_iterable(initial, n_conss)
2102  separate = ensure_iterable(separate, n_conss)
2103  enforce = ensure_iterable(enforce, n_conss)
2104  check = ensure_iterable(check, n_conss)
2105  propagate = ensure_iterable(propagate, n_conss)
2106  local = ensure_iterable(local, n_conss)
2107  modifiable = ensure_iterable(modifiable, n_conss)
2108  dynamic = ensure_iterable(dynamic, n_conss)
2109  removable = ensure_iterable(removable, n_conss)
2110  stickingatnode = ensure_iterable(stickingatnode, n_conss)
2111 
2112  constraints = []
2113  for i, cons in enumerate(conss):
2114  constraints.append(
2115  self.addCons(cons, name[i], initial[i], separate[i], enforce[i],
2116  check[i], propagate[i], local[i], modifiable[i],
2117  dynamic[i], removable[i], stickingatnode[i])
2118  )
2119 
2120  return constraints
2121 
2122  def printCons(self, Constraint constraint):
2123  return PY_SCIP_CALL(SCIPprintCons(self._scip, constraint.scip_cons, NULL))
2124 
2125  def _addLinCons(self, ExprCons lincons, **kwargs):
2126  assert isinstance(lincons, ExprCons), "given constraint is not ExprCons but %s" % lincons.__class__.__name__
2127 
2128  assert lincons.expr.degree() <= 1, "given constraint is not linear, degree == %d" % lincons.expr.degree()
2129  terms = lincons.expr.terms
2130 
2131  cdef SCIP_CONS* scip_cons
2132 
2133  cdef int nvars = len(terms.items())
2134 
2135  vars_array = <SCIP_VAR**> malloc(nvars * sizeof(SCIP_VAR*))
2136  coeffs_array = <SCIP_Real*> malloc(nvars * sizeof(SCIP_Real))
2137 
2138  for i, (key, coeff) in enumerate(terms.items()):
2139  vars_array[i] = <SCIP_VAR*>(<Variable>key[0]).scip_var
2140  coeffs_array[i] = <SCIP_Real>coeff
2141 
2142  PY_SCIP_CALL(SCIPcreateConsLinear(
2143  self._scip, &scip_cons, str_conversion(kwargs['name']), nvars, vars_array, coeffs_array,
2144  kwargs['lhs'], kwargs['rhs'], kwargs['initial'],
2145  kwargs['separate'], kwargs['enforce'], kwargs['check'],
2146  kwargs['propagate'], kwargs['local'], kwargs['modifiable'],
2147  kwargs['dynamic'], kwargs['removable'], kwargs['stickingatnode']))
2148 
2149  PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons))
2150  PyCons = Constraint.create(scip_cons)
2151  PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons))
2152 
2153  free(vars_array)
2154  free(coeffs_array)
2155 
2156  return PyCons
2157 
2158  def _addQuadCons(self, ExprCons quadcons, **kwargs):
2159  terms = quadcons.expr.terms
2160  assert quadcons.expr.degree() <= 2, "given constraint is not quadratic, degree == %d" % quadcons.expr.degree()
2161 
2162  cdef SCIP_CONS* scip_cons
2163  cdef SCIP_EXPR* prodexpr
2164  PY_SCIP_CALL(SCIPcreateConsQuadraticNonlinear(
2165  self._scip, &scip_cons, str_conversion(kwargs['name']),
2166  0, NULL, NULL, # linear
2167  0, NULL, NULL, NULL, # quadratc
2168  kwargs['lhs'], kwargs['rhs'],
2169  kwargs['initial'], kwargs['separate'], kwargs['enforce'],
2170  kwargs['check'], kwargs['propagate'], kwargs['local'],
2171  kwargs['modifiable'], kwargs['dynamic'], kwargs['removable']))
2172 
2173  for v, c in terms.items():
2174  if len(v) == 1: # linear
2175  var = <Variable>v[0]
2176  PY_SCIP_CALL(SCIPaddLinearVarNonlinear(self._scip, scip_cons, var.scip_var, c))
2177  else: # quadratic
2178  assert len(v) == 2, 'term length must be 1 or 2 but it is %s' % len(v)
2179 
2180  varexprs = <SCIP_EXPR**> malloc(2 * sizeof(SCIP_EXPR*))
2181  var1, var2 = <Variable>v[0], <Variable>v[1]
2182  PY_SCIP_CALL( SCIPcreateExprVar(self._scip, &varexprs[0], var1.scip_var, NULL, NULL) )
2183  PY_SCIP_CALL( SCIPcreateExprVar(self._scip, &varexprs[1], var2.scip_var, NULL, NULL) )
2184  PY_SCIP_CALL( SCIPcreateExprProduct(self._scip, &prodexpr, 2, varexprs, 1.0, NULL, NULL) )
2185 
2186  PY_SCIP_CALL( SCIPaddExprNonlinear(self._scip, scip_cons, prodexpr, c) )
2187 
2188  PY_SCIP_CALL( SCIPreleaseExpr(self._scip, &prodexpr) )
2189  PY_SCIP_CALL( SCIPreleaseExpr(self._scip, &varexprs[1]) )
2190  PY_SCIP_CALL( SCIPreleaseExpr(self._scip, &varexprs[0]) )
2191  free(varexprs)
2192 
2193 
2194  PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons))
2195  PyCons = Constraint.create(scip_cons)
2196  PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons))
2197  return PyCons
2198 
2199  def _addNonlinearCons(self, ExprCons cons, **kwargs):
2200  cdef SCIP_EXPR* expr
2201  cdef SCIP_EXPR** varexprs
2202  cdef SCIP_EXPR** monomials
2203  cdef int* idxs
2204  cdef SCIP_CONS* scip_cons
2205 
2206  terms = cons.expr.terms
2207 
2208  # collect variables
2209  variables = {var.ptr():var for term in terms for var in term}
2210  variables = list(variables.values())
2211  varindex = {var.ptr():idx for (idx,var) in enumerate(variables)}
2212 
2213  # create monomials for terms
2214  monomials = <SCIP_EXPR**> malloc(len(terms) * sizeof(SCIP_EXPR*))
2215  termcoefs = <SCIP_Real*> malloc(len(terms) * sizeof(SCIP_Real))
2216  for i, (term, coef) in enumerate(terms.items()):
2217  termvars = <SCIP_VAR**> malloc(len(term) * sizeof(SCIP_VAR*))
2218  for j, var in enumerate(term):
2219  termvars[j] = (<Variable>var).scip_var
2220  PY_SCIP_CALL( SCIPcreateExprMonomial(self._scip, &monomials[i], <int>len(term), termvars, NULL, NULL, NULL) )
2221  termcoefs[i] = <SCIP_Real>coef
2222  free(termvars)
2223 
2224  # create polynomial from monomials
2225  PY_SCIP_CALL( SCIPcreateExprSum(self._scip, &expr, <int>len(terms), monomials, termcoefs, 0.0, NULL, NULL))
2226 
2227  # create nonlinear constraint for expr
2228  PY_SCIP_CALL( SCIPcreateConsNonlinear(
2229  self._scip,
2230  &scip_cons,
2231  str_conversion(kwargs['name']),
2232  expr,
2233  kwargs['lhs'],
2234  kwargs['rhs'],
2235  kwargs['initial'],
2236  kwargs['separate'],
2237  kwargs['enforce'],
2238  kwargs['check'],
2239  kwargs['propagate'],
2240  kwargs['local'],
2241  kwargs['modifiable'],
2242  kwargs['dynamic'],
2243  kwargs['removable']) )
2244  PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons))
2245  PyCons = Constraint.create(scip_cons)
2246  PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons))
2247  PY_SCIP_CALL( SCIPreleaseExpr(self._scip, &expr) )
2248  for i in range(<int>len(terms)):
2249  PY_SCIP_CALL(SCIPreleaseExpr(self._scip, &monomials[i]))
2250  free(monomials)
2251  free(termcoefs)
2252  return PyCons
2253 
2254  def _addGenNonlinearCons(self, ExprCons cons, **kwargs):
2255  cdef SCIP_EXPR** childrenexpr
2256  cdef SCIP_EXPR** scipexprs
2257  cdef SCIP_CONS* scip_cons
2258  cdef int nchildren
2259 
2260  # get arrays from python's expression tree
2261  expr = cons.expr
2262  nodes = expr_to_nodes(expr)
2263 
2264  # in nodes we have a list of tuples: each tuple is of the form
2265  # (operator, [indices]) where indices are the indices of the tuples
2266  # that are the children of this operator. This is sorted,
2267  # so we are going to do is:
2268  # loop over the nodes and create the expression of each
2269  # Note1: when the operator is Operator.const, [indices] stores the value
2270  # Note2: we need to compute the number of variable operators to find out
2271  # how many variables are there.
2272  nvars = 0
2273  for node in nodes:
2274  if node[0] == Operator.varidx:
2275  nvars += 1
2276  vars = <SCIP_VAR**> malloc(nvars * sizeof(SCIP_VAR*))
2277 
2278  varpos = 0
2279  scipexprs = <SCIP_EXPR**> malloc(len(nodes) * sizeof(SCIP_EXPR*))
2280  for i,node in enumerate(nodes):
2281  opidx = node[0]
2282  if opidx == Operator.varidx:
2283  assert len(node[1]) == 1
2284  pyvar = node[1][0] # for vars we store the actual var!
2285  PY_SCIP_CALL( SCIPcreateExprVar(self._scip, &scipexprs[i], (<Variable>pyvar).scip_var, NULL, NULL) )
2286  vars[varpos] = (<Variable>pyvar).scip_var
2287  varpos += 1
2288  continue
2289  if opidx == Operator.const:
2290  assert len(node[1]) == 1
2291  value = node[1][0]
2292  PY_SCIP_CALL( SCIPcreateExprValue(self._scip, &scipexprs[i], <SCIP_Real>value, NULL, NULL) )
2293  continue
2294  if opidx == Operator.add:
2295  nchildren = len(node[1])
2296  childrenexpr = <SCIP_EXPR**> malloc(nchildren * sizeof(SCIP_EXPR*))
2297  coefs = <SCIP_Real*> malloc(nchildren * sizeof(SCIP_Real))
2298  for c, pos in enumerate(node[1]):
2299  childrenexpr[c] = scipexprs[pos]
2300  coefs[c] = 1
2301  PY_SCIP_CALL( SCIPcreateExprSum(self._scip, &scipexprs[i], nchildren, childrenexpr, coefs, 0, NULL, NULL))
2302  free(coefs)
2303  free(childrenexpr)
2304  continue
2305  if opidx == Operator.prod:
2306  nchildren = len(node[1])
2307  childrenexpr = <SCIP_EXPR**> malloc(nchildren * sizeof(SCIP_EXPR*))
2308  for c, pos in enumerate(node[1]):
2309  childrenexpr[c] = scipexprs[pos]
2310  PY_SCIP_CALL( SCIPcreateExprProduct(self._scip, &scipexprs[i], nchildren, childrenexpr, 1, NULL, NULL) )
2311  free(childrenexpr)
2312  continue
2313  if opidx == Operator.power:
2314  # the second child is the exponent which is a const
2315  valuenode = nodes[node[1][1]]
2316  assert valuenode[0] == Operator.const
2317  exponent = valuenode[1][0]
2318  PY_SCIP_CALL( SCIPcreateExprPow(self._scip, &scipexprs[i], scipexprs[node[1][0]], <SCIP_Real>exponent, NULL, NULL ))
2319  continue
2320  if opidx == Operator.exp:
2321  assert len(node[1]) == 1
2322  PY_SCIP_CALL( SCIPcreateExprExp(self._scip, &scipexprs[i], scipexprs[node[1][0]], NULL, NULL ))
2323  continue
2324  if opidx == Operator.log:
2325  assert len(node[1]) == 1
2326  PY_SCIP_CALL( SCIPcreateExprLog(self._scip, &scipexprs[i], scipexprs[node[1][0]], NULL, NULL ))
2327  continue
2328  if opidx == Operator.sqrt:
2329  assert len(node[1]) == 1
2330  PY_SCIP_CALL( SCIPcreateExprPow(self._scip, &scipexprs[i], scipexprs[node[1][0]], <SCIP_Real>0.5, NULL, NULL) )
2331  continue
2332  if opidx == Operator.sin:
2333  assert len(node[1]) == 1
2334  PY_SCIP_CALL( SCIPcreateExprSin(self._scip, &scipexprs[i], scipexprs[node[1][0]], NULL, NULL) )
2335  continue
2336  if opidx == Operator.cos:
2337  assert len(node[1]) == 1
2338  PY_SCIP_CALL( SCIPcreateExprCos(self._scip, &scipexprs[i], scipexprs[node[1][0]], NULL, NULL) )
2339  continue
2340  if opidx == Operator.fabs:
2341  assert len(node[1]) == 1
2342  PY_SCIP_CALL( SCIPcreateExprAbs(self._scip, &scipexprs[i], scipexprs[node[1][0]], NULL, NULL ))
2343  continue
2344  # default:
2345  raise NotImplementedError
2346  assert varpos == nvars
2347 
2348  # create nonlinear constraint for the expression root
2349  PY_SCIP_CALL( SCIPcreateConsNonlinear(
2350  self._scip,
2351  &scip_cons,
2352  str_conversion(kwargs['name']),
2353  scipexprs[len(nodes) - 1],
2354  kwargs['lhs'],
2355  kwargs['rhs'],
2356  kwargs['initial'],
2357  kwargs['separate'],
2358  kwargs['enforce'],
2359  kwargs['check'],
2360  kwargs['propagate'],
2361  kwargs['local'],
2362  kwargs['modifiable'],
2363  kwargs['dynamic'],
2364  kwargs['removable']) )
2365  PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons))
2366  PyCons = Constraint.create(scip_cons)
2367  PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons))
2368  for i in range(len(nodes)):
2369  PY_SCIP_CALL( SCIPreleaseExpr(self._scip, &scipexprs[i]) )
2370 
2371  # free more memory
2372  free(scipexprs)
2373  free(vars)
2374 
2375  return PyCons
2376 
2377  def addConsCoeff(self, Constraint cons, Variable var, coeff):
2378  """Add coefficient to the linear constraint (if non-zero).
2379 
2380  :param Constraint cons: constraint to be changed
2381  :param Variable var: variable to be added
2382  :param coeff: coefficient of new variable
2383 
2384  """
2385  PY_SCIP_CALL(SCIPaddCoefLinear(self._scip, cons.scip_cons, var.scip_var, coeff))
2386 
2387  def addConsNode(self, Node node, Constraint cons, Node validnode=None):
2388  """Add a constraint to the given node
2389 
2390  :param Node node: node to add the constraint to
2391  :param Constraint cons: constraint to add
2392  :param Node validnode: more global node where cons is also valid
2393 
2394  """
2395  if isinstance(validnode, Node):
2396  PY_SCIP_CALL(SCIPaddConsNode(self._scip, node.scip_node, cons.scip_cons, validnode.scip_node))
2397  else:
2398  PY_SCIP_CALL(SCIPaddConsNode(self._scip, node.scip_node, cons.scip_cons, NULL))
2399  Py_INCREF(cons)
2400 
2401  def addConsLocal(self, Constraint cons, Node validnode=None):
2402  """Add a constraint to the current node
2403 
2404  :param Constraint cons: constraint to add
2405  :param Node validnode: more global node where cons is also valid
2406 
2407  """
2408  if isinstance(validnode, Node):
2409  PY_SCIP_CALL(SCIPaddConsLocal(self._scip, cons.scip_cons, validnode.scip_node))
2410  else:
2411  PY_SCIP_CALL(SCIPaddConsLocal(self._scip, cons.scip_cons, NULL))
2412  Py_INCREF(cons)
2413 
2414  def addConsSOS1(self, vars, weights=None, name="SOS1cons",
2415  initial=True, separate=True, enforce=True, check=True,
2416  propagate=True, local=False, dynamic=False,
2417  removable=False, stickingatnode=False):
2418  """Add an SOS1 constraint.
2419 
2420  :param vars: list of variables to be included
2421  :param weights: list of weights (Default value = None)
2422  :param name: name of the constraint (Default value = "SOS1cons")
2423  :param initial: should the LP relaxation of constraint be in the initial LP? (Default value = True)
2424  :param separate: should the constraint be separated during LP processing? (Default value = True)
2425  :param enforce: should the constraint be enforced during node processing? (Default value = True)
2426  :param check: should the constraint be checked for feasibility? (Default value = True)
2427  :param propagate: should the constraint be propagated during node processing? (Default value = True)
2428  :param local: is the constraint only valid locally? (Default value = False)
2429  :param dynamic: is the constraint subject to aging? (Default value = False)
2430  :param removable: should the relaxation be removed from the LP due to aging or cleanup? (Default value = False)
2431  :param stickingatnode: should the constraint always be kept at the node where it was added, even if it may be moved to a more global node? (Default value = False)
2432 
2433  """
2434  cdef SCIP_CONS* scip_cons
2435  cdef int _nvars
2436 
2437  PY_SCIP_CALL(SCIPcreateConsSOS1(self._scip, &scip_cons, str_conversion(name), 0, NULL, NULL,
2438  initial, separate, enforce, check, propagate, local, dynamic, removable, stickingatnode))
2439 
2440  if weights is None:
2441  for v in vars:
2442  var = <Variable>v
2443  PY_SCIP_CALL(SCIPappendVarSOS1(self._scip, scip_cons, var.scip_var))
2444  else:
2445  nvars = len(vars)
2446  for i in range(nvars):
2447  var = <Variable>vars[i]
2448  PY_SCIP_CALL(SCIPaddVarSOS1(self._scip, scip_cons, var.scip_var, weights[i]))
2449 
2450  PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons))
2451  return Constraint.create(scip_cons)
2452 
2453  def addConsSOS2(self, vars, weights=None, name="SOS2cons",
2454  initial=True, separate=True, enforce=True, check=True,
2455  propagate=True, local=False, dynamic=False,
2456  removable=False, stickingatnode=False):
2457  """Add an SOS2 constraint.
2458 
2459  :param vars: list of variables to be included
2460  :param weights: list of weights (Default value = None)
2461  :param name: name of the constraint (Default value = "SOS2cons")
2462  :param initial: should the LP relaxation of constraint be in the initial LP? (Default value = True)
2463  :param separate: should the constraint be separated during LP processing? (Default value = True)
2464  :param enforce: should the constraint be enforced during node processing? (Default value = True)
2465  :param check: should the constraint be checked for feasibility? (Default value = True)
2466  :param propagate: is the constraint only valid locally? (Default value = True)
2467  :param local: is the constraint only valid locally? (Default value = False)
2468  :param dynamic: is the constraint subject to aging? (Default value = False)
2469  :param removable: should the relaxation be removed from the LP due to aging or cleanup? (Default value = False)
2470  :param stickingatnode: should the constraint always be kept at the node where it was added, even if it may be moved to a more global node? (Default value = False)
2471 
2472  """
2473  cdef SCIP_CONS* scip_cons
2474  cdef int _nvars
2475 
2476  PY_SCIP_CALL(SCIPcreateConsSOS2(self._scip, &scip_cons, str_conversion(name), 0, NULL, NULL,
2477  initial, separate, enforce, check, propagate, local, dynamic, removable, stickingatnode))
2478 
2479  if weights is None:
2480  for v in vars:
2481  var = <Variable>v
2482  PY_SCIP_CALL(SCIPappendVarSOS2(self._scip, scip_cons, var.scip_var))
2483  else:
2484  nvars = len(vars)
2485  for i in range(nvars):
2486  var = <Variable>vars[i]
2487  PY_SCIP_CALL(SCIPaddVarSOS2(self._scip, scip_cons, var.scip_var, weights[i]))
2488 
2489  PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons))
2490  return Constraint.create(scip_cons)
2491 
2492  def addConsAnd(self, vars, resvar, name="ANDcons",
2493  initial=True, separate=True, enforce=True, check=True,
2494  propagate=True, local=False, modifiable=False, dynamic=False,
2495  removable=False, stickingatnode=False):
2496  """Add an AND-constraint.
2497  :param vars: list of BINARY variables to be included (operators)
2498  :param resvar: BINARY variable (resultant)
2499  :param name: name of the constraint (Default value = "ANDcons")
2500  :param initial: should the LP relaxation of constraint be in the initial LP? (Default value = True)
2501  :param separate: should the constraint be separated during LP processing? (Default value = True)
2502  :param enforce: should the constraint be enforced during node processing? (Default value = True)
2503  :param check: should the constraint be checked for feasibility? (Default value = True)
2504  :param propagate: should the constraint be propagated during node processing? (Default value = True)
2505  :param local: is the constraint only valid locally? (Default value = False)
2506  :param modifiable: is the constraint modifiable (subject to column generation)? (Default value = False)
2507  :param dynamic: is the constraint subject to aging? (Default value = False)
2508  :param removable: should the relaxation be removed from the LP due to aging or cleanup? (Default value = False)
2509  :param stickingatnode: should the constraint always be kept at the node where it was added, even if it may be moved to a more global node? (Default value = False)
2510  """
2511  cdef SCIP_CONS* scip_cons
2512 
2513  nvars = len(vars)
2514 
2515  _vars = <SCIP_VAR**> malloc(len(vars) * sizeof(SCIP_VAR*))
2516  for idx, var in enumerate(vars):
2517  _vars[idx] = (<Variable>var).scip_var
2518  _resVar = (<Variable>resvar).scip_var
2519 
2520  PY_SCIP_CALL(SCIPcreateConsAnd(self._scip, &scip_cons, str_conversion(name), _resVar, nvars, _vars,
2521  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode))
2522 
2523  PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons))
2524  pyCons = Constraint.create(scip_cons)
2525  PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons))
2526 
2527  free(_vars)
2528 
2529  return pyCons
2530 
2531  def addConsOr(self, vars, resvar, name="ORcons",
2532  initial=True, separate=True, enforce=True, check=True,
2533  propagate=True, local=False, modifiable=False, dynamic=False,
2534  removable=False, stickingatnode=False):
2535  """Add an OR-constraint.
2536  :param vars: list of BINARY variables to be included (operators)
2537  :param resvar: BINARY variable (resultant)
2538  :param name: name of the constraint (Default value = "ORcons")
2539  :param initial: should the LP relaxation of constraint be in the initial LP? (Default value = True)
2540  :param separate: should the constraint be separated during LP processing? (Default value = True)
2541  :param enforce: should the constraint be enforced during node processing? (Default value = True)
2542  :param check: should the constraint be checked for feasibility? (Default value = True)
2543  :param propagate: should the constraint be propagated during node processing? (Default value = True)
2544  :param local: is the constraint only valid locally? (Default value = False)
2545  :param modifiable: is the constraint modifiable (subject to column generation)? (Default value = False)
2546  :param dynamic: is the constraint subject to aging? (Default value = False)
2547  :param removable: should the relaxation be removed from the LP due to aging or cleanup? (Default value = False)
2548  :param stickingatnode: should the constraint always be kept at the node where it was added, even if it may be moved to a more global node? (Default value = False)
2549  """
2550  cdef SCIP_CONS* scip_cons
2551 
2552  nvars = len(vars)
2553 
2554  _vars = <SCIP_VAR**> malloc(len(vars) * sizeof(SCIP_VAR*))
2555  for idx, var in enumerate(vars):
2556  _vars[idx] = (<Variable>var).scip_var
2557  _resVar = (<Variable>resvar).scip_var
2558 
2559  PY_SCIP_CALL(SCIPcreateConsOr(self._scip, &scip_cons, str_conversion(name), _resVar, nvars, _vars,
2560  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode))
2561 
2562  PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons))
2563  pyCons = Constraint.create(scip_cons)
2564  PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons))
2565 
2566  free(_vars)
2567 
2568  return pyCons
2569 
2570  def addConsXor(self, vars, rhsvar, name="XORcons",
2571  initial=True, separate=True, enforce=True, check=True,
2572  propagate=True, local=False, modifiable=False, dynamic=False,
2573  removable=False, stickingatnode=False):
2574  """Add a XOR-constraint.
2575  :param vars: list of BINARY variables to be included (operators)
2576  :param rhsvar: BOOLEAN value, explicit True, False or bool(obj) is needed (right-hand side)
2577  :param name: name of the constraint (Default value = "XORcons")
2578  :param initial: should the LP relaxation of constraint be in the initial LP? (Default value = True)
2579  :param separate: should the constraint be separated during LP processing? (Default value = True)
2580  :param enforce: should the constraint be enforced during node processing? (Default value = True)
2581  :param check: should the constraint be checked for feasibility? (Default value = True)
2582  :param propagate: should the constraint be propagated during node processing? (Default value = True)
2583  :param local: is the constraint only valid locally? (Default value = False)
2584  :param modifiable: is the constraint modifiable (subject to column generation)? (Default value = False)
2585  :param dynamic: is the constraint subject to aging? (Default value = False)
2586  :param removable: should the relaxation be removed from the LP due to aging or cleanup? (Default value = False)
2587  :param stickingatnode: should the constraint always be kept at the node where it was added, even if it may be moved to a more global node? (Default value = False)
2588  """
2589  cdef SCIP_CONS* scip_cons
2590 
2591  nvars = len(vars)
2592 
2593  assert type(rhsvar) is type(bool()), "Provide BOOLEAN value as rhsvar, you gave %s." % type(rhsvar)
2594  _vars = <SCIP_VAR**> malloc(len(vars) * sizeof(SCIP_VAR*))
2595  for idx, var in enumerate(vars):
2596  _vars[idx] = (<Variable>var).scip_var
2597 
2598  PY_SCIP_CALL(SCIPcreateConsXor(self._scip, &scip_cons, str_conversion(name), rhsvar, nvars, _vars,
2599  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode))
2600 
2601  PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons))
2602  pyCons = Constraint.create(scip_cons)
2603  PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons))
2604 
2605  free(_vars)
2606 
2607  return pyCons
2608 
2609  def addConsCardinality(self, consvars, cardval, indvars=None, weights=None, name="CardinalityCons",
2610  initial=True, separate=True, enforce=True, check=True,
2611  propagate=True, local=False, dynamic=False,
2612  removable=False, stickingatnode=False):
2613  """Add a cardinality constraint that allows at most 'cardval' many nonzero variables.
2614 
2615  :param consvars: list of variables to be included
2616  :param cardval: nonnegative integer
2617  :param indvars: indicator variables indicating which variables may be treated as nonzero in cardinality constraint, or None if new indicator variables should be introduced automatically (Default value = None)
2618  :param weights: weights determining the variable order, or None if variables should be ordered in the same way they were added to the constraint (Default value = None)
2619  :param name: name of the constraint (Default value = "CardinalityCons")
2620  :param initial: should the LP relaxation of constraint be in the initial LP? (Default value = True)
2621  :param separate: should the constraint be separated during LP processing? (Default value = True)
2622  :param enforce: should the constraint be enforced during node processing? (Default value = True)
2623  :param check: should the constraint be checked for feasibility? (Default value = True)
2624  :param propagate: should the constraint be propagated during node processing? (Default value = True)
2625  :param local: is the constraint only valid locally? (Default value = False)
2626  :param dynamic: is the constraint subject to aging? (Default value = False)
2627  :param removable: should the relaxation be removed from the LP due to aging or cleanup? (Default value = False)
2628  :param stickingatnode: should the constraint always be kept at the node where it was added, even if it may be moved to a more global node? (Default value = False)
2629 
2630  """
2631  cdef SCIP_CONS* scip_cons
2632  cdef SCIP_VAR* indvar
2633 
2634  PY_SCIP_CALL(SCIPcreateConsCardinality(self._scip, &scip_cons, str_conversion(name), 0, NULL, cardval, NULL, NULL,
2635  initial, separate, enforce, check, propagate, local, dynamic, removable, stickingatnode))
2636 
2637  # circumvent an annoying bug in SCIP 4.0.0 that does not allow uninitialized weights
2638  if weights is None:
2639  weights = list(range(1, len(consvars) + 1))
2640 
2641  for i, v in enumerate(consvars):
2642  var = <Variable>v
2643  if indvars:
2644  indvar = (<Variable>indvars[i]).scip_var
2645  else:
2646  indvar = NULL
2647  if weights is None:
2648  PY_SCIP_CALL(SCIPappendVarCardinality(self._scip, scip_cons, var.scip_var, indvar))
2649  else:
2650  PY_SCIP_CALL(SCIPaddVarCardinality(self._scip, scip_cons, var.scip_var, indvar, <SCIP_Real>weights[i]))
2651 
2652  PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons))
2653  pyCons = Constraint.create(scip_cons)
2654 
2655  PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons))
2656 
2657  return pyCons
2658 
2659 
2660  def addConsIndicator(self, cons, binvar=None, activeone=True, name="IndicatorCons",
2661  initial=True, separate=True, enforce=True, check=True,
2662  propagate=True, local=False, dynamic=False,
2663  removable=False, stickingatnode=False):
2664  """Add an indicator constraint for the linear inequality 'cons'.
2665 
2666  The 'binvar' argument models the redundancy of the linear constraint. A solution for which
2667  'binvar' is 1 must satisfy the constraint.
2668 
2669  :param cons: a linear inequality of the form "<="
2670  :param binvar: binary indicator variable, or None if it should be created (Default value = None)
2671  :param activeone: constraint should active if binvar is 1 (0 if activeone = False)
2672  :param name: name of the constraint (Default value = "IndicatorCons")
2673  :param initial: should the LP relaxation of constraint be in the initial LP? (Default value = True)
2674  :param separate: should the constraint be separated during LP processing? (Default value = True)
2675  :param enforce: should the constraint be enforced during node processing? (Default value = True)
2676  :param check: should the constraint be checked for feasibility? (Default value = True)
2677  :param propagate: should the constraint be propagated during node processing? (Default value = True)
2678  :param local: is the constraint only valid locally? (Default value = False)
2679  :param dynamic: is the constraint subject to aging? (Default value = False)
2680  :param removable: should the relaxation be removed from the LP due to aging or cleanup? (Default value = False)
2681  :param stickingatnode: should the constraint always be kept at the node where it was added, even if it may be moved to a more global node? (Default value = False)
2682 
2683  """
2684  assert isinstance(cons, ExprCons), "given constraint is not ExprCons but %s" % cons.__class__.__name__
2685  cdef SCIP_CONS* scip_cons
2686  cdef SCIP_VAR* _binVar
2687  if cons._lhs is not None and cons._rhs is not None:
2688  raise ValueError("expected inequality that has either only a left or right hand side")
2689 
2690  if cons.expr.degree() > 1:
2691  raise ValueError("expected linear inequality, expression has degree %d" % cons.expr.degree())
2692 
2693  if cons._rhs is not None:
2694  rhs = cons._rhs
2695  negate = False
2696  else:
2697  rhs = -cons._lhs
2698  negate = True
2699 
2700  if binvar is not None:
2701  _binVar = (<Variable>binvar).scip_var
2702  if not activeone:
2703  PY_SCIP_CALL(SCIPgetNegatedVar(self._scip, _binVar, &_binVar))
2704  else:
2705  _binVar = NULL
2706 
2707  PY_SCIP_CALL(SCIPcreateConsIndicator(self._scip, &scip_cons, str_conversion(name), _binVar, 0, NULL, NULL, rhs,
2708  initial, separate, enforce, check, propagate, local, dynamic, removable, stickingatnode))
2709  terms = cons.expr.terms
2710 
2711  for key, coeff in terms.items():
2712  var = <Variable>key[0]
2713  if negate:
2714  coeff = -coeff
2715  PY_SCIP_CALL(SCIPaddVarIndicator(self._scip, scip_cons, var.scip_var, <SCIP_Real>coeff))
2716 
2717  PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons))
2718  pyCons = Constraint.create(scip_cons)
2719 
2720  PY_SCIP_CALL(SCIPreleaseCons(self._scip, &scip_cons))
2721 
2722  return pyCons
2723 
2724  def getSlackVarIndicator(self, Constraint cons):
2725  """Get slack variable of an indicator constraint.
2726 
2727  :param Constraint cons: indicator constraint
2728 
2729  """
2730  cdef SCIP_VAR* var = SCIPgetSlackVarIndicator(cons.scip_cons);
2731  return Variable.create(var)
2732 
2733  def addPyCons(self, Constraint cons):
2734  """Adds a customly created cons.
2735 
2736  :param Constraint cons: constraint to add
2737 
2738  """
2739  PY_SCIP_CALL(SCIPaddCons(self._scip, cons.scip_cons))
2740  Py_INCREF(cons)
2741 
2742  def addVarSOS1(self, Constraint cons, Variable var, weight):
2743  """Add variable to SOS1 constraint.
2744 
2745  :param Constraint cons: SOS1 constraint
2746  :param Variable var: new variable
2747  :param weight: weight of new variable
2748 
2749  """
2750  PY_SCIP_CALL(SCIPaddVarSOS1(self._scip, cons.scip_cons, var.scip_var, weight))
2751 
2752  def appendVarSOS1(self, Constraint cons, Variable var):
2753  """Append variable to SOS1 constraint.
2754 
2755  :param Constraint cons: SOS1 constraint
2756  :param Variable var: variable to append
2757 
2758  """
2759  PY_SCIP_CALL(SCIPappendVarSOS1(self._scip, cons.scip_cons, var.scip_var))
2760 
2761  def addVarSOS2(self, Constraint cons, Variable var, weight):
2762  """Add variable to SOS2 constraint.
2763 
2764  :param Constraint cons: SOS2 constraint
2765  :param Variable var: new variable
2766  :param weight: weight of new variable
2767 
2768  """
2769  PY_SCIP_CALL(SCIPaddVarSOS2(self._scip, cons.scip_cons, var.scip_var, weight))
2770 
2771  def appendVarSOS2(self, Constraint cons, Variable var):
2772  """Append variable to SOS2 constraint.
2773 
2774  :param Constraint cons: SOS2 constraint
2775  :param Variable var: variable to append
2776 
2777  """
2778  PY_SCIP_CALL(SCIPappendVarSOS2(self._scip, cons.scip_cons, var.scip_var))
2779 
2780  def setInitial(self, Constraint cons, newInit):
2781  """Set "initial" flag of a constraint.
2782 
2783  Keyword arguments:
2784  cons -- constraint
2785  newInit -- new initial value
2786  """
2787  PY_SCIP_CALL(SCIPsetConsInitial(self._scip, cons.scip_cons, newInit))
2788 
2789  def setRemovable(self, Constraint cons, newRem):
2790  """Set "removable" flag of a constraint.
2791 
2792  Keyword arguments:
2793  cons -- constraint
2794  newRem -- new removable value
2795  """
2796  PY_SCIP_CALL(SCIPsetConsRemovable(self._scip, cons.scip_cons, newRem))
2797 
2798  def setEnforced(self, Constraint cons, newEnf):
2799  """Set "enforced" flag of a constraint.
2800 
2801  Keyword arguments:
2802  cons -- constraint
2803  newEnf -- new enforced value
2804  """
2805  PY_SCIP_CALL(SCIPsetConsEnforced(self._scip, cons.scip_cons, newEnf))
2806 
2807  def setCheck(self, Constraint cons, newCheck):
2808  """Set "check" flag of a constraint.
2809 
2810  Keyword arguments:
2811  cons -- constraint
2812  newCheck -- new check value
2813  """
2814  PY_SCIP_CALL(SCIPsetConsChecked(self._scip, cons.scip_cons, newCheck))
2815 
2816  def chgRhs(self, Constraint cons, rhs):
2817  """Change right hand side value of a constraint.
2818 
2819  :param Constraint cons: linear or quadratic constraint
2820  :param rhs: new ride hand side (set to None for +infinity)
2821 
2822  """
2823 
2824  if rhs is None:
2825  rhs = SCIPinfinity(self._scip)
2826 
2827  constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode('UTF-8')
2828  if constype == 'linear':
2829  PY_SCIP_CALL(SCIPchgRhsLinear(self._scip, cons.scip_cons, rhs))
2830  elif constype == 'nonlinear':
2831  PY_SCIP_CALL(SCIPchgRhsNonlinear(self._scip, cons.scip_cons, rhs))
2832  else:
2833  raise Warning("method cannot be called for constraints of type " + constype)
2834 
2835  def chgLhs(self, Constraint cons, lhs):
2836  """Change left hand side value of a constraint.
2837 
2838  :param Constraint cons: linear or quadratic constraint
2839  :param lhs: new left hand side (set to None for -infinity)
2840 
2841  """
2842 
2843  if lhs is None:
2844  lhs = -SCIPinfinity(self._scip)
2845 
2846  constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode('UTF-8')
2847  if constype == 'linear':
2848  PY_SCIP_CALL(SCIPchgLhsLinear(self._scip, cons.scip_cons, lhs))
2849  elif constype == 'nonlinear':
2850  PY_SCIP_CALL(SCIPchgLhsNonlinear(self._scip, cons.scip_cons, lhs))
2851  else:
2852  raise Warning("method cannot be called for constraints of type " + constype)
2853 
2854  def getRhs(self, Constraint cons):
2855  """Retrieve right hand side value of a constraint.
2856 
2857  :param Constraint cons: linear or quadratic constraint
2858 
2859  """
2860  constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode('UTF-8')
2861  if constype == 'linear':
2862  return SCIPgetRhsLinear(self._scip, cons.scip_cons)
2863  elif constype == 'quadratic':
2864  return SCIPgetRhsNonlinear(cons.scip_cons)
2865  else:
2866  raise Warning("method cannot be called for constraints of type " + constype)
2867 
2868  def getLhs(self, Constraint cons):
2869  """Retrieve left hand side value of a constraint.
2870 
2871  :param Constraint cons: linear or quadratic constraint
2872 
2873  """
2874  constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode('UTF-8')
2875  if constype == 'linear':
2876  return SCIPgetLhsLinear(self._scip, cons.scip_cons)
2877  elif constype == 'quadratic':
2878  return SCIPgetLhsNonlinear(cons.scip_cons)
2879  else:
2880  raise Warning("method cannot be called for constraints of type " + constype)
2881 
2882  def getActivity(self, Constraint cons, Solution sol = None):
2883  """Retrieve activity of given constraint.
2884  Can only be called after solving is completed.
2885 
2886  :param Constraint cons: linear or quadratic constraint
2887  :param Solution sol: solution to compute activity of, None to use current node's solution (Default value = None)
2888 
2889  """
2890  cdef SCIP_Real activity
2891  cdef SCIP_SOL* scip_sol
2892 
2893  if not self.getStage() >= SCIP_STAGE_SOLVING:
2894  raise Warning("method cannot be called before problem is solved")
2895 
2896  if isinstance(sol, Solution):
2897  scip_sol = sol.sol
2898  else:
2899  scip_sol = NULL
2900 
2901  constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode('UTF-8')
2902  if constype == 'linear':
2903  activity = SCIPgetActivityLinear(self._scip, cons.scip_cons, scip_sol)
2904  else:
2905  raise Warning("method cannot be called for constraints of type " + constype)
2906 
2907  return activity
2908 
2909 
2910  def getSlack(self, Constraint cons, Solution sol = None, side = None):
2911  """Retrieve slack of given constraint.
2912  Can only be called after solving is completed.
2913 
2914 
2915  :param Constraint cons: linear or quadratic constraint
2916  :param Solution sol: solution to compute slack of, None to use current node's solution (Default value = None)
2917  :param side: whether to use 'lhs' or 'rhs' for ranged constraints, None to return minimum (Default value = None)
2918 
2919  """
2920  cdef SCIP_Real activity
2921  cdef SCIP_SOL* scip_sol
2922 
2923 
2924  if not self.getStage() >= SCIP_STAGE_SOLVING:
2925  raise Warning("method cannot be called before problem is solved")
2926 
2927  if isinstance(sol, Solution):
2928  scip_sol = sol.sol
2929  else:
2930  scip_sol = NULL
2931 
2932  constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode('UTF-8')
2933  if constype == 'linear':
2934  lhs = SCIPgetLhsLinear(self._scip, cons.scip_cons)
2935  rhs = SCIPgetRhsLinear(self._scip, cons.scip_cons)
2936  activity = SCIPgetActivityLinear(self._scip, cons.scip_cons, scip_sol)
2937  else:
2938  raise Warning("method cannot be called for constraints of type " + constype)
2939 
2940  lhsslack = activity - lhs
2941  rhsslack = rhs - activity
2942 
2943  if side == 'lhs':
2944  return lhsslack
2945  elif side == 'rhs':
2946  return rhsslack
2947  else:
2948  return min(lhsslack, rhsslack)
2949 
2950  def getTransformedCons(self, Constraint cons):
2951  """Retrieve transformed constraint.
2952 
2953  :param Constraint cons: constraint
2954 
2955  """
2956  cdef SCIP_CONS* transcons
2957  PY_SCIP_CALL(SCIPgetTransformedCons(self._scip, cons.scip_cons, &transcons))
2958  return Constraint.create(transcons)
2959 
2960  def isNLPConstructed(self):
2961  """returns whether SCIP's internal NLP has been constructed"""
2962  return SCIPisNLPConstructed(self._scip)
2963 
2964  def getNNlRows(self):
2965  """gets current number of nonlinear rows in SCIP's internal NLP"""
2966  return SCIPgetNNLPNlRows(self._scip)
2967 
2968  def getNlRows(self):
2969  """returns a list with the nonlinear rows in SCIP's internal NLP"""
2970  cdef SCIP_NLROW** nlrows
2971 
2972  nlrows = SCIPgetNLPNlRows(self._scip)
2973  return [NLRow.create(nlrows[i]) for i in range(self.getNNlRows())]
2974 
2975  def getNlRowSolActivity(self, NLRow nlrow, Solution sol = None):
2976  """gives the activity of a nonlinear row for a given primal solution
2977  Keyword arguments:
2978  nlrow -- nonlinear row
2979  solution -- a primal solution, if None, then the current LP solution is used
2980  """
2981  cdef SCIP_Real activity
2982  cdef SCIP_SOL* solptr
2983 
2984  solptr = sol.sol if not sol is None else NULL
2985  PY_SCIP_CALL( SCIPgetNlRowSolActivity(self._scip, nlrow.scip_nlrow, solptr, &activity) )
2986  return activity
2987 
2988  def getNlRowSolFeasibility(self, NLRow nlrow, Solution sol = None):
2989  """gives the feasibility of a nonlinear row for a given primal solution
2990  Keyword arguments:
2991  nlrow -- nonlinear row
2992  solution -- a primal solution, if None, then the current LP solution is used
2993  """
2994  cdef SCIP_Real feasibility
2995  cdef SCIP_SOL* solptr
2996 
2997  solptr = sol.sol if not sol is None else NULL
2998  PY_SCIP_CALL( SCIPgetNlRowSolFeasibility(self._scip, nlrow.scip_nlrow, solptr, &feasibility) )
2999  return feasibility
3000 
3001  def getNlRowActivityBounds(self, NLRow nlrow):
3002  """gives the minimal and maximal activity of a nonlinear row w.r.t. the variable's bounds"""
3003  cdef SCIP_Real minactivity
3004  cdef SCIP_Real maxactivity
3005 
3006  PY_SCIP_CALL( SCIPgetNlRowActivityBounds(self._scip, nlrow.scip_nlrow, &minactivity, &maxactivity) )
3007  return (minactivity, maxactivity)
3008 
3009  def printNlRow(self, NLRow nlrow):
3010  """prints nonlinear row"""
3011  PY_SCIP_CALL( SCIPprintNlRow(self._scip, nlrow.scip_nlrow, NULL) )
3012 
3013  def checkQuadraticNonlinear(self, Constraint cons):
3014  """returns if the given constraint is quadratic
3015 
3016  :param Constraint cons: constraint
3017 
3018  """
3019  cdef SCIP_Bool isquadratic
3020  PY_SCIP_CALL( SCIPcheckQuadraticNonlinear(self._scip, cons.scip_cons, &isquadratic) )
3021  return isquadratic
3022 
3023  def getTermsQuadratic(self, Constraint cons):
3024  """Retrieve bilinear, quadratic, and linear terms of a quadratic constraint.
3025 
3026  :param Constraint cons: constraint
3027 
3028  """
3029  cdef SCIP_EXPR* expr
3030 
3031  # linear terms
3032  cdef SCIP_EXPR** _linexprs
3033  cdef SCIP_Real* _lincoefs
3034  cdef int _nlinvars
3035 
3036  # bilinear terms
3037  cdef int _nbilinterms
3038  cdef SCIP_EXPR* bilinterm1
3039  cdef SCIP_EXPR* bilinterm2
3040  cdef SCIP_Real bilincoef
3041 
3042  # quadratic terms
3043  cdef int _nquadterms
3044  cdef SCIP_Real sqrcoef
3045  cdef SCIP_Real lincoef
3046  cdef SCIP_EXPR* sqrexpr
3047 
3048  # variables
3049  cdef SCIP_VAR* scipvar1
3050  cdef SCIP_VAR* scipvar2
3051 
3052  assert cons.isNonlinear(), "constraint is not nonlinear"
3053  assert self.checkQuadraticNonlinear(cons), "constraint is not quadratic"
3054 
3055  expr = SCIPgetExprNonlinear(cons.scip_cons)
3056  SCIPexprGetQuadraticData(expr, NULL, &_nlinvars, &_linexprs, &_lincoefs, &_nquadterms, &_nbilinterms, NULL, NULL)
3057 
3058  linterms = []
3059  bilinterms = []
3060  quadterms = []
3061 
3062  for termidx in range(_nlinvars):
3063  var = Variable.create(SCIPgetVarExprVar(_linexprs[termidx]))
3064  linterms.append((var,_lincoefs[termidx]))
3065 
3066  for termidx in range(_nbilinterms):
3067  SCIPexprGetQuadraticBilinTerm(expr, termidx, &bilinterm1, &bilinterm2, &bilincoef, NULL, NULL)
3068  scipvar1 = SCIPgetVarExprVar(bilinterm1)
3069  scipvar2 = SCIPgetVarExprVar(bilinterm2)
3070  var1 = Variable.create(scipvar1)
3071  var2 = Variable.create(scipvar2)
3072  if scipvar1 != scipvar2:
3073  bilinterms.append((var1,var2,bilincoef))
3074  else:
3075  quadterms.append((var1,bilincoef,0.0))
3076 
3077  for termidx in range(_nquadterms):
3078  SCIPexprGetQuadraticQuadTerm(expr, termidx, NULL, &lincoef, &sqrcoef, NULL, NULL, &sqrexpr)
3079  if sqrexpr == NULL:
3080  continue
3081  var = Variable.create(SCIPgetVarExprVar(sqrexpr))
3082  quadterms.append((var,sqrcoef,lincoef))
3083 
3084  return (bilinterms, quadterms, linterms)
3085 
3086  def setRelaxSolVal(self, Variable var, val):
3087  """sets the value of the given variable in the global relaxation solution"""
3088  PY_SCIP_CALL(SCIPsetRelaxSolVal(self._scip, NULL, var.scip_var, val))
3089 
3090  def getConss(self):
3091  """Retrieve all constraints."""
3092  cdef SCIP_CONS** _conss
3093  cdef int _nconss
3094  conss = []
3095 
3096  _conss = SCIPgetConss(self._scip)
3097  _nconss = SCIPgetNConss(self._scip)
3098  return [Constraint.create(_conss[i]) for i in range(_nconss)]
3099 
3100  def getNConss(self):
3101  """Retrieve number of all constraints"""
3102  return SCIPgetNConss(self._scip)
3103 
3104  def delCons(self, Constraint cons):
3105  """Delete constraint from the model
3106 
3107  :param Constraint cons: constraint to be deleted
3108 
3109  """
3110  PY_SCIP_CALL(SCIPdelCons(self._scip, cons.scip_cons))
3111 
3112  def delConsLocal(self, Constraint cons):
3113  """Delete constraint from the current node and it's children
3114 
3115  :param Constraint cons: constraint to be deleted
3116 
3117  """
3118  PY_SCIP_CALL(SCIPdelConsLocal(self._scip, cons.scip_cons))
3119 
3120  def getValsLinear(self, Constraint cons):
3121  """Retrieve the coefficients of a linear constraint
3122 
3123  :param Constraint cons: linear constraint to get the coefficients of
3124 
3125  """
3126  cdef SCIP_Real* _vals
3127  cdef SCIP_VAR** _vars
3128 
3129  constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode('UTF-8')
3130  if not constype == 'linear':
3131  raise Warning("coefficients not available for constraints of type ", constype)
3132 
3133  _vals = SCIPgetValsLinear(self._scip, cons.scip_cons)
3134  _vars = SCIPgetVarsLinear(self._scip, cons.scip_cons)
3135 
3136  valsdict = {}
3137  for i in range(SCIPgetNVarsLinear(self._scip, cons.scip_cons)):
3138  valsdict[bytes(SCIPvarGetName(_vars[i])).decode('utf-8')] = _vals[i]
3139  return valsdict
3140 
3141  def getRowLinear(self, Constraint cons):
3142  """Retrieve the linear relaxation of the given linear constraint as a row.
3143  may return NULL if no LP row was yet created; the user must not modify the row!
3144 
3145  :param Constraint cons: linear constraint to get the coefficients of
3146 
3147  """
3148  constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode('UTF-8')
3149  if not constype == 'linear':
3150  raise Warning("coefficients not available for constraints of type ", constype)
3151 
3152  cdef SCIP_ROW* row = SCIPgetRowLinear(self._scip, cons.scip_cons)
3153  return Row.create(row)
3154 
3155  def getDualsolLinear(self, Constraint cons):
3156  """Retrieve the dual solution to a linear constraint.
3157 
3158  :param Constraint cons: linear constraint
3159 
3160  """
3161  constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode('UTF-8')
3162  if not constype == 'linear':
3163  raise Warning("dual solution values not available for constraints of type ", constype)
3164  if cons.isOriginal():
3165  transcons = <Constraint>self.getTransformedCons(cons)
3166  else:
3167  transcons = cons
3168  return SCIPgetDualsolLinear(self._scip, transcons.scip_cons)
3169 
3170  def getDualMultiplier(self, Constraint cons):
3171  """DEPRECATED: Retrieve the dual solution to a linear constraint.
3172 
3173  :param Constraint cons: linear constraint
3174 
3175  """
3176  raise Warning("model.getDualMultiplier(cons) is deprecated: please use model.getDualsolLinear(cons)")
3177  return self.getDualsolLinear(cons)
3178 
3179  def getDualfarkasLinear(self, Constraint cons):
3180  """Retrieve the dual farkas value to a linear constraint.
3181 
3182  :param Constraint cons: linear constraint
3183 
3184  """
3185  # TODO this should ideally be handled on the SCIP side
3186  if cons.isOriginal():
3187  transcons = <Constraint>self.getTransformedCons(cons)
3188  return SCIPgetDualfarkasLinear(self._scip, transcons.scip_cons)
3189  else:
3190  return SCIPgetDualfarkasLinear(self._scip, cons.scip_cons)
3191 
3192  def getVarRedcost(self, Variable var):
3193  """Retrieve the reduced cost of a variable.
3194 
3195  :param Variable var: variable to get the reduced cost of
3196 
3197  """
3198  redcost = None
3199  try:
3200  redcost = SCIPgetVarRedcost(self._scip, var.scip_var)
3201  if self.getObjectiveSense() == "maximize":
3202  redcost = -redcost
3203  except:
3204  raise Warning("no reduced cost available for variable " + var.name)
3205  return redcost
3206 
3207  def getDualSolVal(self, Constraint cons, boundconstraint=False):
3208  """Retrieve returns dual solution value of a constraint.
3209 
3210  :param Constraint cons: constraint to get the dual solution value of
3211  :param boundconstraint bool: Decides whether to store a bool if the constraint is a bound constraint
3212 
3213  """
3214  cdef SCIP_Real _dualsol
3215  cdef SCIP_Bool _bounded
3216 
3217  if boundconstraint:
3218  SCIPgetDualSolVal(self._scip, cons.scip_cons, &_dualsol, &_bounded)
3219  else:
3220  SCIPgetDualSolVal(self._scip, cons.scip_cons, &_dualsol, NULL)
3221 
3222  return _dualsol
3223 
3224 
3225  def optimize(self):
3226  """Optimize the problem."""
3227  PY_SCIP_CALL(SCIPsolve(self._scip))
3228  self._bestSol = Solution.create(self._scip, SCIPgetBestSol(self._scip))
3229 
3230  def solveConcurrent(self):
3231  """Transforms, presolves, and solves problem using additional solvers which emphasize on
3232  finding solutions."""
3233  if SCIPtpiGetNumThreads() == 1:
3234  warnings.warn("SCIP was compiled without task processing interface. Parallel solve not possible - using optimize() instead of solveConcurrent()")
3235  self.optimize()
3236  else:
3237  PY_SCIP_CALL(SCIPsolveConcurrent(self._scip))
3238  self._bestSol = Solution.create(self._scip, SCIPgetBestSol(self._scip))
3239 
3240  def presolve(self):
3241  """Presolve the problem."""
3242  PY_SCIP_CALL(SCIPpresolve(self._scip))
3243 
3244  # Benders' decomposition methods
3245  def initBendersDefault(self, subproblems):
3246  """initialises the default Benders' decomposition with a dictionary of subproblems
3247 
3248  Keyword arguments:
3249  subproblems -- a single Model instance or dictionary of Model instances
3250  """
3251  cdef SCIP** subprobs
3252  cdef SCIP_BENDERS* benders
3253 
3254  # checking whether subproblems is a dictionary
3255  if isinstance(subproblems, dict):
3256  isdict = True
3257  nsubproblems = len(subproblems)
3258  else:
3259  isdict = False
3260  nsubproblems = 1
3261 
3262  # create array of SCIP instances for the subproblems
3263  subprobs = <SCIP**> malloc(nsubproblems * sizeof(SCIP*))
3264 
3265  # if subproblems is a dictionary, then the dictionary is turned into a c array
3266  if isdict:
3267  for idx, subprob in enumerate(subproblems.values()):
3268  subprobs[idx] = (<Model>subprob)._scip
3269  else:
3270  subprobs[0] = (<Model>subproblems)._scip
3271 
3272  # creating the default Benders' decomposition
3273  PY_SCIP_CALL(SCIPcreateBendersDefault(self._scip, subprobs, nsubproblems))
3274  benders = SCIPfindBenders(self._scip, "default")
3275 
3276  # activating the Benders' decomposition constraint handlers
3277  self.setBoolParam("constraints/benderslp/active", True)
3278  self.setBoolParam("constraints/benders/active", True)
3279  #self.setIntParam("limits/maxorigsol", 0)
3280 
3282  """Solves the subproblems with the best solution to the master problem.
3283  Afterwards, the best solution from each subproblem can be queried to get
3284  the solution to the original problem.
3285 
3286  If the user wants to resolve the subproblems, they must free them by
3287  calling freeBendersSubproblems()
3288  """
3289  cdef SCIP_BENDERS** _benders
3290  cdef SCIP_Bool _infeasible
3291  cdef int nbenders
3292  cdef int nsubproblems
3293 
3294  solvecip = True
3295 
3296  nbenders = SCIPgetNActiveBenders(self._scip)
3297  _benders = SCIPgetBenders(self._scip)
3298 
3299  # solving all subproblems from all Benders' decompositions
3300  for i in range(nbenders):
3301  nsubproblems = SCIPbendersGetNSubproblems(_benders[i])
3302  for j in range(nsubproblems):
3303  PY_SCIP_CALL(SCIPsetupBendersSubproblem(self._scip,
3304  _benders[i], self._bestSol.sol, j, SCIP_BENDERSENFOTYPE_CHECK))
3305  PY_SCIP_CALL(SCIPsolveBendersSubproblem(self._scip,
3306  _benders[i], self._bestSol.sol, j, &_infeasible, solvecip, NULL))
3307 
3309  """Calls the free subproblem function for the Benders' decomposition.
3310  This will free all subproblems for all decompositions.
3311  """
3312  cdef SCIP_BENDERS** _benders
3313  cdef int nbenders
3314  cdef int nsubproblems
3315 
3316  nbenders = SCIPgetNActiveBenders(self._scip)
3317  _benders = SCIPgetBenders(self._scip)
3318 
3319  # solving all subproblems from all Benders' decompositions
3320  for i in range(nbenders):
3321  nsubproblems = SCIPbendersGetNSubproblems(_benders[i])
3322  for j in range(nsubproblems):
3323  PY_SCIP_CALL(SCIPfreeBendersSubproblem(self._scip, _benders[i],
3324  j))
3325 
3326  def updateBendersLowerbounds(self, lowerbounds, Benders benders=None):
3327  """"updates the subproblem lower bounds for benders using
3328  the lowerbounds dict. If benders is None, then the default
3329  Benders' decomposition is updated
3330  """
3331  cdef SCIP_BENDERS* _benders
3332 
3333  assert type(lowerbounds) is dict
3334 
3335  if benders is None:
3336  _benders = SCIPfindBenders(self._scip, "default")
3337  else:
3338  _benders = benders._benders
3339 
3340  for d in lowerbounds.keys():
3341  SCIPbendersUpdateSubproblemLowerbound(_benders, d, lowerbounds[d])
3342 
3343  def activateBenders(self, Benders benders, int nsubproblems):
3344  """Activates the Benders' decomposition plugin with the input name
3345 
3346  Keyword arguments:
3347  benders -- the Benders' decomposition to which the subproblem belongs to
3348  nsubproblems -- the number of subproblems in the Benders' decomposition
3349  """
3350  PY_SCIP_CALL(SCIPactivateBenders(self._scip, benders._benders, nsubproblems))
3351 
3352  def addBendersSubproblem(self, Benders benders, subproblem):
3353  """adds a subproblem to the Benders' decomposition given by the input
3354  name.
3355 
3356  Keyword arguments:
3357  benders -- the Benders' decomposition to which the subproblem belongs to
3358  subproblem -- the subproblem to add to the decomposition
3359  isconvex -- can be used to specify whether the subproblem is convex
3360  """
3361  PY_SCIP_CALL(SCIPaddBendersSubproblem(self._scip, benders._benders, (<Model>subproblem)._scip))
3362 
3363  def setBendersSubproblemIsConvex(self, Benders benders, probnumber, isconvex = True):
3364  """sets a flag indicating whether the subproblem is convex
3365 
3366  Keyword arguments:
3367  benders -- the Benders' decomposition which contains the subproblem
3368  probnumber -- the problem number of the subproblem that the convexity will be set for
3369  isconvex -- flag to indicate whether the subproblem is convex
3370  """
3371  SCIPbendersSetSubproblemIsConvex(benders._benders, probnumber, isconvex)
3372 
3373  def setupBendersSubproblem(self, probnumber, Benders benders = None, Solution solution = None, checktype = PY_SCIP_BENDERSENFOTYPE.LP):
3374  """ sets up the Benders' subproblem given the master problem solution
3375 
3376  Keyword arguments:
3377  probnumber -- the index of the problem that is to be set up
3378  benders -- the Benders' decomposition to which the subproblem belongs to
3379  solution -- the master problem solution that is used for the set up, if None, then the LP solution is used
3380  checktype -- the type of solution check that prompted the solving of the Benders' subproblems, either
3381  PY_SCIP_BENDERSENFOTYPE: LP, RELAX, PSEUDO or CHECK. Default is LP
3382  """
3383  cdef SCIP_BENDERS* scip_benders
3384  cdef SCIP_SOL* scip_sol
3385 
3386  if isinstance(solution, Solution):
3387  scip_sol = solution.sol
3388  else:
3389  scip_sol = NULL
3390 
3391  if benders is None:
3392  scip_benders = SCIPfindBenders(self._scip, "default")
3393  else:
3394  scip_benders = benders._benders
3395 
3396  retcode = SCIPsetupBendersSubproblem(self._scip, scip_benders, scip_sol, probnumber, checktype)
3397 
3398  PY_SCIP_CALL(retcode)
3399 
3400  def solveBendersSubproblem(self, probnumber, solvecip, Benders benders = None, Solution solution = None):
3401  """ solves the Benders' decomposition subproblem. The convex relaxation will be solved unless
3402  the parameter solvecip is set to True.
3403 
3404  Keyword arguments:
3405  probnumber -- the index of the problem that is to be set up
3406  solvecip -- should the CIP of the subproblem be solved, if False, then only the convex relaxation is solved
3407  benders -- the Benders' decomposition to which the subproblem belongs to
3408  solution -- the master problem solution that is used for the set up, if None, then the LP solution is used
3409  """
3410 
3411  cdef SCIP_BENDERS* scip_benders
3412  cdef SCIP_SOL* scip_sol
3413  cdef SCIP_Real objective
3414  cdef SCIP_Bool infeasible
3415 
3416  if isinstance(solution, Solution):
3417  scip_sol = solution.sol
3418  else:
3419  scip_sol = NULL
3420 
3421  if benders is None:
3422  scip_benders = SCIPfindBenders(self._scip, "default")
3423  else:
3424  scip_benders = benders._benders
3425 
3426  PY_SCIP_CALL(SCIPsolveBendersSubproblem(self._scip, scip_benders, scip_sol,
3427  probnumber, &infeasible, solvecip, &objective))
3428 
3429  return infeasible, objective
3430 
3431  def getBendersSubproblem(self, probnumber, Benders benders = None):
3432  """Returns a Model object that wraps around the SCIP instance of the subproblem.
3433  NOTE: This Model object is just a place holder and SCIP instance will not be freed when the object is destroyed.
3434 
3435  Keyword arguments:
3436  probnumber -- the problem number for subproblem that is required
3437  benders -- the Benders' decomposition object for the that the subproblem belongs to (Default = None)
3438  """
3439  cdef SCIP_BENDERS* scip_benders
3440  cdef SCIP* scip_subprob
3441 
3442  if benders is None:
3443  scip_benders = SCIPfindBenders(self._scip, "default")
3444  else:
3445  scip_benders = benders._benders
3446 
3447  scip_subprob = SCIPbendersSubproblem(scip_benders, probnumber)
3448 
3449  return Model.create(scip_subprob)
3450 
3451  def getBendersVar(self, Variable var, Benders benders = None, probnumber = -1):
3452  """Returns the variable for the subproblem or master problem
3453  depending on the input probnumber
3454 
3455  Keyword arguments:
3456  var -- the source variable for which the target variable is requested
3457  benders -- the Benders' decomposition to which the subproblem variables belong to
3458  probnumber -- the problem number for which the target variable belongs, -1 for master problem
3459  """
3460  cdef SCIP_BENDERS* _benders
3461  cdef SCIP_VAR* _mappedvar
3462 
3463  if benders is None:
3464  _benders = SCIPfindBenders(self._scip, "default")
3465  else:
3466  _benders = benders._benders
3467 
3468  if probnumber == -1:
3469  PY_SCIP_CALL(SCIPgetBendersMasterVar(self._scip, _benders, var.scip_var, &_mappedvar))
3470  else:
3471  PY_SCIP_CALL(SCIPgetBendersSubproblemVar(self._scip, _benders, var.scip_var, &_mappedvar, probnumber))
3472 
3473  if _mappedvar == NULL:
3474  mappedvar = None
3475  else:
3476  mappedvar = Variable.create(_mappedvar)
3477 
3478  return mappedvar
3479 
3480  def getBendersAuxiliaryVar(self, probnumber, Benders benders = None):
3481  """Returns the auxiliary variable that is associated with the input problem number
3482 
3483  Keyword arguments:
3484  probnumber -- the problem number for which the target variable belongs, -1 for master problem
3485  benders -- the Benders' decomposition to which the subproblem variables belong to
3486  """
3487  cdef SCIP_BENDERS* _benders
3488  cdef SCIP_VAR* _auxvar
3489 
3490  if benders is None:
3491  _benders = SCIPfindBenders(self._scip, "default")
3492  else:
3493  _benders = benders._benders
3494 
3495  _auxvar = SCIPbendersGetAuxiliaryVar(_benders, probnumber)
3496  auxvar = Variable.create(_auxvar)
3497 
3498  return auxvar
3499 
3500  def checkBendersSubproblemOptimality(self, Solution solution, probnumber, Benders benders = None):
3501  """Returns whether the subproblem is optimal w.r.t the master problem auxiliary variables.
3502 
3503  Keyword arguments:
3504  solution -- the master problem solution that is being checked for optimamlity
3505  probnumber -- the problem number for which optimality is being checked
3506  benders -- the Benders' decomposition to which the subproblem belongs to
3507  """
3508  cdef SCIP_BENDERS* _benders
3509  cdef SCIP_SOL* scip_sol
3510  cdef SCIP_Bool optimal
3511 
3512  if benders is None:
3513  _benders = SCIPfindBenders(self._scip, "default")
3514  else:
3515  _benders = benders._benders
3516 
3517  if isinstance(solution, Solution):
3518  scip_sol = solution.sol
3519  else:
3520  scip_sol = NULL
3521 
3522  PY_SCIP_CALL( SCIPcheckBendersSubproblemOptimality(self._scip, _benders,
3523  scip_sol, probnumber, &optimal) )
3524 
3525  return optimal
3526 
3527  def includeBendersDefaultCuts(self, Benders benders):
3528  """includes the default Benders' decomposition cuts to the custom Benders' decomposition plugin
3529 
3530  Keyword arguments:
3531  benders -- the Benders' decomposition that the default cuts will be applied to
3532  """
3533  PY_SCIP_CALL( SCIPincludeBendersDefaultCuts(self._scip, benders._benders) )
3534 
3535 
3536  def includeEventhdlr(self, Eventhdlr eventhdlr, name, desc):
3537  """Include an event handler.
3538 
3539  Keyword arguments:
3540  eventhdlr -- event handler
3541  name -- name of event handler
3542  desc -- description of event handler
3543  """
3544  n = str_conversion(name)
3545  d = str_conversion(desc)
3546  PY_SCIP_CALL(SCIPincludeEventhdlr(self._scip, n, d,
3547  PyEventCopy,
3548  PyEventFree,
3549  PyEventInit,
3550  PyEventExit,
3551  PyEventInitsol,
3552  PyEventExitsol,
3553  PyEventDelete,
3554  PyEventExec,
3555  <SCIP_EVENTHDLRDATA*>eventhdlr))
3556  eventhdlr.model = <Model>weakref.proxy(self)
3557  eventhdlr.name = name
3558  Py_INCREF(eventhdlr)
3559 
3560  def includePricer(self, Pricer pricer, name, desc, priority=1, delay=True):
3561  """Include a pricer.
3562 
3563  :param Pricer pricer: pricer
3564  :param name: name of pricer
3565  :param desc: description of pricer
3566  :param priority: priority of pricer (Default value = 1)
3567  :param delay: should the pricer be delayed until no other pricers or already existing problem variables with negative reduced costs are found? (Default value = True)
3568 
3569  """
3570  n = str_conversion(name)
3571  d = str_conversion(desc)
3572  PY_SCIP_CALL(SCIPincludePricer(self._scip, n, d,
3573  priority, delay,
3574  PyPricerCopy, PyPricerFree, PyPricerInit, PyPricerExit, PyPricerInitsol, PyPricerExitsol, PyPricerRedcost, PyPricerFarkas,
3575  <SCIP_PRICERDATA*>pricer))
3576  cdef SCIP_PRICER* scip_pricer
3577  scip_pricer = SCIPfindPricer(self._scip, n)
3578  PY_SCIP_CALL(SCIPactivatePricer(self._scip, scip_pricer))
3579  pricer.model = <Model>weakref.proxy(self)
3580  Py_INCREF(pricer)
3581 
3582  def includeConshdlr(self, Conshdlr conshdlr, name, desc, sepapriority=0,
3583  enfopriority=0, chckpriority=0, sepafreq=-1, propfreq=-1,
3584  eagerfreq=100, maxprerounds=-1, delaysepa=False,
3585  delayprop=False, needscons=True,
3586  proptiming=PY_SCIP_PROPTIMING.BEFORELP,
3587  presoltiming=PY_SCIP_PRESOLTIMING.MEDIUM):
3588  """Include a constraint handler
3589 
3590  :param Conshdlr conshdlr: constraint handler
3591  :param name: name of constraint handler
3592  :param desc: description of constraint handler
3593  :param sepapriority: priority for separation (Default value = 0)
3594  :param enfopriority: priority for constraint enforcing (Default value = 0)
3595  :param chckpriority: priority for checking feasibility (Default value = 0)
3596  :param sepafreq: frequency for separating cuts; 0 = only at root node (Default value = -1)
3597  :param propfreq: frequency for propagating domains; 0 = only preprocessing propagation (Default value = -1)
3598  :param eagerfreq: frequency for using all instead of only the useful constraints in separation, propagation and enforcement; -1 = no eager evaluations, 0 = first only (Default value = 100)
3599  :param maxprerounds: maximal number of presolving rounds the constraint handler participates in (Default value = -1)
3600  :param delaysepa: should separation method be delayed, if other separators found cuts? (Default value = False)
3601  :param delayprop: should propagation method be delayed, if other propagators found reductions? (Default value = False)
3602  :param needscons: should the constraint handler be skipped, if no constraints are available? (Default value = True)
3603  :param proptiming: positions in the node solving loop where propagation method of constraint handlers should be executed (Default value = SCIP_PROPTIMING.BEFORELP)
3604  :param presoltiming: timing mask of the constraint handler's presolving method (Default value = SCIP_PRESOLTIMING.MEDIUM)
3605 
3606  """
3607  n = str_conversion(name)
3608  d = str_conversion(desc)
3609  PY_SCIP_CALL(SCIPincludeConshdlr(self._scip, n, d, sepapriority, enfopriority, chckpriority, sepafreq, propfreq, eagerfreq,
3610  maxprerounds, delaysepa, delayprop, needscons, proptiming, presoltiming,
3611  PyConshdlrCopy, PyConsFree, PyConsInit, PyConsExit, PyConsInitpre, PyConsExitpre,
3612  PyConsInitsol, PyConsExitsol, PyConsDelete, PyConsTrans, PyConsInitlp, PyConsSepalp, PyConsSepasol,
3613  PyConsEnfolp, PyConsEnforelax, PyConsEnfops, PyConsCheck, PyConsProp, PyConsPresol, PyConsResprop, PyConsLock,
3614  PyConsActive, PyConsDeactive, PyConsEnable, PyConsDisable, PyConsDelvars, PyConsPrint, PyConsCopy,
3615  PyConsParse, PyConsGetvars, PyConsGetnvars, PyConsGetdivebdchgs,
3616  <SCIP_CONSHDLRDATA*>conshdlr))
3617  conshdlr.model = <Model>weakref.proxy(self)
3618  conshdlr.name = name
3619  Py_INCREF(conshdlr)
3620 
3621  def createCons(self, Conshdlr conshdlr, name, initial=True, separate=True, enforce=True, check=True, propagate=True,
3622  local=False, modifiable=False, dynamic=False, removable=False, stickingatnode=False):
3623  """Create a constraint of a custom constraint handler
3624 
3625  :param Conshdlr conshdlr: constraint handler
3626  :param name: name of constraint
3627  :param initial: (Default value = True)
3628  :param separate: (Default value = True)
3629  :param enforce: (Default value = True)
3630  :param check: (Default value = True)
3631  :param propagate: (Default value = True)
3632  :param local: (Default value = False)
3633  :param modifiable: (Default value = False)
3634  :param dynamic: (Default value = False)
3635  :param removable: (Default value = False)
3636  :param stickingatnode: (Default value = False)
3637 
3638  """
3639 
3640  n = str_conversion(name)
3641  cdef SCIP_CONSHDLR* scip_conshdlr
3642  scip_conshdlr = SCIPfindConshdlr(self._scip, str_conversion(conshdlr.name))
3643  constraint = Constraint()
3644  PY_SCIP_CALL(SCIPcreateCons(self._scip, &(constraint.scip_cons), n, scip_conshdlr, <SCIP_CONSDATA*>constraint,
3645  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode))
3646  return constraint
3647 
3648  def includePresol(self, Presol presol, name, desc, priority, maxrounds, timing=SCIP_PRESOLTIMING_FAST):
3649  """Include a presolver
3650 
3651  :param Presol presol: presolver
3652  :param name: name of presolver
3653  :param desc: description of presolver
3654  :param priority: priority of the presolver (>= 0: before, < 0: after constraint handlers)
3655  :param maxrounds: maximal number of presolving rounds the presolver participates in (-1: no limit)
3656  :param timing: timing mask of presolver (Default value = SCIP_PRESOLTIMING_FAST)
3657 
3658  """
3659  n = str_conversion(name)
3660  d = str_conversion(desc)
3661  PY_SCIP_CALL(SCIPincludePresol(self._scip, n, d, priority, maxrounds, timing, PyPresolCopy, PyPresolFree, PyPresolInit,
3662  PyPresolExit, PyPresolInitpre, PyPresolExitpre, PyPresolExec, <SCIP_PRESOLDATA*>presol))
3663  presol.model = <Model>weakref.proxy(self)
3664  Py_INCREF(presol)
3665 
3666  def includeSepa(self, Sepa sepa, name, desc, priority=0, freq=10, maxbounddist=1.0, usessubscip=False, delay=False):
3667  """Include a separator
3668 
3669  :param Sepa sepa: separator
3670  :param name: name of separator
3671  :param desc: description of separator
3672  :param priority: priority of separator (>= 0: before, < 0: after constraint handlers)
3673  :param freq: frequency for calling separator
3674  :param maxbounddist: maximal relative distance from current node's dual bound to primal bound compared to best node's dual bound for applying separation
3675  :param usessubscip: does the separator use a secondary SCIP instance? (Default value = False)
3676  :param delay: should separator be delayed, if other separators found cuts? (Default value = False)
3677 
3678  """
3679  n = str_conversion(name)
3680  d = str_conversion(desc)
3681  PY_SCIP_CALL(SCIPincludeSepa(self._scip, n, d, priority, freq, maxbounddist, usessubscip, delay, PySepaCopy, PySepaFree,
3682  PySepaInit, PySepaExit, PySepaInitsol, PySepaExitsol, PySepaExeclp, PySepaExecsol, <SCIP_SEPADATA*>sepa))
3683  sepa.model = <Model>weakref.proxy(self)
3684  sepa.name = name
3685  Py_INCREF(sepa)
3686 
3687  def includeReader(self, Reader reader, name, desc, ext):
3688  """Include a reader
3689 
3690  :param Reader reader: reader
3691  :param name: name of reader
3692  :param desc: description of reader
3693  :param ext: file extension of reader
3694 
3695  """
3696  n = str_conversion(name)
3697  d = str_conversion(desc)
3698  e = str_conversion(ext)
3699  PY_SCIP_CALL(SCIPincludeReader(self._scip, n, d, e, PyReaderCopy, PyReaderFree,
3700  PyReaderRead, PyReaderWrite, <SCIP_READERDATA*>reader))
3701  reader.model = <Model>weakref.proxy(self)
3702  reader.name = name
3703  Py_INCREF(reader)
3704 
3705  def includeProp(self, Prop prop, name, desc, presolpriority, presolmaxrounds,
3706  proptiming, presoltiming=SCIP_PRESOLTIMING_FAST, priority=1, freq=1, delay=True):
3707  """Include a propagator.
3708 
3709  :param Prop prop: propagator
3710  :param name: name of propagator
3711  :param desc: description of propagator
3712  :param presolpriority: presolving priority of the propgator (>= 0: before, < 0: after constraint handlers)
3713  :param presolmaxrounds: maximal number of presolving rounds the propagator participates in (-1: no limit)
3714  :param proptiming: positions in the node solving loop where propagation method of constraint handlers should be executed
3715  :param presoltiming: timing mask of the constraint handler's presolving method (Default value = SCIP_PRESOLTIMING_FAST)
3716  :param priority: priority of the propagator (Default value = 1)
3717  :param freq: frequency for calling propagator (Default value = 1)
3718  :param delay: should propagator be delayed if other propagators have found reductions? (Default value = True)
3719 
3720  """
3721  n = str_conversion(name)
3722  d = str_conversion(desc)
3723  PY_SCIP_CALL(SCIPincludeProp(self._scip, n, d,
3724  priority, freq, delay,
3725  proptiming, presolpriority, presolmaxrounds,
3726  presoltiming, PyPropCopy, PyPropFree, PyPropInit, PyPropExit,
3727  PyPropInitpre, PyPropExitpre, PyPropInitsol, PyPropExitsol,
3728  PyPropPresol, PyPropExec, PyPropResProp,
3729  <SCIP_PROPDATA*> prop))
3730  prop.model = <Model>weakref.proxy(self)
3731  Py_INCREF(prop)
3732 
3733  def includeHeur(self, Heur heur, name, desc, dispchar, priority=10000, freq=1, freqofs=0,
3734  maxdepth=-1, timingmask=SCIP_HEURTIMING_BEFORENODE, usessubscip=False):
3735  """Include a primal heuristic.
3736 
3737  :param Heur heur: heuristic
3738  :param name: name of heuristic
3739  :param desc: description of heuristic
3740  :param dispchar: display character of heuristic
3741  :param priority: priority of the heuristic (Default value = 10000)
3742  :param freq: frequency for calling heuristic (Default value = 1)
3743  :param freqofs: frequency offset for calling heuristic (Default value = 0)
3744  :param maxdepth: maximal depth level to call heuristic at (Default value = -1)
3745  :param timingmask: positions in the node solving loop where heuristic should be executed (Default value = SCIP_HEURTIMING_BEFORENODE)
3746  :param usessubscip: does the heuristic use a secondary SCIP instance? (Default value = False)
3747 
3748  """
3749  nam = str_conversion(name)
3750  des = str_conversion(desc)
3751  dis = ord(str_conversion(dispchar))
3752  PY_SCIP_CALL(SCIPincludeHeur(self._scip, nam, des, dis,
3753  priority, freq, freqofs,
3754  maxdepth, timingmask, usessubscip,
3755  PyHeurCopy, PyHeurFree, PyHeurInit, PyHeurExit,
3756  PyHeurInitsol, PyHeurExitsol, PyHeurExec,
3757  <SCIP_HEURDATA*> heur))
3758  heur.model = <Model>weakref.proxy(self)
3759  heur.name = name
3760  Py_INCREF(heur)
3761 
3762  def includeRelax(self, Relax relax, name, desc, priority=10000, freq=1):
3763  """Include a relaxation handler.
3764 
3765  :param Relax relax: relaxation handler
3766  :param name: name of relaxation handler
3767  :param desc: description of relaxation handler
3768  :param priority: priority of the relaxation handler (negative: after LP, non-negative: before LP, Default value = 10000)
3769  :param freq: frequency for calling relaxation handler
3770 
3771  """
3772  nam = str_conversion(name)
3773  des = str_conversion(desc)
3774  PY_SCIP_CALL(SCIPincludeRelax(self._scip, nam, des, priority, freq, PyRelaxCopy, PyRelaxFree, PyRelaxInit, PyRelaxExit,
3775  PyRelaxInitsol, PyRelaxExitsol, PyRelaxExec, <SCIP_RELAXDATA*> relax))
3776  relax.model = <Model>weakref.proxy(self)
3777  relax.name = name
3778 
3779  Py_INCREF(relax)
3780 
3781  def includeCutsel(self, Cutsel cutsel, name, desc, priority):
3782  """include a cut selector
3783 
3784  :param Cutsel cutsel: cut selector
3785  :param name: name of cut selector
3786  :param desc: description of cut selector
3787  :param priority: priority of the cut selector
3788  """
3789 
3790  nam = str_conversion(name)
3791  des = str_conversion(desc)
3792  PY_SCIP_CALL(SCIPincludeCutsel(self._scip, nam, des,
3793  priority, PyCutselCopy, PyCutselFree, PyCutselInit, PyCutselExit,
3794  PyCutselInitsol, PyCutselExitsol, PyCutselSelect,
3795  <SCIP_CUTSELDATA*> cutsel))
3796  cutsel.model = <Model>weakref.proxy(self)
3797  Py_INCREF(cutsel)
3798 
3799  def includeBranchrule(self, Branchrule branchrule, name, desc, priority, maxdepth, maxbounddist):
3800  """Include a branching rule.
3801 
3802  :param Branchrule branchrule: branching rule
3803  :param name: name of branching rule
3804  :param desc: description of branching rule
3805  :param priority: priority of branching rule
3806  :param maxdepth: maximal depth level up to which this branching rule should be used (or -1)
3807  :param maxbounddist: maximal relative distance from current node's dual bound to primal bound compared to best node's dual bound for applying branching rule (0.0: only on current best node, 1.0: on all nodes)
3808 
3809  """
3810  nam = str_conversion(name)
3811  des = str_conversion(desc)
3812  PY_SCIP_CALL(SCIPincludeBranchrule(self._scip, nam, des,
3813  priority, maxdepth, maxbounddist,
3814  PyBranchruleCopy, PyBranchruleFree, PyBranchruleInit, PyBranchruleExit,
3815  PyBranchruleInitsol, PyBranchruleExitsol, PyBranchruleExeclp, PyBranchruleExecext,
3816  PyBranchruleExecps, <SCIP_BRANCHRULEDATA*> branchrule))
3817  branchrule.model = <Model>weakref.proxy(self)
3818  Py_INCREF(branchrule)
3819 
3820  def includeNodesel(self, Nodesel nodesel, name, desc, stdpriority, memsavepriority):
3821  """Include a node selector.
3822 
3823  :param Nodesel nodesel: node selector
3824  :param name: name of node selector
3825  :param desc: description of node selector
3826  :param stdpriority: priority of the node selector in standard mode
3827  :param memsavepriority: priority of the node selector in memory saving mode
3828 
3829  """
3830  nam = str_conversion(name)
3831  des = str_conversion(desc)
3832  PY_SCIP_CALL(SCIPincludeNodesel(self._scip, nam, des,
3833  stdpriority, memsavepriority,
3834  PyNodeselCopy, PyNodeselFree, PyNodeselInit, PyNodeselExit,
3835  PyNodeselInitsol, PyNodeselExitsol, PyNodeselSelect, PyNodeselComp,
3836  <SCIP_NODESELDATA*> nodesel))
3837  nodesel.model = <Model>weakref.proxy(self)
3838  Py_INCREF(nodesel)
3839 
3840  def includeBenders(self, Benders benders, name, desc, priority=1, cutlp=True, cutpseudo=True, cutrelax=True,
3841  shareaux=False):
3842  """Include a Benders' decomposition.
3843 
3844  Keyword arguments:
3845  benders -- the Benders decomposition
3846  name -- the name
3847  desc -- the description
3848  priority -- priority of the Benders' decomposition
3849  cutlp -- should Benders' cuts be generated from LP solutions
3850  cutpseudo -- should Benders' cuts be generated from pseudo solutions
3851  cutrelax -- should Benders' cuts be generated from relaxation solutions
3852  shareaux -- should the Benders' decomposition share the auxiliary variables of the highest priority Benders' decomposition
3853  """
3854  n = str_conversion(name)
3855  d = str_conversion(desc)
3856  PY_SCIP_CALL(SCIPincludeBenders(self._scip, n, d,
3857  priority, cutlp, cutrelax, cutpseudo, shareaux,
3858  PyBendersCopy, PyBendersFree, PyBendersInit, PyBendersExit, PyBendersInitpre,
3859  PyBendersExitpre, PyBendersInitsol, PyBendersExitsol, PyBendersGetvar,
3860  PyBendersCreatesub, PyBendersPresubsolve, PyBendersSolvesubconvex,
3861  PyBendersSolvesub, PyBendersPostsolve, PyBendersFreesub,
3862  <SCIP_BENDERSDATA*>benders))
3863  cdef SCIP_BENDERS* scip_benders
3864  scip_benders = SCIPfindBenders(self._scip, n)
3865  benders.model = <Model>weakref.proxy(self)
3866  benders.name = name
3867  benders._benders = scip_benders
3868  Py_INCREF(benders)
3869 
3870  def includeBenderscut(self, Benders benders, Benderscut benderscut, name, desc, priority=1, islpcut=True):
3871  """ Include a Benders' decomposition cutting method
3872 
3873  Keyword arguments:
3874  benders -- the Benders' decomposition that this cutting method is attached to
3875  benderscut --- the Benders' decomposition cutting method
3876  name -- the name
3877  desc -- the description
3878  priority -- priority of the Benders' decomposition
3879  islpcut -- is this cutting method suitable for generating cuts for convex relaxations?
3880  """
3881  cdef SCIP_BENDERS* _benders
3882 
3883  _benders = benders._benders
3884 
3885  n = str_conversion(name)
3886  d = str_conversion(desc)
3887  PY_SCIP_CALL(SCIPincludeBenderscut(self._scip, _benders, n, d, priority, islpcut,
3888  PyBenderscutCopy, PyBenderscutFree, PyBenderscutInit, PyBenderscutExit,
3889  PyBenderscutInitsol, PyBenderscutExitsol, PyBenderscutExec,
3890  <SCIP_BENDERSCUTDATA*>benderscut))
3891 
3892  cdef SCIP_BENDERSCUT* scip_benderscut
3893  scip_benderscut = SCIPfindBenderscut(_benders, n)
3894  benderscut.model = <Model>weakref.proxy(self)
3895  benderscut.benders = benders
3896  benderscut.name = name
3897  # TODO: It might be necessary in increment the reference to benders i.e Py_INCREF(benders)
3898  Py_INCREF(benderscut)
3899 
3900 
3901  def getLPBranchCands(self):
3902  """gets branching candidates for LP solution branching (fractional variables) along with solution values,
3903  fractionalities, and number of branching candidates; The number of branching candidates does NOT account
3904  for fractional implicit integer variables which should not be used for branching decisions. Fractional
3905  implicit integer variables are stored at the positions *nlpcands to *nlpcands + *nfracimplvars - 1
3906  branching rules should always select the branching candidate among the first npriolpcands of the candidate list
3907 
3908  :return tuple (lpcands, lpcandssol, lpcadsfrac, nlpcands, npriolpcands, nfracimplvars) where
3909 
3910  lpcands: list of variables of LP branching candidates
3911  lpcandssol: list of LP candidate solution values
3912  lpcandsfrac list of LP candidate fractionalities
3913  nlpcands: number of LP branching candidates
3914  npriolpcands: number of candidates with maximal priority
3915  nfracimplvars: number of fractional implicit integer variables
3916 
3917  """
3918  cdef int ncands
3919  cdef int nlpcands
3920  cdef int npriolpcands
3921  cdef int nfracimplvars
3922 
3923  cdef SCIP_VAR** lpcands
3924  cdef SCIP_Real* lpcandssol
3925  cdef SCIP_Real* lpcandsfrac
3926 
3927  PY_SCIP_CALL(SCIPgetLPBranchCands(self._scip, &lpcands, &lpcandssol, &lpcandsfrac,
3928  &nlpcands, &npriolpcands, &nfracimplvars))
3929 
3930  return ([Variable.create(lpcands[i]) for i in range(nlpcands)], [lpcandssol[i] for i in range(nlpcands)],
3931  [lpcandsfrac[i] for i in range(nlpcands)], nlpcands, npriolpcands, nfracimplvars)
3932 
3934  """gets branching candidates for pseudo solution branching (non-fixed variables)
3935  along with the number of candidates.
3936 
3937  :return tuple (pseudocands, npseudocands, npriopseudocands) where
3938 
3939  pseudocands: list of variables of pseudo branching candidates
3940  npseudocands: number of pseudo branching candidates
3941  npriopseudocands: number of candidates with maximal priority
3942 
3943  """
3944  cdef int npseudocands
3945  cdef int npriopseudocands
3946 
3947  cdef SCIP_VAR** pseudocands
3948 
3949  PY_SCIP_CALL(SCIPgetPseudoBranchCands(self._scip, &pseudocands, &npseudocands, &npriopseudocands))
3950 
3951  return ([Variable.create(pseudocands[i]) for i in range(npseudocands)], npseudocands, npriopseudocands)
3952 
3953  def branchVar(self, variable):
3954  """Branch on a non-continuous variable.
3955 
3956  :param variable: Variable to branch on
3957  :return: tuple(downchild, eqchild, upchild) of Nodes of the left, middle and right child. Middle child only exists
3958  if branch variable is integer (it is None otherwise)
3959 
3960  """
3961  cdef SCIP_NODE* downchild
3962  cdef SCIP_NODE* eqchild
3963  cdef SCIP_NODE* upchild
3964 
3965  PY_SCIP_CALL(SCIPbranchVar(self._scip, (<Variable>variable).scip_var, &downchild, &eqchild, &upchild))
3966  return Node.create(downchild), Node.create(eqchild), Node.create(upchild)
3967 
3968 
3969  def branchVarVal(self, variable, value):
3970  """Branches on variable using a value which separates the domain of the variable.
3971 
3972  :param variable: Variable to branch on
3973  :param value: float, value to branch on
3974  :return: tuple(downchild, eqchild, upchild) of Nodes of the left, middle and right child. Middle child only exists
3975  if branch variable is integer (it is None otherwise)
3976 
3977  """
3978  cdef SCIP_NODE* downchild
3979  cdef SCIP_NODE* eqchild
3980  cdef SCIP_NODE* upchild
3981 
3982  PY_SCIP_CALL(SCIPbranchVarVal(self._scip, (<Variable>variable).scip_var, value, &downchild, &eqchild, &upchild))
3983 
3984  return Node.create(downchild), Node.create(eqchild), Node.create(upchild)
3985 
3986  def calcNodeselPriority(self, Variable variable, branchdir, targetvalue):
3987  """calculates the node selection priority for moving the given variable's LP value
3988  to the given target value;
3989  this node selection priority can be given to the SCIPcreateChild() call
3990 
3991  :param variable: variable on which the branching is applied
3992  :param branchdir: type of branching that was performed
3993  :param targetvalue: new value of the variable in the child node
3994  :return: node selection priority for moving the given variable's LP value to the given target value
3995 
3996  """
3997  return SCIPcalcNodeselPriority(self._scip, variable.scip_var, branchdir, targetvalue)
3998 
3999  def calcChildEstimate(self, Variable variable, targetvalue):
4000  """Calculates an estimate for the objective of the best feasible solution
4001  contained in the subtree after applying the given branching;
4002  this estimate can be given to the SCIPcreateChild() call
4003 
4004  :param variable: Variable to compute the estimate for
4005  :param targetvalue: new value of the variable in the child node
4006  :return: objective estimate of the best solution in the subtree after applying the given branching
4007 
4008  """
4009  return SCIPcalcChildEstimate(self._scip, variable.scip_var, targetvalue)
4010 
4011  def createChild(self, nodeselprio, estimate):
4012  """Create a child node of the focus node.
4013 
4014  :param nodeselprio: float, node selection priority of new node
4015  :param estimate: float, estimate for(transformed) objective value of best feasible solution in subtree
4016  :return: Node, the child which was created
4017 
4018  """
4019  cdef SCIP_NODE* child
4020  PY_SCIP_CALL(SCIPcreateChild(self._scip, &child, nodeselprio, estimate))
4021  return Node.create(child)
4022 
4023  # Diving methods (Diving is LP related)
4024  def startDive(self):
4025  """Initiates LP diving
4026  It allows the user to change the LP in several ways, solve, change again, etc, without affecting the actual LP that has. When endDive() is called,
4027  SCIP will undo all changes done and recover the LP it had before startDive
4028  """
4029  PY_SCIP_CALL(SCIPstartDive(self._scip))
4030 
4031  def endDive(self):
4032  """Quits probing and resets bounds and constraints to the focus node's environment"""
4033  PY_SCIP_CALL(SCIPendDive(self._scip))
4034 
4035  def chgVarObjDive(self, Variable var, newobj):
4036  """changes (column) variable's objective value in current dive"""
4037  PY_SCIP_CALL(SCIPchgVarObjDive(self._scip, var.scip_var, newobj))
4038 
4039  def chgVarLbDive(self, Variable var, newbound):
4040  """changes variable's current lb in current dive"""
4041  PY_SCIP_CALL(SCIPchgVarLbDive(self._scip, var.scip_var, newbound))
4042 
4043  def chgVarUbDive(self, Variable var, newbound):
4044  """changes variable's current ub in current dive"""
4045  PY_SCIP_CALL(SCIPchgVarUbDive(self._scip, var.scip_var, newbound))
4046 
4047  def getVarLbDive(self, Variable var):
4048  """returns variable's current lb in current dive"""
4049  return SCIPgetVarLbDive(self._scip, var.scip_var)
4050 
4051  def getVarUbDive(self, Variable var):
4052  """returns variable's current ub in current dive"""
4053  return SCIPgetVarUbDive(self._scip, var.scip_var)
4054 
4055  def chgRowLhsDive(self, Row row, newlhs):
4056  """changes row lhs in current dive, change will be undone after diving
4057  ends, for permanent changes use SCIPchgRowLhs()
4058  """
4059  PY_SCIP_CALL(SCIPchgRowLhsDive(self._scip, row.scip_row, newlhs))
4060 
4061  def chgRowRhsDive(self, Row row, newrhs):
4062  """changes row rhs in current dive, change will be undone after diving
4063  ends, for permanent changes use SCIPchgRowLhs()
4064  """
4065  PY_SCIP_CALL(SCIPchgRowRhsDive(self._scip, row.scip_row, newrhs))
4066 
4067  def addRowDive(self, Row row):
4068  """adds a row to the LP in current dive"""
4069  PY_SCIP_CALL(SCIPaddRowDive(self._scip, row.scip_row))
4070 
4071  def solveDiveLP(self, itlim = -1):
4072  """solves the LP of the current dive no separation or pricing is applied
4073  no separation or pricing is applied
4074  :param itlim: maximal number of LP iterations to perform (Default value = -1, that is, no limit)
4075  returns two booleans:
4076  lperror -- if an unresolved lp error occured
4077  cutoff -- whether the LP was infeasible or the objective limit was reached
4078  """
4079  cdef SCIP_Bool lperror
4080  cdef SCIP_Bool cutoff
4081 
4082  PY_SCIP_CALL(SCIPsolveDiveLP(self._scip, itlim, &lperror, &cutoff))
4083  return lperror, cutoff
4084 
4085  def inRepropagation(self):
4086  """returns if the current node is already solved and only propagated again."""
4087  return SCIPinRepropagation(self._scip)
4088 
4089  # Probing methods (Probing is tree based)
4090  def startProbing(self):
4091  """Initiates probing, making methods SCIPnewProbingNode(), SCIPbacktrackProbing(), SCIPchgVarLbProbing(),
4092  SCIPchgVarUbProbing(), SCIPfixVarProbing(), SCIPpropagateProbing(), SCIPsolveProbingLP(), etc available
4093  """
4094  PY_SCIP_CALL( SCIPstartProbing(self._scip) )
4095 
4096  def endProbing(self):
4097  """Quits probing and resets bounds and constraints to the focus node's environment"""
4098  PY_SCIP_CALL( SCIPendProbing(self._scip) )
4099 
4100  def newProbingNode(self):
4101  """creates a new probing sub node, whose changes can be undone by backtracking to a higher node in the
4102  probing path with a call to backtrackProbing()
4103  """
4104  PY_SCIP_CALL( SCIPnewProbingNode(self._scip) )
4105 
4106  def backtrackProbing(self, probingdepth):
4107  """undoes all changes to the problem applied in probing up to the given probing depth
4108  :param probingdepth: probing depth of the node in the probing path that should be reactivated
4109  """
4110  PY_SCIP_CALL( SCIPbacktrackProbing(self._scip, probingdepth) )
4111 
4112  def getProbingDepth(self):
4113  """returns the current probing depth"""
4114  return SCIPgetProbingDepth(self._scip)
4115 
4116  def chgVarObjProbing(self, Variable var, newobj):
4117  """changes (column) variable's objective value during probing mode"""
4118  PY_SCIP_CALL( SCIPchgVarObjProbing(self._scip, var.scip_var, newobj) )
4119 
4120  def chgVarLbProbing(self, Variable var, lb):
4121  """changes the variable lower bound during probing mode
4122 
4123  :param Variable var: variable to change bound of
4124  :param lb: new lower bound (set to None for -infinity)
4125  """
4126  if lb is None:
4127  lb = -SCIPinfinity(self._scip)
4128  PY_SCIP_CALL(SCIPchgVarLbProbing(self._scip, var.scip_var, lb))
4129 
4130  def chgVarUbProbing(self, Variable var, ub):
4131  """changes the variable upper bound during probing mode
4132 
4133  :param Variable var: variable to change bound of
4134  :param ub: new upper bound (set to None for +infinity)
4135  """
4136  if ub is None:
4137  ub = SCIPinfinity(self._scip)
4138  PY_SCIP_CALL(SCIPchgVarUbProbing(self._scip, var.scip_var, ub))
4139 
4140  def fixVarProbing(self, Variable var, fixedval):
4141  """Fixes a variable at the current probing node."""
4142  PY_SCIP_CALL( SCIPfixVarProbing(self._scip, var.scip_var, fixedval) )
4143 
4145  """returns whether the objective function has changed during probing mode"""
4146  return SCIPisObjChangedProbing(self._scip)
4147 
4148  def inProbing(self):
4149  """returns whether we are in probing mode; probing mode is activated via startProbing() and stopped via endProbing()"""
4150  return SCIPinProbing(self._scip)
4151 
4152  def solveProbingLP(self, itlim = -1):
4153  """solves the LP at the current probing node (cannot be applied at preprocessing stage)
4154  no separation or pricing is applied
4155  :param itlim: maximal number of LP iterations to perform (Default value = -1, that is, no limit)
4156  returns two booleans:
4157  lperror -- if an unresolved lp error occured
4158  cutoff -- whether the LP was infeasible or the objective limit was reached
4159  """
4160  cdef SCIP_Bool lperror
4161  cdef SCIP_Bool cutoff
4162 
4163  PY_SCIP_CALL( SCIPsolveProbingLP(self._scip, itlim, &lperror, &cutoff) )
4164  return lperror, cutoff
4165 
4166  def applyCutsProbing(self):
4167  """applies the cuts in the separation storage to the LP and clears the storage afterwards;
4168  this method can only be applied during probing; the user should resolve the probing LP afterwards
4169  in order to get a new solution
4170  returns:
4171  cutoff -- whether an empty domain was created
4172  """
4173  cdef SCIP_Bool cutoff
4174 
4175  PY_SCIP_CALL( SCIPapplyCutsProbing(self._scip, &cutoff) )
4176  return cutoff
4177 
4178  def propagateProbing(self, maxproprounds):
4179  """applies domain propagation on the probing sub problem, that was changed after SCIPstartProbing() was called;
4180  the propagated domains of the variables can be accessed with the usual bound accessing calls SCIPvarGetLbLocal()
4181  and SCIPvarGetUbLocal(); the propagation is only valid locally, i.e. the local bounds as well as the changed
4182  bounds due to SCIPchgVarLbProbing(), SCIPchgVarUbProbing(), and SCIPfixVarProbing() are used for propagation
4183  :param maxproprounds: maximal number of propagation rounds (Default value = -1, that is, no limit)
4184  returns:
4185  cutoff -- whether the probing node can be cutoff
4186  ndomredsfound -- number of domain reductions found
4187  """
4188  cdef SCIP_Bool cutoff
4189  cdef SCIP_Longint ndomredsfound
4190 
4191  PY_SCIP_CALL( SCIPpropagateProbing(self._scip, maxproprounds, &cutoff, &ndomredsfound) )
4192  return cutoff, ndomredsfound
4193 
4194  def interruptSolve(self):
4195  """Interrupt the solving process as soon as possible."""
4196  PY_SCIP_CALL(SCIPinterruptSolve(self._scip))
4197 
4198  def restartSolve(self):
4199  """Restarts the solving process as soon as possible."""
4200  PY_SCIP_CALL(SCIPrestartSolve(self._scip))
4201 
4202  # Solution functions
4203 
4204  def writeLP(self, filename="LP.lp"):
4205  """writes current LP to a file
4206  :param filename: file name (Default value = "LP.lp")
4207  """
4208  absfile = str_conversion(abspath(filename))
4209  PY_SCIP_CALL( SCIPwriteLP(self._scip, absfile) )
4210 
4211  def createSol(self, Heur heur = None):
4212  """Create a new primal solution.
4213 
4214  :param Heur heur: heuristic that found the solution (Default value = None)
4215 
4216  """
4217  cdef SCIP_HEUR* _heur
4218  cdef SCIP_SOL* _sol
4219 
4220  if isinstance(heur, Heur):
4221  n = str_conversion(heur.name)
4222  _heur = SCIPfindHeur(self._scip, n)
4223  else:
4224  _heur = NULL
4225  PY_SCIP_CALL(SCIPcreateSol(self._scip, &_sol, _heur))
4226  solution = Solution.create(self._scip, _sol)
4227  return solution
4228 
4229  def createPartialSol(self, Heur heur = None):
4230  """Create a partial primal solution, initialized to unknown values.
4231  :param Heur heur: heuristic that found the solution (Default value = None)
4232 
4233  """
4234  cdef SCIP_HEUR* _heur
4235  cdef SCIP_SOL* _sol
4236 
4237  if isinstance(heur, Heur):
4238  n = str_conversion(heur.name)
4239  _heur = SCIPfindHeur(self._scip, n)
4240  else:
4241  _heur = NULL
4242  PY_SCIP_CALL(SCIPcreatePartialSol(self._scip, &_sol, _heur))
4243  partialsolution = Solution.create(self._scip, _sol)
4244  return partialsolution
4245 
4246  def printBestSol(self, write_zeros=False):
4247  """Prints the best feasible primal solution."""
4248  PY_SCIP_CALL(SCIPprintBestSol(self._scip, NULL, write_zeros))
4249 
4250  def printSol(self, Solution solution=None, write_zeros=False):
4251  """Print the given primal solution.
4252 
4253  Keyword arguments:
4254  solution -- solution to print
4255  write_zeros -- include variables that are set to zero
4256  """
4257  if solution is None:
4258  PY_SCIP_CALL(SCIPprintSol(self._scip, NULL, NULL, write_zeros))
4259  else:
4260  PY_SCIP_CALL(SCIPprintSol(self._scip, solution.sol, NULL, write_zeros))
4261 
4262  def writeBestSol(self, filename="origprob.sol", write_zeros=False):
4263  """Write the best feasible primal solution to a file.
4264 
4265  Keyword arguments:
4266  filename -- name of the output file
4267  write_zeros -- include variables that are set to zero
4268  """
4269  # use this doubled opening pattern to ensure that IOErrors are
4270  # triggered early and in Python not in C,Cython or SCIP.
4271  with open(filename, "w") as f:
4272  cfile = fdopen(f.fileno(), "w")
4273  PY_SCIP_CALL(SCIPprintBestSol(self._scip, cfile, write_zeros))
4274 
4275  def writeBestTransSol(self, filename="transprob.sol", write_zeros=False):
4276  """Write the best feasible primal solution for the transformed problem to a file.
4277 
4278  Keyword arguments:
4279  filename -- name of the output file
4280  write_zeros -- include variables that are set to zero
4281  """
4282  # use this double opening pattern to ensure that IOErrors are
4283  # triggered early and in python not in C, Cython or SCIP.
4284  with open(filename, "w") as f:
4285  cfile = fdopen(f.fileno(), "w")
4286  PY_SCIP_CALL(SCIPprintBestTransSol(self._scip, cfile, write_zeros))
4287 
4288  def writeSol(self, Solution solution, filename="origprob.sol", write_zeros=False):
4289  """Write the given primal solution to a file.
4290 
4291  Keyword arguments:
4292  solution -- solution to write
4293  filename -- name of the output file
4294  write_zeros -- include variables that are set to zero
4295  """
4296  # use this doubled opening pattern to ensure that IOErrors are
4297  # triggered early and in Python not in C,Cython or SCIP.
4298  with open(filename, "w") as f:
4299  cfile = fdopen(f.fileno(), "w")
4300  PY_SCIP_CALL(SCIPprintSol(self._scip, solution.sol, cfile, write_zeros))
4301 
4302  def writeTransSol(self, Solution solution, filename="transprob.sol", write_zeros=False):
4303  """Write the given transformed primal solution to a file.
4304 
4305  Keyword arguments:
4306  solution -- transformed solution to write
4307  filename -- name of the output file
4308  write_zeros -- include variables that are set to zero
4309  """
4310  # use this doubled opening pattern to ensure that IOErrors are
4311  # triggered early and in Python not in C,Cython or SCIP.
4312  with open(filename, "w") as f:
4313  cfile = fdopen(f.fileno(), "w")
4314  PY_SCIP_CALL(SCIPprintTransSol(self._scip, solution.sol, cfile, write_zeros))
4315 
4316  # perhaps this should not be included as it implements duplicated functionality
4317  # (as does it's namesake in SCIP)
4318  def readSol(self, filename):
4319  """Reads a given solution file, problem has to be transformed in advance.
4320 
4321  Keyword arguments:
4322  filename -- name of the input file
4323  """
4324  absfile = str_conversion(abspath(filename))
4325  PY_SCIP_CALL(SCIPreadSol(self._scip, absfile))
4326 
4327  def readSolFile(self, filename):
4328  """Reads a given solution file.
4329 
4330  Solution is created but not added to storage/the model.
4331  Use 'addSol' OR 'trySol' to add it.
4332 
4333  Keyword arguments:
4334  filename -- name of the input file
4335  """
4336  cdef SCIP_Bool partial
4337  cdef SCIP_Bool error
4338  cdef SCIP_Bool stored
4339  cdef Solution solution
4340 
4341  str_absfile = abspath(filename)
4342  absfile = str_conversion(str_absfile)
4343  solution = self.createSol()
4344  PY_SCIP_CALL(SCIPreadSolFile(self._scip, absfile, solution.sol, False, &partial, &error))
4345  if error:
4346  raise Exception("SCIP: reading solution from file " + str_absfile + " failed!")
4347 
4348  return solution
4349 
4350  def setSolVal(self, Solution solution, Variable var, val):
4351  """Set a variable in a solution.
4352 
4353  :param Solution solution: solution to be modified
4354  :param Variable var: variable in the solution
4355  :param val: value of the specified variable
4356 
4357  """
4358  cdef SCIP_SOL* _sol
4359  _sol = <SCIP_SOL*>solution.sol
4360  PY_SCIP_CALL(SCIPsetSolVal(self._scip, _sol, var.scip_var, val))
4361 
4362  def trySol(self, Solution solution, printreason=True, completely=False, checkbounds=True, checkintegrality=True, checklprows=True, free=True):
4363  """Check given primal solution for feasibility and try to add it to the storage.
4364 
4365  :param Solution solution: solution to store
4366  :param printreason: should all reasons of violations be printed? (Default value = True)
4367  :param completely: should all violation be checked? (Default value = False)
4368  :param checkbounds: should the bounds of the variables be checked? (Default value = True)
4369  :param checkintegrality: has integrality to be checked? (Default value = True)
4370  :param checklprows: have current LP rows (both local and global) to be checked? (Default value = True)
4371  :param free: should solution be freed? (Default value = True)
4372 
4373  """
4374  cdef SCIP_Bool stored
4375  if free:
4376  PY_SCIP_CALL(SCIPtrySolFree(self._scip, &solution.sol, printreason, completely, checkbounds, checkintegrality, checklprows, &stored))
4377  else:
4378  PY_SCIP_CALL(SCIPtrySol(self._scip, solution.sol, printreason, completely, checkbounds, checkintegrality, checklprows, &stored))
4379  return stored
4380 
4381  def checkSol(self, Solution solution, printreason=True, completely=False, checkbounds=True, checkintegrality=True, checklprows=True, original=False):
4382  """Check given primal solution for feasibility without adding it to the storage.
4383 
4384  :param Solution solution: solution to store
4385  :param printreason: should all reasons of violations be printed? (Default value = True)
4386  :param completely: should all violation be checked? (Default value = False)
4387  :param checkbounds: should the bounds of the variables be checked? (Default value = True)
4388  :param checkintegrality: has integrality to be checked? (Default value = True)
4389  :param checklprows: have current LP rows (both local and global) to be checked? (Default value = True)
4390  :param original: must the solution be checked against the original problem (Default value = False)
4391 
4392  """
4393  cdef SCIP_Bool feasible
4394  if original:
4395  PY_SCIP_CALL(SCIPcheckSolOrig(self._scip, solution.sol, &feasible, printreason, completely))
4396  else:
4397  PY_SCIP_CALL(SCIPcheckSol(self._scip, solution.sol, printreason, completely, checkbounds, checkintegrality, checklprows, &feasible))
4398  return feasible
4399 
4400  def addSol(self, Solution solution, free=True):
4401  """Try to add a solution to the storage.
4402 
4403  :param Solution solution: solution to store
4404  :param free: should solution be freed afterwards? (Default value = True)
4405 
4406  """
4407  cdef SCIP_Bool stored
4408  if free:
4409  PY_SCIP_CALL(SCIPaddSolFree(self._scip, &solution.sol, &stored))
4410  else:
4411  PY_SCIP_CALL(SCIPaddSol(self._scip, solution.sol, &stored))
4412  return stored
4413 
4414  def freeSol(self, Solution solution):
4415  """Free given solution
4416 
4417  :param Solution solution: solution to be freed
4418 
4419  """
4420  PY_SCIP_CALL(SCIPfreeSol(self._scip, &solution.sol))
4421 
4422  def getNSols(self):
4423  """gets number of feasible primal solutions stored in the solution storage in case the problem is transformed;
4424  in case the problem stage is SCIP_STAGE_PROBLEM, the number of solution in the original solution candidate
4425  storage is returned
4426  """
4427  return SCIPgetNSols(self._scip)
4428 
4429  def getNSolsFound(self):
4430  """gets number of feasible primal solutions found so far"""
4431  return SCIPgetNSolsFound(self._scip)
4432 
4433  def getNLimSolsFound(self):
4434  """gets number of feasible primal solutions respecting the objective limit found so far"""
4435  return SCIPgetNLimSolsFound(self._scip)
4436 
4438  """gets number of feasible primal solutions found so far, that improved the primal bound at the time they were found"""
4439  return SCIPgetNBestSolsFound(self._scip)
4440 
4441  def getSols(self):
4442  """Retrieve list of all feasible primal solutions stored in the solution storage."""
4443  cdef SCIP_SOL** _sols
4444  cdef SCIP_SOL* _sol
4445  _sols = SCIPgetSols(self._scip)
4446  nsols = SCIPgetNSols(self._scip)
4447  sols = []
4448 
4449  for i in range(nsols):
4450  sols.append(Solution.create(self._scip, _sols[i]))
4451 
4452  return sols
4453 
4454  def getBestSol(self):
4455  """Retrieve currently best known feasible primal solution."""
4456  self._bestSol = Solution.create(self._scip, SCIPgetBestSol(self._scip))
4457  return self._bestSol
4458 
4459  def getSolObjVal(self, Solution sol, original=True):
4460  """Retrieve the objective value of the solution.
4461 
4462  :param Solution sol: solution
4463  :param original: objective value in original space (Default value = True)
4464 
4465  """
4466  if sol == None:
4467  sol = Solution.create(self._scip, NULL)
4468  sol._checkStage("getSolObjVal")
4469  if original:
4470  objval = SCIPgetSolOrigObj(self._scip, sol.sol)
4471  else:
4472  objval = SCIPgetSolTransObj(self._scip, sol.sol)
4473  return objval
4474 
4475  def getObjVal(self, original=True):
4476  """Retrieve the objective value of value of best solution.
4477  Can only be called after solving is completed.
4478 
4479  :param original: objective value in original space (Default value = True)
4480 
4481  """
4482  if not self.getStage() >= SCIP_STAGE_SOLVING:
4483  raise Warning("method cannot be called before problem is solved")
4484  return self.getSolObjVal(self._bestSol, original)
4485 
4486  def getSolVal(self, Solution sol, Expr expr):
4487  """Retrieve value of given variable or expression in the given solution or in
4488  the LP/pseudo solution if sol == None
4489 
4490  :param Solution sol: solution
4491  :param Expr expr: polynomial expression to query the value of
4492 
4493  Note: a variable is also an expression
4494  """
4495  # no need to create a NULL solution wrapper in case we have a variable
4496  if sol == None and isinstance(expr, Variable):
4497  var = <Variable> expr
4498  return SCIPgetSolVal(self._scip, NULL, var.scip_var)
4499  if sol == None:
4500  sol = Solution.create(self._scip, NULL)
4501  return sol[expr]
4502 
4503  def getVal(self, Expr expr):
4504  """Retrieve the value of the given variable or expression in the best known solution.
4505  Can only be called after solving is completed.
4506 
4507  :param Expr expr: polynomial expression to query the value of
4508 
4509  Note: a variable is also an expression
4510  """
4511  if not self.getStage() >= SCIP_STAGE_SOLVING:
4512  raise Warning("method cannot be called before problem is solved")
4513  return self.getSolVal(self._bestSol, expr)
4514 
4515  def getPrimalbound(self):
4516  """Retrieve the best primal bound."""
4517  return SCIPgetPrimalbound(self._scip)
4518 
4519  def getDualbound(self):
4520  """Retrieve the best dual bound."""
4521  return SCIPgetDualbound(self._scip)
4522 
4523  def getDualboundRoot(self):
4524  """Retrieve the best root dual bound."""
4525  return SCIPgetDualboundRoot(self._scip)
4526 
4527  def writeName(self, Variable var):
4528  """Write the name of the variable to the std out.
4529 
4530  :param Variable var: variable
4531 
4532  """
4533  PY_SCIP_CALL(SCIPwriteVarName(self._scip, NULL, var.scip_var, False))
4534 
4535  def getStage(self):
4536  """Retrieve current SCIP stage"""
4537  return SCIPgetStage(self._scip)
4538 
4539  def getStatus(self):
4540  """Retrieve solution status."""
4541  cdef SCIP_STATUS stat = SCIPgetStatus(self._scip)
4542  if stat == SCIP_STATUS_OPTIMAL:
4543  return "optimal"
4544  elif stat == SCIP_STATUS_TIMELIMIT:
4545  return "timelimit"
4546  elif stat == SCIP_STATUS_INFEASIBLE:
4547  return "infeasible"
4548  elif stat == SCIP_STATUS_UNBOUNDED:
4549  return "unbounded"
4550  elif stat == SCIP_STATUS_USERINTERRUPT:
4551  return "userinterrupt"
4552  elif stat == SCIP_STATUS_INFORUNBD:
4553  return "inforunbd"
4554  elif stat == SCIP_STATUS_NODELIMIT:
4555  return "nodelimit"
4556  elif stat == SCIP_STATUS_TOTALNODELIMIT:
4557  return "totalnodelimit"
4558  elif stat == SCIP_STATUS_STALLNODELIMIT:
4559  return "stallnodelimit"
4560  elif stat == SCIP_STATUS_GAPLIMIT:
4561  return "gaplimit"
4562  elif stat == SCIP_STATUS_MEMLIMIT:
4563  return "memlimit"
4564  elif stat == SCIP_STATUS_SOLLIMIT:
4565  return "sollimit"
4566  elif stat == SCIP_STATUS_BESTSOLLIMIT:
4567  return "bestsollimit"
4568  elif stat == SCIP_STATUS_RESTARTLIMIT:
4569  return "restartlimit"
4570  else:
4571  return "unknown"
4572 
4574  """Retrieve objective sense."""
4575  cdef SCIP_OBJSENSE sense = SCIPgetObjsense(self._scip)
4576  if sense == SCIP_OBJSENSE_MAXIMIZE:
4577  return "maximize"
4578  elif sense == SCIP_OBJSENSE_MINIMIZE:
4579  return "minimize"
4580  else:
4581  return "unknown"
4582 
4583  def catchEvent(self, eventtype, Eventhdlr eventhdlr):
4584  """catches a global (not variable or row dependent) event"""
4585  cdef SCIP_EVENTHDLR* _eventhdlr
4586  if isinstance(eventhdlr, Eventhdlr):
4587  n = str_conversion(eventhdlr.name)
4588  _eventhdlr = SCIPfindEventhdlr(self._scip, n)
4589  else:
4590  raise Warning("event handler not found")
4591  PY_SCIP_CALL(SCIPcatchEvent(self._scip, eventtype, _eventhdlr, NULL, NULL))
4592 
4593  def dropEvent(self, eventtype, Eventhdlr eventhdlr):
4594  """drops a global event (stops to track event)"""
4595  cdef SCIP_EVENTHDLR* _eventhdlr
4596  if isinstance(eventhdlr, Eventhdlr):
4597  n = str_conversion(eventhdlr.name)
4598  _eventhdlr = SCIPfindEventhdlr(self._scip, n)
4599  else:
4600  raise Warning("event handler not found")
4601  PY_SCIP_CALL(SCIPdropEvent(self._scip, eventtype, _eventhdlr, NULL, -1))
4602 
4603  def catchVarEvent(self, Variable var, eventtype, Eventhdlr eventhdlr):
4604  """catches an objective value or domain change event on the given transformed variable"""
4605  cdef SCIP_EVENTHDLR* _eventhdlr
4606  if isinstance(eventhdlr, Eventhdlr):
4607  n = str_conversion(eventhdlr.name)
4608  _eventhdlr = SCIPfindEventhdlr(self._scip, n)
4609  else:
4610  raise Warning("event handler not found")
4611  PY_SCIP_CALL(SCIPcatchVarEvent(self._scip, var.scip_var, eventtype, _eventhdlr, NULL, NULL))
4612 
4613  def dropVarEvent(self, Variable var, eventtype, Eventhdlr eventhdlr):
4614  """drops an objective value or domain change event (stops to track event) on the given transformed variable"""
4615  cdef SCIP_EVENTHDLR* _eventhdlr
4616  if isinstance(eventhdlr, Eventhdlr):
4617  n = str_conversion(eventhdlr.name)
4618  _eventhdlr = SCIPfindEventhdlr(self._scip, n)
4619  else:
4620  raise Warning("event handler not found")
4621  PY_SCIP_CALL(SCIPdropVarEvent(self._scip, var.scip_var, eventtype, _eventhdlr, NULL, -1))
4622 
4623  def catchRowEvent(self, Row row, eventtype, Eventhdlr eventhdlr):
4624  """catches a row coefficient, constant, or side change event on the given row"""
4625  cdef SCIP_EVENTHDLR* _eventhdlr
4626  if isinstance(eventhdlr, Eventhdlr):
4627  n = str_conversion(eventhdlr.name)
4628  _eventhdlr = SCIPfindEventhdlr(self._scip, n)
4629  else:
4630  raise Warning("event handler not found")
4631  PY_SCIP_CALL(SCIPcatchRowEvent(self._scip, row.scip_row, eventtype, _eventhdlr, NULL, NULL))
4632 
4633  def dropRowEvent(self, Row row, eventtype, Eventhdlr eventhdlr):
4634  """drops a row coefficient, constant, or side change event (stops to track event) on the given row"""
4635  cdef SCIP_EVENTHDLR* _eventhdlr
4636  if isinstance(eventhdlr, Eventhdlr):
4637  n = str_conversion(eventhdlr.name)
4638  _eventhdlr = SCIPfindEventhdlr(self._scip, n)
4639  else:
4640  raise Warning("event handler not found")
4641  PY_SCIP_CALL(SCIPdropRowEvent(self._scip, row.scip_row, eventtype, _eventhdlr, NULL, -1))
4642 
4643  # Statistic Methods
4644 
4645  def printStatistics(self):
4646  """Print statistics."""
4647  PY_SCIP_CALL(SCIPprintStatistics(self._scip, NULL))
4648 
4649  def writeStatistics(self, filename="origprob.stats"):
4650  """Write statistics to a file.
4651 
4652  Keyword arguments:
4653  filename -- name of the output file
4654  """
4655  # use this doubled opening pattern to ensure that IOErrors are
4656  # triggered early and in Python not in C,Cython or SCIP.
4657  with open(filename, "w") as f:
4658  cfile = fdopen(f.fileno(), "w")
4659  PY_SCIP_CALL(SCIPprintStatistics(self._scip, cfile))
4660 
4661  def getNLPs(self):
4662  """gets total number of LPs solved so far"""
4663  return SCIPgetNLPs(self._scip)
4664 
4665  # Verbosity Methods
4666 
4667  def hideOutput(self, quiet = True):
4668  """Hide the output.
4669 
4670  :param quiet: hide output? (Default value = True)
4671 
4672  """
4673  SCIPsetMessagehdlrQuiet(self._scip, quiet)
4674 
4675  # Output Methods
4676 
4677  def redirectOutput(self):
4678  """Send output to python instead of terminal."""
4679 
4680  cdef SCIP_MESSAGEHDLR *myMessageHandler
4681 
4682  PY_SCIP_CALL(SCIPmessagehdlrCreate(&myMessageHandler, False, NULL, False, relayMessage, relayMessage, relayMessage, NULL, NULL))
4683  PY_SCIP_CALL(SCIPsetMessagehdlr(self._scip, myMessageHandler))
4684  SCIPmessageSetErrorPrinting(relayErrorMessage, NULL)
4685 
4686  def setLogfile(self, path):
4687  """sets the log file name for the currently installed message handler
4688  :param path: name of log file, or None (no log)
4689  """
4690  c_path = str_conversion(path) if path else None
4691  SCIPsetMessagehdlrLogfile(self._scip, c_path)
4692 
4693  # Parameter Methods
4694 
4695  def setBoolParam(self, name, value):
4696  """Set a boolean-valued parameter.
4697 
4698  :param name: name of parameter
4699  :param value: value of parameter
4700 
4701  """
4702  n = str_conversion(name)
4703  PY_SCIP_CALL(SCIPsetBoolParam(self._scip, n, value))
4704 
4705  def setIntParam(self, name, value):
4706  """Set an int-valued parameter.
4707 
4708  :param name: name of parameter
4709  :param value: value of parameter
4710 
4711  """
4712  n = str_conversion(name)
4713  PY_SCIP_CALL(SCIPsetIntParam(self._scip, n, value))
4714 
4715  def setLongintParam(self, name, value):
4716  """Set a long-valued parameter.
4717 
4718  :param name: name of parameter
4719  :param value: value of parameter
4720 
4721  """
4722  n = str_conversion(name)
4723  PY_SCIP_CALL(SCIPsetLongintParam(self._scip, n, value))
4724 
4725  def setRealParam(self, name, value):
4726  """Set a real-valued parameter.
4727 
4728  :param name: name of parameter
4729  :param value: value of parameter
4730 
4731  """
4732  n = str_conversion(name)
4733  PY_SCIP_CALL(SCIPsetRealParam(self._scip, n, value))
4734 
4735  def setCharParam(self, name, value):
4736  """Set a char-valued parameter.
4737 
4738  :param name: name of parameter
4739  :param value: value of parameter
4740 
4741  """
4742  n = str_conversion(name)
4743  PY_SCIP_CALL(SCIPsetCharParam(self._scip, n, ord(value)))
4744 
4745  def setStringParam(self, name, value):
4746  """Set a string-valued parameter.
4747 
4748  :param name: name of parameter
4749  :param value: value of parameter
4750 
4751  """
4752  n = str_conversion(name)
4753  v = str_conversion(value)
4754  PY_SCIP_CALL(SCIPsetStringParam(self._scip, n, v))
4755 
4756  def setParam(self, name, value):
4757  """Set a parameter with value in int, bool, real, long, char or str.
4758 
4759  :param name: name of parameter
4760  :param value: value of parameter
4761  """
4762  cdef SCIP_PARAM* param
4763 
4764  n = str_conversion(name)
4765  param = SCIPgetParam(self._scip, n)
4766 
4767  if param == NULL:
4768  raise KeyError("Not a valid parameter name")
4769 
4770  paramtype = SCIPparamGetType(param)
4771 
4772  if paramtype == SCIP_PARAMTYPE_BOOL:
4773  PY_SCIP_CALL(SCIPsetBoolParam(self._scip, n, bool(int(value))))
4774  elif paramtype == SCIP_PARAMTYPE_INT:
4775  PY_SCIP_CALL(SCIPsetIntParam(self._scip, n, int(value)))
4776  elif paramtype == SCIP_PARAMTYPE_LONGINT:
4777  PY_SCIP_CALL(SCIPsetLongintParam(self._scip, n, int(value)))
4778  elif paramtype == SCIP_PARAMTYPE_REAL:
4779  PY_SCIP_CALL(SCIPsetRealParam(self._scip, n, float(value)))
4780  elif paramtype == SCIP_PARAMTYPE_CHAR:
4781  PY_SCIP_CALL(SCIPsetCharParam(self._scip, n, ord(value)))
4782  elif paramtype == SCIP_PARAMTYPE_STRING:
4783  v = str_conversion(value)
4784  PY_SCIP_CALL(SCIPsetStringParam(self._scip, n, v))
4785 
4786 
4787  def getParam(self, name):
4788  """Get the value of a parameter of type
4789  int, bool, real, long, char or str.
4790 
4791  :param name: name of parameter
4792  """
4793  cdef SCIP_PARAM* param
4794 
4795  n = str_conversion(name)
4796  param = SCIPgetParam(self._scip, n)
4797 
4798  if param == NULL:
4799  raise KeyError("Not a valid parameter name")
4800 
4801  paramtype = SCIPparamGetType(param)
4802 
4803  if paramtype == SCIP_PARAMTYPE_BOOL:
4804  return SCIPparamGetBool(param)
4805  elif paramtype == SCIP_PARAMTYPE_INT:
4806  return SCIPparamGetInt(param)
4807  elif paramtype == SCIP_PARAMTYPE_LONGINT:
4808  return SCIPparamGetLongint(param)
4809  elif paramtype == SCIP_PARAMTYPE_REAL:
4810  return SCIPparamGetReal(param)
4811  elif paramtype == SCIP_PARAMTYPE_CHAR:
4812  return chr(SCIPparamGetChar(param))
4813  elif paramtype == SCIP_PARAMTYPE_STRING:
4814  return SCIPparamGetString(param).decode('utf-8')
4815 
4816  def getParams(self):
4817  """Gets the values of all parameters as a dict mapping parameter names
4818  to their values."""
4819  cdef SCIP_PARAM** params
4820 
4821  params = SCIPgetParams(self._scip)
4822  result = {}
4823  for i in range(SCIPgetNParams(self._scip)):
4824  name = SCIPparamGetName(params[i]).decode('utf-8')
4825  result[name] = self.getParam(name)
4826  return result
4827 
4828  def setParams(self, params):
4829  """Sets multiple parameters at once.
4830 
4831  :param params: dict mapping parameter names to their values.
4832  """
4833  for name, value in params.items():
4834  self.setParam(name, value)
4835 
4836  def readParams(self, file):
4837  """Read an external parameter file.
4838 
4839  :param file: file to be read
4840 
4841  """
4842  absfile = str_conversion(abspath(file))
4843  PY_SCIP_CALL(SCIPreadParams(self._scip, absfile))
4844 
4845  def writeParams(self, filename='param.set', comments = True, onlychanged = True):
4846  """Write parameter settings to an external file.
4847 
4848  :param filename: file to be written (Default value = 'param.set')
4849  :param comments: write parameter descriptions as comments? (Default value = True)
4850  :param onlychanged: write only modified parameters (Default value = True)
4851 
4852  """
4853  str_absfile = abspath(filename)
4854  absfile = str_conversion(str_absfile)
4855  PY_SCIP_CALL(SCIPwriteParams(self._scip, absfile, comments, onlychanged))
4856  print('wrote parameter settings to file ' + str_absfile)
4857 
4858  def resetParam(self, name):
4859  """Reset parameter setting to its default value
4860 
4861  :param name: parameter to reset
4862 
4863  """
4864  n = str_conversion(name)
4865  PY_SCIP_CALL(SCIPresetParam(self._scip, n))
4866 
4867  def resetParams(self):
4868  """Reset parameter settings to their default values"""
4869  PY_SCIP_CALL(SCIPresetParams(self._scip))
4870 
4871  def setEmphasis(self, paraemphasis, quiet = True):
4872  """Set emphasis settings
4873 
4874  :param paraemphasis: emphasis to set
4875  :param quiet: hide output? (Default value = True)
4876 
4877  """
4878  PY_SCIP_CALL(SCIPsetEmphasis(self._scip, paraemphasis, quiet))
4879 
4880  def readProblem(self, filename, extension = None):
4881  """Read a problem instance from an external file.
4882 
4883  :param filename: problem file name
4884  :param extension: specify file extension/type (Default value = None)
4885 
4886  """
4887  absfile = str_conversion(abspath(filename))
4888  if extension is None:
4889  PY_SCIP_CALL(SCIPreadProb(self._scip, absfile, NULL))
4890  else:
4891  extension = str_conversion(extension)
4892  PY_SCIP_CALL(SCIPreadProb(self._scip, absfile, extension))
4893 
4894  # Counting functions
4895 
4896  def count(self):
4897  """Counts the number of feasible points of problem."""
4898  PY_SCIP_CALL(SCIPcount(self._scip))
4899 
4900  def getNReaders(self):
4901  """Get number of currently available readers."""
4902  return SCIPgetNReaders(self._scip)
4903 
4904  def getNCountedSols(self):
4905  """Get number of feasible solution."""
4906  cdef SCIP_Bool valid
4907  cdef SCIP_Longint nsols
4908 
4909  nsols = SCIPgetNCountedSols(self._scip, &valid)
4910  if not valid:
4911  print('total number of solutions found is not valid!')
4912  return nsols
4913 
4915  """Sets SCIP parameters such that a valid counting process is possible."""
4916  PY_SCIP_CALL(SCIPsetParamsCountsols(self._scip))
4917 
4918  def freeReoptSolve(self):
4919  """Frees all solution process data and prepares for reoptimization"""
4920  PY_SCIP_CALL(SCIPfreeReoptSolve(self._scip))
4921 
4922  def chgReoptObjective(self, coeffs, sense = 'minimize'):
4923  """Establish the objective function as a linear expression.
4924 
4925  :param coeffs: the coefficients
4926  :param sense: the objective sense (Default value = 'minimize')
4927 
4928  """
4929 
4930  cdef SCIP_OBJSENSE objsense
4931 
4932  if sense == "minimize":
4933  objsense = SCIP_OBJSENSE_MINIMIZE
4934  elif sense == "maximize":
4935  objsense = SCIP_OBJSENSE_MAXIMIZE
4936  else:
4937  raise Warning("unrecognized optimization sense: %s" % sense)
4938 
4939  assert isinstance(coeffs, Expr), "given coefficients are not Expr but %s" % coeffs.__class__.__name__
4940 
4941  if coeffs.degree() > 1:
4942  raise ValueError("Nonlinear objective functions are not supported!")
4943  if coeffs[CONST] != 0.0:
4944  raise ValueError("Constant offsets in objective are not supported!")
4945 
4946  cdef SCIP_VAR** _vars
4947  cdef int _nvars
4948  _vars = SCIPgetOrigVars(self._scip)
4949  _nvars = SCIPgetNOrigVars(self._scip)
4950  _coeffs = <SCIP_Real*> malloc(_nvars * sizeof(SCIP_Real))
4951 
4952  for i in range(_nvars):
4953  _coeffs[i] = 0.0
4954 
4955  for term, coef in coeffs.terms.items():
4956  # avoid CONST term of Expr
4957  if term != CONST:
4958  assert len(term) == 1
4959  var = <Variable>term[0]
4960  for i in range(_nvars):
4961  if _vars[i] == var.scip_var:
4962  _coeffs[i] = coef
4963 
4964  PY_SCIP_CALL(SCIPchgReoptObjective(self._scip, objsense, _vars, &_coeffs[0], _nvars))
4965 
4966  free(_coeffs)
4967 
4968  def chgVarBranchPriority(self, Variable var, priority):
4969  """Sets the branch priority of the variable.
4970  Variables with higher branch priority are always preferred to variables with lower priority in selection of branching variable.
4971 
4972  :param Variable var: variable to change priority of
4973  :param priority: the new priority of the variable (the default branching priority is 0)
4974  """
4975  assert isinstance(var, Variable), "The given variable is not a pyvar, but %s" % var.__class__.__name__
4976  PY_SCIP_CALL(SCIPchgVarBranchPriority(self._scip, var.scip_var, priority))
4977 
4978 # debugging memory management
4980  return BMSgetMemoryUsed() == 0
4981 
4983  BMScheckEmptyMemory()
pyscipopt.scip.Model.addConss
def addConss(self, conss, name='', initial=True, separate=True, enforce=True, check=True, propagate=True, local=False, modifiable=False, dynamic=False, removable=False, stickingatnode=False)
Definition: scip.pyx:2057
SCIPnlrowGetConstant
SCIP_Real SCIPnlrowGetConstant(SCIP_NLROW *nlrow)
SCIPgetProbName
const char * SCIPgetProbName(SCIP *scip)
SCIPnodeGetDomchg
SCIP_DOMCHG * SCIPnodeGetDomchg(SCIP_NODE *node)
pyscipopt.scip.Model.freeBendersSubproblems
def freeBendersSubproblems(self)
Definition: scip.pyx:3308
SCIPincludeBenderscut
SCIP_RETCODE SCIPincludeBenderscut(SCIP *scip, SCIP_BENDERS *benders, const char *name, const char *desc, int priority, SCIP_Bool islpcut, SCIP_DECL_BENDERSCUTCOPY((*benderscutcopy)), SCIP_DECL_BENDERSCUTFREE((*benderscutfree)), SCIP_DECL_BENDERSCUTINIT((*benderscutinit)), SCIP_DECL_BENDERSCUTEXIT((*benderscutexit)), SCIP_DECL_BENDERSCUTINITSOL((*benderscutinitsol)), SCIP_DECL_BENDERSCUTEXITSOL((*benderscutexitsol)), SCIP_DECL_BENDERSCUTEXEC((*benderscutexec)), SCIP_BENDERSCUTDATA *benderscutdata)
pyscipopt.scip.Model.tightenVarUb
def tightenVarUb(self, Variable, var, ub, force=False)
Definition: scip.pyx:1540
pyscipopt.scip.Model.propagateProbing
def propagateProbing(self, maxproprounds)
Definition: scip.pyx:4178
SCIPgetReadingTime
SCIP_Real SCIPgetReadingTime(SCIP *scip)
SCIPconsIsPropagated
SCIP_Bool SCIPconsIsPropagated(SCIP_CONS *cons)
pyscipopt.scip.Model.setObjIntegral
def setObjIntegral(self)
Definition: scip.pyx:1335
pyscipopt.scip.Model.includeSepa
def includeSepa(self, Sepa, sepa, name, desc, priority=0, freq=10, maxbounddist=1.0, usessubscip=False, delay=False)
Definition: scip.pyx:3666
pyscipopt.scip.Column.__class__
__class__
Definition: scip.pyx:379
SCIPexprGetQuadraticBilinTerm
void SCIPexprGetQuadraticBilinTerm(SCIP_EXPR *expr, int termidx, SCIP_EXPR **expr1, SCIP_EXPR **expr2, SCIP_Real *coef, int *pos2, SCIP_EXPR **prodexpr)
pyscipopt.scip.Model.getRowLinear
def getRowLinear(self, Constraint, cons)
Definition: scip.pyx:3141
pyscipopt.scip.Model.getPseudoBranchCands
def getPseudoBranchCands(self)
Definition: scip.pyx:3933
pyscipopt.scip.Row.getVals
def getVals(self)
Definition: scip.pyx:471
SCIPisEQ
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
pyscipopt.scip.Node.scip_node
scip_node
Definition: scip.pyx:645
pyscipopt.scip.Event.getOldBound
def getOldBound(self)
Definition: scip.pyx:295
SCIPdropVarEvent
SCIP_RETCODE SCIPdropVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
SCIPaddConsNode
SCIP_RETCODE SCIPaddConsNode(SCIP *scip, SCIP_NODE *node, SCIP_CONS *cons, SCIP_NODE *validnode)
SCIPisFeasIntegral
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
SCIPchgVarLbNode
SCIP_RETCODE SCIPchgVarLbNode(SCIP *scip, SCIP_NODE *node, SCIP_VAR *var, SCIP_Real newbound)
pyscipopt.scip.Model.fixVar
def fixVar(self, Variable, var, val)
Definition: scip.pyx:1497
pyscipopt.scip.Model.getDualfarkasLinear
def getDualfarkasLinear(self, Constraint, cons)
Definition: scip.pyx:3179
SCIPsetMessagehdlrQuiet
void SCIPsetMessagehdlrQuiet(SCIP *scip, SCIP_Bool quiet)
pyscipopt.scip.Row.isModifiable
def isModifiable(self)
Definition: scip.pyx:437
pyscipopt.scip.Variable.getLPSol
def getLPSol(self)
Definition: scip.pyx:838
SCIPnlrowGetLhs
SCIP_Real SCIPnlrowGetLhs(SCIP_NLROW *nlrow)
pyscipopt.scip.Model.setProbName
def setProbName(self, name)
Definition: scip.pyx:1364
SCIPincludeReader
SCIP_RETCODE SCIPincludeReader(SCIP *scip, const char *name, const char *desc, const char *extension, SCIP_DECL_READERCOPY((*readercopy)), SCIP_DECL_READERFREE((*readerfree)), SCIP_DECL_READERREAD((*readerread)), SCIP_DECL_READERWRITE((*readerwrite)), SCIP_READERDATA *readerdata)
SCIPgetVarsLinear
SCIP_VAR ** SCIPgetVarsLinear(SCIP *scip, SCIP_CONS *cons)
pyscipopt.scip.Model.getSlack
def getSlack(self, Constraint, cons, Solution, sol=None, side=None)
Definition: scip.pyx:2910
SCIPaddCons
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
SCIPgetDualbound
SCIP_Real SCIPgetDualbound(SCIP *scip)
pyscipopt.scip.NLRow.__class__
__class__
Definition: scip.pyx:530
pyscipopt.scip.BoundChange
Definition: scip.pyx:584
SCIPgetStatus
SCIP_STATUS SCIPgetStatus(SCIP *scip)
SCIPchgRhsNonlinear
SCIP_RETCODE SCIPchgRhsNonlinear(SCIP *scip, SCIP_CONS *cons, SCIP_Real rhs)
SCIPgetTransformedCons
SCIP_RETCODE SCIPgetTransformedCons(SCIP *scip, SCIP_CONS *cons, SCIP_CONS **transcons)
SCIPgetGap
SCIP_Real SCIPgetGap(SCIP *scip)
SCIPcreatePartialSol
SCIP_RETCODE SCIPcreatePartialSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
pyscipopt.scip.Model.delVar
def delVar(self, Variable, var)
Definition: scip.pyx:1510
SCIPgetDualboundRoot
SCIP_Real SCIPgetDualboundRoot(SCIP *scip)
SCIPsetIntParam
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
SCIPincludeConshdlr
SCIP_RETCODE SCIPincludeConshdlr(SCIP *scip, const char *name, const char *desc, int sepapriority, int enfopriority, int chckpriority, int sepafreq, int propfreq, int eagerfreq, int maxprerounds, SCIP_Bool delaysepa, SCIP_Bool delayprop, SCIP_Bool needscons, SCIP_PROPTIMING proptiming, SCIP_PRESOLTIMING presoltiming, SCIP_DECL_CONSHDLRCOPY((*conshdlrcopy)), SCIP_DECL_CONSFREE((*consfree)), SCIP_DECL_CONSINIT((*consinit)), SCIP_DECL_CONSEXIT((*consexit)), SCIP_DECL_CONSINITPRE((*consinitpre)), SCIP_DECL_CONSEXITPRE((*consexitpre)), SCIP_DECL_CONSINITSOL((*consinitsol)), SCIP_DECL_CONSEXITSOL((*consexitsol)), SCIP_DECL_CONSDELETE((*consdelete)), SCIP_DECL_CONSTRANS((*constrans)), SCIP_DECL_CONSINITLP((*consinitlp)), SCIP_DECL_CONSSEPALP((*conssepalp)), SCIP_DECL_CONSSEPASOL((*conssepasol)), SCIP_DECL_CONSENFOLP((*consenfolp)), SCIP_DECL_CONSENFORELAX((*consenforelax)), SCIP_DECL_CONSENFOPS((*consenfops)), SCIP_DECL_CONSCHECK((*conscheck)), SCIP_DECL_CONSPROP((*consprop)), SCIP_DECL_CONSPRESOL((*conspresol)), SCIP_DECL_CONSRESPROP((*consresprop)), SCIP_DECL_CONSLOCK((*conslock)), SCIP_DECL_CONSACTIVE((*consactive)), SCIP_DECL_CONSDEACTIVE((*consdeactive)), SCIP_DECL_CONSENABLE((*consenable)), SCIP_DECL_CONSDISABLE((*consdisable)), SCIP_DECL_CONSDELVARS((*consdelvars)), SCIP_DECL_CONSPRINT((*consprint)), SCIP_DECL_CONSCOPY((*conscopy)), SCIP_DECL_CONSPARSE((*consparse)), SCIP_DECL_CONSGETVARS((*consgetvars)), SCIP_DECL_CONSGETNVARS((*consgetnvars)), SCIP_DECL_CONSGETDIVEBDCHGS((*consgetdivebdchgs)), SCIP_CONSHDLRDATA *conshdlrdata)
pyscipopt.scip.Model.__init__
def __init__(self, problemName='model', defaultPlugins=True, Model, sourceModel=None, origcopy=False, globalcopy=True, enablepricing=False, createscip=True, threadsafe=False)
Definition: scip.pyx:942
pyscipopt.scip.Model.getBestNode
def getBestNode(self)
Definition: scip.pyx:1749
SCIPcreateExprValue
SCIP_RETCODE SCIPcreateExprValue(SCIP *scip, SCIP_EXPR **expr, SCIP_Real value, SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), void *ownercreatedata)
SCIPchgVarUb
SCIP_RETCODE SCIPchgVarUb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
pyscipopt.scip.Model.addVarToRow
def addVarToRow(self, Row, row, not, None, Variable, var, not, None, value)
Definition: scip.pyx:1926
pyscipopt.scip.Model._addGenNonlinearCons
def _addGenNonlinearCons(self, ExprCons, cons, **kwargs)
Definition: scip.pyx:2254
pyscipopt.scip.Constraint.isSeparated
def isSeparated(self)
Definition: scip.pyx:869
SCIPaddPricedVar
SCIP_RETCODE SCIPaddPricedVar(SCIP *scip, SCIP_VAR *var, SCIP_Real score)
SCIPconsIsLocal
SCIP_Bool SCIPconsIsLocal(SCIP_CONS *cons)
pyscipopt.scip.Model.catchEvent
def catchEvent(self, eventtype, Eventhdlr, eventhdlr)
Definition: scip.pyx:4583
pyscipopt.scip.Model.getDepth
def getDepth(self)
Definition: scip.pyx:1137
pyscipopt.scip.Model._scip
_scip
Definition: scip.pyx:1001
SCIPcreateExprPow
SCIP_RETCODE SCIPcreateExprPow(SCIP *scip, SCIP_EXPR **expr, SCIP_EXPR *child, SCIP_Real exponent, SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), void *ownercreatedata)
pyscipopt.scip.Model.setHeuristics
def setHeuristics(self, setting)
Definition: scip.pyx:1377
pyscipopt.scip.Model.__hash__
def __hash__(self)
Definition: scip.pyx:987
SCIPeventGetNewbound
SCIP_Real SCIPeventGetNewbound(SCIP_EVENT *event)
pyscipopt.scip.Model.redirectOutput
def redirectOutput(self)
Definition: scip.pyx:4677
pyscipopt.scip.Model.setRelaxSolVal
def setRelaxSolVal(self, Variable, var, val)
Definition: scip.pyx:3086
pyscipopt.scip.Model.isInfinity
def isInfinity(self, value)
Definition: scip.pyx:1169
SCIPgetVars
SCIP_VAR ** SCIPgetVars(SCIP *scip)
pyscipopt.scip.Column.getLb
def getLb(self)
Definition: scip.pyx:363
SCIPaddVar
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
SCIProwGetParallelism
SCIP_Real SCIProwGetParallelism(SCIP_ROW *row1, SCIP_ROW *row2, char orthofunc)
SCIPgetNActiveBenders
int SCIPgetNActiveBenders(SCIP *scip)
pyscipopt.scip.Model.dropEvent
def dropEvent(self, eventtype, Eventhdlr, eventhdlr)
Definition: scip.pyx:4593
SCIPsetSeparating
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
pyscipopt.scip.Model.checkQuadraticNonlinear
def checkQuadraticNonlinear(self, Constraint, cons)
Definition: scip.pyx:3013
SCIPfreeTransform
SCIP_RETCODE SCIPfreeTransform(SCIP *scip)
pyscipopt.scip.Model.branchVarVal
def branchVarVal(self, variable, value)
Definition: scip.pyx:3969
pyscipopt.scip.Model.getLPBInvRow
def getLPBInvRow(self, row)
Definition: scip.pyx:1838
SCIPcreateExprAbs
SCIP_RETCODE SCIPcreateExprAbs(SCIP *scip, SCIP_EXPR **expr, SCIP_EXPR *child, SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), void *ownercreatedata)
SCIPboundchgGetBoundchgtype
SCIP_BOUNDCHGTYPE SCIPboundchgGetBoundchgtype(SCIP_BOUNDCHG *boundchg)
SCIPaddSolFree
SCIP_RETCODE SCIPaddSolFree(SCIP *scip, SCIP_SOL **sol, SCIP_Bool *stored)
pyscipopt.scip.Model.chgRowRhsDive
def chgRowRhsDive(self, Row, row, newrhs)
Definition: scip.pyx:4061
SCIPchgVarObj
SCIP_RETCODE SCIPchgVarObj(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
pyscipopt.scip.Model.getObjVal
def getObjVal(self, original=True)
Definition: scip.pyx:4475
pyscipopt.scip.NLRow.getRhs
def getRhs(self)
Definition: scip.pyx:518
SCIPgetNLPRows
int SCIPgetNLPRows(SCIP *scip)
SCIPchgVarUbGlobal
SCIP_RETCODE SCIPchgVarUbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
SCIPreleaseVar
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
SCIPcreateConsSOS1
SCIP_RETCODE SCIPcreateConsSOS1(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *weights, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
pyscipopt.scip.Model.includeRelax
def includeRelax(self, Relax, relax, name, desc, priority=10000, freq=1)
Definition: scip.pyx:3762
SCIPgetNlRowSolActivity
SCIP_RETCODE SCIPgetNlRowSolActivity(SCIP *scip, SCIP_NLROW *nlrow, SCIP_SOL *sol, SCIP_Real *activity)
pyscipopt.scip.Row.getNLPNonz
def getNLPNonz(self)
Definition: scip.pyx:462
pyscipopt.scip.Model.setLongintParam
def setLongintParam(self, name, value)
Definition: scip.pyx:4715
SCIPeventGetNode
SCIP_NODE * SCIPeventGetNode(SCIP_EVENT *event)
SCIPwriteTransProblem
SCIP_RETCODE SCIPwriteTransProblem(SCIP *scip, const char *filename, const char *extension, SCIP_Bool genericnames)
pyscipopt.scip.Model.to_ptr
def to_ptr(self, give_ownership)
Definition: scip.pyx:1035
SCIPvarGetLPSol
SCIP_Real SCIPvarGetLPSol(SCIP_VAR *var)
pyscipopt.scip.Node.getAddedConss
def getAddedConss(self)
Definition: scip.pyx:672
pyscipopt.scip.Model.getDualboundRoot
def getDualboundRoot(self)
Definition: scip.pyx:4523
SCIPrepropagateNode
SCIP_RETCODE SCIPrepropagateNode(SCIP *scip, SCIP_NODE *node)
pyscipopt.scip.Model.getLPColsData
def getLPColsData(self)
Definition: scip.pyx:1804
SCIPcreateVarBasic
SCIP_RETCODE SCIPcreateVarBasic(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype)
pyscipopt.scip.Model.cacheRowExtensions
def cacheRowExtensions(self, Row, row, not, None)
Definition: scip.pyx:1915
pyscipopt.scip.Model.setSolVal
def setSolVal(self, Solution, solution, Variable, var, val)
Definition: scip.pyx:4350
SCIPcolGetLPPos
int SCIPcolGetLPPos(SCIP_COL *col)
pyscipopt.scip.Model.getObjectiveSense
def getObjectiveSense(self)
Definition: scip.pyx:4573
pyscipopt.scip.Model.separateSol
def separateSol(self, Solution, sol=None, pretendroot=False, allowlocal=True, onlydelayed=False)
Definition: scip.pyx:1987
pyscipopt.scip.Column.getPrimsol
def getPrimsol(self)
Definition: scip.pyx:359
SCIPconsGetHdlr
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
SCIPdropEvent
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
pyscipopt.scip.Model.getActivity
def getActivity(self, Constraint, cons, Solution, sol=None)
Definition: scip.pyx:2882
pyscipopt.scip.Model.chgVarUbDive
def chgVarUbDive(self, Variable, var, newbound)
Definition: scip.pyx:4043
SCIPnlrowGetRhs
SCIP_Real SCIPnlrowGetRhs(SCIP_NLROW *nlrow)
pyscipopt.scip.Model.disablePropagation
def disablePropagation(self, onlyroot=False)
Definition: scip.pyx:1385
SCIPconsIsModifiable
SCIP_Bool SCIPconsIsModifiable(SCIP_CONS *cons)
pyscipopt.scip.Model.writeProblem
def writeProblem(self, filename='model.cip', trans=False, genericnames=False)
Definition: scip.pyx:1395
pyscipopt.scip.Event.getNode
def getNode(self)
Definition: scip.pyx:304
SCIPconshdlrGetName
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
SCIPfreeSol
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
pyscipopt.scip.Variable.getUbLocal
def getUbLocal(self)
Definition: scip.pyx:830
SCIPgetTransformedVar
SCIP_RETCODE SCIPgetTransformedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **transvar)
SCIPgetVarLbDive
SCIP_Real SCIPgetVarLbDive(SCIP *scip, SCIP_VAR *var)
SCIPsolveConcurrent
SCIP_RETCODE SCIPsolveConcurrent(SCIP *scip)
pyscipopt.scip.Model.setPresolve
def setPresolve(self, setting)
Definition: scip.pyx:1356
SCIPconsGetName
const char * SCIPconsGetName(SCIP_CONS *cons)
pyscipopt.scip.Model.__dealloc__
def __dealloc__(self)
Definition: scip.pyx:981
SCIPnodeIsActive
SCIP_Bool SCIPnodeIsActive(SCIP_NODE *node)
SCIPnlrowGetLinearCoefs
SCIP_Real * SCIPnlrowGetLinearCoefs(SCIP_NLROW *nlrow)
SCIPgetLhsLinear
SCIP_Real SCIPgetLhsLinear(SCIP *scip, SCIP_CONS *cons)
pyscipopt.scip.Model.chgVarLbProbing
def chgVarLbProbing(self, Variable, var, lb)
Definition: scip.pyx:4120
pyscipopt.scip.Model.addConsSOS2
def addConsSOS2(self, vars, weights=None, name="SOS2cons", initial=True, separate=True, enforce=True, check=True, propagate=True, local=False, dynamic=False, removable=False, stickingatnode=False)
Definition: scip.pyx:2453
SCIPgetBestSol
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
pyscipopt.scip.Model.setBendersSubproblemIsConvex
def setBendersSubproblemIsConvex(self, Benders, benders, probnumber, isconvex=True)
Definition: scip.pyx:3363
pyscipopt.scip.Model.checkSol
def checkSol(self, Solution, solution, printreason=True, completely=False, checkbounds=True, checkintegrality=True, checklprows=True, original=False)
Definition: scip.pyx:4381
SCIPgetCutEfficacy
SCIP_Real SCIPgetCutEfficacy(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
pyscipopt.scip.Model.addConsCardinality
def addConsCardinality(self, consvars, cardval, indvars=None, weights=None, name="CardinalityCons", initial=True, separate=True, enforce=True, check=True, propagate=True, local=False, dynamic=False, removable=False, stickingatnode=False)
Definition: scip.pyx:2609
SCIPaddObjoffset
SCIP_RETCODE SCIPaddObjoffset(SCIP *scip, SCIP_Real addval)
pyscipopt.scip.Model.getDualsolLinear
def getDualsolLinear(self, Constraint, cons)
Definition: scip.pyx:3155
pyscipopt.scip.Model.isFeasEQ
def isFeasEQ(self, val1, val2)
Definition: scip.pyx:1185
SCIPcreateExprCos
SCIP_RETCODE SCIPcreateExprCos(SCIP *scip, SCIP_EXPR **expr, SCIP_EXPR *child, SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), void *ownercreatedata)
pyscipopt.scip.Variable.getIndex
def getIndex(self)
Definition: scip.pyx:800
pyscipopt.scip.Model.solveBendersSubproblem
def solveBendersSubproblem(self, probnumber, solvecip, Benders, benders=None, Solution, solution=None)
Definition: scip.pyx:3400
SCIPfeastol
SCIP_Real SCIPfeastol(SCIP *scip)
pyscipopt.scip.Constraint
Definition: scip.pyx:842
SCIPexprGetQuadraticData
void SCIPexprGetQuadraticData(SCIP_EXPR *expr, SCIP_Real *constant, int *nlinexprs, SCIP_EXPR ***linexprs, SCIP_Real **lincoefs, int *nquadexprs, int *nbilinexprs, SCIP_Real **eigenvalues, SCIP_Real **eigenvectors)
SCIPrestartSolve
SCIP_RETCODE SCIPrestartSolve(SCIP *scip)
pyscipopt.scip.Model.dropRowEvent
def dropRowEvent(self, Row, row, eventtype, Eventhdlr, eventhdlr)
Definition: scip.pyx:4633
pyscipopt.scip.Model.getLPBranchCands
def getLPBranchCands(self)
Definition: scip.pyx:3901
SCIPreadSol
SCIP_RETCODE SCIPreadSol(SCIP *scip, const char *filename)
pyscipopt.scip.Model.getNSolsFound
def getNSolsFound(self)
Definition: scip.pyx:4429
SCIPgetCurrentNode
SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
SCIPfeasFrac
SCIP_Real SCIPfeasFrac(SCIP *scip, SCIP_Real val)
pyscipopt.scip.Model.getNNlRows
def getNNlRows(self)
Definition: scip.pyx:2964
SCIPnodeGetDepth
int SCIPnodeGetDepth(SCIP_NODE *node)
pyscipopt.scip.Solution._evaluate
def _evaluate(self, term)
Definition: scip.pyx:553
pyscipopt.scip.Model.createChild
def createChild(self, nodeselprio, estimate)
Definition: scip.pyx:4011
SCIPgetBendersMasterVar
SCIP_RETCODE SCIPgetBendersMasterVar(SCIP *scip, SCIP_BENDERS *benders, SCIP_VAR *var, SCIP_VAR **mappedvar)
SCIPcreateConsCardinality
SCIP_RETCODE SCIPcreateConsCardinality(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, int cardval, SCIP_VAR **indvars, SCIP_Real *weights, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
pyscipopt.scip.Model.includeNodesel
def includeNodesel(self, Nodesel, nodesel, name, desc, stdpriority, memsavepriority)
Definition: scip.pyx:3820
SCIPchgVarLb
SCIP_RETCODE SCIPchgVarLb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
SCIPfreeProb
SCIP_RETCODE SCIPfreeProb(SCIP *scip)
pyscipopt.scip.Model.writeBestSol
def writeBestSol(self, filename="origprob.sol", write_zeros=False)
Definition: scip.pyx:4262
SCIPaddVarSOS1
SCIP_RETCODE SCIPaddVarSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real weight)
pyscipopt.scip.Model.getNCountedSols
def getNCountedSols(self)
Definition: scip.pyx:4904
pyscipopt.scip.Model.startDive
def startDive(self)
Definition: scip.pyx:4024
pyscipopt.scip.Model.includeBenderscut
def includeBenderscut(self, Benders, benders, Benderscut, benderscut, name, desc, priority=1, islpcut=True)
Definition: scip.pyx:3870
pyscipopt.scip.Model.getObjoffset
def getObjoffset(self, original=True)
Definition: scip.pyx:1323
pyscipopt.scip.Model.addConsCoeff
def addConsCoeff(self, Constraint, cons, Variable, var, coeff)
Definition: scip.pyx:2377
pyscipopt.scip.Model.checkBendersSubproblemOptimality
def checkBendersSubproblemOptimality(self, Solution, solution, probnumber, Benders, benders=None)
Definition: scip.pyx:3500
pyscipopt.scip.is_memory_freed
def is_memory_freed()
Definition: scip.pyx:4979
SCIPisLE
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
pyscipopt.scip.Row.isIntegral
def isIntegral(self)
Definition: scip.pyx:429
pyscipopt.scip.Model.createCons
def createCons(self, Conshdlr, conshdlr, name, initial=True, separate=True, enforce=True, check=True, propagate=True, local=False, modifiable=False, dynamic=False, removable=False, stickingatnode=False)
Definition: scip.pyx:3621
SCIPgetVarUbDive
SCIP_Real SCIPgetVarUbDive(SCIP *scip, SCIP_VAR *var)
pyscipopt.scip.Node.__eq__
def __eq__(self, other)
Definition: scip.pyx:751
SCIPaddOrigObjoffset
SCIP_RETCODE SCIPaddOrigObjoffset(SCIP *scip, SCIP_Real addval)
SCIPwriteLP
SCIP_RETCODE SCIPwriteLP(SCIP *scip, const char *filename)
SCIPappendVarCardinality
SCIP_RETCODE SCIPappendVarCardinality(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_VAR *indvar)
pyscipopt.scip.Model.optimize
def optimize(self)
Definition: scip.pyx:3225
SCIPnodeGetNAddedConss
int SCIPnodeGetNAddedConss(SCIP_NODE *node)
pyscipopt.scip.Model.chgVarObjDive
def chgVarObjDive(self, Variable, var, newobj)
Definition: scip.pyx:4035
pyscipopt.scip.DomainChanges.scip_domchg
scip_domchg
Definition: scip.pyx:628
pyscipopt.scip.Model.epsilon
def epsilon(self)
Definition: scip.pyx:1145
pyscipopt.scip.Model.infinity
def infinity(self)
Definition: scip.pyx:1141
SCIPincludeSepa
SCIP_RETCODE SCIPincludeSepa(SCIP *scip, const char *name, const char *desc, int priority, int freq, SCIP_Real maxbounddist, SCIP_Bool usessubscip, SCIP_Bool delay, SCIP_DECL_SEPACOPY((*sepacopy)), SCIP_DECL_SEPAFREE((*sepafree)), SCIP_DECL_SEPAINIT((*sepainit)), SCIP_DECL_SEPAEXIT((*sepaexit)), SCIP_DECL_SEPAINITSOL((*sepainitsol)), SCIP_DECL_SEPAEXITSOL((*sepaexitsol)), SCIP_DECL_SEPAEXECLP((*sepaexeclp)), SCIP_DECL_SEPAEXECSOL((*sepaexecsol)), SCIP_SEPADATA *sepadata)
SCIPdelCons
SCIP_RETCODE SCIPdelCons(SCIP *scip, SCIP_CONS *cons)
pyscipopt.scip.Row.getOrigintype
def getOrigintype(self)
Definition: scip.pyx:449
pyscipopt.scip.Model.getNChildren
def getNChildren(self)
Definition: scip.pyx:1121
SCIPchgVarObjProbing
SCIP_RETCODE SCIPchgVarObjProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
pyscipopt.scip.Model.getVars
def getVars(self, transformed=False)
Definition: scip.pyx:1677
pyscipopt.scip.Model.updateBendersLowerbounds
def updateBendersLowerbounds(self, lowerbounds, Benders, benders=None)
Definition: scip.pyx:3326
SCIPcheckSol
SCIP_RETCODE SCIPcheckSol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *feasible)
pyscipopt.scip.Model.readParams
def readParams(self, file)
Definition: scip.pyx:4836
pyscipopt.scip.Model.getVarLbDive
def getVarLbDive(self, Variable, var)
Definition: scip.pyx:4047
SCIPgetLocalOrigEstimate
SCIP_Real SCIPgetLocalOrigEstimate(SCIP *scip)
pyscipopt.scip.Row.getNorm
def getNorm(self)
Definition: scip.pyx:476
SCIPgetDualSolVal
SCIP_RETCODE SCIPgetDualSolVal(SCIP *scip, SCIP_CONS *cons, SCIP_Real *dualsolval, SCIP_Bool *boundconstraint)
pyscipopt.scip.Model.getCutLPSolCutoffDistance
def getCutLPSolCutoffDistance(self, Row, cut, not, None, Solution, sol, not, None)
Definition: scip.pyx:1964
SCIPbranchVarVal
SCIP_RETCODE SCIPbranchVarVal(SCIP *scip, SCIP_VAR *var, SCIP_Real val, SCIP_NODE **downchild, SCIP_NODE **eqchild, SCIP_NODE **upchild)
pyscipopt.scip.Constraint.isEnforced
def isEnforced(self)
Definition: scip.pyx:873
pyscipopt.scip.Model.printNlRow
def printNlRow(self, NLRow, nlrow)
Definition: scip.pyx:3009
pyscipopt.scip.Event.__repr__
def __repr__(self)
Definition: scip.pyx:288
pyscipopt.scip.Model.catchRowEvent
def catchRowEvent(self, Row, row, eventtype, Eventhdlr, eventhdlr)
Definition: scip.pyx:4623
pyscipopt.scip.Node.getEstimate
def getEstimate(self)
Definition: scip.pyx:668
pyscipopt.scip.Event.event
event
Definition: scip.pyx:280
SCIPsetMessagehdlrLogfile
void SCIPsetMessagehdlrLogfile(SCIP *scip, const char *filename)
pyscipopt.scip.Model.getNLPIterations
def getNLPIterations(self)
Definition: scip.pyx:1097
SCIPeventGetVar
SCIP_VAR * SCIPeventGetVar(SCIP_EVENT *event)
pyscipopt.scip.Model.getLPRowsData
def getLPRowsData(self)
Definition: scip.pyx:1812
SCIPincludeEventhdlr
SCIP_RETCODE SCIPincludeEventhdlr(SCIP *scip, const char *name, const char *desc, SCIP_DECL_EVENTCOPY((*eventcopy)), SCIP_DECL_EVENTFREE((*eventfree)), SCIP_DECL_EVENTINIT((*eventinit)), SCIP_DECL_EVENTEXIT((*eventexit)), SCIP_DECL_EVENTINITSOL((*eventinitsol)), SCIP_DECL_EVENTEXITSOL((*eventexitsol)), SCIP_DECL_EVENTDELETE((*eventdelete)), SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
pyscipopt.scip.Model.getSols
def getSols(self)
Definition: scip.pyx:4441
pyscipopt.scip.Model.setStringParam
def setStringParam(self, name, value)
Definition: scip.pyx:4745
pyscipopt.scip.Node.getParent
def getParent(self)
Definition: scip.pyx:648
pyscipopt.scip.Row.isRemovable
def isRemovable(self)
Definition: scip.pyx:441
pyscipopt.scip.Variable.getLbOriginal
def getLbOriginal(self)
Definition: scip.pyx:810
pyscipopt.scip.Column.scip_col
scip_col
Definition: scip.pyx:329
pyscipopt.scip.Model.appendVarSOS2
def appendVarSOS2(self, Constraint, cons, Variable, var)
Definition: scip.pyx:2771
SCIPgetActivityLinear
SCIP_Real SCIPgetActivityLinear(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol)
pyscipopt.scip.Node.__hash__
def __hash__(self)
Definition: scip.pyx:748
SCIPprintRow
SCIP_RETCODE SCIPprintRow(SCIP *scip, SCIP_ROW *row, FILE *file)
SCIPboundchgIsRedundant
SCIP_Bool SCIPboundchgIsRedundant(SCIP_BOUNDCHG *boundchg)
SCIPinfinity
SCIP_Real SCIPinfinity(SCIP *scip)
pyscipopt.scip.Model.addConsXor
def addConsXor(self, vars, rhsvar, name="XORcons", initial=True, separate=True, enforce=True, check=True, propagate=True, local=False, modifiable=False, dynamic=False, removable=False, stickingatnode=False)
Definition: scip.pyx:2570
pyscipopt.scip.Model.from_ptr
def from_ptr(capsule, take_ownership)
Definition: scip.pyx:1021
pyscipopt.scip.Model.includeDefaultPlugins
def includeDefaultPlugins(self)
Definition: scip.pyx:1048
SCIPgetLPObjval
SCIP_Real SCIPgetLPObjval(SCIP *scip)
SCIPsetEmphasis
SCIP_RETCODE SCIPsetEmphasis(SCIP *scip, SCIP_PARAMEMPHASIS paramemphasis, SCIP_Bool quiet)
SCIPgetNOrigVars
int SCIPgetNOrigVars(SCIP *scip)
pyscipopt.scip.Column.getObjCoeff
def getObjCoeff(self)
Definition: scip.pyx:371
pyscipopt.scip.Model.freeTransform
def freeTransform(self)
Definition: scip.pyx:1065
SCIPprintVersion
void SCIPprintVersion(SCIP *scip, FILE *file)
pyscipopt.scip.Model.freeSol
def freeSol(self, Solution, solution)
Definition: scip.pyx:4414
SCIPaddPoolCut
SCIP_RETCODE SCIPaddPoolCut(SCIP *scip, SCIP_ROW *row)
SCIPgetParams
SCIP_PARAM ** SCIPgetParams(SCIP *scip)
SCIPendDive
SCIP_RETCODE SCIPendDive(SCIP *scip)
pyscipopt.scip.Column.__eq__
def __eq__(self, other)
Definition: scip.pyx:378
SCIPsetObjIntegral
SCIP_RETCODE SCIPsetObjIntegral(SCIP *scip)
pyscipopt.scip.Variable.__get__
def __get__(self)
Definition: scip.pyx:768
pyscipopt.scip.Model.getObjlimit
def getObjlimit(self)
Definition: scip.pyx:1252
pyscipopt.scip.DomainChanges.getBoundchgs
def getBoundchgs(self)
Definition: scip.pyx:631
pyscipopt.scip.Model.getParam
def getParam(self, name)
Definition: scip.pyx:4787
SCIPgetNTotalNodes
SCIP_Longint SCIPgetNTotalNodes(SCIP *scip)
SCIPvarGetLbOriginal
SCIP_Real SCIPvarGetLbOriginal(SCIP_VAR *var)
SCIPcreateConsAnd
SCIP_RETCODE SCIPcreateConsAnd(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *resvar, int nvars, SCIP_VAR **vars, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
pyscipopt.scip.Model.setCheck
def setCheck(self, Constraint, cons, newCheck)
Definition: scip.pyx:2807
pyscipopt.scip.Model.getNIntVars
def getNIntVars(self)
Definition: scip.pyx:1718
pyscipopt.scip.Model.setRemovable
def setRemovable(self, Constraint, cons, newRem)
Definition: scip.pyx:2789
pyscipopt.scip.str_conversion
str_conversion
Definition: scip.pyx:46
SCIPprintBestTransSol
SCIP_RETCODE SCIPprintBestTransSol(SCIP *scip, FILE *file, SCIP_Bool printzeros)
SCIPcount
SCIP_RETCODE SCIPcount(SCIP *scip)
SCIPboundchgGetVar
SCIP_VAR * SCIPboundchgGetVar(SCIP_BOUNDCHG *boundchg)
SCIPresetParams
SCIP_RETCODE SCIPresetParams(SCIP *scip)
SCIPconsIsRemovable
SCIP_Bool SCIPconsIsRemovable(SCIP_CONS *cons)
pyscipopt.scip.Model.getTransformedCons
def getTransformedCons(self, Constraint, cons)
Definition: scip.pyx:2950
pyscipopt.scip.Model.getPresolvingTime
def getPresolvingTime(self)
Definition: scip.pyx:1093
SCIPpresolve
SCIP_RETCODE SCIPpresolve(SCIP *scip)
SCIPgetNConss
int SCIPgetNConss(SCIP *scip)
pyscipopt.scip.Model.getNlRows
def getNlRows(self)
Definition: scip.pyx:2968
pyscipopt.scip.Model.writeName
def writeName(self, Variable, var)
Definition: scip.pyx:4527
SCIPgetRowLinear
SCIP_ROW * SCIPgetRowLinear(SCIP *scip, SCIP_CONS *cons)
pyscipopt.scip.Model.writeParams
def writeParams(self, filename='param.set', comments=True, onlychanged=True)
Definition: scip.pyx:4845
SCIPcreateCons
SCIP_RETCODE SCIPcreateCons(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_CONSHDLR *conshdlr, SCIP_CONSDATA *consdata, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
SCIProwGetBasisStatus
SCIP_BASESTAT SCIProwGetBasisStatus(SCIP_ROW *row)
SCIProwGetNLPNonz
int SCIProwGetNLPNonz(SCIP_ROW *row)
SCIProwGetOriginCons
SCIP_CONS * SCIProwGetOriginCons(SCIP_ROW *row)
SCIPprintTransSol
SCIP_RETCODE SCIPprintTransSol(SCIP *scip, SCIP_SOL *sol, FILE *file, SCIP_Bool printzeros)
pyscipopt.scip.Model.addConsAnd
def addConsAnd(self, vars, resvar, name="ANDcons", initial=True, separate=True, enforce=True, check=True, propagate=True, local=False, modifiable=False, dynamic=False, removable=False, stickingatnode=False)
Definition: scip.pyx:2492
SCIProwGetRhs
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
pyscipopt.scip.Node.getDepth
def getDepth(self)
Definition: scip.pyx:656
pyscipopt.scip.Model.includeProp
def includeProp(self, Prop, prop, name, desc, presolpriority, presolmaxrounds, proptiming, presoltiming=SCIP_PRESOLTIMING_FAST, priority=1, freq=1, delay=True)
Definition: scip.pyx:3705
pyscipopt.scip.Model.presolve
def presolve(self)
Definition: scip.pyx:3240
SCIPvarSetData
void SCIPvarSetData(SCIP_VAR *var, SCIP_VARDATA *vardata)
SCIPfreeBendersSubproblem
SCIP_RETCODE SCIPfreeBendersSubproblem(SCIP *scip, SCIP_BENDERS *benders, int probnumber)
SCIPsetObjsense
SCIP_RETCODE SCIPsetObjsense(SCIP *scip, SCIP_OBJSENSE objsense)
SCIPcreateConsIndicator
SCIP_RETCODE SCIPcreateConsIndicator(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *binvar, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
SCIPcreateBendersDefault
SCIP_RETCODE SCIPcreateBendersDefault(SCIP *scip, SCIP **subproblems, int nsubproblems)
SCIPcreateEmptyRowSepa
SCIP_RETCODE SCIPcreateEmptyRowSepa(SCIP *scip, SCIP_ROW **row, SCIP_SEPA *sepa, const char *name, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool removable)
SCIPgetNLPCols
int SCIPgetNLPCols(SCIP *scip)
SCIPboundchgGetBoundtype
SCIP_BOUNDTYPE SCIPboundchgGetBoundtype(SCIP_BOUNDCHG *boundchg)
pyscipopt.scip.Model.getBestLeaf
def getBestLeaf(self)
Definition: scip.pyx:1745
SCIPcatchVarEvent
SCIP_RETCODE SCIPcatchVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
pyscipopt.scip.Model.addSol
def addSol(self, Solution, solution, free=True)
Definition: scip.pyx:4400
SCIPaddVarSOS2
SCIP_RETCODE SCIPaddVarSOS2(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real weight)
pyscipopt.scip.Model.isNLPConstructed
def isNLPConstructed(self)
Definition: scip.pyx:2960
pyscipopt.scip.Model.getNlRowSolActivity
def getNlRowSolActivity(self, NLRow, nlrow, Solution, sol=None)
Definition: scip.pyx:2975
SCIPvarGetLbGlobal
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
SCIPincludeNodesel
SCIP_RETCODE SCIPincludeNodesel(SCIP *scip, const char *name, const char *desc, int stdpriority, int memsavepriority, SCIP_DECL_NODESELCOPY((*nodeselcopy)), SCIP_DECL_NODESELFREE((*nodeselfree)), SCIP_DECL_NODESELINIT((*nodeselinit)), SCIP_DECL_NODESELEXIT((*nodeselexit)), SCIP_DECL_NODESELINITSOL((*nodeselinitsol)), SCIP_DECL_NODESELEXITSOL((*nodeselexitsol)), SCIP_DECL_NODESELSELECT((*nodeselselect)), SCIP_DECL_NODESELCOMP((*nodeselcomp)), SCIP_NODESELDATA *nodeseldata)
SCIPgetNlRowSolFeasibility
SCIP_RETCODE SCIPgetNlRowSolFeasibility(SCIP *scip, SCIP_NLROW *nlrow, SCIP_SOL *sol, SCIP_Real *feasibility)
pyscipopt.scip.Node.__class__
__class__
Definition: scip.pyx:752
pyscipopt.scip.Model.getTotalTime
def getTotalTime(self)
Definition: scip.pyx:1081
pyscipopt.scip.Column.getLPPos
def getLPPos(self)
Definition: scip.pyx:332
pyscipopt.scip.Model.getOpenNodes
def getOpenNodes(self)
Definition: scip.pyx:1757
SCIPgetNChildren
int SCIPgetNChildren(SCIP *scip)
SCIPgetNParams
int SCIPgetNParams(SCIP *scip)
SCIPgetSolOrigObj
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
pyscipopt.scip.Model.setEnforced
def setEnforced(self, Constraint, cons, newEnf)
Definition: scip.pyx:2798
pyscipopt.scip.Model.getCutEfficacy
def getCutEfficacy(self, Row, cut, not, None, Solution, sol=None)
Definition: scip.pyx:1956
pyscipopt.scip.Event.__eq__
def __eq__(self, other)
Definition: scip.pyx:317
pyscipopt.scip.Model.includeBenders
def includeBenders(self, Benders, benders, name, desc, priority=1, cutlp=True, cutpseudo=True, cutrelax=True, shareaux=False)
Definition: scip.pyx:3840
pyscipopt.scip.Model.printRow
def printRow(self, Row, row, not, None)
Definition: scip.pyx:1930
SCIPvarGetName
const char * SCIPvarGetName(SCIP_VAR *var)
pyscipopt.scip.Model.setLogfile
def setLogfile(self, path)
Definition: scip.pyx:4686
pyscipopt.scip.Constraint.__repr__
def __repr__(self)
Definition: scip.pyx:858
pyscipopt.scip.Variable.getCol
def getCol(self)
Definition: scip.pyx:804
SCIPchgRhsLinear
SCIP_RETCODE SCIPchgRhsLinear(SCIP *scip, SCIP_CONS *cons, SCIP_Real rhs)
pyscipopt.scip.Model.frac
def frac(self, value)
Definition: scip.pyx:1157
SCIPbendersSubproblem
SCIP * SCIPbendersSubproblem(SCIP_BENDERS *benders, int probnumber)
pyscipopt.scip.Constraint.isActive
def isActive(self)
Definition: scip.pyx:905
pyscipopt.scip.Model.getBendersSubproblem
def getBendersSubproblem(self, probnumber, Benders, benders=None)
Definition: scip.pyx:3431
SCIPwriteVarName
SCIP_RETCODE SCIPwriteVarName(SCIP *scip, FILE *file, SCIP_VAR *var, SCIP_Bool type)
SCIPdelConsLocal
SCIP_RETCODE SCIPdelConsLocal(SCIP *scip, SCIP_CONS *cons)
SCIPcreate
SCIP_RETCODE SCIPcreate(SCIP **scip)
pyscipopt.scip.Row.scip_row
scip_row
Definition: scip.pyx:390
pyscipopt.scip.Constraint.isLinear
def isLinear(self)
Definition: scip.pyx:909
SCIProwIsInGlobalCutpool
SCIP_Bool SCIProwIsInGlobalCutpool(SCIP_ROW *row)
pyscipopt.scip.NLRow.__eq__
def __eq__(self, other)
Definition: scip.pyx:529
SCIProwIsLocal
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
pyscipopt.scip.Model.createSol
def createSol(self, Heur, heur=None)
Definition: scip.pyx:4211
pyscipopt.scip.Model.getBestSol
def getBestSol(self)
Definition: scip.pyx:4454
pyscipopt.scip.Model.addVarSOS1
def addVarSOS1(self, Constraint, cons, Variable, var, weight)
Definition: scip.pyx:2742
pyscipopt.scip.Model.getNBestSolsFound
def getNBestSolsFound(self)
Definition: scip.pyx:4437
pyscipopt.scip.Variable.getLbGlobal
def getLbGlobal(self)
Definition: scip.pyx:818
pyscipopt.scip.Model.setRealParam
def setRealParam(self, name, value)
Definition: scip.pyx:4725
pyscipopt.scip.Variable.ptr
def ptr(self)
Definition: scip.pyx:772
pyscipopt.scip.Model.setupBendersSubproblem
def setupBendersSubproblem(self, probnumber, Benders, benders=None, Solution, solution=None, checktype=PY_SCIP_BENDERSENFOTYPE.LP)
Definition: scip.pyx:3373
SCIPapplyCutsProbing
SCIP_RETCODE SCIPapplyCutsProbing(SCIP *scip, SCIP_Bool *cutoff)
pyscipopt.scip.Model.addVar
def addVar(self, name='', vtype='C', lb=0.0, ub=None, obj=0.0, pricedVar=False, pricedVarScore=1.0)
Definition: scip.pyx:1418
pyscipopt.scip.Variable.isOriginal
def isOriginal(self)
Definition: scip.pyx:791
SCIPgetLPColsData
SCIP_RETCODE SCIPgetLPColsData(SCIP *scip, SCIP_COL ***cols, int *ncols)
pyscipopt.scip.Model.trySol
def trySol(self, Solution, solution, printreason=True, completely=False, checkbounds=True, checkintegrality=True, checklprows=True, free=True)
Definition: scip.pyx:4362
SCIPsetMessagehdlr
SCIP_RETCODE SCIPsetMessagehdlr(SCIP *scip, SCIP_MESSAGEHDLR *messagehdlr)
pyscipopt.scip.Model.getDualSolVal
def getDualSolVal(self, Constraint, cons, boundconstraint=False)
Definition: scip.pyx:3207
SCIPfindPricer
SCIP_PRICER * SCIPfindPricer(SCIP *scip, const char *name)
SCIPgetVarRedcost
SCIP_Real SCIPgetVarRedcost(SCIP *scip, SCIP_VAR *var)
pyscipopt.scip.Model.catchVarEvent
def catchVarEvent(self, Variable, var, eventtype, Eventhdlr, eventhdlr)
Definition: scip.pyx:4603
SCIPeventGetOldbound
SCIP_Real SCIPeventGetOldbound(SCIP_EVENT *event)
SCIPcreateExprLog
SCIP_RETCODE SCIPcreateExprLog(SCIP *scip, SCIP_EXPR **expr, SCIP_EXPR *child, SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), void *ownercreatedata)
pyscipopt.scip.Variable.scip_var
scip_var
Definition: scip.pyx:763
pyscipopt.scip.NLRow.getLhs
def getLhs(self)
Definition: scip.pyx:514
pyscipopt.scip.Model.enableReoptimization
def enableReoptimization(self, enable=True)
Definition: scip.pyx:1221
SCIPcreateExprMonomial
SCIP_RETCODE SCIPcreateExprMonomial(SCIP *scip, SCIP_EXPR **expr, int nfactors, SCIP_VAR **vars, SCIP_Real *exponents, SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), void *ownercreatedata)
SCIPcacheRowExtensions
SCIP_RETCODE SCIPcacheRowExtensions(SCIP *scip, SCIP_ROW *row)
pyscipopt.scip.Model.createEmptyRowUnspec
def createEmptyRowUnspec(self, name="row", lhs=0.0, rhs=None, local=True, modifiable=False, removable=True)
Definition: scip.pyx:1885
SCIPgetRowLPActivity
SCIP_Real SCIPgetRowLPActivity(SCIP *scip, SCIP_ROW *row)
pyscipopt.scip.Constraint.__hash__
def __hash__(self)
Definition: scip.pyx:919
pyscipopt.scip.Model._addNonlinearCons
def _addNonlinearCons(self, ExprCons, cons, **kwargs)
Definition: scip.pyx:2199
SCIPgetRhsNonlinear
SCIP_Real SCIPgetRhsNonlinear(SCIP_CONS *cons)
pyscipopt.scip.Constraint.isOriginal
def isOriginal(self)
Definition: scip.pyx:861
pyscipopt.scip.Model.getObjective
def getObjective(self)
Definition: scip.pyx:1300
SCIPbendersGetNSubproblems
int SCIPbendersGetNSubproblems(SCIP_BENDERS *benders)
SCIPcreateSol
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
pyscipopt.scip.Constraint.isInitial
def isInitial(self)
Definition: scip.pyx:865
SCIPgetBestboundNode
SCIP_NODE * SCIPgetBestboundNode(SCIP *scip)
pyscipopt.scip.Model.getReadingTime
def getReadingTime(self)
Definition: scip.pyx:1089
pyscipopt.scip.Model.endDive
def endDive(self)
Definition: scip.pyx:4031
pyscipopt.scip.Model.addPyCons
def addPyCons(self, Constraint, cons)
Definition: scip.pyx:2733
pyscipopt.scip.Model.branchVar
def branchVar(self, variable)
Definition: scip.pyx:3953
SCIPgetNSiblings
int SCIPgetNSiblings(SCIP *scip)
pyscipopt.scip.Model.calcChildEstimate
def calcChildEstimate(self, Variable, variable, targetvalue)
Definition: scip.pyx:3999
pyscipopt.scip.Row.isInGlobalCutpool
def isInGlobalCutpool(self)
Definition: scip.pyx:445
SCIPchgVarBranchPriority
SCIP_RETCODE SCIPchgVarBranchPriority(SCIP *scip, SCIP_VAR *var, int branchpriority)
pyscipopt.scip.BoundChange.getBoundtype
def getBoundtype(self)
Definition: scip.pyx:607
SCIPgetLPBasisInd
SCIP_RETCODE SCIPgetLPBasisInd(SCIP *scip, int *basisind)
pyscipopt.scip.Model.endProbing
def endProbing(self)
Definition: scip.pyx:4096
pyscipopt.scip.Model.getNVars
def getNVars(self)
Definition: scip.pyx:1710
SCIPvarGetObj
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
SCIPactivatePricer
SCIP_RETCODE SCIPactivatePricer(SCIP *scip, SCIP_PRICER *pricer)
SCIPgetBestSibling
SCIP_NODE * SCIPgetBestSibling(SCIP *scip)
pyscipopt.scip.Model.setInitial
def setInitial(self, Constraint, cons, newInit)
Definition: scip.pyx:2780
pyscipopt.scip.Model.resetParam
def resetParam(self, name)
Definition: scip.pyx:4858
pyscipopt.scip.Column
Definition: scip.pyx:321
pyscipopt.scip.Node.getNAddedConss
def getNAddedConss(self)
Definition: scip.pyx:685
SCIPgetNSepaRounds
int SCIPgetNSepaRounds(SCIP *scip)
pyscipopt.scip.Model.chgVarLb
def chgVarLb(self, Variable, var, lb)
Definition: scip.pyx:1589
pyscipopt.scip.Variable.__repr__
def __repr__(self)
Definition: scip.pyx:776
pyscipopt.scip.Model._modelvars
_modelvars
Definition: scip.pyx:959
pyscipopt.scip.Model.getNSepaRounds
def getNSepaRounds(self)
Definition: scip.pyx:1982
pyscipopt.scip.Node.getDomchg
def getDomchg(self)
Definition: scip.pyx:741
pyscipopt.scip.Model.resetParams
def resetParams(self)
Definition: scip.pyx:4867
SCIPgetRhsLinear
SCIP_Real SCIPgetRhsLinear(SCIP *scip, SCIP_CONS *cons)
pyscipopt.scip.Node
Definition: scip.pyx:637
pyscipopt.scip.Node.getNParentBranchings
def getNParentBranchings(self)
Definition: scip.pyx:697
pyscipopt.scip.Model.chgVarObjProbing
def chgVarObjProbing(self, Variable, var, newobj)
Definition: scip.pyx:4116
SCIProwGetName
const char * SCIProwGetName(SCIP_ROW *row)
pyscipopt.scip.Model.getRowObjParallelism
def getRowObjParallelism(self, Row, row)
Definition: scip.pyx:1938
SCIPfindConshdlr
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
pyscipopt.scip.Constraint.__class__
__class__
Definition: scip.pyx:923
SCIPlpiGetRealSolQuality
SCIP_RETCODE SCIPlpiGetRealSolQuality(SCIP_LPI *lpi, SCIP_LPSOLQUALITY qualityindicator, SCIP_Real *quality)
SCIPstartProbing
SCIP_RETCODE SCIPstartProbing(SCIP *scip)
pyscipopt.scip.Model.includeCutsel
def includeCutsel(self, Cutsel, cutsel, name, desc, priority)
Definition: scip.pyx:3781
pyscipopt.scip.DomainChanges
Definition: scip.pyx:620
pyscipopt.scip.Model.tightenVarLb
def tightenVarLb(self, Variable, var, lb, force=False)
Definition: scip.pyx:1523
pyscipopt.scip.Model.isFeasNegative
def isFeasNegative(self, value)
Definition: scip.pyx:1173
SCIPgetParam
SCIP_PARAM * SCIPgetParam(SCIP *scip, const char *name)
pyscipopt.scip.Model.calcNodeselPriority
def calcNodeselPriority(self, Variable, variable, branchdir, targetvalue)
Definition: scip.pyx:3986
SCIPgetSolTransObj
SCIP_Real SCIPgetSolTransObj(SCIP *scip, SCIP_SOL *sol)
SCIPcatchRowEvent
SCIP_RETCODE SCIPcatchRowEvent(SCIP *scip, SCIP_ROW *row, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
SCIPisCutEfficacious
SCIP_Bool SCIPisCutEfficacious(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
SCIPincludeBenders
SCIP_RETCODE SCIPincludeBenders(SCIP *scip, const char *name, const char *desc, int priority, SCIP_Bool cutlp, SCIP_Bool cutpseudo, SCIP_Bool cutrelax, SCIP_Bool shareauxvars, SCIP_DECL_BENDERSCOPY((*benderscopy)), SCIP_DECL_BENDERSFREE((*bendersfree)), SCIP_DECL_BENDERSINIT((*bendersinit)), SCIP_DECL_BENDERSEXIT((*bendersexit)), SCIP_DECL_BENDERSINITPRE((*bendersinitpre)), SCIP_DECL_BENDERSEXITPRE((*bendersexitpre)), SCIP_DECL_BENDERSINITSOL((*bendersinitsol)), SCIP_DECL_BENDERSEXITSOL((*bendersexitsol)), SCIP_DECL_BENDERSGETVAR((*bendersgetvar)), SCIP_DECL_BENDERSCREATESUB((*benderscreatesub)), SCIP_DECL_BENDERSPRESUBSOLVE((*benderspresubsolve)), SCIP_DECL_BENDERSSOLVESUBCONVEX((*benderssolvesubconvex)), SCIP_DECL_BENDERSSOLVESUB((*benderssolvesub)), SCIP_DECL_BENDERSPOSTSOLVE((*benderspostsolve)), SCIP_DECL_BENDERSFREESUB((*bendersfreesub)), SCIP_BENDERSDATA *bendersdata)
pyscipopt.scip.Row.getNNonz
def getNNonz(self)
Definition: scip.pyx:458
SCIPsetPresolving
SCIP_RETCODE SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
SCIPsetBoolParam
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
SCIPtrySolFree
SCIP_RETCODE SCIPtrySolFree(SCIP *scip, SCIP_SOL **sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
pyscipopt.scip.Model.getNConss
def getNConss(self)
Definition: scip.pyx:1714
SCIPconsIsDynamic
SCIP_Bool SCIPconsIsDynamic(SCIP_CONS *cons)
pyscipopt.scip.Model.flushRowExtensions
def flushRowExtensions(self, Row, row, not, None)
Definition: scip.pyx:1922
SCIPvarGetLbLocal
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
SCIPnodeGetEstimate
SCIP_Real SCIPnodeGetEstimate(SCIP_NODE *node)
pyscipopt.scip.Model.setParam
def setParam(self, name, value)
Definition: scip.pyx:4756
SCIPgetRowNumIntCols
int SCIPgetRowNumIntCols(SCIP *scip, SCIP_ROW *row)
pyscipopt.scip.BoundChange.getBoundchgtype
def getBoundchgtype(self)
Definition: scip.pyx:603
pyscipopt.scip.Model.chgVarUbGlobal
def chgVarUbGlobal(self, Variable, var, ub)
Definition: scip.pyx:1623
pyscipopt.scip.BoundChange.scip_boundchg
scip_boundchg
Definition: scip.pyx:592
SCIPisLPSolBasic
SCIP_Bool SCIPisLPSolBasic(SCIP *scip)
SCIPgetNCutsApplied
int SCIPgetNCutsApplied(SCIP *scip)
SCIPcheckQuadraticNonlinear
SCIP_RETCODE SCIPcheckQuadraticNonlinear(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *isquadratic)
SCIPbendersGetAuxiliaryVar
SCIP_VAR * SCIPbendersGetAuxiliaryVar(SCIP_BENDERS *benders, int probnumber)
pyscipopt.scip.Model._addLinCons
def _addLinCons(self, ExprCons, lincons, **kwargs)
Definition: scip.pyx:2125
pyscipopt.scip.Model.feasFrac
def feasFrac(self, value)
Definition: scip.pyx:1153
SCIPbendersSetSubproblemIsConvex
void SCIPbendersSetSubproblemIsConvex(SCIP_BENDERS *benders, int probnumber, SCIP_Bool isconvex)
SCIPconsIsInitial
SCIP_Bool SCIPconsIsInitial(SCIP_CONS *cons)
SCIPtightenVarLb
SCIP_RETCODE SCIPtightenVarLb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
SCIPgetLPBInvARow
SCIP_RETCODE SCIPgetLPBInvARow(SCIP *scip, int r, SCIP_Real *binvrow, SCIP_Real *coefs, int *inds, int *ninds)
pyscipopt.scip.Constraint.isChecked
def isChecked(self)
Definition: scip.pyx:877
SCIPnodeGetNumber
SCIP_Longint SCIPnodeGetNumber(SCIP_NODE *node)
pyscipopt.scip.Model.getBendersVar
def getBendersVar(self, Variable, var, Benders, benders=None, probnumber=-1)
Definition: scip.pyx:3451
pyscipopt.scip.Solution.sol
sol
Definition: scip.pyx:540
pyscipopt.scip.Model.getBestboundNode
def getBestboundNode(self)
Definition: scip.pyx:1753
pyscipopt.scip.Row.getConsOriginConshdlrtype
def getConsOriginConshdlrtype(self)
Definition: scip.pyx:453
SCIPgetNBestSolsFound
SCIP_Longint SCIPgetNBestSolsFound(SCIP *scip)
pyscipopt.scip.Model.getNLPRows
def getNLPRows(self)
Definition: scip.pyx:1820
pyscipopt.scip.Model.interruptSolve
def interruptSolve(self)
Definition: scip.pyx:4194
pyscipopt.scip.Model.setBoolParam
def setBoolParam(self, name, value)
Definition: scip.pyx:4695
SCIPstartDive
SCIP_RETCODE SCIPstartDive(SCIP *scip)
SCIPtightenVarUb
SCIP_RETCODE SCIPtightenVarUb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
SCIPnodeGetLowerbound
SCIP_Real SCIPnodeGetLowerbound(SCIP_NODE *node)
pyscipopt.scip.Model.getNLimSolsFound
def getNLimSolsFound(self)
Definition: scip.pyx:4433
pyscipopt.scip.Model.chgRowLhsDive
def chgRowLhsDive(self, Row, row, newlhs)
Definition: scip.pyx:4055
pyscipopt.scip.Model.hideOutput
def hideOutput(self, quiet=True)
Definition: scip.pyx:4667
SCIPaddVarToRow
SCIP_RETCODE SCIPaddVarToRow(SCIP *scip, SCIP_ROW *row, SCIP_VAR *var, SCIP_Real val)
SCIPisInfinity
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
pyscipopt.scip.Model.getStage
def getStage(self)
Definition: scip.pyx:4535
SCIPcolGetUb
SCIP_Real SCIPcolGetUb(SCIP_COL *col)
SCIPgetProbingDepth
int SCIPgetProbingDepth(SCIP *scip)
SCIPisZero
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
pyscipopt.scip.Model.constructLP
def constructLP(self)
Definition: scip.pyx:1788
pyscipopt.scip.Model.createEmptyRowSepa
def createEmptyRowSepa(self, Sepa, sepa, name="row", lhs=0.0, rhs=None, local=True, modifiable=False, removable=True)
Definition: scip.pyx:1866
SCIPexprGetQuadraticQuadTerm
void SCIPexprGetQuadraticQuadTerm(SCIP_EXPR *quadexpr, int termidx, SCIP_EXPR **expr, SCIP_Real *lincoef, SCIP_Real *sqrcoef, int *nadjbilin, int **adjbilin, SCIP_EXPR **sqrexpr)
SCIPgetLPRowsData
SCIP_RETCODE SCIPgetLPRowsData(SCIP *scip, SCIP_ROW ***rows, int *nrows)
SCIProwGetCols
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
pyscipopt.scip.NLRow.scip_nlrow
scip_nlrow
Definition: scip.pyx:495
pyscipopt.scip.Model.getNBinVars
def getNBinVars(self)
Definition: scip.pyx:1722
pyscipopt.scip.Model.getPrimalbound
def getPrimalbound(self)
Definition: scip.pyx:4515
SCIPgetTotalTime
SCIP_Real SCIPgetTotalTime(SCIP *scip)
SCIPsetConsEnforced
SCIP_RETCODE SCIPsetConsEnforced(SCIP *scip, SCIP_CONS *cons, SCIP_Bool enforce)
pyscipopt.scip.Model.restartSolve
def restartSolve(self)
Definition: scip.pyx:4198
pyscipopt.scip.BoundChange.getVar
def getVar(self)
Definition: scip.pyx:599
SCIPgetNCountedSols
SCIP_Longint SCIPgetNCountedSols(SCIP *scip, SCIP_Bool *valid)
SCIPgetObjlimit
SCIP_Real SCIPgetObjlimit(SCIP *scip)
SCIPbranchVar
SCIP_RETCODE SCIPbranchVar(SCIP *scip, SCIP_VAR *var, SCIP_NODE **downchild, SCIP_NODE **eqchild, SCIP_NODE **upchild)
SCIPboundchgGetNewbound
SCIP_Real SCIPboundchgGetNewbound(SCIP_BOUNDCHG *boundchg)
SCIPpropagateProbing
SCIP_RETCODE SCIPpropagateProbing(SCIP *scip, int maxproprounds, SCIP_Bool *cutoff, SCIP_Longint *ndomredsfound)
SCIPcreateChild
SCIP_RETCODE SCIPcreateChild(SCIP *scip, SCIP_NODE **node, SCIP_Real nodeselprio, SCIP_Real estimate)
pyscipopt.scip.Model.freeProb
def freeProb(self)
Definition: scip.pyx:1061
SCIPcreateProbBasic
SCIP_RETCODE SCIPcreateProbBasic(SCIP *scip, const char *name)
SCIPisGT
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIPincludeBranchrule
SCIP_RETCODE SCIPincludeBranchrule(SCIP *scip, const char *name, const char *desc, int priority, int maxdepth, SCIP_Real maxbounddist, SCIP_DECL_BRANCHCOPY((*branchcopy)), SCIP_DECL_BRANCHFREE((*branchfree)), SCIP_DECL_BRANCHINIT((*branchinit)), SCIP_DECL_BRANCHEXIT((*branchexit)), SCIP_DECL_BRANCHINITSOL((*branchinitsol)), SCIP_DECL_BRANCHEXITSOL((*branchexitsol)), SCIP_DECL_BRANCHEXECLP((*branchexeclp)), SCIP_DECL_BRANCHEXECEXT((*branchexecext)), SCIP_DECL_BRANCHEXECPS((*branchexecps)), SCIP_BRANCHRULEDATA *branchruledata)
SCIPprintNlRow
SCIP_RETCODE SCIPprintNlRow(SCIP *scip, SCIP_NLROW *nlrow, FILE *file)
pyscipopt.scip.Model.getValsLinear
def getValsLinear(self, Constraint, cons)
Definition: scip.pyx:3120
pyscipopt.scip.Variable.isInLP
def isInLP(self)
Definition: scip.pyx:795
SCIPisObjChangedProbing
SCIP_Bool SCIPisObjChangedProbing(SCIP *scip)
SCIPcopy
SCIP_RETCODE SCIPcopy(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *suffix, SCIP_Bool global, SCIP_Bool enablepricing, SCIP_Bool threadsafe, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
SCIPdomchgGetBoundchg
SCIP_BOUNDCHG * SCIPdomchgGetBoundchg(SCIP_DOMCHG *domchg, int pos)
pyscipopt.scip.Row.getLhs
def getLhs(self)
Definition: scip.pyx:398
SCIPaddVarIndicator
SCIP_RETCODE SCIPaddVarIndicator(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
SCIPtightenVarUbGlobal
SCIP_RETCODE SCIPtightenVarUbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
SCIPendProbing
SCIP_RETCODE SCIPendProbing(SCIP *scip)
pyscipopt.scip.Node.getType
def getType(self)
Definition: scip.pyx:660
SCIPcreateConsQuadraticNonlinear
SCIP_RETCODE SCIPcreateConsQuadraticNonlinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nlinvars, SCIP_VAR **linvars, SCIP_Real *lincoefs, int nquadterms, SCIP_VAR **quadvars1, SCIP_VAR **quadvars2, SCIP_Real *quadcoefs, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable)
pyscipopt.scip.Model.addVarSOS2
def addVarSOS2(self, Constraint, cons, Variable, var, weight)
Definition: scip.pyx:2761
SCIPupdateNodeLowerbound
SCIP_RETCODE SCIPupdateNodeLowerbound(SCIP *scip, SCIP_NODE *node, SCIP_Real newbound)
pyscipopt.scip.Model.getVarUbDive
def getVarUbDive(self, Variable, var)
Definition: scip.pyx:4051
SCIPtrySol
SCIP_RETCODE SCIPtrySol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
pyscipopt.scip.Model.addConsIndicator
def addConsIndicator(self, cons, binvar=None, activeone=True, name="IndicatorCons", initial=True, separate=True, enforce=True, check=True, propagate=True, local=False, dynamic=False, removable=False, stickingatnode=False)
Definition: scip.pyx:2660
SCIPcatchEvent
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
SCIPbendersUpdateSubproblemLowerbound
void SCIPbendersUpdateSubproblemLowerbound(SCIP_BENDERS *benders, int probnumber, SCIP_Real lowerbound)
SCIPgetLhsNonlinear
SCIP_Real SCIPgetLhsNonlinear(SCIP_CONS *cons)
SCIPcreateConsOr
SCIP_RETCODE SCIPcreateConsOr(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *resvar, int nvars, SCIP_VAR **vars, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
SCIPnlrowGetDualsol
SCIP_Real SCIPnlrowGetDualsol(SCIP_NLROW *nlrow)
SCIPchgVarLbGlobal
SCIP_RETCODE SCIPchgVarLbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
SCIPgetBestLeaf
SCIP_NODE * SCIPgetBestLeaf(SCIP *scip)
SCIPnlrowGetLinearVars
SCIP_VAR ** SCIPnlrowGetLinearVars(SCIP_NLROW *nlrow)
pyscipopt.scip.Model.getLPBInvARow
def getLPBInvARow(self, row)
Definition: scip.pyx:1849
pyscipopt.scip.Model.feastol
def feastol(self)
Definition: scip.pyx:1149
SCIPgetStage
SCIP_STAGE SCIPgetStage(SCIP *scip)
SCIPnodeGetParent
SCIP_NODE * SCIPnodeGetParent(SCIP_NODE *node)
SCIPdomchgGetNBoundchgs
int SCIPdomchgGetNBoundchgs(SCIP_DOMCHG *domchg)
SCIPsolve
SCIP_RETCODE SCIPsolve(SCIP *scip)
pyscipopt.scip.Model.addCons
def addCons(self, cons, name='', initial=True, separate=True, enforce=True, check=True, propagate=True, local=False, modifiable=False, dynamic=False, removable=False, stickingatnode=False)
Definition: scip.pyx:2011
pyscipopt.scip.Model.setParams
def setParams(self, params)
Definition: scip.pyx:4828
pyscipopt.scip.Model
Definition: scip.pyx:939
SCIPfindBenders
SCIP_BENDERS * SCIPfindBenders(SCIP *scip, const char *name)
pyscipopt.scip.Model.getLPSolstat
def getLPSolstat(self)
Definition: scip.pyx:1783
SCIPinterruptSolve
SCIP_RETCODE SCIPinterruptSolve(SCIP *scip)
pyscipopt.scip.Variable.vtype
def vtype(self)
Definition: scip.pyx:779
pyscipopt.scip.Model.writeBestTransSol
def writeBestTransSol(self, filename="transprob.sol", write_zeros=False)
Definition: scip.pyx:4275
SCIPchgRowRhsDive
SCIP_RETCODE SCIPchgRowRhsDive(SCIP *scip, SCIP_ROW *row, SCIP_Real newrhs)
SCIPaddVarCardinality
SCIP_RETCODE SCIPaddVarCardinality(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_VAR *indvar, SCIP_Real weight)
pyscipopt.scip.Column.getBasisStatus
def getBasisStatus(self)
Definition: scip.pyx:336
SCIPconsIsChecked
SCIP_Bool SCIPconsIsChecked(SCIP_CONS *cons)
SCIPgetLPBranchCands
SCIP_RETCODE SCIPgetLPBranchCands(SCIP *scip, SCIP_VAR ***lpcands, SCIP_Real **lpcandssol, SCIP_Real **lpcandsfrac, int *nlpcands, int *npriolpcands, int *nfracimplvars)
pyscipopt.scip.Model.isLE
def isLE(self, val1, val2)
Definition: scip.pyx:1189
SCIPaddBendersSubproblem
SCIP_RETCODE SCIPaddBendersSubproblem(SCIP *scip, SCIP_BENDERS *benders, SCIP *subproblem)
pyscipopt.scip.Event.getRow
def getRow(self)
Definition: scip.pyx:309
pyscipopt.scip.Model.getNInfeasibleLeaves
def getNInfeasibleLeaves(self)
Definition: scip.pyx:1113
SCIPcheckBendersSubproblemOptimality
SCIP_RETCODE SCIPcheckBendersSubproblemOptimality(SCIP *scip, SCIP_BENDERS *benders, SCIP_SOL *sol, int probnumber, SCIP_Bool *optimal)
pyscipopt.scip.Model.addConsSOS1
def addConsSOS1(self, vars, weights=None, name="SOS1cons", initial=True, separate=True, enforce=True, check=True, propagate=True, local=False, dynamic=False, removable=False, stickingatnode=False)
Definition: scip.pyx:2414
SCIPgetBestNode
SCIP_NODE * SCIPgetBestNode(SCIP *scip)
pyscipopt.scip.Model.inRepropagation
def inRepropagation(self)
Definition: scip.pyx:4085
SCIPgetNCuts
int SCIPgetNCuts(SCIP *scip)
SCIPreadSolFile
SCIP_RETCODE SCIPreadSolFile(SCIP *scip, const char *filename, SCIP_SOL *sol, SCIP_Bool xml, SCIP_Bool *partial, SCIP_Bool *error)
pyscipopt.scip.Event.getNewBound
def getNewBound(self)
Definition: scip.pyx:291
pyscipopt.scip.Model.getNSols
def getNSols(self)
Definition: scip.pyx:4422
pyscipopt.scip.Node.isActive
def isActive(self)
Definition: scip.pyx:689
SCIPcreateConsNonlinear
SCIP_RETCODE SCIPcreateConsNonlinear(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_EXPR *expr, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable)
SCIPsetConsChecked
SCIP_RETCODE SCIPsetConsChecked(SCIP *scip, SCIP_CONS *cons, SCIP_Bool check)
pyscipopt.scip.Model.getNNodes
def getNNodes(self)
Definition: scip.pyx:1101
pyscipopt.scip.Constraint.__get__
def __get__(self)
Definition: scip.pyx:854
pyscipopt.scip.Model.getLPBasisInd
def getLPBasisInd(self)
Definition: scip.pyx:1828
SCIPreadParams
SCIP_RETCODE SCIPreadParams(SCIP *scip, const char *filename)
pyscipopt.scip.Model.getNlRowActivityBounds
def getNlRowActivityBounds(self, NLRow, nlrow)
Definition: scip.pyx:3001
pyscipopt.scip.Variable.getUbOriginal
def getUbOriginal(self)
Definition: scip.pyx:814
pyscipopt.scip.Model.getRowLPActivity
def getRowLPActivity(self, Row, row)
Definition: scip.pyx:1906
SCIPsetSolVal
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
SCIPnodeGetNDomchg
void SCIPnodeGetNDomchg(SCIP_NODE *node, int *nbranchings, int *nconsprop, int *nprop)
SCIPgetNLPNlRows
SCIP_NLROW ** SCIPgetNLPNlRows(SCIP *scip)
SCIPchgVarUbProbing
SCIP_RETCODE SCIPchgVarUbProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
SCIPgetOpenNodesData
SCIP_RETCODE SCIPgetOpenNodesData(SCIP *scip, SCIP_NODE ***leaves, SCIP_NODE ***children, SCIP_NODE ***siblings, int *nleaves, int *nchildren, int *nsiblings)
SCIPcalcNodeselPriority
SCIP_Real SCIPcalcNodeselPriority(SCIP *scip, SCIP_VAR *var, SCIP_BRANCHDIR branchdir, SCIP_Real targetvalue)
SCIPfrac
SCIP_Real SCIPfrac(SCIP *scip, SCIP_Real val)
SCIPflushRowExtensions
SCIP_RETCODE SCIPflushRowExtensions(SCIP *scip, SCIP_ROW *row)
SCIPcreateConsLinear
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
pyscipopt.scip.Model.getGap
def getGap(self)
Definition: scip.pyx:1133
pyscipopt.scip.Row.getBasisStatus
def getBasisStatus(self)
Definition: scip.pyx:414
pyscipopt.scip.Model.isObjChangedProbing
def isObjChangedProbing(self)
Definition: scip.pyx:4144
pyscipopt.scip.Model.includeBranchrule
def includeBranchrule(self, Branchrule, branchrule, name, desc, priority, maxdepth, maxbounddist)
Definition: scip.pyx:3799
pyscipopt.scip.Model.isGT
def isGT(self, val1, val2)
Definition: scip.pyx:1201
SCIPcolGetPrimsol
SCIP_Real SCIPcolGetPrimsol(SCIP_COL *col)
SCIPgetNLeaves
int SCIPgetNLeaves(SCIP *scip)
pyscipopt.scip.Event.__hash__
def __hash__(self)
Definition: scip.pyx:314
pyscipopt.scip.Model.setCharParam
def setCharParam(self, name, value)
Definition: scip.pyx:4735
SCIPchgLhsNonlinear
SCIP_RETCODE SCIPchgLhsNonlinear(SCIP *scip, SCIP_CONS *cons, SCIP_Real lhs)
SCIPcreateConsSOS2
SCIP_RETCODE SCIPcreateConsSOS2(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *weights, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
pyscipopt.scip.Model.includeHeur
def includeHeur(self, Heur, heur, name, desc, dispchar, priority=10000, freq=1, freqofs=0, maxdepth=-1, timingmask=SCIP_HEURTIMING_BEFORENODE, usessubscip=False)
Definition: scip.pyx:3733
pyscipopt.scip.Model.includeBendersDefaultCuts
def includeBendersDefaultCuts(self, Benders, benders)
Definition: scip.pyx:3527
SCIPvarGetType
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
SCIPepsilon
SCIP_Real SCIPepsilon(SCIP *scip)
SCIProwIsIntegral
SCIP_Bool SCIProwIsIntegral(SCIP_ROW *row)
pyscipopt.scip.BoundChange.getNewBound
def getNewBound(self)
Definition: scip.pyx:595
pyscipopt.scip.Solution.scip
scip
Definition: scip.pyx:542
pyscipopt.scip.Model.getLhs
def getLhs(self, Constraint, cons)
Definition: scip.pyx:2868
SCIPenableReoptimization
SCIP_RETCODE SCIPenableReoptimization(SCIP *scip, SCIP_Bool enable)
pyscipopt.scip.NLRow.getDualsol
def getDualsol(self)
Definition: scip.pyx:522
pyscipopt.scip.Model.getNFeasibleLeaves
def getNFeasibleLeaves(self)
Definition: scip.pyx:1109
pyscipopt.scip.Model.getNSiblings
def getNSiblings(self)
Definition: scip.pyx:1125
pyscipopt.scip.Model.fixVarProbing
def fixVarProbing(self, Variable, var, fixedval)
Definition: scip.pyx:4140
SCIPnlrowGetName
const char * SCIPnlrowGetName(SCIP_NLROW *nlrow)
SCIPprintSol
SCIP_RETCODE SCIPprintSol(SCIP *scip, SCIP_SOL *sol, FILE *file, SCIP_Bool printzeros)
SCIPconsIsActive
SCIP_Bool SCIPconsIsActive(SCIP_CONS *cons)
pyscipopt.scip.Model.getRhs
def getRhs(self, Constraint, cons)
Definition: scip.pyx:2854
SCIPgetPrimalbound
SCIP_Real SCIPgetPrimalbound(SCIP *scip)
SCIPcreateConsXor
SCIP_RETCODE SCIPcreateConsXor(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_Bool rhs, int nvars, SCIP_VAR **vars, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
pyscipopt.scip.Model.chgVarUbNode
def chgVarUbNode(self, Node, node, Variable, var, ub)
Definition: scip.pyx:1645
pyscipopt.scip.NLRow.__get__
def __get__(self)
Definition: scip.pyx:499
SCIPnodeGetType
SCIP_NODETYPE SCIPnodeGetType(SCIP_NODE *node)
pyscipopt.scip.Model.getLocalEstimate
def getLocalEstimate(self, original=False)
Definition: scip.pyx:1345
pyscipopt.scip.Node.isPropagatedAgain
def isPropagatedAgain(self)
Definition: scip.pyx:693
pyscipopt.scip.Node.getLowerbound
def getLowerbound(self)
Definition: scip.pyx:664
pyscipopt.scip.Row.getConstant
def getConstant(self)
Definition: scip.pyx:406
pyscipopt.scip.Row
Definition: scip.pyx:382
pyscipopt.scip.Event.getVar
def getVar(self)
Definition: scip.pyx:299
SCIPincludeProp
SCIP_RETCODE SCIPincludeProp(SCIP *scip, const char *name, const char *desc, int priority, int freq, SCIP_Bool delay, SCIP_PROPTIMING timingmask, int presolpriority, int presolmaxrounds, SCIP_PRESOLTIMING presoltiming, SCIP_DECL_PROPCOPY((*propcopy)), SCIP_DECL_PROPFREE((*propfree)), SCIP_DECL_PROPINIT((*propinit)), SCIP_DECL_PROPEXIT((*propexit)), SCIP_DECL_PROPINITPRE((*propinitpre)), SCIP_DECL_PROPEXITPRE((*propexitpre)), SCIP_DECL_PROPINITSOL((*propinitsol)), SCIP_DECL_PROPEXITSOL((*propexitsol)), SCIP_DECL_PROPPRESOL((*proppresol)), SCIP_DECL_PROPEXEC((*propexec)), SCIP_DECL_PROPRESPROP((*propresprop)), SCIP_PROPDATA *propdata)
SCIPdropRowEvent
SCIP_RETCODE SCIPdropRowEvent(SCIP *scip, SCIP_ROW *row, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
SCIPreadProb
SCIP_RETCODE SCIPreadProb(SCIP *scip, const char *filename, const char *extension)
pyscipopt.scip.print_memory_in_use
def print_memory_in_use()
Definition: scip.pyx:4982
pyscipopt.scip.Model.computeBestSolSubproblems
def computeBestSolSubproblems(self)
Definition: scip.pyx:3281
SCIPlpiGetIterations
SCIP_RETCODE SCIPlpiGetIterations(SCIP_LPI *lpi, int *iterations)
SCIPchgVarLbProbing
SCIP_RETCODE SCIPchgVarLbProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
pyscipopt.scip.Event.__class__
__class__
Definition: scip.pyx:318
pyscipopt.scip.Constraint.isDynamic
def isDynamic(self)
Definition: scip.pyx:893
SCIPgetNlRowActivityBounds
SCIP_RETCODE SCIPgetNlRowActivityBounds(SCIP *scip, SCIP_NLROW *nlrow, SCIP_Real *minactivity, SCIP_Real *maxactivity)
pyscipopt.scip.Model.lpiGetIterations
def lpiGetIterations(self)
Definition: scip.pyx:1225
pyscipopt.scip.Model.chgLhs
def chgLhs(self, Constraint, cons, lhs)
Definition: scip.pyx:2835
pyscipopt.scip.Model.getRowActivity
def getRowActivity(self, Row, row)
Definition: scip.pyx:1902
pyscipopt.scip.Model.setObjlimit
def setObjlimit(self, objlimit)
Definition: scip.pyx:1243
SCIPcalcChildEstimate
SCIP_Real SCIPcalcChildEstimate(SCIP *scip, SCIP_VAR *var, SCIP_Real targetvalue)
pyscipopt.scip.Model.createProbBasic
def createProbBasic(self, problemName='model')
Definition: scip.pyx:1052
SCIProwGetLPPos
int SCIProwGetLPPos(SCIP_ROW *row)
SCIProwGetConstant
SCIP_Real SCIProwGetConstant(SCIP_ROW *row)
pyscipopt.scip.Model.solveConcurrent
def solveConcurrent(self)
Definition: scip.pyx:3230
pyscipopt.scip.Constraint.isNonlinear
def isNonlinear(self)
Definition: scip.pyx:914
pyscipopt.scip.Model.getNlRowSolFeasibility
def getNlRowSolFeasibility(self, NLRow, nlrow, Solution, sol=None)
Definition: scip.pyx:2988
pyscipopt.scip.Model.includePricer
def includePricer(self, Pricer, pricer, name, desc, priority=1, delay=True)
Definition: scip.pyx:3560
SCIPaddSol
SCIP_RETCODE SCIPaddSol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *stored)
pyscipopt.scip.Model.readSol
def readSol(self, filename)
Definition: scip.pyx:4318
SCIPbacktrackProbing
SCIP_RETCODE SCIPbacktrackProbing(SCIP *scip, int probingdepth)
pyscipopt.scip.Model.getTransformedVar
def getTransformedVar(self, Variable, var)
Definition: scip.pyx:1476
SCIPchgRowLhsDive
SCIP_RETCODE SCIPchgRowLhsDive(SCIP *scip, SCIP_ROW *row, SCIP_Real newlhs)
pyscipopt.scip.Model.getProbName
def getProbName(self)
Definition: scip.pyx:1077
SCIPcreateExprProduct
SCIP_RETCODE SCIPcreateExprProduct(SCIP *scip, SCIP_EXPR **expr, int nchildren, SCIP_EXPR **children, SCIP_Real coefficient, SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), void *ownercreatedata)
SCIProwGetOrigintype
SCIP_ROWORIGINTYPE SCIProwGetOrigintype(SCIP_ROW *row)
pyscipopt.scip.Model.isCutEfficacious
def isCutEfficacious(self, Row, cut, not, None, Solution, sol=None)
Definition: scip.pyx:1960
SCIPprintCons
SCIP_RETCODE SCIPprintCons(SCIP *scip, SCIP_CONS *cons, FILE *file)
SCIPactivateBenders
SCIP_RETCODE SCIPactivateBenders(SCIP *scip, SCIP_BENDERS *benders, int nsubproblems)
pyscipopt.scip.Row.__eq__
def __eq__(self, other)
Definition: scip.pyx:483
pyscipopt.scip.Model.freeReoptSolve
def freeReoptSolve(self)
Definition: scip.pyx:4918
SCIProwGetDualsol
SCIP_Real SCIProwGetDualsol(SCIP_ROW *row)
SCIPaddLinearVarNonlinear
SCIP_RETCODE SCIPaddLinearVarNonlinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real coef)
pyscipopt.scip.Model.includeReader
def includeReader(self, Reader, reader, name, desc, ext)
Definition: scip.pyx:3687
pyscipopt.scip.Row.getLPPos
def getLPPos(self)
Definition: scip.pyx:410
SCIPincludeRelax
SCIP_RETCODE SCIPincludeRelax(SCIP *scip, const char *name, const char *desc, int priority, int freq, SCIP_DECL_RELAXCOPY((*relaxcopy)), SCIP_DECL_RELAXFREE((*relaxfree)), SCIP_DECL_RELAXINIT((*relaxinit)), SCIP_DECL_RELAXEXIT((*relaxexit)), SCIP_DECL_RELAXINITSOL((*relaxinitsol)), SCIP_DECL_RELAXEXITSOL((*relaxexitsol)), SCIP_DECL_RELAXEXEC((*relaxexec)), SCIP_RELAXDATA *relaxdata)
SCIPgetSolvingTime
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
SCIPisLT
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIPfixVarProbing
SCIP_RETCODE SCIPfixVarProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval)
pyscipopt.scip.Constraint.scip_cons
scip_cons
Definition: scip.pyx:850
SCIPincludeCutsel
SCIP_RETCODE SCIPincludeCutsel(SCIP *scip, const char *name, const char *desc, int priority, SCIP_DECL_CUTSELCOPY((*cutselcopy)), SCIP_DECL_CUTSELFREE((*cutselfree)), SCIP_DECL_CUTSELINIT((*cutselinit)), SCIP_DECL_CUTSELEXIT((*cutselexit)), SCIP_DECL_CUTSELINITSOL((*cutselinitsol)), SCIP_DECL_CUTSELEXITSOL((*cutselexitsol)), SCIP_DECL_CUTSELSELECT((*cutselselect)), SCIP_CUTSELDATA *cutseldata)
pyscipopt.scip.Constraint.isPropagated
def isPropagated(self)
Definition: scip.pyx:881
SCIPgetNLPs
SCIP_Longint SCIPgetNLPs(SCIP *scip)
pyscipopt.scip.Event
Definition: scip.pyx:273
SCIPcreateExprSum
SCIP_RETCODE SCIPcreateExprSum(SCIP *scip, SCIP_EXPR **expr, int nchildren, SCIP_EXPR **children, SCIP_Real *coefficients, SCIP_Real constant, SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), void *ownercreatedata)
pyscipopt.scip.Column.isIntegral
def isIntegral(self)
Definition: scip.pyx:350
pyscipopt.scip.Variable.getObj
def getObj(self)
Definition: scip.pyx:834
SCIPappendVarSOS2
SCIP_RETCODE SCIPappendVarSOS2(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
pyscipopt.scip.Model.chgVarLbNode
def chgVarLbNode(self, Node, node, Variable, var, lb)
Definition: scip.pyx:1634
SCIPsetConsRemovable
SCIP_RETCODE SCIPsetConsRemovable(SCIP *scip, SCIP_CONS *cons, SCIP_Bool removable)
SCIPvarIsInLP
SCIP_Bool SCIPvarIsInLP(SCIP_VAR *var)
SCIPinRepropagation
SCIP_Bool SCIPinRepropagation(SCIP *scip)
SCIPsetupBendersSubproblem
SCIP_RETCODE SCIPsetupBendersSubproblem(SCIP *scip, SCIP_BENDERS *benders, SCIP_SOL *sol, int probnumber, SCIP_BENDERSENFOTYPE type)
pyscipopt.scip.Solution.__getitem__
def __getitem__(self, Expr, expr)
Definition: scip.pyx:545
SCIPconsIsSeparated
SCIP_Bool SCIPconsIsSeparated(SCIP_CONS *cons)
pyscipopt.scip.Model.chgVarLbDive
def chgVarLbDive(self, Variable, var, newbound)
Definition: scip.pyx:4039
pyscipopt.scip.NLRow
Definition: scip.pyx:487
SCIPcheckSolOrig
SCIP_RETCODE SCIPcheckSolOrig(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *feasible, SCIP_Bool printreason, SCIP_Bool completely)
SCIPincludePricer
SCIP_RETCODE SCIPincludePricer(SCIP *scip, const char *name, const char *desc, int priority, SCIP_Bool delay, SCIP_DECL_PRICERCOPY((*pricercopy)), SCIP_DECL_PRICERFREE((*pricerfree)), SCIP_DECL_PRICERINIT((*pricerinit)), SCIP_DECL_PRICEREXIT((*pricerexit)), SCIP_DECL_PRICERINITSOL((*pricerinitsol)), SCIP_DECL_PRICEREXITSOL((*pricerexitsol)), SCIP_DECL_PRICERREDCOST((*pricerredcost)), SCIP_DECL_PRICERFARKAS((*pricerfarkas)), SCIP_PRICERDATA *pricerdata)
SCIPtightenVarLbGlobal
SCIP_RETCODE SCIPtightenVarLbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
SCIPcreateExprExp
SCIP_RETCODE SCIPcreateExprExp(SCIP *scip, SCIP_EXPR **expr, SCIP_EXPR *child, SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), void *ownercreatedata)
pyscipopt.scip.Model.setIntParam
def setIntParam(self, name, value)
Definition: scip.pyx:4705
SCIPfindHeur
SCIP_HEUR * SCIPfindHeur(SCIP *scip, const char *name)
pyscipopt.scip.Model.getLPObjVal
def getLPObjVal(self)
Definition: scip.pyx:1799
SCIPchgVarLbDive
SCIP_RETCODE SCIPchgVarLbDive(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
pyscipopt.scip.Model.__class__
__class__
Definition: scip.pyx:991
SCIPfindSepa
SCIP_SEPA * SCIPfindSepa(SCIP *scip, const char *name)
pyscipopt.scip.Column.getUb
def getUb(self)
Definition: scip.pyx:367
SCIPisFeasNegative
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
SCIPgetNLPIterations
SCIP_Longint SCIPgetNLPIterations(SCIP *scip)
pyscipopt.scip.Model.writeTransSol
def writeTransSol(self, Solution, solution, filename="transprob.sol", write_zeros=False)
Definition: scip.pyx:4302
SCIPaddExprNonlinear
SCIP_RETCODE SCIPaddExprNonlinear(SCIP *scip, SCIP_CONS *cons, SCIP_EXPR *expr, SCIP_Real coef)
pyscipopt.scip.Constraint.__eq__
def __eq__(self, other)
Definition: scip.pyx:922
SCIPvarGetUbLocal
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
SCIPgetLPBInvRow
SCIP_RETCODE SCIPgetLPBInvRow(SCIP *scip, int r, SCIP_Real *coefs, int *inds, int *ninds)
SCIPgetNIntVars
int SCIPgetNIntVars(SCIP *scip)
SCIPisNLPConstructed
SCIP_Bool SCIPisNLPConstructed(SCIP *scip)
SCIPgetNReaders
int SCIPgetNReaders(SCIP *scip)
SCIPisFeasZero
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
pyscipopt.expr.expr_to_nodes
def expr_to_nodes(expr)
Definition: expr.pxi:639
pyscipopt.scip.Model.setMaximize
def setMaximize(self)
Definition: scip.pyx:1239
SCIPgetLocalTransEstimate
SCIP_Real SCIPgetLocalTransEstimate(SCIP *scip)
SCIPdelVar
SCIP_RETCODE SCIPdelVar(SCIP *scip, SCIP_VAR *var, SCIP_Bool *deleted)
pyscipopt.scip.Node.getNumber
def getNumber(self)
Definition: scip.pyx:652
SCIPversion
SCIP_Real SCIPversion(void)
SCIPgetNBinVars
int SCIPgetNBinVars(SCIP *scip)
SCIPinProbing
SCIP_Bool SCIPinProbing(SCIP *scip)
pyscipopt.scip.Model.addObjoffset
def addObjoffset(self, offset, solutions=False)
Definition: scip.pyx:1311
SCIProwGetVals
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
pyscipopt.scip.Model.getSolVal
def getSolVal(self, Solution, sol, Expr, expr)
Definition: scip.pyx:4486
SCIPchgVarType
SCIP_RETCODE SCIPchgVarType(SCIP *scip, SCIP_VAR *var, SCIP_VARTYPE vartype, SCIP_Bool *infeasible)
pyscipopt.scip.Row.__hash__
def __hash__(self)
Definition: scip.pyx:480
SCIPreleaseRow
SCIP_RETCODE SCIPreleaseRow(SCIP *scip, SCIP_ROW **row)
SCIPreleaseCons
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
pyscipopt.scip.Model.version
def version(self)
Definition: scip.pyx:1069
SCIPprintStatistics
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
SCIPgetConss
SCIP_CONS ** SCIPgetConss(SCIP *scip)
SCIPconsIsEnforced
SCIP_Bool SCIPconsIsEnforced(SCIP_CONS *cons)
SCIPsetObjlimit
SCIP_RETCODE SCIPsetObjlimit(SCIP *scip, SCIP_Real objlimit)
SCIPgetBendersSubproblemVar
SCIP_RETCODE SCIPgetBendersSubproblemVar(SCIP *scip, SCIP_BENDERS *benders, SCIP_VAR *var, SCIP_VAR **mappedvar, int probnumber)
SCIPwriteOrigProblem
SCIP_RETCODE SCIPwriteOrigProblem(SCIP *scip, const char *filename, const char *extension, SCIP_Bool genericnames)
SCIPincludeHeur
SCIP_RETCODE SCIPincludeHeur(SCIP *scip, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEURCOPY((*heurcopy)), SCIP_DECL_HEURFREE((*heurfree)), SCIP_DECL_HEURINIT((*heurinit)), SCIP_DECL_HEUREXIT((*heurexit)), SCIP_DECL_HEURINITSOL((*heurinitsol)), SCIP_DECL_HEUREXITSOL((*heurexitsol)), SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
pyscipopt.scip.Model.readSolFile
def readSolFile(self, filename)
Definition: scip.pyx:4327
SCIPgetSlackVarIndicator
SCIP_VAR * SCIPgetSlackVarIndicator(SCIP_CONS *cons)
SCIPgetNNodes
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIPcolGetBasisStatus
SCIP_BASESTAT SCIPcolGetBasisStatus(SCIP_COL *col)
SCIPeventGetRow
SCIP_ROW * SCIPeventGetRow(SCIP_EVENT *event)
pyscipopt.scip.Model.tightenVarUbGlobal
def tightenVarUbGlobal(self, Variable, var, ub, force=False)
Definition: scip.pyx:1557
SCIPvarGetUbOriginal
SCIP_Real SCIPvarGetUbOriginal(SCIP_VAR *var)
SCIPaddConsLocal
SCIP_RETCODE SCIPaddConsLocal(SCIP *scip, SCIP_CONS *cons, SCIP_NODE *validnode)
SCIPgetRowObjParallelism
SCIP_Real SCIPgetRowObjParallelism(SCIP *scip, SCIP_ROW *row)
SCIPfreeReoptSolve
SCIP_RETCODE SCIPfreeReoptSolve(SCIP *scip)
pyscipopt.scip.Model.setSeparating
def setSeparating(self, setting)
Definition: scip.pyx:1369
SCIPaddRow
SCIP_RETCODE SCIPaddRow(SCIP *scip, SCIP_ROW *row, SCIP_Bool forcecut, SCIP_Bool *infeasible)
pyscipopt.scip.Model.addVarLocks
def addVarLocks(self, Variable, var, nlocksdown, nlocksup)
Definition: scip.pyx:1487
pyscipopt.scip.NLRow.__hash__
def __hash__(self)
Definition: scip.pyx:526
SCIPeventGetType
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
pyscipopt.scip.Row.__get__
def __get__(self)
Definition: scip.pyx:394
SCIPsolveProbingLP
SCIP_RETCODE SCIPsolveProbingLP(SCIP *scip, int itlim, SCIP_Bool *lperror, SCIP_Bool *cutoff)
SCIPfixVar
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
SCIPaddVarLocks
SCIP_RETCODE SCIPaddVarLocks(SCIP *scip, SCIP_VAR *var, int nlocksdown, int nlocksup)
pyscipopt.scip.Model.getSolObjVal
def getSolObjVal(self, Solution, sol, original=True)
Definition: scip.pyx:4459
pyscipopt.scip.Row.getCols
def getCols(self)
Definition: scip.pyx:466
SCIPcreateEmptyRowUnspec
SCIP_RETCODE SCIPcreateEmptyRowUnspec(SCIP *scip, SCIP_ROW **row, const char *name, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool removable)
SCIPfindBenderscut
SCIP_BENDERSCUT * SCIPfindBenderscut(SCIP_BENDERS *benders, const char *name)
SCIPgetObjsense
SCIP_OBJSENSE SCIPgetObjsense(SCIP *scip)
pyscipopt.scip.Column.__hash__
def __hash__(self)
Definition: scip.pyx:375
pyscipopt.scip.Model.updateNodeLowerbound
def updateNodeLowerbound(self, Node, node, lb)
Definition: scip.pyx:1726
SCIPchgVarUbDive
SCIP_RETCODE SCIPchgVarUbDive(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
SCIPsetCharParam
SCIP_RETCODE SCIPsetCharParam(SCIP *scip, const char *name, char value)
SCIPgetTransObjoffset
SCIP_Real SCIPgetTransObjoffset(SCIP *scip)
SCIPgetNFeasibleLeaves
SCIP_Longint SCIPgetNFeasibleLeaves(SCIP *scip)
pyscipopt.scip.Model.includeEventhdlr
def includeEventhdlr(self, Eventhdlr, eventhdlr, name, desc)
Definition: scip.pyx:3536
pyscipopt.scip.Model.printSol
def printSol(self, Solution, solution=None, write_zeros=False)
Definition: scip.pyx:4250
SCIProwIsRemovable
SCIP_Bool SCIProwIsRemovable(SCIP_ROW *row)
pyscipopt.scip.Model.getRowDualSol
def getRowDualSol(self, Row, row)
Definition: scip.pyx:1947
pyscipopt.scip.Model.getBestSibling
def getBestSibling(self)
Definition: scip.pyx:1741
pyscipopt.scip.Event.getType
def getType(self)
Definition: scip.pyx:284
SCIPnewProbingNode
SCIP_RETCODE SCIPnewProbingNode(SCIP *scip)
pyscipopt.scip.Model.getDualMultiplier
def getDualMultiplier(self, Constraint, cons)
Definition: scip.pyx:3170
pyscipopt.scip.Model.includeConshdlr
def includeConshdlr(self, Conshdlr, conshdlr, name, desc, sepapriority=0, enfopriority=0, chckpriority=0, sepafreq=-1, propfreq=-1, eagerfreq=100, maxprerounds=-1, delaysepa=False, delayprop=False, needscons=True, proptiming=PY_SCIP_PROPTIMING.BEFORELP, presoltiming=PY_SCIP_PRESOLTIMING.MEDIUM)
Definition: scip.pyx:3582
pyscipopt.scip.Solution
Definition: scip.pyx:533
SCIPsolveBendersSubproblem
SCIP_RETCODE SCIPsolveBendersSubproblem(SCIP *scip, SCIP_BENDERS *benders, SCIP_SOL *sol, int probnumber, SCIP_Bool *infeasible, SCIP_Bool solvecip, SCIP_Real *objective)
pyscipopt.scip.Model.getNLPs
def getNLPs(self)
Definition: scip.pyx:4661
SCIProwIsModifiable
SCIP_Bool SCIProwIsModifiable(SCIP_ROW *row)
SCIProwGetNorm
SCIP_Real SCIProwGetNorm(SCIP_ROW *row)
pyscipopt.scip.Model.tightenVarLbGlobal
def tightenVarLbGlobal(self, Variable, var, lb, force=False)
Definition: scip.pyx:1573
pyscipopt.scip.Model.getTermsQuadratic
def getTermsQuadratic(self, Constraint, cons)
Definition: scip.pyx:3023
SCIPgetValsLinear
SCIP_Real * SCIPgetValsLinear(SCIP *scip, SCIP_CONS *cons)
SCIPgetOrigVars
SCIP_VAR ** SCIPgetOrigVars(SCIP *scip)
SCIPaddRowDive
SCIP_RETCODE SCIPaddRowDive(SCIP *scip, SCIP_ROW *row)
pyscipopt.scip.Variable
Definition: scip.pyx:755
SCIPconsIsStickingAtNode
SCIP_Bool SCIPconsIsStickingAtNode(SCIP_CONS *cons)
SCIPgetExprNonlinear
SCIP_EXPR * SCIPgetExprNonlinear(SCIP_CONS *cons)
pyscipopt.scip.Model.startProbing
def startProbing(self)
Definition: scip.pyx:4090
pyscipopt.scip.Model.delConsLocal
def delConsLocal(self, Constraint, cons)
Definition: scip.pyx:3112
pyscipopt.scip.Model.newProbingNode
def newProbingNode(self)
Definition: scip.pyx:4100
pyscipopt.scip.Model.addBendersSubproblem
def addBendersSubproblem(self, Benders, benders, subproblem)
Definition: scip.pyx:3352
SCIPreleaseExpr
SCIP_RETCODE SCIPreleaseExpr(SCIP *scip, SCIP_EXPR **expr)
pyscipopt.scip.Model.solveProbingLP
def solveProbingLP(self, itlim=-1)
Definition: scip.pyx:4152
pyscipopt.scip.Model._freescip
_freescip
Definition: scip.pyx:958
pyscipopt.scip.Model.getNCuts
def getNCuts(self)
Definition: scip.pyx:1974
SCIPappendVarSOS1
SCIP_RETCODE SCIPappendVarSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
pyscipopt.scip.Model.isFeasIntegral
def isFeasIntegral(self, value)
Definition: scip.pyx:1177
pyscipopt.scip.BoundChange.__repr__
def __repr__(self)
Definition: scip.pyx:615
SCIPaddCoefLinear
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
SCIPsetRelaxSolVal
SCIP_RETCODE SCIPsetRelaxSolVal(SCIP *scip, SCIP_RELAX *relax, SCIP_VAR *var, SCIP_Real val)
SCIPsetProbName
SCIP_RETCODE SCIPsetProbName(SCIP *scip, const char *name)
pyscipopt.scip.Node.getParentBranchings
def getParentBranchings(self)
Definition: scip.pyx:711
SCIPgetOrigObjoffset
SCIP_Real SCIPgetOrigObjoffset(SCIP *scip)
pyscipopt.scip.Model.writeStatistics
def writeStatistics(self, filename="origprob.stats")
Definition: scip.pyx:4649
pyscipopt.scip.BoundChange.isRedundant
def isRedundant(self)
Definition: scip.pyx:611
pyscipopt.scip.Model.getNLPCols
def getNLPCols(self)
Definition: scip.pyx:1824
SCIPgetDualsolLinear
SCIP_Real SCIPgetDualsolLinear(SCIP *scip, SCIP_CONS *cons)
SCIPgetNNLPNlRows
int SCIPgetNNLPNlRows(SCIP *scip)
SCIPisFeasEQ
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIProwGetNNonz
int SCIProwGetNNonz(SCIP_ROW *row)
pyscipopt.scip.Model.getRowParallelism
def getRowParallelism(self, Row, row1, Row, row2, orthofunc=101)
Definition: scip.pyx:1942
pyscipopt.scip.Model.isEQ
def isEQ(self, val1, val2)
Definition: scip.pyx:1181
SCIPnodeIsPropagatedAgain
SCIP_Bool SCIPnodeIsPropagatedAgain(SCIP_NODE *node)
pyscipopt.scip.Model.releaseRow
def releaseRow(self, Row, row, not, None)
Definition: scip.pyx:1911
pyscipopt.scip.Model.getBestChild
def getBestChild(self)
Definition: scip.pyx:1737
pyscipopt.scip.Model.getCurrentNode
def getCurrentNode(self)
Definition: scip.pyx:1129
SCIPprintBestSol
SCIP_RETCODE SCIPprintBestSol(SCIP *scip, FILE *file, SCIP_Bool printzeros)
SCIPgetNVars
int SCIPgetNVars(SCIP *scip)
pyscipopt.scip.Model._bestSol
_bestSol
Definition: scip.pyx:1002
pyscipopt.scip.Constraint.isStickingAtNode
def isStickingAtNode(self)
Definition: scip.pyx:901
pyscipopt.scip.Model.setObjective
def setObjective(self, coeffs, sense='minimize', clear='true')
Definition: scip.pyx:1256
SCIPsetHeuristics
SCIP_RETCODE SCIPsetHeuristics(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
pyscipopt.scip.Model.dropVarEvent
def dropVarEvent(self, Variable, var, eventtype, Eventhdlr, eventhdlr)
Definition: scip.pyx:4613
pyscipopt.scip.Model.getNTotalNodes
def getNTotalNodes(self)
Definition: scip.pyx:1105
pyscipopt.scip.Model.getCondition
def getCondition(self, exact=False)
Definition: scip.pyx:1205
pyscipopt.scip.Model.getBendersAuxiliaryVar
def getBendersAuxiliaryVar(self, probnumber, Benders, benders=None)
Definition: scip.pyx:3480
pyscipopt.scip.Model.chgReoptObjective
def chgReoptObjective(self, coeffs, sense='minimize')
Definition: scip.pyx:4922
pyscipopt.scip.Model.addConsOr
def addConsOr(self, vars, resvar, name="ORcons", initial=True, separate=True, enforce=True, check=True, propagate=True, local=False, modifiable=False, dynamic=False, removable=False, stickingatnode=False)
Definition: scip.pyx:2531
pyscipopt.scip.Node.getNDomchg
def getNDomchg(self)
Definition: scip.pyx:733
pyscipopt.scip.Model.printBestSol
def printBestSol(self, write_zeros=False)
Definition: scip.pyx:4246
SCIPnlrowGetNLinearVars
int SCIPnlrowGetNLinearVars(SCIP_NLROW *nlrow)
pyscipopt.scip.Model.isZero
def isZero(self, value)
Definition: scip.pyx:1161
SCIPgetBestChild
SCIP_NODE * SCIPgetBestChild(SCIP *scip)
SCIPcolGetLb
SCIP_Real SCIPcolGetLb(SCIP_COL *col)
pyscipopt.scip.Model.addConsNode
def addConsNode(self, Node, node, Constraint, cons, Node, validnode=None)
Definition: scip.pyx:2387
pyscipopt.scip.Model.isLT
def isLT(self, val1, val2)
Definition: scip.pyx:1193
pyscipopt.scip.Model.chgRhs
def chgRhs(self, Constraint, cons, rhs)
Definition: scip.pyx:2816
SCIPvarGetUbGlobal
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
pyscipopt.scip.Model.applyCutsProbing
def applyCutsProbing(self)
Definition: scip.pyx:4166
pyscipopt.scip.Model.readProblem
def readProblem(self, filename, extension=None)
Definition: scip.pyx:4880
SCIPwriteParams
SCIP_RETCODE SCIPwriteParams(SCIP *scip, const char *filename, SCIP_Bool comments, SCIP_Bool onlychanged)
pyscipopt.scip.Solution.__repr__
def __repr__(self)
Definition: scip.pyx:563
pyscipopt.scip.Model.backtrackProbing
def backtrackProbing(self, probingdepth)
Definition: scip.pyx:4106
SCIPchgVarUbNode
SCIP_RETCODE SCIPchgVarUbNode(SCIP *scip, SCIP_NODE *node, SCIP_VAR *var, SCIP_Real newbound)
pyscipopt.scip.Model._addQuadCons
def _addQuadCons(self, ExprCons, quadcons, **kwargs)
Definition: scip.pyx:2158
SCIPgetNInfeasibleLeaves
SCIP_Longint SCIPgetNInfeasibleLeaves(SCIP *scip)
pyscipopt.scip.Model.chgVarType
def chgVarType(self, Variable, var, vtype)
Definition: scip.pyx:1656
pyscipopt.scip.Model.getNLeaves
def getNLeaves(self)
Definition: scip.pyx:1117
pyscipopt.scip.Model.isLPSolBasic
def isLPSolBasic(self)
Definition: scip.pyx:1860
SCIPcopyOrig
SCIP_RETCODE SCIPcopyOrig(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *suffix, SCIP_Bool enablepricing, SCIP_Bool threadsafe, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
pyscipopt.scip.Model.appendVarSOS1
def appendVarSOS1(self, Constraint, cons, Variable, var)
Definition: scip.pyx:2752
SCIPsetStringParam
SCIP_RETCODE SCIPsetStringParam(SCIP *scip, const char *name, const char *value)
pyscipopt.scip.Model.getStatus
def getStatus(self)
Definition: scip.pyx:4539
pyscipopt.scip.NLRow.getLinearTerms
def getLinearTerms(self)
Definition: scip.pyx:507
SCIPgetSolVal
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
pyscipopt.scip.Constraint.isModifiable
def isModifiable(self)
Definition: scip.pyx:889
SCIPsetParamsCountsols
SCIP_RETCODE SCIPsetParamsCountsols(SCIP *scip)
pyscipopt.scip.NLRow.getConstant
def getConstant(self)
Definition: scip.pyx:503
SCIPgetNVarsLinear
int SCIPgetNVarsLinear(SCIP *scip, SCIP_CONS *cons)
pyscipopt.scip.Model.getRowNumIntCols
def getRowNumIntCols(self, Row, row)
Definition: scip.pyx:1934
SCIPgetCutLPSolCutoffDistance
SCIP_Real SCIPgetCutLPSolCutoffDistance(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
pyscipopt.scip.Model.addPoolCut
def addPoolCut(self, Row, row, not, None)
Definition: scip.pyx:1952
SCIPvarGetCol
SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
SCIPchgReoptObjective
SCIP_RETCODE SCIPchgReoptObjective(SCIP *scip, SCIP_OBJSENSE objsense, SCIP_VAR **vars, SCIP_Real *coefs, int nvars)
SCIPgetRowActivity
SCIP_Real SCIPgetRowActivity(SCIP *scip, SCIP_ROW *row)
SCIPvarIsOriginal
SCIP_Bool SCIPvarIsOriginal(SCIP_VAR *var)
pyscipopt.scip.Model.chgVarLbGlobal
def chgVarLbGlobal(self, Variable, var, lb)
Definition: scip.pyx:1612
SCIPgetDualfarkasLinear
SCIP_Real SCIPgetDualfarkasLinear(SCIP *scip, SCIP_CONS *cons)
SCIPgetSols
SCIP_SOL ** SCIPgetSols(SCIP *scip)
pyscipopt.scip.Model.setEmphasis
def setEmphasis(self, paraemphasis, quiet=True)
Definition: scip.pyx:4871
pyscipopt.scip.Model.createPartialSol
def createPartialSol(self, Heur, heur=None)
Definition: scip.pyx:4229
pyscipopt.scip.Model.count
def count(self)
Definition: scip.pyx:4896
SCIPcolGetVar
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
SCIPsetLongintParam
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
SCIPcreateExprVar
SCIP_RETCODE SCIPcreateExprVar(SCIP *scip, SCIP_EXPR **expr, SCIP_VAR *var, SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), void *ownercreatedata)
pyscipopt.scip.Model.inProbing
def inProbing(self)
Definition: scip.pyx:4148
SCIPnodeGetParentBranchings
void SCIPnodeGetParentBranchings(SCIP_NODE *node, SCIP_VAR **branchvars, SCIP_Real *branchbounds, SCIP_BOUNDTYPE *boundtypes, int *nbranchvars, int branchvarssize)
pyscipopt.scip.Model.getSolvingTime
def getSolvingTime(self)
Definition: scip.pyx:1085
pyscipopt.scip.Model.chgVarUb
def chgVarUb(self, Variable, var, ub)
Definition: scip.pyx:1600
pyscipopt.scip.Model.setParamsCountsols
def setParamsCountsols(self)
Definition: scip.pyx:4914
pyscipopt.scip.Model.getNReaders
def getNReaders(self)
Definition: scip.pyx:4900
SCIPcreateExprSin
SCIP_RETCODE SCIPcreateExprSin(SCIP *scip, SCIP_EXPR **expr, SCIP_EXPR *child, SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), void *ownercreatedata)
SCIPgetVarExprVar
SCIP_VAR * SCIPgetVarExprVar(SCIP_EXPR *expr)
SCIPgetNSols
int SCIPgetNSols(SCIP *scip)
SCIPsetRealParam
SCIP_RETCODE SCIPsetRealParam(SCIP *scip, const char *name, SCIP_Real value)
pyscipopt.scip.Model.chgVarBranchPriority
def chgVarBranchPriority(self, Variable, var, priority)
Definition: scip.pyx:4968
pyscipopt.scip.Variable.getUbGlobal
def getUbGlobal(self)
Definition: scip.pyx:822
SCIPresetParam
SCIP_RETCODE SCIPresetParam(SCIP *scip, const char *name)
pyscipopt.scip.Solution.__setitem__
def __setitem__(self, Variable, var, value)
Definition: scip.pyx:560
SCIPisGE
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIPcolGetObj
SCIP_Real SCIPcolGetObj(SCIP_COL *col)
pyscipopt.scip.Model.addRowDive
def addRowDive(self, Row, row)
Definition: scip.pyx:4067
pyscipopt.scip.Model.printCons
def printCons(self, Constraint, constraint)
Definition: scip.pyx:2122
pyscipopt.scip.Model.writeSol
def writeSol(self, Solution, solution, filename="origprob.sol", write_zeros=False)
Definition: scip.pyx:4288
SCIPgetLPSolstat
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
SCIPfree
SCIP_RETCODE SCIPfree(SCIP **scip)
pyscipopt.scip.Model.getVal
def getVal(self, Expr, expr)
Definition: scip.pyx:4503
pyscipopt.scip.Model.repropagateNode
def repropagateNode(self, Node, node)
Definition: scip.pyx:1777
SCIPchgLhsLinear
SCIP_RETCODE SCIPchgLhsLinear(SCIP *scip, SCIP_CONS *cons, SCIP_Real lhs)
SCIPnodeGetAddedConss
void SCIPnodeGetAddedConss(SCIP_NODE *node, SCIP_CONS **addedconss, int *naddedconss, int addedconsssize)
pyscipopt.scip.Model.printVersion
def printVersion(self)
Definition: scip.pyx:1073
SCIPfindEventhdlr
SCIP_EVENTHDLR * SCIPfindEventhdlr(SCIP *scip, const char *name)
pyscipopt.scip.Model.includePresol
def includePresol(self, Presol, presol, name, desc, priority, maxrounds, timing=SCIP_PRESOLTIMING_FAST)
Definition: scip.pyx:3648
pyscipopt.scip.Model.__eq__
def __eq__(self, other)
Definition: scip.pyx:990
SCIPgetDepth
int SCIPgetDepth(SCIP *scip)
pyscipopt.scip.Model.getNCutsApplied
def getNCutsApplied(self)
Definition: scip.pyx:1978
SCIPcolIsIntegral
SCIP_Bool SCIPcolIsIntegral(SCIP_COL *col)
SCIPvarGetIndex
int SCIPvarGetIndex(SCIP_VAR *var)
pyscipopt.scip.Model.getDualbound
def getDualbound(self)
Definition: scip.pyx:4519
pyscipopt.scip.Model.solveDiveLP
def solveDiveLP(self, itlim=-1)
Definition: scip.pyx:4071
SCIPsolveDiveLP
SCIP_RETCODE SCIPsolveDiveLP(SCIP *scip, int itlim, SCIP_Bool *lperror, SCIP_Bool *cutoff)
pyscipopt.scip.Model.setMinimize
def setMinimize(self)
Definition: scip.pyx:1235
pyscipopt.scip.Model.printStatistics
def printStatistics(self)
Definition: scip.pyx:4645
SCIPseparateSol
SCIP_RETCODE SCIPseparateSol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool pretendroot, SCIP_Bool allowlocal, SCIP_Bool onlydelayed, SCIP_Bool *delayed, SCIP_Bool *cutoff)
SCIPgetPresolvingTime
SCIP_Real SCIPgetPresolvingTime(SCIP *scip)
SCIPgetPseudoBranchCands
SCIP_RETCODE SCIPgetPseudoBranchCands(SCIP *scip, SCIP_VAR ***pseudocands, int *npseudocands, int *npriopseudocands)
pyscipopt.scip.Model.getConss
def getConss(self)
Definition: scip.pyx:3090
pyscipopt.scip.Row.__class__
__class__
Definition: scip.pyx:484
SCIProwGetLhs
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
SCIPgetNLimSolsFound
SCIP_Longint SCIPgetNLimSolsFound(SCIP *scip)
pyscipopt.scip.Model.addCut
def addCut(self, Row, cut, not, None, forcecut=False)
Definition: scip.pyx:1968
pyscipopt.scip.Solution._checkStage
def _checkStage(self, method)
Definition: scip.pyx:578
pyscipopt.scip.Model.isGE
def isGE(self, val1, val2)
Definition: scip.pyx:1197
pyscipopt.scip.Model.getProbingDepth
def getProbingDepth(self)
Definition: scip.pyx:4112
SCIPgetBenders
SCIP_BENDERS ** SCIPgetBenders(SCIP *scip)
pyscipopt.scip.Model.chgVarUbProbing
def chgVarUbProbing(self, Variable, var, ub)
Definition: scip.pyx:4130
SCIPconsIsOriginal
SCIP_Bool SCIPconsIsOriginal(SCIP_CONS *cons)
pyscipopt.scip.Variable.getLbLocal
def getLbLocal(self)
Definition: scip.pyx:826
pyscipopt.scip.Model.getVarRedcost
def getVarRedcost(self, Variable, var)
Definition: scip.pyx:3192
SCIPgetNSolsFound
SCIP_Longint SCIPgetNSolsFound(SCIP *scip)
SCIPgetLPI
SCIP_RETCODE SCIPgetLPI(SCIP *scip, SCIP_LPI **lpi)
SCIPincludePresol
SCIP_RETCODE SCIPincludePresol(SCIP *scip, const char *name, const char *desc, int priority, int maxrounds, SCIP_PRESOLTIMING timing, SCIP_DECL_PRESOLCOPY((*presolcopy)), SCIP_DECL_PRESOLFREE((*presolfree)), SCIP_DECL_PRESOLINIT((*presolinit)), SCIP_DECL_PRESOLEXIT((*presolexit)), SCIP_DECL_PRESOLINITPRE((*presolinitpre)), SCIP_DECL_PRESOLEXITPRE((*presolexitpre)), SCIP_DECL_PRESOLEXEC((*presolexec)), SCIP_PRESOLDATA *presoldata)
pyscipopt.scip.Model.initBendersDefault
def initBendersDefault(self, subproblems)
Definition: scip.pyx:3245
pyscipopt.scip.Model.activateBenders
def activateBenders(self, Benders, benders, int, nsubproblems)
Definition: scip.pyx:3343
SCIPgetNegatedVar
SCIP_RETCODE SCIPgetNegatedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **negvar)
pyscipopt.scip.Model.delCons
def delCons(self, Constraint, cons)
Definition: scip.pyx:3104
SCIPchgVarObjDive
SCIP_RETCODE SCIPchgVarObjDive(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
SCIPconstructLP
SCIP_RETCODE SCIPconstructLP(SCIP *scip, SCIP_Bool *cutoff)
pyscipopt.scip.Model.writeLP
def writeLP(self, filename="LP.lp")
Definition: scip.pyx:4204
pyscipopt.scip.Row.isLocal
def isLocal(self)
Definition: scip.pyx:433
pyscipopt.scip.Model.getSlackVarIndicator
def getSlackVarIndicator(self, Constraint, cons)
Definition: scip.pyx:2724
pyscipopt.scip.Constraint.isRemovable
def isRemovable(self)
Definition: scip.pyx:897
pyscipopt.scip.Model.getParams
def getParams(self)
Definition: scip.pyx:4816
pyscipopt.scip.Constraint.isLocal
def isLocal(self)
Definition: scip.pyx:885
pyscipopt.scip.Model.addConsLocal
def addConsLocal(self, Constraint, cons, Node, validnode=None)
Definition: scip.pyx:2401
SCIPsetConsInitial
SCIP_RETCODE SCIPsetConsInitial(SCIP *scip, SCIP_CONS *cons, SCIP_Bool initial)
pyscipopt.scip.Row.getRhs
def getRhs(self)
Definition: scip.pyx:402
pyscipopt.scip.Column.getVar
def getVar(self)
Definition: scip.pyx:354
pyscipopt.scip.Model.isFeasZero
def isFeasZero(self, value)
Definition: scip.pyx:1165