T–79.4201 Search Problems and Algorithms T–79.4201 Search Problems and Algorithms 3 Search Spaces and Objective Functions. Complete Search Methods Search Spaces and Objective Functions (2/4) 3.1 Search Spaces and Objective Functions (1/4) Note that if SAT formulas are required to be in conjunctive normal form (as in e.g. 3-SAT), then it can also be viewed as an An instance I of a combinatorial search or optimisation problem Π determines a search space X of candidate solutions. optimisation problem: OPT-3-SAT: The computational difficulty in such problems arises from the Instance F = family of m 3-clauses on n variables { x 1 ,..., x n } . fact that X is typically exponential in the size of I (= HUGE). Search space X = all truth assignments t : { x 1 ,..., x n } → { 0 , 1 } . E.g. SAT: Objective (cost) function: c ( t ) = number of clauses not satisfied by Instance F = propositional formula on n variables { x 1 ,..., x n } . t . Search space X = all truth assignments t : { x 1 ,..., x n } → { 0 , 1 } . Goal: minimise c ( t ) . Goal: find t ∈ X that makes F true. Size of X = 2 n points ( 0 / 1 -vectors). I.N. & P .O. Autumn 2006 I.N. & P .O. Autumn 2006 T–79.4201 Search Problems and Algorithms T–79.4201 Search Problems and Algorithms Search Spaces and Objective Functions (4/4) Search Spaces and Objective Functions (3/4) OPT-SG (or SPIN GLASS GROUND STATE): Instance: An n × n matrix C of “coupling constants” c ij between n OPT-TSP: “spins” and an n -vector h (“external field”). Instance: An n × n matrix D of distances d ij between n “cities”. Search space: X = all “spin configurations” σ ∈ {− 1 , 1 } n . Search space: X = all permutations (“tours”) π of { 1 ,..., n } . Cost function (“Hamiltonian”): Cost function: d ( π ) = ∑ n − 1 i = 1 d π ( i ) π ( i + 1 ) + d π ( n ) π ( 1 ) . Goal: minimise d ( π ) . H ( σ ) = − ∑ c ij σ i σ j − ∑ h i σ i . � i , j � i Note: Here | X | = n ! . (More precisely: | X | = ( n − 1 )! / 2 , if the starting points and orientations of tours are ignored.) Goal: minimise H ( σ ) . Here again | X | = 2 n . I.N. & P .O. Autumn 2006 I.N. & P .O. Autumn 2006
T–79.4201 Search Problems and Algorithms T–79.4201 Search Problems and Algorithms function backtrack( I :instance; x :partialsol): if x is a complete solution then 3.2 Complete Search Methods: Backtrack Search return x (1/2) else for all extensions e 1 ,... e k to x do Bactrack search is a systematic method to search for a x ′ ← backtrack( I , x ⊕ e i ); satisfying, or an optimal solution x in a search space X . if x ′ is a complete solution then return x ′ end for ; return fail end if . I.N. & P .O. Autumn 2006 I.N. & P .O. Autumn 2006 T–79.4201 Search Problems and Algorithms T–79.4201 Search Problems and Algorithms 3.3 Backtrack Search in Games A backtrack search generates a search tree of increasingly Backtrack Search (2/2) complete partial solutions. Let us illustrate this in the case of evaluating position values in For instance, in the case of SAT, each partial truth assignment a game of 3 × 3 noughts-and-crosses. t : { x 1 ,... , x i } → { 0 , 1 } has two possible extension e 0 and e 1 : one assigns value 0 to variable x i + 1 and the other assigns value 1 . Associate to each incomplete position t in the game its payoff value for player X : In the case of TSP , the partial solutions could be nonrepeating sequences of cities (initial segments of tours), and the 1 if X has a winning strategy from t , extensions could be choices of next city. (Also other arrangements are possible). payoff( t ) = − 1 if O has a winning strategy from t , if neither has a winning strategy from t . 0 The complete annotated search, or game tree of this game is illustrated on the next slide. I.N. & P .O. Autumn 2006 I.N. & P .O. Autumn 2006
T–79.4201 Search Problems and Algorithms T–79.4201 Search Problems and Algorithms Turn: Position: The Minimax Rule X 0 The payoff values for all positions can be computed by X X O X .... augmenting a backtrack search of the game tree with 0 0 0 . . computations according to the following minimax rules: . . X X X O X O O 1 Position type Payoff value X X X X X X X final (complete) can be determined directly O X O X X O X O O O O O O X O 1 -1 0 X moves payoff = max {payoff values of immed. extensions} O moves payoff = min {payoff values of immed. extensions} X O X X X X O X X X X X X O X X O X O O X O O O O O O O X O O X O 0 -1 0 1 X O X X O X X X X O X X O X X O O X O O X O O X O O X O 0 0 1 I.N. & P .O. Autumn 2006 I.N. & P .O. Autumn 2006 T–79.4201 Search Problems and Algorithms T–79.4201 Search Problems and Algorithms function payoff ( t :position; k :depth; m:{MIN, MAX}): if k = 0 or t is a final position then return eval( t ) Bounded Depth Search else if m = MAX then v ← − ∞ else v ← ∞ ; Game trees in realistic games are usually evaluated only to for all t ’s extensions s do some predetermined lookup depth k , at which some heuristic if m = MAX then evaluation function eval( t ) is applied to estimate the payoff values v ← max( v , payoff( s , k − 1 , MIN)) of the incomplete positions t . else v ← min( v , payoff( s , k − 1 , MAX)) end if ; return v end if . I.N. & P .O. Autumn 2006 I.N. & P .O. Autumn 2006
T–79.4201 Search Problems and Algorithms T–79.4201 Search Problems and Algorithms 3.4 Alpha-Beta Pruning The size of a search tree can often be considerably reduced by p eliminating branches that cannot improve an already known MIN < 10 solution. In the case of game trees this process is known as alpha-beta pruning . During the backtrack search of the game tree, maintain at each MAX 10 t > 15 ... node t an intermediate payoff value , which for MIN nodes is an 15 upper bound on the eventual true payoff value, and for MAX nodes a lower bound. Then when it is clear that no further search below a given node t can improve the payoff value of its father, the remaining subtrees of t cab be pruned. (See next slide.) Can be left unsearched, since it is already known that payoff(p) < 10 and payoff(t) > 15. I.N. & P .O. Autumn 2006 I.N. & P .O. Autumn 2006 T–79.4201 Search Problems and Algorithms T–79.4201 Search Problems and Algorithms 3.5 Branch-and-Bound Search (1/2) Similar pruning techniques can greatly improve the efficiency of function payoff αβ ( t , k , m , pv ); pv = father’s intermediate payoff backtrack search in optimisation problems. if k = 0 or t is a final position then return eval( t ) Consider e.g. the TSP problem and choose: else if m = MAX then v ← − ∞ else v ← ∞ ; Partial solution : A set of edges (links) that have been decided to either include or exclude from the complete solution tour. for all t ’s extensions s do if m = MAX then Bounding heuristic : Let the TSP instance under consideration be v ← max( v , payoff αβ ( s , k − 1 , MIN, v )); given by distance matrix D = d ij . Then the following inequality holds for any complete tour π : if v ≥ pv then return v else 1 2 ∑ d ( π ) { ( d ij + d jk ) | at city j tour π uses links ij and jk } = v ← min( v , payoff αβ ( s , k − 1 , MAX, v )); i if v ≤ pv then return v 1 2 ∑ end if ; ≥ i , k ( d ij + d jk ) . min return v j end if . This estimate can be used to lower bound the length of tours achievable from any given partial solution, and prune the search tree correspondingly. I.N. & P .O. Autumn 2006 I.N. & P .O. Autumn 2006
T–79.4201 Search Problems and Algorithms T–79.4201 Search Problems and Algorithms 1 Branch-and-Bound Search (2/2) 2 ((2+3)+(3+3)+(4+4)+(2+5)+(3+6)) no constr. a b c d e C > 17,5 Consider the following small TSP instance: ab ab 3 C > 17,5 C > 18,5 3 prune prune a b ac ac ac ac ad ad 4 4 C > 18 C > 18,5 ae 7 ae 6 C > 20,5 prune C > 21 prune 8 e c ad ad ad ad 2 6 5 ae ae ae ae C > 18 C > 23 C > 18,5 C > 23,5 d Using the above lower-bounding heuristic, the search tree for bc bc be be the minimum tour on this instance can be pruned as presented tour tour tour tour abceda abecda acbeda acebda on the following slide. C = 23 C = 21 C = 19 C = 23 MINIMUM I.N. & P .O. Autumn 2006 I.N. & P .O. Autumn 2006 T–79.4201 Search Problems and Algorithms T–79.4201 Search Problems and Algorithms A*: Path Length Estimation 3.6 The A* Algorithm An important characteristic of A* is that the remaining distance from a node x to a goal node is estimated by some heuristic A* is basically a reformulation of the branch-and-bound search h ( x ) ≥ 0 . technique in terms of path search in graphs. As the algorithm visits a new node, it is placed in a set OPEN. Given: Nodes in OPEN are selected for further exploration in increasing order of the evaluation function ◮ search graph [neighbourhood structure] ( X , N ) ◮ start node x 0 ∈ X f ( x ) = g ( x )+ h ( x ) , ◮ set of goal nodes X ∗ ⊆ X where g ( x ) = dist ( x 0 , x ) is the shortest presently known ◮ edge costs c ( x , x ′ ) ≥ 0 for x ∈ X , x ′ ∈ N ( x ) distance from the start node. A heuristic h ( x ) is admissible , if it underestimates the true Task : find a (minimum-cost) path from x 0 to some x ∈ X ∗ . remaining minimal distance h ∗ ( x ) , i.e. if for all x ∈ X : h ( x ) ≤ h ∗ ( x ) := min x ∗ ∈ X ∗ dist ( x , x ∗ ) . I.N. & P .O. Autumn 2006 I.N. & P .O. Autumn 2006
Recommend
More recommend