Printing the solution
The gurobi()
function returns a struct
as its result.
This struct contains a number of fields, where each field contains
information about the computed solution. The available fields depend
on the result of the optimization, the type of model that was solved
(LP, QP, QCP, SOCP, or MIP), and the algorithm used to solve the model.
The returned struct
will always contain a status
field,
which indicates whether Gurobi was able to compute an optimal solution
to the model. You should consult the Status Codes section of
the Gurobi Reference Manual
for a complete list of all possible status codes. If Gurobi was able
to find a solution to the model, the return value will also include
objval
and x
fields. The former gives the
objective value for the computed solution, and the latter is the
computed solution vector (one entry per column of the constraint
matrix). For continuous models, we will also return dual information
(reduced costs and dual multipliers), and possibly an optimal basis.
For a list of all possible fields and details about when you will
find them populated, refer to the documentation for the
gurobi()
function in the reference manual.
In our example, we simply print the optimal objective value
(result.objval
)
and the optimal solution vector
(result.x
).