LM27.2 - Structure of CSP
LM27.2 - Structure of CSP
• There are various ways in which the structure of the problem, as represented by the constraint
graph, can be used to find solutions quickly.
• The only possible way to deal with the real world is to decompose it into many subproblems.
• Look at the constraint graph for Australia (Figure 6.12(a)), one fact is: Tasmania is not connected to
the mainland.
• It is obvious that coloring Tasmania and coloring the mainland are independent subproblems—any
solution for the mainland combined with any solution for Tasmania yields a solution for the whole
map.
• A constraint graph is a tree when any two variables are connected by only one path.
• A CSP is defined to be directed arc-consistent under an ordering of variables X1,X2, . . . ,Xn if and
only if every Xi is arc-consistent with each Xj for j > i.
• 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.
• Figure 6.10(a) shows a sample tree and (b) shows one possible ordering.
• Any tree with n nodes has n−1 arcs, so we can make this graph directed arc-consistent in O(n) steps,
each of which must compare up to d possible domain values for two variables, for a total time of
O(nd2).
• Once we have a directed arc-consistent graph, we can just march down the list of variables and
choose any remaining value.
• Since each link from a parent to its child is arc consistent, we know that for any value we choose for
the parent, there will be a valid value left to choose for the child.
• That means we won’t have to backtrack; we can move linearly through the variables.
AL3391/AI/II AI&DS/III SEM/KG-KiTE
STRUCTURE OF CSP
• We have an efficient algorithm for trees, we can consider whether more general constraint graphs can be
reduced to trees.
• There are two primary ways to do this, one based on removing nodes and one based on collapsing nodes
together.
• The first approach involves assigning values to some variables so that the remaining variables form a tree.
• Consider the constraint graph for Australia, shown in Figure 6.12(a). If we could delete South Australia, the
graph would become a tree, as in (b).
• We can do this (in the graph, not the continent) by fixing a value for SA and deleting from the domains of the
other variables any values that are inconsistent with the value chosen for SA.
• Now, any solution for the CSP after SA and its constraints are removed will be consistent with the value chosen
for SA.
• Therefore, we can solve the remaining tree with the algorithm given above and thus solve the whole problem.
1. Choose a subset S of the CSP’s variables such that the constraint graph becomes a tree after removal of S. S is
called a cycle cutset.
2. For each possible assignment to the variables in S that satisfies all constraints on S,
(a) remove from the domains of the remaining variables any values that are inconsistent with the assignment
for S, and
(b) If the remaining CSP has a solution, return it together with the assignment for S.
AL3391/AI/II AI&DS/III SEM/KG-KiTE
STRUCTURE OF CSP
• If the cycle cutset has size c, then the total run time is O(dc.(n − c)d2).
• If the graph is “nearly a tree,” then c will be small and the savings over straight backtracking
will be huge.
• Finding the smallest cycle cutset is NP-hard, but several efficient approximation algorithms
are known.
• Each subproblem is solved independently, and the resulting solutions are then combined.
Like most divide-and-conquer algorithms, this works well if no subproblem is too large.
• Figure 6.13 shows a tree decomposition of the mapcoloring problem into five subproblems.
• Every variable in the original problem appears in at least one of the subproblems.
• If two variables are connected by a constraint in the original problem, they must appear
together (along with the constraint) in at least one of the subproblems.
• If a variable appears in two subproblems in the tree, it must appear in every subproblem
along the path connecting those subproblems.
• The first two conditions ensure that all the variables and constraints are represented in the
decomposition.
• The third condition seems rather technical, but simply reflects the constraint that any given
variable must have the same value in every subproblem in which it appears; the links joining
subproblems in the tree enforce this constraint.
• For example, SA appears in all four of the connected subproblems in Figure 6.13.
• You can verify from Figure 6.12 that this decomposition makes sense.
• We solve each subproblem independently; if any one has no solution, we know the entire problem
has no solution.
• If we can solve all the subproblems, then we attempt to construct a global solution as follows.
• First, we view each subproblem as a “mega-variable” whose domain is the set of all solutions for the
subproblem.
• For example, the leftmost subproblem in Figure 6.13 is a map-coloring problem with three variables
and hence has six solutions—one is {WA = red ,SA = blue, NT = green}.
• Then, we solve the constraints connecting the subproblems, using the efficient algorithm for trees
given earlier.
• The constraints between subproblems simply insist that the subproblem solutions agree on their
shared variables.
• For example, given the solution {WA = red ,SA = blue, NT = green} for the first subproblem, the only
consistent solution for the next subproblem is {SA = blue, NT = green,Q = red}.
• A given constraint graph admits many tree decompositions; in choosing a decomposition, the aim is
to make the subproblems as small as possible.
• The tree width of a tree decomposition of a graph is one less than the size of the largest
subproblem; the tree width of the graph itself is defined to be the minimum tree width among all its
tree decompositions.
• Hence, CSPs with constraint graphs of bounded tree width are solvable in polynomial time.
AL3391/AI/II AI&DS/III SEM/KG-KiTE
STRUCTURE OF CSP
Value Symmetry:
• For every consistent solution, there is actually a set of n! solutions formed by permuting the
color names.
• For example, on the Australia map we know that WA,NT, and SA must all have different
colors, but there are 3! = 6 ways to assign the three colors to these three regions.
• We would like to reduce the search space by a factor of n! by breaking the symmetry.
• This constraint ensures that only one of the n! solutions is possible: {NT = blue, SA = green, WA =
red}.
• For map coloring, it was easy to find a constraint that eliminates the symmetry, and in general it is
possible to find constraints that eliminate all but one symmetric solution in polynomial time, but it is
NP-hard to eliminate all symmetry among intermediate sets of values during search.
• The complexity of solving a CSP is strongly related to the structure of its constraint graph.
• Cutset conditioning can reduce a general CSP to a tree-structured one and is quite efficient
if a small cutset can be found.
• Tree decomposition techniques transform the CSP into a tree of subproblems and are
efficient if the tree width of the constraint graph is small.