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

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

Subject:Computer SciencePrice: Bought3

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)

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE