添加许多约束时PuLP会变慢

时间:2017-10-23 07:05:34

标签: python linear-programming pulp

基于此 PuLP very slow when adding many constraints

我不确定已实施的补丁实际上是否解决了问题。我指的是:

“实际允许”+ =“只需使用类”

的iadd

有没有更新?有人能够提供这段代码的“更快”版本吗?

import pulp
vars = pulp.LpVariable.dicts("var",range(1000),0,None,pulp.LpContinuous)
coeffs = range(1000)
expr = pulp.LpAffineExpression()
import time
start_time = time.time()
for n in range(1000):  #Ten times building an expression of 1000 elements
    #print n
    for i in range(1000): # 1000 elements
        expr += coeffs[i] * vars[i]
print("--- %s seconds ---" % (time.time() - start_time))

由于

1 个答案:

答案 0 :(得分:1)

这应该快得多

scrollIntoView