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.

7.2. SOLVING LINEAR SYSTEMS INVOLVING THE BASIS MATRIX 95<br />

89<br />

90 ptrb = [ 0,1 ]<br />

91 ptre = [ 1,3 ]<br />

92<br />

93 #int[] bsub = new int[numvar];<br />

94 #double[] b = new double[numvar];<br />

95 #int[] basis = new int[numvar];<br />

96<br />

97<br />

98 with mosek.Env() as env:<br />

99 with mosek.Task(env) as task:<br />

100 # Directs the log task stream to the user specified<br />

101 # method task msg obj.streamCB<br />

102 task.set Stream(mosek.streamtype.log,<br />

103 lambda msg : sys.stdout.write(msg))<br />

104 # Put A matrix and factor A.<br />

105 # Call this function only once for a given task.<br />

106<br />

107 basis = [0] * numvar<br />

108 b = [ 0.0, -2.0 ]<br />

109 bsub = [ 0, 1 ]<br />

110<br />

111 put a(task,<br />

112 aval,<br />

113 asub,<br />

114 ptrb,<br />

115 ptre,<br />

116 numvar,<br />

117 basis)<br />

118<br />

119 # now solve rhs<br />

120 b = [ 1, -2]<br />

121 bsub = [ 0, 1 ]<br />

122 nz = task.solvewithbasis(0,2,bsub,b)<br />

123 print("\nSolution to Bx = b:\n")<br />

124<br />

125 # Print solution and show correspondents<br />

126 # to original variables in the problem<br />

127 for i in range(nz):<br />

128 if basis[bsub[i]] < numcon:<br />

129 print("This should never happen")<br />

130 else:<br />

131 print("x%d = %d" % (basis[bsub[i]] - numcon, b[bsub[i]]))<br />

132<br />

133 b[0] = 7<br />

134 bsub[0] = 0<br />

135<br />

136 nz = task.solvewithbasis(0,1,bsub,b);<br />

137<br />

138 print("\nSolution to Bx = b:\n")<br />

139 # Print solution and show correspondents<br />

140 # to original variables in the problem<br />

<strong>141</strong> for i in range(nz):<br />

142 if basis[bsub[i]] < numcon:<br />

143 print ("This should never happen")<br />

144 else:<br />

145 print ("x%d = %d" % (basis[bsub[i]] - numcon, b[bsub[i]] ))<br />

146

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

Saved successfully!

Ooh no, something went wrong!