Concepts
Features
Reference
Gurobi batch object. Batch optimization is a feature available with theGurobi Cluster Manager. It allows a client program to build anoptimization model, submit it to a Compute Server cluster (through aCluster Manager), and later check on the status of the model andretrieve its solution. For more information, please refer to theBatch Optimization section.
Commonly used methods on batch objects includeupdate(refresh attributes from the Cluster Manager),abort (abortexecution of a batch request),retry (retry optimization foran interrupted or failed batch),discard (remove the batchrequest and all related information from the Cluster Manager), andgetJSONSolution (query solution information for the batchrequest).
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 theoption of calling the REST API directly.
Batch objects have four attributes:
BatchID: Unique ID for the batch request.
BatchStatus: Last batch status. Status values aredescribed in theBatch Status Code section.
BatchErrorCode: Last error code.
BatchErrorMessage: Last error message.
You can access their values by usingget. Note that allBatch attributes are locally cached, and are only updated when youcreate a client-side batch object or when you explicitly update thiscache, which can done by callingupdate.
Constructor forGRBBatch.
Given aBatchID, as returned byoptimizeBatch, and a Gurobi environment thatcan connect to the appropriate Cluster Manager (i.e., one whereparametersCSManager,UserName, andServerPassword have been setappropriately), this function returns aGRBBatch object. With it, you can querythe current status of the associated batch request and, once the batchrequest has been processed, you can query its solution. Please refer totheBatch Optimization section for detailsand examples.
env – The environment in which the new batch object should becreated.
batchID – ID of the batch request for which you want to accessstatus and other information.
New batch object.
GRBBatchbatch=GRBBatch(env,batchID);
This method instructs the Cluster Manager to abort the processing ofthis batch request, changing its status to ABORTED. Please refer to theBatch Status Codes section for furtherdetails.
// Abort this batch if it is taking too longtime_tcurtime=time(NULL);if(curtime-starttime>maxwaittime){batch->abort();break;}
This method instructs the Cluster Manager to remove all informationrelated to the batch request in question, including the stored solutionif available. Further queries for the associated batch request will failwith error codeDATA_NOT_AVAILABLE. Use thisfunction with care, as the removed information can not be recoveredlater on.
voidbatchdiscard(stringbatchID)
This method retrieves the solution of a completed batch request from aCluster Manager. The solution is returned as aJSON solutionstring. For this call to succeed, the status of the batchrequest must be COMPLETED. Note further that the result file storedCluster Manager side must be gzip-compressed and exactly one result fileshould be associated with this batch; for batches submittedprogrammatically through the API both will be the case. Please refer totheBatch Status Codes section for furtherdetails.
The requested solution in JSON format.
// Pretty printing the general solution informationcout<<"JSON solution:"<<batch->getJSONSolution()<<endl;
Query the value of an int-valued batch attribute.
attr – The attribute being queried.
The current value of the requested attribute.
Query the value of a string-valued batch attribute.
attr – The attribute being queried.
The current value of the requested attribute.
This method instructs the Cluster Manager to retry optimization of afailed or aborted batch request, changing its status to SUBMITTED.Please refer to theBatch Status Codessection for further details.
// If the batch failed, we try againif(BatchStatus==GRB_BATCH_FAILED)batch->retry();
All Batch attribute values are cached locally, so queries return thevalue received during the last communication with the Cluster Manager.This method refreshes the values of all attributes with the valuescurrently available in the Cluster Manager (which involves networkcommunication).
// 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);
This method returns the stored solution of a completed batch requestfrom a Cluster Manager. The solution is returned in a gzip-compressedJSON file. The file name you provide must end with a .json.gz extension.The JSON format is described in theJSON solution format section. Note that for this call to succeed, the status ofthe batch request must be COMPLETED. Note further that the result filestored Cluster Manager side must be gzip-compressed and exactly oneresult file should be associated with this batch; for batches submittedprogrammatically through the API both will be the case. Please refer totheBatch Status Codes section for furtherdetails.
filename – Name of file where the solution should be stored (inJSON format).
// Write the full JSON solution string to a filebatch->writeJSONSolution("batch-sol.json.gz");
Help and Feedback