| 1 | """ |
|---|
| 2 | Example: |
|---|
| 3 | Concider the problem |
|---|
| 4 | 0.5 * (x1^2 + 2x2^2 + 3x3^2) + 15x1 + 8x2 + 80x3 -> min (1) |
|---|
| 5 | subjected to |
|---|
| 6 | x1 + 2x2 + 3x3 <= 150 (2) |
|---|
| 7 | 8x1 + 15x2 + 80x3 <= 800 (3) |
|---|
| 8 | x2 - x3 = 25 (4) |
|---|
| 9 | x1 <= 15 (5) |
|---|
| 10 | """ |
|---|
| 11 | |
|---|
| 12 | from numpy import diag, matrix, inf |
|---|
| 13 | from scikits.openopt import QP |
|---|
| 14 | p = QP(diag([1,2,3]), [15,8,80], A = matrix('1 2 3; 8 15 80'), b = [150, 800], Aeq = [0, 1, -1], beq = 25, ub = [15,inf,inf]) |
|---|
| 15 | # or p = QP(H=diag([1,2,3]), f=[15,8,80], A = matrix('1 2 3; 8 15 80'), b = [150, 800], Aeq = [0, 1, -1], beq = 25, ub = [15,inf,inf]) |
|---|
| 16 | r = p.solve('cvxopt_qp', iprint = 0) |
|---|
| 17 | # r = p.solve('nlp:ipopt'), r = p.solve('nlp:algencan') |
|---|
| 18 | f_opt, x_opt = r.ff, r.xf |
|---|
| 19 | # x_opt = array([-14.99999995, -2.59999996, -27.59999991]) |
|---|
| 20 | # f_opt = -1191.90000013 |
|---|