Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# 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:

- your access ID (CSAPIAccessID) and the corresponding secret key (CSAPISecret), or

- your user name (Username) and the corresponding password (ServerPassword).

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

    #include "gurobi_c++.h"

    // Create empty environment, set options and start
    GRBEnv env = GRBEnv(true);
    env.set(GRB_StringParam_CSManager, "server1:61080");
    env.set(GRB_StringParam_CSAPIAccessID, "12345-678990");
    env.set(GRB_StringParam_CSAPISecret, "abcdef-abcdef");
    env.start();

    // Load model and optimize
    GRBModel model = GRBModel(env, "misc07.mps");
    model.optimize();

    using Gurobi;

    // Create empty environment, set options and start
    GRBEnv env = new GRBEnv(true);
    env.Set("CSManager", "server1:61080");
    env.Set("CSAPIAccessID", "12345-678990");
    env.Set("CSAPISecret", "abcdef-abcdef");
    env.Start();

    // Load model and optimize
    GRBModel model = new GRBModel(env, "misc07.mps");
    model.Optimize();

    // Clean up model and environment
    model.Dispose();
    env.Dispose();

    import gurobi.*;

    // Create empty environment, set options and start
    GRBEnv env = new GRBEnv(true);
    env.set(GRB.StringParam.CSManager, "server1:61080");
    env.set(GRB.StringParam.CSAPIAccessID, "12345-678990");
    env.set(GRB.StringParam.CSAPISecret, "abcdef-abcdef");
    env.start();

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

    // Clean up model and environment
    model.dispose();
    env.dispose();

    import gurobipy as gp

    # Create empty environment, set options and start
    env = gp.Env(empty=True)
    env.setParam("CSManager", "server1:61080")
    env.setParam("CSAPIAccessID", "12345-678990")
    env.setParam("CSAPISecret", "abcdef-abcdef")
    env.start()

    # Load model and optimize
    model = gp.read('misc07.mps', env=env)
    model.optimize()

    # Clean up model and environment
    model.dispose()
    env.dispose()

    Imports Gurobi

    ' Create empty environment, set options and start
    Dim env As New GRBEnv(True)
    env.Set("CSManager", "server1:61080")
    env.Set("CSAPIAccessID", "12345-678990")
    env.Set("CSAPISecret", "abcdef-abcdef")
    env.Start()

    ' Load model and optimize
    Dim model As New GRBModel(env, "misc07.mps")
    model.Optimize()

    ' Clean up model and environment
    model.Dispose()
    env.Dispose()

To use a Compute Server for the optimization computation, you need the set the ComputeServer parameter and ServerPassword parameter before starting the environment.

    #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_COMPUTESERVER, "server1:61000");
       if (error) goto QUIT;
       error = GRBsetstrparam(env, GRB_STR_PAR_SERVERPASSWORD, "passwd");
       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;
    }

    #include "gurobi_c++.h"

    // Create empty environment, set options and start
    GRBEnv env = GRBEnv(true);
    env.set(GRB_StringParam_ComputeServer, "server1:61000");
    env.set(GRB_StringParam_ServerPassword, "passwd");
    env.start();

    // Load model and optimize
    GRBModel model = GRBModel(env, "misc07.mps");
    model.optimize();

    using Gurobi;

    // Create empty environment, set options and start
    GRBEnv env = new GRBEnv(true);
    env.Set("ComputeServer", "server1:61000");
    env.Set("ServerPassword", "passwd");
    env.Start();

    // Load model and optimize
    GRBModel model = new GRBModel(env, "misc07.mps");
    model.Optimize();

    // Clean up model and environment
    model.Dispose();
    env.Dispose();

    import gurobi.*;

    // Create empty environment, set options and start
    GRBEnv env = new GRBEnv(true);
    env.set(GRB.StringParam.ComputeServer, "server1:61000");
    env.set(GRB.StringParam.ServerPassword, "passwd");
    env.start();

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

    // Clean up model and environment
    model.dispose();
    env.dispose();

    import gurobipy as gp

    # Create empty environment, set options and start
    env = gp.Env(empty=True)
    env.setParam("ComputeServer", "server1:61000")
    env.setParam("ServerPassword", "passwd")
    env.start()

    # Load model and optimize
    model = gp.read('misc07.mps', env=env)
    model.optimize()

    # Clean up model and environment
    model.dispose()
    env.dispose()

    Imports Gurobi

    ' Create empty environment, set options and start
    Dim env As New GRBEnv(True)
    env.Set("ComputeServer", "server1:61000")
    env.Set("ServerPassword", "passwd")
    env.Start()

    ' Load model and optimize
    Dim model As New GRBModel(env, "misc07.mps")
    model.Optimize()

    ' Clean up model and environment
    model.Dispose()
    env.Dispose()

You can use the CloudAccessID and CloudSecretKey parameters to provide your credentials in order to launch an Gurobi Instant Cloud instance.

    #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_CLOUDACCESSID, "12345-678990");
       if (error) goto QUIT;
       error = GRBsetstrparam(env, GRB_STR_PAR_CLOUDSECRETKEY, "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;
    }

    #include "gurobi_c++.h"

    // Create empty environment, set options and start
    GRBEnv env = GRBEnv(true);
    env.set(GRB_StringParam_CloudAccessID, "12345-678990");
    env.set(GRB_StringParam_CloudSecretKey, "abcdef-abcdef");
    env.start();

    // Load model and optimize
    GRBModel model = GRBModel(env, "misc07.mps");
    model.optimize();

    using Gurobi;

    // Create empty environment, set options and start
    GRBEnv env = new GRBEnv(true);
    env.Set("CloudAccessID", "12345-678990");
    env.Set("CloudSecretKey", "abcdef-abcdef");
    env.Start();

    // Load model and optimize
    GRBModel model = new GRBModel(env, "misc07.mps");
    model.Optimize();

    // Clean up model and environment
    model.Dispose();
    env.Dispose();

    import gurobi.*;

    // Create empty environment, set options and start
    GRBEnv env = new GRBEnv(true);
    env.set(GRB.StringParam.CloudAccessID, "12345-678990");
    env.set(GRB.StringParam.CloudSecretKey, "abcdef-abcdef");
    env.start();

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

    // Clean up model and environment
    model.dispose();
    env.dispose();

    import gurobipy as gp

    # Create empty environment, set options and start
    env = gp.Env(empty=True)
    env.setParam("CloudAccessID", "12345-678990")
    env.setParam("CloudSecretKey", "abcdef-abcdef")
    env.start()

    # Load model and optimize
    model = gp.read('misc07.mps', env=env)
    model.optimize()

    # Clean up model and environment
    model.dispose()
    env.dispose()

    Imports Gurobi

    ' Create empty environment, set options and start
    Dim env As New GRBEnv(True)
    env.Set("CloudAccessID", "12345-678990")
    env.Set("CloudSecretKey", "abcdef-abcdef")
    env.Start()

    ' Load model and optimize
    Dim model As New GRBModel(env, "misc07.mps")
    model.Optimize()

    ' Clean up model and environment
    model.Dispose()
    env.Dispose()

To connect to a Token Server, you would use the TokenServer parameter.

    #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_TOKENSERVER, "myserver");
       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;
    }

    #include "gurobi_c++.h"

    // Create empty environment, set options and start
    GRBEnv env = GRBEnv(true);
    env.set(GRB_StringParam_TokenServer, "myserver");
    env.start();

    // Load model and optimize
    GRBModel model = GRBModel(env, "misc07.mps");
    model.optimize();

    using Gurobi;

    // Create empty environment, set options and start
    GRBEnv env = new GRBEnv(true);
    env.Set("TokenServer", "myserver");
    env.Start();

    // Load model and optimize
    GRBModel model = new GRBModel(env, "misc07.mps");
    model.Optimize();

    // Clean up model and environment
    model.Dispose();
    env.Dispose();

    import gurobi.*;

    // Create empty environment, set options and start
    GRBEnv env = new GRBEnv(true);
    env.set(GRB.StringParam.TokenServer, "myserver");
    env.start();

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

    // Clean up model and environment
    model.dispose();
    env.dispose();

    import gurobipy as gp

    # Create empty environment, set options and start
    env = gp.Env(empty=True)
    env.setParam("TokenServer", "myserver")
    env.start()

    # Load model and optimize
    model = gp.read('misc07.mps', env=env)
    model.optimize()

    # Clean up model and environment
    model.dispose()
    env.dispose()

    Imports Gurobi

    ' Create empty environment, set options and start
    Dim env As New GRBEnv(True)
    env.Set("TokenServer", "myserver")
    env.Start()

    ' Load model and optimize
    Dim model As New GRBModel(env, "misc07.mps")
    model.Optimize()

    ' Clean up model and environment
    model.Dispose()
    env.Dispose()

You can use the LicenseID, WLSAccessID, and WLSSecret parameters to provide your ID and secret key for your Web License Service (WLS) license.

    #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_LICENSEID, "12345");
       if (error) goto QUIT;
       error = GRBsetstrparam(env, GRB_STR_PAR_WLSACCESSID, "12345-678990");
       if (error) goto QUIT;
       error = GRBsetstrparam(env, GRB_STR_PAR_WLSSECRET, "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;
    }

    #include "gurobi_c++.h"

    // Create empty environment, set options and start
    GRBEnv env = GRBEnv(true);
    env.set(GRB_StringParam_LicenseID, "12345");
    env.set(GRB_StringParam_WLSAccessID, "12345-678990");
    env.set(GRB_StringParam_WLSSecret, "abcdef-abcdef");
    env.start();

    // Load model and optimize
    GRBModel model = GRBModel(env, "misc07.mps");
    model.optimize();

    using Gurobi;

    // Create empty environment, set options and start
    GRBEnv env = new GRBEnv(true);
    env.Set("LicenseID", "12345");
    env.Set("WLSAccessID", "12345-678990");
    env.Set("WLSSecret", "abcdef-abcdef");
    env.Start();

    // Load model and optimize
    GRBModel model = new GRBModel(env, "misc07.mps");
    model.Optimize();

    // Clean up model and environment
    model.Dispose();
    env.Dispose();

    import gurobi.*;

    // Create empty environment, set options and start
    GRBEnv env = new GRBEnv(true);
    env.set(GRB.StringParam.LicenseID, "12345");
    env.set(GRB.StringParam.WLSAccessID, "12345-678990");
    env.set(GRB.StringParam.WLSSecret, "abcdef-abcdef");
    env.start();

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

    // Clean up model and environment
    model.dispose();
    env.dispose();

    import gurobipy as gp

    # Create empty environment, set options and start
    with gp.Env(empty=True) as env:
       env.setParam("LicenseID", "12345")
       env.setParam("WLSAccessID", "12345-678990")
       env.setParam("WLSSecret", "abcdef-abcdef")
       env.start()
       # Load model and optimize
       with gp.read('misc07.mps', env=env) as model:
          model.optimize()

    Imports Gurobi

    ' Create empty environment, set options and start
    Dim env As New GRBEnv(True)
    env.Set("LicenseID", "12345")
    env.Set("WLSAccessID", "12345-678990")
    env.Set("WLSSecret", "abcdef-abcdef")
    env.Start()

    ' Load model and optimize
    Dim model As New GRBModel(env, "misc07.mps")
    model.Optimize()

    ' Clean up model and environment
    model.Dispose()
    env.Dispose()

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.

Help and Feedback

Press `/` or click to search this documentation | Gurobi website | Gurobi community forum
Go to other Gurobi documentation | Gurobi download | Contact support