When you want to change the values of Gurobi parameters, you have several options.
Setting parameters
From the Python API
You have several options to set parameters in the Python interface. Here are a few options to set the TimeLimit parameter:
m.Params.TimeLimit = 100.0
m.setParam(GRB.Param.TimeLimit, 100.0)
m.setParam("TimeLimit", 100.0)
For more details, please see Python Parameter Examples.
From other language APIs
For details for each API, please see the Parameter Examples section of the Reference Manual.
C |
error = GRBsetdblparam(GRBgetenv(model), GRB_DBL_PAR_TIMELIMIT, 100.0); For more details and how to set parameters of other types, please see C Parameter Examples.
|
|
C++ |
GRBModel *m = ...; For more details and how to set parameters of other types, please see C++ Parameter Examples.
|
|
C# |
GRBModel m = ...; m.Parameters.TimeLimit = 100.0; For more details and how to set parameters of other types, please see C# Parameter Examples.
|
|
Java |
GRBModel m = ...; m.set(GRB.DoubleParam.TimeLimit, 100.0); For more details and how to set parameters of other types, please see Java Parameter Examples.
|
|
Matlab |
params.timelimit = 100; For more details, please see MATLAB Parameter Examples.
|
|
R |
params <- list(TimeLimit=100) For more details, please see R Parameter Examples.
|
|
Visual Basic |
GRBModel m = ... m.Parameters.TimeLimit = 100.0 For more details, please see Visual Basic Parameter Examples
|
Using the command-line interface (gurobi_cl)
For example:
> gurobi_cl Threads=1 /opt/gurobi1001/linux64/examples/data/coins.lp
For further details, see How do I use the Gurobi Command Line Interface (gurobi_cl)?
Using a gurobi.env file
Another 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/gurobi1001/linux64/examples/data/coins.lp
Set parameter Threads to value 1
Read parameters from file gurobi.env
Set parameter LogFile to value "gurobi.log"
Using license file /opt/gurobi/gurobi.lic
Using gurobi.env file
Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (linux64 - "Ubuntu 20.04.6 LTS")
Copyright (c) 2023, Gurobi Optimization, LLC
Read LP format model from file /opt/gurobi1001/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.
Note: 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, an example is the parameter ConcurrentSettings.
In the interactive shell (gurobi.sh)
For example:
gurobi> m.setParam('Threads', 1)
For further details, see gurobi.sh: Changing Parameters. Please note that starting with version 11.0.2, the Gurobi Interactive Shell has been deprecated.
Comments
0 comments
Article is closed for comments.