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;
}