root/PythonPackages/OpenOpt/openopt/examples/lp_1.py

Revision 1070, 1.2 kB (checked in by dmitrey, 4 months ago)

minor oo example change

Line  
1 """
2 Example:
3 Let's concider the problem
4 15x1 + 8x2 + 80x3 -> min        (1)
5 subjected to
6 x1 + 2x2 + 3x3 <= 15              (2)
7 8x1 +  15x2 +  80x3 <= 80      (3)
8 8x1  + 80x2 + 15x3 <=150      (4)
9 100x1 +  10x2 + x3 >= 800     (5)
10 80x1 + 8x2 + 15x3 = 750         (6)
11 x1 + 10x2 + 100x3 = 80           (7)
12 x1 >= 4                                     (8)
13 -8 >= x2 >= -80                        (9)
14 """
15
16 from numpy import *
17 from openopt import LP
18 f = array([15,8,80])
19 A = mat('1 2 3; 8 15 80; 8 80 15; -100 -10 -1') # numpy.ndarray is also allowed
20 b = [15, 80, 150, -800] # numpy.ndarray, matrix etc are also allowed
21 Aeq = mat('80 8 15; 1 10 100') # numpy.ndarray is also allowed
22 beq = (750, 80)
23
24 lb = [4, -80, -inf]
25 ub = [inf, -8, inf]
26 p = LP(f, A=A, Aeq=Aeq, b=b, beq=beq, lb=lb, ub=ub)
27 #or p = LP(f=f, A=A, Aeq=Aeq, b=b, beq=beq, lb=lb, ub=ub)
28
29 #r = p.minimize('glpk') # CVXOPT must be installed
30 #r = p.minimize('lpSolve') # lpsolve must be installed
31 r = p.minimize('pclp')
32 #search for max: r = p.maximize('glpk') # CVXOPT & glpk must be installed
33 #r = p.minimize('nlp:ralg', ftol=1e-7, xtol=1e-7, goal='min', plot=1)
34
35 print('objFunValue: %f' % r.ff) # should print 204.48841578
36 print('x_opt: %s' % r.xf) # should print [ 9.89355041 -8.          1.5010645 ]
Note: See TracBrowser for help on using the browser.