python - 使用 Pulp 更新约束

标签 python linear-programming pulp

假设有一个线性程序和一个形式的约束:

4 x_1 + 3 x_2 ≤ 10

并且您想将其更新为

4 x_1 + 3 x_2 + 10 x_3 ≤ 10

或到

3 x_2 ≤ 10

为了做到这一点,我从头开始“重写”约束,比如

prob.constraints[0] = ...

但是对于很长的约束,这是非常低效的。

有没有更简单的方法来从约束中添加或删除变量?

最佳答案

您可以通过以下方式将新条款添加到您的约束中:

prob.constraints[0].addterm(x_3, 10)

同样,您可以通过以下方式删除条款

prob.constraints[0].pop(x_1)

这完成了您列出的两个示例。

关于python - 使用 Pulp 更新约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46469630/

相关文章:

python - 大型数据集的贪婪集覆盖有什么好的实现吗?

python - 具有软限制的聚合目标函数/目标的多背包问题

python - 在 PyGTK/GObject 中使用枚举属性

python - tensorflow 和 Pycharm

python - 访问html元素BeautifulSoup Python2.7

linux - 有什么好的工具可以解决 linux 上的整数程序问题?

python - 在 Pulp Python 中制定 LP 的约束

python - Python 中的 CPLEX - 学生许可证

python - 如何配置 PuLP 调用 GLPK 求解器

python - 并行线程 python GIL 与 Java