Revision 1039, 0.6 kB (checked in by dmitrey, 4 months ago) |
OO examples: changes toward Python3 compatibility
|
Line |
|
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.5 (4) |
9 |
x1 <= 15 (5) |
10 |
""" |
11 |
|
12 |
from numpy import diag, matrix, inf |
13 |
from 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.5, ub = [15,inf,inf]) |
15 |
# or p = QP(H=diag([1,2,3]), f=[15,8,80], A= ...) |
16 |
r = p._solve('cvxopt_qp', iprint = 0) |
17 |
f_opt, x_opt = r.ff, r.xf |
18 |
# x_opt = array([-15. , -2.5, -28. ]) |
19 |
# f_opt = -1190.25 |