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:
xp.Sum(paramdict.get(k, 0) * v for k, v in vardict.items())
- Parameters:
- paramdictParamDict1D
ParamDict1D to be used for dot product.
- Returns:
- xp.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 @ VarDict1DandVarDict1D @ ParamDict1Dwill 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:
>>> nodes = IndexSet1D(['A', 'B', 'C'], name='node')
Add variables:
>>> from opti_extensions.xpress import addVariables >>> node_select = addVariables(prob, nodes, name='node-select', vartype=xp.binary)
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 * node-select(A) + 200 * node-select(B)
>>> fixed_cost @ node_select 100 * node-select(A) + 200 * node-select(B)
>>> node_select @ fixed_cost 100 * node-select(A) + 200 * node-select(B)