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:

having the bounds

In the `OPF`

format the example is displayed as shown in Listing 15.1.

### 15.3.7.2 Quadratic Example `qo1.opf`

¶

An example of a quadratic optimization problem is

This can be formulated in `opf`

as shown below.

```
[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:

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.

### 15.3.7.4 Mixed Integer Example `milo1.opf`

¶

Consider the mixed integer problem:

This can be implemented in `OPF`

with the file in Listing 15.4.