The MOSEK Python optimizer API manual Version 7.0 (Revision 141)

Optimizer API for Python - Documentation - Mosek Optimizer API for Python - Documentation - Mosek

25.11.2015 Views

194 CHAPTER 15. SENSITIVITY ANALYSIS 83 1.0,1.0,1.0,1.0,1.0,1.0,1.0 ] 84 85 numcon = len(bkc) 86 numvar = len(bkx) 87 numanz = len(val) 88 89 # Input linear data 90 task.inputdata(numcon,numvar, 91 c,0.0, 92 ptrb, ptre, sub, val, 93 bkc, blc, buc, 94 bkx, blx, bux) 95 # Set objective sense 96 task.putobjsense(mosek.objsense.minimize) 97 98 # Optimize 99 task.optimize(); 100 101 # Analyze upper bound on c1 and the equality constraint on c4 102 subi = [ 0, 3 ] 103 marki = [ mosek.mark.up, mosek.mark.up ] 104 105 # Analyze lower bound on the variables x12 and x31 106 subj = [ 1, 4 ] 107 markj = [ mosek.mark.lo, mosek.mark.lo ] 108 109 leftpricei = zeros(2,float) 110 rightpricei = zeros(2,float) 111 leftrangei = zeros(2,float) 112 rightrangei = zeros(2,float) 113 leftpricej = zeros(2,float) 114 rightpricej = zeros(2,float) 115 leftrangej = zeros(2,float) 116 rightrangej = zeros(2,float) 117 118 119 task.primalsensitivity( subi, 120 marki, 121 subj, 122 markj, 123 leftpricei, 124 rightpricei, 125 leftrangei, 126 rightrangei, 127 leftpricej, 128 rightpricej, 129 leftrangej, 130 rightrangej) 131 132 print (’Results from sensitivity analysis on bounds:’) 133 print (’\tleftprice | rightprice | leftrange | rightrange ’ ) 134 print (’For constraints:’) 135 136 for i in range(2): 137 print (’\t%10f %10f %10f %10f’ % (leftpricei[i], 138 rightpricei[i], 139 leftrangei[i], 140 rightrangei[i]))

15.6. SENSITIVITY ANALYSIS WITH THE COMMAND LINE TOOL 195 141 142 print (’For variables:’) 143 for i in range(2): 144 print (’\t%10f %10f %10f %10f’ % (leftpricej[i], 145 rightpricej[i], 146 leftrangej[i], 147 rightrangej[i])) 148 149 150 leftprice = zeros(2,float) 151 rightprice = zeros(2,float) 152 leftrange = zeros(2,float) 153 rightrange = zeros(2,float) 154 subc = array([ 2, 5 ]) 155 156 task.dualsensitivity( subc, 157 leftprice, 158 rightprice, 159 leftrange, 160 rightrange) 161 162 print (’Results from sensitivity analysis on objective coefficients:’) 163 164 for i in range(2): 165 print (’\t%10f %10f %10f %10f’ % (leftprice[i], 166 rightprice[i], 167 leftrange[i], 168 rightrange[i])) 169 170 return None 171 172 # call the main function 173 try: 174 main () 175 except mosek.Exception as e: 176 print ("ERROR: %s" % str(e.errno)) 177 if e.msg is not None: 178 print ("\t%s" % e.msg) 179 sys.exit(1) 180 except: 181 import traceback 182 traceback.print exc() 183 sys.exit(1) 15.6 Sensitivity analysis with the command line tool A sensitivity analysis can be performed with the MOSEK command line tool using the command mosek myproblem.mps -sen sensitivity.ssp where sensitivity.ssp is a file in the format described in the next section. The ssp file describes which parts of the problem the sensitivity analysis should be performed on. By default results are written to a file named myproblem.sen. If necessary, this filename can be

15.6. SENSITIVITY ANALYSIS WITH THE COMMAND LINE TOOL 195<br />

<strong>141</strong><br />

142 print (’For variables:’)<br />

143 for i in range(2):<br />

144 print (’\t%10f %10f %10f %10f’ % (leftpricej[i],<br />

145 rightpricej[i],<br />

146 leftrangej[i],<br />

147 rightrangej[i]))<br />

148<br />

149<br />

150 leftprice = zeros(2,float)<br />

151 rightprice = zeros(2,float)<br />

152 leftrange = zeros(2,float)<br />

153 rightrange = zeros(2,float)<br />

154 subc = array([ 2, 5 ])<br />

155<br />

156 task.dualsensitivity( subc,<br />

157 leftprice,<br />

158 rightprice,<br />

159 leftrange,<br />

160 rightrange)<br />

161<br />

162 print (’Results from sensitivity analysis on objective coefficients:’)<br />

163<br />

164 for i in range(2):<br />

165 print (’\t%10f %10f %10f %10f’ % (leftprice[i],<br />

166 rightprice[i],<br />

167 leftrange[i],<br />

168 rightrange[i]))<br />

169<br />

170 return None<br />

171<br />

172 # call the main function<br />

173 try:<br />

174 main ()<br />

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

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

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

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

179 sys.exit(1)<br />

180 except:<br />

181 import traceback<br />

182 traceback.print exc()<br />

183 sys.exit(1)<br />

15.6 Sensitivity analysis with the command line tool<br />

A sensitivity analysis can be performed with the <strong>MOSEK</strong> command line tool using the command<br />

mosek myproblem.mps -sen sensitivity.ssp<br />

where sensitivity.ssp is a file in the format described in the next section. <strong>The</strong> ssp file describes<br />

which parts of the problem the sensitivity analysis should be performed on.<br />

By default results are written to a file named myproblem.sen.<br />

If necessary, this filename can be

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

Saved successfully!

Ooh no, something went wrong!