You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pyscipopt/scip.pyx
+71-2
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,9 @@ from cpython.pycapsule cimport PyCapsule_New, PyCapsule_IsValid, PyCapsule_GetPo
12
12
from libc.stdlib cimport malloc, free
13
13
from libc.stdio cimport fdopen
14
14
15
+
from collections.abc import Iterable
16
+
from itertools import repeat
17
+
15
18
include"expr.pxi"
16
19
include"lp.pxi"
17
20
include"benders.pxi"
@@ -1979,18 +1982,19 @@ cdef class Model:
1979
1982
stickingatnode=False):
1980
1983
"""Add a linear or quadratic constraint.
1981
1984
1982
-
:param cons: list of coefficients
1985
+
:param cons: constraint object
1983
1986
:param name: the name of the constraint, generic name if empty (Default value = '')
1984
1987
:param initial: should the LP relaxation of constraint be in the initial LP? (Default value = True)
1985
1988
:param separate: should the constraint be separated during LP processing? (Default value = True)
1986
1989
:param enforce: should the constraint be enforced during node processing? (Default value = True)
1987
-
:param check: should the constraint be checked during for feasibility? (Default value = True)
1990
+
:param check: should the constraint be checked for feasibility? (Default value = True)
1988
1991
:param propagate: should the constraint be propagated during node processing? (Default value = True)
1989
1992
:param local: is the constraint only valid locally? (Default value = False)
1990
1993
:param modifiable: is the constraint modifiable (subject to column generation)? (Default value = False)
1991
1994
:param dynamic: is the constraint subject to aging? (Default value = False)
1992
1995
:param removable: should the relaxation be removed from the LP due to aging or cleanup? (Default value = False)
1993
1996
: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)
1997
+
:return The added @ref scip#Constraint "Constraint" object.
1994
1998
1995
1999
"""
1996
2000
assertisinstance(cons, ExprCons), "given constraint is not ExprCons but %s"% cons.__class__.__name__
Each of the constraints is added to the model using Model.addCons().
2032
+
2033
+
For all parameters, except @p conss, this method behaves differently depending on the type of the passed argument:
2034
+
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.
2035
+
2. Else, the (default) value will be applied to all of the constraints.
2036
+
2037
+
:param conss An iterable of constraint objects. Any iterable will be converted into a list before further processing.
2038
+
: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).
2039
+
:param initial: should the LP relaxation of constraints be in the initial LP? (Default value = True)
2040
+
:param separate: should the constraints be separated during LP processing? (Default value = True)
2041
+
:param enforce: should the constraints be enforced during node processing? (Default value = True)
2042
+
:param check: should the constraints be checked for feasibility? (Default value = True)
2043
+
:param propagate: should the constraints be propagated during node processing? (Default value = True)
2044
+
:param local: are the constraints only valid locally? (Default value = False)
2045
+
:param modifiable: are the constraints modifiable (subject to column generation)? (Default value = False)
2046
+
:param dynamic: are the constraints subject to aging? (Default value = False)
2047
+
:param removable: should the relaxation be removed from the LP due to aging or cleanup? (Default value = False)
2048
+
: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)
2049
+
:return A list of added @ref scip#Constraint "Constraint" objects.
2050
+
2051
+
:see addCons()
2052
+
"""
2053
+
defensure_iterable(elem, length):
2054
+
ifisinstance(elem, Iterable):
2055
+
return elem
2056
+
else:
2057
+
returnlist(repeat(elem, length))
2058
+
2059
+
assertisinstance(conss, Iterable), "Given constraint list is not iterable."
2060
+
2061
+
conss =list(conss)
2062
+
n_conss =len(conss)
2063
+
2064
+
ifisinstance(name, str):
2065
+
if name =="":
2066
+
name = [""for idx inrange(n_conss)]
2067
+
else:
2068
+
name = ["%s_%s"% (name, idx) for idx inrange(n_conss)]
0 commit comments