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 63<br />

Denoting the number of items of each type by x 0 , x 1 and x 2 , this problem can be formulated as the<br />

linear optimization problem:<br />

and<br />

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

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

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

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

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

<strong>The</strong> following code loads this problem into the optimization task.<br />

35 # Create a <strong>MOSEK</strong> environment<br />

36 env = mosek.Env ()<br />

37<br />

[ production.py ]<br />

38 # Create a task<br />

39 task = env.Task(0,0)<br />

40 # Attach a printer to the task<br />

41 task.set Stream (mosek.streamtype.log, streamprinter)<br />

42<br />

43 # Bound keys for constraints<br />

44 bkc = [mosek.boundkey.up,<br />

45 mosek.boundkey.up,<br />

46 mosek.boundkey.up]<br />

47 # Bound values for constraints<br />

48 blc = array ([-inf, -inf, -inf])<br />

49 buc = array ([100000.0 , 50000.0, 60000.0])<br />

50<br />

51 # Bound keys for variables<br />

52 bkx = [mosek.boundkey.lo,<br />

53 mosek.boundkey.lo,<br />

54 mosek.boundkey.lo]<br />

55 # Bound values for variables<br />

56 blx = array ([ 0.0, 0.0, 0.0])<br />

57 bux = array ([+inf, +inf, +inf])<br />

58<br />

59 # Objective coefficients<br />

60 csub = array([ 0, 1, 2 ])<br />

61 cval = array([ 1.5, 2.5, 3.0 ])<br />

62<br />

63 # We input the A matrix column-wise<br />

64 # asub contains row indexes<br />

65 asub = array([ 0, 1, 2,<br />

66 0, 1, 2,<br />

67 0, 1, 2])<br />

68 # acof contains coefficients<br />

69 acof = array([ 2.0, 3.0, 2.0,<br />

70 4.0, 2.0, 3.0,<br />

71 3.0, 3.0, 2.0 ])<br />

72 # aptrb and aptre contains the offsets into asub and acof where<br />

73 # columns start and end respectively<br />

74 aptrb = array([ 0, 3, 6 ])<br />

75 aptre = array([ 3, 6, 9 ])

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

Saved successfully!

Ooh no, something went wrong!