Global Functions#
Gurobi global functions. These functions can be accessed from the main Gurobi shell prompt. In contrast to all other methods in the Gurobi Python interface, these functions do not require a Gurobi object to invoke them.
- disposeDefaultEnv()#
Dispose of the default environment.
Calling this function releases the default environment created by the Gurobi Python module. This function is particularly useful in a long-running Python session (e.g., within a Jupyter notebook), where the Gurobi environment would otherwise continue to exist for the full duration of the session.
Note that models built with the default environment must be garbage collected before the default environment can be freed. You can force a model
mto be garbage collected with the statementdel m. A call todisposeDefaultEnvprints the messageFreeing default Gurobi environment
and then attempts to free the default environment. Note however that this attempt may fail if some models referencing the default environment have not yet been disposed of. If that is the case, the default environment will be automatically freed when the last model referencing it is disposed of.
- Example:
gp.disposeDefaultEnv()
- multidict(data)#
This function splits a single dictionary into multiple dictionaries. The input dictionary should map each key to a list of
nvalues. The function returns a list of the shared keys as its first result, followed by thenindividual Gurobi tuple dictionaries (stored astupledictobjects).- Parameters:
data – A Python dictionary. Each key should map to a list of values.
- Returns:
A list, where the first member contains the shared key values, and the following members contain the dictionaries that result from splitting the value lists from the input dictionary.
- Example:
keys, dict1, dict2 = gp.multidict( { 'key1': [1, 2], 'key2': [1, 3], 'key3': [1, 4] } )
- paramHelp(paramname)#
Obtain help about a Gurobi parameter.
- Parameters:
paramname – String containing the name of parameter that you would like help with. The name can include ‘*’ and ‘?’ wildcards. If more than one parameter matches, the matching names are listed. Note that case is ignored.
- Example:
gp.paramHelp("Cuts") gp.paramHelp("Heu*") gp.paramHelp("*cuts")
- quicksum(data)#
A version of the Python
sumfunction that is much more efficient for building large Gurobi expressions (LinExprorQuadExprobjects). The function takes a list of terms as its argument.Note that while
quicksumis much faster thansum, it isn’t the fastest approach for building a large expression. UseaddTermsor theLinExpr()constructor if you want the quickest possible expression construction.
- read(filename, env=defaultEnv)#
Read a model from a file.
- Parameters:
filename – Name of file containing model. Note that the type of the file is encoded in the file name suffix. Valid suffixes are
.mps,.rew,.lp,.rlp,.dua,.dlp,.ilp, or.opb. The files can be compressed, so additional suffixes of.gz,.bz2,.zip, or.7zare accepted. The file name may contain*or?wildcards. No file is read when no wildcard match is found. If more than one match is found, this routine will attempt to read the first matching file.env – Environment in which to create the model. Creating your environment (using the
Env constructor) gives you more control over Gurobi licensing, but it can make your program more complex. Use the default environment unless you know that you need to control your own environments.
- Returns:
Modelobject containing the model that was read from the input file.- Example:
m = gp.read("afiro.mps") m.optimize()
- readParams(filename)#
Read a set of parameter settings from a file. The file name must end in
.prm, and the file must be in PRM format.- Parameters:
filename – Name of file containing parameter settings.
- Example:
gp.readParams("params.prm")
- resetParams()#
Reset the values of all parameters to their default values. Note that existing models that are stored inside Python data structures (lists, dictionaries, etc.), or inside user classes aren’t affected.
- Example:
gp.resetParams()
- setParam(paramname, newvalue)#
Set the value of a parameter to a new value. Note that existing models that are stored inside Python data structures (lists, dictionaries, etc.), or inside user classes aren’t affected.
- Parameters:
paramname – String containing the name of parameter that you would like to modify. The name can include ‘*’ and ‘?’ wildcards. If more than one parameter matches, the matching names are listed and none are modified. Note that case is ignored.
newvalue – Desired new value for parameter. Can be ‘default’, which indicates that the parameter should be reset to its default value.
- Example:
gp.setParam("Cuts", 2) gp.setParam("Heu*", 0.5) setParam("*Interval", 10)