Using MOSEK from the R language

 
R is a programming language and open source software environment for statistical computing and graphics. It has excellent support for retrieving data from offline and online data sources, and the R-to-MOSEK Optimization Interface allows you to channel this information directly into optimization problems. Even better, the computed solutions can be verified, visualized or further analyzed by the wide range of R tools.

Packaging network

The R-to-MOSEK Optimization Interface is distributed as a package called Rmosek on the CRAN repository. In this way, the latest release and bugfixes are never more than a single command away from your R software environment.

The optimization interface

The Rmosek package is minimalistic in the sense that you formulate your optimization problems using standard R functionality and primitive variables. The problem structure can thus be built, loaded and saved in the fastest or easiest way, relative to the R programming language, and then pushed to the optimization engine with little overhead.
The optimization interface allows the user to solve:

Example cqo1 for R

The following is a conic optimization problem with six variables, one linear constraint, and two second-order cones:
 \begin{array}{lccccc} \displaystyle{} \mbox{minimize}&\displaystyle{} x_{4} + x_{5} + x_{6} &\displaystyle{} &\displaystyle{} &\displaystyle{} &\displaystyle{} \\[0pt] \displaystyle{} \mbox{subject to}&\displaystyle{} x_{1}+x_{2}+ 2 x_{3} &\displaystyle{} = &\displaystyle{} 1, &\displaystyle{} &\displaystyle{} \\[0pt] \displaystyle{} &\displaystyle{} x_{1},x_{2},x_{3} &\displaystyle{} \geq{}&\displaystyle{} 0, &\displaystyle{} &\displaystyle{} \\[0pt] \displaystyle{} &\displaystyle{} x_{4} \geq{}\sqrt{x_{1}^{2} + x_{2}^{2}}, &\displaystyle{} &\displaystyle{} &\displaystyle{} &\displaystyle{} \\[0pt] \displaystyle{} &\displaystyle{} 2 x_{5} x_{6} \geq{} x_{3}. &\displaystyle{} &\displaystyle{} &\displaystyle{} &\displaystyle{} \\[0pt] \end{array}
To construct this, we fill a list with data from the linear part of the problem.
  1. cqo1 <- list(sense = "min") 
  2. cqo1$c <- c(0,0,0,1,1,1) 
  3. cqo1$A <- Matrix(c(1,1,2,0,0,0),  
  4. nrow=1, sparse=TRUE) 
  5. cqo1$bc <- rbind(blc = c(1),  
  6. buc = c(1)) 
  7. cqo1$bx <- rbind(blx = c(0,0,0,-Inf,-Inf,-Inf), 
  8. bux = rep(Inf,6)) 
Separately, the quadratic and rotated quadratic cone is specified.
  1. cqo1$cones <- cbind(list("QUAD", c(4,1,2)), 
  2. list("RQUAD", c(5,6,3))) 
So far we have not used the Rmosek package. It does, however, come to play when we solve the problem.
  1. r <- mosek(cqo1) 
The given result contains the computed solution along with human and computer readable status codes to interpret it.

Online documentation