基于此 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))
由于
答案 0 :(得分:1)
这应该快得多
scrollIntoView