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

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

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

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

Saved successfully!

Ooh no, something went wrong!