Warning

This file format is to a large extent deprecated. While it can still be used for linear and quadratic problems, for conic problems the Sec. 15.5 (The PTF Format) is recommended.

15.3 The OPF Format

The Optimization Problem Format (OPF) is an alternative to LP and MPS files for specifying optimization problems. It is row-oriented, inspired by the CPLEX LP format.

Apart from containing objective, constraints, bounds etc. it may contain complete or partial solutions, comments and extra information relevant for solving the problem. It is designed to be easily read and modified by hand and to be forward compatible with possible future extensions.

Intended use

The OPF file format is meant to replace several other files:

  • The LP file format: Any problem that can be written as an LP file can be written as an OPF file too; furthermore it naturally accommodates ranged constraints and variables as well as arbitrary characters in names, fixed expressions in the objective, empty constraints, and conic constraints.

  • Parameter files: It is possible to specify integer, double and string parameters along with the problem (or in a separate OPF file).

  • Solution files: It is possible to store a full or a partial solution in an OPF file and later reload it.

15.3.1 The File Format

The format uses tags to structure data. A simple example with the basic sections may look like this:

[comment]
This is a comment. You may write almost anything here...
[/comment]

# This is a single-line comment.

[objective min 'myobj']
x + 3 y + x^2 + 3 y^2 + z + 1
[/objective]

[constraints]
[con 'con01'] 4 <= x + y  [/con]
[/constraints]

[bounds]
[b] -10 <= x,y <= 10  [/b]

[cone quad] x,y,z [/cone]
[/bounds]

A scope is opened by a tag of the form [tag] and closed by a tag of the form [/tag]. An opening tag may accept a list of unnamed and named arguments, for examples:

[tag value] tag with one unnamed argument [/tag]
[tag arg=value] tag with one named argument [/tag]

Unnamed arguments are identified by their order, while named arguments may appear in any order, but never before an unnamed argument. The value can be a quoted, single-quoted or double-quoted text string, i.e.

[tag 'value']     single-quoted value [/tag]
[tag arg='value'] single-quoted value [/tag]
[tag "value"]     double-quoted value [/tag]
[tag arg="value"] double-quoted value [/tag]

15.3.2 Sections

The recognized tags are

[comment]

A comment section. This can contain almost any text: Between single quotes () or double quotes (") any text may appear. Outside quotes the markup characters ([ and ]) must be prefixed by backslashes. Both single and double quotes may appear alone or inside a pair of quotes if it is prefixed by a backslash.

[objective]

The objective function: This accepts one or two parameters, where the first one (in the above example min) is either min or max (regardless of case) and defines the objective sense, and the second one (above myobj), if present, is the objective name. The section may contain linear and quadratic expressions.

If several objectives are specified, all but the last are ignored.

[constraints]

This does not directly contain any data, but may contain subsections con defining a linear constraint.

[con]

Defines a single constraint; if an argument is present ([con NAME]) this is used as the name of the constraint, otherwise it is given a null-name. The section contains a constraint definition written as linear and quadratic expressions with a lower bound, an upper bound, with both or with an equality. Examples:

[constraints]
[con 'con1'] 0 <= x + y       [/con]
[con 'con2'] 0 >= x + y       [/con]
[con 'con3'] 0 <= x + y <= 10 [/con]
[con 'con4']      x + y  = 10 [/con]
[/constraints]

Constraint names are unique. If a constraint is specified which has the same name as a previously defined constraint, the new constraint replaces the existing one.

[bounds]

This does not directly contain any data, but may contain subsections b (linear bounds on variables) and cone (cones).

[b]

Bound definition on one or several variables separated by comma (,). An upper or lower bound on a variable replaces any earlier defined bound on that variable. If only one bound (upper or lower) is given only this bound is replaced. This means that upper and lower bounds can be specified separately. So the OPF bound definition:

[b]  x,y >= -10  [/b]
[b]  x,y <= 10   [/b]

results in the bound \(-10 \leq x,y \leq 10\).

[cone]

Specifies a cone. A cone is defined as a sequence of variables which belong to a single unique cone. The supported cone types are:

  • quad: a quadratic cone of \(n\) variables \(x_1,\ldots, x_n\) defines a constraint of the form

    \[x_1^2 \geq \sum_{i=2}^n x_i^2,\quad x_1\geq 0.\]
  • rquad: a rotated quadratic cone of \(n\) variables \(x_1,\ldots ,x_n\) defines a constraint of the form

    \[2x_1 x_2 \geq \sum_{i=3}^n x_i^2,\quad x_1,x_2\geq 0.\]
  • pexp: primal exponential cone of \(3\) variables \(x_1,x_2,x_3\) defines a constraint of the form

    \[x_1\geq x_2\exp(x_3/x_2), \quad x_1,x_2\geq 0.\]
  • ppow with parameter \(0<\alpha<1\): primal power cone of \(n\) variables \(x_1,\ldots ,x_n\) defines a constraint of the form

    \[x_1^\alpha x_2^{1-\alpha}\geq \sqrt{\sum_{j=3}^{n} x_j^2},\quad x_1,x_2 \geq 0.\]
  • dexp: dual exponential cone of \(3\) variables \(x_1,x_2,x_3\) defines a constraint of the form

    \[x_1 \geq -x_3 e^{-1}\exp(x_2/x_3), \quad x_3\leq 0,x_1 \geq 0.\]
  • dpow with parameter \(0<\alpha<1\): dual power cone of \(n\) variables \(x_1,\ldots ,x_n\) defines a constraint of the form

    \[\left(\frac{x_1}{\alpha}\right)^\alpha \left(\frac{x_2}{1-\alpha}\right)^{1-\alpha} \geq \sqrt{\sum_{j=3}^{n^t} x^2_j}, \quad x_1, x_2 \geq 0.\]
  • zero: zero cone of \(n\) variables \(x_1,\ldots ,x_n\) defines a constraint of the form

    \[x_1=\cdots=x_n=0\]

A [bounds]-section example:

[bounds]
[b]  0 <= x,y <= 10  [/b] # ranged bound
[b] 10 >= x,y >=  0  [/b] # ranged bound
[b]  0 <= x,y <= inf [/b] # using inf
[b]       x,y free   [/b] # free variables
# Let (x,y,z,w) belong to the cone K
[cone rquad] x,y,z,w  [/cone] # rotated quadratic cone
[cone ppow '3e-01' 'a'] x1, x2, x3 [/cone] # power cone with alpha=1/3 and name 'a'
[/bounds]

By default all variables are free.

[variables]

This defines an ordering of variables as they should appear in the problem. This is simply a space-separated list of variable names.

[integer]

This contains a space-separated list of variables and defines the constraint that the listed variables must be integer-valued.

[hints]

This may contain only non-essential data; for example estimates of the number of variables, constraints and non-zeros. Placed before all other sections containing data this may reduce the time spent reading the file.

In the hints section, any subsection which is not recognized by MOSEK is simply ignored. In this section a hint is defined as follows:

[hint ITEM] value [/hint]

The hints recognized by MOSEK are:

  • numvar (number of variables),

  • numcon (number of linear/quadratic constraints),

  • numanz (number of linear non-zeros in constraints),

  • numqnz (number of quadratic non-zeros in constraints).

[solutions]

This section can contain a set of full or partial solutions to a problem. Each solution must be specified using a [solution]-section, i.e.

[solutions]
[solution]...[/solution] #solution 1
[solution]...[/solution] #solution 2
#other solutions....
[solution]...[/solution] #solution n
[/solutions]

The syntax of a [solution]-section is the following:

[solution SOLTYPE status=STATUS]...[/solution]

where SOLTYPE is one of the strings

  • interior, a non-basic solution,

  • basic, a basic solution,

  • integer, an integer solution,

and STATUS is one of the strings

  • UNKNOWN,

  • OPTIMAL,

  • INTEGER_OPTIMAL,

  • PRIM_FEAS,

  • DUAL_FEAS,

  • PRIM_AND_DUAL_FEAS,

  • NEAR_OPTIMAL,

  • NEAR_PRIM_FEAS,

  • NEAR_DUAL_FEAS,

  • NEAR_PRIM_AND_DUAL_FEAS,

  • PRIM_INFEAS_CER,

  • DUAL_INFEAS_CER,

  • NEAR_PRIM_INFEAS_CER,

  • NEAR_DUAL_INFEAS_CER,

  • NEAR_INTEGER_OPTIMAL.

Most of these values are irrelevant for input solutions; when constructing a solution for simplex hot-start or an initial solution for a mixed integer problem the safe setting is UNKNOWN.

A [solution]-section contains [con] and [var] sections. Each [con] and [var] section defines solution information for a single variable or constraint, specified as list of KEYWORD/value pairs, in any order, written as

KEYWORD=value

Allowed keywords are as follows:

  • sk. The status of the item, where the value is one of the following strings:

    • LOW, the item is on its lower bound.

    • UPR, the item is on its upper bound.

    • FIX, it is a fixed item.

    • BAS, the item is in the basis.

    • SUPBAS, the item is super basic.

    • UNK, the status is unknown.

    • INF, the item is outside its bounds (infeasible).

  • lvl Defines the level of the item.

  • sl Defines the level of the dual variable associated with its lower bound.

  • su Defines the level of the dual variable associated with its upper bound.

  • sn Defines the level of the variable associated with its cone.

  • y Defines the level of the corresponding dual variable (for constraints only).

A [var] section should always contain the items sk, lvl, sl and su. Items sl and su are not required for integer solutions.

A [con] section should always contain sk, lvl, sl, su and y.

An example of a solution section

[solution basic status=UNKNOWN]
[var x0] sk=LOW    lvl=5.0      [/var]
[var x1] sk=UPR    lvl=10.0     [/var]
[var x2] sk=SUPBAS lvl=2.0  sl=1.5 su=0.0 [/var]

[con c0] sk=LOW    lvl=3.0 y=0.0 [/con]
[con c0] sk=UPR    lvl=0.0 y=5.0 [/con]
[/solution]
  • [vendor] This contains solver/vendor specific data. It accepts one argument, which is a vendor ID – for MOSEK the ID is simply mosek – and the section contains the subsection parameters defining solver parameters. When reading a vendor section, any unknown vendor can be safely ignored. This is described later.

Comments using the # may appear anywhere in the file. Between the # and the following line-break any text may be written, including markup characters.

15.3.3 Numbers

Numbers, when used for parameter values or coefficients, are written in the usual way by the printf function. That is, they may be prefixed by a sign (+ or -) and may contain an integer part, decimal part and an exponent. The decimal point is always . (a dot). Some examples are

1
1.0
.0
1.
1e10
1e+10
1e-10

Some invalid examples are

e10   # invalid, must contain either integer or decimal part
.     # invalid
.e10  # invalid

More formally, the following standard regular expression describes numbers as used:

[+|-]?([0-9]+[.][0-9]*|[.][0-9]+)([eE][+|-]?[0-9]+)?

15.3.4 Names

Variable names, constraint names and objective name may contain arbitrary characters, which in some cases must be enclosed by quotes (single or double) that in turn must be preceded by a backslash. Unquoted names must begin with a letter (a-z or A-Z) and contain only the following characters: the letters a-z and A-Z, the digits 0-9, braces ({ and }) and underscore (_).

Some examples of legal names:

an_unquoted_name
another_name{123}
'single quoted name'
"double quoted name"
"name with \\"quote\\" in it"
"name with []s in it"

15.3.5 Parameters Section

In the vendor section solver parameters are defined inside the parameters subsection. Each parameter is written as

[p PARAMETER_NAME] value [/p]

where PARAMETER_NAME is replaced by a MOSEK parameter name, usually of the form MSK_IPAR_..., MSK_DPAR_... or MSK_SPAR_..., and the value is replaced by the value of that parameter; both integer values and named values may be used. Some simple examples are

[vendor mosek]
[parameters]
[p MSK_IPAR_OPF_MAX_TERMS_PER_LINE] 10     [/p]
[p MSK_IPAR_OPF_WRITE_PARAMETERS]   MSK_ON [/p]
[p MSK_DPAR_DATA_TOL_BOUND_INF]     1.0e18 [/p]
[/parameters]
[/vendor]

15.3.6 Writing OPF Files from MOSEK

To write an OPF file add the .opf extension to the file name.

15.3.7 Examples

This section contains a set of small examples written in OPF and describing how to formulate linear, quadratic and conic problems.

15.3.7.1 Linear Example lo1.opf

Consider the example:

\[\begin{split}\begin{array}{lccccccccl} \mbox{maximize} & 3 x_0 & + & 1 x_1 & + & 5 x_2 & + & 1 x_3 & &\\ \mbox{subject to} & 3 x_0 & + & 1 x_1 & + & 2 x_2 & & & = & 30,\\ & 2 x_0 & + & 1 x_1 & + & 3 x_2 & + & 1 x_3 & \geq & 15,\\ & & & 2 x_1 & & & + & 3 x_3 & \leq & 25, \end{array}\end{split}\]

having the bounds

\[\begin{split}\begin{array}{ccccc} 0 & \leq & x_0 & \leq & \infty ,\\ 0 & \leq & x_1 & \leq & 10,\\ 0 & \leq & x_2 & \leq & \infty ,\\ 0 & \leq & x_3 & \leq & \infty . \end{array}\end{split}\]

In the OPF format the example is displayed as shown in Listing 15.1.

Listing 15.1 Example of an OPF file for a linear problem. Click here to download.
[comment]
  The lo1 example in OPF format
[/comment]

[hints]
  [hint NUMVAR] 4 [/hint]
  [hint NUMCON] 3 [/hint]
  [hint NUMANZ] 9 [/hint]
[/hints]

[variables disallow_new_variables]
  x1 x2 x3 x4 
[/variables]

[objective maximize 'obj']
   3 x1 + x2 + 5 x3 + x4
[/objective]

[constraints]
  [con 'c1'] 3 x1 +   x2 + 2 x3         = 30 [/con]
  [con 'c2'] 2 x1 +   x2 + 3 x3 +   x4 >= 15 [/con]
  [con 'c3']        2 x2        + 3 x4 <= 25 [/con]
[/constraints]

[bounds]
  [b] 0 <= * [/b]
  [b] 0 <= x2 <= 10 [/b]
[/bounds]

15.3.7.2 Quadratic Example qo1.opf

An example of a quadratic optimization problem is

\[\begin{split}\begin{array}{lrcl} \mbox{minimize} & & & x_1^2 + 0.1 x_2^2 + x_3^2 - x_1 x_3 - x_2 \\ \mbox{subject to} & 1 & \leq & x_1 + x_2 + x_3, \\ & & & x \geq 0. \end{array}\end{split}\]

This can be formulated in opf as shown below.

Listing 15.2 Example of an OPF file for a quadratic problem. Click here to download.
[comment]
  The qo1 example in OPF format
[/comment]

[hints]
  [hint NUMVAR] 3 [/hint]
  [hint NUMCON] 1 [/hint]
  [hint NUMANZ] 3 [/hint]
  [hint NUMQNZ] 4 [/hint]
[/hints]

[variables disallow_new_variables]
  x1 x2 x3 
[/variables]

[objective minimize 'obj']
  # The quadratic terms are often written with a factor of 1/2 as here, 
  # but this is not required.

   - x2 + 0.5 ( 2.0 x1 ^ 2 - 2.0 x3 * x1 + 0.2 x2 ^ 2 + 2.0 x3 ^ 2 )
[/objective]

[constraints]
  [con 'c1'] 1.0 <= x1 + x2 + x3 [/con]
[/constraints]

[bounds]
  [b] 0 <= * [/b]
[/bounds]

15.3.7.3 Conic Quadratic Example cqo1.opf

Consider the example:

\[\begin{split}\begin{array}{lccccc} \mbox{minimize} & x_3 + x_4 + x_5 & & & &\\ \mbox{subject to} & x_0 + x_1 + 2 x_2 & = & 1, & &\\ & x_0,x_1,x_2 & \geq & 0, & &\\ & x_3 \geq \sqrt{x_0^2 + x_1^2}, & & & &\\ & 2 x_4 x_5 \geq x_2^2. & & & & \end{array}\end{split}\]

Please note that the type of the cones is defined by the parameter to [cone ...]; the content of the cone-section is the names of variables that belong to the cone. The resulting OPF file is in Listing 15.3.

Listing 15.3 Example of an OPF file for a conic quadratic problem. Click here to download.
[comment]
  The cqo1 example in OPF format.
[/comment]

[hints]
  [hint NUMVAR] 6 [/hint]
  [hint NUMCON] 1 [/hint]
  [hint NUMANZ] 3 [/hint]
[/hints]

[variables disallow_new_variables]
  x1 x2 x3 x4 x5 x6 
[/variables]

[objective minimize 'obj']
   x4 + x5 + x6
[/objective]

[constraints]
  [con 'c1']  x1 + x2 + 2e+00 x3 = 1e+00 [/con]
[/constraints]

[bounds]
  # We let all variables default to the positive orthant
  [b] 0 <= * [/b]

  # ...and change those that differ from the default
  [b] x4,x5,x6 free [/b]

  # Define quadratic cone: x4 >= sqrt( x1^2 + x2^2 )
  [cone quad 'k1'] x4, x1, x2 [/cone]

  # Define rotated quadratic cone: 2 x5 x6 >= x3^2
  [cone rquad 'k2'] x5, x6, x3 [/cone]
[/bounds]

15.3.7.4 Mixed Integer Example milo1.opf

Consider the mixed integer problem:

\[\begin{split}\begin{array}{lccl} \mbox{maximize} & x_0 + 0.64 x_1 & & \\ \mbox{subject to} & 50 x_0 + 31 x_1 & \leq & 250, \\ & 3 x_0 - 2 x_1 & \geq & -4, \\ & x_0, x_1 \geq 0 & & \mbox{and integer} \end{array}\end{split}\]

This can be implemented in OPF with the file in Listing 15.4.

Listing 15.4 Example of an OPF file for a mixed-integer linear problem. Click here to download.
[comment]
  The milo1 example in OPF format
[/comment]

[hints]
  [hint NUMVAR] 2 [/hint]
  [hint NUMCON] 2 [/hint]
  [hint NUMANZ] 4 [/hint]
[/hints]

[variables disallow_new_variables]
  x1 x2 
[/variables]

[objective maximize 'obj']
   x1 + 6.4e-1 x2
[/objective]

[constraints]
  [con 'c1'] 5e+1 x1 + 3.1e+1 x2 <= 2.5e+2 [/con]
  [con 'c2'] -4 <= 3 x1 - 2 x2 [/con]
[/constraints]

[bounds]
  [b] 0 <= * [/b]
[/bounds]

[integer]
  x1 x2 
[/integer]