Question: I want to get a solution for the constraint that all variables sum will be 18. It is a simple example for CSP. The code

I want to get a solution for the constraint that all variables sum will be 18.

It is a simple example for CSP.

The code

import constraint

problem = constraint.Problem()

problem.addVariables("a", range(9))

problem.addVariables("b", range(8))

problem.addVariables("c", range(7))

problem.addVariables("d", range(3))

problem.addVariables("e", range(2))

problem.addVariables("f", range(2))

problem.addConstraint(constraint.ExactSumConstraint(18, [7,2,2,2,2,2]), ["a", "b", "c","d", "e", "f"])

solution = problem.getSolutions()

print(solution)

Step by Step Solution

3.37 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!