
The R-to-MOSEK Optimization Interface Henrik Alsing Friberg MOSEK ApS, Fruebjergvej 3, Box 16, DK 2100 Copenhagen, Blog: http://themosekblog.blogspot.com ISMP, Berlin 2012 http://www.mosek.com Introduction 2 / 48 What is R? Introduction The R Project What is R? What is MOSEK? What is Rmosek? A fast open-source programming language for Installation technical computing and graphics. Simple models Advanced models Better formulations Highlights: Data handling and visualization ■ One million users – Intel Capital, 2009 High performance Summary ■ The Comprehensive R Archive Network (3895 packages and counting) ■ Direct interfaces to C and Fortran (as well as C++, Perl, Java, Python, Matlab, Excel etc.) ■ Revolution Analytics ■ RStudio 3 / 48 What is MOSEK? Introduction MOSEK What is R? What is MOSEK? What is Rmosek? A high performance software library designed to Installation solve large-scale convex optimization problems. Simple models Advanced models Better formulations Highlights: Data handling and visualization ■ Linear constraints (LP) High performance Summary ■ Second-order cone constraints (SOCP) ■ Semidefinite constraints (SDP) ■ Mixed-integer variables (MIP) ■ Quadratic terms (QP and QCQP) ■ Separable convex operators – log(xi), exp(xi), ... 4 / 48 What is Rmosek? Introduction Rmosek What is R? What is MOSEK? What is Rmosek? A simple interface from R to the optimizers of Installation MOSEK. Simple models Advanced models Better formulations Why? Data handling and visualization ■ Some financial customers find R better than MATLAB. High performance Summary ■ Replace unofficial implementations. 5 / 48 What is Rmosek? Introduction Rmosek What is R? What is MOSEK? What is Rmosek? A simple interface from R to the optimizers of Installation MOSEK. Simple models Advanced models Better formulations Why? Data handling and visualization ■ Some financial customers find R better than MATLAB. High performance Summary ■ Replace unofficial implementations. Goals: ■ Open-source ■ Highly effective ■ Integrate with what R users normally do 5 / 48 Installation Introduction A oneliner for Windows, MacOS and Linux: What is R? What is MOSEK? install.packages("Rmosek", type="source") What is Rmosek? Installation Simple models Advanced models Better formulations Data handling and visualization High performance Summary 6 / 48 Installation Introduction A oneliner for Windows, MacOS and Linux: What is R? What is MOSEK? install.packages("Rmosek", type="source") What is Rmosek? Installation Simple models Package overview: Advanced models library(help="Rmosek") Better formulations Data handling and visualization Major functions: High performance ■ mosek(prob) Summary ■ mosek write(prob, file) ■ mosek read(file) The problem is an R-variable.. Create as you like! 6 / 48 Simple models 7 / 48 Linear optimization Introduction Simple models 3x1 + 1x2 + 5x3 + 1x4 Linear optimization maximize 1 2 3 Advanced models subject to 3x + 1x + 2x = 30, Better formulations 2x1 + 1x2 + 3x3 + 1x4 ≥ 15, Data handling and 2x2 + 3x4 ≤ 25, visualization High performance 0 ≤ x1 ≤ ∞, Summary 0 ≤ x2 ≤ 10, 0 ≤ x3 ≤ ∞, 0 ≤ x4 ≤ ∞. 8 / 48 Linear optimization Introduction lo1 <- list() Simple models Linear optimization Advanced models ## Objective Better formulations lo1$sense <- "max" Data handling and visualization lo1$c <- c(3, 1, 5, 1) High performance Summary ## Constraint matrix lo1$A <- spMatrix(nrow = 3, ncol = 4, i = c(1, 2, 1, 2, 3, 1, 2, 2, 3), j = c(1, 1, 2, 2, 2, 3, 3, 4, 4), x = c(3, 2, 1, 1, 2, 2, 3, 1, 3) ) 9 / 48 Linear optimization Introduction ## Constraint bounds Simple models Linear optimization lo1$bc <- cbind(c(30, 30), Advanced models c(15, Inf), Better formulations c(-Inf, 25)) Data handling and visualization High performance ## Variable bounds Summary lo1$bx <- cbind(c(0, Inf), c(0, 10), c(0, Inf), c(0, Inf)) 10 / 48 Advanced models 11 / 48 Second-order cone and semidefinite optimization 2 1 0 Introduction x1 x1 Simple models minimize 1 2 1 • + Advanced models 0 1 2 Second-order cone 1 0 0 and semidefinite optimization subject to 0 1 0 • x1 + x1 = 1.0 , Better formulations 0 0 1 Data handling and visualization 1 1 1 High performance 1 1 1 • x1 + x2 + x3 = 0.5 , Summary 1 1 1 3 2 2 (x1,x2,x3) ∈ R , x1 ≥ x + x , x1 0 . p 2 3 12 / 48 Second-order cone and semidefinite optimization 2 1 0 Introduction x1 x1 Simple models minimize 1 2 1 • + Advanced models 0 1 2 Second-order cone 1 0 0 and semidefinite optimization subject to 0 1 0 • x1 + x1 = 1.0 , Better formulations 0 0 1 Data handling and visualization 1 1 1 High performance 1 1 1 • x1 + x2 + x3 = 0.5 , Summary 1 1 1 3 2 2 (x1,x2,x3) ∈ R , x1 ≥ x + x , x1 0 . p 2 3 sdo1 <- list() sdo1$sense <- "minimize" sdo1$c <- c(1,0,0) 13 / 48 Second-order cone and semidefinite optimization 2 1 0 Introduction x1 x1 Simple models minimize 1 2 1 • + Advanced models 0 1 2 Second-order cone 1 0 0 and semidefinite optimization subject to 0 1 0 • x1 + x1 = 1.0 , Better formulations 0 0 1 Data handling and visualization 1 1 1 High performance 1 1 1 • x1 + x2 + x3 = 0.5 , Summary 1 1 1 3 2 2 (x1,x2,x3) ∈ R , x1 ≥ x + x , x1 0 . p 2 3 sdo1$A <- spMatrix(nrow=2, ncol=3, i = c(1,2,2), j = c(1,2,3), x = c(1,1,1) ) 14 / 48 Second-order cone and semidefinite optimization 2 1 0 Introduction x1 x1 Simple models minimize 1 2 1 • + Advanced models 0 1 2 Second-order cone 1 0 0 and semidefinite optimization subject to 0 1 0 • x1 + x1 = 1.0 , Better formulations 0 0 1 Data handling and visualization 1 1 1 High performance 1 1 1 • x1 + x2 + x3 = 0.5 , Summary 1 1 1 3 2 2 (x1,x2,x3) ∈ R , x1 ≥ x + x , x1 0 . p 2 3 sdo1$bc <- cbind(c(1.0, 1.0), c(0.5, 0.5)) 15 / 48 Second-order cone and semidefinite optimization 2 1 0 Introduction x1 x1 Simple models minimize 1 2 1 • + Advanced models 0 1 2 Second-order cone 1 0 0 and semidefinite optimization subject to 0 1 0 • x1 + x1 = 1.0 , Better formulations 0 0 1 Data handling and visualization 1 1 1 High performance 1 1 1 • x1 + x2 + x3 = 0.5 , Summary 1 1 1 3 2 2 (x1, x2, x3) ∈ R , x1 ≥ x + x , x1 0 . p 2 3 sdo1$bx <- cbind(c(-Inf, Inf), c(-Inf, Inf), c(-Inf, Inf)) 16 / 48 Second-order cone and semidefinite optimization 2 1 0 Introduction x1 x1 Simple models minimize 1 2 1 • + Advanced models 0 1 2 Second-order cone 1 0 0 and semidefinite optimization subject to 0 1 0 • x1 + x1 = 1.0 , Better formulations 0 0 1 Data handling and visualization 1 1 1 High performance 1 1 1 • x1 + x2 + x3 = 0.5 , Summary 1 1 1 3 2 2 (x1,x2,x3) ∈ R , x1 ≥ x + x , x1 0 . p 2 3 sdo1$cones <- cbind( list("quad", c(1,2,3)) ) 17 / 48 Second-order cone and semidefinite optimization 2 1 0 Introduction x1 x1 Simple models minimize 1 2 1 • + Advanced models 0 1 2 Second-order cone 1 0 0 and semidefinite optimization subject to 0 1 0 • x1 + x1 = 1.0 , Better formulations 0 0 1 Data handling and visualization 1 1 1 High performance 1 1 1 • x1 + x2 + x3 = 0.5 , Summary 1 1 1 3 2 2 (x1,x2,x3) ∈ R , x1 ≥ x + x , x1 0 . p 2 3 sdo1$bardim <- c(3) 18 / 48 Second-order cone and semidefinite optimization 2 1 0 Introduction x1 x1 Simple models minimize 1 2 1 • + Advanced models 0 1 2 Second-order cone 1 0 0 and semidefinite optimization subject to 0 1 0 • x1 + x1 = 1.0 , Better formulations 0 0 1 Data handling and visualization 1 1 1 High performance 1 1 1 • x1 + x2 + x3 = 0.5 , Summary 1 1 1 3 2 2 (x1,x2,x3) ∈ R , x1 ≥ x + x , x1 0 . p 2 3 # Block triplet format (SDPA) sdo1$barc$j <- c(1,1,1,1,1) sdo1$barc$k <- c(1,2,2,3,3) sdo1$barc$l <- c(1,1,2,2,3) sdo1$barc$v <- c(2,1,2,1,2) 19 / 48 Second-order cone and semidefinite optimization 2 1 0 Introduction x1 x1 Simple models minimize 1 2 1 • + Advanced models 0 1 2 Second-order cone 1 0 0 and semidefinite optimization subject to 0 1 0 • x1 + x1 = 1.0 , Better formulations 0 0 1 Data handling and visualization 1 1 1 High performance 1 1 1 • x1 + x2 + x3 = 0.5 , Summary 1 1 1 3 2 2 (x1,x2,x3) ∈ R , x1 ≥ x + x , x1 0 . p 2 3 # Block triplet format (SDPA) sdo1$barA$i <- c(1,1,1, 2,2,2,2,2,2) sdo1$barA$j <- c(1,1,1, 1,1,1,1,1,1) sdo1$barA$k <- c(1,2,3, 1,2,3,2,3,3) sdo1$barA$l <- c(1,2,3, 1,1,1,2,2,3) sdo1$barA$v <- c(1,1,1, 1,1,1,1,1,1) 20 / 48 Better formulations 21 / 48 General quadratic formulation Introduction 1 T T T minimize 2 x Qx + c x + e v + k Simple models subject to −v ≤ x ≤ v, Advanced models Better formulations General quadratic formulation Separable quadratic formulation Conic quadratic formulation rr <- mosek_read("probQP.opf") Data handling and qp <- rr$prob visualization High performance Summary rqp <- mosek(qp) 22 / 48 General quadratic formulation Introduction 1 T T T minimize 2 x Qx + c x + e v + k Simple models subject to −v ≤ x ≤ v, Advanced models Better formulations General quadratic formulation Separable quadratic formulation Conic quadratic formulation ITE PFEAS DFEAS POBJ TIME Data handling and 8 1.3e-14 3.1e-08 4.213156702e+03 74.84 visualization 9 1.2e-14 2.5e-09 4.213153627e+03 82.54 High performance Summary 10 1.1e-14 1.3e-10 4.213153292e+03 90.21 23 / 48 Separable quadratic formulation T Introduction Cholesky Factorization: Q = A A Simple models Advanced models 1 T T T Better formulations minimize 2 w w + c x + e v + k General quadratic formulation subject to −v ≤ x ≤ v, Separable quadratic Ax w, formulation = Conic quadratic formulation Data handling and visualization High performance Summary 24 / 48 Separable quadratic formulation T Introduction Cholesky Factorization: Q = A A Simple models Advanced models 1 T T T Better formulations minimize 2 w w + c x + e v + k General
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages55 Page
-
File Size-