The MOSEK Python optimizer API manual Version 7.0 (Revision 141)
Optimizer API for Python - Documentation - Mosek Optimizer API for Python - Documentation - Mosek
92 CHAPTER 7. ADVANCED API TUTORIAL 113 else: 114 print ("x%s = %s" % (basis[varsub[i]] - numcon, w1[varsub[i]])) 115 116 # Solve B^Tx = w2 117 nz = 1 118 varsub[0] = 0 119 120 nz = task.solvewithbasis(1, nz, varsub, w2) 121 122 print ("Solution to B^Tx = w2:") 123 124 for i in range(nz): 125 if basis[varsub[i]] < numcon: 126 print ("xc %s = %s" % (basis[varsub[i]], w2[varsub[i]])) 127 else: 128 print ("x %s = %s" % (basis[varsub[i]] - numcon, w2[varsub[i]]) ) 129 except Exception as e: 130 print (e) 131 132 if name == ’ main ’: 133 main() In the example above the linear system is solved using the optimal basis for (7.4) and the original right-hand side of the problem. Thus the solution to the linear system is the optimal solution to the problem. When running the example program the following output is produced. basis[0] = 1 Basis variable no 0 is xc1. basis[1] = 2 Basis variable no 1 is x0. Solution to Bx = b: x0 = 2.000000e+00 xc1 = -4.000000e+00 Solution to B^Tx = c: x1 = -1.000000e+00 x0 = 1.000000e+00 Please note that the ordering of the basis variables is and thus the basis is given by: It can be verified that [ B = [ ] x c 1 x 0 [ ] x c 1 = x 0 0 1 − 1 1 [ − 4 2 ] ]
7.2. SOLVING LINEAR SYSTEMS INVOLVING THE BASIS MATRIX 93 is a solution to [ 0 1 − 1 1 ] [ ] [ x c 1 2 = x 0 6 ] . 7.2.3 Solving arbitrary linear systems MOSEK can be used to solve an arbitrary (rectangular) linear system Ax = b using the Task.solvewithbasis function without optimizing the problem as in the previous example. This is done by setting up an A matrix in the task, setting all variables to basic and calling the Task.solvewithbasis function with the b vector as input. The solution is returned by the function. Below we demonstrate how to solve the linear system with b = (1, −2) and b = (7, 0) . [ 0 1 − 1 1 ] [ ] x0 = x 1 [ b1 b 2 ] [ solvelinear.py ] 1 from future import with statement 2 ## 3 # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 4 # 5 # File : solvelinear.py 6 # 7 # Purpose : To demonstrate the usage of MSK solvewithbasis 8 # when solving the linear system: 9 # 10 # 1.0 x1 = b1 11 # -1.0 x0 + 1.0 x1 = b2 12 # 13 # with two different right hand sides 14 # 15 # b = (1.0, -2.0) 16 # 17 # and 18 # 19 # b = (7.0, 0.0) 20 ## 21 22 import mosek 23 24 def put a( task, 25 aval, 26 asub, 27 ptrb, 28 ptre, 29 numvar, 30 basis): (7.5)
- 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 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: 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
- Page 147 and 148: 10.1. LINEAR OPTIMIZATION 125 be a
- Page 149 and 150: 10.2. CONIC QUADRATIC OPTIMIZATION
- Page 151 and 152: 10.2. CONIC QUADRATIC OPTIMIZATION
- Page 153 and 154: 10.3. SEMIDEFINITE OPTIMIZATION 131
- Page 155 and 156: 10.4. QUADRATIC AND QUADRATICALLY C
- Page 157 and 158: Chapter 11 The optimizers for conti
- Page 159 and 160: 11.1. HOW AN OPTIMIZER WORKS 137 11
- Page 161 and 162: 11.2. LINEAR OPTIMIZATION 139 11.2.
- Page 163 and 164: 11.2. LINEAR OPTIMIZATION 141 Whene
92 CHAPTER 7. ADVANCED <strong>API</strong> TUTORIAL<br />
113 else:<br />
114 print ("x%s = %s" % (basis[varsub[i]] - numcon, w1[varsub[i]]))<br />
115<br />
116 # Solve B^Tx = w2<br />
117 nz = 1<br />
118 varsub[0] = 0<br />
119<br />
120 nz = task.solvewithbasis(1, nz, varsub, w2)<br />
121<br />
122 print ("Solution to B^Tx = w2:")<br />
123<br />
124 for i in range(nz):<br />
125 if basis[varsub[i]] < numcon:<br />
126 print ("xc %s = %s" % (basis[varsub[i]], w2[varsub[i]]))<br />
127 else:<br />
128 print ("x %s = %s" % (basis[varsub[i]] - numcon, w2[varsub[i]]) )<br />
129 except Exception as e:<br />
130 print (e)<br />
131<br />
132 if name == ’ main ’:<br />
133 main()<br />
In the example above the linear system is solved using the optimal basis for (7.4) and the original<br />
right-hand side of the problem. Thus the solution to the linear system is the optimal solution to the<br />
problem. When running the example program the following output is produced.<br />
basis[0] = 1<br />
Basis variable no 0 is xc1.<br />
basis[1] = 2<br />
Basis variable no 1 is x0.<br />
Solution to Bx = b:<br />
x0 = 2.000000e+00<br />
xc1 = -4.000000e+00<br />
Solution to B^Tx = c:<br />
x1 = -1.000000e+00<br />
x0 = 1.000000e+00<br />
Please note that the ordering of the basis variables is<br />
and thus the basis is given by:<br />
It can be verified that<br />
[<br />
B =<br />
[ ] x<br />
c<br />
1<br />
x 0<br />
[ ] x<br />
c<br />
1<br />
=<br />
x 0<br />
0 1<br />
− 1 1<br />
[ − 4<br />
2<br />
]<br />
]