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
> gurobi_cl Threads=1 /opt/gurobi1003/linux64/examples/data/coins.lp
and through interactive shellcommands
gurobi> 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 /opt/gurobi1003/linux64/examples/data/coins.lp
Using license file /opt/gurobi/gurobi.lic
Using gurobi.env file
Set parameter Threads to value 1
Set parameter LogFile to value "gurobi.log"
Gurobi Optimizer version 10.0.3 build v10.0.3rc0 (linux64)
Copyright (c) 2023, Gurobi Optimization, LLC
Read LP format model from file /opt/gurobi1003/linux64/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 1 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 1 (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%
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.