8.1.3. IO management¶
All API I/O functions related to controlling a model are declared in this file, including
reading a model from a file and writing the loaded model to a file.
redirecting solver log.
Supported model files are
MPS: File extension name must be
.mps
,.mps.gz
, or.mps.bz2
.LP: File extension name must be
.lp
,.lp.gz
, orlp.bz2
..dat-s
file, used in SDP..nl
file. You can usemindoptampl filename.nl
to solve it, more details Verify mindoptampl.
You can find the examples of the files in examples
folder in MindOpt installation package.
All API functions related to this.
Examples
MdoMdl * model = NULL;
Mdo_createMdl(&model);
/* Set log */
Mdo_setLogToConsole(model, flag_LogToConsole);
Mdo_setLogFile(model, "logfile.log");
/* Read/write problem */
Mdo_readProb(model, "problem.mps");
Mdo_writeProb(model, "copy_problem.lp");
/* Solve */
Mdo_solveProb(model);
/* Write solution and basis */
Mdo_writeSoln(model, MY_FOLDER "basis.bas");
Mdo_writeSoln(model, MY_FOLDER "solution.sol");
/* Write/read optimization task */
const char * model_file = "./my_model.mdo";
const char * param_file = "./my_param.mdo";
const char * soln_file = "./my_soln.mdo";
Mdo_writeTask(model, model_file, MDO_YES, MDO_NO, MDO_NO);
Mdo_writeTask(model, param_file, MDO_NO, MDO_YES, MDO_NO);
Mdo_writeTask(model, soln_file, MDO_NO, MDO_NO, MDO_YES);
Mdo_readTask(model, model_file, MDO_YES, MDO_NO, MDO_NO);
Mdo_readTask(model, param_file, MDO_NO, MDO_YES, MDO_NO);
Mdo_readTask(model, soln_file, MDO_NO, MDO_NO, MDO_YES);
Functions
-
MdoResult Mdo_readProb(MdoMdlPtr mdl, const char *filename)¶
This function reads an optimization problem from a file.
- Parameters
mdl – Pointer to the model.
filename – A character array that specifies the filename.
- Return
A response code that specifies the status of the function.
- See
Note
Once the function is called, the previously loaded problem will be abandoned.
Note that the type of the inputted model is determined by the file suffix. Valid suffixes are
.mps(.bz2/.gz)
or.lp(.bz2/.gz)
or.dat-s
.
-
MdoResult Mdo_writeProb(const MdoMdlPtr mdl, const char *filename)¶
This function writes an optimization problem to a file.
- Parameters
mdl – Pointer to the model.
filename – A character array that specifies the filename.
- Return
A response code that specifies the status of the function.
- See
Note
Note that the type of the output model is determined by the file suffix. Valid suffixes are
.mps(.bz2/.gz)
or.lp(.bz2/.gz)
.
-
MdoResult Mdo_writeSoln(const MdoMdlPtr mdl, const char *filename)¶
This function writes an optimization solution to a file.
- Parameters
mdl – Pointer to the model.
filename – A character array that specifies the filename.
- Return
A response code that specifies the status of the function.
Note
Note that the type of the optimization solution is determined by the file suffix. Valid suffixes are
.sol
or.bas
.
-
MdoResult Mdo_readTask(MdoMdlPtr mdl, const char *filename, MdoBool read_model, MdoBool read_param, MdoBool read_soln)¶
This function loads an optimization model task from a file.
- Parameters
mdl – Pointer to the model.
filename – A character array that specifies the model.
read_model – A boolean flag that specifies if the model shall be loaded.
read_param – A boolean flag that specifies if the parameters shall be loaded.
read_soln – A boolean flag that specifies if the solution shall be loaded.
- Return
A response code that specifies the status of the function.
- See
Note
Once the function is called, the previously loaded problem will be abandoned.
A model task file includes the problem data, parameter settings, and solutions in a binary format.
-
MdoResult Mdo_writeTask(const MdoMdlPtr mdl, const char *filename, MdoBool write_model, MdoBool write_param, MdoBool write_soln)¶
This function writes an optimization model task to a file.
- Parameters
mdl – Pointer to the model.
filename – A character array that specifies the filename.
write_model – A boolean flag that specifies if the model shall be outputted.
write_param – A boolean flag that specifies if the parameters shall be outputted.
write_soln – A boolean flag that specifies if the solution shall be outputted.
- Return
A response code that specifies the status of the function.
- See
Note
A model task file includes the problem data, parameter settings, and solutions in a binary format.
-
MdoResult Mdo_setLogToConsole(MdoMdlPtr mdl, MdoBool flag)¶
This function specified if the log shall be printed out to screen or not.
- Parameters
mdl – Pointer to the model.
flag – A flag that specified if the log shall be printed out to screen or not.
-
MdoResult Mdo_setLogFile(MdoMdlPtr mdl, const char *filename)¶
This function redirects output log to a file.
- Parameters
mdl – Pointer to the model.
filename – Path to the log file.
-
MdoResult Mdo_setLogCallback(MdoMdlPtr mdl, void (*logcb)(const char *msg, void *userdata), void *userdata)¶
This function redirects output log to a user-defined callback function.
- param mdl
Pointer to the model.
- param logcb
User defined callback function.
- param userdata
User defined data taht will be passed into the callback function.