Solving a Model

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 compressed using gzip, bzip2, or 7z. See the File Format discussion for more information on accepted formats.

The most basic command-line command is the following:

gurobi_cl model.mps
This 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. For example:

gurobi_cl Method=2 TimeLimit=100 model.mps
The full set of Gurobi parameters is described in the Parameter section.

Gurobi Compute Server users can add the --server= switch to specify a server. For example, the command:

gurobi_cl --server=server1 Method=2 TimeLimit=100 model.mps
would solve the model stored in file model.mps on machine server1, assuming it is running Gurobi Compute Server. If the Compute Server has an access password, use the --password= switch to specify it.

Writing Result Files

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.mps
The 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 write a .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:

  • the subsystem represented by the IIS is infeasible, and
  • if any of the constraints or bounds of the IIS is removed, the subsystem becomes feasible.
Note that an infeasible model may have multiple IISs. The one returned by Gurobi is not necessarily one of minimal cardinality. Thus, there may exist other IISs with fewer constraints or bounds.

If an IIS computation is interrupted before completion, Gurobi will internally store the best available IIS found so far.

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.mps
Gurobi can write compressed files directly, so this command would also work (assuming that 7zip is installed on your machine):
gurobi_cl TimeLimit=0 ResultFile=model.lp.7z model.mps

The 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.mps
will write two files.

Reading Input Files

You can use the InputFile parameter to read input files during the optimization. The most common input formats are .bas (a simplex basis), .mst (a MIP start), .sol (also a MIP start), .hnt (MIP hints), and .ord (a MIP priority order). For example, the following command:

gurobi_cl InputFile=model.bas model.mps
would start the optimization of the continuous model stored in file model.mps using the basis provided in file model.bas.

Reading input files is equivalent to setting the values of Gurobi attributes. A .bas file populates the VBasis and CBasis attributes, while a .ord file populates the BranchPriority attribute. A .mst or .sol file populates the Start attribute. A .hnt file populates the VarHintVal and VarHintPri attributes.

Again, you should consult the File Formats section for more information on supported file formats

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