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.

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

Bound key Type of bound Lower bound Upper bound<br />

boundkey.fx · · · = l j Finite Identical to the lower bound<br />

boundkey.fr Free Minus infinity Plus infinity<br />

boundkey.lo l j ≤ · · · Finite Plus infinity<br />

boundkey.ra l j ≤ · · · ≤ u j Finite Finite<br />

boundkey.up · · · ≤ u j Minus infinity Finite<br />

Table 5.1: Interpretation of the bound keys.<br />

Recall that in our example the A matrix is given by<br />

A =<br />

⎡<br />

⎣ 3 1 2 0<br />

2 1 3 1<br />

0 2 0 3<br />

This matrix is stored in sparse format in the arrays:<br />

62 asub = [ array([0, 1]),<br />

63 array([0, 1, 2]),<br />

64 array([0, 1]),<br />

65 array([1, 2])]<br />

66 aval = [ array([3.0, 2.0]),<br />

67 array([1.0, 1.0, 2.0]),<br />

68 array([2.0, 3.0]),<br />

69 array([1.0, 3.0]) ]<br />

[ lo1.py ]<br />

⎤<br />

⎦ .<br />

<strong>The</strong> array aval[j] contains the non-zero values of column j and asub[j] contains the row index<br />

of these non-zeros.<br />

Using the function Task.putacol we set column j of A<br />

[ lo1.py ]<br />

91 task.putacol(j, # Variable (column) index.<br />

92 asub[j], # Row index of non-zeros in column j.<br />

93 aval[j]) # Non-zero Values of column j.<br />

Alternatively, the same A matrix can be set one row at a time; please see section 5.2.2 for an<br />

example.<br />

Finally, the bounds on each constraint are set by looping over each constraint index i = 0, . . . , numcon−<br />

1<br />

[ lo1.py ]<br />

95 # Set the bounds on constraints.<br />

96 # blc[i]

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

Saved successfully!

Ooh no, something went wrong!