lookup#

VarDictND.lookup(*key)[source]#

Get the variable for the specified key, or zero if it is not found.

Parameters:
*keykey
Returns:
gurobipy.Var or 0

Examples

Create gurobipy model:

>>> from gurobipy import GRB, Model
>>> mdl = Model()

Create index-set:

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

Add variables:

>>> from opti_extensions.gurobipy import addVars
>>> arc_flow = addVars(mdl, arcs, ub=10, vtype=GRB.CONTINUOUS, name='arc-flow')
>>> mdl.update()

Lookup with keys:

>>> arc_flow.lookup('A', 'B')
<gurobi.Var arc-flow[A,B]>
>>> arc_flow.lookup('X', 'Y')
0