Constraint Satisfaction Problems
Table of contents
- Defining CSP with Map Coloring Problem
- Arc consistency
- Sudoku Example of CSP
- Backtracking Search
- Min Conflicts
- Tree CSP
Defining CSP with Map Coloring Problem
A map coloring problem is a type of CSP where each state can be assigned a color from the set (red,green,blue). The constraint involved says that no two neighbouring state is allowed to have the same color.
Given below is a map of Australia showing its states and territories. You can select a color from the color palette given on the top right and then click on any state to color it with the selected color.
Try to color all the states while satisfying the condition that neighbouring states cannot have the same color.
Arc consistency
- Y = X + 1
- Z >= Y + 1
- W != Y
- W != Z
Step by step visualization of the procedure. Click to restart the simulation.
Sudoku Example of CSP
All sudoku puzzles can be forumulated as CSP by considering each cell as a variable. The initial domain of all cells is {1,2,3,4,5,6,7,8,9}.
The constraints are formulated by the fact that in the solution of a sudoku puzzle, no two cell in a row, column or block can have identical numbers. Thus, there is an
AllDiff( ) constraint for all the rows, columns and blocks.
The given sudoku puzzle calculates the reduced domain for each cell and shows them as dots. You can hover over any cell to see how the domain was reduced on the right side of the puzzle. The colors of the cross denote if the number was eliminated due to row, column or block. If the domain of a cell has reduced to just 1 variable (or number), this means we can safely assign that number there. This will further reduce the domain of other cells. Click to assign the number.
Try to solve the entire puzzle by assigning numbers by clicking on cells whose domains have reduced to 1 variable.
Use the restart button to reset the puzzle.
Backtracking Search
Backtracking Search is a type of Search algorithm that is useful to solve CSPs. It interweaves inferences and search to arrive at a solution by pruning parts of the search tree.
It repeatedly chooses an unassigned variable and tries all the possible values for it. If any inconsistency is detected, it backtracks and tries another value for the previous assignment.
In the diagram below, with no heuristic the variables are chosen in a random order, and so are the values of each variable. Use the Next button to move forward and Previous button to go back. You can also use the slider to go to any state directly. The table shows the values left in the domain of each variable; the column of the variable just assigned is highlighted.
Restart the diagrams several times and notice how many assignments a random ordering takes. Try to figure out why a particular ordering performs well (or bad).
Then turn on the heuristics of section 6.3 and compare the number of assignments:
- Minimum remaining values (MRV) chooses the variable with the fewest legal values left, the one most likely to cause a failure soon.
- Degree chooses the variable involved in the most constraints on the unassigned variables; together with MRV it only breaks the ties, as at the start, when every variable has three colors and the degree picks SA.
- Least constraining value (LCV) tries first the value that rules out the fewest values of the neighbors.
- Forward checking removes, after each assignment, the inconsistent values from the domains of the unassigned neighbors, and tries the next value as soon as a domain becomes empty (in red in the table). Without it the domains stay whole, and a value that conflicts with an assigned neighbor is only skipped when its turn comes.
Assignments : ( in this run)
Min Conflicts
Min conflicts stuff
Tree CSP
Tree CSP Stuff
Third Party License Information
- Australia Map Lokal_Profil [CC BY-SA 2.5, GFDL or CC-BY-SA-3.0], via Wikimedia Commons