5.7 Implementation Issues
5.7.1 The search tree
The backtracking search tree generated by a CSP solver can be depicted as a directed rooted tree with the root at the top and leaves at the bottom. To remove infeasible paths, we enforce arc consistency (Sabin & Freuder 1994). This will remove incon- sistent values from domains D(X) for uninstantiated variables X. When searching for solutions, the search branches on unassigned variables and instantiates their un- pruned values. The search backtracks when it reaches a dead end (a path in the search tree that cannot be extended to any optimal solution) or all variables were instantiated. Children nodes are created in between from the top down to the bot- tom linked through directed edges so that every node has a unique parent (except the root). When all variables are instantiated, the resulting (complete) assignment is associated with a node that we call an end node. Thus, a leaf node at the bottom of the search tree can be a node associated with a partial assignment or an end node which is associated with a complete assignment.
Solutions (i.e., complete assignments) are created when all variables are instan- tiated. Variables and values are instantiated in an order compatible with the user’s preferences (see Proposition 1 in Section 5.3). This will prevent any newly found solution β to be bettered by any other solution found later during the search. In fact, the algorithm proceeds by assigning values to the variables in a top-down manner according to the variable ordering shown in the user’s preferences (see Proposition 1(1) in Section 5.3).
The values for a variable X are considered according to the preferential ordering induced by the assignment made to the variables that are instantiated before X in the search tree and whose values determine the ordering of the values of X. Let V be a set of variables and Γ be the set of user preferences. Let Uϕ and Wϕ be two
uϕ : xϕ > x0ϕ[Wϕ], (Wϕ ⊆ (V \ (Uϕ∪ Xϕ))), then variables in Uϕ are instantiated
in the search tree before Xϕ which is instantiated before variables in Wϕ. According
to ϕ, if the assignment already made in the search tree is compatible with uϕ, then
xϕ should be instantiated before x0ϕ (xϕ and x0ϕ are assumed to be consistent with
regards to the CSP).
This ordering is not necessarily as efficient as the commonly-used variable or- dering heuristics from the perspective of solving a CSP; it is indeed effectively ran- dom regarding the CSP solving. Further, it is well known that imposing an ordering on the splitting heuristic, used for searching solutions, may lead to a significant degradation in the performances of the solver used for finding solutions (Järvisalo et al. 2005, Järvisalo & Junttila 2009). Although this is not the case for several appli- cations, see, e.g., (Giunchiglia et al. 1998, Maratea et al. 2010) in the context of satis- fiability planning (Kautz & Selman 1992) and Answer Set Programming (Gelfond & Lifschitz 1988b, Gelfond & Lifschitz 1991).
However, such an ordering gives the algorithm the anytime property. In fact, this ordering ensures that a solution that is already found (previously generated) is guaranteed to be optimal: it will not be dominated by a solution that will be found later during the search. Thus, the algorithm can stop anytime, being sure the set of solutions obtained so far (till the moment it stops) is a subset of the set of all optimal solutions (obtained if the algorithm terminates the execution normally). Without this property, we would have to maintain a potentially large set of candidate solutions. Section 4 of (Boerkoel et al. 2010) discussed ways of realising the performance bene- fits of a heuristic variable ordering while preserving the early termination properties of the CP-net-based ordering.
In the search tree, each node N is associated with a variable V(N) and has its cur- rent domain D(V (N )) (which we abbreviate to D(N )) filled with consistent values regarding constraint propagation and as presented in Definition 2 in Section 2.11 of Chapter 2. Every time the associated variable is instantiated with a value v ∈ D(N ), a new branch in the search tree is generated at the top of which node M is created. N will then become the parent of M. A partial assignment A(M) (i.e., Av in the CPOp-
timizer procedure) is created at node M. It corresponds to the assignments made on the path from the root to node M. The search process tries to extend this par- tial assignment incrementally by instantiating the uninstantiated variables. N will have a number of children equal to the number of values in D(N ) after instantiating variable V(N). Every child node (e.g., node M) will become the root of a subtree STv
which is created below N if at least one of its values is consistent regarding constraint propagation (e.g., the instantiation of one value satisfies all constraints). There will be search for solutions in STv. Each time all variables are instantiated (at each end
5.7. Implementation Issues
to N and we assign the next unassigned value (if any) to V(N). Then, we add the set of solutions that were found after creating node N to the set of solutions that were found before creating node N.
Example 12. LetV be the set of variables {X1, X2, X3} with (initial) domains defined
as follows:X1 = {x11, x12}, X2 = {x21, x22} and X3 = {x31, x32}. The set of variables
have their domains constrained as the following pairs of values are not allowed in a solution: (x21, x32), (x12, x31). The user’s preferences are represented by a cp-theory Γ which consists of the five statements:> : x22> x21[∅], x22 : x12> x11[∅], x21: x11>
x12[∅], x11: x32> x31[∅], x12: x31 > x32[∅].
The corresponding search tree with a variable instantiation ordering compatible with the user’s preferences (i.e.,Γ) is depicted in Figure 5.7.1.
Figure 5.3: Example of a search tree