Add an MVar object to a model. An
MVar acts like a NumPy ndarray of Gurobi decision variables.
MVar can have an arbitrary number of dimensions, defined by the
shape: An int, or tuple of int. The shape of the array.
lb (optional): Lower bound(s) for new variables.
ub (optional): Upper bound(s) for new variables.
obj (optional): Objective coefficient(s) for new variables.
vtype (optional): Variable type(s) for new variables.
name (optional): Names for new variables. The given name will be subscripted by the index of the generator expression, so if the index is an integer, c would become c, c, etc. Note that the generated names will be stored as ASCII strings, so you should avoid using names that contain non-ASCII characters. In addition, names that contain spaces are strongly discouraged, because they can't be written to LP format files.
The values of the
arguments can either be scalars, lists, or ndarrays. Their shapes
should match the shape of the new
MVar object, or they should
be broadcastable to the given shape.
name argument can either be a single string, used as a
common base name that will be suffixed for each variable by its
indices, or an ndarray of strings matching the shape of the
New MVar object.
# Add a 4-by-2 matrix binary variable x = model.addMVar((4,2), vtype=GRB.BINARY) # Add a vector of three variables with non-default lower bounds y = model.addMVar((3,), lb=[-1, -2, -1])