The MOSEK Python optimizer API manual Version 7.0 (Revision 141)
Optimizer API for Python - Documentation - Mosek Optimizer API for Python - Documentation - Mosek
44 CHAPTER 5. BASIC API TUTORIAL The second argument specify the semidefinite variable index j; in this example there is only a single variable, so the index is 0. The next three arguments give the number of matrices used in the linear combination, their indices (as returned by Task.appendsparsesymmat), and the weights for the individual matrices, respectively. In this example, we form the objective matrix coefficient directly from a single symmetric matrix. Similary, a constraint matrix coefficient A ij is setup by the function Task.putbaraij: 123 task.putbaraij(0, 0, [syma0], [1.0]) 124 task.putbaraij(1, 0, [syma1], [1.0]) [ sdo1.py ] where the second argument specifies the constraint number (the corresponding row of A), and the third argument specifies the semidefinite variable index (the corresponding column of A). The next three arguments specify a weighted combination of symmetric matrices used to form the constraint matrix coefficient. After the problem is solved, we read the solution using Task.getbarxj: 146 task.getbarxj(mosek.soltype.itr, 0, barx) [ sdo1.py ] The function returns the half-vectorization of x j (the lower triangular part stacked as a column vector), where the semidefinite variable index j is given in the second argument, and the third argument is a pointer to an array for storing the numerical values. 5.5 Quadratic optimization MOSEK can solve quadratic and quadratically constrained convex problems. This class of problems can be formulated as follows: 1 minimize 2 xT Q o x + c T x + c f subject to lk c ≤ 1 n−1 ∑ 2 xT Q k x + a k,j x j ≤ u c k, k = 0, . . . , m − 1, j=0 l x j ≤ x j ≤ u x j , j = 0, . . . , n − 1. (5.7) Without loss of generality it is assumed that Q o and Q k are all symmetric because x T Qx = 0.5x T (Q + Q T )x. This implies that a non-symmetric Q can be replaced by the symmetric matrix 1 2 (Q + QT ). The problem is required to be convex. More precisely, the matrix Q o must be positive semi-definite and the kth constraint must be of the form
5.5. QUADRATIC OPTIMIZATION 45 with a negative semi-definite Q k or of the form lk c ≤ 1 n−1 ∑ 2 xT Q k x + a k,j x j (5.8) j=0 n−1 1 ∑ 2 xT Q k x + a k,j x j ≤ u c k. (5.9) j=0 with a positive semi-definite Q k . This implies that quadratic equalities are not allowed. Specifying a non-convex problem will result in an error when the optimizer is called. 5.5.1 Example: Quadratic objective The following is an example of a quadratic, linearly constrained problem: This can be written equivalently as minimize x 2 1 + 0.1x 2 2 + x 2 3 − x 1 x 3 − x 2 subject to 1 ≤ x 1 + x 2 + x 3 x ≥ 0 where Q o = ⎡ ⎣ 0 0.2 0 2 0 − 1 − 1 0 2 minimize 1/2x T Q o x + c T x subject to Ax ≥ b x ≥ 0, ⎤ ⎦ , c = ⎡ ⎣ 0 − 1 0 ⎤ ⎦ , A = [ 1 1 1 ] , and b = 1. Please note that MOSEK always assumes that there is a 1/2 in front of the x T Qx term in the objective. Therefore, the 1 in front of x 2 0 becomes 2 in Q, i.e. Q o 0,0 = 2. 5.5.1.1 Source code 1 ## [ qo1.py ] 2 # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 # 4 # File: qo1.py 5 # 6 # Purpose: Demonstrate how to solve a quadratic 7 # optimization problem using the MOSEK Python API. 8 ## 9
- Page 15 and 16: CONTENTS xv B.1.45 dparam.mio near
- Page 17 and 18: CONTENTS xvii B.2.68 iparam.log sim
- Page 19 and 20: CONTENTS xix B.2.160iparam.sim refa
- Page 21 and 22: CONTENTS xxi D.18 Long integer info
- Page 23 and 24: Contact information Phone +45 3917
- Page 25 and 26: License agreement Before using the
- Page 27 and 28: Chapter 1 Changes and new features
- Page 29 and 30: 1.4. API CHANGES 7 1.3.3 Mixed-inte
- Page 31 and 32: 1.10. SUMMARY OF API CHANGES 9 •
- Page 33 and 34: 1.10. SUMMARY OF API CHANGES 11 •
- Page 35 and 36: 1.10. SUMMARY OF API CHANGES 13 •
- Page 37 and 38: Chapter 2 About this manual This ma
- Page 39 and 40: Chapter 3 Getting support and help
- Page 41 and 42: Chapter 4 Testing installation and
- Page 43 and 44: Chapter 5 Basic API tutorial In thi
- 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: 5.4. SEMIDEFINITE OPTIMIZATION 43 1
- 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 and 96: 5.13. CONVENTIONS EMPLOYED IN THE A
- Page 97 and 98: 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
5.5. QUADRATIC OPTIMIZATION 45<br />
with a negative semi-definite Q k or of the form<br />
lk c ≤ 1 n−1<br />
∑<br />
2 xT Q k x + a k,j x j (5.8)<br />
j=0<br />
n−1<br />
1 ∑<br />
2 xT Q k x + a k,j x j ≤ u c k. (5.9)<br />
j=0<br />
with a positive semi-definite Q k . This implies that quadratic equalities are not allowed. Specifying a<br />
non-convex problem will result in an error when the <strong>optimizer</strong> is called.<br />
5.5.1 Example: Quadratic objective<br />
<strong>The</strong> following is an example of a quadratic, linearly constrained problem:<br />
This can be written equivalently as<br />
minimize x 2 1 + 0.1x 2 2 + x 2 3 − x 1 x 3 − x 2<br />
subject to 1 ≤ x 1 + x 2 + x 3<br />
x ≥ 0<br />
where<br />
Q o =<br />
⎡<br />
⎣ 0 0.2 0<br />
2 0 − 1<br />
− 1 0 2<br />
minimize 1/2x T Q o x + c T x<br />
subject to Ax ≥ b<br />
x ≥ 0,<br />
⎤<br />
⎦ , c =<br />
⎡<br />
⎣ 0 − 1<br />
0<br />
⎤<br />
⎦ , A = [ 1 1 1 ] , and b = 1.<br />
Please note that <strong>MOSEK</strong> always assumes that there is a 1/2 in front of the x T Qx term in the objective.<br />
<strong>The</strong>refore, the 1 in front of x 2 0 becomes 2 in Q, i.e. Q o 0,0 = 2.<br />
5.5.1.1 Source code<br />
1 ##<br />
[ qo1.py ]<br />
2 # Copyright: Copyright (c) <strong>MOSEK</strong> ApS, Denmark. All rights reserved.<br />
3 #<br />
4 # File: qo1.py<br />
5 #<br />
6 # Purpose: Demonstrate how to solve a quadratic<br />
7 # optimization problem using the <strong>MOSEK</strong> <strong>Python</strong> <strong>API</strong>.<br />
8 ##<br />
9