15.1 The LP File Format¶
MOSEK supports the LP file format with some extensions. The LP format is not a completely well-defined standard and hence different optimization packages may interpret the same LP file in slightly different ways. MOSEK tries to emulate as closely as possible CPLEX’s behavior, but tries to stay backward compatible.
The LP file format can specify problems of the form
where
\(x \in \real^n\) is the vector of decision variables.
\(c \in \real^n\) is the linear term in the objective.
\(q^o: \in \real^n \rightarrow \real\) is the quadratic term in the objective where
and it is assumed that
\(A \in \real^{m\times n}\) is the constraint matrix.
\(l^c \in \real^m\) is the lower limit on the activity for the constraints.
\(u^c \in \real^m\) is the upper limit on the activity for the constraints.
\(l^x \in \real^n\) is the lower limit on the activity for the variables.
\(u^x \in \real^n\) is the upper limit on the activity for the variables.
\(q: \real^n \rightarrow \real\) is a vector of quadratic functions. Hence,
where it is assumed that
\(\mathcal{J} \subseteq \{1,2,\ldots ,n\}\) is an index set of the integer constrained variables.
15.1.1 File Sections¶
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.
15.1.1.1 Objective Function¶
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
4 x1 + x2 - 0.1 x3
and so forth. The quadratic terms are written in square brackets ([ ]/2
) 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 \(\half\) , 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.
15.1.1.2 Constraints¶
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 \(Q^i\).
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 per line, but MOSEK supports defining ranged constraints by using double-colon (::
) instead of a single-colon (:
) after the constraint name, i.e.
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 an equality with a slack variable. For example the expression (15.1) may be written as
15.1.1.3 Bounds¶
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 \(+\infty\) . A variable may be declared free with the keyword free
, which means that the lower bound is \(-\infty\) and the upper bound is \(+\infty\) . 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 \(\pm \infty\) (written as +inf
/-inf
/+infinity
/-infinity
) as in the example
bounds
x1 free
x2 <= 5
0.1 <= x2
x3 = 42
2 <= x4 < +inf
15.1.1.4 Variable Types¶
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.
15.1.1.5 Terminating Section¶
Finally, an LP formatted file must be terminated with the keyword
end
15.1.2 LP File Examples¶
Linear example lo1.lp
\ File: lo1.lp
maximize
obj: 3 x1 + x2 + 5 x3 + x4
subject to
c1: 3 x1 + x2 + 2 x3 = 30
c2: 2 x1 + x2 + 3 x3 + x4 >= 15
c3: 2 x2 + 3 x4 <= 25
bounds
0 <= x1 <= +infinity
0 <= x2 <= 10
0 <= x3 <= +infinity
0 <= x4 <= +infinity
end
Mixed integer example milo1.lp
maximize
obj: x1 + 6.4e-01 x2
subject to
c1: 5e+01 x1 + 3.1e+01 x2 <= 2.5e+02
c2: 3e+00 x1 - 2e+00 x2 >= -4e+00
bounds
0 <= x1 <= +infinity
0 <= x2 <= +infinity
general
x1 x2
end
15.1.3 LP Format peculiarities¶
15.1.3.2 Names¶
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.
MOSEK accepts any character as valid for names, except \0
. A name that is not allowed in LP file will be changed and a warning will be issued.
The algorithm for making names LP valid works as follows: The name is interpreted as an utf-8
string. For a Unicode character c
:
If
c==_
(underscore), the output is__
(two underscores).If
c
is a valid LP name character, the output is justc
.If
c
is another character in the ASCII range, the output is_XX
, whereXX
is the hexadecimal code for the character.If
c
is a character in the range 127-65535, the output is_uXXXX
, whereXXXX
is the hexadecimal code for the character.If
c
is a character above 65535, the output is_UXXXXXXXX
, whereXXXXXXXX
is the hexadecimal code for the character.
Invalid utf-8
substrings are escaped as _XX'
, and if a name starts with a period, e
or E
, that character is escaped as _XX
.
15.1.3.3 Variable Bounds¶
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.
15.1.3.1 Comments¶
Anything on a line after a
\
is ignored and is treated as a comment.