C++ API - GRBBatch#

class GRBBatch#

Gurobi batch object. Batch optimization is a feature available with the Gurobi Cluster Manager. It allows a client program to build an optimization model, submit it to a Compute Server cluster (through a Cluster Manager), and later check on the status of the model and retrieve its solution. For more information, please refer to the Batch Optimization section.

Commonly used methods on batch objects include update (refresh attributes from the Cluster Manager), abort (abort execution of a batch request), retry (retry optimization for an interrupted or failed batch), discard (remove the batch request and all related information from the Cluster Manager), and getJSONSolution (query solution information for the batch request).

These methods are built on top of calls to the Cluster Manager REST API. They are meant to simplify such calls, but note that you always have the option of calling the REST API directly.

Batch objects have four attributes:

You can access their values by using get. Note that all Batch attributes are locally cached, and are only updated when you create a client-side batch object or when you explicitly update this cache, which can done by calling update.

GRBBatch GRBBatch(GRBEnv &env, string &batchID)#

Constructor for GRBBatch.

Given a BatchID, as returned by optimizeBatch, and a Gurobi environment that can connect to the appropriate Cluster Manager (i.e., one where parameters CSManager, UserName, and ServerPassword have been set appropriately), this function returns a GRBBatch object. With it, you can query the current status of the associated batch request and, once the batch request has been processed, you can query its solution. Please refer to the Batch Optimization section for details and examples.

Parameters:
  • env – The environment in which the new batch object should be created.

  • batchID – ID of the batch request for which you want to access status and other information.

Returns:

New batch object.

Example:
GRBBatch batch = GRBBatch(env, batchID);
void abort()#

This method instructs the Cluster Manager to abort the processing of this batch request, changing its status to ABORTED. Please refer to the Batch Status Codes section for further details.

Example:
// Abort this batch if it is taking too long
time_t curtime = time(NULL);
if (curtime - starttime > maxwaittime) {
  batch->abort();
  break;
}
void discard()#

This method instructs the Cluster Manager to remove all information related to the batch request in question, including the stored solution if available. Further queries for the associated batch request will fail with error code DATA_NOT_AVAILABLE. Use this function with care, as the removed information can not be recovered later on.

Example:
void
batchdiscard(string batchID)
string getJSONSolution()#

This method retrieves the solution of a completed batch request from a Cluster Manager. The solution is returned as a JSON solution string. For this call to succeed, the status of the batch request must be COMPLETED. Note further that the result file stored Cluster Manager side must be gzip-compressed and exactly one result file should be associated with this batch; for batches submitted programmatically through the API both will be the case. Please refer to the Batch Status Codes section for further details.

Returns:

The requested solution in JSON format.

Example:
// Pretty printing the general solution information
cout << "JSON solution:" << batch->getJSONSolution() << endl;
int get(GRB_IntAttr attr)#

Query the value of an int-valued batch attribute.

Parameters:

attr – The attribute being queried.

Returns:

The current value of the requested attribute.

string get(GRB_StringAttr attr)#

Query the value of a string-valued batch attribute.

Parameters:

attr – The attribute being queried.

Returns:

The current value of the requested attribute.

void retry()#

This method instructs the Cluster Manager to retry optimization of a failed or aborted batch request, changing its status to SUBMITTED. Please refer to the Batch Status Codes section for further details.

Example:
// If the batch failed, we try again
if (BatchStatus == GRB_BATCH_FAILED)
  batch->retry();
void update()#

All Batch attribute values are cached locally, so queries return the value received during the last communication with the Cluster Manager. This method refreshes the values of all attributes with the values currently available in the Cluster Manager (which involves network communication).

Example:
// Update the resident attribute cache of the Batch object with the
// latest values from the cluster manager.
batch->update();
BatchStatus = batch->get(GRB_IntAttr_BatchStatus);
void writeJSONSolution(string &filename)#

This method returns the stored solution of a completed batch request from a Cluster Manager. The solution is returned in a gzip-compressed JSON file. The file name you provide must end with a .json.gz extension. The JSON format is described in the JSON solution format section. Note that for this call to succeed, the status of the batch request must be COMPLETED. Note further that the result file stored Cluster Manager side must be gzip-compressed and exactly one result file should be associated with this batch; for batches submitted programmatically through the API both will be the case. Please refer to the Batch Status Codes section for further details.

Parameters:

filename – Name of file where the solution should be stored (in JSON format).

Example:
// Write the full JSON solution string to a file
batch->writeJSONSolution("batch-sol.json.gz");