0

based on this PuLP very slow when adding many constraints

I am not sure the patch that has been implemented actually solves the problem. I am referring to:

"actually allow "+=" simply by using iadd of the class"

Is there any update on this? Is someone able to provide a "faster" version of this bit of code please?

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))

Thanks

1 Answer 1

1

This should be much faster

import pulp
vars = pulp.LpVariable.dicts("var",range(1000),0,None,pulp.LpContinuous)
coeffs = range(1000)
import time
start_time = time.time()
for n in range(1000):  #Ten times building an expression of 1000 elements
    #print n
    pulp.lpSum([coeffs[i] * vars[i] for i in range(1000)])
print("--- %s seconds ---" % (time.time() - start_time))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.