Using a gurobi.env file

When you want to change the values of Gurobi parameters, you actually have several options. We've already discussed parameter changes through the command-line tool (e.g., gurobi_cl Threads=1 coins.lp), and through interactive shell commands (e.g., m.setParam('Threads', 1)). Each of our language APIs also provides methods for setting parameters. The other option is through a gurobi.env file.

Whenever the Gurobi library starts, it will look for gurobi.env in the current working directory, and will apply any parameter changes contained therein. This is true whether the Gurobi library is invoked from the command-line tool, from the interactive shell, or from any of the Gurobi APIs. Parameter settings are stored one per line in this file, with the parameter name first, followed by at least one space, followed by the desired value. Lines beginning with the # sign are comments and are ignored. To give an example, the following (Linux) commands:

> echo "Threads 1" > gurobi.env
> gurobi_cl coins.lp
Using license file /opt/gurobi/gurobi.lic
Using gurobi.env file
Set parameter LogFile to value gurobi.log
Set parameter Threads to value 1

Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (linux64)

Copyright (c) 2020, Gurobi Optimization, LLC

Read LP format model from file coins.lp
Reading time = 0.00 seconds
: 4 rows, 9 columns, 16 nonzeros
Optimize a model with 4 rows, 9 columns and 16 nonzeros
Model fingerprint: 0xa0c5449c
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)

Root relaxation: objective 1.134615e+02, 2 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   -0.00000  113.46154      -     -    0s
H    0     0                     113.4500000  113.46154  0.01%     -    0s
     0     0  113.46154    0    1  113.45000  113.46154  0.01%     -    0s

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

Solution count 2: 113.45 -0

Optimal solution found (tolerance 1.00e-04)
Best objective 1.134500000000e+02, best bound 1.134500000000e+02, gap 0.0000%
would read the new value of the Threads parameter from gurobi.env and then optimize model coins.lp using one thread. Note that if the same parameter is changed in both gurobi.env and in your program (or through the Gurobi command-line tool), the value from gurobi.env will be overridden.

A few parameters can only be used from the Gurobi command-line tool, and thus can't be set through gurobi.env. These parameters are labeled 'Command-line only' in the Parameter section of the Gurobi Reference Manual.

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.