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.4. SEMIDEFINITE OPTIMIZATION 43<br />

162 except mosek.Exception as e:<br />

163 print ("ERROR: %s" % str(e.errno))<br />

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

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

166 sys.exit(1)<br />

167 except:<br />

168 import traceback<br />

169 traceback.print exc()<br />

170 sys.exit(1)<br />

171 sys.exit(0)<br />

5.4.1.2 Source code comments<br />

This example introduces several new functions. <strong>The</strong> first new function Task.appendbarvars is used<br />

to append the semidefinite variable:<br />

79 task.appendbarvars(BARVARDIM)<br />

[ sdo1.py ]<br />

Symmetric matrices are created using the function Task.appendsparsesymmat:<br />

103 symc = \<br />

104 task.appendsparsesymmat(BARVARDIM[0],<br />

105 barci,<br />

106 barcj,<br />

107 barcval)<br />

108<br />

109 syma0 = \<br />

110 task.appendsparsesymmat(BARVARDIM[0],<br />

111 barai[0],<br />

112 baraj[0],<br />

113 baraval[0])<br />

114<br />

115 syma1 = \<br />

116 task.appendsparsesymmat(BARVARDIM[0],<br />

117 barai[1],<br />

118 baraj[1],<br />

119 baraval[1])<br />

[ sdo1.py ]<br />

<strong>The</strong> second argument specifies the dimension of the symmetric variable and the third argument gives<br />

the number of non-zeros in the lower triangular part of the matrix. <strong>The</strong> next three arguments specify<br />

the non-zeros in the lower-triangle in triplet format, and the last argument will be updated with a<br />

unique index of the created symmetric matrix.<br />

After one or more symmetric matrices have been created using Task.appendsparsesymmat, we can<br />

combine them to setup a objective matrix coefficient c j using Task.putbarcj, which forms a linear<br />

combination of one more symmetric matrices:<br />

121 task.putbarcj(0, [symc], [1.0])<br />

[ sdo1.py ]

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

Saved successfully!

Ooh no, something went wrong!