Constraint Satisfaction Problem
Constraint Satisfaction Problems (CSPs) are a class of identification problems where the task is to assign values to variables that satisfy a set of constraints. Unlike search algorithms, CSPs care only about whether an assignment meets all constraints, not the sequence of steps to reach it.
CSPs are formally defined by:
- Variables , each with a domain of possible values.
- A domain specifying allowable values.
- Constraints restricting variable combinations.
There are combinations that could be assigned to the variables.
CSPs are NP-hard, meaning no known polynomial-time algorithm guarantees solutions. To make solving feasible, CSPs are often reformulated as search problems, traditionally as an optimization on DFS known as backtracking search with the following optimizations:
- States are a snapshot of the current assignments. Some variables already have values, others don’t yet.
- The successor function is the “next move”: pick one more variable and give it a value.
- The goal test checks if every variable has a value and all constraints are satisfied.
Examples
N-Queens
Consider the -queens identification problem: given an chessboard, can we find a configuration in which to place queens on the board such that no two queens attack each another?
We can formulate this problem as a CSP as follows:
- The variables are the grid positions on the chess board.
- The domain is , such that each is a boolean value representing whether there is a queen at position .
- The constraints are as follows:
- , stating that no two queens can be on the same row or column.
- , stating that no two queens can be on the same diagonal.
- A constraint ensuring that there are exactly positions marked with , such that .