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 program to use a specific license, you could do the following:

To use a Cluster Manager you need to provide the URL and your credentials in order to launch an instance on the Cluster Manager. The URL to the Cluster Manager (CSManager) must always be specified. It usually includes a port number. In addition, and depending on the type of credentials you want to use, you must provide either:

The example code will feature CSAPIAccessID and CSAPISecret.

#include "gurobi_c.h"

int main(void) {
   GRBenv   *env   = NULL;
   GRBmodel *model = NULL;

   int error = 0;

   /* Create empty environment, set options and start */
   error = GRBemptyenv(&env);
   if (error) goto QUIT;
   error = GRBsetstrparam(env, GRB_STR_PAR_CSMANAGER, "server1:61080");
   if (error) goto QUIT;
   error = GRBsetstrparam(env, GRB_STR_PAR_CSAPIACCESSID, "12345-678990");
   if (error) goto QUIT;
   error = GRBsetstrparam(env, GRB_STR_PAR_CSAPISECRET, "abcdef-abcdef");
   if (error) goto QUIT;
   error = GRBstartenv(env);
   if (error) goto QUIT;

   /* Load model and optimize */
   error = GRBreadmodel(env, "misc07.mps", &model);
   if (error) goto QUIT;
   error = GRBoptimize(model);
   if (error) goto QUIT;

QUIT:

   /* Clean up model and environment */
   GRBfreemodel(model);
   GRBfreeenv(env);

   return error;
}

Note

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

Note

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 constructor documentation for an example.