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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

40 CHAPTER 5. BASIC <strong>API</strong> TUTORIAL<br />

and<br />

x 00 + x 11 + x 22 + x 0 = 1,<br />

x 00 + x 11 + x 22 + 2(x 10 + x 20 + x 21 ) + x 1 + x 2 = 1/2.<br />

5.4.1.1 Source code<br />

1 ##<br />

[ sdo1.py ]<br />

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

3 #<br />

4 # File: sdo1.py<br />

5 #<br />

6 # Purpose: Demonstrates how to solve a small mixed semidefinite and conic quadratic<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 import mosek<br />

12<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 value of infinity is ignored, we define it solely<br />

21 # for symbolic purposes<br />

22 inf = 0.0<br />

23<br />

24 # Define a stream printer to grab output from <strong>MOSEK</strong><br />

25 def streamprinter(text):<br />

26 sys.stdout.write(text)<br />

27 sys.stdout.flush()<br />

28<br />

29 def main ():<br />

30 # Make mosek environment<br />

31 env = mosek.Env()<br />

32<br />

33 # Create a task object and attach log stream printer<br />

34 task = env.Task(0,0)<br />

35 task.set Stream(mosek.streamtype.log, streamprinter)<br />

36<br />

37 # Bound keys for constraints<br />

38 bkc = [mosek.boundkey.fx,<br />

39 mosek.boundkey.fx]<br />

40<br />

41 # Bound values for constraints<br />

42 blc = [1.0, 0.5]<br />

43 buc = [1.0, 0.5]<br />

44<br />

45 # Below is the sparse representation of the A

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

Saved successfully!

Ooh no, something went wrong!