The MOSEK Python optimizer API manual Version 7.0 (Revision 141)
Optimizer API for Python - Documentation - Mosek Optimizer API for Python - Documentation - Mosek
62 CHAPTER 5. BASIC API TUTORIAL 34 if solsta in [ mosek.solsta.optimal, 35 mosek.solsta.near optimal ]: 36 print ("An optimal basic solution is located.") 37 task.solutionsummary(mosek.streamtype.log) 38 elif solsta in [ mosek.solsta.dual infeas cer, 39 mosek.solsta.near dual infeas cer ]: 40 print ("Dual infeasibility certificate found.") 41 elif solsta in [ mosek.solsta.prim infeas cerl, 42 mosek.solsta.near prim infeas cer ]: 43 print("Primal infeasibility certificate found.\n"); 44 elif solsta == mosek.solsta.sta unknown: 45 # The solutions status is unknown. The termination code 46 # indicating why the optimizer terminated prematurely. 47 print ("The solution status is unknown.") 48 print ("Termination code: %s" % str(trmcode)) 49 else: 50 print ("An unexpected solution status is obtained.") 51 52 except mosek.MosekException as err: 53 print ("Generic error:") 54 print (err) 55 56 if name == ’ main ’: 57 import sys 58 main(sys.argv[1:]) 5.10 Problem modification and reoptimization Often one might want to solve not just a single optimization problem, but a sequence of problem, each differing only slightly from the previous one. This section demonstrates how to modify and re-optimize an existing problem. The example we study is a simple production planning model. 5.10.1 Example: Production planning A company manufactures three types of products. Suppose the stages of manufacturing can be split into three parts, namely Assembly, Polishing and Packing. In the table below we show the time required for each stage as well as the profit associated with each product. Product no. Assembly (minutes) Polishing (minutes) Packing (minutes) Profit ($) 0 2 3 2 1.50 1 4 2 3 2.50 2 3 3 2 3.00 With the current resources available, the company has 100, 000 minutes of assembly time, 50, 000 minutes of polishing time and 60, 000 minutes of packing time available per year. Now the question is how many items of each product the company should produce each year in order to maximize profit?
5.10. PROBLEM MODIFICATION AND REOPTIMIZATION 63 Denoting the number of items of each type by x 0 , x 1 and x 2 , this problem can be formulated as the linear optimization problem: and maximize 1.5x 0 + 2.5x 1 + 3.0x 2 subject to 2x 0 + 4x 1 + 3x 2 ≤ 100000, 3x 0 + 2x 1 + 3x 2 ≤ 50000, 2x 0 + 3x 1 + 2x 2 ≤ 60000, x 0 , x 1 , x 2 ≥ 0. The following code loads this problem into the optimization task. 35 # Create a MOSEK environment 36 env = mosek.Env () 37 [ production.py ] 38 # Create a task 39 task = env.Task(0,0) 40 # Attach a printer to the task 41 task.set Stream (mosek.streamtype.log, streamprinter) 42 43 # Bound keys for constraints 44 bkc = [mosek.boundkey.up, 45 mosek.boundkey.up, 46 mosek.boundkey.up] 47 # Bound values for constraints 48 blc = array ([-inf, -inf, -inf]) 49 buc = array ([100000.0 , 50000.0, 60000.0]) 50 51 # Bound keys for variables 52 bkx = [mosek.boundkey.lo, 53 mosek.boundkey.lo, 54 mosek.boundkey.lo] 55 # Bound values for variables 56 blx = array ([ 0.0, 0.0, 0.0]) 57 bux = array ([+inf, +inf, +inf]) 58 59 # Objective coefficients 60 csub = array([ 0, 1, 2 ]) 61 cval = array([ 1.5, 2.5, 3.0 ]) 62 63 # We input the A matrix column-wise 64 # asub contains row indexes 65 asub = array([ 0, 1, 2, 66 0, 1, 2, 67 0, 1, 2]) 68 # acof contains coefficients 69 acof = array([ 2.0, 3.0, 2.0, 70 4.0, 2.0, 3.0, 71 3.0, 3.0, 2.0 ]) 72 # aptrb and aptre contains the offsets into asub and acof where 73 # columns start and end respectively 74 aptrb = array([ 0, 3, 6 ]) 75 aptre = array([ 3, 6, 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 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: 5.9. RESPONSE HANDLING 61 Note that
- 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
- 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
62 CHAPTER 5. BASIC <strong>API</strong> TUTORIAL<br />
34 if solsta in [ mosek.solsta.optimal,<br />
35 mosek.solsta.near optimal ]:<br />
36 print ("An optimal basic solution is located.")<br />
37 task.solutionsummary(mosek.streamtype.log)<br />
38 elif solsta in [ mosek.solsta.dual infeas cer,<br />
39 mosek.solsta.near dual infeas cer ]:<br />
40 print ("Dual infeasibility certificate found.")<br />
41 elif solsta in [ mosek.solsta.prim infeas cerl,<br />
42 mosek.solsta.near prim infeas cer ]:<br />
43 print("Primal infeasibility certificate found.\n");<br />
44 elif solsta == mosek.solsta.sta unknown:<br />
45 # <strong>The</strong> solutions status is unknown. <strong>The</strong> termination code<br />
46 # indicating why the <strong>optimizer</strong> terminated prematurely.<br />
47 print ("<strong>The</strong> solution status is unknown.")<br />
48 print ("Termination code: %s" % str(trmcode))<br />
49 else:<br />
50 print ("An unexpected solution status is obtained.")<br />
51<br />
52 except mosek.MosekException as err:<br />
53 print ("Generic error:")<br />
54 print (err)<br />
55<br />
56 if name == ’ main ’:<br />
57 import sys<br />
58 main(sys.argv[1:])<br />
5.10 Problem modification and reoptimization<br />
Often one might want to solve not just a single optimization problem, but a sequence of problem, each<br />
differing only slightly from the previous one. This section demonstrates how to modify and re-optimize<br />
an existing problem. <strong>The</strong> example we study is a simple production planning model.<br />
5.10.1 Example: Production planning<br />
A company manufactures three types of products. Suppose the stages of manufacturing can be split<br />
into three parts, namely Assembly, Polishing and Packing. In the table below we show the time<br />
required for each stage as well as the profit associated with each product.<br />
Product no. Assembly (minutes) Polishing (minutes) Packing (minutes) Profit ($)<br />
0 2 3 2 1.50<br />
1 4 2 3 2.50<br />
2 3 3 2 3.00<br />
With the current resources available, the company has 100, 000 minutes of assembly time, 50, 000<br />
minutes of polishing time and 60, 000 minutes of packing time available per year.<br />
Now the question is how many items of each product the company should produce each year in order<br />
to maximize profit?