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:

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

ParamDict1D to be used for dot product.

Returns:
highspy.highs_linear_expression
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 highspy model:

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

Create index-set:

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

Add variables:

>>> from opti_extensions.highspy import addVariables
>>> node_select = addVariables(
...     mdl, nodes, type=HighsVarType.kInteger, lb=0, ub=1, name_prefix='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)
100.0_v0  200.0_v1  0.0_v2
>>> fixed_cost @ node_select
100.0_v0  200.0_v1  0.0_v2
>>> node_select @ fixed_cost
100.0_v0  200.0_v1  0.0_v2