Questions & AnswersPython Programming

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

Question
Answered step-by-step
Asked by DoctorSnake6165 on coursehero.com

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

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)

Answer & Explanation

Solved by verified expert
Answered by rupanshukumar2563 on coursehero.com
um dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec
CliffsNotes Logo

Unlock access to this and over
10,000 step-by-step explanations

Unlock Explanation

Have an account? Log In

Step-by-step explanation

um dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Done
1 attachment
Subscribe to unlock attachment
PNG

Get unstuck with a CliffsNotes subscription

Example CliffsNotes Question and Answer
Unlock every step-by-step explanation, download literature note PDFs, plus more.Get Access