dot#

VarDict1D.dot(paramdict)[source]#

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

Assumes the coef to be zero if not found in the ParamDict1D.

Equivalent to:

model.sum(paramdict.get(k, 0) * v for k, v in vardict.items())
Parameters:
paramdictParamDict1D

ParamDict1D to be used for dot product.

Returns:
docplex.mp.linear.LinearExpr or docplex.mp.linear.ZeroExpr
Raises:
TypeError

If the paramdict is not as instance of ParamDict1D.

Notes

This method is equivalent to using the matrix multiplication operator @.

Both ParamDict1D @ VarDict1D and VarDict1D @ ParamDict1D will also produce the same result.

Examples

Create DOcplex model:

>>> from docplex.mp.model import Model
>>> mdl = Model()

Create index-set:

>>> nodes = IndexSet1D(['A', 'B', 'C'], name='node')

Add variables:

>>> from opti_extensions.docplex import add_variables
>>> node_select = add_variables(mdl, nodes, 'B', name='node-select')

Define parameter:

>>> from opti_extensions import ParamDict1D
>>> fixed_cost = ParamDict1D({'A': 100, 'B': 200})

Compute dot product (three alternative ways):

>>> node_select.dot(fixed_cost)
docplex.mp.LinearExpr(100node-select_A+200node-select_B)
>>> fixed_cost @ node_select
docplex.mp.LinearExpr(100node-select_A+200node-select_B)
>>> node_select @ fixed_cost
docplex.mp.LinearExpr(100node-select_A+200node-select_B)