Documentation

Solving a Model


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.

Gurobi Instant Cloud users can add the --accessid=, --secretkey=, and --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.mps
would solve the model stored in file model.mps on cloud pool mypool using the provided access ID and secret key. If the pool isn't currently active, it will launch it first.

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 the one with minimum cardinality; there may exist others with fewer constraints or bounds.

If an IIS computation is interrupted before completion, Gurobi will return the smallest IIS found to that point.

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