Try our new documentation site (beta).
Env()
Env ( logfilename=””, empty=False, params=None )
Env constructor. You will generally want to use the default environment in Gurobi Python programs. The exception is when you want explicit control over environment garbage collection. By creating your own environment object and always passing it to methods that take an environment as input (read or the Model constructor), you will avoid creating the default environment. Once every model created using an Env object is garbage collected, and once the Env object itself is no longer referenced, the garbage collector will reclaim the environment and release all associated resources.
If the environment is not empty, This method will also populate any parameter (ComputeServer, TokenServer, ServerPassword, etc.) specified in your gurobi.lic file. This method will also check the current working directory for a file named gurobi.env, and it will attempt to read parameter settings from this file if it exists. The file should be in PRM format (briefly, each line should contain a parameter name, followed by the desired value for that parameter).
In general, you should aim to create a single Gurobi environment in your program, even if you plan to work with multiple models. Reusing one environment is much more efficient than creating and destroying multiple environments. The one exception is if you are writing a multi-threaded program, since environments are not thread safe. In this case, you will need a separate environment for each of your threads.
Arguments:
logfilename: Name of the log file for this environment. Pass an empty string if you don't want a log file.
empty: Indicates whether the environment should be empty. You should use empty=True if you want to set parameters before actually starting the environment. This can be useful if you want to connect to a Compute Server, a Token Server, the Gurobi Instant Cloud or a Cluster Manager. See the Environment Section for more details.
params: A dict containing Gurobi parameter/value pairs that should be set already upon environment creation. Any server related parameters can be set through this dict, too.
Return value:
New environment object.
Example usage:
env = Env("gurobi.log") m = read("misc07.mps", env) m.optimize()
Example usage:
p = {"ComputeServer": "localhost:33322", "ServerPassword": "pass", "TimeLimit": 120.0} with Env(params=p) as env, read('misc07.mps', env=env) as model: model.optimize()