4.5 Variable and Value Ordering
A search algorithm for constraint satisfaction requires the order in which variables are to
be considered to be specified as well as the order in which the values are assigned to the
variable on backtracking. Choosing the right order of variables (and values) can
noticeably improve the efficiency of constraint satisfaction.
4.5.1 Variable Ordering
Experiments and analysis of several researchers have shown that the ordering in which
variables are chosen for instantiation can have substantial impact on the complexity of
backtrack search. The ordering may be either
, in which the order of the variables is specified before the search
begins, and it is not changed thereafter, or
, in which the choice of next variable to be considered at any
point depends on the current state of the search.
Dynamic ordering is not feasible for all search algorithms, e.g., with simple backtracking
there is no extra information available during the search that could be used to make a
different choice of ordering from the initial ordering. However, with forward checking,
the current state includes the domains of the variables as they have been pruned by the
current set of instantiations, and so it is possible to base the choice of next variable on
Several heuristics have been developed and analyzed for selecting variable ordering. The
most common one is based on the "
" principle, which can be explained as
To succeed, try first where you are most likely to fail
In this method, the variable with the fewest possible remaining alternatives is selected for
instantiation. Thus the order of variable instantiations is, in general, different in different
branches of the tree, and is determined dynamically. This method is based on assumption
that any value is equally likely to participate in a solution, so that the more values there
are, the more likely it is that one of them will be a successful one.
The first-fail principle may seem slightly misleading, after all, we do not want to fail. The
reason is that if the current partial solution does not lead to a complete solution, then the
sooner we discover this the better. Hence encouraging early failure, if failure is
inevitable, is beneficial in the long term. On the other end, if the current partial solution
can be extended to a complete solution, then every remaining variable must be
instantiated and the one with smallest domain is likely to be the most difficult to find a
value for (instantiating other variables first may further reduce its domain and lead to a
failure). Hence the principle could equally well be stated as:
Deal with hard cases first: they can only get more difficult if you put them off.
Version 1 CSE IIT, Kharagpur