dot#

VarDictND.dot(paramdict)[source]#

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

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

Equivalent to:

highspy.Highs.qsum(paramdict.get(k, 0) * v for k, v in vardict.items())
Parameters:
paramdictParamDictND

ParamDictND to be used for dot product; should have tuple keys of same length as VarDictND.

Returns:
highspy.highs_linear_expression
Raises:
TypeError

If the paramdict is not as instance of ParamDictND.

ValueError

If the paramdict does not have tuple keys of same length as VarDictND.

Notes

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

Both ParamDictND @ VarDictND and VarDictND @ ParamDictND will also produce the same result.

Examples

Create highspy model:

>>> from highspy import Highs, HighsVarType
>>> mdl = Highs()

Create index-set:

>>> arcs = IndexSetND([('A', 'B'), ('B', 'C'), ('C', 'B')], names=['ori', 'des'])

Add variables:

>>> from opti_extensions.highspy import addVariables
>>> arc_flow = addVariables(
...     mdl, arcs, ub=10, type=HighsVarType.kContinuous, name_prefix='arc-flow_'
... )

Define parameter:

>>> from opti_extensions import ParamDictND
>>> cost = ParamDictND({('A', 'B'): 10, ('B', 'C'): 20})

Compute dot product (three alternative ways):

>>> arc_flow.dot(cost)
10.0_v0  20.0_v1  0.0_v2
>>> cost @ arc_flow
10.0_v0  20.0_v1  0.0_v2
>>> arc_flow @ cost
10.0_v0  20.0_v1  0.0_v2