python的一个线性规划库 - pulp

代码
http://code.google.com/p/pulp-or/

文档
http://130.216.209.237/engsci392/pulp/OptimisationWithPuLP


还要安装glpk , arch linux用yaourt 可以安装

代码比较久远了,要改一改

$ sudo vi /usr/lib/python2.6/site-packages/pulp/solvers.py

300行左右,修改成
        proc = ["glpsol", "--cpxlp", tmpLp, "-o", tmpSol]


________________________________________________________________

from pulp import *
prob = LpProblem("horse", LpMinimize)
x = LpVariable("x", 0 , None, LpInteger)
y = LpVariable("y", 0 , None,LpInteger )
z = LpVariable("z", 0 , None,LpInteger)

prob += x+y+z == 100, "c1"
prob += x*3+y*2+z*0.5 == 100, "c2"

prob.writeLP("horse.lp")

prob.solve(GLPK())

print "Status:", LpStatus[prob.status]

for v in prob.variables():
    print v.name, "=", v.varValue

结果
x = 20
y = 0
z = 80
注意,有时候会变成,其实一样
y = 0
x = 20
z = 80


你可能感兴趣的:(linux,python,Google)