The command-line tool provides an easy way to solve a model stored in
a file. The model can be stored in several different formats,
including MPS, REW, LP, and RLP, and the file can optionally be
7z. See the
File Format discussion for more
information on accepted formats.
The most basic command-line command is the following:
gurobi_cl model.mpsThis will read the model from the indicated file, optimize it, and display the Gurobi log file as the solve proceeds.
You can optionally include an arbitrary number of
parameter=value commands before the name of the file.
gurobi_cl Method=2 TimeLimit=100 model.mpsThe full set of Gurobi parameters is described in the Parameter section.
Gurobi Compute Server users can add the
to specify a server. For example, the command:
gurobi_cl --server=server1 Method=2 TimeLimit=100 model.mpswould solve the model stored in file
server1, assuming it is running Gurobi Compute Server. If the Compute Server has an access password, use the
--password=switch to specify it.
Gurobi Instant Cloud users can add the
--pool= switches to run a model on a
cloud instance. For example, the command:
gurobi_cl --accessid=0f5e0ace-f929-a919-82d5-02272b3b0e19 \ --secretkey=8EDZOIf7T9avp0ZHef9Tsw --pool=mypool model.mpswould solve the model stored in file
model.mpson cloud pool
mypoolusing the provided access ID and secret key. If the pool isn't currently active, it will launch it first.
While it is often useful to simply solve a model and display the log, it is also common to want to review the resulting solution. You can use the ResultFile parameter to write the solution to a file:
gurobi_cl ResultFile=model.sol model.mpsThe file name suffix determines the type of file written. Useful file formats for solution information are
.sol(for solution vectors) and
.bas(for simplex basis information). Again, you should consult the section on File Formats for a list of the supported formats
If you have an infeasible model, you may want to examine a
corresponding Irreducible Inconsistent Subsystem (IIS) to identify the
cause of the infeasibility. You can ask the command-line tool to
.ilp format file. It will attempt to solve the model,
and if the model is found to be infeasible, it will automatically
compute an IIS and write it to the requested file name.
An IIS is a subset of the constraints and variable bounds with the following properties:
- It is still infeasible, and
- If a single constraint or bound is removed, the subsystem becomes feasible.
IIS results are returned in a number of attributes: IISConstr, IISLB, IISUB, IISSOS, IISQConstr, and IISGenConstr. Each indicates whether the corresponding model element is a member of the computed IIS.
Note that for models with general function constraints, piecewise-linear approximation of the constraints may cause unreliable IIS results.
The IIS log provides information about the progress of the algorithm, including a guess at the eventual IIS size.
If an IIS computation is interrupted before completion, Gurobi will return the smallest infeasible subsystem found to that point.
The IISConstrForce, IISLBForce, IISUBForce, IISSOSForce, IISQConstrForce, and IISGenConstrForce attributes allow you mark model elements to either include or exclude from the computed IIS. Setting the attribute to 1 forces the corresponding element into the IIS, setting it to 0 forces it out of the IIS, and setting it to -1 allows the algorithm to decide.
To give an example of when these attributes might be useful, consider the case where an initial model is known to be feasible, but it becomes infeasible after adding constraints or tightening bounds. If you are only interested in knowing which of the changes caused the infeasibility, you can force the unmodified bounds and constraints into the IIS. That allows the IIS algorithm to focus exclusively on the new constraints, which will often be substantially faster.
Note that setting any of the
Force attributes to 0 may make the
resulting subsystem feasible, which would then make it impossible to
construct an IIS. Trying anyway will result in a
GRB_ERROR_IIS_NOT_INFEASIBLE error. Similarly, setting this
attribute to 1 may result in an IIS that is not irreducible. More
precisely, the system would only be irreducible with respect to the
model elements that have force values of -1 or 0.
Another use of
ResultFile is to translate between file formats.
For example, if you want to translate a model from MPS format to LP
format, you could issue the following command:
gurobi_cl TimeLimit=0 ResultFile=model.lp model.mpsGurobi can write compressed files directly, so this command would also work (assuming that
7zipis installed on your machine):
gurobi_cl TimeLimit=0 ResultFile=model.lp.7z model.mps
ResultFile parameter works differently from other
parameters in the command-line interface. While a parameter normally
takes a single value, you can actually specify multiple result files.
For example, the following command:
gurobi_cl ResultFile=model.sol ResultFile=model.bas model.mpswill write two files.
You can use the InputFile
parameter to read input files during the optimization. The most
common input formats are
.bas (a simplex basis),
.sol (also a MIP start),
.hnt (MIP hints),
.ord (a MIP priority order).
For example, the following command:
gurobi_cl InputFile=model.bas model.mpswould start the optimization of the continuous model stored in file
model.mpsusing the basis provided in file
Reading input files is equivalent to setting the values of Gurobi
.bas file populates the
CBasis attributes, while a
file populates the BranchPriority
.sol file populates the
.hnt file populates the
Again, you should consult the File Formats section for more information on supported file formats