1

I am writing a LpProblem and I need to create a constraint where the sum of some variables is multiples of 100... 100, 200, 300...

I am trying the next expressions using mod(), round() and int() but none works because they don't support LpAffineExpression.

probl += lpSum([vars[h] for h in varSKU if h[2] == b]) % 100 == 0

probl += lpSum([vars[h] for h in varSKU if h[2] == b]) / 100 == int(lpSum([vars[h] for h in varSKU if h[2] == b]) / 100)

probl += lpSum([vars[h] for h in varSKU if h[2] == b]) / 100 == round(lpSum([vars[h] for h in varSKU if h[2] == b]) / 100)

Can you give me some ideas for write this constraint.

Thank you!

1 Answer 1

1

One fairly simple approach:

  • introduce an integer-variable I
  • build your constraint as: probl += lpSum([vars[h] for h in varSKU if h[2] == b]) == I*100
  • (constrain I as needed: e.g. I >= 1; I <= N)

Keep in mind: when having multiple constraints and the multiples of 100 are not necessarily the same for your constraints, you will need one auxiliary variable I_x for each constraint!

(And: you can't use python's operators in general within pulp or any other LP-modelling sytem (round, int, mod, ceil, ...)! You have to accept the rules/form those modelling-systems allow: in this case -> LpAffineExpression)

Sign up to request clarification or add additional context in comments.

1 Comment

Where should the integer - variable I be placed in the objective function of the model probl?

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.