root/trunk/openopt/scikits/openopt/examples/qp_1.py

Revision 1408, 0.8 KB (checked in by dmitrey.kroshko, 17 months ago)

qp2nlp converter + minor changes

Line 
1"""
2Example:
3Concider the problem
40.5 * (x1^2 + 2x2^2 + 3x3^2) + 15x1 + 8x2 + 80x3 -> min        (1)
5subjected to
6x1 + 2x2 + 3x3 <= 150            (2)
78x1 +  15x2 +  80x3 <= 800    (3)
8x2 - x3 = 25                              (4)
9x1 <= 15                                  (5)
10"""
11
12from numpy import diag, matrix, inf
13from scikits.openopt import QP
14p = 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])
16r = p.solve('cvxopt_qp', iprint = 0)
17# r = p.solve('nlp:ipopt'), r = p.solve('nlp:algencan')
18f_opt, x_opt = r.ff, r.xf
19# x_opt = array([-14.99999995,  -2.59999996, -27.59999991])
20# f_opt = -1191.90000013
Note: See TracBrowser for help on using the browser.