Filter Content By
Version

Configuration parameters

When you start a Gurobi session, you often have to provides details about your configuration. You may need to indicate whether you want to use a license on your local machine, a license from a Token Server, or perhaps you want to offload your computation to a Compute Server or to Gurobi Instant Cloud. In the case of a Token Server or a Compute Server, you have to provide the name of the server. For Compute Server and Instant Cloud, you also need to provide login credentials.

In many situations, the configuration information you need is already stored in your license file (gurobi.lic) or in your environment file (gurobi.env). These files are read automatically, so you can simply create a standard Gurobi environment object (using GRBloadenv in C, or through the appropriate GRBEnv constructor in the object-oriented interfaces).

What if you need to provide configuration information from your application at runtime instead? You can use an empty environment to split environment creation into a few steps (as opposed to the standard, single-step approach mentioned above). In the first step, you would create an empty environment object (using GRBemptyenv in C, or through the appropriate GRBEnv constructor in the object-oriented interfaces). You would then set configuration parameters on this environment using the standard parameter API. Finally, you would start the environment (using GRBstartenv in C, or using the env.start() method in the object-oriented interfaces), which will use the configuration parameters you just set.

Empty environment example

To give a simple example, if you want your Python program to offload the optimization computation to a Compute Server named server1, you could say:

import gurobipy as gp
from gurobipy import GRB

# Set up environment
env = gp.Env(empty=True)
env.setParam('ComputeServer', 'server1:61000')
env.start()

model.optimize()


An equivalent Java program would look like this:

import gurobi.*;
...
// Set up environment
GRBenv env = new GRBEnv(true);
env.set(GRB.StringParam.ComputeServer,  "server1:61000");
env.start();

GRBModel model = new GRBModel(env, "misc07.mps");
model.optimize()


An equivalent C program would look like this:

#include "gurobi_c.h"
int main(void) {
GRBenv   *env   = NULL;
GRBmodel *model = NULL;
int error   = 0;

/* Set up environment */
error = GRBemptyenv(&env);
if (error) goto QUIT;
error = GRBsetstrparam(GRB_STR_PAR_COMPUTESERVER, "server1:61000");
if (error) goto QUIT;
if (error) goto QUIT;
error = GRBstartenv(env);
if (error) goto QUIT;

/* Load model and optimize */
if (error) goto QUIT;
error = GRBoptimize(model);
if (error) goto QUIT;

QUIT:
/* Clean up model and environment */
GRBfreemodel(model);
GRBfreeenv(env);
return error;
}


This example uses the ComputeServer parameter to connect to a Compute Server. To give a few more examples of configuration parameters, you can use the CloudAccessID and CloudSecretKey parameters to provide your credentials in order to launch an Instant Cloud instance. To connect to a token server, you would use the TokenServer parameter. You can also use the LicenseID, WLSAccessID, and WLSSecret parameters to provide your IDs and secret key for your WLS license. You can find more information about WLS licenses in your account on the Gurobi Web License Manager site. The full list of Gurobi parameters can be found here.

Configuration parameters must be set before you start the Gurobi environment. Changes have no effect once the environment has been started.

In Python you can also provide such configuration parameters directly as a dict argument to the environment constructor, without creating an empty environment first. Please refer to the Env() documentation for an example.