Trees | Indices | Help |
|
---|
|
Instance Methods | |||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Inherited from |
Class Variables | |
type_ = IndicatorType() See IndicatorType() |
Method Details |
Creates a new IndicatorConstraintInterface. The indicator constraints interface is exposed by the top-level Cplex class as Cplex.indicator_constraints. This constructor is not meant to be used externally.
|
Returns the number of indicator constraints. Example usage: >>> import cplex >>> c = cplex.Cplex() >>> c.indicator_constraints.add(name="ind1") 0 >>> c.indicator_constraints.get_num() 1 |
Adds indicator constraints to the problem. Takes up to eight keyword arguments. If more than one argument is specified, all arguments must have the same length. lin_expr : either a list of SparsePair instances or a matrix in list-of-lists format.
sense : must be either a list of single-character strings or a string containing the senses of the indicator constraints. Each entry must be one of 'G', 'L', 'E', indicating greater-than-or-equal-to (>=), less-than-or-equal-to (<=), and equality (=), respectively. Left unspecified, the default is 'E'. rhs : a list of floats, specifying the righthand side of each indicator constraint. indvar : a list of names or indices (or a mixture of the two), of the variables that control whether the constraint is active or not. complemented : a list of values (0 or 1). Default value of 0 instructs CPLEX to interpret indicator constraint as active when the indicator variable is 1. Set complemented to 1 to instruct CPLEX that the indicator constraint is active when indvar = 0. name : a list of strings that determine the names of the individual constraints. indtype : a list of the types of indicator constraints. Defaults to CPX_INDICATOR_IF ('->'). See IndicatorType(). Returns an iterator containing the indices of the added indicator constraints. >>> import cplex >>> c = cplex.Cplex() >>> indices = c.variables.add(names=["x1", "x2", "x3"]) >>> indices = c.indicator_constraints.add_batch( ... lin_expr=[cplex.SparsePair(ind=["x2"], val=[2.0]), ... cplex.SparsePair(ind=["x3"], val=[2.0])], ... sense="LL", ... rhs=[1.0, 1.0], ... indvar=["x1", "x2"], ... complemented=[0, 0], ... name=["ind1", "ind2"], ... indtype=[c.indicator_constraints.type_.if_, ... c.indicator_constraints.type_.if_]) >>> len(list(indices)) 2 |
Adds an indicator constraint to the problem. Takes up to eight keyword arguments. lin_expr : either a SparsePair or a list of two lists, the first of which contains variable indices or names, the second of which contains values.
sense : the sense of the constraint, may be "L", "G", or "E": default is "E" rhs : a float defining the righthand side of the constraint indvar : the name or index of the variable that controls if the constraint is active complemented : default value of 0 instructs CPLEX to interpret indicator constraint as active when the indicator variable is 1. Set complemented to 1 to instruct CPLEX that the indicator constraint is active when indvar = 0. name : the name of the constraint. indtype : the type of indicator constraint. Defaults to CPX_INDICATOR_IF ('->'). See IndicatorType(). Returns the index of the added indicator constraint. >>> import cplex >>> c = cplex.Cplex() >>> indices = c.variables.add(names = ["x1", "x2"]) >>> c.indicator_constraints.add( ... indvar="x1", ... complemented=0, ... rhs=1.0, ... sense="G", ... lin_expr=cplex.SparsePair(ind=["x2"], val=[2.0]), ... name="ind1", ... indtype=c.indicator_constraints.type_.if_) 0 |
Deletes indicator constraints from the problem. There are four forms by which indicator_constraints.delete may be called.
See CPXdelindconstrs in the Callable Library Reference Manual for more detail. Example usage: >>> import cplex >>> c = cplex.Cplex() >>> [c.indicator_constraints.add(name=str(i)) for i in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> c.indicator_constraints.get_num() 10 >>> c.indicator_constraints.delete(8) >>> c.indicator_constraints.get_names() ['0', '1', '2', '3', '4', '5', '6', '7', '9'] >>> c.indicator_constraints.delete("1", 3) >>> c.indicator_constraints.get_names() ['0', '4', '5', '6', '7', '9'] >>> c.indicator_constraints.delete([2, "0", 5]) >>> c.indicator_constraints.get_names() ['4', '6', '7'] >>> c.indicator_constraints.delete() >>> c.indicator_constraints.get_names() [] |
Returns the indicator variables of a set of indicator constraints. May be called by four forms.
>>> import cplex >>> c = cplex.Cplex() >>> indices = c.variables.add(names = [str(i) for i in range(11)], types = "B" * 11) >>> [c.indicator_constraints.add( ... name=str(i), indvar=i, ... lin_expr=cplex.SparsePair(ind=[i+1], val=[1.0])) ... for i in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> c.indicator_constraints.get_num() 10 >>> c.indicator_constraints.get_indicator_variables(8) 8 >>> c.indicator_constraints.get_indicator_variables("1",3) [1, 2, 3] >>> c.indicator_constraints.get_indicator_variables([2,"0",5]) [2, 0, 5] >>> c.indicator_constraints.get_indicator_variables() [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
Returns whether a set of indicator constraints is complemented. May be called by four forms.
>>> import cplex >>> c = cplex.Cplex() >>> indices = c.variables.add(names = [str(i) for i in range(11)], types = "B" * 11) >>> [c.indicator_constraints.add( ... name=str(i), indvar=10, ... complemented=i % 2) ... for i in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> c.indicator_constraints.get_num() 10 >>> c.indicator_constraints.get_complemented(8) 0 >>> c.indicator_constraints.get_complemented("1",3) [1, 0, 1] >>> c.indicator_constraints.get_complemented([2,"0",5]) [0, 0, 1] >>> c.indicator_constraints.get_complemented() [0, 1, 0, 1, 0, 1, 0, 1, 0, 1] |
Returns the number of nonzeros in a set of indicator constraints. May be called by four forms.
>>> import cplex >>> c = cplex.Cplex() >>> indices = c.variables.add(names = [str(i) for i in range(11)], types = "B" * 11) >>> [c.indicator_constraints.add( ... name=str(i), indvar=10, ... lin_expr=[range(i), [1.0 * (j+1.0) for j in range(i)]]) ... for i in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> c.indicator_constraints.get_num() 10 >>> c.indicator_constraints.get_num_nonzeros(8) 8 >>> c.indicator_constraints.get_num_nonzeros("1",3) [1, 2, 3] >>> c.indicator_constraints.get_num_nonzeros([2,"0",5]) [2, 0, 5] >>> c.indicator_constraints.get_num_nonzeros() [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
Returns the righthand side of a set of indicator constraints. May be called by four forms.
>>> import cplex >>> c = cplex.Cplex() >>> [c.indicator_constraints.add(rhs=1.5 * i, name=str(i)) for i in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> c.indicator_constraints.get_num() 10 >>> c.indicator_constraints.get_rhs(8) 12.0 >>> c.indicator_constraints.get_rhs("1",3) [1.5, 3.0, 4.5] >>> c.indicator_constraints.get_rhs([2,"0",5]) [3.0, 0.0, 7.5] >>> c.indicator_constraints.get_rhs() [0.0, 1.5, 3.0, 4.5, 6.0, 7.5, 9.0, 10.5, 12.0, 13.5] |
Returns the sense of a set of indicator constraints. May be called by four forms.
>>> import cplex >>> c = cplex.Cplex() >>> [c.indicator_constraints.add(name=str(i), sense=j) ... for i, j in enumerate("EGLE")] [0, 1, 2, 3] >>> c.indicator_constraints.get_num() 4 >>> c.indicator_constraints.get_senses(1) 'G' >>> c.indicator_constraints.get_senses("1",3) ['G', 'L', 'E'] >>> c.indicator_constraints.get_senses([2,"0",1]) ['L', 'E', 'G'] >>> c.indicator_constraints.get_senses() ['E', 'G', 'L', 'E'] |
Returns the type of a set of indicator constraints. See IndicatorType(). May be called by four forms.
>>> import cplex >>> c = cplex.Cplex() >>> idx = c.indicator_constraints.add(name='i1') >>> c.indicator_constraints.get_types(idx) 1 >>> c.indicator_constraints.type_[1] 'if_' |
Returns the linear constraint of a set of indicator constraints. Returns a list of SparsePair instances or a single SparsePair instance, depending on the form by which it was called. May be called by four forms.
>>> import cplex >>> c = cplex.Cplex() >>> indices = c.variables.add( ... names=[str(i) for i in range(4)], ... types="B" * 4 ... ) >>> [c.indicator_constraints.add( ... name=str(i), indvar=3, ... lin_expr=[range(i), [1.0 * (j+1.0) for j in range(i)]]) ... for i in range(3)] [0, 1, 2] >>> c.indicator_constraints.get_num() 3 >>> c.indicator_constraints.get_linear_components(2) SparsePair(ind = [0, 1], val = [1.0, 2.0]) >>> for row in c.indicator_constraints.get_linear_components("0", 1): ... print(row) SparsePair(ind = [], val = []) SparsePair(ind = [0], val = [1.0]) >>> for row in c.indicator_constraints.get_linear_components([1, "0"]): ... print(row) SparsePair(ind = [0], val = [1.0]) SparsePair(ind = [], val = []) >>> for row in c.indicator_constraints.get_linear_components(): ... print(row) SparsePair(ind = [], val = []) SparsePair(ind = [0], val = [1.0]) SparsePair(ind = [0, 1], val = [1.0, 2.0]) |
Returns the names of a set of indicator constraints. May be called by four forms.
>>> import cplex >>> c = cplex.Cplex() >>> [c.indicator_constraints.add(name="i" + str(i)) ... for i in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> c.indicator_constraints.get_num() 10 >>> c.indicator_constraints.get_names(8) 'i8' >>> c.indicator_constraints.get_names(1, 3) ['i1', 'i2', 'i3'] >>> c.indicator_constraints.get_names([2, 0, 5]) ['i2', 'i0', 'i5'] >>> c.indicator_constraints.get_names() ['i0', 'i1', 'i2', 'i3', 'i4', 'i5', 'i6', 'i7', 'i8', 'i9'] |
Trees | Indices | Help |
|
---|