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:
xp.Sum(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:
- xp.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 @ VarDictNDandVarDictND @ ParamDictNDwill also produce the same result.Examples
Create xpress problem:
>>> import xpress as xp >>> import warnings >>> warnings.filterwarnings('ignore', category=xp.LicenseWarning)
>>> prob = xp.problem()
Create index-set:
>>> arcs = IndexSetND([('A', 'B'), ('B', 'C'), ('C', 'B')], names=['ori', 'des'])
Add variables:
>>> from opti_extensions.xpress import addVariables >>> arc_flow = addVariables(prob, arcs, name='arc-flow', ub=10, vartype=xp.continuous)
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 * arc-flow(('A', 'B')) + 20 * arc-flow(('B', 'C'))
>>> cost @ arc_flow 10 * arc-flow(('A', 'B')) + 20 * arc-flow(('B', 'C'))
>>> arc_flow @ cost 10 * arc-flow(('A', 'B')) + 20 * arc-flow(('B', 'C'))