• No results found

Systematic Search Algorithms

3.4

Systematic Search Algorithms

This family of algorithms takes a systematic approach to looking for solutions in the entire search space. For example, consider the simple problem illustrated in figure 3.1. Assume that you would like to timetable 3 modules in your department. The modules (W EB, OOP , DAT ABASES) have to be assigned a time so that no two modules are timetabled at the same time. In addition, there must be a two hour break between the W EB and DAT ABASES modules so that the absolute difference between W EB and DAT ABASES is greater than or equal to 2 (i.e. |W EB − DAT ABASES| >= 2). The W EB module has four times available (11am, 1pm, 2pm, 3pm) whilst the other modules have two possible times but the times are different for each module (10am and 12pm for OOP and 10am and 11am for DAT ABASES respectively). Formally, this problem can be modelled as a CSP as X = {W EB, OOP, DAT ABASES}, DW EB = {11am, 1pm, 2pm, 3pm}, DOOP = {10am, 12pm}, DDAT ABASES = {10am, 11am}, C1 = [W EB 6= OOP ], C2= [DAT ABASES 6= OOP ], C3 = [|W EB − DAT ABASES| >= 2].

Figure 3.1: A simple Constraint Satisfaction Problem

The simplest algorithm in this backtracking family is the Naive Backtracking algo- rithm [87].

Initially, all variables are unassigned. For our sample problem, it is assumed that the variables are ordered e.g. W EB, OOP and DAT ABASES and that values are chosen in

Figure 3.2: The Naive Backtracking search tree for our simple CSP

the order that they appear in the domain. The search tree produced by Naive Backtracking when solving this problem is shown in figure 3.2 where black circles indicate the solution and grey circles indicate value combinations that do not lead to a solution. The algorithm then selects a variable (e.g. the W EB variable) and assigns a value to that variable which satisfies all constraints. Then the next variable (e.g. the OOP variable) is selected and assigned a value consistent with the constraints, and with the value already assigned to previous variables (e.g. the W EB variable). This process is repeated until all variables are assigned, i.e. a solution to the problem is found. However, if a variable cannot be assigned a value without violating constraints, the algorithm backtracks to the previous variable, choosing another value for this variable which does not violate constraints. For example, in the sample problem, the DAT ABASES variable has no consistent value whilst the W EB variable has value 11am. This will result in the algorithm initially backtracking to the OOP variable and exhausting all possible values for that variable before backtracking to the W EB variable and changing its value.

The Naive Backtracking algorithm attempts all variable value combinations in the worst case [21]. Consequently, a number of improvements to this algorithm have been proposed. Backjumping [33] maintains a backjumping variable which is a neighbour (i.e. shares a constraint with) of the current processing variable and is the lowest variable higher in the search ordering than the current processing variable. When the current processing variable has no consistent values, the algorithm tries to find a new value for

3.4. Systematic Search Algorithms 16 this backjumping variable rather than the previous variable in the search ordering.

Figure 3.3: The Backjumping search tree for our simple CSP

For example, the sample problem (in figure 3.1) would produce the search tree shown in figure 3.3 where black circles indicate the solution and grey circles indicate value com- binations that do not lead to a solution. Specifically, the search would start with W EB being assigned 11am as its first domain value. This is consistent with all constraints since there are no constraints to check. OOP would be assigned 10am since this satisfies the con- straint of OOP 6= W EB. We now instantiate the DAT ABASES variable but there are no consistent values since 10am and 11am violate the constraint between DAT ABASES and W EB 1. In Naive Backtracking, we would backtrack to the OOP variable as it is the previous variable in the search. In Backjumping, we would backjump to the W EB variable as this is the variable which is causing DAT ABASES to be unable to choose a value i.e. changing the value of OOP cannot improve the situation. If the backjump variable also has no consistent values, then naive backtracking is used to backtrack to the previous variable.

Conflict-Directed Backjumping [74] is an improvement over backjumping in which a conflict set of possible backjumping variables is maintained. This enables repeated backjumping with the deepest variable in the conflict set being chosen when a backjump

1

Incidentally, 10am violates the constraint between OOP and DAT ABASES whilst 11am satisfies this constraint.

is required and that variable then being removed from the conflict set. This conflict set takes the form of nogoods where variable assignments which are found not to lead towards a solution are recorded.

Dynamic Backtracking [34] is a further improvement to Conflict-Directed Back- jumping which allows variable re-ordering and maintains the search information after backjumping which has not been invalidated by the backjump. Other improvements to backtracking include backmarking [33] and forward checking [3].

Forward checking, which can be combined with any systematic search algorithm, checks if unassigned neighbours of the current processing variable have any consistent val- ues with the proposed assignment of the current processing variable. If not, the proposed assignment for the current processing variable is abandoned and another assignment is chosen. For example, in the sample problem, forward checking would discover when as- signing 11am to W EB that there is no consistent value for DAT ABASES when W EB takes 11am as its value and so would cause W EB to choose 1pm before moving to assign OOP as the next variable in the search. This prevents the exploration of parts of the search tree that are doomed to failure because of a particular variable value combination (as W EB being set to 11am was causing the problem).

Systematic search algorithms are complete in that they are guaranteed to find a solution or determine that the problem is unsolvable. However, they may take exponential time to do this.