Can we directly model following constraint in pulp

x != y

as following:

constarint = pulp.LpConstraint(x != y)
model += constraint

Will this work as intended? Here, x and y can take positive Integer values.

  • 2
    $\begingroup$ Actually it is a concept in CP rather than being in MIP. To use that in Pulp Please, search all-different constraint and its linearization. $\endgroup$
    – A.Omidi
    Commented May 4 at 19:57
  • $\begingroup$ See math.stackexchange.com/a/1517850/651442 $\endgroup$
    – PeterD
    Commented May 5 at 17:27

1 Answer 1


Will this work as intended? No.

Try it out and use


to verify what PuLP does with this. This is a good debugging tool in general.

Obviously, PuLP could handle this much better (e.g. by generating an exception). Defensive programming + operator overloading requires a lot of care even for operators you don't want to support.

Note. A good reference on how to implement AllDifferent constraints in a MIP model is: Williams, H. Paul and Yan, Hong (2001), Representations of the 'all_different' predicate of constraint satisfaction in integer programming, Informs Journal on Computing, 13 (2). 96-103.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.