Empty Environment Examples

Empty Environment Examples

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.setParam('ServerPassword', 'passwd')

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

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.set(GRB.StringParam.ServerPassword, "passwd");

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

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;
  error = GRBsetstrparam(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;