# GLPK/Interoperability

Interoperability, in this case, refers to the ability to translate between and/or use common linear and mixed integer problem specification formats under GLPK. These formats are used to present and archive problem instances. The notion of a problem format should not be confused with that of a high-level modeling language, such as GLPK MathProg. This page also considers the solution recovery formats provided by GLPK and gives information on the machine processing of GLPK output.

## Overview

GLPK can readily input and output problems in various problem specification formats:
* the CPLEX LP format (includes MIP problems)
* the MPS format in fixed (ancient) and free (modern) variants
* a custom DIMACS-like format named GLPK format.
This means GLPK can be used to create problems for other solvers. And can take problems from other sources and either reformat them or solve them. This functionality is available through both GLPSOL and the GLPK callable library. Indeed some users employ GLPK solely for its model generation and problem reformatting features — and never actually invoke the underlying solver.
GLPK is not able to write back results to these formats in cases where the underlying format specification provides for this. Users must rely on the native GLPK solution output instead. Nor does GLPK currently support any of the XML-based optimization formats including that developed as part of the COIN-OR OS (Optimization Services) project.
In addition, GLPK offers several graph reading and writing routines which make use of the DIMACS clique/coloring format and also a custom GLPK plain text format. These API routines are not currently available through GLPSOL and are not discussed further.
Earlier versions of GLPK have supported the OPB pseudo-boolean format.
The following file extension conventions normally apply:
| Format | File extension | Comment |
| CPLEX LP | .lp | |
| MPS | .mps | fixed and free |
| GLPK | .glp .glpk | |
The official GLPK documentation gives full details of each supported format.
Finally, an example of sensitivity analysis is included on this page although it is not really an interoperability issue. Sensitivity analysis interpretation keys are given in the glp_print_ranges entry.

## GLPSOL usage

GLPSOL offers convenient command-line usage for achieving interoperability. A review of the help message from GLPSOL makes a good starting point.
The following table summarizes the relevant interoperability options (the MathProg column is included for completeness):
| | CPLEX LP | MPS fixed | MPS free | GLPK | MathProg |
| Read | --lp | --mps | --freemps | --glp | --math |
| Write | --wlp filename | --wmps filename | --wfreemps filename | --wglp filename | not possible |
As indicated, it is not generally possible to create a high-level model from a lower-level problem format. That said, the CPLEX LP format is the most human legible.
The following example reads in an existing convert.lp CPLEX LP format file and outputs a GLPK format file without solving the model. In this case, the --check option prevents the model from being run.
The GLPSOL options for solution capture comprise:
| | Printable format | Plain text format |
| Recover | --output filename | --write filename |
The printable format is designed to be understood by humans. The plain text format is for machine processing. Neither format represents an established standard. A copy of the terminal output can also be written to file using the --log option. Hence:
The same functionality provided by GLPSOL is also available through API routines from the GLPK callable library.
Again the official GLPK documentation gives full details of each format.

## Machine processing GLPK output

Users may wish to automatically process the output from GLPK. But GLPK cannot produce common machine-parsable formats like CSV (comma-separated values) or XML or specialized dialects based on these two protocols. Instead, the GLPK maintainer advises:
   "To access the solution found by GLPSOL from a computer program, one could write the model with the --wglp option and the solution with the --write option. The ordering of rows and columns is the same in both files. It is enough to obtain all necessary information. (The only improvements I would like to make here is to use a DIMACS-like format for solution files.)" Source: [help-glpk], 19 Jan 2011, grammar corrected, emphasis added.
See elsewhere on this page for representative output from these two GLPSOL options.
The same output can also be generated using the appropriate API calls, namely: glp_write_sol, glp_write_ipt, glp_write_mip, and glp_write_prob.

## Short examples

This section uses the short.mod model, first introduced on the MathProg page. Save the following model in a file named short.mod.
Astute readers may notice that this model does not contain advanced MathProg language features and thus looks much like a problem format (the solve and display statements excepted).
A selection of calls and results are given next. This exercise also provides a useful visual comparison of these various formats.

### GLPSOL output format

See here for information regarding the KKT optimality conditions.

### GLPSOL sensitivity analysis

See here for information regarding the table headers.

## References

* ↑ Fourer, Robert; Lopes, Leo; Martin, Kipp (2005), "LPFML: A W3C XML Schema for Linear and Integer Programming", INFORMS Journal on Computing, vol. 17, no. 2, pp. 139–158, doi:10.1287/ijoc.1040.0120
* ↑ The obsolete option --wcpxlp is equivalent to --wlp.