foundations of computational agents
Arc consistency simplifies the network by removing values of variables. A complementary method is variable elimination (VE), which simplifies the network by removing variables.
The idea of VE is to remove the variables one by one. When removing a variable , VE constructs a new constraint on some of the remaining variables reflecting the effects of on all of the other variables. This new constraint replaces all of the constraints that involve , forming a reduced network that does not involve . The new constraint is constructed so that any solution to the reduced CSP can be extended to a solution of the CSP that contains . In addition to creating the new constraint, VE provides a way to construct a solution to the CSP that contains from a solution to the reduced CSP.
The following algorithm is described using the relational algebra calculations of join and project.
When eliminating , the influence of on the remaining variables is through the constraint relations that involve . First, the algorithm collects all of the constraints that involve . Let the join of all of these relations be the relation , where is the set of other variables in the scope of . Thus is the set of all variables that are neighbors of in the constraint graph. The algorithm then projects onto ; this relation replaces all of the relations that involve . It now has a reduced CSP that involves one less variable, which it solves recursively. Once it has a solution for the reduced CSP, it extends that solution to a solution for the original CSP by joining the solution with .
When only one variable is left, it returns those domain elements that are consistent with the constraints on this variable.
Consider a CSP that contains the variables , , and , each with domain . Suppose the constraints that involve are and . There may be many other variables, but if does not have any constraints in common with these variables, eliminating will not impose any new constraints on these other variables. To remove , first join on the relations that involve :
To get the relation on and induced by , project this join onto and , which gives
This relation on and contains all of the information about the constraints on that affect the solutions of the rest of the network.
The original constraints on are replaced with the new constraint on and . VE then solves the rest of the network, which is now simpler because it does not involve the variable . To generate one or all solutions, the algorithm remembers the joined relation on to construct a solution that involves from a solution to the reduced network.
Figure 4.6 gives a recursive algorithm for variable elimination, VE_CSP, to find all solutions for a CSP.
The base case of the recursion occurs when only one variable is left. In this case (line 8), a solution exists if and only if there are rows in the join of the final relations. Note that these relations are all relations on a single variable, and so they are the sets of legal values for this variable. The join of these relations is the intersection of these sets.
In the non-base case, a variable is selected for elimination (line 10). Which variable is selected does not affect the correctness of the algorithm, but it may affect the efficiency. To eliminate variable , the algorithm propagates the effect of onto those variables that is directly related to. This is achieved by joining all of the relations in which is involved (line 13) and then projecting out of the resulting relation (line 14). Thus, a simplified problem (with one less variable) has been created that can be solved recursively. To get the possible values for , the algorithm joins the solution of the simplified problem with the relation that defines the effect of .
If you only wanted to find one solution, instead of returning , the algorithm can return one element of the join. No matter which element it returns, that element is guaranteed to be part of a solution. If any value of in this algorithm contains no tuples, there are no solutions.
The efficiency of the VE algorithm depends on the order in which variables are selected. The intermediate structure – which variables the intermediate relations are over – depends not on the actual content of relations but only on the graph structure of the constraint network. The efficiency of this algorithm can be determined by considering the graphical structure. In general, VE is efficient when the constraint network is sparse. The number of variables in the largest relation returned for a particular variable ordering is called the treewidth of the graph for that variable ordering. The treewidth of a graph is the minimum treewidth for any ordering. The complexity of VE is exponential in treewidth and linear in the number of variables. This can be compared to searching [see Section 4.3], which is exponential in the number of variables.
Finding an elimination ordering that results in the smallest treewidth is NP-hard. However, some good heuristics exist. The two most common are:
min-factor: at each stage, select the variable that results in the smallest relation
minimum deficiency or minimum fill: at each stage, select the variable that adds the fewest arcs to the remaining constraint network. The deficiency of a variable is the number of pairs of variables that are in a relationship with that are not in a relationship with each other. The intuition is that it is okay to remove a variable that results in a large relation as long as it does not make the network more complicated.
The minimum deficiency has usually been found empirically to give a smaller treewidth than min-factor, but it is more difficult to compute.
VE can also be combined with arc consistency; whenever VE removes a variable, arc consistency can be used to further simplify the problem. This approach can result in smaller intermediate tables.