Userguide
Userguide
Userguide
2
Contents
1 Installation 5
1.1 Windows platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 UNIX-alike platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 A guided tour 14
2.1 Help: How do I use the interface? . . . . . . . . . . . . . . . . . . . . . . . . 14
2.2 Linear Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.2.1 Solving LP problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.2.2 Duality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.2.3 Switching Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2.4 Hot-starting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.2.5 Complete Best Practice example . . . . . . . . . . . . . . . . . . . . 29
2.3 Conic Quadratic Programming . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.3.1 Solving CQP problems . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.3.2 Duality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.3.3 Notes on Quadratic Programming (QP/QCQP) . . . . . . . . . . . . 40
2.4 Semidefinite Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.4.1 Solving SDP problems . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.4.2 Duality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.5 Mixed Integer Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.5.1 Solving MILP and MICQP problems . . . . . . . . . . . . . . . . . . 44
2.5.2 Hot-starting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.5.3 Termination criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
2.6 Parameter settings in MOSEK . . . . . . . . . . . . . . . . . . . . . . . . . 49
2.7 Exporting and Importing optimization models . . . . . . . . . . . . . . . . . 51
2.7.1 The write and read functionality . . . . . . . . . . . . . . . . . . . . 51
2.7.2 Writing immediately before/after optimizing . . . . . . . . . . . . . 54
2.8 Frequently Asked Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.8.1 How to make Rmosek silent? . . . . . . . . . . . . . . . . . . . . . . 56
2.8.2 How to force a premature termination? . . . . . . . . . . . . . . . . 56
2.8.3 How to change the termination criteria? . . . . . . . . . . . . . . . . 56
2.8.4 How to find the objective value and other information items? . . . . 57
2.8.5 How to report a bug or get further help? . . . . . . . . . . . . . . . . 57
3 Advanced topics 58
3.1 Parallel optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
3.1.1 The multicore package . . . . . . . . . . . . . . . . . . . . . . . . . . 58
3.2 Quadratic Convex Optimization . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.2.1 Solving QP problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3
3.3 Separable Convex Optimization . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.3.1 Solving SCOPT problems . . . . . . . . . . . . . . . . . . . . . . . . 63
3.3.2 Convexity, differentiability and safe bounds . . . . . . . . . . . . . . 66
3.3.3 Importing and exporting modelfiles . . . . . . . . . . . . . . . . . . . 67
4 Developers corner 68
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.2 Limitations and Missing Features . . . . . . . . . . . . . . . . . . . . . . . . 69
A Command reference 70
B Conic transformations 77
B.1 The Quadratic Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
4
INSTALLATION
1 Installation
1.1 Windows platforms
The interface documented here is part of the Rmosek package distributed from http:
//rmosek.r-forge.r-project.org/. Notice, however, that a pre-compiled binary version
of it has not been distributed1 . Thus a small amount of configuration is necessary in order
to install the package. It is not very difficult, but besides the basic installation of R you
will need two pieces of software readily available through the Internet. In summary:
The following is a step-by-step guide through the installation of the package. We skip
the installation of MOSEK as it has been well documented elsewhere and assume that
the target machine already has a working installation. Please refer to the documentation
available at http://mosek.com for the verification of this installation. The basic test for
this is:
For additional help installing this interface, the section on packages in the “R for
Windows FAQ” available on the CRAN website may be useful. The “R Installation and
Administration” manual, also published by CRAN on their website, is another good source
of information.
1
Such a binary would have to be built individually for each version of R and MOSEK.
2
Check http://mosek.com on free licenses for academic use and trial evaluation periods. For commercial
use, licenses needed to handle a problem with MOSEK is also those needed when using Rmosek.
5
1.1 Windows platforms INSTALLATION
R toolset and Cygwin DLLs will extend the Windows CMD with Unix-style commands,
while the R toolchain (based on MinGW compilers) makes it possible to compile the
C++ source code in the package. These components can be replaced by any other Unix-
style shell and C++ build chain, but in the remaining guide the use of Rtools will be
assumed.
After the installation of Rtools you will have to set the Windows environment variable
called PATH , in order to utilize the components. Assuming that the home directory of
the Rtools installation was c:\Rtools, the entries shown below will have to be added to
the existing PATH variable. Note that all entries in the PATH variable must be separated
by a semicolon (;), and that all these entries have to represent folders that exist on the
target machine.
Add c:\Rtools\bin; to enable the R toolset and Cygwin DLLs.
Add c:\Rtools\gcc-VERSION\bin; (for some VERSION) to enable the R toolchain.
That was it, but before we move on to the installation process, please ensure that the
PATH variable also contains the “bin” folder of all MOSEK installations (32 and/or 64
bit) that you wish this interface to target. This is necessary for automatic configuration
to work, and could look something like:
C:\Progra∼1\Mosek\7\tools\platform\win64x86\bin
6
1.1 Windows platforms INSTALLATION
Now open R for the architecture (64 or 32 bit) you wish to install the package on. Make sure
all your packages are up to date by writing update.packages(), and execute a command
similar to the one shown below. This will install the ’Rmosek’ package:
Note that this package will have to be installed from source as it needs a static link to
the MOSEK optimization library. This unfortunately means that dependencies (i.e. the
’Matrix’ package) will also be installed from source if new releases are available. Since it
is more time-consuming to install the ’Matrix’ package from source, it is recommended to
start with a call to update.packages(). The availability of the ’Matrix’ package should
not be a problem, as it has been part of the standard R installation since version 2.9.0.
2. Setup the local system descriptors, Localsys.txt, for each of the sub-architectures you
will be using: 64 bit (e.g. x64) and/or 32 bit (e.g. i386). These files come with a
guide written into them that clearly states how this should be done.
The first step is to extract the Rmosek_VERSION.tar.gz archive that you downloaded.
This can either be done by using one of the many tools freely available online4 , or the
4
Search the web for the keywords: Windows, Packing, Unpacking, Tar, Gz
7
1.1 Windows platforms INSTALLATION
tar-command that was installed with Rtools. If you choose to use the tar-command, you
can extract the package by opening Windows CMD and executing a command similar to:
Remember to exchange LOCATION and VERSION with the correct values. For those
not familiar with Windows CMD, we recommend the use of an external tool as this
configuration can then be performed entirely within Windows Explorer.
The second step is to tell the package where to find the MOSEK optimization library. Open
the extracted directory called Rmosek in either Windows CMD or Windows Explorer, and
navigate to the subdirectory called src\setup. If you want to install a 64 bit version of the
package (making an interface between 64 bit R and 64 bit MOSEK), open the folder x64
and follow the guide in Localsys.txt. If you want to install a 32 bit version of the package
(making an interface between 32 bit R and 32 bit MOSEK), open instead the folder i386
and follow the guide in this Localsys.txt. An example of this is shown in Figure 1.
The third and final step is to compress the (previously extracted and now altered) directory
called Rmosek, back into the Rmosek_VERSION.tar.gz archive. Again you can either make
use of the external tools from step one, or open the Windows CMD and execute a command
similar to:
install.packages("LOCATION\Rmosek_VERSION.tar.gz", repos=NULL,
type="source", INSTALL_opts="--no-multiarch")
Remember to exchange LOCATION and VERSION with the correct values. The first
argument should be the path to your manually configured package. The second argument
tells that the package is local and not in an online repository. The third argument tells
that it is a source package and so should be compiled. The fourth and final argument
specifies that you only wish to install the package to the specific architecture (64 or 32 bit)
of the opened R program. If you wish to install on both architectures, and did configure
the package for both 32 and 64 bit, simply remove this last argument.
Notice that if you wish to uninstall the ’Rmosek’ package at some point, this can be done
as for any other package with the command remove.packages("Rmosek").
8
1.1 Windows platforms INSTALLATION
##################
## Step 1 of 2 ##
##################
## Please substitute [ MOSEK_HOME_PATH ] below , with the path to the
## platform - specific folder within the MOSEK installation you want to
## use . Note that this path should contain a " bin " and a " h " folder .
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
## For example you can write :
## PKG_MOSEKHOME = C :\ Progra ~1\ Mosek \7\ tools \ platform \ win64x86
##
## If your computer contains the two directories :
## C :\ Progra ~1\ Mosek \7\ tools \ platform \ win64x86 \ bin
## C :\ Progra ~1\ Mosek \7\ tools \ platform \ win64x86 \ h
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PKG_MOSEKHOME =[ MOSEK_HOME_PATH ]
##################
## Step 2 of 2 ##
##################
## Please substitute [ MOSEK_LIB_FILE ] below , with the name of the library
## you wish to use within the " bin " folder of your PKG_MOSEKHOME path .
## This " bin " folder must contain a file called [ MOSEK_LIB_FILE ]. lib .
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
## Continuing the example from above , you can write :
## PKG_MOSEKLIB = mosek64_7_0
##
## If your computer contains the file :
## C :\ Progra ~1\ Mosek \7\ tools \ platform \ win64x86 \ bin \ mosek64_7_0 . lib
## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PKG_MOSEKLIB =[ MOSEK_LIB_FILE ]
9
1.2 UNIX-alike platforms INSTALLATION
The following is a step-by-step guide through the installation of the package. We skip
the installation of MOSEK as it has been well documented elsewhere and assume that
the target machine already has a working installation. Please refer to the documentation
available at http://mosek.com for the verification of this installation. The basic test is:
For additional help on installing this interface, the section on installing packages in the
manual “R Installation and Administration”, published on the CRAN website, is a good
source of information.
5
Such a binary would have to be built individually for each version of R and MOSEK.
6
Check http://mosek.com on free licenses for academic use and trial evaluation periods. For commercial
use, licenses needed to handle a problem with MOSEK is also those needed when using Rmosek.
10
1.2 UNIX-alike platforms INSTALLATION
For automatic configuration to work, the PATH variable should contain the “bin” folder of
the single MOSEK installation (32 or 64 bit) that you wish this interface to target. This
could look something like:
∼/mosek/7/tools/platform/linux64x86/bin
If more than one “bin” folder from a MOSEK installation are specified, only the first one
will be found by automatic configuration. Additional architectures can be added afterwards
if necessary.
Now open R for the architecture (64 or 32 bit) you wish to install the package on. Make sure
all your packages are up to date by writing update.packages(), and execute a command
similar to the one shown below. This will install the ’Rmosek’ package:
Note that this package will have to be installed from source as it needs a static link to
the MOSEK optimization library. This unfortunately means that dependencies (i.e. the
’Matrix’ package) will also be installed from source if new releases are available. Since it
is more time-consuming to install the ’Matrix’ package from source, it is recommended to
start with a call to update.packages(). The availability of the ’Matrix’ package should
not be a problem, as it has been part of the standard R installation since version 2.9.0.
11
1.2 UNIX-alike platforms INSTALLATION
/home/username/mosek/7/tools/platform/linux64x86
Notice that auto-expansions such as ∼ does not work, and in case the folder definition
contains spaces you will either have to wrap the definition in single-quotes or add
backslashes in front of all spaces.
The definition of the argument PKG_MOSEKLIB should be the name of the
optimization library in the “bin” subdirectory that you wish to utilize in the Rmosek
package. This library will be statically linked to the package after a successful installation.
Note that the name of the optimization library should be specified without the “lib” prefix,
and without its file-extension. The PKG_MOSEKLIB would thus normally be either
mosek or mosek64 (linking to respectively libmosek.so and libmosek64.so, or respectively
libmosek.dylib and libmosek64.dylib, depending on the Unix-alike system). Using mosek64
requires a 64 bit version of the opened R program and MOSEK installation, while mosek
implies 32 bit.
12
1.2 UNIX-alike platforms INSTALLATION
Open R in the sub-architecture you wish to extend your installation to, and execute a
command similar to the one shown below:
13
A GUIDED TOUR
2 A guided tour
2.1 Help: How do I use the interface?
To access the functions of the R-to-MOSEK interface, the Rmosek package have to be
loaded first. Opening the R-console and typing the command:
require(Rmosek)
will load the package if it has been installed properly. If this does not work, you should
go back to Section 1 and check your installation. Note that the Matrix package will
automatically be loaded also as the Rmosek package depends on it for the representation
of sparse matrices. The Matrix package have been part of the standard R installation since
version 2.9.0, and should thus be available without further notice.
If the package loaded successfully without errors, you should now be able to use the
functions of the R-to-MOSEK interface. For example, the following function will return
the version of the MOSEK optimization library that this package is currently linked to:
mosek_version()
To see a summary of the Rmosek package with a complete list of all exported functions,
the following command can be used:
library(help="Rmosek")
In addition to mosek_version, this list also includes mosek, which is the main function
of the package able to solve a broad range of convex optimization problems using one
of the optimizers from MOSEK. When mosek is called for the first time, a MOSEK
environment is acquired occupying one user license. Given the extra overhead of acquiring
and releasing licenses, this environment is typically held until R is terminated. If the
user wish to release the environment and occupied license earlier than this, a call to
mosek_clean will free such resources. To support other modeling languages, the functions
mosek_read and mosek_write is able to handle model files in several formats. The
functions mosek_lptoprob and mosek_qptoprob offers an alternative way of formulating
linear and quadratic programs.
14
2.1 Help: How do I use the interface? A GUIDED TOUR
Being aware of how the user licenses of MOSEK are handled in this interface, we can now
proceed with guidance on how to use the available functions. For instance, if you wish
to know more about the mosek function, you would simple have to execute the following
command:
?mosek
This will give you a detailed description of the function, including a list of recognized
input arguments, an outline of the expected output, and an example of its usage. This
information will also be shown if you fail to call a function with the correct number of
input arguments. As an example, the input arguments and return value printed as part of
the information given when calling ?mosek, is shown in Figure 2.
Many of the input and output arguments are probably not relevant for your project and so
will not all be explained here, but instead elaborated in the sections to which they belong.
If you are new to the interface, you can simply to read on. If you on the other hand are
looking for something specifically, it may be beneficial to look at the brief summary in
Appendix A for references to more information.
Usage :
r <- mosek ( problem , opts = list ())
Arguments :
problem LIST
.. $sense STRING
.. $c NUMERIC VECTOR
.. $c0 NUMERIC ( OPTIONAL )
.. $A SPARSE MATRIX
.. $bc NUMERIC MATRIX (2 rows )
.. $bx NUMERIC MATRIX (2 rows )
.. $cones LIST MATRIX (2 rows ) ( OPTIONAL )
.. $bardim NUMERIC VECTOR ( OPTIONAL )
.. $barc LIST ( OPTIONAL )
.. $barA LIST ( OPTIONAL )
.. $intsub NUMERIC VECTOR ( OPTIONAL )
.. $qobj LIST ( OPTIONAL )
.. $scopt LIST ( OPTIONAL )
.. $iparam / $dparam / $sparam LIST ( OPTIONAL )
.... $ < MSK_PARAM > STRING / NUMERIC ( OPTIONAL )
.. $sol LIST ( OPTIONAL )
.... $itr / $bas / $int LIST ( OPTIONAL )
15
2.1 Help: How do I use the interface? A GUIDED TOUR
Value :
r LIST
.. $response LIST
.... $code NUMERIC
.... $msg STRING
.. $sol LIST
.... $itr / $bas / $int LIST ( SOLVER DEPENDENT )
...... $solsta STRING
...... $prosta STRING
...... $skc STRING VECTOR
...... $skx STRING VECTOR
...... $skn STRING VECTOR ( NOT in $bas )
...... $xc NUMERIC VECTOR
...... $xx NUMERIC VECTOR
...... $barx NUMERIC VECTOR ( NOT in $bas )
...... $slc NUMERIC VECTOR ( NOT IN $int )
...... $suc NUMERIC VECTOR ( NOT IN $int )
...... $slx NUMERIC VECTOR ( NOT IN $int )
...... $sux NUMERIC VECTOR ( NOT IN $int )
...... $snx NUMERIC VECTOR ( NOT IN $int / $bas )
...... $bars NUMERIC VECTOR ( NOT in $int / $bas )
...... $pobjval NUMERIC *
...... $dobjval NUMERIC *( NOT IN $int )
...... $pobjbound NUMERIC *( $int ONLY )
...... $maxinfeas LIST *
........ $pbound NUMERIC *
........ $peq NUMERIC *
........ $pcone NUMERIC *( NOT in $bas )
........ $dbound NUMERIC *( NOT in $int )
........ $deq NUMERIC *( NOT in $int )
........ $dcone NUMERIC *( NOT in $int / $bas )
........ $int NUMERIC *( $int ONLY )
.. $iinfo / $dinfo LIST *
.... $ < MSK_INFO > NUMERIC *
16
2.2 Linear Programming A GUIDED TOUR
minimize cT x + c0
c
subject to l ≤ Ax ≤ uc , (2.1)
lx ≤ x ≤ ux .
All LP problems can be written on this form where e.g. equality constraint will be given the
same upper and lower bound, but what if you have an upper-bounded constraint with no
lower-bound? To exclude such bounds, the interface utilizes the R constant Inf and allows
you to specify lower bounds of minus infinity (-Inf ) and upper bounds of plus infinity (Inf ),
that will render bounds as non-existing. The interface will always expect LP problems on
this form, and will accordingly set the dual variables of the non-existing bounds to zero to
satisfy complementarity - a condition for optimality.
This is easily programmed in R as shown in Figure 4. The first line overwrites any previous
definitions of the variable lo1, preparing for the new problem description. The problem is
then defined and finally solved on the last line.
7
Check out: mosek.com → Documentation → Optimization tools manual → Modeling → Linear
optimization.
17
2.2 Linear Programming A GUIDED TOUR
Notice how the R value Inf is used in both the constraint bounds (blc and buc) and the
variable upper bound (bux), to avoid the specification of an actual bound. If this example
does not work you should go back to Section 1 on setting up the interface.
From this example the input arguments for the linear program (2.1) follows easily (refer
to the definitions of input arguments in Figure 2, Section 2.1).
Objective The string sense is the objective goal and could be either “minimize”,
“min”, “maximize” or “max”. The dense numeric vector c specifies the coefficients
in front of the variables in the linear objective function, and the optional constant
scalar c0 (reads: c zero) is a constant in the objective corresponding to c0 in
problem (2.1), that will be assumed zero if not specified.
Constraint Matrix The sparse matrix A is the constraint matrix of the problem
with the constraint coefficients written row-wise. Notice that for larger problems
it may be more convenient to define an empty sparse matrix and specify the non-
zero elements one at a time A(i, j) = aij , rather than writing out the full matrix
as done in the ’lo1’ example. E.g. Matrix(0,nrow=30,ncol=50,sparse=TRUE).
Bounds The constraint bounds bc with rows blc (constraint lower bound) and buc
(constraint upper bound), as well as the variable bounds bx with rows blx (variable
lower bound) and bux (variable upper bound), are both given as dense numeric
matrices. These are equivalent to the bounds of problem (2.1), namely lc , uc , lx
and ux .
18
2.2 Linear Programming A GUIDED TOUR
Error messages works fine when you are interacting with the interface, but in automated
optimization frameworks they are not easily handled. This is why a response is always
returned as part of the result, when calling a function that may produce errors (see e.g.
Figure 2). The response is a list containing a code and msg. When an error happens inside
a function call to the MOSEK optimization library, the code is the response code returned
by the function call8 and msg is the corresponding error message. When an error happens
within the interface, the code equals NaN and the msg is the error message which, in case
of unexpected execution paths, may require technical knowledge to understand. When no
errors are encountered, the code is zero, but beware that comparison operators such as
’==’ does not handle NaN very good. Using identical may be a better alternative.
8
Check out: mosek.com → Documentation → C API manual → Response codes.
19
2.2 Linear Programming A GUIDED TOUR
The ’lo1’ Example (Part 2 of 5) The ’lo1’ example was solved using the default
optimizer (the interior-point algorithm) and contains two solutions: the interior-point (itr)
and the basic solution (bas) partly shown here.
As seen in Figure 5 and Figure 6 the solution space of the problem was not empty (as it
is primal feasible) and the objective was not unbounded (as it is dual feasible). In addition
the optimizer was able to identify the optimal solution.
Figure 5: Primal Solution I (lo1)
r$sol$itr
{
$solsta
[1] " OPTIMAL "
$prosta
[1] " P R I MA L _ A ND _ D U AL _ F E AS I B L E "
$skc
[1] " EQ " " SB " " UL "
$skx
[1] " LL " " LL " " SB " " SB "
$skn
character (0)
$xc
[1] 30.00000 53.33333 25.00000
$xx
[1] 1.044111 e -08 2.856068 e -08 1.500000 e +01 8.333333 e +00
...
}
Notice that the basic solution bas is likely to have a higher numerical accuracy than the
interior-point solution itr as is the case in this example considering the xx variables.
20
2.2 Linear Programming A GUIDED TOUR
The solution you receive from the interface will contain the primal variable x (called xx)
and the activity of each constraint, xc, defined by xc = Ax. From the solution status
(called solsta) it can be seen how good this solution is, e.g. optimal, nearly optimal,
feasible or infeasible. If the solution status is not as you expected, it might be that the
problem is either ill-posed, infeasible or unbounded (dual infeasible). This can be read
from the problem status (called prosta). The solution and problem status are based on
certificates found by the MOSEK optimization library9 , and should always be verified
before the returned solution values are used (see Section 2.2.5).
The solution also contains status key vectors for both variables and constraints (called skx
and skc). The variable skn is not useful for linear programming problems. Each status
key will be one of the following two-character strings.
BS : Basic
In basic (bas) solutions: The constraint or variable belongs to the basis of the
corresponding simplex tableau.
SB : Super Basic
In interior-point (itr) and integer (int) solutions: The activity of a constraint or variable
is in between its bounds.
LL : Lower Level
The constraint or variable is at its lower bound.
UL : Upper Level
The constraint or variable is at its upper bound.
EQ : Equality
The constraint or variable is at its fixed value (equal lower and upper bound).
UN : Unknown
The status of the constraint or variable could not be determined (in practice never
returned by MOSEK).
In addition to the primal variables just presented, the returned solutions also contains dual
variables not shown here. The dual variables can be used for sensitivity analysis of the
problem parameters and are related to the dual problem explained in Section 2.2.2.
9
More details on problem and solution status keys available at:
mosek.com → Documentation → Optimization tools manual → Symbolic constants reference.
21
2.2 Linear Programming A GUIDED TOUR
2.2.2 Duality
The dual problem corresponding to the primal problem (2.1) defined in Section 2.2.1, is
shown below in (2.4). Notice that the coefficients of the dual problem is the same as those
used in the primal problem. Matrix A for example is still the constraint matrix of the
primal problem, merely transposed in the dual problem.
In addition, the dual problem have dual variables for each lower and upper, constraint
and variable bound in the primal problem: scl ∈ Rm , scu ∈ Rm , sxl ∈ Rn and sxu ∈ Rn (the
latter being the dual variable of the upper variable bound).
Recall that equality constraints had to be specified using two inequalities (with lc = uc )
by definition of the primal problem (2.1). This means that an equality constraint will have
two dual variables instead of just one. If the user wants to calculate the one dual variable,
as it would have been if equality constraints could be specified directly, then this is given
by scl − scu . However, it is not always recommended to do so, as it is often easier to stay
with the same problem formulation and do all calculations directly on that.
The ’lo1’ Example (Part 3 of 5) The part of the solution to the ’lo1’ example that
was previously omitted, is now shown in Figure 7 and 8. The dual variables slc, suc, slx
and sux corresponds naturally to scl , scu , sxl and sxu in the dual problem. The variable snx
is not useful for linear programming problems.
Looking at the definition of the ’lo1’ problem (2.2), the first constraint is an equality,
the second is an lower bound, and the third is an upper bound. The dual variable of
the inequalities should just be read from slc and suc respectively, while for the equality
constraint, having two dual variables, you could also look at the combined lower minus
upper constraint dual variable (slc - suc), which in this case would give you a dual value
of 2.5.
22
2.2 Linear Programming A GUIDED TOUR
Notice that the basic solution bas is likely to have a higher numerical accuracy than the
interior-point solution itr as is the case here.
23
2.2 Linear Programming A GUIDED TOUR
the enum reference-string “OPTIMIZER_FREE” which imply that MOSEK should choose
an optimizer on its own. Currently MOSEK always selects the interior-point algorithm
for linear programming problems which performs especially well for large optimization
problems, but for small to medium sized problems it might sometimes be beneficial to
switch over to the simplex method.
The ’lo1’ Example (Part 4 of 5) In this example we shall try to solve the ’lo1’ example
from Section 2.2.1 using the primal simplex method. This is specified by setting the
integer parameter to the reference-string “OPTIMIZER_PRIMAL_SIMPLEX” as shown
in Figure 9, adding a single line to the ’lo1’ definition from earlier.
24
2.2 Linear Programming A GUIDED TOUR
The output only contains the optimal basic solution bas, which is equivalent to the basic
solution found by the interior-point algorithm in the previous ’lo1’ examples. To verify
that the primal simplex method was actually the optimizer used for this problem, we can
check the log printed to the screen and shown in Figure 10.
2.2.4 Hot-starting
Hot-starting (also known as warm-starting) is a way to make the optimization process
aware of a point in the solution space which, depending on the quality of it (feasibility
and closeness to the optimal solution), can increase the speed of optimization. In linear
programming it is typically used when you know the optimal solution to a similar problem
with only few small changes to the constraints and objective. In these cases it is assumed
that the next optimal solution is nearby in the solution space, and thus it would also makes
sense to switch to the simplex optimizers excellent for small changes to the set of basic
variables - even on large problems. In fact, currently, the user will have to use one of the
simplex optimizers for hot-starting in linear programming, as the interior-point optimizer
in MOSEK cannot take advantage of initial solutions.
Simplex optimizers only look for the basic solution bas in the input argument $sol, and do
not consider the solution and problem statuses within. These may however be specified
anyway for the convenience of the user, and warnings will only be given if no useful
information could be given to the MOSEK optimizer despite the fact that $sol had a
non-empty definition and hot-starting was attempted.
25
2.2 Linear Programming A GUIDED TOUR
which is equal to the ’lo1’ problem (2.2), except that a new variable x5 has been added.
To hot-start from the previous solution of Figure 4, which is still primal feasible, we can
expand the problem description and include x5 as shown.
26
2.2 Linear Programming A GUIDED TOUR
27
2.2 Linear Programming A GUIDED TOUR
So basically stkeys[[idx]] will return the status key of index idx, and can be vectorized
as stkeys[idxvec] for a vector of indexes idxvec. Going in the opposite direction from
status keys to indexes requires a bit more work. For this you can use match(str,stkeys)
to find the index of a status key str, and equivalently match(strvec,stkeys) for a vector
of status keys strvec.
28
2.2 Linear Programming A GUIDED TOUR
29
2.2 Linear Programming A GUIDED TOUR
error in the first place, the returned solution may only be partially constructed. Ultimately,
no guarantees about the availability of variables can be given when the response code is
not zero.
In case of a non-zero response code, the availability of a variable within a result res,
can be tested with an expression similar to !inherits(try({res$sol$itr$solsta})),
"try-error"), which is TRUE when a solution status to a interior-point solution in the
result has been defined. Notice that a scope has been defined in the input argument of
the try function using ’{’ and ’}’. Within this scope, several variables can be tested for
existence, or alternatively, entire blocks of code may be inserted and attempted evaluated.
A response code of zero is not enough to conclude that a solution can be extracted from
the returned data. In particular, the returned data may be a certificate of primal or dual
infeasibility instead of a solution to the problem. Moreover, the returned primal variables
may not contain any useful information if the solution status is e.g. DUAL_FEASIBLE. This
also holds true for dual variables if the solution status is e.g. PRIMAL_FEASIBLE. Thus it is
important to check and respond to the solution status before using the solution variables.
30
2.2 Linear Programming A GUIDED TOUR
PRIMAL_INFEASIBLE
The problem description is primal infeasible.
NEAR_PRIMAL_FEASIBLE
The problem description satisfies a relaxed primal feasibility criterion.
PRIMAL_FEASIBLE
The problem description is primal feasible.
ILL_POSED (non-linear problems only)
The problem description has an unstable formulation.
Regarding the usefulness of the returned data, the solution status often tells the whole
story. For mixed integer programs (see Section 2.5), there is however no certificates for
infeasibility and this status have to be read from the problem status. Also, if the solution
status is UNKNOWN, the problem status may still contain valuable information. Furthermore,
for non-linear problems, it is a good idea to verify that the problem status is not ILL_POSED.
The ’lo1’ Example (Part 5 of 5) In this example we define a function which shall
try to solve the ’lo1’ example from Section 2.2.1, and return the variable activities of the
basic solution. The function is completely silent except for the explicit cat-commands,
and will not fail to return a usable result unless explicitly stopped by a stop-command.
Furthermore, the double-typed parameter OPTIMIZE_MAX_TIME (see e.g. the FAQ,
Section 2.8.3) can be controlled by the input argument maxtime. If zero, MOSEK will have
no time to identify a useful solution. The function is shown in Figure 15.
As seen, the verbosity is set to zero with the option verbose to specify that the interface
should be completely silent (see the FAQ, Section 2.8.1). Also, any execution errors that
may be thrown by the mosek function is caught. The function then verifies the response
code, and chooses to continue even this is not zero (you may choose to do otherwise). It
then extracts the basic solution and, at the same time, evaluate whether all the variables
that we are going to use are defined. We do not bother to check if the problem status is
ill-posed, as ’lo1’ is a linear program, but instead continue to the solution status which is
only accepted if it is close to optimal (again, you may choose to do otherwise). Finally the
solution variable activities of the solution is returned.
31
2.2 Linear Programming A GUIDED TOUR
switch ( rbas$solsta ,
OPTIMAL = {
cat (" The solution was optimal , I am happy !\ n ")
},
NEAR_OPTIMAL = {
cat (" The solution was close to optimal , very good ..\ n ")
},
# OTHERWISE :
{
cat ( paste ("**" , " Solution status :" , rbas$solsta , "\ n "))
cat ( paste ("**" , " Problem status :" , rbas$prosta , "\ n "))
stop (" Solution could not be accepted !")
}
)
return ( rbas$xx )
}
32
2.3 Conic Quadratic Programming A GUIDED TOUR
minimize cT x + c0
c
subject to l ≤ Ax ≤ uc ,
(2.7)
lx ≤ x ≤ ux ,
x ∈ C.
The convex cone C can be written as the Cartesian product over a finite set of convex cones
C = C1 × · · · × Cp , which basically means that the variables can be partitioned into subsets
of variables belonging to different cones. In principle this also means that each variable can
only belong to one cone, but in practice we can define several duplicates x̂i of xi belonging
to different cones and connected by x̂i = xi in the linear constraints of (2.7).
The MOSEK optimization library currently allows three types of convex cones: The R-
cone, the quadratic cone and the rotated quadratic cone. The R-cone contains the full
set of real numbers and is the default cone in this interface for variables with no other
specification. Notice that if all variables belonged to this cone the problem would reduce
to a linear programming problem. The quadratic cone is defined by
v
uXnt
Ct = x ∈ Rnt : x1 ≥ t x2j
u
(2.8)
j=2
for which the indexes shown here refer only to the subset of variables belonging to the
cone. Similarly the rotated quadratic cone is given by
nt
x ∈ Rnt : 2x1 x2 ≥ x2j , x1 ≥ 0, x2 ≥ 0 .
X
Ct = (2.9)
j=3
These definitions may seem restrictive, but can model a large number of problems as shown
by the transformations of Appendix B.
13
Check out: mosek.com → Documentation → Optimization tools manual → Modeling → Conic
optimization.
33
2.3 Conic Quadratic Programming A GUIDED TOUR
The first cone is of the quadratic cone type (MSK_CT_QUAD), while the second is of the
rotated quadratic cone type (MSK_CT_RQUAD.) The subindexes of the variables used
to define these cones follow naturally as seen in the following R code.
Figure 16: Conic Quadratic Optimization (cqo1)
cqo1 <- list ( sense = " min ")
cqo1$c <- c (0 ,0 ,0 ,1 ,1 ,1)
cqo1$A <- Matrix ( c (1 ,1 ,2 ,0 ,0 ,0) ,
nrow =1 , byrow = TRUE , sparse = TRUE )
cqo1$bc <- rbind ( blc = 1 , buc = 1)
cqo1$bx <- rbind ( blx = c (0 ,0 ,0 , - Inf , - Inf , - Inf ) ,
bux = rep ( Inf ,6))
cqo1$cones <- cbind (
list (" QUAD " , c (4 ,1 ,2)) ,
list (" RQUAD " , c (5 ,6 ,3))
)
rownames ( cqo1$cones ) <- c (" type " ," sub ");
r <- mosek ( cqo1 )
From this example the input arguments for a conic program (2.7) follow easily (refer to
Figure 2, Section 2.1). The objective function, the linear constraints and variable bounds
should all be specified as for linear programs (see Section 2.2), and the only addition to
this is the quadratic cones specified in the list-typed matrix cones.
The cones matrix has a column for each cone, and a row for each descriptive element.
The first row called type, should specify the cone type in a string, being either quadratic
“QUAD” or rotated quadratic “RQUAD”. Notice that the MOSEK library cone type prefix
“MSK_CT_” is optional. The second row called sub, should specify the subset of variables
belonging to the cone in a numeric vector - and the ordering does matter! The i’th element
of sub will be the index of the variable referred by xi , in the cone definitions (2.8) and (2.9).
As an example, the rotated quadratic cone with subindexes c(4,6,2,3) would define the
cone n o
Ct = x ∈ R4 : 2x4 x6 ≥ x22 + x23 , x4 ≥ 0, x6 ≥ 0 . (2.11)
34
2.3 Conic Quadratic Programming A GUIDED TOUR
Figure 16 showed a simple way to specify cones given an explicit representation. In many
practical cases, however, cones are more conveniently specified in chunks or within a loop.
For this purpose, preallocation should always be preferred as shown here.
Figure 17: Preallocating cones (cqo1)
NUMCONES <- 2
cqo1$cones <- matrix ( list () , nrow =2 , ncol = NUMCONES )
rownames ( cqo1$cones ) <- c (" type " ," sub ")
cqo1$cones [ ,1] <- list (" QUAD " , c (4 ,1 ,2))
cqo1$cones [ ,2] <- list (" RQUAD " , c (5 ,6 ,3))
Error messages works fine when you are interacting with the interface, but in automated
optimization frameworks they are not easily handled. This is why a response is always
returned as part of the result, when calling a function that may produce errors (see e.g.
Figure 2). The response is a list containing a code and msg. When an error happens inside
a function call to the MOSEK optimization library, the code is the response code returned
by the function call14 and msg is the corresponding error message. When an error happens
within the interface, the code equals NaN and the msg is the error message which, in case
of unexpected execution paths, may require technical knowledge to understand. When no
errors are encountered, the code is zero, but beware that comparison operators such as
’==’ does not handle NaN very good. Using identical may be a better alternative.
14
Check out: mosek.com → Documentation → C API manual → Response codes.
35
2.3 Conic Quadratic Programming A GUIDED TOUR
The ’cqo1’ Example (Part 2 of 3) The ’cqo’ example was solved using the default
optimizer (the interior-point algorithm) and contains the interior-point solution partly
presented here.
As seen in Figure 18 the solution space of the problem was not empty (as it is primal
feasible) and the problem was not unbounded (as it is dual feasible). In addition the
optimizer was able to identify one of the optimal solutions.
Figure 18: Primal Solution (cqo1)
r$sol$itr
{
$solsta
[1] " OPTIMAL "
$prosta
[1] " P R IM A L _ AN D _ D U AL _ F E AS I B L E "
$skc
[1] " EQ "
$skx
[1] " SB " " SB " " SB " " SB " " SB " " SB "
$skn
[1] " UL " " UL "
$xc
[1] 1
$xx
[1] 0.2609205 0.2609205 0.2390795 0.3689974 0.1690547 0.1690547
...
}
The solution you receive from the interface will contain the primal variable x (called xx)
and the activity of each constraint, xc, defined by xc = Ax. From the solution status
(called solsta) it can be seen how good this solution is, e.g. optimal, nearly optimal,
feasible or infeasible. If the solution status is not as you expected, it might be that the
problem is either ill-posed, infeasible or unbounded (dual infeasible). This can be read
from the problem status (called prosta). The solution and problem status are based on
certificates found by the MOSEK optimization library15 , and should always be verified
before the returned solution values are used (see Section 2.2.5).
15
More details on problem and solution status keys available at:
mosek.com → Documentation → Optimization tools manual → Symbolic constants reference.
36
2.3 Conic Quadratic Programming A GUIDED TOUR
The solution also contains status key vectors for both variables, linear constraints and
conic constraints (called skx, skc and skn). Each status key will be one of the following
two-character strings.
BS : Basic
In basic (bas) solutions: The constraint or variable belongs to the basis of the
corresponding simplex tableau.
SB : Super Basic
In interior-point (itr) and integer (int) solutions: The constraint or variable is in
between its bounds.
LL : Lower Level
The constraint or variable is at its lower bound.
UL : Upper Level
The constraint or variable is at its upper bound.
EQ : Equality
The constraint or variable is at its fixed value (equal lower and upper bound).
UN : Unknown
The status of the constraint or variable could not be determined.
In addition to the primal variables just presented, the returned solutions also contain dual
variables not shown here. The dual variables can be used for sensitivity analysis of the
problem parameters and are related to the dual problem explained in Section 2.3.2.
37
2.3 Conic Quadratic Programming A GUIDED TOUR
2.3.2 Duality
The dual problem corresponding to the primal conic quadratic problem (2.7) defined in
Section 2.3.1, is shown below in (2.12). Notice that the coefficients of the dual problem is
the same as those used in the primal problem. Matrix A for example is still the constraint
matrix of the primal problem, merely transposed in the dual problem formulation.
The dual problem is very similar to that of linear programming (Section 2.2.2), except
for the added variable sxn belonging to the dual cone of C given by C ∗ .
The dual cone C ∗ always has the same number of variables as its primal C, and is in fact
easily expressed for the three convex cone types supported by MOSEK. For the R-cone its
dual is the single point in space with dual variables sxn all zero, such that (2.12) coincides
with the dual linear program (2.4), when all primal variables belong to the R-cone.
Just as easily it holds true that both the quadratic and rotated quadratic cones are self
dual such that C = C ∗ . These facts ease the formulation of dual conic problems and have
been exploited by the MOSEK optimization library for fast computations.
The ’cqo1’ Example (Part 3 of 3) The part of the solutions to the ’cqo1’ example
that was previously omitted, is now shown in Figure 19. The dual variables slc, suc, slx,
sux and snx correspond naturally to scl , scu , sxl , sxu and sxn in the dual problem.
Looking at the definition of the ’cqo1’ problem (2.10), the first and only constraint is an
equality constraint why its dual variables can either be read individually from its implicit
lower an upper bound, slc and suc, or from the combined lower minus upper constraint
dual variable (slc - suc). Notice that since none of the primal variables have upper bounds,
the corresponding dual variables sux are all fixed to zeros. Further more, since all primal
variables belong to a self-dual quadratic cone, all of the snx variables can attain values
from the corresponding quadratic cones.
38
2.3 Conic Quadratic Programming A GUIDED TOUR
39
2.3 Conic Quadratic Programming A GUIDED TOUR
minimize 0.5 xT Q0 x + cT x
(2.13)
subject to 0.5 xT Q1 x + aT x ≤ b.
While quadratic terms are added directly to the objective function and constraint matrix
in quadratic programming, CQP formulations instead retain both a linear objective and a
linear constraint matrix, closely resembling a linear program. All non-linearities, such as
quadratic terms, are in this case formulated by themselves using quadratic cones. Many
types of non-linearities can be modeled using these quadratic cones as seen in Appendix B,
but in the case of (2.13), the result is two of the simplest possible rotated quadratic cones
- one for the xT Q0 x term and one for the xT Q1 x term.
CQP formulations also have the advantage that there are no conditions on when a model is
convex or not, because it always is. The transformation from quadratic programs to conic
quadratic programs is based on a matrix factorization requiring Q0 and Q1 to be positive
semidefinite, which is exactly the convexity requirement for QCQP’s. This means that
xT Q0 x can be transformed only if xT Q0 x is convex. In some sense, this transformation
can be seen as a model-strengthening preprocessing step that only has to be done once.
All further changes to the model can of course be made directly to the CQP.
40
2.4 Semidefinite Programming A GUIDED TOUR
Cone C is defined as in Section 2.3, but could just be the set of reals x ∈ Rn . The problem
has p symmetric positive semidefinite matrix variables X j ∈ Sr+j of dimension rj × rj , and
symmetric coefficients C j ∈ Srj and Amj ∈ Srj . We use the standard notation for the
matrix inner product, i.e., for U, V ∈ Rm×n we have
m X
X n
hU, V i = Uij Vij .
i=1 j=1
41
2.4 Semidefinite Programming A GUIDED TOUR
42
2.4 Semidefinite Programming A GUIDED TOUR
2.4.2 Duality
The dual problem corresponding to the primal semidefinite problem (2.14), is shown below
in (2.16). Notice that the coefficients of the dual problem is the same as those used in the
primal problem. Matrix A for example is still the constraint matrix of the primal problem,
merely transposed in the dual problem formulation.
The dual problem is very similar to that of conic quadratic programming (Section 2.12),
except for the added constraint and the p positive semidefinite variables S j .
43
2.5 Mixed Integer Programming A GUIDED TOUR
• Relax the termination criterion: In case the run time is not acceptable, the first thing
to do is to relax the termination criterion (see Section 2.5.3)
• Specify a good initial solution: In many cases a good feasible solution is either known
or easily computed using problem specific knowledge. If a good feasible solution is
known, it is usually worthwhile to use this as a starting point for the integer optimizer.
A change that the user will notice when starting to enforce integrality is that the notion of a
dual problem is no longer defined for the problem at hand. This means that dual variables
will no longer be part of the solution to the optimization problem, and that only the primal
variables, constraint activities and problem/solution status reports, can be expected from
the output structure returned by the interface.
17
Check out: mosek.com → Documentation → Optimization tools manual → The optimizer for mixed
integer problems.
18
See for instance: L. A. Wolsey, Integer programming, John Wiley and Sons, 1998
44
2.5 Mixed Integer Programming A GUIDED TOUR
The ’milo1’ Example (Part 1 of 2) The way of requiring integer variables is the
same regardless of whether we solve linear or conic quadratic problems. The following is
an example of a simple mixed integer linear optimization problem, with two inequalities
and two non-negative integer variables:
maximize x1 + 0.64x2
subject to 50x1 + 31x2 ≤ 250,
3x1 − 2x2 ≥ −4, (2.17)
x1 , x2 ≥ 0 and integer.
This is easily programmed in R using the piece code shown in Figure 21, where x1 and x2
are pointed out as integer variables.
Figure 21: Mixed Integer Optimization (milo1) Figure 22: Output object (milo1)
milo1 <- list ( sense = " max ") r$sol$int
milo1$c <- c (1 , 0.64) {
milo1$A <- Matrix ( c ( 50 , 31 , $solsta
3 , -2 ) , [1] " INTEGER_OPTIMAL "
nrow = 2 , $prosta
byrow = TRUE , [1] " PRIMAL_FEASIBLE "
sparse = TRUE ) $skc
milo1$bc <- [1] " UL " " SB "
rbind ( blc = c ( - Inf , -4) , $skx
buc = c (250 , Inf )) [1] " SB " " LL "
milo1$bx <- $xc
rbind ( blx = c (0 ,0) , [1] 250 15
bux = c ( Inf , Inf )) $xx
milo1$intsub <- c (1 ,2) [1] 5 0
r <- mosek ( milo1 ) }
The input arguments follow those of a linear or conic program with the additional
identification of the integer variables (refer to Figure 2). The column vector intsub should
simply contain indexes to the subset of variables for which integrality is required. For
instance if x should be a binary {0,1}-variable, its index in the problem formulation should
be added to intsub, and its bounds 0 ≤ x ≤ 1 should be specified explicitly.
If executed correctly you should be able to see the log of the interface and optimization
process printed to the screen. The output structure shown in Figure 22, will only include
45
2.5 Mixed Integer Programming A GUIDED TOUR
an integer solution int, since we are no longer in the continuous domain for which the
interior-point algorithm operates. The structure also contains the problem status as well
as the solution status based on certificates found by the MOSEK optimization library19 .
2.5.2 Hot-starting
Hot-starting (also known as warm-starting) is a way to make the optimization process
aware of a feasible point in the solution space which, depending on the quality of it
(closeness to the optimal solution), can increase the speed of optimization. In mixed
integer programming there are many ways to exploit a feasible solution and for anything
but small sized problems, it can only be recommended to let the optimizer know about a
feasible solution if one is available.
For many users the main advantage of hot-starting a mixed integer program will be the
increased performance, but others may also find appreciation for the fact that the returned
solution can only be better (or in worst-case the same) as the solution fed in. This is
important in many applications where infeasible or low-quality solutions are not acceptable
even when time is short. Heuristics are thus combined with hot-started mixed integer
programs to yield a more reliable tool of optimization.
The ’milo1’ Example (Part 2 of 2) For a small problem like the previously introduced
milo1, that can be solved to optimality without branching, it is not really useful to hot-
start. This example nevertheless illustrates the principle of how it can be done.
19
More details on problem and solution status keys available at:
mosek.com → Documentation → Optimization tools manual → Symbolic constants reference.
46
2.5 Mixed Integer Programming A GUIDED TOUR
is satisfied for all variables in the problem, j ∈ J. Hence, such a solution is defined as
feasible to the mixed integer problem. Whenever the optimizer locates an integer feasible
solution it will check if the criterion
is satisfied. If this is the case, the integer optimizer terminates and reports the integer
feasible solution as an optimal solution. Please note that z is a valid upper bound, and
z a valid lower bound, to the optimal objective value z ∗ . In minimization problems, z
normally increases gradually during the solution process, while z decreases each time a
better integer solution is located starting at the warm-started or heuristically preprocessor
generated solution value.
The δ tolerances are specified using parameters and have default values as shown below.
If an optimal solution can not be located within a reasonable amount of time, it may be
advantageous to employ a relaxed termination criterion after some time. Whenever the
integer optimizer locates an integer feasible solution, and has spent at least the number
of seconds defined by the double-typed parameter MIO_DISABLE_TERM_TIME on
solving the problem, it will check whether the criterion
47
2.5 Mixed Integer Programming A GUIDED TOUR
is satisfied. If it is satisfied, the optimizer will report that the candidate solution is near
optimal and then terminate. Please note that the relaxed termination criterion is not
active by default, as the delay (MIO_DISABLE_TERM_TIME) is -1 by default.
Given the delay (MIO_DISABLE_TERM_TIME) is different from -1, the integer
optimizer also offers two additional parameters to stop the optimizer prematurely once the
specified delay have passed. Beware that these parameters, in the table below, are not able
to guarantee any kind of near optimality, and with a default value of -1 they are ignored
until explicitly defined.
Another option is to terminate whenever the number of distinct integer feasible solution
reaches the value of the parameter MIO_MAX_NUM_SOLUTIONS. Note that this
criteria does not depend on the delay (MIO_DISABLE_TERM_TIME).
Finally, if all other termination criteria fail to be satisfied, the double-typed parameter
OPTIMIZER_MAX_TIME can be used to define the maximum number of seconds to
spend before terminating with the best integer feasible solution (if any). See Section 2.6
on how to specify all these parameters.
48
2.6 Parameter settings in MOSEK A GUIDED TOUR
Revisiting the ’lo1’ example from Section 2.2.1, we can now try to silence the
optimization process as shown below.
Notice that errors and warnings from the interface itself will not be affected by this
parameter. These are controlled separately by the option verbose.
20
Check out: mosek.com → Documentation → C API manual → Parameter reference.
49
2.6 Parameter settings in MOSEK A GUIDED TOUR
Adding parameters to the input arguments of a convex optimization problem is, as seen,
straightforward (refer to Figure 2). The list iparam should specify its variables with a
name, matching that of an integer-typed parameter, and a value, being the corresponding
parameter value. Similarly the list dparam is for double-typed parameters, and sparam
is for string-typed parameters. Notice that reference-strings to an enum (a small set of
named possibilities) is also integer-typed, as the input reference-strings are automatically
converted to indexes by the interface.
Figure 25: Selecting the dual simplex method with parameter ’OPTIMIZER’
lo1 <- list ( sense = " max ")
lo1$c <- c (3 ,1 ,5 ,1)
lo1$A <- Matrix ( c (3 ,1 ,2 ,0 ,
2 ,1 ,3 ,1 ,
0 ,2 ,0 ,3) , nrow =3 , byrow = TRUE , sparse = TRUE )
blc <- c (30 ,15 , - Inf )
buc <- c (30 , Inf ,25); lo1$bc <- rbind ( blc , buc );
blx <- c (30 ,15 , - Inf )
bux <- c (30 , Inf ,25); lo1$bx <- rbind ( blx , bux );
lo1$iparam <- list ( OPTIMIZER = " O PTI MI ZE R_D UA L_ SI MPL EX ");
r <- mosek ( lo1 )
Setting a parameter to NULL will remove it from the list according to the R language
definition. Setting a parameter to NA or NaN, will on the other hand keep it on the list,
only to be ignored by the interface with warnings confirming that this took place. Errors
will be generated when a parameter name is not recognized or when the value defined for
it is not within its feasible range.
50
2.7 Exporting and Importing optimization models A GUIDED TOUR
As seen in Figure 26, some of these modeling formats have more limitations than others.
The ’lp’ format only support linear problems and integer variables. The ’mps’ format is
more general with support of conic constraints and vendor-specific parameter settings. The
’opf’ format further allow solutions to be defined, but only the ’task’ format handles the
full problem description with semidefinite variables.
In all formats supporting parameter settings, either none or the entire list of all
parameters in MOSEK are exported. This will lead to large problem descriptions when
parameters are imported from a file. To save and reload the constructed R-variables exactly
as they are, please use the save and load commands part of the R language definition.
51
2.7 Exporting and Importing optimization models A GUIDED TOUR
Exporting the ’lo1’ Example Revisiting the ’lo1’ example from Section 2.2.1, we can
now try to export the optimization model to the ’opf’ format. In the current example we
export the problem description to a file called ’lo1.opf’ in the current working directory.
Beware that this file is overwritten if it already exists! Afterwards, using the standard
file.show command, the file is displayed in the R-console.
In the example we did not have either parameters or initial solutions defined in the problem
description, but if we had, the options usesol and useparam could be used to indicate
whether to write them to the file or not. By default, usesol is true and useparam is
false. Parameters are thus usually omitted in exported models. Note that since it does
not make sense for an initial solution to specify a solution or problem status, the solutions
exported as part of a problem description will always have unknown statuses. The export
functionality in the mosek function behaves differently in this regard (see Section 2.7.2) .
52
2.7 Exporting and Importing optimization models A GUIDED TOUR
Importing the ’lo1’ Example (Part 1 of 2) We will now try to import the ’lo1’
optimization model that was exported in Figure 27. In the current example we import
from a file called ’lo1.opf’ in the current working directory. Notice that we use the options
usesol and useparam to indicate that we do not wish to read solutions from the file, but
are interested in the parameter settings. Checking that the response code is fine, we print
a message and assign the ’lo1’ variable. Please note the size of the fields iparam, dparam
and sparam of the imported problem description.
Figure 28: Importing a Linear Optimization Problem
r <- mosek_read (" lo1 . opf " , list ( usesol = FALSE , useparam = TRUE ))
The options usesol and useparam behaves as for the mosek_write function, and can be
used to specify whether to read the solutions and parameter settings from the file. By
default, usesol is true and useparam is false. Note that for all parameters not defined in
the file, the default value in the MOSEK optimization library is assigned instead. This
means that the returned problem description will always be quite large when parameters
are imported.
Another option of special interest is the string-typed matrixformat which can specify the
format of the imported sparse constraint matrix called A in Figure 2. The recognized values
for this option are shown below with pkgMatrix:COO (abbreviated COO) being the default.
All string values are case insensitive.
COO / pkgMatrix:COO
The sparse coordinate format (aka triplet format) from package ’Matrix’.
CSC / pkgMatrix:CSC
The compressed sparse column format from package ’Matrix’.
simple:COO
The sparse coordinate format (aka triplet format) based on list-objects.
When setting matrixformat to the string-value simple:COO, the constraint matrix will
be a named list with scalars nrow and ncol telling respective the number of rows and
columns of matrix A, and lists i, j and v telling the ij-coordinates of each value in v. All
these matrix formats are allowed in the problem description given as input to the mosek
and mosek_write functions.
53
2.7 Exporting and Importing optimization models A GUIDED TOUR
Importing the ’lo1’ Example (Part 2 of 2) We will again try to import the ’lo1’
optimization model that was exported in Figure 27, only this time ignoring all parameters
and with the matrixformat option set to simple:COO. This is shown in Figure 29 where
a file called ’lo1.opf’ is imported from the current working directory. The structure of the
imported constraint matrix is shown in Figure 30.
The option ’writebefore’ will export the model exactly as MOSEK have received it,
immediately before it starts the optimization procedure. This can for instance be used
to inspect the problem description in formats that the user may be more familiar with,
to see if what was intended, matched what had been expressed. This option can also be
used as a log-file of the last solved model, such that if the MOSEK optimization library
somehow behaves unexpected, the input model can easily be reported.
The option ’writeafter’ will export the model and identified solutions, immediately after
the optimization procedure has ended. In contrast to the mosek_write function, these
54
2.7 Exporting and Importing optimization models A GUIDED TOUR
solutions are not seen as initial solutions, and do have the correct solution and problems
statuses exported with them. Notice that only the ’opf’ and ’task’ formats support solutions
(Figure 26), and that all other modeling formats would thus result in files similar to those
written by ’writebefore’.
Finally, it may be of interest, that the options usesol and useparam can also be used in this
context. These options were explained in the description of mosek_write and mosek_read
previously in this chapter.
55
2.8 Frequently Asked Questions A GUIDED TOUR
The verbosity of the MOSEK optimization library, can be regulated by a large range of
parameters21 . In many cases the integer-typed ’LOG’-parameter provides sufficient control
over the logging details and can be set as shown in Figure 24, Section 2.6.
21
Check out: mosek.com → Documentation → C API manual → Logging parameters.
22
Check out: mosek.com → Documentation → C API manual → Termination criterion parameters.
56
2.8 Frequently Asked Questions A GUIDED TOUR
2.8.4 How to find the objective value and other information items?
Extra details from a call to the mosek function, can be requested using the options soldetail
and getinfo (see e.g. Figure 2, Section 2.1).
Currently there exists three levels of solution detail: NoExtras=0 (the default),
ObjectiveValues=1 and MaxInfeas=2. Setting soldetail to at least 1, will add the primal
objective value pobjval and the dual objective value dobjval (or a primal objective
bound pobjbound in case of mixed-integer optimization.). Setting soldetail to at least
2, furthermore adds the list of maximal infeasibilities maxinfeas. This list covers the
primal constraints, variables, semidefinite variables and cones (pcon, pvar, pbarvar and
pcone), the dual constraints, variables, semidefinite variables and cones (pcon, pvar,
pbarvar and dcone), as well as the fractionality of primal integer variables int.
Setting getinfo to the boolean value TRUE, will add two lists with information items
extracted from the MOSEK optimization library. One contains all available integer-typed
information iinfo, based on items with a prefix of MSK_IINF_ and MSK_LIINF_ in the
MOSEK C API23 . The other list contains all available double-typed information dinfo,
based on items with a prefix of MSK_DINF_ in the MOSEK C API.
23
Check out: mosek.com → Documentation → C API manual → API constants.
57
ADVANCED TOPICS
3 Advanced topics
3.1 Parallel optimization
3.1.1 The multicore package
The R package called ’multicore’, provides functions for parallel execution of R code on
machines with multiple cores or CPUs. Windows is not currently supported, but the
package should work on most UNIX-alike platforms.
The multicore package works by copying the full memory state of the R session to
new processes. While this seems like a large overhead, in practice, the copy is delayed
until modification assuring a smooth parallel execution. The downside is that this low-
level memory state copy is not safe for all types of resources. As an example, parallel
interactions with the GUI or on-screen devices can cause the R session to crash. It is thus
recommended only to use the multicore package in console R.
In the Rmosek package a license is an externally acquired resource, and attempts to
simply copy the memory state of this resource will provoke a session crash. Thus, licenses
should always be released before the time of parallelization.
A consequence of this is that each new process will be using a separate license. That is,
your license system should allow 8 licenses to be checked out simultaneously, if you wish
to solve 8 optimization problems in parallel. Please note that unlimited academic and
commercial licenses are available at MOSEK.
58
3.1 Parallel optimization ADVANCED TOPICS
This problem is infeasible for λ < 40/9 ≈ 4.44. As shown in Figure 31, the problem is
solved by 4 parallel processes for 10 different values of λ stepping from 3 to 30.
#
# Solve permutations of this problem in parallel
#
require ( foreach ); require ( doMC )
registerDoMC ( cores =4)
mosek_clean ()
r <- foreach ( lambda = seq (3 ,30 , length =10)) % dopar %
{
lo1$bc [ ,1] <- c ( lambda , lambda )
return ( mosek ( lo1 ) )
}
Note that we use a loop construct from the ’foreach’ package, with the package ’doMC’
(depending on package ’multicore’) registered as the parallel back-end. This is easier than
using the multicore package directly. Please see the documentation of the foreach package
for more details on how to use this.
Furthermore, note the mosek_clean() call immediately before the %dopar% operator which
is highly recommended for a smooth parallel execution.
59
3.1 Parallel optimization ADVANCED TOPICS
mosek_clean ()
r <- foreach ( lambda = seq (3 ,30 , length =10)) % dopar % capture . output . helper (
file = paste (" RESULTS_FILE_ " , lambda , sep ="") ,
code = function ()
{
lo1$bc [ ,1] <- c ( lambda , lambda )
return ( mosek ( lo1 ) )
}
)
The defined capture.output.helper solves two problems. It makes sure that the
return value is correctly propagated to the foreach-loop, as opposed to the standard
capture.output function ignoring return values. It also calls mosek_clean(), to capture
any cleaning messages from Rmosek, which would otherwise appear on screen when the
parallel process is terminated outside the control of capture.output.
60
3.2 Quadratic Convex Optimization ADVANCED TOPICS
minimize 0.5xT Qx + cT x + c0
subject to lc ≤ Ax ≤ uc , (3.3)
x
l ≤ x ≤ ux .
• The MOSEK optimization library does not support the combination of quadratic
convex optimization with conic constraints.
If the problem at hand involves quadratic objective terms, quadratic convex optimization
may very well be the best way to solve it. Nevertheless, it is easy to try the conic quadratic
formulation of these problems, for which the optimizer will sometimes perform even better
(see Section 2.3.3).
The ’qo1’ Example The following is an example of a linear constrained problem with
a convex quadratic objective.
subject to x1 + x2 + x3 ≥ 1, (3.4)
x1 , x2 , x3 ≥ 0 .
The quadratic objective terms are easily appended on top of the linear formulation as
shown in the following R code (Figure 33).
61
3.2 Quadratic Convex Optimization ADVANCED TOPICS
The objective term −2x3 x1 has been specified with half the coefficient, i.e. −1, in the field
qobj. Note that this is in contrary to squared variables, e.g. 2x21 , as explained in the text.
From this example the input arguments for a quadratic convex program (3.3) follow easily
(refer to Figure 2, Section 2.1). The linear part of the objective function and constraints,
as well as the constraint and variable bounds, should all be specified as for linear programs
(see Section 2.2). The only addition to this is the list called qobj containing the triplets
of row indexes i, column indexes j and values v that define Q. The number of rows and
columns of matrix Q should not be specified, as these dimensions are already known from
the number of variables in the linear part of the problem.
The inputted Q is always assumed symmetric, and note that this is without loss of
generality. This is efficient as only the lower triangular part of Q thus needs to be specified.
Setting a coefficient at the lower triangular position (i,j) will, by symmetry, imply that the
same coefficient is also present at position (j,i). In order to add the objective term −2x3 x1 ,
one would see it as −x3 x1 − x1 x3 and only input a coefficient of −1 to row 3 of column 1.
62
3.3 Separable Convex Optimization ADVANCED TOPICS
minimize z(x) + cT x + c0
c
subject to l ≤ w(x) + Ax ≤ uc , (3.5)
lx ≤ x ≤ ux ,
where n
X
z(x) = zj (xj ) , zj : R → R.
j=1
.. (3.6)
n
w .(x) X
w(x) = i , wi (x) = wij (xj ) , wij : R → R.
.. j=1
.
• Since the operators zj (xj ) and wij (xj ) are arbitrarily defined, the optimizer for
separable convex optimization has less knowledge, and can be expected to perform
worse, than the optimizer for conic quadratic programs.
• The MOSEK optimization library does not support the combination of separable
convex optimization with integer variables or conic constraints.
63
3.3 Separable Convex Optimization ADVANCED TOPICS
For the sake of performance, and the usability of the ’sco’ file-format, callback functionality
to custom R evaluation code have not been supported. Instead, a list of common operators
with customizable coefficients have been added to this interface, making it both fast and
easy to use. The reader is encouraged to contact us, in case this list of operators is found
to be insufficient.
With constants f ∈ R, g ∈ R and h ∈ R, the interface currently allows:
minimize x1 − ln(x3 )
subject to x21 + x22 ≤ 1,
(3.7)
x1 + 2x2 − x3 = 0 ,
x3 ≥ 0 .
The objective contains one logarithm operator, and the first constraint contains two power
operators. These operators are easily appended on top of the linear formulation as shown
in the following R code (Figure 34).
64
3.3 Separable Convex Optimization ADVANCED TOPICS
From this example the input arguments for a separable convex program (3.5) follow easily
(refer to Figure 2, Section 2.1). The linear part of the objective function and constraints,
as well as the constraint and variable bounds, should all be specified as for linear programs
(see Section 2.2). The only addition to this is the list called scopt containing the list-typed
operator matrices opro (for objective) and oprc (for constraints).
The operator matrices have a column for each operator and a row for each descriptive
element. The opro matrix have five rows called {type, j, f, g, h}, while the oprc matrix have
six rows called {type, i, j, f, g, h}. Row type should specify the operator type in a string,
being either entropy "ENT", exponential "EXP", logarithm "LOG" or power "POW". Row
i (not in opro) should specify the index of the constraint to which the non-linear term
should be added. Row j should specify the variable index of the operator. Rows f , g and
h should specify the coefficients of the operator (see Figure 27).
Examples are:
Terms in opro type j f g h
In objective: exp(1.4x1 + 1.1) "EXP" 1 1.0 1.4 1.1
In objective: ln(1.5x2 + 1.2) "LOG" 2 1.0 1.5 1.2
√
In objective: 2.1 x3 "POW" 3 2.1 0.5 0.0
65
3.3 Separable Convex Optimization ADVANCED TOPICS
Note that the definition of the entropy operator (see Figure 27), was the only operator
defined without g and h. Thus, for entropy operators, these two unused rows in the operator
matrix can be set to either zero or any empty definition (NULL, NA or NaN).
Disciplined convexity means that the expression gi (x) of a constraint lic ≤ gi (x) ≤ uci , is
required to be concave if the lower bound is finite (i.e. not -Inf), and required to be convex
if the upper bound is finite (i.e. not Inf). This also implies that the expression should be
linear if both the lower and upper bound is defined with finite values.
In case of separable convex optimization, this means that each unary operator of an
expression - required to be convex (resp. concave) - is used only in its convex (resp.
concave) domain. A problem which is disciplined convex is guaranteed to be convex.
66
3.3 Separable Convex Optimization ADVANCED TOPICS
Exporting the ’sco1’ Example Revisiting the ’sco1’ example from Section 3.3.1, we
can now try to export the optimization model to the ’opf’ format with operators in an ’sco’
file. In particular, the current example will export the problem description to respectively
’sco1.opf’ and ’sco1.sco’ in the current working directory. Beware that these files are
overwritten if they already exists! Afterwards, using the standard file.show command,
the files are displayed in the R-console.
r <- mosek_write ( sco1 , " sco1 . opf " , list ( scofile =" sco1 . sco "))
file . show (" sco1 . opf " , " sco1 . sco ")
The same option, ’scofile’, can be used when calling mosek_read (see Section 2.7). This
function will read in a problem description of a separable convex optimization problem from
the location of two files. These two files can also be read independently of each other.
67
DEVELOPERS CORNER
4 Developers corner
4.1 Introduction
In the project’s src folder you can find the header and source files (*.h and *.cc) containing
the C++ code of the R-to-MOSEK interface. Moreover, the Rmosek.cc file contains the
functions that are callable from R.
This code has been written and commented so that it should be easy to understand
how the interface handles the input and output structures, prints to the screen and
communicates with the MOSEK optimization library. Four important references proved
to be useful in the development of this interface.
• R Language Definition25
• Writing R Extensions 25
The program is free software and has been released under the terms of the GNU Lesser
General Public License as published by the Free Software Foundation, either version 2.1 of
the License, or any later version. You are welcome to extend upon this release and modify
the interface to your personal needs. The source code is distributed as part of the Rmosek
package.
Notes on the Matrix package: A number of bugfixes were introduced in the Matrix
package posterior to dependencies on R(>=2.12.0). These fixes have been backported in
this package, to older versions of the package Matrix(>=0.9996875-3) depending only on
R(>=2.10.0). Effectively, more users will be able to run Rmosek. The source code for this
backport is located in the compatibility folder from which it is included in the local_stubs.h
and local_stubs.cc files.
24
Check out: mosek.com → Documentation → C API manual → API reference.
25
Check out: r-project.org → Manuals
68
4.2 Limitations and Missing Features DEVELOPERS CORNER
1. Direct input of Quadratic Constrained Programs: At the moment the user will
need to manually transform the Quadratic Constrained Problem to a Conic Program
as the interface only provides for the direct input of linear and conic programs.
The MOSEK optimization library actually supports the direct input of Quadratic
Constrained programs, so this should only require a small amount of coding.
26
Check out: mosek.com → Optimization toolbox for MATLAB.
69
COMMAND REFERENCE
A Command reference
◮ r <- mosek_version()
Retrieves a string containing the version number of the utilized MOSEK optimization
library. Briefly mentioned in Section 2.1.
The argument sense is the goal of the optimization and should indicate whether we wish
to maximize or minimize the objective function given by f (x) = cT x + c0 , where c is the
objective coefficients and c0 the objective constant. The matrix A together with bounds
bc describes the linear constraints of the problem, while variable bounds are given by bx.
These input arguments describe a linear program (see Section 2.2).
The argument cones is used for Conic Programming and has been described in Section
2.3. The issue regarding the transformation of other convex problems to the formulation of a
Conic Program has been addressed in Appendix B, with more details on the transformation
of Quadratic Programs in Section 2.3.3.
70
COMMAND REFERENCE
The arguments bardim, barc and barA are used for Semidefinite Programming and
have been described in Section 2.4.
The argument intsub is used to specify whether some of the variables should only be
allowed to take integer values as part of a feasible solution. This is necessary for the class
of Mixed Integer Programs described in Section 2.5.
The argument qobj is used for quadratic convex optimization and allows quadratic
terms in the objective function. This argument has been described in Section 3.2.
The argument scopt is used for separable convex optimization and allows non-linear
unary operators in formulations involving exponential or logarithmic terms. This argument
has been described in Section 3.3.
The arguments iparam, dparam and sparam are used to specify lists of integer-,
double- and string-typed parameters for the MOSEK optimization library in order to aid
or take control of the optimization process. This has been described in Section 2.6.
The argument sol is used to specify an initial solution used to hot-start the optimization
process, which is likely to increase the solution speed. This has been described for linear
programming in Section 2.2.4 and for mixed integer programming in Section 2.5.2.
The options opts could have any name, and are, in fact, often input directly as an
anonymous list. It has the following fields.
The argument verbose is used to specify the amount of logging information given by
the interface. This is described in Section 2.8.1.
The argument usesol can be used to ignore the problem field sol, while useparam
can be used to ignore the fields iparam, dparam and sparam, without having to change the
problem description. This usage has not been covered by the user guide, but it should be
noted that both options are true by default in contrary to the context of Section 2.7.
The arguments soldetail and getinfo are used to control the amount of information
returned about the solution, and the MOSEK optimization library internals, respectively.
This is described in Section 2.8.4.
71
COMMAND REFERENCE
The arguments writebefore and writeafter are used to see the optimization model
(and identified solution) constructed by MOSEK, written out to a file just before (or
immediately after) the optimization process. This is described in Section 2.7.
The resulting function output variable r, returned by the interface, is capable of holding
the three types of solutions listed below, along with the response of the function call. The
existence of a solution depends on the optimization problem and the algorithm used to
solve it.
r Result of the ’mosek’ function
..$response Response from the MOSEK optimization library
....$code ID-code of response
....$msg Human-readable message
..$sol Solution list
....$itr/$bas/$int Solution description
......$solsta Solution status
......$prosta Problem status
......$skc Linear constraint status keys
......$skx Variable bound status keys
......$skn Conic constraint status keys
......$xc Constraint activities
......$xx Variable activities
......$barx Semidefinite variable activities
......$slc Dual variable for constraint lower bounds
......$suc Dual variable for constraint upper bounds
......$slx Dual variable for variable lower bounds
......$sux Dual variable for variable lower bounds
......$snx Dual variable of conic constraints
......$bars Dual variable of semidefinite domains
......$pobjval Primal objective value27
......$dobjval Dual objective value27
......$pobjbound Best primal objective bound from relaxations27
......$maxinfeas Maximal solution infeasibilities27
........$pbound In primal inequality constraints
........$peq In primal equality constraints
........$pcone In primal cone constraints
........$dbound In dual inequality constraints
........$deq In dual equality constraints
........$dcone In dual cone constraints
27
Only available if requested by option soldetail.
72
COMMAND REFERENCE
The response can be used to determine whether a function call returned successfully.
It contains a numeric response code, code, and a string response message, msg, both
explained in “Errors, warnings and response codes” in Section 2.2.1. Please also see Section
2.2.5 on how to use this information.
The solution itr will exist whenever the interior-point algorithm has been executed.
This algorithm is used by default for all continuous optimization problems, and has been
described in Section 2.2, 2.3 and 2.4.
The solution bas will exist whenever the interior-point algorithm or the simplex method
has been executed to solve a linear optimization problem (see Section 2.2).
The solution int will exist whenever variables are required to take integer values and
the corresponding Mixed Integer Program has been solved (see Section 2.5).
The iinfo and dinfo lists hold information on the MOSEK optimization library
internals, and have been described in Section 2.8.4.
◮ mosek_clean()
Forces the early release of any previously acquired MOSEK license. If you do not share
a limited number of licenses among multiple users, you do not need to use this function.
The acquisition of a new MOSEK license will automatically take place at the next call to
the function mosek given a valid problem description, using a small amount of extra time.
This usage is briefly mentioned in Section 2.1.
For advanced users: If you utilize the .Call convention directly, bypassing the mosek R-
function definition, an Rf_error will result in an unclean memory space. For this reason
you can also use mosek_clean to tidy up uncleaned resources in case an error occurs.
Otherwise this cleaning will not happen until the next call to mosek or until the library is
unloaded. This usage have not been documented elsewhere.
73
COMMAND REFERENCE
The input variable problem could have any name, but should be a list object describing
the optimization problem using the same fields as for the mosek function on page 70.
The input variable filepath should be a string describing the path to modelfile. This
path can either be absolute or relative to the working directory, and will overwrite any
existing data on this location. The specified location will be the destination of the exported
model.
The options opts could have any name, and are, in fact, often specified directly as an
anonymous list. It has the following fields.
The argument verbose is used to specify the amount of logging information given by
the interface. This is described in Section 2.6.
The argument usesol can be used to ignore the problem field sol, while useparam
can be used to ignore the fields iparam, dparam and sparam, when writing the optimization
model. By default, the argument usesol is true and useparam is false, in contrary to the
defaults of the mosek function. These two options are covered in Section 2.7.
The argument getinfo is used to indicate whether to extract information about the
MOSEK optimization library internals. This is described in Section 2.8.4.
The argument scofile is used in separable convex optimization to specify the file to
which the operators must be saved. This is described in Section 3.3.3.
The resulting function output variable r, returned by the interface, holds the response of
the function call.
r Result of the ’mosek_write’ function
..$response Response from the MOSEK optimization library
....$code ID-code of response
....$msg Human-readable message
..$iinfo/$dinfo MOSEK information list29
....$<MSK_INFO> Value of any <MSK_INFO>
29
Only available if requested by option getinfo.
74
COMMAND REFERENCE
The response can be used to determined whether a function call returned successfully.
It contains a numeric response code, code, and a string response message, msg, both
explained in “Errors, warnings and response codes” in Section 2.2.1. Please also see Section
2.7 for an example on how to use this information.
The iinfo and dinfo lists hold information on the MOSEK optimization library
internals, and have been described in Section 2.8.4.
The options opts could have any name, and are, in fact, often input directly as an
anonymous list. It has the following fields.
The argument verbose is used to specify the amount of logging information given by
the interface. This is described in Section 2.6.
The argument usesol can be used to ignore the problem field sol, while useparam
can be used to ignore the fields iparam, dparam and sparam, when reading the optimization
model. By default, the argument usesol is true and useparam is false, in contrary to the
defaults of the mosek function. These two options are covered in Section 2.7.
The argument getinfo is used to indicate whether to extract information about the
MOSEK optimization library internals. This is described in Section 2.8.4.
75
COMMAND REFERENCE
The argument scofile is used in separable convex optimization to specify the file from
which the operators should be read. This is described in Section 3.3.3.
The argument matrixformat determines the matrix format of the problem field A.
Currently a sparse coordinate (COO) and a compressed sparse column (CSC) format is
supported from package ’Matrix’, along with a simple list-based coordinate format. This
is described in Section 2.7.
The resulting function output variable r, returned by the interface, holds the response of
the function call.
r Result of the ’mosek_read’ function
..$response Response from the MOSEK optimization library
....$code ID-code of response
....$msg Human-readable message
..$prob Problem description
..$iinfo/$dinfo MOSEK information list30
....$<MSK_INFO> Value of any <MSK_INFO>
The response can be used to determined whether a function call returned successfully.
It contains a numeric response code, code, and a string response message, msg, both
explained in “Errors, warnings and response codes” in Section 2.2.1. Please see Section 2.7
for an example on how to use this information.
The output variable prob is a list object describing the imported optimization problem.
It has the same fields as the input variable ’problem’ for the mosek function on page 70.
The iinfo and dinfo lists hold information on the MOSEK optimization library
internals, and have been described in Section 2.8.4.
30
Only available if requested by option getinfo.
76
CONIC TRANSFORMATIONS
B Conic transformations
This appendix will introduce the reader to some of the transformations that make it
possible to formulate a large class of non-linear problems as Conic Quadratic Programs31 .
Transformations do not have to be hard, and some non-linear constraints easily take the
shape of a quadratic cone (see Section 2.3.1 for definitions). Linear constraints can be
added to a Conic Quadratic Program directly without transformations.
√ √
The x Example Given constraint x ≥ t with x, t ≥ 0, we rewrite it to a rotated
quadratic cone as follows: √
x ≥ t
x ≥ t2 (B.1)
2xr ≥ t2
The definition of linear relationships hardly have any effect on speed of the optimization
process, and many techniques are implemented in MOSEK to effectively reduce the size
of the problem. Thus many CQP formulations solve faster than what could be expected
from the larger model that results from almost any transformation.
31
More examples and transformation rules can be found online:
Check out: mosek.com → Documentation → Optimization tools manual → Modeling → Conic
optimization.
77
CONIC TRANSFORMATIONS
Monomials in General The crucial step in transforming the individual terms (mono-
mials) of a polynomial function to the form of a conic program, is the following recursion
holding true for positive integers n and non-negative yj variables. Here, each line implies
the next, and the inequality ends up having the same form as to begin with, only with
n reduced by one. Repeating this procedure until n = 1, the inequality will finally take
the form of a rotated quadratic cone. From the first expression, we move the coefficients
around to get line two, substitute variables by the cones in (B.5) to get line three, and take
the square root on both sides to reach line four.
n n−1
s2 ≤ 2n2 [y1 yh2 · · · y2n ] i
n n−1
s2 ≤ 2 (n−1)2 (2y1 y2 ) (2y3 y4 ) · · · (2y(2n −1) y2n )
n n−1 (B.4)
s2 ≤ 2(n−1)2 x21 x22 · · · x22n−1
(n−1) n−2
s2 ≤ 2(n−1)2 [x1 x2 · · · x2n−1 ]
Also note that the definition of new variables created by this recursion all takes the form
of a rotated quadratic cone as shown below, with all yj ≥ 0.
x2j ≤ 2 y(2j−1) y2j ∀j (B.5)
Type I Having the inequality xp/q ≤ t for some rational exponent p/q ≥ 1, we are now
able to transform it into a set of cones by substituting p = 2n − w for positive integers n
and w. This will yield a form close to the top of (B.4) as shown below, where the variables
x and t just needs to be coupled with s and y for the recursion to be usable. An example
of this follows in (B.9).
xp/q ≤ t
(2 n −w)/q
x ≤ t (B.6)
n
x2 ≤ xw tq
Type II The inequality xp/q ≥ t for some rational exponent 0 ≤ p/q ≤ 1 and x ≥ 0, can
be transformed into the form of a type I monomial quite easily.
xp/q ≥ t
q/p (B.7)
x ≥ t
Type III Having instead the inequality x−p/q ≤ t for any integers p ≥ 1, q ≥ 1, we can
use the transform shown below. This again will yield a form close to the top of (B.4),
where s is a constant and the variables just need to be coupled with y. You need to choose
n such that 2n ≥ p + q in order to make this transformation work. See example (B.10).
x−p/q ≤ t
(B.8)
1 ≤ xp tq
78
CONIC TRANSFORMATIONS
x5/3 ≤ t
x5 ≤ t3
x8 ≤ x3 t3 (B.9)
s8 12
≤ 2 y 1 y2 · · · y 8
s = x, y1 = y2 = y3 = x, y4 = y5 = y6 = t, y7 = 2−12 , y8 = 1
x−5/2 ≤ t
x−5 ≤ t2
1 ≤ x5 t2 (B.10)
s8 12
≤ 2 y1 y 2 · · · y8
s = (212 )1/8 , y1 = y2 = . . . = y5 = x, y6 = y7 = t, y8 = 1
Polynomials Now that we have seen how to transform the individual terms (monomials)
of a polynomial function to the form of a conic program, it is easy to transform entire
polynomial constraints. We assume aj ≥ 0 for monomials of type I and III, and aj ≤ 0 for
monomials of type II.
Pn pj /qj
j=1 aj xj ≤ b (B.11)
Substituting each monomial by a new variable uj , we are able to isolate each monomial by
itself and use the previously defined transformation rules.
Pn
j=1 aj uj ≤ b
p /q
xj j j ≤ uj ∀j of type I and III (B.12)
p /q
xj j j ≥ uj ∀j of type II
Regarding the objective function, minimization problems can be rewritten as shown below
matching (B.11) and, therefore, it is applicable to the isolation of monomials and the whole
transformation used above. In this way the objective function can also take the linear form
required by conic programs.
minimize b
minimize f (x) ⇐⇒ (B.13)
f (x) ≤ b
79
CONIC TRANSFORMATIONS
minimize cT x
Pn fj
subject to j=1 xj ≤ b (B.14)
x≥0
minimize cT x
Pn
subject to j=1 fj zj = b√
vj = 2 j = 1, . . . , n (B.15)
vj2 ≤ 2zj xj j = 1, . . . , n
x, z ≥ 0
Polynomials - Example 2 The objective function with a mixture of type I and type
III monomials
minimize x2 + x−2 (B.16)
minimize u + v
subject to x2 ≤ u (B.17)
x−2 ≤ v
minimize u + v
subject to x2 ≤ 2uw
s2 ≤ 2y21 y22
2
y21 ≤ 2y1 y2
2
y22 ≤ 2y3 y4
(B.18)
w = 1
s = 23/4
y1 = y2 = x
y3 = v
y4 = 1
80
B.1 The Quadratic Program CONIC TRANSFORMATIONS
where F and G are matrices and c and a are column vectors. Here a convex quadratic
term xT Qx would be written kF xk2 , where F T F = Q is the Cholesky factorization. For
simplicity’s sake we assume that there is only one constraint, but it should be obvious how
to generalize the methods to an arbitrary number of constraints. Problem (B.19) can be
reformulated as
minimize 0.5ktk2 + cT x
subject to 0.5kzk2 + aT x ≤ b
(B.20)
Fx − t = 0
Gx − z = 0
after the introduction of the new variables t and z. It is easy to convert this problem to a
conic quadratic optimization problem, i.e.
minimize v + cT x
subject to p + aT x = b
Fx − t = 0
Gx − z = 0
(B.21)
w = 1
q = 1
ktk2 ≤ 2vw v, w ≥ 0
kzk2 ≤ 2pq p, q ≥ 0
In this case the last two inequalities both take the form of a rotated quadratic cone, and
the entire problem can be solved as a conic quadratic program, Section 2.3, using the
interior-point algorithm.
81