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

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,

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,

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

Saved successfully!

Ooh no, something went wrong!