Java API - GRBBatch#

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 the batch object include update (refresh attributes from the Cluster Manager), abort (abort execution of a batch request), retry (retry optimization for an interrupted or failed batch request), 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.

While the Java garbage collector will eventually collect an unused GRBBatch object, the vast majority of the memory associated with a model is stored outside of the Java heap. As a result, the garbage collector can’t see this memory usage, and thus it can’t take this quantity into account when deciding whether collection is necessary. We recommend that you call GRBBatch.dispose when you are done with the batch.

GRBBatch GRBBatch(GRBEnv env, String batchID)#

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.

Arguments:
  • 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.

Return value:

New batch object.

Example:
// Create Batch-object
GRBBatch batch = new 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:
// Request to abort the batch
batch.abort();
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:
// Request to erase input and output data related to this batch
batch.discard();
void dispose()#

Free all resources associated with this Batch object. After this method is called, this Batch object must no longer be used.

Example:
// Dispose resources
batch.dispose();
String getJSONSolution()#

This function 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.

Return value:

The requested solution in JSON format.

Example:
// print JSON solution into string
System.out.println("JSON solution:" + batch.getJSONSolution());
int get(GRB.IntAttr attr)#

Query the value of an int-valued batch attribute.

Arguments:

attr – The attribute being queried.

Return value:

The current value of the requested attribute.

String get(GRB.StringAttr attr)#

Query the value of a string-valued batch attribute.

Arguments:

attr – The attribute being queried.

Return value:

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:
// Retry the batch job
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 local attributes
batch.update();
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.

Arguments:

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

Example:
// save solution into a file
batch.writeJSONSolution("batch-sol.json.gz");