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.

8.1. PORTFOLIO OPTIMIZATION 105<br />

63 task.putvarboundlist(range(offsetx+0,offsetx+n),n*[mosek.boundkey.lo],n*[0.0],n*[inf])<br />

64 for j in range(0,n):<br />

65 task.putvarname(offsetx+j,"x[%d]" % (1+j))<br />

sets up the data for x variables. For instance<br />

[ case portfolio 1.py ]<br />

58 task.putclist(range(offsetx+0,offsetx+n),mu)<br />

inputs the objective coefficients for the x variables. Moreover, the code<br />

[ case portfolio 1.py ]<br />

64 for j in range(0,n):<br />

65 task.putvarname(offsetx+j,"x[%d]" % (1+j))<br />

assigns meaningful names to the <strong>API</strong> variables. This is not needed but it makes debugging easier.<br />

8.1.2.3 Debugging tips<br />

Implementing an optimization model in <strong>optimizer</strong> can be cumbersome and error-prone and it is very<br />

easy to make mistakes. In order to check the implemented code for mistakes it is very useful to dump<br />

the problem to a file in a human readable form for visual inspection. <strong>The</strong> line<br />

86 #task.writedata("dump.opf")<br />

[ case portfolio 1.py ]<br />

does that and this will produce a file with the content<br />

[comment]<br />

Written by <strong>MOSEK</strong> version <strong>7.0</strong>.0.86<br />

Date 01-10-13<br />

Time 08:15:47<br />

[/comment]<br />

[hints]<br />

[hint NUMVAR] 7 [/hint]<br />

[hint NUMCON] 4 [/hint]<br />

[hint NUMANZ] 12 [/hint]<br />

[hint NUMQNZ] 0 [/hint]<br />

[hint NUMCONE] 1 [/hint]<br />

[/hints]<br />

[variables disallow new variables]<br />

’x[1]’ ’x[2]’ ’x[3]’ s ’t[1]’<br />

’t[2]’ ’t[3]’<br />

[/variables]<br />

[objective maximize]<br />

1.073e-001 ’x[1]’ + 7.37e-002 ’x[2]’ + 6.270000000000001e-002 ’x[3]’<br />

[/objective]<br />

[constraints]<br />

[con ’budget’]<br />

’x[1]’ + ’x[2]’ + ’x[3]’ = 1e+000 [/con]

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

Saved successfully!

Ooh no, something went wrong!