abc*_*abc 3 python linear-programming pulp
假设有一个线性程序和以下形式的约束:
\n\n4 x_1 + 3 x_2 \xe2\x89\xa4 10\nRun Code Online (Sandbox Code Playgroud)\n\n并且您想要将其更新为
\n\n4 x_1 + 3 x_2 + 10 x_3 \xe2\x89\xa4 10\nRun Code Online (Sandbox Code Playgroud)\n\n或者
\n\n3 x_2 \xe2\x89\xa4 10\nRun Code Online (Sandbox Code Playgroud)\n\n为了做到这一点,我从头开始“重写”约束,就像
\n\nprob.constraints[0] = ...\nRun Code Online (Sandbox Code Playgroud)\n\n但对于很长的约束来说,这是非常低效的。
\n\n是否有更简单的方法来添加或删除约束中的变量?
\n您可以通过以下方式向约束添加新术语:
prob.constraints[0].addterm(x_3, 10)
Run Code Online (Sandbox Code Playgroud)
同样,您可以通过删除术语
prob.constraints[0].pop(x_1)
Run Code Online (Sandbox Code Playgroud)
这完成了您列出的两个示例。