There are a number of different file formats around for persisting optimisation models, ojAlgo even has its own model file format.

One of the file formats stands out as “the” standard. MPS (Mathematical Programming System) is a file format for describing linear programming (LP) and mixed integer programming (MIP) problems. It’s an old format developed by IBM for one of their early optimisation products, but it’s still widely used and supported by all the major commercial LP solvers. There has been several extensions to the original specification. Most notably the possibility to describe QP models.

WikipediA has a description of the format as well as a very small example file. (I’ve seen this particular model/file used in other places, and we’ll use it for this example.) It’s a text file so it is human readable. If you just know a little bit about linear programming you can read the model (since it’s so small).

ojAlgo supports reading MPS files. The main reason for that is to be able to make use of industry standard test model collections. A large part of ojAlgo’s optimisation test cases are based on (standard) MPS files found in various such collections. In particular there are tests from:

To persist an ExpressionsBasedModel, in order to later read it back, you need to use ojAlgo’s own file format (EBM). It’s the only file format currently supported to write a model.

  • MPS: read (with the most important format extensions supported)
  • EBM: read/write (it’s ojAlgo’s own file format)

Example Code

Console

class UsingMPS
ojAlgo
2022-05-21

MPS-model ok!
############################################
0 <= XONE <= 4
-1 <= YTWO <= 1
0 <= ZTHREE
7 <= MYEQN: 0.0 <= 7
10 <= LIM2: 2.0
COST: 2.0 (1)
LIM1: 2.0 <= 5
############################################

Minimised => OPTIMAL 54.0 @ { 4, -1, 6 }
Maximised => OPTIMAL 80.0 @ { 4, 1, 8 }

=== Variables ===
2 <= XONE: 4 (1) <= 4
-1 <= YTWO: 1 (4) <= 1
6 <= ZTHREE: 8 (9) <= 8

=== Expressions ===
7 <= MYEQN <= 7
10 <= LIM2
COST
LIM1 <= 5

Modified => OPTIMAL 53.5 @ { 3.5, -1, 6 }
Integer constrained => INFEASIBLE 56.0 @ { 2, 0, 6 }

Modified model
############################################
2 <= XONE (1) <= 4
-1 <= YTWO (4) <= 1
6 <= ZTHREE (9) <= 8
7 <= MYEQN: 7.0 <= 7
9.5 <= LIM2: 10.0
COST: 66.0
LIM1: 3.0 <= 5.5
############################################