Skip to content

Performance issue while adding constraints #436

Answered by stumitchell
Ervin66 asked this question in Q&A
Discussion options

You must be logged in to vote

Pulp uses the += operator to add constraints to LpProblems this is idiomatic usage.

However often people come from other libraries and languages and use += to generate single constraints like the following

for b in Bars:
    c = LpAffineExpression()
    for w in Warehouses:
        c += vars[w][b]
    prob +=c >=demand[b]

in this case the += in this line c += vars[w][b] makes the code very slow

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@Ervin66
Comment options

Comment options

You must be logged in to vote
2 replies
@Ervin66
Comment options

@stumitchell
Comment options

Comment options

You must be logged in to vote
1 reply
@Ervin66
Comment options

Answer selected by stumitchell
Comment options

You must be logged in to vote
1 reply
@Ervin66
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants