DOcplex variable functionality#

Note

Provided through opti_extensions.docplex.* namespace.

Add variable(s)#

add_variable(model, vartype[, lb, ub, name])

Create and add a single variable to the DOcplex model.

add_variables(model, indexset, vartype[, ...])

Create and add multiple variables (corresponding to an index-set) to the DOcplex model.

VarDict1D#

Custom subclass of dict to store DOcplex model variables with 1-dim scalar keys.

VarDict1D

This class is not meant to be instantiated; VarDict1D is built through the opti_extensions.docplex.add_variables function.

Attributes#

VarDict1D.model

The DOcplex model associated with the variables.

VarDict1D.vartype

The DOcplex VarType corresponding to the variables.

VarDict1D.key_name

Name to refer to 1-dim scalar keys.

VarDict1D.value_name

Name to refer to Dict values.

Numerical operations#

VarDict1D.sum()

Sum all variables in an expression.

VarDict1D.sum_squares()

Sum squares of all variables in an expression.

VarDict1D.dot(paramdict)

Sum the products of variables with corresponding coef from ParamDict1D, in an expression.

The @ operator#

The matrix multiplication operator @ can be used instead of the dot method. Both ParamDict1D @ VarDict1D and VarDict1D @ ParamDict1D will produce the same result as VarDict1D.dot(ParamDict1D).

Mapping operations#

VarDict1D.get(key[, default])

Get the variable for the specified key, or the default if not found.

VarDict1D.lookup(key)

Get the variable for the specified key, or zero if it is not found.

Views#

  • VarDict1D.items()

  • VarDict1D.keys()

  • VarDict1D.values()

VarDictND#

Custom subclass of dict to store DOcplex model variables with N-dim tuple keys.

VarDictND

This class is not meant to be instantiated; VarDictND is built through the opti_extensions.docplex.add_variables function.

Attributes#

VarDictND.model

The DOcplex model associated with the variables.

VarDictND.vartype

The DOcplex VarType corresponding to the variables.

VarDictND.key_names

Names to refer to each dimension of N-dim tuple keys.

VarDictND.value_name

Name to refer to Dict values.

Numerical operations#

VarDictND.sum(*pattern)

Sum all variables, or a subset based on wildcard pattern, in an expression.

VarDictND.sum_squares(*pattern)

Sum squares of all variables, or a subset based on wildcard pattern, in an expression.

VarDictND.dot(paramdict)

Sum the products of variables with corresponding coef from ParamDictND, in an expression.

The @ operator#

The matrix multiplication operator @ can be used instead of the dot method. Both ParamDictND @ VarDictND and VarDictND @ ParamDictND will produce the same result as VarDictND.dot(ParamDictND).

Mapping operations#

VarDictND.get(key[, default])

Get the variable for the specified key, or the default if not found.

VarDictND.lookup(*key)

Get the variable for the specified key, or zero if it is not found.

Efficient subset selection#

VarDictND.subset_keys(*pattern)

Get a subset of the N-dim tuple keys of the Dict with a wildcard pattern.

VarDictND.subset_values(*pattern)

Get Dict values for all keys that match the wildcard pattern.

Views#

  • VarDictND.items()

  • VarDictND.keys()

  • VarDictND.values()