数学建模简单的说就是求最大化最小化问题,现在大学都有数学建模比赛,另外做科研的时候其实也经常用到。一般要么是用Lingo,要么是用matlab,其实AMPL是比较通用的描述及数学建模的语言,不过比较贵,记得我以前发神经买过一年的license花了我快2000块钱。
现在cplex或者ampl都有破解版的可以下到,不过毕竟不知道什么时候就不能用了,其实也有免费的软件可以用,glpk就可以解LP或者MIP的问题,而且还自带一个简单的模型描述语言,不过有时候要描述复杂一点的场景就有点不行了。
PULP是用python写的建模描述语言,自带的例子里面就带有column generation的例子,显然是比glpk自带的那个强不少,下面就用一个例子来说明一个简单建模的流程吧。
# Import PuLP modeler functions
from pulp import *
# A new LP problem
prob = LpProblem("test1", LpMinimize)
# Variables
# 0 <= x <= 4
x = LpVariable("x", 0, 4)
# -1 <= y <= 1
y = LpVariable("y", -1, 1)
# 0 <= z
z = LpVariable("z", 0)
# Use None for +/- Infinity, i.e. z <= 0 -> LpVariable("z", None, 0)
# Objective
prob += x + 4*y + 9*z, "obj"
# (the name at the end is facultative)
# Constraints
prob += x+y <= 5, "c1"
prob += x+z >= 10, "c2"
prob += -y+z == 7, "c3"
# (the names at the end are facultative)
# Write the problem as an LP file
prob.writeLP("test1.lp")
# Solve the problem using the default solver
prob.solve()
# Use prob.solve(GLPK()) instead to choose GLPK as the solver
# Use GLPK(msg = 0) to suppress GLPK messages
# If GLPK is not in your path and you lack the pulpGLPK module,
# replace GLPK() with GLPK("/path/")
# Where /path/ is the path to glpsol (excluding glpsol itself).
# If you want to use CPLEX, use CPLEX() instead of GLPK().
# If you want to use XPRESS, use XPRESS() instead of GLPK().
# If you want to use COIN, use COIN() instead of GLPK(). In this last case,
# two paths may be provided (one to clp, one to cbc).
# Print the status of the solved LP
print "Status:", LpStatus[prob.status]
# Print the value of the variables at the optimum
for v in prob.variables():
print v.name, "=", v.varValue
# Print the value of the objective
print "objective=", value(prob.objective)
分享到:
相关推荐
资源分类:Python库 所属语言:Python 资源全名:pulp_python-client-3.3.0.dev1618458733.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
PuLP是用Python编写的LP建模器。 PuLP可以生成MPS或LP文件,并调用 ,COIN-OR CLP / , , , , , , , 来解决线性问题。 安装 安装纸浆的最简单方法是通过 如果您的系统上有pip: python -m pip install pulp...
资源分类:Python库 所属语言:Python 资源全名:PuLP-1.5.1.zip 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:pulp_python-client-3.0.0b12.dev1598566289.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:pulp_python-client-3.6.0.dev1633059275.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源来自pypi官网。 资源全名:pulp_python-client-3.6.0.dev1639106886.tar.gz
Pulp Repo 带来了托管内部 puppet 存储库的能力(除其他外)(如 puppetforge 但没有漂亮的 Web 界面)。 快速开始 安装 禁用 在同一个机器上安装服务器、管理客户端和消费者: class { 'pulp': } # Install ...
资源分类:Python库 所属语言:Python 资源全名:pulp-2to3-migration-0.15.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:pulp_rpm-client-3.8.0.dev1602521314.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:pulp_python-client-3.7.0.dev1649650315.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:pulp_python-client-3.7.0.dev1647857394.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:pulp-smash-2017.3.31.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
python库。 资源全名:pulp_python-client-3.2.0.tar.gz
资源分类:Python库 所属语言:Python 使用前提:需要解压 资源全名:pulp_deb-2.12.1-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:pulp_rpm-client-3.0.0b71571591453.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
python库。 资源全名:pulp_python-client-3.3.0.dev1618890811.tar.gz
资源来自pypi官网。 资源全名:pulp_python-client-3.0.0b13.dev1610251280.tar.gz
python库。 资源全名:pulp_python-client-3.0.0b12.dev1601244520.tar.gz
python库。 资源全名:pulp_python-client-3.0.0b13.dev1608954229.tar.gz
Windows 7上安装pulp和glpk步骤: 亲测环境: Windows 6.1.7601 Service Pack 1 Build 7601 x64 Python 2.7.11 PuLP 1.6.8 GLPK 4.34 安装步骤: 1、下载PuLP安装包:前提是,已安装python2.6以及2.6以上版本,在...