An atomic state-space algorithm makes progress in one way only, what is it?
A CSP algorithm has choices! It can choose a new variable to assign, or do a type of inference called constraint propagation, using the constraints to reduce the number of legal values a variable can have (which can then reduce further the legal values for other variables).
It does this to reduce the choices for further assignment (making search easier).
When can this search be done?
The idea is local consistency, if each variable is a node and each constraint an edge, by enforcing consistency, inconsistent values will be eliminated throughout the graph.
A variable is node consistent if all the values in the domain satisfy the unary constraints. (South Wales)
A graph is node consistent if every node is node consistent.
Since it’s possible to reduce any \(n\)-airy graph to a binary one, many solvers only work with binary constraints, expecting the user to reduce the problem ahead of time (we’ll take this assumption going forward)
A variable is arc-consistent if every value in its domain satisfy the variables binary constraints.
Put another way, variables are arc-consistent with each other if both have some value in their domain that satisfies the binary constraint. Example
This can assist in some problems (like some number problems) but not others (like the map coloring problem) Why?
Consider the map-coloring problem. What if we try to color Australia with only two colors, red and blue.
Does arc-consistency help here?
Does this problem have a solution?
To make progress on map coloring problems, we need a stronger idea of consistency.
Path consistency tightens binary constraints by using implicit constraints inferred by looking at triples of variables.
A two variable set \(\{X_i,X_j\}\) is path-consistent with respect to a third variable \(X_m\) if, for every assignment \(\{X_i=a,X_j=b\}\) consistent with any relevant constraints, there is also an assignment to \(X_m\) that satisfies the constraints on \(\{X_i,X_m\}\) and \(\{X_m,X_j\}\) (as if there was a path between \(X_i\) and \(X_j\) with \(X_m\) in the middle.
Let’s apply this to the Australia map problem! What do we learn?
A CSP is \(k\)-consistent if, for any set of \(k-1\) variables, and for for any consistent assignment to those variables, a consistent value can always be assigned to the \(k\)th variable.
1-consistency says, given an empty set, we can make any set of one variable consistent (what is this called?)
What about 2-consistency?
3-consistency?
A CSP is strongly k-consistent if it is \(k\)-consistent and also (\(k-1\))-consistent, (\(k-2\))-consistent, … down to 1-consistent.
If we have a CSP which has \(n\) nodes and make it strongly \(n\)-consistent, then we solve the problem by finding a valid value for each variable \(X_i\), only needing to search through the \(d\) values in the domain. With the total runtime being \(O(n^2d)\).
But… constraint satisfaction is NP-complete in general, and any algorithm for finding \(n\)-consistency must take exponential \(n\) time in the worst case. Worse, it also requires space exponential in \(n\).
Really, we just have to observe and find an appropriate level of consistency checking, 2-consistency is common, 3-consistency less so…
Global constraints are common and are solvable by special-purpose algorithms.
Consider \(AllDiff\), what would be a possible algorithm for deciding \(AllDiff\)?
Map example
Another higher-order constraint is a resource constraint sometimes called the \(AtMost\) constraint.
For large resource-constrained problems (like mass logistics), it’s impractical to represent domains as lists of integers, instead domains are represented as upper and lower bounds, and are adjusted by bounds propagation
A Sudoku and its solution
What happens when we finish our constraint propagation and we still have variables with multiple possible values?
Search!
Specifically, we’ll focus on solutions with partial assignemnts (complete comes later)
Think for a moment how a standard depth-limited search (as in Ch. 3) could solve CSPs…
For a CSP with \(n\) variables, of domain size \(d\), all the solution nodes are at depth \(n\)
However, our branching factor (at the top level) is \(nd\), because we can assign any of the \(d\) values can be assigned to \(n\) variables.
Therefore… the branching factor is \((n-1)d\)… and so on for \(n\) levels… doesn’t this look grim?
How many levels does the tree have?
Well, CSPs are commutative, which means what?
Taking this into account, we should only ever consider a single variable at each node…
Which takes us back to a \(d^n\) number of leaves, as we would hope
Backtracking Pseudocode
Partial Australia Search
Notice, we’re not keeping different representations of the solution, we’re modifying it as we go.
When we did tree-search in Chapter 3, we had to use domain-specific heuristics
Now, we can make our search more efficient using domain-independent heuristics!
Which variable should be assigned next \((SelectUnassaginedValue)\), and in what order should its values be tried \((OrderDomainValues)\)
What inferences should be performed at each step in the search \((Inference)\)
Can we \(Backtrack\) more than one step (when appropriate)?
Can we save and reuse partial results from the search?