# docplex.mp.dvar module¶

class docplex.mp.dvar.Var[source]

Bases: docplex.mp.basic.IndexableObject, docplex.mp.operand.LinearOperand, docplex.mp.basic._AbstractBendersAnnotated, docplex.mp.basic._AbstractValuable

This class models decision variables. Decision variables are instantiated by docplex.mp.model.Model methods such as docplex.mp.model.Model.var().

basis_status

This property returns the basis status of the variable, if any. The variable must be continuous, otherwise an exception is raised.

Returns: An enumerated value from the enumerated type docplex.constants.BasisStatus.

Note

for the model to hold basis information, the model must have been solved as a LP problem. In some cases, a model which failed to solve may still have a basis available. Use Model.has_basis() to check whether the model has basis information or not.

benders_annotation

This property is used to get or set the Benders annotation of a variable. The value of the annotation must be a positive integer

equals(other)[source]

This method is used to test equality to an expression. Because of the overloading of operator == through the redefinition of the __eq__ method, you cannot use == to test for equality. In order to test that two decision variables ar ethe same, use th Python is operator; use the equals method to test whether a given expression is equivalent to a variable: for example, calling equals with a linear expression which consists of this variable only, with a coefficient of 1, returns True.

Parameters: other – an expression or a variable. A boolean value, True if the passed variable is this very variable, or if the passed expression is equivalent to the variable, else False.
get_key()[source]

Returns the key used to create the variable, or None.

When the variable is part of a list or dictionary of variables created from a sequence of keys, returns the key associated with the variable.

Example

xs = m.continuous_var_dict(keys=[‘a’, ‘b’, ‘c’]) xa = xs[‘a’] assert xa.get_key() == ‘a’

Returns: a Python object, possibly None.
is_binary()[source]

Checks if the variable is binary.

Returns: True if the variable is of type Binary. Boolean
is_continuous()[source]

Checks if the variable is continuous.

Returns: True if the variable is of type Continuous. Boolean
is_discrete()[source]

Checks if the variable is discrete.

Returns: True if the variable is of type Binary or Integer. Boolean
is_integer()[source]

Checks if the variable is integer.

Returns: True if the variable is of type Integer. Boolean
iter_constraints()[source]

Returns an iterator traversing all constraints in which the variable is used.

Returns: An iterator.
lb

This property is used to get or set the lower bound of the variable.

Possible values for the lower bound depend on the variable type. Binary variables accept only 0 or 1 as bounds. An integer variable will convert the lower bound value to the ceiling integer value of the argument.

name

This property is used to get or set the name of the modeling object.

reduced_cost

Returns the reduced cost of the variable.

This method will raise an exception if the model has not been solved as a LP.

Note:
For a large number of variables (> 100), using the Model.reduced_costs() method can be much faster.
Returns:
The reduced cost of the variable (a float value).

solution_value

This property returns the solution value of the variable.

Raises: DOCplexException – if the model has not been solved succesfully.
sv

Same as solution_value but shorter

to_bool(precision=1e-06)[source]

Converts a variable value to True or False.

Assuming the variable is discrete (integer or binary), returns True if the variable value is set a non-zero integer, taking into account precision. For binary variables, returns TRue if the variable value equals 1, taking into account precision.

Raises: DOCplexException – if the model has not been solved successfully. DOCplexException – if the variable is not discrete True if the variable value is nonzero, else False. Boolean
ub

This property is used to get or set the upper bound of the variable.

Possible values for the upper bound depend on the variable type. Binary variables accept only 0 or 1 as bounds. An integer variable will convert the upper bound value to the floor integer value of the argument.

To reset the upper bound to its default infinity value, use docplex.mp.model.Model.infinity().

vartype

This property returns the variable type, an instance of VarType`.