Constraint satisfaction
Professor Devin Balkcom
devin@cs.dartmouth.edu
office: Sudikoff 206
Sometimes for a search probem:
(An example of factoring state.)
An assigment of values to variables is the state of the problem. We want to find an assignment consistent with the constraints.
Constraints:
(An example of factoring state.)
An assigment of values to variables is the state of the problem. We want to find an assignment consistent with the constraints.
(A quick list -- discussion coming soon.)
What are variables, domains, constraints for each of the following?
Variables have different names. But we want to write general code. An example assignment:
state = {0, 1, 1, 2, 0, 1, 0}
variable order: WA, NT, SA, Q, NSW, V, T
So NT has the value 1 (green).
Domains can be represented by sets of numbers.
Constraints:
Arc consistency
We say that an arc from variable $X$ to variable $Y$ is consistent if for every value of $X$ there exists some value of $Y$.
Assume $SA \in \{blue\}$ and $NSW \in \{red, blue\}$.
Is SA arc consistent with respect to NSW?
Yes, since for every value of SA (only blue), there is at least one value of NSW (in this case, red).
So, SA is consistent, and not causing any trouble.
Assume $SA \in \{blue\}$ and $NSW \in \{red, blue\}$.
Is NSW arc consistent with respect to SA?
No, since for at least one value of NSW (blue), there are no legal values for $SA$.
i.e., we have learned something about NSW domain.
Delete blue from NSW domain.
Let's use inference to quickly solve the map-coloring problem for Australia. (On the board.) Start with partial assignment $WA = red$.
Run-time:
$O(c d^2)$
To make constraints consistent, delete values.
But consider the 'mega-variable' (SA, V), with possible assignments $(red, blue)$ and $(blue, red)$, after checking binary constraints and deleting.
Is $(red, blue)$ 3-consistent with any value from NSW domain? No, so delete $(red, blue)$ from the `SA-V` domain.
Same for $(blue, red)$.
What's the run-time? How about for higher-order consistency? (Consider brute-force assignment checking for $n$-consistency.)
What if each variable must have a different value? For example, a section for CS 1 must have its own room and cannot share.
One idea: Does an assignment of values to a set of variables cover a number of values equal to the number of variables in the set? (Written as code, not a white-list.)
Naive approach:
Run-time. Branching factor at top is $n d$, if $d$ size of domain. At next level, $(n - 1) d$, since once variable has been assigned.
Tree has $n! d^n$ leaves. That can't be good; there are only $d^n$ possible assignments!
Consider only a single variable at each node.
Branching factor is now $d$, depth $n$. So, $d^n$ leaves.
Ordering heuristics:
Assume we've assigned $WA = r$ and $NT = g$. Should we consider $SA$ next or $Q$ next?
Pick variable involved in the most constraints: SA.
(Idea: get maximum information from first assigments.)
Idea: We don't have to try all values. Try the ones that are most promising first.
Least-constraining value: choose the value that rules out as few values for adjacent variables as possible.
Why fail-fast for variables, but fail-slow for values?
We can interleave search and inference.
Forward checking: Whenever variable X is assigned, delete conflicting values from adjacent domains.
or
Constraint propagation: create a queue, add arcs pointing to X, and propagate constraint using AC-3, etc.
min-conflicts:
This works surprisingly well, particularly if there are many densely distributed solutions.
Which CSPs are hard, and which are easy?
Some apparently continuous CSP problems are not:
Assume we know all of the distances. Can we compute the configuration of the protein?
What if we don't know which atoms the distances correspond to? Variables $\theta_1 \ldots \theta_n$. Assign values so that distances appear in from legal set.
Linear programs are one example.
Will it fall? (Image from Anne Loomis M.S. thesis.)
Which order should we take this apart in? (Jenga)
Reauleax's graphical method:
We want there to be no solution to some linear program.
For any CSP, we can pose a dual problem that has the same solution, and for which all constraints are binary.
$(WA, NT) = C_1 \in \{ (r, g), (r, b), \ldots \}$
$C_{12}: ((WA, NT), (WA, SA) ) \in \{ (rg, rb), (gr, gb), (br, bg) \}$
New constraints force edges of original constraint graph agree on values at vertices. If you make two constraints agree on red at a vertex, and then a third agrees with one of the others, they all agree.