A constraint captures a rule over one or more variables. It stores the variables it constrains and exposes isSatisfied(assignment:), which determines whether a partial or complete assignment remains valid. The base implementation returns true; concrete problems override it with their own rule. section 3.1
Use a constraint inside a generic constraint-satisfaction framework:
- Declare vars as the variables participating in the rule. section 3.1
- Register the constraint with the CSP so search checks it whenever a related variable receives a value. section 3.1
Map coloring
A binary MapColoringConstraint stores two neighboring regions. Its isSatisfied method returns true until both regions have colors, then rejects assignments using the same color. The same abstraction also supports an all-queens constraint that rejects equal rows or matching diagonals. section 3.2
Constraints make the search framework reusable: map coloring, eight queens, and word search provide different variables, domains, and rules while sharing the same backtracking search. section 3.3 section 3.4


















