来源:F.Rossi, P.Van Beek, T. Walsh. Handbook of Constraints Programming. Elsevier, 2006.
4.2 Branching Strategies
In the naive backtracking algorithm (BT), a node p = {x1 = a1, . . . , xj = aj} in the search tree is a set of assignments and p is extended by selecting a variable x and adding a branch to a new node p∪{x = a}, for each a∈dom(x). The assignment x = a is said to be posted along a branch. As the search progresses deeper in the tree, additional assignments are posted and upon backtracking the assignments are retracted. However, this is just one possible branching strategy, and several alternatives have been proposed and examined in the literature.
More generally, a node p = {b1, . . . , bj} in the search tree of a backtracking algorithm is a set of branching constraints, where bi, 1≤i≤j, is the branching constraint posted at level i in the search tree. A node p is extended by adding the branches p∪{b1j+1}, . . . , p∪{bkj+1}, for some branching constraints bi j+1, 1 ≤i≤ k. The branches are often ordered using a heuristic, with the left-most branch being the most promising. To ensure completeness, the constraints posted on all the branches from a node must be mutually exclusive and exhaustive.
Usually, branching strategies consist of posting unary constraints. In this case, a variable ordering heuristic is used to select the next variable to branch on and the ordering of the branches is determined by a value ordering heuristic (see Section 4.6). As a running example, let x be the variable to be branched on, let dom(x) = {1, . . . , 6}, and assume that the value ordering heuristic is lexicographic ordering. Three popular branching strategies involving unary constraints are the following.
1. Enumeration. The variable x is instantiated in turn to each value in its domain. A branch is generated for each value in the domain of the variable and the constraint x = 1 is posted along the first branch, x = 2 along the second branch, and so on. The enumeration branching strategy is assumed in many textbook presentations of backtracking and in much work on backtracking algorithms for solving CSPs. An alternative name for this branching strategy in the literature is d-way branching, where d is the size of the domain.
2. Binary choice points. The variable x is instantiated to some value in its domain. Assuming the value 1 is chosen in our example, two branches are generated and the constraints x = 1 and x ≠ 1 are posted, respectively. This branching strategy is often used in constraint programming languages for solving CSPs (see, e.g., [72, 123]) and is used by Sabin and Freuder [116] in their backtracking algorithm which maintains arc consistency during the search. An alternative name for this branching strategy in the literature is 2-way branching.
3. Domain splitting. Here the variable is not necessarily instantiated, but rather the choices for the variable are reduced in each subproblem. For ordered domains such as in our example, this could consist of posting a constraint of the form x ≤ 3 on one branch and posting x > 3 on the other branch.
The three schemes are, of course, identical if the domains are binary (such as, for example, in SAT).
Table 4.1: Some named backtracking algorithms. Hybrid algorithms which combine techniques are denoted by hyphenated names. For example, MAC-CBJ is an algorithm that maintains arc consistency and performs conflict-directed backjumping.
BT | Naive backtracking: checks constraints with no uninstantiated variables; chronologically backtracks. |
MAC | Maintains arc consistency on constraints with at least one uninstantiated variable; chronologically backtracks. |
FC | Forward checking algorithm: maintains arc consistency on constraints with exactly one uninstantiated variable; chronologically backtracks. |
DPLL | Forward checking algorithm specialized to SAT problems: uses unit propagation; chronologically backtracks. |
MCk | Maintains strong k-consistency; chronologically backtracks. |
CBJ | Conflict-directed backjumping; no constraint propagation. |
BJ | Limited backjumping; no constraint propagation. |
DBT | Dynamic backtracking: backjumping with 0-order relevance-bounded nogood recording; no constraint propagation. |
Branching strategies that consist of posting non-unary constraints have also been proposed, as have branching strategies that are specific to a class of problems. As an example of both, consider job shop scheduling where we must schedule a set of tasks t1, . . . , tk on a set of resources. Let xi be a finite domain variable representing the starting time of ti and let di be the fixed duration of ti. A popular branching strategy is to order or serialize the tasks that share a resource. Consider two tasks t1 and t2 that share the same resource. The branching strategy is to post the constraint x1 +d1≤x2 along one branch and to post the constraint x2 + d2≤x1 along the other branch (see, e.g., [23] and references therein). This continues until either a dead end is detected or all tasks have been ordered. Once all tasks are ordered, one can easily construct a solution to the problem; i.e., an assignment of a value to each xi. It is interesting to note that, conceptually, the above branching strategy is equivalent to adding auxiliary variables to the CSP model which are then branched on. For the two tasks t1 and t2 that share the same resource, we would add the auxiliary variable O12 with dom(O12) = {0, 1} and the constraints O12 = 1 ⇐⇒ x1+d1≤x2 and O12 = 0 ⇐⇒ x2+d2≤x1. In general, if the underlying backtracking algorithm has a fixed branching strategy, one can simulate a different branching strategy by adding auxiliary variables. Thus, the choice of branching strategy and the design of the CSP model are interdependent decisions.
There has been further work on branching strategies that has examined the relative power of the strategies and proposed new strategies. Van Hentenryck [128, pp.90–92] examines tradeoffs between the enumeration and domain splitting strategies. Milano and van Hoeve [97] show that branching strategies can be viewed as the combination of a value ordering heuristic and a domain splitting strategy. The value ordering is used to rank the domain values and the domain splitting strategy is used to partition the domain into two or more sets. Of course, the set with the most highly ranked values will be branched into first. The technique is shown to work well on optimization problems.
Smith and Sturdy [121] show that when using chronological backtracking with 2-way branching to find all solutions, the value ordering can have an effect on the efficiency of the backtracking search. This is a surprise, since it is known that value ordering has no effect under these circumstances when using d-way branching. Hwang and Mitchell [71] show that backtracking with 2-way branching is exponentially more powerful than backtracking with d-way branching. It is clear that d-way branching can be simulated by 2-way branching with no loss of efficiency. Hwang and Mitchell show that the converse does not hold. They give a class of problems where a d-way branching algorithm with an optimal variable and value ordering takes exponentially more steps than a 2-way branching algorithm with a simple variable and value ordering. However, note that the result holds only if the CSP model is assumed to be fixed. It does not hold if we are permitted to add auxiliary variables to the CSP model.