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.

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

1 #<br />

5.3.1.1 Source code<br />

[ cqo1.py ]<br />

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

3 #<br />

4 # File: cqo1.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<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 # We might write everything directly as a script, but it looks nicer<br />

30 # to create a function.<br />

31 def main ():<br />

32 # Make a <strong>MOSEK</strong> environment<br />

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

34 # Attach a printer to the environment<br />

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

36<br />

37 # Create a task<br />

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

39 # Attach a printer to the task<br />

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

41<br />

42 bkc = [ mosek.boundkey.fx ]<br />

43 blc = [ 1.0 ]<br />

44 buc = [ 1.0 ]<br />

45<br />

46 c = [ 0.0, 0.0, 0.0,<br />

47 1.0, 1.0, 1.0 ]<br />

48 bkx = [ mosek.boundkey.lo,mosek.boundkey.lo,mosek.boundkey.lo,<br />

49 mosek.boundkey.fr,mosek.boundkey.fr,mosek.boundkey.fr ]<br />

50 blx = [ 0.0, 0.0, 0.0,<br />

51 -inf, -inf, -inf ]<br />

52 bux = [ inf, inf, inf,<br />

53 inf, inf, inf ]<br />

54<br />

55 asub = [ array([0]), array([0]), array([0]) ]

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

Saved successfully!

Ooh no, something went wrong!