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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.10. PROBLEM MODIFICATION AND REOPTIMIZATION 65<br />

and<br />

maximize 1.5x 0 + 2.5x 1 + 3.0x 2<br />

subject to 3x 0 + 4x 1 + 3x 2 ≤ 100000,<br />

3x 0 + 2x 1 + 3x 2 ≤ 50000,<br />

2x 0 + 3x 1 + 2x 2 ≤ 60000,<br />

(5.11)<br />

x 0 , x 1 , x 2 ≥ 0.<br />

After changing the A matrix we can find the new optimal solution by calling<br />

Task.optimize again.<br />

5.10.3 Appending variables<br />

We now want to add a new product with the following data:<br />

Product no. Assembly (minutes) Polishing (minutes) Packing (minutes) Profit ($)<br />

3 4 0 1 1.00<br />

This corresponds to creating a new variable x 3 , appending a new column to the A matrix and setting<br />

a new value in the objective. We do this in the following code.<br />

[ production.py ]<br />

122 # Append a new varaible x 3 to the problem */<br />

123 task.appendvars(1)<br />

124<br />

125 # Set bounds on new varaible<br />

126 task.putbound(mosek.accmode.var,<br />

127 task.getnumvar()-1,<br />

128 mosek.boundkey.lo,<br />

129 0,<br />

130 +inf)<br />

131<br />

132 # Change objective<br />

133 task.putcj(task.getnumvar()-1,1.0)<br />

134<br />

135 # Put new values in the A matrix<br />

136 acolsub = array([0, 2])<br />

137 acolval = array([4.0, 1.0])<br />

138<br />

139 task.putacol(task.getnumvar()-1, # column index<br />

140 acolsub,<br />

<strong>141</strong> acolval)<br />

After this operation the problem looks this way:<br />

maximize 1.5x 0 + 2.5x 1 + 3.0x 2 + 1.0x 3<br />

subject to 3x 0 + 4x 1 + 3x 2 + 4x 3 ≤ 100000,<br />

3x 0 + 2x 1 + 3x 2 ≤ 50000,<br />

2x 0 + 3x 1 + 2x 2 + 1x 3 ≤ 60000,<br />

(5.12)

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

Saved successfully!

Ooh no, something went wrong!