Filter Content By
Version

## Solving the model using the Gurobi command-line interface

The final step in solving our optimization problem is to pass the model to the Gurobi Optimizer. We'll use the Gurobi command-line interface, as it is typically the simplest of our interfaces to use when solving a model stored in a file.

To use the command-line interface, you'll first need to open a Console window. If you are unfamiliar with running command-line commands on a Windows system, you can learn more here. (Note that the Gurobi Interactive Shell, which was used earlier to test your license, does not directly accept command-line program input).

The name of the Gurobi command-line tool is gurobi_cl. To invoke it, type gurobi_cl, followed by the name of the model file. For example, if our model is stored in the file c:\gurobi1003\win64\examples\data\coins.lp, you would type the following command into your command-line window...

> gurobi_cl c:\gurobi1003\win64\examples\data\coins.lp

This command should produce the following output...

Set parameter LogFile to value "gurobi.log"

Gurobi Optimizer version 10.0.3 build v10.0.3rc0 (win64)
Copyright (c) 2023, Gurobi Optimization, LLC

Read LP format model from file c:/gurobi1003/win64/examples/data/coins.lp

Reading time = 0.00 seconds
: 4 rows, 9 columns, 16 nonzeros

CPU model: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz, instruction set [SSE2]
Thread count: 4 physical cores, 4 logical processors, using up to 4 threads

Optimize a model with 4 rows, 9 columns and 16 nonzeros
Model fingerprint: 0x06e334a4
Variable types: 4 continuous, 5 integer (0 binary)
Coefficient statistics:
Matrix range     [6e-02, 7e+00]
Objective range  [1e-02, 1e+00]
Bounds range     [5e+01, 1e+03]
RHS range        [0e+00, 0e+00]
Found heuristic solution: objective -0.0000000
Presolve removed 1 rows and 5 columns
Presolve time: 0.00s
Presolved: 3 rows, 4 columns, 9 nonzeros
Variable types: 0 continuous, 4 integer (0 binary)
Found heuristic solution: objective 26.1000000

Root relaxation: objective 1.134615e+02, 2 iterations, 0.00 seconds (0.00 work units)

Nodes    |    Current Node    |     Objective Bounds      |     Work
Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

0     0  113.46153    0    1   26.10000  113.46153   335%     -    0s
H    0     0                     113.3000000  113.46153  0.14%     -    0s
H    0     0                     113.4500000  113.46153  0.01%     -    0s
0     0  113.46153    0    1  113.45000  113.46153  0.01%     -    0s

Explored 1 nodes (2 simplex iterations) in 0.00 seconds (0.00 work units)
Thread count was 4 (of 4 available processors)

Solution count 4: 113.45 113.3 26.1 -0

Optimal solution found (tolerance 1.00e-04)
Best objective 1.134500000000e+02, best bound 1.134500000000e+02, gap 0.0000%

Details on the format of the Gurobi log file can be found in the Gurobi Reference Manual. For now, you can simply note that the optimal objective value is 113.45. Recall that the objective is denoted in dollars. We can therefore conclude that by a proper choice of production plan, the Mint can produce $113.45 worth of coins using the available minerals. Moreover, because this value is optimal, we know that it is not possible to produce coins with value greater than$113.45!

It would clearly be useful to know the exact number of each coin produced by this optimal plan. The gurobi_cl command allows you to set Gurobi parameters through command-line arguments. One particularly useful parameter for the purposes of this example is ResultFile, which instructs the Gurobi Optimizer to write a file once optimization is complete. The type of the file is encoded in the suffix. To request a .sol file:

> gurobi_cl ResultFile=coins.sol c:\gurobi1003\win64\examples\data\coins.lp

The command will produce a file that contains solution values for the variables in the model:

# Objective value = 113.45
Pennies 0
Nickels 0
Dimes 2
Quarters 53
Dollars 100
Cu 999.8
Ni 46.9
Zi 50
Mn 30

In the optimal solution, we'll produce 100 dollar coins, 53 quarters, and 2 dimes.

If we wanted to explore the parameters of the model (for example, to consider how the optimal solution changes with different quantities of available minerals), we could use a text editor to modify the input file. However, it is typically better to do such tests within a more powerful system. We'll now describe the Gurobi Interactive Shell, which provides an environment for creating, modifying, and experimenting with optimization models.

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

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