Input-Output#
-
int GRBreadmodel(GRBenv *env, const char *filename, GRBmodel **modelP)#
Read a model from a file.
- Return value:
A non-zero return value indicates that a problem occurred while reading the model. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling
GRBgeterrormsg
.- Arguments:
env – The environment in which to load the new model. This should come from a previous call to
GRBloadenv
.filename – The path to the file to be read. Note that the type of the file is encoded in the file name suffix. Valid suffixes are
.mps
,.rew
,.lp
,.rlp
,.dua
,.dlp
,.ilp
, or.opb
. The files can be compressed, so additional suffixes of.zip
,.gz
,.bz2
,.7z
or.xz
are accepted.modelP – The location in which the pointer to the model should be placed.
- Example:
GRBmodel *model; error = GRBreadmodel(env, "/tmp/model.mps.bz2", &model);
-
int GRBread(GRBmodel *model, const char *filename)#
This method is the general entry point for importing data from a file into a model. It can be used to read basis files for continuous models, start vectors for MIP models, variable hints for MIP models, branching priorities for MIP models, or parameter settings. The type of data read is determined by the file suffix. File formats are described in the File Format section.
Note that reading a file does not process all pending model modifications. These modifications can be processed by calling
GRBupdatemodel
.Note also that this is not the method to use if you want to read a new model from a file. For that, use the
GRBreadmodel routine
.- Return value:
A non-zero return value indicates that a problem occurred while reading the file. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling
GRBgeterrormsg
.- Arguments:
model – The model that will receive the information read from the file.
filename – The path to the file to be read. The suffix on the file must be either
.mst
or.sol
for a MIP start file,.hnt
for a MIP hint file,.ord
for a priority order file,.bas
for a basis file,.attr
for a collection of attribute settings, or.prm
for a parameter file. The suffix may optionally be followed by.zip
,.gz
,.bz2
,.7z
or.xz
.
- Example:
error = GRBread(model, "/tmp/model.mst.bz2");
-
int GRBwrite(GRBmodel *model, const char *filename)#
This routine is the general entry point for writing optimization data to a file. It can be used to write optimization models, solution vectors, basis vectors, start vectors, or parameter settings. The type of data written is determined by the file suffix. File formats are described in the File Format section.
Note that writing a model to a file will process all pending model modifications. This is also true when writing other model information such as solutions, bases, etc.
Note also that when you write a Gurobi parameter file (PRM), both integer or double parameters not at their default value will be saved, but no string parameter will be saved into the file.
Finally, note that when IgnoreNames=1, the names of variables and constraints are replaced with default names when writing a file.
- Return value:
A non-zero return value indicates that a problem occurred while writing the file. Refer to the Error Codes table for a list of possible return values. Details on the error can be obtained by calling
GRBgeterrormsg
.- Arguments:
model – The model containing the data to be written.
filename – The name of the file to be written. The file type is encoded in the file name suffix. Valid suffixes are
.mps
,.rew
,.lp
, or.rlp
for writing the model itself,.dua
or.dlp
for writing the dualized model (only pure LP),.ilp
for writing just the IIS associated with an infeasible model (seeGRBcomputeIIS
for further information),.sol
for writing the solution selected by the SolutionNumber parameter,.mst
for writing a start vector,.hnt
for writing a hint file,.bas
for writing an LP basis,.prm
for writing modified parameter settings,.attr
for writing model attributes, or.json
for writing solution information in JSON format. If your system has compression utilities installed (e.g.,7z
orzip
for Windows, andgzip
,bzip2
, orunzip
for Linux or macOS), then the files can be compressed, so additional suffixes of.zip
,.gz
,.bz2
,.7z
or.xz
are accepted.
- Example:
error = GRBwrite(model, "/tmp/model.rlp.gz");