Reading and optimizing a model

To access the Gurobi Interactive Shell, you can:

  • Double-click on the Gurobi desktop shortcut.
  • Select the Gurobi Interactive Shell from the Start Menu.
  • Open a DOS command shell and type gurobi.bat.
If you've installed a Python IDE, the shell will also be available from that environment.

Once the optimizer has started, you are ready to load and optimize a model. We'll consider model coins.lp from <installdir>/examples/data...

> gurobi.bat

Set parameter LogFile to value "gurobi.log"

Gurobi Interactive Shell (linux64), Version 10.0.3
Copyright (c) 2023, Gurobi Optimization, LLC
Type "help()" for help

gurobi> m = read("c:/gurobi1003/win64/examples/data/coins.lp")
Read LP format model from file c:/gurobi1003/win64/examples/data/coins.lp

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

gurobi> m.optimize()
Gurobi Optimizer version 10.0.3 build v10.0.3rc0 (win64)

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%

The read() command reads a model from a file and returns a Model object. In the example, that object is placed into variable m. There is no need to declare variables in the Python language; you simply assign a value to a variable.

Note that read() accepts wildcard characters, so you could also have said:

gurobi> m = read("c:/gurobi1003/win64/*/*/coin*")

Note also that Gurobi commands that read or write files will also function correctly with compressed files. If gzip, bzip2, or 7zip are installed on your machine and available in your default path, then you simply need to add the appropriate suffix (.gz, .bz2, .zip, or .7z) to the file name to read or write compressed versions.

The next statement in the example, m.optimize(), invokes the optimize method on the Model object (you can obtain a list of all methods on Model objects by typing help(Model) or help(m)). The node log generated by the optimize() call shows the progress of the optimization. The most prominent measurements of progress are the Incumbent and BestBd values, which track the best solution found so far, and the bound on the best possible solution. For more details on the node log, refer to the MIP Logging section in the Gurobi Reference Manual. The Gurobi optimization engine finds an optimal solution with objective 113.45.

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.