Definition
A constraint satisfaction problem consist of three components, , and :
- is a set of variables,
- is a set of domains, , one for each variable
- is a set of constraints that specify allowable combination of values.
Each domain consists of a set of allowable values, for variable . Each constraint consists of a pair , where
scope
is a tuple of variables that participate in the constraint andrel
is a relation that defines the values that those variables can take on.
To solve a CSP, we need to define a state space and the notion of a solution. Each state in a CSP is defined by an assignment of values to some or all of the variables, . An assignment that does not violate any constraints is called a consistent or legal assignment. A complete assignment is one in which every variable is assigned, and a solution to a CSP is a consistent, complete assignment. A partial assignment is one that assigns values to only some of the variables.
Constraint Hypergraph
In a constraint hypergraph
- Nodes represent variables.
- Hyperedges represent constraints. A hyperedge is like an edge, but it can connect any number of nodes (not just two). Each hyperedge connects all the variables involved in a particular constraint.
Example: Suppose you have the following CSP:
- Variables:
- Domains:
- Constraints:
- The constraint hypergraph would have four nodes (for ). It would have two hyperedges:
- One hyperedge connects and (representing ).
- One hyperedge connects and (representing ).
Constraint Propagation
Note
CSPs can indeed be solved by naive DFS and BFS, but the time consumption might be relatively high. Constraint propagation aims to reduce the domain size of the variables, so that there would be less chance that we would change the values of the assigned variables.
In CSPs, algorithms can perform search (variable assignment) or constraint propagation (inference to reduce variable domains). Constraint propagation can sometimes solve the problem without search.
Node consistency
A single variable (corresponding to a node in the CSP network) is node-consistent if all values in its domain satisfy its unary constraints. For example, in map coloring, if SA's domain is and SA dislikes green, node consistency reduces the domain to .
CSPs can be simplified by enforcing node consistency and transforming -ary constraints into binary ones.
Arc consistency
A variable is arc-consistent with respect to if every value in has a corresponding value in that satisfies the binary constraint .
Example: For with domains , enforcing arc consistency reduces 's domain to and 's to .
Path consistency
A pair is path-consistent with respect to if for every consistent assignment , there exists a value for that satisfies constraints with both and .
K-consistency
A CSP is -consistent if any consistent assignment to variables can be extended to a -th variable.
- 1-consistency = node consistency.
- 2-consistency = arc consistency.
- 3-consistency = path consistency. Strong -consistency: -consistency for all .
- A strongly -consistent CSP can be solved in time without backtracking, where is the domain size at most.
- Trade-off: Higher requires exponential time/space.
Other constraints
A global constraint is one involving an arbitrary number of variables. For example, the Alldiff constraint says that all the variables involved must have distinct values.
The resource constraint, sometimes called the at most constraint limits the maximum value of a variable.
Arc Consistency Algorithms
AC-3 Algorithm
- Uses a queue of arcs to enforce consistency.
- If a domain is revised, neighboring arcs are rechecked.
- Time complexity: for constraints and domain size .
AC3 reduces the domain by checking if an assignment of a variable is compatible with its neighboring variables (does not violate constraints). When no situation can be found where this assignment is compatible with neighboring variables, this value is removed from the domain of the variable.
Local Search
The initial state assign a value to every variable, and the search changes the value of one variable at a time.
In choosing a new value for a variable, the most obvious heuristic is to select the value that results in the minimum number of conflicts with other variables—the min conflicts heuristic.
The Structure of CSPs
Subproblems
Independent Subproblems: any solutions of all the subproblems can be combined into a solution of the whole problem. There are no conflicts between two different subproblems.
Independence can be ascertained simply by finding connected components of the constraint graph.
Dividing the whole problem into subproblems can help reduce time complexity.
Tree-structured CSPs
To solve a tree-structured CSP, first pick any variable to be the root of the tree, and choose an ordering of the variables such that each variable appears after its parent in the tree. Such an ordering is called a topological sort.