gurobi()

gurobi ( model, params=NULL, env=NULL )

This function optimizes the given model. The algorithm used for the optimization depends on the model type (simplex or barrier for a continuous model; branch-and-cut for a MIP model). Upon successful completion it will return a list variable containing solution information.

Please consult this section for a discussion of some of the practical issues associated with solving a precisely defined mathematical model using finite-precision floating-point arithmetic.

Arguments:

model: The model list must contain a valid Gurobi model. See the model argument section for more information.

params: The params list, when provided, contains a list of modified Gurobi parameters. See the params argument section for more information.

env: The env list, when provided, allows you to use Gurobi Compute Server or Gurobi Instant Cloud. See the env argument section for more information.

Example usage:

result <- gurobi(model, params)
if (result$status == 'OPTIMAL') {
  print(result$objval)
  print(result$x)
} else {
  cat('Optimization returned status:', formatC(result$status), '\n')
}
Return value:

The optimization result

The gurobi function returns a list, with the various results of the optimization stored in its named components. The specific results that are available depend on the type of model that was solved, the parameters used, and the status of the optimization. The following is a list of named components that might be available in the returned result. We will discuss the circumstances under which each will be available after presenting the list.

Model named components:

status
The status of the optimization, returned as a string. The desired result is 'OPTIMAL', which indicates that an optimal solution to the model was found. Other status are possible, for example if the model has no feasible solution or if you set a Gurobi parameter that leads to early solver termination. See the Status Code section for further information on the Gurobi status codes.

objval
The objective value of the computed solution. Note that for multi-objective models result$objval will be a vector, where result$objval[[i]] stores the value for model$multiobj[[i]].

objbound
Best available bound on solution (lower bound for minimization, upper bound for maximization).

objboundc
The best unrounded bound on the optimal objective. In contrast to objbound, this attribute does not take advantage of objective integrality information to round to a tighter bound. For example, if the objective is known to take an integral value and the current best bound is 1.5, ObjBound will return 2.0 while ObjBoundC will return 1.5.

mipgap
Current relative MIP optimality gap; computed as <span>$</span>\vert ObjBound-ObjVal\vert/\vert ObjVal\vert<span>$</span> (where <span>$</span>ObjBound<span>$</span> and <span>$</span>ObjVal<span>$</span> are the MIP objective bound and incumbent solution objective, respectively). Returns GRB_INFINITY when an incumbent solution has not yet been found, when no objective bound is available, or when the current incumbent objective is 0. This is only available for mixed-integer problems.

runtime
The elapsed wall-clock time (in seconds) for the optimization.

itercount
Number of simplex iterations performed.

baritercount
Number of barrier iterations performed.

nodecount
Number of branch-and-cut nodes explored.

farkasproof
Magnitude of infeasibility violation in Farkas infeasibility proof. Only available if the model was found to be infeasible. Please refer to FarkasProof for details.

Variable named components:

x
The computed solution. This vector contains one entry for each column of A.

rc
Variable reduced costs for the computed solution. This vector contains one entry for each column of A.

vbasis
Variable basis status values for the computed optimal basis. You generally should not concern yourself with the contents of this vector. If you wish to use an advanced start later, you would simply copy the vbasis and cbasis named components into the corresponding named components for the next model. This vector contains one entry for each column of A.

unbdray
Unbounded ray. Provides a vector that, when added to any feasible solution, yields a new solution that is also feasible but improves the objective. Only available if the model is found to be unbounded. This vector contains one entry for each column of A.

Linear constraint named components:

slack
The constraint slack for the computed solution. This vector contains one entry for each row of A.

pi
Dual values for the computed solution (also known as shadow prices). This vector contains one entry for each row of A.

cbasis
Constraint basis status values for the computed optimal basis. This vector contains one entry for each row of A.

farkasdual
Farkas infeasibility proof. Only available if the model was found to be infeasible. Please refer to FarkasDual for details.

Quadratic constraint named components:

qcslack
The quadratic constraint slack in the current solution. This vector contains one entry for each quadratic constraint.

qcpi
The dual values associated with the quadratic constraints. This vector contains one entry for each quadratic constraint.

Solution Pool named components:

pool
When multiple solutions are found during the optimization call, these solutions are returned in this named component. A list of lists. When present, each list has the following named components:
objval
Stores the objective value of the <span>$</span>i<span>$</span>-th solution in result$pool[[i]]$objval. Note that when the model is a multi-objective model, instead of a single value,
result$pool[[i]]$objval[j] stores the value of the <span>$</span>j<span>$</span>-th objective function for the <span>$</span>i<span>$</span>-th solution.

xn
Stores the <span>$</span>i<span>$</span>-th solution in result$pool[[i]]$xn. This vector contains one entry for each column of A.
Note that to query the number of solutions stored, you can query the length of result$pool.

poolobjbound
For single-objective MIP optimization problems, this value gives a bound on the best possible objective of an undiscovered solution. The difference between this value and objbound is that the former gives an objective bound for undiscovered solutions, while the latter gives a bound for any solution.

What is Available When

The status named component will be present in all cases. It indicates whether Gurobi was able to find a proven optimal solution to the model. In cases where a solution to the model was found, optimal or otherwise, the objval and x named components will be present.

For linear and quadratic programs, if a solution is available, then the pi and rc named components will also be present. For models with quadratic constraints, if the parameter qcpdual is set to 1, the named component qcpi will be present. If the final solution is a basic solution (computed by simplex), then vbasis and cbasis will be present. If the model is an unbounded linear program and the InfUnbdInfo parameter is set to 1, the named component unbdray will be present. Finally, if the model is an infeasible linear program and the InfUnbdInfo parameter is set to 1, the named components farkasdual and farkasproof will be set.

For mixed integer problems, no dual information (i.e. pi, slack, rc, vbasis, cbasis, qcslack, qcpi, ubdray or farkasdual) is ever available. When multiple solutions are found, the pool and poolobjbound named components will be present. Depending on the status named component value, the named components nodecount, objbound, objbundc and mipgap will be available.

For continuous and mixed-integer models, under normal execution, the named components runtime, itercount and baritercount will be available.

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