The MOSEK Python optimizer API manual Version 7.0 (Revision 141)
Optimizer API for Python - Documentation - Mosek Optimizer API for Python - Documentation - Mosek
74 CHAPTER 5. BASIC API TUTORIAL ptrb 0 2 3 5 ptre 2 3 5 7 asub 0 2 1 0 3 0 1 2 aval 1.1 3.1 2.2 1.3 4.4 1.4 3.4 2.5 Column 0 Column 1 Figure 5.1: The matrix A (5.17) represented in column ordered packed sparse matrix format. A = ⎡ ⎢ ⎣ 1.1 1.3 1.4 2.2 2.5 3.1 3.4 4.4 which can be represented in the column ordered sparse matrix format as ⎤ ⎥ ⎦ . (5.17) ptrb = [0, 2, 3, 5, 7], ptre = [2, 3, 5, 7, 8], asub = [0, 2, 1, 0, 3, 0, 2, 1], aval = [1.1, 3.1, 2.2, 1.3, 4.4, 1.4, 3.4, 2.5]. Fig. 5.1 illustrates how the matrix A (5.17) is represented in column ordered sparse matrix format. 5.13.3.3 Row ordered sparse matrix The matrix A (5.17) can also be represented in the row ordered sparse matrix format as: ptrb = [0, 3, 5, 7], ptre = [3, 5, 7, 8], asub = [0, 2, 3, 1, 4, 0, 3, 2], aval = [1.1, 1.3, 1.4, 2.2, 2.5, 3.1, 3.4, 4.4].
5.13. CONVENTIONS EMPLOYED IN THE API 75 5.13.4 Array objects The MOSEK Python API provides a simple array object in the module mosekarr. This includes a one-dimensional dense array which can be of type Float, Int or Object, and a few operators and functions to create and modify array objects. Arrays can be constructed in several ways: # Create an array of integers a0 = array([1,2,3],int) # Create an array of floats a1 = array([1,2,3],float) # Create an integer array of ones a2 = ones(10) # Create an float array of ones a3 = ones(10,float) # Create a range of integers 5,6,...,9 a4 = range(5,10) # Create and array of objects a5 = array([’a string’, ’b string’, 10, 2.2]) A limited set of operations on arrays are available - these should work more or less like the equivalent Numeric operations: a = ones(10,float) b = 1.0 * arange(10) # element-wise multiplication, addition and subtraction c0 = a * b c1 = a + b c2 = a - b # multiplly each element by 2.1 c4 = a * 2.1 # add 2 to each element c5 = a + 2 If more advanced array operations is needed, it is necessary to install the Python Numeric package. 5.13.5 Typical problems using the Python API Since all all type-information in Python is implicit, type-checking is performed only when required, and in certain cases it is necessary to explicitly write type information. The MOSEK API currently only supports its own array object (mosek.array.array) and Pythonnumpy arrays. Other array or list compatible objects will are accepted but are converted. Typically type errors occur in two situations:
- Page 45 and 46: 5.1. THE BASICS 23 5 # 6 # Purpose:
- Page 47 and 48: 5.2. LINEAR OPTIMIZATION 25 and the
- Page 49 and 50: 5.2. LINEAR OPTIMIZATION 27 Load a
- Page 51 and 52: 5.2. LINEAR OPTIMIZATION 29 Optimiz
- Page 53 and 54: 5.2. LINEAR OPTIMIZATION 31 88 task
- Page 55 and 56: 5.2. LINEAR OPTIMIZATION 33 51 mose
- Page 57 and 58: 5.3. CONIC QUADRATIC OPTIMIZATION 3
- Page 59 and 60: 5.3. CONIC QUADRATIC OPTIMIZATION 3
- Page 61 and 62: 5.4. SEMIDEFINITE OPTIMIZATION 39 m
- Page 63 and 64: 5.4. SEMIDEFINITE OPTIMIZATION 41 4
- Page 65 and 66: 5.4. SEMIDEFINITE OPTIMIZATION 43 1
- Page 67 and 68: 5.5. QUADRATIC OPTIMIZATION 45 with
- Page 69 and 70: 5.5. QUADRATIC OPTIMIZATION 47 68 #
- Page 71 and 72: 5.5. QUADRATIC OPTIMIZATION 49 5.5.
- Page 73 and 74: 5.5. QUADRATIC OPTIMIZATION 51 81 a
- Page 75 and 76: 5.6. THE SOLUTION SUMMARY 53 • Th
- Page 77 and 78: 5.7. INTEGER OPTIMIZATION 55 21 # f
- Page 79 and 80: 5.7. INTEGER OPTIMIZATION 57 137 sy
- Page 81 and 82: 5.8. THE SOLUTION SUMMARY FOR MIXED
- Page 83 and 84: 5.9. RESPONSE HANDLING 61 Note that
- Page 85 and 86: 5.10. PROBLEM MODIFICATION AND REOP
- Page 87 and 88: 5.10. PROBLEM MODIFICATION AND REOP
- Page 89 and 90: 5.11. SOLUTION ANALYSIS 67 151 # Pu
- Page 91 and 92: 5.13. CONVENTIONS EMPLOYED IN THE A
- Page 93 and 94: 5.13. CONVENTIONS EMPLOYED IN THE A
- Page 95: 5.13. CONVENTIONS EMPLOYED IN THE A
- Page 99 and 100: Chapter 6 Nonlinear API tutorial Th
- Page 101 and 102: 6.1. SEPARABLE CONVEX (SCOPT) INTER
- Page 103 and 104: 6.1. SEPARABLE CONVEX (SCOPT) INTER
- Page 105 and 106: 6.1. SEPARABLE CONVEX (SCOPT) INTER
- Page 107 and 108: Chapter 7 Advanced API tutorial Thi
- Page 109 and 110: 7.1. THE PROGRESS CALL-BACK 87 71 p
- Page 111 and 112: 7.2. SOLVING LINEAR SYSTEMS INVOLVI
- Page 113 and 114: 7.2. SOLVING LINEAR SYSTEMS INVOLVI
- Page 115 and 116: 7.2. SOLVING LINEAR SYSTEMS INVOLVI
- Page 117 and 118: 7.2. SOLVING LINEAR SYSTEMS INVOLVI
- Page 119 and 120: Chapter 8 A case study 8.1 Portfoli
- Page 121 and 122: 8.1. PORTFOLIO OPTIMIZATION 99 e T
- Page 123 and 124: 8.1. PORTFOLIO OPTIMIZATION 101 is
- Page 125 and 126: 8.1. PORTFOLIO OPTIMIZATION 103 15
- Page 127 and 128: 8.1. PORTFOLIO OPTIMIZATION 105 63
- Page 129 and 130: 8.1. PORTFOLIO OPTIMIZATION 107 8.1
- Page 131 and 132: 8.1. PORTFOLIO OPTIMIZATION 109 110
- Page 133 and 134: 8.1. PORTFOLIO OPTIMIZATION 111 z j
- Page 135 and 136: 8.1. PORTFOLIO OPTIMIZATION 113 Var
- Page 137 and 138: 8.1. PORTFOLIO OPTIMIZATION 115 56
- Page 139 and 140: 8.1. PORTFOLIO OPTIMIZATION 117 172
- Page 141 and 142: Chapter 9 Usage guidelines The purp
- Page 143 and 144: 9.3. WRITING TASK DATA TO A FILE 12
- Page 145 and 146: Chapter 10 Problem formulation and
74 CHAPTER 5. BASIC <strong>API</strong> TUTORIAL<br />
ptrb<br />
0 2 3 5<br />
ptre<br />
2 3 5 7<br />
asub<br />
0 2 1 0 3 0 1 2<br />
aval<br />
1.1 3.1 2.2 1.3 4.4 1.4 3.4 2.5<br />
Column 0 Column 1<br />
Figure 5.1:<br />
<strong>The</strong> matrix A (5.17) represented in column ordered packed sparse matrix format.<br />
A =<br />
⎡<br />
⎢<br />
⎣<br />
1.1 1.3 1.4<br />
2.2 2.5<br />
3.1 3.4<br />
4.4<br />
which can be represented in the column ordered sparse matrix format as<br />
⎤<br />
⎥<br />
⎦ . (5.17)<br />
ptrb = [0, 2, 3, 5, 7],<br />
ptre = [2, 3, 5, 7, 8],<br />
asub = [0, 2, 1, 0, 3, 0, 2, 1],<br />
aval = [1.1, 3.1, 2.2, 1.3, 4.4, 1.4, 3.4, 2.5].<br />
Fig. 5.1 illustrates how the matrix A (5.17) is represented in column ordered sparse matrix format.<br />
5.13.3.3 Row ordered sparse matrix<br />
<strong>The</strong> matrix A (5.17) can also be represented in the row ordered sparse matrix format as:<br />
ptrb = [0, 3, 5, 7],<br />
ptre = [3, 5, 7, 8],<br />
asub = [0, 2, 3, 1, 4, 0, 3, 2],<br />
aval = [1.1, 1.3, 1.4, 2.2, 2.5, 3.1, 3.4, 4.4].