The MOSEK Python optimizer API manual Version 7.0 (Revision 141)
Optimizer API for Python - Documentation - Mosek Optimizer API for Python - Documentation - Mosek
iv CONTENTS 5.3.1 Example: Conic quadratic optimization . . . . . . . . . . . . . . . . . . . . . . . 35 5.4 Semidefinite optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 5.4.1 Example: Semidefinite optimization . . . . . . . . . . . . . . . . . . . . . . . . . 39 5.5 Quadratic optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 5.5.1 Example: Quadratic objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 5.5.2 Example: Quadratic constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 5.6 The solution summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 5.7 Integer optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 5.7.1 Example: Mixed integer linear optimization . . . . . . . . . . . . . . . . . . . . . 54 5.7.2 Specifying an initial solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 5.7.3 Example: Specifying an integer solution . . . . . . . . . . . . . . . . . . . . . . . 57 5.8 The solution summary for mixed integer problems . . . . . . . . . . . . . . . . . . . . 59 5.9 Response handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 5.10 Problem modification and reoptimization . . . . . . . . . . . . . . . . . . . . . . . . . . 62 5.10.1 Example: Production planning . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 5.10.2 Changing the A matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 5.10.3 Appending variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 5.10.4 Reoptimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 5.10.5 Appending constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 5.11 Solution analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 5.11.1 Retrieving solution quality information with the API . . . . . . . . . . . . . . . . 67 5.12 Efficiency considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 5.12.1 API overhead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 5.13 Conventions employed in the API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 5.13.1 Naming conventions for arguments . . . . . . . . . . . . . . . . . . . . . . . . . . 69 5.13.2 Vector formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 5.13.3 Matrix formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 5.13.4 Array objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 5.13.5 Typical problems using the Python API . . . . . . . . . . . . . . . . . . . . . . . 75 5.14 The license system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 5.14.1 Waiting for a free license . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 6 Nonlinear API tutorial 77 6.1 Separable convex (SCopt) interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 6.1.1 Adding separable terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 6.1.2 Example: Simple separable problem . . . . . . . . . . . . . . . . . . . . . . . . . 80 6.1.3 Ensuring convexity and differentiability . . . . . . . . . . . . . . . . . . . . . . . 82 6.1.4 SCopt Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 7 Advanced API tutorial 85 7.1 The progress call-back . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 7.1.1 Source code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 7.2 Solving linear systems involving the basis matrix . . . . . . . . . . . . . . . . . . . . . 88 7.2.1 Identifying the basis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 7.2.2 An example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 7.2.3 Solving arbitrary linear systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
CONTENTS v 8 A case study 97 8.1 Portfolio optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 8.1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 8.1.2 A basic portfolio optimization model . . . . . . . . . . . . . . . . . . . . . . . . . 98 8.1.3 The efficient frontier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 8.1.4 Improving the computational efficiency . . . . . . . . . . . . . . . . . . . . . . . 109 8.1.5 Slippage cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 9 Usage guidelines 119 9.1 Verifying the results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 9.1.1 Verifying primal feasibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 9.1.2 Verifying optimality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 9.2 Turn on logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 9.3 Writing task data to a file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 9.4 Important API limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 9.4.1 Thread safety . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 9.5 Bug reporting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 10 Problem formulation and solutions 123 10.1 Linear optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 10.1.1 Duality for linear optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 10.1.2 Infeasibility for linear optimization . . . . . . . . . . . . . . . . . . . . . . . . . . 126 10.2 Conic quadratic optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 10.2.1 Duality for conic quadratic optimization . . . . . . . . . . . . . . . . . . . . . . . 128 10.2.2 Infeasibility for conic quadratic optimization . . . . . . . . . . . . . . . . . . . . 129 10.3 Semidefinite optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 10.3.1 Duality for semidefinite optimization . . . . . . . . . . . . . . . . . . . . . . . . . 130 10.3.2 Infeasibility for semidefinite optimization . . . . . . . . . . . . . . . . . . . . . . 131 10.4 Quadratic and quadratically constrained optimization . . . . . . . . . . . . . . . . . . 132 10.4.1 Duality for quadratic and quadratically constrained optimization . . . . . . . . . 132 10.4.2 Infeasibility for quadratic and quadratically constrained optimization . . . . . . . 133 11 The optimizers for continuous problems 135 11.1 How an optimizer works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 11.1.1 Presolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 11.1.2 Dualizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 11.1.3 Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 11.1.4 Using multiple threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 11.2 Linear optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 11.2.1 Optimizer selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 11.2.2 The interior-point optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 11.2.3 The simplex based optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 11.2.4 The interior-point or the simplex optimizer? . . . . . . . . . . . . . . . . . . . . . 145 11.2.5 The primal or the dual simplex variant? . . . . . . . . . . . . . . . . . . . . . . . 145 11.3 Linear network optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 11.3.1 Network flow problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 11.4 Conic optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
- Page 1 and 2: The MOSEK Python optimizer API manu
- Page 3: Contents 1 Changes and new features
- Page 7 and 8: CONTENTS vii 14.2.1 Caveats . . . .
- Page 9 and 10: CONTENTS ix A.2.70 Task.getdviolvar
- 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
CONTENTS<br />
v<br />
8 A case study 97<br />
8.1 Portfolio optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97<br />
8.1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97<br />
8.1.2 A basic portfolio optimization model . . . . . . . . . . . . . . . . . . . . . . . . . 98<br />
8.1.3 <strong>The</strong> efficient frontier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106<br />
8.1.4 Improving the computational efficiency . . . . . . . . . . . . . . . . . . . . . . . 109<br />
8.1.5 Slippage cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109<br />
9 Usage guidelines 119<br />
9.1 Verifying the results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119<br />
9.1.1 Verifying primal feasibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120<br />
9.1.2 Verifying optimality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120<br />
9.2 Turn on logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120<br />
9.3 Writing task data to a file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121<br />
9.4 Important <strong>API</strong> limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121<br />
9.4.1 Thread safety . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121<br />
9.5 Bug reporting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121<br />
10 Problem formulation and solutions 123<br />
10.1 Linear optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123<br />
10.1.1 Duality for linear optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124<br />
10.1.2 Infeasibility for linear optimization . . . . . . . . . . . . . . . . . . . . . . . . . . 126<br />
10.2 Conic quadratic optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127<br />
10.2.1 Duality for conic quadratic optimization . . . . . . . . . . . . . . . . . . . . . . . 128<br />
10.2.2 Infeasibility for conic quadratic optimization . . . . . . . . . . . . . . . . . . . . 129<br />
10.3 Semidefinite optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130<br />
10.3.1 Duality for semidefinite optimization . . . . . . . . . . . . . . . . . . . . . . . . . 130<br />
10.3.2 Infeasibility for semidefinite optimization . . . . . . . . . . . . . . . . . . . . . . 131<br />
10.4 Quadratic and quadratically constrained optimization . . . . . . . . . . . . . . . . . . 132<br />
10.4.1 Duality for quadratic and quadratically constrained optimization . . . . . . . . . 132<br />
10.4.2 Infeasibility for quadratic and quadratically constrained optimization . . . . . . . 133<br />
11 <strong>The</strong> <strong>optimizer</strong>s for continuous problems 135<br />
11.1 How an <strong>optimizer</strong> works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135<br />
11.1.1 Presolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136<br />
11.1.2 Dualizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137<br />
11.1.3 Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138<br />
11.1.4 Using multiple threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138<br />
11.2 Linear optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138<br />
11.2.1 Optimizer selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138<br />
11.2.2 <strong>The</strong> interior-point <strong>optimizer</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139<br />
11.2.3 <strong>The</strong> simplex based <strong>optimizer</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144<br />
11.2.4 <strong>The</strong> interior-point or the simplex <strong>optimizer</strong>? . . . . . . . . . . . . . . . . . . . . . 145<br />
11.2.5 <strong>The</strong> primal or the dual simplex variant? . . . . . . . . . . . . . . . . . . . . . . . 145<br />
11.3 Linear network optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146<br />
11.3.1 Network flow problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146<br />
11.4 Conic optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146