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.

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

76<br />

77 numvar = len(bkx)<br />

78 numcon = len(bkc)<br />

79<br />

80 # Append the constraints<br />

81 task.appendcons(numcon)<br />

82<br />

83 # Append the variables.<br />

84 task.appendvars(numvar)<br />

85<br />

86 # Input objective<br />

87 task.putcfix(0.0)<br />

88 task.putclist(csub,cval)<br />

89<br />

90 # Put constraint bounds<br />

91 task.putconboundslice(0, numcon, bkc, blc, buc)<br />

92<br />

93 # Put variable bounds<br />

94 task.putvarboundslice(0, numvar,bkx, blx, bux)<br />

95<br />

96 # Input A non-zeros by columns<br />

97 for j in range(numvar):<br />

98 ptrb,ptre = aptrb[j],aptre[j]<br />

99 task.putacol(j,<br />

100 asub[ptrb:ptre],<br />

101 acof[ptrb:ptre])<br />

102<br />

103 # Input the objective sense (minimize/maximize)<br />

104 task.putobjsense(mosek.objsense.maximize)<br />

105<br />

106<br />

107 # Optimize the task<br />

108 task.optimize()<br />

109<br />

110 # Output a solution<br />

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

112 task.getsolutionslice(mosek.soltype.bas,<br />

113 mosek.solitem.xx,<br />

114 0,numvar,<br />

115 xx)<br />

116 print ("xx =", [i for i in xx])<br />

5.10.2 Changing the A matrix<br />

Suppose we want to change the time required for assembly of product 0 to 3 minutes. This corresponds<br />

to setting a 0,0 = 3, which is done by calling the function Task.putaij as shown below.<br />

120 task.putaij(0, 0, 3.0)<br />

[ production.py ]<br />

<strong>The</strong> problem now has the form:

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

Saved successfully!

Ooh no, something went wrong!