MOSEK supports the LP file format with some extensions i.e. MOSEK can read and write LP formatted files.
The LP format is not a well-defined standard and hence different optimization packages may interpretate a specific LP formatted file differently.
The LP file format can specify problems on the form
![]() |
where
is the quadratic term in the objective where
![]() |
and it is assumed that
![]() |
(D.2.1) |
is a vector of quadratic functions. Hence,
![]() |
where it is assumed that
![]() |
(D.2.2) |
An LP formatted file contains a number of sections specifying the objective, constraints, variable bounds, and variable types. The section keywords may be any mix of upper and lower case letters.
The first section beginning with one of the keywords
max maximum maximize min minimum minimize
defines the objective sense and the objective function, i.e.
![]() |
The objective may be given a name by writing
myname:
before the expressions. If no name is given, then the objective is named obj.
The objective function contains linear and quadratic terms. The linear terms are written as in the example
4 x1 + x2 - 0.1 x3
and so forth. The quadratic terms are written in square brackets ([ ]) and are either squared or multiplied as in the examples
x1 ^ 2
and
x1 * x2
There may be zero or more pairs of brackets containing quadratic expressions.
An example of an objective section is:
minimize myobj: 4 x1 + x2 - 0.1 x3 + [ x1 ^ 2 + 2.1 x1 * x2 ]/2
Please note that the quadratic expressions are multiplied with , so that the above expression means
![]() |
If the same variable occurs more than once in the linear part, the coefficients are added, so that 4 x1 + 2 x1 is equivalent to 6 x1. In the quadratic expressions x1 * x2 is equivalent to x2 * x1 and as in the linear part , if the same variables multiplied or squared occur several times their coefficients are added.
The second section beginning with one of the keywords
subj to subject to s.t. st
defines the linear constraint matrix (A) and the quadratic matrices ().
A constraint contains a name (optional), expressions adhering to the same rules as in the objective and a bound:
subject to con1: x1 + x2 + [ x3 ^ 2 ]/2 <= 5.1
The bound type (here <=) may be any of <, <=, =, >, >= (< and <= mean the same), and the bound may be any number.
In the standard LP format it is not possible to define more than one bound, but MOSEK supports defining ranged constraints by using double-colon (“::”) instead of a single-colon (“:”) after the constraint name, i.e.
![]() |
(D.2.3) |
may be written as
con:: -5 < x_1 + x_2 < 5
By default MOSEK writes ranged constraints this way.
If the files must adhere to the LP standard, ranged constraints must either be split into upper bounded and lower bounded constraints or be written as en equality with a slack variable. For example the expression (D.2.3) may be written as
![]() |
Bounds on the variables can be specified in the bound section beginning with one of the keywords
bound bounds
The bounds section is optional but should, if present, follow the subject to section. All variables listed in the bounds section must occur in either the objective or a constraint.
The default lower and upper bounds are 0 and +∞. A variable may be declared free with the keyword free, which means that the lower bound is -∞ and the upper bound is +∞. Furthermore it may be assigned a finite lower and upper bound. The bound definitions for a given variable may be written in one or two lines, and bounds can be any number or (written as +inf/-inf/+infinity/-infinity) as in the example
bounds x1 free x2 <= 5 0.1 <= x2 x3 = 42 2 <= x4 < +inf
The final two sections are optional and must begin with one of the keywords
bin binaries binary
and
gen general
Under general all integer variables are listed, and under binary all binary (integer variables with bounds 0 and 1) are listed:
general x1 x2 binary x3 x4
Again, all variables listed in the binary or general sections must occur in either the objective or a constraint.
A simple example of an LP file with two variables, four constraints and one integer variable is:
minimize -10 x1 -9 x2 subject to 0.7 x1 + x2 <= 630 0.5 x1 + 0.833 x2 <= 600 x1 + 0.667 x2 <= 708 0.1 x1 + 0.025 x2 <= 135 bounds 10 <= x1 x1 <= +inf 20 <= x2 <= 500 general x1 end
Anything on a line after a “” is ignored and is treated as a comment.
A name for an objective, a constraint or a variable may contain the letters a-z, A-Z, the digits 0-9 and the characters
!"#$%&()/,.;?@_'`{}|~
The first character in a name must not be a number, a period or the letter 'e' or 'E'. Keywords must not be used as names.
It is strongly recommended not to use double quotes (") in names.
Specifying several upper or lower bounds on one variable is possible but MOSEK uses only the tightest bounds. If a variable is fixed (with =), then it is considered the tightest bound.
Some optimization software packages employ a more strict definition of the LP format that the one used by MOSEK. The limitations imposed by the strict LP format are the following:
If an LP formatted file created by MOSEK should satisfies the strict definition, then the parameter
Env.iparam.write_lp_strict_format
should be set; note, however, that some problems cannot be written correctly as a strict LP formatted file. For instance, all names are truncated to 16 characters and hence they may loose their uniqueness and change the problem.
To get around some of the inconveniences converting from other problem formats, MOSEK allows lines to contain 1024 characters and names may have any length (shorter than the 1024 characters).
Internally in MOSEK names may contain any (printable) character, many of which cannot be used in LP names. Setting the parameters
Env.iparam.read_lp_quoted_names
and
Env.iparam.write_lp_quoted_names
allows MOSEK to use quoted names. The first parameter tells MOSEK to remove quotes from quoted names e.g, "x1", when reading LP formatted files. The second parameter tells MOSEK to put quotes around any semi-illegal name (names beginning with a number or a period) and fully illegal name (containing illegal characters). As double quote is a legal character in the LP format, quoting semi-illegal names makes them legal in the pure LP format as long as they are still shorter than 16 characters. Fully illegal names are still illegal in a pure LP file.
The LP format is not a formal standard and different vendors have slightly different interpretations of the LP format. To make MOSEK's definition of the LP format more compatible whith the definitions of other vendors use the paramter setting
MSK_IPAR_WRITE_LP_STRICT_FORMAT MSK_ON
This setting may lead to truncation of some names and hence to an invalid LP file. The simple solution to this problem is to use the paramter setting
MSK_IPAR_WRITE_GENERIC_NAMES MSK_ON
which will cause all names to be renamed systematically in the output file.
A few parameters control the visual formatting of LP files written by MOSEK in order to make it easier to read the files. These parameters are
MSK_IPAR_WRITE_LP_LINE_WIDTH MSK_IPAR_WRITE_LP_TERMS_PER_LINE
The first parameter sets the maximum number of characters on a single line. The default value is 80 corresponding roughly to the width of a standard text document.
The second parameter sets the maximum number of terms per line; a term means a sign, a coefficient, and a name (for example “+ 42 elephants”). The default value is 0, meaning that there is no maximum.
If the input file should be read as fast as possible using the least amount of memory, then it is important to tell MOSEK how many non-zeros, variables and constraints the problem contains. These values can be set using the parameters
MSK_IPAR_READ_CON MSK_IPAR_READ_VAR MSK_IPAR_READ_ANZ MSK_IPAR_READ_QNZ
Reading and writing an LP file with MOSEK may change it superficially. If an LP file contains unnamed constraints or objective these are given their generic names when the file is read (however unnamed constraints in MOSEK are written without names).