The MOSEK Python optimizer API manual Version 7.0 (Revision 141)
Optimizer API for Python - Documentation - Mosek Optimizer API for Python - Documentation - Mosek
192 CHAPTER 15. SENSITIVITY ANALYSIS Basis type Var. β 1 β 2 σ 1 σ 2 c 1 −∞ 3.00 300.00 300.00 c 2 −∞ ∞ 100.00 100.00 c 3 −2.00 ∞ 0.00 0.00 c 4 −∞ 2.00 500.00 500.00 c 5 −3.00 ∞ 500.00 500.00 c 6 −∞ 2.00 500.00 500.00 c 7 −2.00 ∞ 0.00 0.00 Optimal partition type Var. β 1 β 2 σ 1 σ 2 c 1 −∞ 3.00 300.00 300.00 c 2 −∞ ∞ 100.00 100.00 c 3 −2.00 ∞ 0.00 0.00 c 4 −∞ 2.00 500.00 500.00 c 5 −3.00 ∞ 500.00 500.00 c 6 −∞ 2.00 500.00 500.00 c 7 −2.00 ∞ 0.00 0.00 Table 15.2: Ranges and shadow prices related to the objective coefficients. Left: Results for the basis type sensitivity analysis. Right: Results for the optimal partition type sensitivity analysis. β ∈ [0, 300] then the optimal objective value will increase by the value σ 1 β = 3β. 15.5 Sensitivity analysis from the MOSEK API MOSEK provides the functions Task.primalsensitivity and Task.dualsensitivity for performing sensitivity analysis. The code below gives an example of its use. 2 ## [ sensitivity.py ] 3 # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 4 # 5 # File: sensitivity.py 6 # 7 # Purpose: To demonstrate how to perform sensitivity 8 # analysis from the API on a small problem: 9 # 10 # minimize 11 # 12 # obj: +1 x11 + 2 x12 + 5 x23 + 2 x24 + 1 x31 + 2 x33 + 1 x34 13 # st 14 # c1: + x11 + x12
15.5. SENSITIVITY ANALYSIS FROM THE MOSEK API 193 25 26 import sys 27 28 import mosek 29 # If numpy is installed, use that, otherwise use the 30 # Mosek’s array module. 31 try: 32 from numpy import array,zeros,ones 33 except ImportError: 34 from mosek.array import array, zeros, ones 35 36 37 # Since the actual value of Infinity is ignores, we define it solely 38 # for symbolic purposes: 39 inf = 0.0 40 41 # Define a stream printer to grab output from MOSEK 42 def streamprinter(text): 43 sys.stdout.write(text) 44 sys.stdout.flush() 45 46 47 48 # We might write everything directly as a script, but it looks nicer 49 # to create a function. 50 def main (): 51 # Create a MOSEK environment 52 env = mosek.Env () 53 # Attach a printer to the environment 54 env.set Stream (mosek.streamtype.log, streamprinter) 55 56 # Create a task 57 task = env.Task(0,0) 58 # Attach a printer to the task 59 task.set Stream (mosek.streamtype.log, streamprinter) 60 61 # Set up data 62 63 bkc = [ mosek.boundkey.up,mosek.boundkey.up, 64 mosek.boundkey.up,mosek.boundkey.fx, 65 mosek.boundkey.fx,mosek.boundkey.fx, 66 mosek.boundkey.fx ] 67 blc = [ -inf, -inf, -inf, 800., 100., 500., 500. ] 68 buc = [ 400., 1200., 1000., 800., 100., 500., 500. ] 69 70 bkx = [ mosek.boundkey.lo,mosek.boundkey.lo, 71 mosek.boundkey.lo,mosek.boundkey.lo, 72 mosek.boundkey.lo,mosek.boundkey.lo, 73 mosek.boundkey.lo ] 74 c = [ 1.0,2.0,5.0,2.0,1.0,2.0,1.0 ] 75 blx = [ 0.0,0.0,0.0,0.0,0.0,0.0,0.0 ] 76 bux = [ inf,inf,inf,inf,inf,inf,inf ] 77 78 ptrb = [ 0,2,4,6, 8,10,12 ] 79 ptre = [ 2,4,6,8,10,12,14 ] 80 sub = [ 0,3,0,4,1,5,1,6,2,3,2,5,2,6 ] 81 82 val = [ 1.0,1.0,1.0,1.0,1.0,1.0,1.0,
- Page 163 and 164: 11.2. LINEAR OPTIMIZATION 141 Whene
- Page 165 and 166: 11.2. LINEAR OPTIMIZATION 143 11.2.
- Page 167 and 168: 11.2. LINEAR OPTIMIZATION 145 • R
- Page 169 and 170: 11.5. NONLINEAR CONVEX OPTIMIZATION
- Page 171 and 172: 11.6. SOLVING PROBLEMS IN PARALLEL
- Page 173 and 174: 11.6. SOLVING PROBLEMS IN PARALLEL
- Page 175 and 176: 11.6. SOLVING PROBLEMS IN PARALLEL
- Page 177 and 178: Chapter 12 The optimizers for mixed
- Page 179 and 180: 12.3. THE MIXED-INTEGER CONIC OPTIM
- Page 181 and 182: 12.5. TERMINATION CRITERION 159 •
- Page 183 and 184: 12.7. UNDERSTANDING SOLUTION QUALIT
- Page 185 and 186: Chapter 13 The analyzers 13.1 The p
- Page 187 and 188: 13.1. THE PROBLEM ANALYZER 165 Cons
- Page 189 and 190: 13.2. ANALYZING INFEASIBLE PROBLEMS
- Page 191 and 192: 13.2. ANALYZING INFEASIBLE PROBLEMS
- Page 193 and 194: 13.2. ANALYZING INFEASIBLE PROBLEMS
- Page 195 and 196: 13.2. ANALYZING INFEASIBLE PROBLEMS
- Page 197 and 198: 13.2. ANALYZING INFEASIBLE PROBLEMS
- Page 199 and 200: Chapter 14 Primal feasibility repai
- Page 201 and 202: 14.2. AUTOMATIC REPAIR 179 One way
- Page 203 and 204: 14.3. FEASIBILITY REPAIR IN MOSEK 1
- Page 205 and 206: 14.3. FEASIBILITY REPAIR IN MOSEK 1
- Page 207 and 208: Chapter 15 Sensitivity analysis 15.
- Page 209 and 210: 15.4. SENSITIVITY ANALYSIS FOR LINE
- Page 211 and 212: 15.4. SENSITIVITY ANALYSIS FOR LINE
- Page 213: 15.4. SENSITIVITY ANALYSIS FOR LINE
- Page 217 and 218: 15.6. SENSITIVITY ANALYSIS WITH THE
- Page 219 and 220: 15.6. SENSITIVITY ANALYSIS WITH THE
- Page 221 and 222: Appendix A API reference This chapt
- Page 223 and 224: 201 • Task.relaxprimal Obtain inf
- Page 225 and 226: A.1. EXCEPTIONS 203 • Task.putvar
- Page 227 and 228: A.2. CLASS TASK 205 Arguments which
- Page 229 and 230: A.2. CLASS TASK 207 See also • Ro
- Page 231 and 232: A.2. CLASS TASK 209 Description: Ap
- Page 233 and 234: A.2. CLASS TASK 211 Description: If
- Page 235 and 236: A.2. CLASS TASK 213 A.2.16 Task.com
- Page 237 and 238: A.2. CLASS TASK 215 subj : int[] In
- Page 239 and 240: A.2. CLASS TASK 217 firsti : int In
- Page 241 and 242: A.2. CLASS TASK 219 A.2.27 Task.get
- Page 243 and 244: A.2. CLASS TASK 221 valijkl : Descr
- Page 245 and 246: A.2. CLASS TASK 223 A.2.33 Task.get
- Page 247 and 248: A.2. CLASS TASK 225 idx : long Inde
- Page 249 and 250: A.2. CLASS TASK 227 A.2.41 Task.get
- Page 251 and 252: A.2. CLASS TASK 229 i : int Index o
- Page 253 and 254: A.2. CLASS TASK 231 A.2.49 Task.get
- Page 255 and 256: A.2. CLASS TASK 233 conetype : cone
- Page 257 and 258: A.2. CLASS TASK 235 Description: Ob
- Page 259 and 260: A.2. CLASS TASK 237 sub : int[] Ind
- Page 261 and 262: A.2. CLASS TASK 239 A.2.64 Task.get
- Page 263 and 264: A.2. CLASS TASK 241 Computes the vi
15.5. SENSITIVITY ANALYSIS FROM THE <strong>MOSEK</strong> <strong>API</strong> 193<br />
25<br />
26 import sys<br />
27<br />
28 import mosek<br />
29 # If numpy is installed, use that, otherwise use the<br />
30 # Mosek’s array module.<br />
31 try:<br />
32 from numpy import array,zeros,ones<br />
33 except ImportError:<br />
34 from mosek.array import array, zeros, ones<br />
35<br />
36<br />
37 # Since the actual value of Infinity is ignores, we define it solely<br />
38 # for symbolic purposes:<br />
39 inf = 0.0<br />
40<br />
41 # Define a stream printer to grab output from <strong>MOSEK</strong><br />
42 def streamprinter(text):<br />
43 sys.stdout.write(text)<br />
44 sys.stdout.flush()<br />
45<br />
46<br />
47<br />
48 # We might write everything directly as a script, but it looks nicer<br />
49 # to create a function.<br />
50 def main ():<br />
51 # Create a <strong>MOSEK</strong> environment<br />
52 env = mosek.Env ()<br />
53 # Attach a printer to the environment<br />
54 env.set Stream (mosek.streamtype.log, streamprinter)<br />
55<br />
56 # Create a task<br />
57 task = env.Task(0,0)<br />
58 # Attach a printer to the task<br />
59 task.set Stream (mosek.streamtype.log, streamprinter)<br />
60<br />
61 # Set up data<br />
62<br />
63 bkc = [ mosek.boundkey.up,mosek.boundkey.up,<br />
64 mosek.boundkey.up,mosek.boundkey.fx,<br />
65 mosek.boundkey.fx,mosek.boundkey.fx,<br />
66 mosek.boundkey.fx ]<br />
67 blc = [ -inf, -inf, -inf, 800., 100., 500., 500. ]<br />
68 buc = [ 400., 1200., 1000., 800., 100., 500., 500. ]<br />
69<br />
70 bkx = [ mosek.boundkey.lo,mosek.boundkey.lo,<br />
71 mosek.boundkey.lo,mosek.boundkey.lo,<br />
72 mosek.boundkey.lo,mosek.boundkey.lo,<br />
73 mosek.boundkey.lo ]<br />
74 c = [ 1.0,2.0,5.0,2.0,1.0,2.0,1.0 ]<br />
75 blx = [ 0.0,0.0,0.0,0.0,0.0,0.0,0.0 ]<br />
76 bux = [ inf,inf,inf,inf,inf,inf,inf ]<br />
77<br />
78 ptrb = [ 0,2,4,6, 8,10,12 ]<br />
79 ptre = [ 2,4,6,8,10,12,14 ]<br />
80 sub = [ 0,3,0,4,1,5,1,6,2,3,2,5,2,6 ]<br />
81<br />
82 val = [ 1.0,1.0,1.0,1.0,1.0,1.0,1.0,