Changeset 950 for trunk/openopt/scikits/openopt/examples/milp_1.py
- Timestamp:
- 04/29/08 10:47:33 (7 months ago)
- Files:
-
- trunk/openopt/scikits/openopt/examples/milp_1.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openopt/scikits/openopt/examples/milp_1.py
r595 r950 5 5 6 6 f = [1, 2, 3, 4, 5, 4, 2, 1] 7 intVars = [5, 8] 8 lb = 1.5 * ones([8,1]) 7 8 # indexing starts from ZERO! 9 # while in native lpsolve-python wrapper from 1 10 # so if you used [5,8] for native lp_solve python binding 11 # you should use [4,7] instead 12 intVars = [4, 7] 13 14 lb = -1.5 * ones([8,1]) 15 ub = 15 * ones([8,1]) 9 16 A = zeros((5, 8)) 10 17 b = zeros(5) … … 14 21 b[i] = -150 + 80*sin(80*i) 15 22 16 p = MILP(f=f, intVars=intVars, lb=lb, A=A, b=b)23 p = MILP(f=f, lb=lb, ub=ub, A=A, b=b, intVars=intVars) 17 24 r = p.solve('lpSolve') 25 print 'f_opt:', r.ff # 25.801450769161505 26 print 'x_opt:', r.xf # [ 15. 10.15072538 -1.5 -1.5 -1. -1.5 -1.5 15.] 18 27 19 print 'f_opt:', r.ff # 55.05 20 print 'x_opt:' 21 print r.xf # [1.54923517 1.5 1.5 1.5 2. 1.5 1.5 21.] 28 """ 29 if you have installed glpk+cvxopt 1.0 or later 30 (with BUILD_GLPK=1 in setup.py file) 31 you can handle MILP problems with binary constraints 32 (coords x from p.binVars should be in {0, 1}): 33 34 p = MILP(f=f, lb=lb, ub=ub, A=A, b=b, intVars=intVars, binVars=[1]) 35 #intVars, binVars indexing from ZERO! 36 r = p.solve('glpk') 37 38 print 'f_opt:', r.ff # 26.566058805272387 39 print 'x_opt:', r.xf # [15. 1. -1.5 -1.5 -1. -1.5 8.0330294 15.] 40 """
