GRBEnv#

class GRBEnv#

Gurobi environment object. Gurobi models are always associated with an environment. You must create an environment before you can create and populate a model. You will generally only need a single environment object in your program.

The methods on environment objects are mainly used to manage Gurobi parameters (e.g., get, getParamInfo, set).

GRBEnv GRBEnv()#

Constructor for GRBEnv object. Creates a Gurobi environment (with logging disabled). 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.

Returns:

An environment object (with no associated log file).

GRBEnv GRBEnv(bool empty)#

Constructor for GRBEnv object. If empty=true, creates an empty environment. Use GRBEnv::start to start the environment. If empty=false, the result is the same as providing no arguments to the constructor.

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.

Parameters:

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, a Cluster Manager or use a WLS license. See the Environment Section for more details.

Returns:

An environment object.

GRBEnv GRBEnv(const string &logFileName)#

Constructor for GRBEnv object. Creates a Gurobi environment (with logging enabled). 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.

Parameters:

logFileName – The desired log file name.

Returns:

An environment object.

double get(GRB_DoubleParam param)#

Query the value of a double-valued parameter.

Parameters:

param – The parameter being queried. Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

Returns:

The current value of the requested parameter.

int get(GRB_IntParam param)#

Query the value of an int-valued parameter.

Parameters:

param – The parameter being queried. Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

Returns:

The current value of the requested parameter.

string get(GRB_StringParam param)#

Query the value of a string-valued parameter.

Parameters:

param – The parameter being queried. Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

Returns:

The current value of the requested parameter.

const string getErrorMsg()#

Query the error message for the most recent exception associated with this environment.

Returns:

The error string.

void getParamInfo(GRB_DoubleParam param, double *valP, double *minP, double *maxP, double **defP)#

Obtain detailed information about a double parameter.

Parameters:
  • param – The parameter of interest. Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

  • valP – The current value of the parameter.

  • minP – The minimum allowed value of the parameter.

  • maxP – The maximum allowed value of the parameter.

  • defP – The default value of the parameter.

void getParamInfo(GRB_IntParam param, int *valP, int *minP, int *maxP, int *defP)#

Obtain detailed information about an integer parameter.

Parameters:
  • param – The parameter of interest. Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

  • valP – The current value of the parameter.

  • minP – The minimum allowed value of the parameter.

  • maxP – The maximum allowed value of the parameter.

  • defP – The default value of the parameter.

void getParamInfo(GRB_StringParam param, string *valP, string *defP)#

Obtain detailed information about a string parameter.

Parameters:
  • param – The parameter of interest. Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

  • valP – The current value of the parameter.

  • defP – The default value of the parameter.

void message(const string &message)#

Write a message to the console and the log file.

Parameters:

message – Print a message to the console and to the log file. Note that this call has no effect unless the OutputFlag parameter is set.

void readParams(const string &paramfile)#

Read new parameter settings from a file.

Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

Parameters should be listed one per line, with the parameter name first and the desired value second. For example:

# Gurobi parameter file
Threads 1
MIPGap 0

Blank lines and lines that begin with the hash symbol are ignored.

Parameters:

paramfile – Name of the file containing parameter settings.

void resetParams()#

Reset all parameters to their default values.

Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

void set(GRB_DoubleParam param, double newvalue)#

Set the value of a double-valued parameter.

Parameters:
  • param – The parameter being modified. Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

  • newvalue – The desired new value of the parameter.

Note

Note that a model gets its own copy of the environment when it is created. Changes to the original environment have no effect on the copy, and vice versa. Use the appropriate version of the overloaded method GRBModel::set to change a parameter on an existing model.

void set(GRB_IntParam param, int newvalue)#

Set the value of an int-valued parameter.

Parameters:
  • param – The parameter being modified. Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

  • newvalue – The desired new value of the parameter.

Note

Note that a model gets its own copy of the environment when it is created. Changes to the original environment have no effect on the copy, and vice versa. Use the appropriate version of the overloaded method GRBModel::set to change a parameter on an existing model.

void set(GRB_StringParam param, const string &newvalue)#

Set the value of a string-valued parameter.

Parameters:
  • param – The parameter being modified. Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

  • newvalue – The desired new value of the parameter.

Note

Note that a model gets its own copy of the environment when it is created. Changes to the original environment have no effect on the copy, and vice versa. Use the appropriate version of the overloaded method GRBModel::set to change a parameter on an existing model.

void set(const string &param, const string &newvalue)#

Set the value of any parameter using strings alone.

Parameters:
  • param – The name of the parameter being modified. Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

  • newvalue – The desired new value of the parameter.

Note

Note that a model gets its own copy of the environment when it is created. Changes to the original environment have no effect on the copy, and vice versa. Use the appropriate version of the overloaded method GRBModel::set to change a parameter on an existing model.

void start()#

Start an empty environment. If the environment has already been started, this method will do nothing. If the call fails, the environment will have the same state as it had before the call to this method.

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). After that, it will apply all parameter changes specified by the user prior to this call. Note that this might overwrite parameters set in the license file, or in the gurobi.env file, if present.

After all these changes are performed, the code will actually activate the environment, and make it ready to work with models.

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.

Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

void writeParams(const string &paramfile)#

Write all non-default parameter settings to a file.

Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

Parameters:

paramfile – Name of the file to which non-default parameter settings should be written. The previous contents are overwritten.