Using an API to Create a Compute Server Job¶
As was noted earlier, a Remote Services client program will always need to be told how to reach the Remote Services cluster. This can be done in two ways. The first is through a license file. This approach is described in an earlier discussion. It requires no changes to the application program itself. The same program can perform optimization locally or remotely, depending on the settings in the license file.
Your second option for specifying the desired Compute Servers is through
API calls. You would first construct an empty environment (using
GRBemptyenv in C or the appropriate GRBEnv constructor in the
object-oriented interfaces), then set the appropriate parameters on this
environment (typically ComputeServer and ServerPassword), and
then start the empty environment (using GRBstartenv in C or
env.start() in the object-oriented interfaces). In Python, you can
directly give the appropriate parameters to the environment when creating it.
Once a model is solved and you have retrieved the results from it, we
recommend you dispose of it immediately. If you don’t need the
environment for another model, dispose of the environment as well, to
release the remote job. The following example shows how to offload the optimization computation to a
Compute Server named server1 in various APIs, with proper resource
management.
GRBenv *env = NULL;
GRBmodel *model = NULL;
int error = 0;
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;
error = GRBreadmodel(env, "misc07.mps", &model);
if (error) goto QUIT;
error = GRBoptimize(model);
if (error) goto QUIT;
/* Extract the solution */
/* ... */
QUIT:
GRBfreemodel(model);
GRBfreeenv(env);
/* return error; */
GRBEnv env = GRBEnv(true);
env.set(GRB_StringParam_ComputeServer, "server1:61000");
env.set(GRB_StringParam_ServerPassword, "passwd");
env.start();
GRBModel model = GRBModel(env, "misc07.mps");
model.optimize();
// Extract the solution
// ...
using GRBEnv env = new GRBEnv(true);
env.Set("ComputeServer", "server1:61000");
env.Set("ServerPassword", "passwd");
env.Start();
using GRBModel model = new GRBModel(env, "misc07.mps");
model.Optimize();
// Extract the solution
// ...
GRBEnv env = null;
GRBModel model = null;
try {
env = new GRBEnv(true);
env.set(GRB.StringParam.ComputeServer, "server1:61000");
env.set(GRB.StringParam.ServerPassword, "passwd");
env.start();
model = new GRBModel(env, "misc07.mps");
model.optimize();
// Extract the solution
// ...
} finally {
if (model != null) {
model.dispose();
}
if (env != null) {
env.dispose();
}
}
params.ComputeServer = 'server1:61000';
params.ServerPassword = 'passwd';
model = gurobi_read('misc07.mps');
result = gurobi(model, params);
% Extract the solution
% ...
with gp.Env(
params={
"ComputeServer": "server1:61000",
"ServerPassword": "passwd",
}
) as env, gp.read("misc07.mps", env=env) as model:
model.optimize()
# Extract the solution
...
params <- list(
ComputeServer = 'server1:61000',
ServerPassword = 'passwd'
)
model <- gurobi_read('misc07.mps')
result <- gurobi(model, params)
# Extract the solution
# ...
We refer you to the Gurobi Reference Manual for details on these routines.