The MOSEK Python optimizer API manual Version 7.0 (Revision 141)

Optimizer API for Python - Documentation - Mosek Optimizer API for Python - Documentation - Mosek

25.11.2015 Views

72 CHAPTER 5. BASIC API TUTORIAL 5.13.2 Vector formats Three different vector formats are used in the MOSEK API: Full vector: This is simply an array where the first element corresponds to the first item, the second element to the second item etc. For example to get the linear coefficients of the objective in task, one would write c = zeros(numvar,float) task.getc(c) where numvar is the number of variables in the problem. Vector slice: A vector slice is a range of values. For example, to get the bounds associated constraint 3 through 10 (both inclusive) one would write upper bound = zeros(8,float) lower bound = zeros(8,float) bound key = array([None] * 8) task.getboundslice(accmode.con, 2, 10, bound key,lower bound,upper bound) Please note that items in MOSEK are numbered from 0 , so that the index of the first item is 0 , and the index of the n ’th item is n − 1. Sparse vector: A sparse vector is given as an array of indexes and an array of values. For example, to input a set of bounds associated with constraints number 1, 6, 3, and 9, one might write bound index = [ 1, 6, 3, 9] bound key = [boundkey.fr,boundkey.lo,boundkey.up,boundkey.fx] lower bound = [ 0.0, -10.0, 0.0, 5.0] upper bound = [ 0.0, 0.0, 6.0, 5.0] task.putboundlist(accmode.con, bound index, bound key,lower bound,upper bound) Note that the list of indexes need not be ordered. 5.13.3 Matrix formats The coefficient matrices in a problem are inputted and extracted in a sparse format, either as complete or a partial matrices. Basically there are two different formats for this.

5.13. CONVENTIONS EMPLOYED IN THE API 73 5.13.3.1 Unordered triplets In unordered triplet format each entry is defined as a row index, a column index and a coefficient. For example, to input the A matrix coefficients for a 1,2 = 1.1 , a 3,3 = 4.3 , and a 5,4 = 0.2 , one would write as follows: subi = array([ 1, 3, 5 ]) subj = array([ 2, 3, 4 ]) cof = array([ 1.1, 4.3, 0.2 ]) task.putaijlist(subi,subj,cof) Please note that in some cases (like Task.putaijlist) only the specified indexes remain modified — all other are unchanged. In other cases (such as Task.putqconk) the triplet format is used to modify all entries — entries that are not specified are set to 0. 5.13.3.2 Row or column ordered sparse matrix In a sparse matrix format only the non-zero entries of the matrix are stored. MOSEK uses a sparse packed matrix format ordered either by rows or columns. In the column-wise format the position of the non-zeros are given as a list of row indexes. In the row-wise format the position of the non-zeros are given as a list of column indexes. Values of the non-zero entries are given in column or row order. A sparse matrix in column ordered format consists of: asub: aval: ptrb: ptre: List of row indexes. List of non-zero entries of A ordered by columns. Where ptrb[j] is the position of the first value/index in aval / asub for column j. Where ptre[j] is the position of the last value/index plus one in aval / asub for column j. The values of a matrix A with numcol columns are assigned so that for We define j = 0, . . . , numcol − 1. As an example consider the matrix a asub[k],j = aval[k], k = ptrb[j], . . . , ptre[j] − 1.

72 CHAPTER 5. BASIC <strong>API</strong> TUTORIAL<br />

5.13.2 Vector formats<br />

Three different vector formats are used in the <strong>MOSEK</strong> <strong>API</strong>:<br />

Full vector:<br />

This is simply an array where the first element corresponds to the first item, the second element<br />

to the second item etc. For example to get the linear coefficients of the objective in task, one<br />

would write<br />

c = zeros(numvar,float)<br />

task.getc(c)<br />

where numvar is the number of variables in the problem.<br />

Vector slice:<br />

A vector slice is a range of values. For example, to get the bounds associated constraint 3 through<br />

10 (both inclusive) one would write<br />

upper bound = zeros(8,float)<br />

lower bound = zeros(8,float)<br />

bound key = array([None] * 8)<br />

task.getboundslice(accmode.con, 2, 10,<br />

bound key,lower bound,upper bound)<br />

Please note that items in <strong>MOSEK</strong> are numbered from 0 , so that the index of the first item is 0<br />

, and the index of the n ’th item is n − 1.<br />

Sparse vector:<br />

A sparse vector is given as an array of indexes and an array of values. For example, to input a<br />

set of bounds associated with constraints number 1, 6, 3, and 9, one might write<br />

bound index = [ 1, 6, 3, 9]<br />

bound key = [boundkey.fr,boundkey.lo,boundkey.up,boundkey.fx]<br />

lower bound = [ 0.0, -10.0, 0.0, 5.0]<br />

upper bound = [ 0.0, 0.0, 6.0, 5.0]<br />

task.putboundlist(accmode.con, bound index,<br />

bound key,lower bound,upper bound)<br />

Note that the list of indexes need not be ordered.<br />

5.13.3 Matrix formats<br />

<strong>The</strong> coefficient matrices in a problem are inputted and extracted in a sparse format, either as complete<br />

or a partial matrices. Basically there are two different formats for this.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!