用python-pulp解决线性规划问题
来源:互联网 发布:矩阵型组织结构 编辑:程序博客网 时间:2024/05/16 11:50
Linux环境下,要是用python的pulp进行线性规划
需要先安装
1、pulp
直接终端输入:$ easy_install pulp
(注:若无easy_install 则终端输入 $ sudo apt-get install python-setuptools)
2、调试安装glpk
最常见的是:直接终端输入$ sudo apt-get install glpk
若不行:点击打开链接
尔后就可以模仿着写出python代码
from pulp import *#对象sum = LpProblem('money', LpMinimize)x11 = LpVariable('x11', lowBound = 0)x12 = LpVariable('x12', lowBound = 0)x13 = LpVariable('x13', lowBound = 0)x14 = LpVariable('x14', lowBound = 0)x15 = LpVariable('x15', lowBound = 0)x16 = LpVariable('x16', lowBound = 0)x10 = LpVariable('x10', lowBound = 0)y11 = LpVariable('y11', lowBound = 0)y12 = LpVariable('y12', lowBound = 0)y13 = LpVariable('y13', lowBound = 0)y14 = LpVariable('y14', lowBound = 0)y15 = LpVariable('y15', lowBound = 0)y16 = LpVariable('y16', lowBound = 0)y10 = LpVariable('y10', lowBound = 0)x22 = LpVariable('x22', lowBound = 0)x23 = LpVariable('x23', lowBound = 0)x24 = LpVariable('x24', lowBound = 0)x25 = LpVariable('x25', lowBound = 0)x26 = LpVariable('x26', lowBound = 0)x20 = LpVariable('x20', lowBound = 0)y22 = LpVariable('y22', lowBound = 0)y23 = LpVariable('y23', lowBound = 0)y24 = LpVariable('y24', lowBound = 0)y25 = LpVariable('y25', lowBound = 0)y26 = LpVariable('y26', lowBound = 0)y20 = LpVariable('y20', lowBound = 0)x33 = LpVariable('x33', lowBound = 0)x34 = LpVariable('x34', lowBound = 0)x35 = LpVariable('x35', lowBound = 0)x36 = LpVariable('x36', lowBound = 0)x30 = LpVariable('x30', lowBound = 0)y33 = LpVariable('y33', lowBound = 0)y34 = LpVariable('y34', lowBound = 0)y35 = LpVariable('y35', lowBound = 0)y36 = LpVariable('y36', lowBound = 0)y30 = LpVariable('y30', lowBound = 0)x44 = LpVariable('x44', lowBound = 0)x45 = LpVariable('x45', lowBound = 0)x46 = LpVariable('x46', lowBound = 0)x40 = LpVariable('x40', lowBound = 0)y44 = LpVariable('y44', lowBound = 0)y45 = LpVariable('y45', lowBound = 0)y46 = LpVariable('y46', lowBound = 0)y40 = LpVariable('y40', lowBound = 0)x55 = LpVariable('x55', lowBound = 0)x56 = LpVariable('x56', lowBound = 0)x50 = LpVariable('x50', lowBound = 0)y55 = LpVariable('y55', lowBound = 0)y56 = LpVariable('y56', lowBound = 0)y50 = LpVariable('y50', lowBound = 0)x66 = LpVariable('x66', lowBound = 0)x60 = LpVariable('x60', lowBound = 0)y66 = LpVariable('y66', lowBound = 0)y60 = LpVariable('y60', lowBound = 0)s1 = LpVariable('s1', lowBound = 0)s2 = LpVariable('s2', lowBound = 0)s3 = LpVariable('s3', lowBound = 0)s4 = LpVariable('s4', lowBound = 0)s5 = LpVariable('s5', lowBound = 0)s6 = LpVariable('s6', lowBound = 0)s0 = LpVariable('s0', lowBound = 0)# 载入约束变量sum += 15*x11+15.3*x12+15.5*x13+15.7*x14+15.9*x15+16.1*x16 +16*y11+16.3*y12+16.5*y13+16.7*y14+16.9*y15+17.1*y16 +14*x22+14.3*x23+14.5*x24+14.7*x25+14.9*x26 +15*y22+15.3*y23+15.5*y24+15.7*y25+15.9*y26 +13.5*x33+13.8*x34+14*x35+14.2*x36 +14.5*y33+14.8*y34+15*y35+15.2*y36 +13*x44+13.3*x45+13.5*x46 +14*y44+14.3*y45+14.5*y46 +13*x55+13.3*x56 +14*y55+14.3*y56 +13.5*x66 +14.5*y66sum += x11+x12+x13+x14+x15+x16+x10 ==60sum += y11+y12+y13+y14+y15+y16+y10 ==10sum += x22+x23+x24+x25+x26+x20 ==50sum += y22+y23+y24+y25+y26+y20 ==10sum += x33+x34+x35+x36+x30 ==90sum += y33+y34+y35+y36+y30 ==20sum += x44+x45+x46+x40 ==100sum += y44+y45+y46+y40 ==40sum += x55+x56+x50 ==100sum += y55+y56+y50 ==40sum += x66+x60 ==80sum += y66+y60 ==40sum += s1+s2+s3+s4+s5+s6+s0 ==103sum += x11+y11+s1 == 104sum += x12+x22+y12+y22+s2 == 75sum += x13+x23+x33+y13+y23+y33+s3 == 115sum += x14+x24+x34+x44+y14+y24+y34+y44+s4 == 160sum += x15+x25+x35+x45+x55+y15+y25+y35+y45+y55+s5 == 103sum += x16+x26+x36+x46+x56+x66+y16+y26+y36+y46+y56+y66+s6 == 150sum += x10+x20+x30+x40+x50+x60+y10+y20+y30+y40+y50+y60+s0 == 36# 求解GLPK().solve(sum)# 显示结果for i in sum.variables(): print(i.name + "=" + str(i.varValue))
问题:
总结不足:初涉python,代码过于冗长
0 0
- 用python-pulp解决线性规划问题
- 用Python的pulp解决线性规划问题
- 线性规划的python的pulp包
- 用python pulp的线性规划方法计算满足营养所需的最少食物
- 用lingo12解决线性规划问题
- 使用python-pymprog模块解决线性规划的问题
- 算法实验之线性规划解决配料问题
- 用 Octave 求解线性规划问题
- Python PuLP and Glpk 安装步骤
- Python中使用pulp进行线性规范计算
- matlab和Python线性规划
- python求线性规划
- 关于matlab 线性规划问题
- matlab求解线性规划问题
- 线性规划求解路径问题
- matlab 求解线性规划问题
- JZOJ5259. 线性规划问题
- matlab指派问题 线性规划
- JDBC的几种封装
- bad_weak_ptr的原因
- iOS开发抠psd文件中的图
- socket函数send和recv函数
- ffmpeg基础知识
- 用python-pulp解决线性规划问题
- web.xml配置,避免乱码
- 解决:Xvfb 缺少cyrillic 100dpi 75dpi 100dpi 75dpi
- LeedCode 之 Plus One
- PHPword 表格内换行处理
- STL:set详解
- Joint Face Detection and Alignment Using Multi-task Cascade Convolutional Networks笔记
- mybatis generator xml配置模板
- [Leetcode] #343 Integer Break (DP)