|
Revision 1408, 0.8 kB
(checked in by dmitrey.kroshko, 2 months ago)
|
qp2nlp converter + minor changes
|
| 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 (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 |
|
|---|
| 16 |
r = p.solve('cvxopt_qp', iprint = 0) |
|---|
| 17 |
|
|---|
| 18 |
f_opt, x_opt = r.ff, r.xf |
|---|
| 19 |
|
|---|
| 20 |
|
|---|