25.11.2015 Views

The MOSEK Python optimizer API manual Version 7.0 (Revision 141)

Optimizer API for Python - Documentation - Mosek

Optimizer API for Python - Documentation - Mosek

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.5. QUADRATIC OPTIMIZATION 49<br />

5.5.2 Example: Quadratic constraints<br />

In this section describes how to solve a problem with quadratic constraints. Please note that quadratic<br />

constraints are subject to the convexity requirement (5.8).<br />

Consider the problem:<br />

This is equivalent to<br />

minimize x 2 1 + 0.1x 2 2 + x 2 3 − x 1 x 3 − x 2<br />

subject to 1 ≤ x 1 + x 2 + x 3 − x 2 1 − x 2 2 − 0.1x 2 3 + 0.2x 1 x 3 ,<br />

x ≥ 0.<br />

where<br />

⎡<br />

Q o = ⎣<br />

minimize 1/2x T Q o x + c T x<br />

subject to 1/2x T Q 0 x + Ax ≥ b,<br />

2 0 − 1<br />

0 0.2 0<br />

− 1 0 2<br />

Q 0 =<br />

⎤<br />

⎡<br />

⎦ , c = ⎣<br />

⎡<br />

0<br />

− 1<br />

0<br />

⎤<br />

⎣ − 2 0 0.2<br />

0 − 2 0<br />

0.2 0 − 0.2<br />

⎦ , A = [ 1 1 1 ] , b = 1.<br />

⎤<br />

⎦ .<br />

1 #<br />

5.5.2.1 Source code<br />

[ qcqo1.py ]<br />

2 # Copyright: Copyright (c) <strong>MOSEK</strong> ApS, Denmark. All rights reserved.<br />

3 #<br />

4 # File: qcqo1.py<br />

5 #<br />

6 # Purpose: Demonstrates how to solve small linear<br />

7 # optimization problem using the <strong>MOSEK</strong> <strong>Python</strong> <strong>API</strong>.<br />

8 ##<br />

9<br />

10 import sys<br />

11<br />

12 import mosek<br />

13 # If numpy is installed, use that, otherwise use the<br />

14 # Mosek’s array module.<br />

15 try:<br />

16 from numpy import array,zeros,ones<br />

17 except ImportError:<br />

18 from mosek.array import array, zeros, ones<br />

19<br />

20 # Since the actual value of Infinity is ignores, we define it solely<br />

21 # for symbolic purposes:<br />

22 inf = 0.0

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

Saved successfully!

Ooh no, something went wrong!