问题标签 [pulp]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
3973 浏览

python - testing pulp installation fails

Following instructions from http://www.coin-or.org/PuLP/main/installing_pulp_at_home.html#installation , I installed PuLP using "Windows Installation from source"

When I tried to run the test on the page ( Instructions on the page : "To test that that you pulp installation is working correctly please type the following into a python interpreter and note that the output should be similar. The output below is what you would expect if you have not installed any other solvers and the CoinMP solver bundled with pulp works.")

My Results :

import pulp pulp.pulpTestAll() Solver pulp.solvers.CPLEX_DLL unavailable. Solver pulp.solvers.CPLEX_CMD unavailable. Solver pulp.solvers.COIN_CMD unavailable. Solver pulp.solvers.COINMP_DLL unavailable. Solver pulp.solvers.GLPK_CMD unavailable. Solver pulp.solvers.XPRESS unavailable. Solver pulp.solvers.GUROBI unavailable.

According to the webpage,this should be my output :

import pulp pulp.pulpTestAll()
Solver pulp.pulp.COIN_MEM unavailable. Solver pulp.pulp.COIN_CMD unavailable. Testing continuous LP solution Testing maximize continuous LP solution Testing unbounded continuous LP solution Testing MIP solution Testing MIP relaxation Testing feasibility problem (no objective) Testing an infeasible problem Testing an integer infeasible problem (Error to be fixed) Testing column based modelling Testing column based modelling with empty constraints Testing dual variables and slacks reporting Testing resolve of problem Testing Sequential Solves Testing fractional constraints Testing elastic constraints (no change) Testing elastic constraints (freebound) Testing elastic constraints (penalty unchanged) Testing elastic constraints (penalty unbounded) * Solver pulp.pulp.COINMP_DLL passed. Solver pulp.pulp.GLPK_MEM unavailable. Solver pulp.pulp.GLPK_CMD unavailable. Solver pulp.pulp.XPRESS unavailable.

I am using Python 2.7.1, PuLP 1.4.7 on Windows 7 64 bit.

I guess it is because the CoinMP solver bundled with PuLP is not working. I just started working on Python a week back, I am just an amateur in programming.

0 投票
2 回答
10686 浏览

python - Python Pulp 使用矩阵

在多年使用 Matlab 之后,我对 Python 还是很陌生。我正在尝试使用 Pulp 来建立一个整数线性程序。

给定一个数字数组:

我想最大化:

受约束

并且有边界(基于向量的边界)

然而,在纸浆中,我看不到如何正确地进行向量声明。我正在使用:

我只能输入个人界限(所以只有1个数字)。

对于约束,我真的必须每行都做这一行吗?看来我错过了什么。我会很感激一些帮助。该文档讨论了一个简短的示例。在我的例子中,变量的数量是几千个。

0 投票
2 回答
1636 浏览

python - 允许用户输入变量 (Python)

我正在使用 PuLP 开发一个项目,我正在尝试创建一个终端提示符以允许用户输入他们的数据,然后我的 Python 程序会将输入更改为 PuLP 可读的代码。为此,我必须允许用户输入:

我的代码将 eval() 这段代码以及创建变量 a、b 和 c 等

有任何想法吗?我试过使用 exec() 但它似乎不太喜欢。

目前我通过以下方式获得输入:

所以字符串 2*a+3*B <= c 存储为 entryS

0 投票
0 回答
123 浏览

python - 纸浆问题(python)

我对纸浆有疑问,我正在尝试转换此约束

但我不确定这是否公平,我没有任何错误,但是,目标函数为 0

0 投票
1 回答
1243 浏览

python - 如何使用 PuLP 配置时间/时间线性编程约束?

我正在尝试使用 PuLP 解决假设的线性问题。该问题旨在最大限度地降低 5 年内的运营成本,同时最大限度地提高产品形状和条件。该问题必须产生5个成本,每年一个,同时优化整个系统和每年的运营。

total_cost涉及维护三种类型的传感器:

  • 问题必须考虑到,每年,传感器的状态都比前一年好,并且不能超过 12% 的传感器的状态为"Very poor".
  • 如果曝光不高,系统应该能够用另一种类型的传感器替换或降级购买新的传感器。(此声明与本帖无关)

对于sensor_type_a

  • 固定成本:
    • 每单位 1 至 5 年的租金为[50, 55, 55, 55, 60]
    • 第 1 年至第 5 年的每单位保险为[ 1.0, 1.2, 1.2, 1.8, 2.0]
  • 可变成本:
    • 功率基于传感器测量的项目数:10+.05*each_measurement。价格每年上涨1%
    • 维护是基于$500 for the total number of sensors + each_measurement*2.45. 价格每年上涨2%
  • 曝光指数指示每个传感器的状态,并基于下表:

_

对于sensor_type_b

  • 固定成本:
    • 每单位 1 至 5 年的租金为[60, 65, 65, 70, 75]
    • 第 1 年至第 5 年的每单位保险为[ 1.1, 1.3, 1.4, 1.7, 2.0]
  • 可变成本:
    • 功率基于传感器测量的项目数:10+.08*each_measurement。价格每年上涨1%
    • 维护是基于$500 for the total number of sensors + each_measurement*2.65. 价格每年上涨1.5%
  • 曝光指数表示每个传感器的状态,基于下表:

_

对于sensor_type_c

  • 固定成本:
    • 1 至 5 年所有单元的维护是[5000, 5100, 5200, 5300, 5400]
    • 第 1 年至第 5 年的每单位保险为[ 1.1, 1.3, 1.4, 1.7, 2.0]
  • 曝光指数表示每个传感器的状态,基于下表:

_

我的目标函数/方程是最小化之一:

我的限制:

我在设置约束函数时遇到了麻烦。这是我在概念上想做的事情(伪和python的混合):

问题:

如果我的伪+python 没有走上正轨,我该如何正确设置约束来解决问题?

请注意,我为每个变量填写的每个项目都有一个表格,其中包含适当的类别和数据点

编辑以反映以下评论:

总共有 2,700 个单元或位置需要测量。我有以下性质的表:

该模型不能改变今年传感器类型的构成,但它应该能够为未来几年充分建模。这意味着包括更换成本等,以获得更好的传感器并降低总体成本。

单位可以互换。

0 投票
1 回答
1184 浏览

python - 如何简化重复的 Python PuLP 语法?

如何将以下 Python PuLP 语句简化为更 Pythonic、易于管理和正确的语句:

0 投票
2 回答
3673 浏览

python - 纸浆中的背包,添加对所选项目数量的约束

我有一些纸浆代码,它解决了我的背包问题。

但是对于这段代码,我需要附加另一个限制:例如,非零的数量prob.variables必须等于(例如)10 的限制。

有人可以帮忙吗?

更新:

对于这段代码,我有输出:

prob.variables具有非零值的数量仅等于 4。但是说我需要 10,我将如何确保呢?

0 投票
1 回答
3464 浏览

python - 使用 Python 进行线性规划(Pulp) - 调度

我试图通过将其公式化为(整数)线性问题来优化时间表。我在编码部分遇到了一些问题(主要是由于纸浆),这与配方完全不同。

问题:

附表 n 船舶,为期 5 年(时间步长以月为单位),受以下限制:

  • 每月只有一艘船必须在“本地巡逻”(状态 = 'C')
  • 每年只有一艘船必须进行“扩展巡逻”(状态 = 'A'),即从 7 月到 10 月的四个月时间段
  • 每艘船必须在 5 年内进行一次为期 4 个月的检查(状态 = '4')
  • 每艘船在 5 年期间必须有 8 个月的休息时间(状态 = '8')
  • 每艘船必须大约每 5 个月进行一次定期维护(状态 = 'M')
  • 一艘船在给定月份只能处于一种状态,但它也可以没有状态(开放/空置,'_')

目标函数公式:

定义计算计划偏离 5 个月 ('M') 维护计划的次数(和数量)的松弛变量。

如果需要,我可以更多地解释设置,但现在我有一些基本问题可能是我的问题的根源。

这是我的限制之一(blockList 存储每艘船的 4 个月和 8 个月块的开始):

我想取上述表达式的LHS的绝对值,但我不能,因为对象被初始化为pulp.LpVariable。任何解决方法的建议?

Anyways, that may or may not fix my problem. If it doesn't, my next question is for anyone familiar with pulp. How can I know if the solution true, or if there was some sort of elasticity added by the solver in the background? (Running the code as is with that constraint gives incorrect results, and using a different solver like GLPK gives an error).

0 投票
1 回答
2308 浏览

python - 从 PuLP 迁移到 Scipy

我使用 PuLP 来解决一些具有约束、上限和下限的最小化问题。这是非常容易和干净的。

但我只需要使用 Scipy 和 Numpy 模块。

我正在阅读: http ://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html

多元标量函数的约束最小化

但是我有点迷失了......一些好人可以在 Scipy 中发布一个像这样的 PuLP 的小例子?

提前致谢。毫米

0 投票
1 回答
1332 浏览

r - Rglpk_solve_lp 和 glpsol(由纸浆 glpk 求解器内部使用)为相同的 LP 返回不同的值

lp 问题可以在Portfolio Optimization Problem中找到。该问题基于 Guy yollins 演示R Tools for Portfolio Optimization中的 cvar 优化。

当我在 R 中读取 lp 文件并执行它时,找到了最佳解决方案。而当我通过 glpsol 执行相同操作时,它会显示“LP 没有原始可行的解决方案”。我使用 glpsol 作为纸浆,当求解器参数为纸浆.GLPK() 时,内部使用 glpsol 来求解 lp。

在 R 中运行 lp 的步骤:

在 glpsol 中运行 lp 的步骤:

知道为什么吗?我尝试在 R 中查看 Rglpk_solve_lp 函数的代码。它似乎正在调用 glpk c 库的 glp_simplex 函数。我猜 glpsol 也在内部调用 glp_simplex 。

环境详情:
OS:Ubuntu 12.04
R 版本:3.02
Rglpk 版本:0.5-1(GLPK 4.52 版本随源码包提供)
glpsol 版本:4.52