Filter Content By
Version

## Using a gurobi.env file

When you want to change the values of Gurobi parameters, you actually have several options available for doing so. 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 we'd like to mention now is the gurobi.env file.

Whenever the Gurobi library starts, it will look for file 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, 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 /Library/gurobi/gurobi.lic
Using gurobi.env file
Set parameter LogFile to value gurobi.log
Set parameter Threads to value 1

Gurobi Optimizer version 9.0.1 build v9.0.1rc0 (mac64)

Copyright (c) 2019, 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 file 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), the value from gurobi.env will be overridden.

The distribution includes a sample gurobi.env file (in the bin directory). The sample includes every parameter, with the default value for each, but with all settings commented out.