Show
Ignore:
Timestamp:
04/29/08 10:47:33 (7 months ago)
Author:
dmitrey.kroshko
Message:

some changes, some updates in docstrings + add glpk MILP solver

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openopt/scikits/openopt/examples/milp_1.py

    r595 r950  
    55 
    66f = [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 
     12intVars = [4, 7] 
     13 
     14lb = -1.5 * ones([8,1]) 
     15ub = 15 * ones([8,1]) 
    916A = zeros((5, 8)) 
    1017b = zeros(5) 
     
    1421    b[i] = -150 + 80*sin(80*i) 
    1522 
    16 p = MILP(f=f, intVars=intVars, lb=lb, A=A, b=b
     23p = MILP(f=f, lb=lb, ub=ub, A=A, b=b, intVars=intVars
    1724r = p.solve('lpSolve') 
     25print 'f_opt:', r.ff # 25.801450769161505 
     26print 'x_opt:', r.xf # [ 15. 10.15072538 -1.5 -1.5 -1.  -1.5 -1.5 15.] 
    1827 
    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""" 
     29if you have installed glpk+cvxopt 1.0 or later  
     30(with BUILD_GLPK=1 in setup.py file)  
     31you can handle MILP problems with binary constraints  
     32(coords x from p.binVars should be in {0, 1}): 
     33 
     34p = MILP(f=f, lb=lb, ub=ub, A=A, b=b, intVars=intVars, binVars=[1]) 
     35#intVars, binVars indexing from ZERO! 
     36r = p.solve('glpk')  
     37 
     38print 'f_opt:', r.ff # 26.566058805272387 
     39print 'x_opt:', r.xf # [15.  1.  -1.5 -1.5 -1. -1.5 8.0330294 15.] 
     40"""