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.

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

126 if e.msg is not None:<br />

127 import traceback<br />

128 traceback.print exc()<br />

129 print ("\t%s" % e.msg)<br />

130 sys.exit(1)<br />

131 except:<br />

132 import traceback<br />

133 traceback.print exc()<br />

134 sys.exit(1)<br />

135 print ("Finished OK")<br />

136 sys.exit(0)<br />

5.5.1.2 Example code comments<br />

Most of the functionality in this example has already been explained for the linear optimization example<br />

in Section 5.2 and it will not be repeated here.<br />

This example introduces one new function, Task.putqobj, which is used to input the quadratic terms<br />

of the objective function.<br />

Since Q o is symmetric only the lower triangular part of Q o is inputted.<br />

computed by <strong>MOSEK</strong> using the relation<br />

<strong>The</strong> upper part of Q o is<br />

Q o ij = Q o ji.<br />

Entries from the upper part may not appear in the input.<br />

<strong>The</strong> lower triangular part of the matrix Q o is specified using an unordered sparse triplet format (for<br />

details, see Section 5.13.3):<br />

84 qsubi = [ 0, 1, 2, 2 ]<br />

85 qsubj = [ 0, 1, 0, 2 ]<br />

86 qval = [ 2.0, 0.2, -1.0, 2.0 ]<br />

[ qo1.py ]<br />

Please note that<br />

• only non-zero elements are specified (any element not specified is 0 by definition),<br />

• the order of the non-zero elements is insignificant, and<br />

• only the lower triangular part should be specified.<br />

Finally, the matrix Q o is loaded into the task:<br />

88 task.putqobj(qsubi,qsubj,qval)<br />

[ qo1.py ]

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

Saved successfully!

Ooh no, something went wrong!