Setting penalty value for constraints in ConstraintSatisfactionProblem


is there a possibility to set a certain penalty value for violating a constraint set in csp.add_constraint, and therefore making it a soft constraint?

Thank you in advance,




  • Hello,

    So far this is not possible, but it is possible to submit a feature request.

    Here is a link to the GitHub page:

    You can create a new issue from this page and then click the "Get Started" button next to "Feature Request":

    For convenience here is a link to the new feature page:

    It sounds like having a weighted binary CSP might be a bit error prone, and might not provide the best solutions, but it is worth submitting and feature request and explaining your use case.

    I hope this helps!

    Comment actions Permalink
  • Oh, thank you. How should I implement such a problem then? I'm coding nurse scheduling problem, it has some hard constraints and some soft ones.

    I've seen some implementations directly defining qubo equation to do this. Is there a more high-level possibility?


    Comment actions Permalink
  • Oh! That makes sense.

    I think the best way would be to create a QUBO, but of course, having a high level way of implementing would be great!

    I actually just noticed that there is a feature request for this already!

    If you want to add a comment to this, it will probably help encourage the feature to be implemented sooner than later.
    Having users that actually want to use a feature is great motivation for implementing it!

    In the mean time, let me see if I can help find an alternative high-level solution to your problem.

    Comment actions Permalink
  • Great, thank you! :D

    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post