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:
gp.quicksum(paramdict.get(k, 0) * v for k, v in vardict.items())
- Parameters:
- paramdictParamDict1D
ParamDict1D to be used for dot product.
- Returns:
- gurobipy.LinExpr
- 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 gurobipy model:
>>> from gurobipy import GRB, Model >>> mdl = Model()
Create index-set:
>>> nodes = IndexSet1D(['A', 'B', 'C'], name='node')
Add variables:
>>> from opti_extensions.gurobipy import addVars >>> node_select = addVars(mdl, nodes, vtype=GRB.BINARY, name='node-select') >>> mdl.update()
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) <gurobi.LinExpr: 100.0 node-select[A] + 200.0 node-select[B] + 0.0 node-select[C]>
>>> fixed_cost @ node_select <gurobi.LinExpr: 100.0 node-select[A] + 200.0 node-select[B] + 0.0 node-select[C]>
>>> node_select @ fixed_cost <gurobi.LinExpr: 100.0 node-select[A] + 200.0 node-select[B] + 0.0 node-select[C]>