The MOSEK Python optimizer API manual Version 7.0 (Revision 141)
Optimizer API for Python - Documentation - Mosek Optimizer API for Python - Documentation - Mosek
40 CHAPTER 5. BASIC API TUTORIAL and x 00 + x 11 + x 22 + x 0 = 1, x 00 + x 11 + x 22 + 2(x 10 + x 20 + x 21 ) + x 1 + x 2 = 1/2. 5.4.1.1 Source code 1 ## [ sdo1.py ] 2 # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 # 4 # File: sdo1.py 5 # 6 # Purpose: Demonstrates how to solve a small mixed semidefinite and conic quadratic 7 # optimization problem using the MOSEK Python API. 8 ## 9 10 import sys 11 import mosek 12 13 # If numpy is installed, use that, otherwise use the 14 # Mosek’s array module. 15 try: 16 from numpy import array,zeros,ones 17 except ImportError: 18 from mosek.array import array, zeros, ones 19 20 # Since the value of infinity is ignored, we define it solely 21 # for symbolic purposes 22 inf = 0.0 23 24 # Define a stream printer to grab output from MOSEK 25 def streamprinter(text): 26 sys.stdout.write(text) 27 sys.stdout.flush() 28 29 def main (): 30 # Make mosek environment 31 env = mosek.Env() 32 33 # Create a task object and attach log stream printer 34 task = env.Task(0,0) 35 task.set Stream(mosek.streamtype.log, streamprinter) 36 37 # Bound keys for constraints 38 bkc = [mosek.boundkey.fx, 39 mosek.boundkey.fx] 40 41 # Bound values for constraints 42 blc = [1.0, 0.5] 43 buc = [1.0, 0.5] 44 45 # Below is the sparse representation of the A
5.4. SEMIDEFINITE OPTIMIZATION 41 46 # matrix stored by row. 47 asub = [ array([0]), 48 array([1, 2])] 49 aval = [ array([1.0]), 50 array([1.0, 1.0]) ] 51 52 conesub = [0, 1, 2] 53 54 barci = [0, 1, 1, 2, 2] 55 barcj = [0, 0, 1, 1, 2] 56 barcval = [2.0, 1.0, 2.0, 1.0, 2.0] 57 58 barai = [array([0, 1, 2]), 59 array([0, 1, 2, 1, 2, 2])] 60 baraj = [array([0, 1, 2]), 61 array([0, 0, 0, 1, 1, 2])] 62 baraval = [array([1.0, 1.0, 1.0]), 63 array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0])] 64 65 numvar = 3 66 numcon = len(bkc) 67 BARVARDIM = [3] 68 69 # Append ’numvar’ variables. 70 # The variables will initially be fixed at zero (x=0). 71 task.appendvars(numvar) 72 73 # Append ’numcon’ empty constraints. 74 # The constraints will initially have no bounds. 75 task.appendcons(numcon) 76 77 # Append matrix variables of sizes in ’BARVARDIM’. 78 # The variables will initially be fixed at zero. 79 task.appendbarvars(BARVARDIM) 80 81 # Set the linear term c 0 in the objective. 82 task.putcj(0, 1.0) 83 84 for j in range(numvar): 85 # Set the bounds on variable j 86 # blx[j]
- Page 11 and 12: CONTENTS xi A.2.162Task.isdouparnam
- Page 13 and 14: CONTENTS xiii A.2.254Task.readparam
- 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: 5.4. SEMIDEFINITE OPTIMIZATION 39 m
- 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
5.4. SEMIDEFINITE OPTIMIZATION 41<br />
46 # matrix stored by row.<br />
47 asub = [ array([0]),<br />
48 array([1, 2])]<br />
49 aval = [ array([1.0]),<br />
50 array([1.0, 1.0]) ]<br />
51<br />
52 conesub = [0, 1, 2]<br />
53<br />
54 barci = [0, 1, 1, 2, 2]<br />
55 barcj = [0, 0, 1, 1, 2]<br />
56 barcval = [2.0, 1.0, 2.0, 1.0, 2.0]<br />
57<br />
58 barai = [array([0, 1, 2]),<br />
59 array([0, 1, 2, 1, 2, 2])]<br />
60 baraj = [array([0, 1, 2]),<br />
61 array([0, 0, 0, 1, 1, 2])]<br />
62 baraval = [array([1.0, 1.0, 1.0]),<br />
63 array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0])]<br />
64<br />
65 numvar = 3<br />
66 numcon = len(bkc)<br />
67 BARVARDIM = [3]<br />
68<br />
69 # Append ’numvar’ variables.<br />
70 # <strong>The</strong> variables will initially be fixed at zero (x=0).<br />
71 task.appendvars(numvar)<br />
72<br />
73 # Append ’numcon’ empty constraints.<br />
74 # <strong>The</strong> constraints will initially have no bounds.<br />
75 task.appendcons(numcon)<br />
76<br />
77 # Append matrix variables of sizes in ’BARVARDIM’.<br />
78 # <strong>The</strong> variables will initially be fixed at zero.<br />
79 task.appendbarvars(BARVARDIM)<br />
80<br />
81 # Set the linear term c 0 in the objective.<br />
82 task.putcj(0, 1.0)<br />
83<br />
84 for j in range(numvar):<br />
85 # Set the bounds on variable j<br />
86 # blx[j]