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.

5.2. LINEAR OPTIMIZATION 29<br />

Optimization:<br />

After the problem is set-up the task can be optimized by calling the function Task.optimize.<br />

[ lo1.py ]<br />

105 task.optimize()<br />

Extracting the solution.<br />

After optimizing the status of the solution is examined with a call to Task.getsolsta. If the<br />

solution status is reported as solsta.optimal or solsta.near optimal the solution is extracted<br />

in the lines below:<br />

[ lo1.py ]<br />

116 xx = zeros(numvar, float)<br />

117 task.getxx(mosek.soltype.bas, # Request the basic solution.<br />

118 xx)<br />

<strong>The</strong> Task.getxx function obtains the solution. <strong>MOSEK</strong> may compute several solutions depending<br />

on the <strong>optimizer</strong> employed. In this example the basic solution is requested by setting the<br />

first argument to soltype.bas.<br />

1 #<br />

5.2.1.2 Source code for lo1<br />

[ lo1.py ]<br />

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

3 #<br />

4 # File: lo1.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 from future import with statement<br />

10<br />

11 import sys<br />

12 import mosek<br />

13<br />

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

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

16 try:<br />

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

18 except ImportError:<br />

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

20<br />

21 # Since the value of infinity is ignored, we define it solely<br />

22 # for symbolic purposes<br />

23 inf = 0.0<br />

24<br />

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

26 def streamprinter(text):<br />

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

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

29

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

Saved successfully!

Ooh no, something went wrong!