Try our new documentation site (beta).


Model.addVar()

addVar ( lb=0.0, ub=GRB.INFINITY, obj=0.0, vtype=GRB.CONTINUOUS, name="", column=None )

Add a decision variable to a model.

Arguments:

lb (optional): Lower bound for new variable.

ub (optional): Upper bound for new variable.

obj (optional): Objective coefficient for new variable.

vtype (optional): Variable type for new variable (GRB.CONTINUOUS, GRB.BINARY, GRB.INTEGER, GRB.SEMICONT, or GRB.SEMIINT).

name (optional): Name for new variable. Note that name will be stored as an ASCII string. Thus, a name like 'A<span>$</span>{\rightarrow}<span>$</span>B' will produce an error, because '<span>$</span>{\rightarrow}<span>$</span>' can not be represented as an ASCII character. Note also that names that contain spaces are strongly discouraged, because they can't be written to LP format files.

column (optional): Column object that indicates the set of constraints in which the new variable participates, and the associated coefficients.

Return value:

New variable object.

Example usage:

  x = model.addVar()                                     # all default arguments
  y = model.addVar(vtype=GRB.INTEGER, obj=1.0, name="y") # arguments by name
  z = model.addVar(0.0, 1.0, 1.0, GRB.BINARY, "z")       # arguments by position

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.

Search

Gurobi Optimization