Try our new documentation site (beta).


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:

  • It is still infeasible, and
  • If a single constraint or bound is removed, the subsystem becomes feasible.
Note that an infeasible model may have multiple IISs. The one returned by Gurobi is not necessarily the smallest one; there may exist others with fewer constraints or bounds.

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.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

Gurobi Optimization