# Reading and optimizing a model

Filter Content By
Version
Languages

## Reading and optimizing a model

There are several ways to access the Gurobi Interactive Shell from Windows:

• 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.
From Linux or Mac OS, you can simply type gurobi.sh from the command prompt. 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 (or gurobi.sh for Linux or Mac OS)

Gurobi Interactive Shell, Version 6.5.0
Copyright (c) 2015, Gurobi Optimization, Inc.
Type "help()" for help

Read LP format model from file c:/gurobi650/win64/examples/data/coins.lp
(null): 4 rows, 9 columns, 16 nonzeros
gurobi> m.optimize()
Optimize a model with 4 rows, 9 columns and 16 nonzeros
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
Found heuristic solution: objective 113.3000000

Root relaxation: objective 1.134615e+02, 4 iterations, 0.00 seconds

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

0     0  113.46154    0    1  113.30000  113.46154  0.14%     -    0s
0     0  113.45952    0    1  113.30000  113.45952  0.14%     -    0s
H    0     0                     113.4500000  113.45952  0.01%     -    0s

Explored 0 nodes (5 simplex iterations) in 0.00 seconds
Thread count was 4 (of 4 available processors)

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


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:/gurobi650/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 Gurobi optimization engine finds an optimal solution with objective 113.45.