Search
Search Trees
● node = state A ● arcs = operators ● search = control Depth B C D
E F G Fringe or search frontier
branching factor = # choices of each node Search Criteria
● Completeness: guarantees to find a solution when there is one
● Optimality: highest quality solution where there are different solutions
● Efficiency: time complexity and space complexity
Goal: find the right search criterion for a problem
Search Algorithms
Types of search algorithms in two perspectives: ● Based on information used ■ Blind Search e.g., depth-first, breath-first, bidirectional search ■ Heuristic Search e.g., hill climbing, best first search, A* search
● Based on search direction (more later) ■ Goal-driven (backward chaining): search from goal states to verify given data ■ Data-driven (forward chaining): search from data to find goal states Blind Search
Blind Search (Uninformed or Brute force search)
● Systematically generates states and test against the goal
● Depends on topology of search tree
● Is distinguished by the order in which nodes are expanded
● Has no information about the number of steps or the path cost from current state to the goal state Examples:
■ Depth First
■ Breadth First
Backtracking
A start
B C D
E F G goal H I J Solution path: ACG Backtracking Algorithm
CS = current state SL = state list of current path being evaluated for solution A start NSL = new state list DE = dead end list of states whose descendants failed to contain goal node B C D Begin SL := [start]; NSL := [start]; DE := []; CS:= Start; while NSL != [] do E F G goal begin if CS = goal then return SL; if CS has no children then H I J begin while SL is not empty and CS = first element of SL do begin add CS to DE; I CS SL NSL DE remove first element from SL; 0 A A A remove first element from NSL; 1 B B A BCD A CS := first element of NSL 2 E E BA EF BCDA end; 3 H H EBA HI EFBCDA add CS to SL; 4 I IEBA IEFBCDA H end 5 E EBA EFBCDA IH else begin F FBA FBCDA EIH place new children of CS on NSL; CS := first element of NSL; 6 J J FBA J FBCDA EIH add CS to SL 7 F FBA FBCDA JEIH end B BA BCDA FJEIH end; C CA CDA BFJEIH return FAIL; 8 G GCA GCDA BFJEIH end
Backtracking Algorithm
A start
B C D
A start E F G goal
H I J C B I CS SL NSL DE 0 A A A 1 B B A BCD A E F G goal 2 E E BA EF BCDA 3 H H EBA HI EFBCDA 4 I IEBA IEFBCDA H H I J 5 E EBA EFBCDA IH F FBA FBCDA EIH 6 J J FBA J FBCDA EIH 7 F FBA FBCDA JEIH Tracing SL B BA BCDA FJEIH C CA CDA BFJEIH 8 G GCA GCDA BFJEIH Breadth-First Search (BFS)
● Expands the shallowest node first A start
B C D
E F G goal A BCD H I J Algorithm: CDEF DEFG 1. Let Q = queue contain start state EFG 2. If head of Q is a goal state STOP FGHI 3. Generate successors of head and GHIJ add them at the tail of Q. Remove the head. 4. Go to 2 Solution: trace ancestors - ACG Node expansion order: ABCDEFG
Depth-First Search (DFS)
● Expands the deepest node first A start
B C D
E F G goal A BCD H I J EFCD Algorithm: H I FCD I FCD 1. Let Q = queue contain start state FCD 2. If head of Q is a goal state STOP JGCD 3. Generate successors of head and GCD add them at the head of Q. Remove the head. Solution: ABFG 4. Go to 2 Node expansion order: ABEHIFJG Complexity
Given b = branching factor, d = solution depth Running time = the time generating nodes at depth 1, 2, .. ,d = b + b2 + ....bd # nodes generated d Time complexity is O (b ) for both BFS and DFS b . . . b2 Space required = max queue length For BFS: = # nodes at depth d = bd Space complexity is O (bd)
For DFS: = bd Space complexity is O (bd)
Characteristics
BFS ● Shortest path solution ● Optimal if unit cost (since cost = path length) ● Complete ● Time complexity O (bd) Space complexity O (bd) DFS ● Space efficiency (Space complexity O(bd)) ● Not complete (should avoid when space has large/infinite depth) ● Not optimal (see example 2) BFS Example 2
B 3 Given cost 9 D A 5 E Solution cost = 18 Start 4 Goal 7 11 C
A A B C B C C D D D E Solution: ACE D E E C B E Solution path – trace ancestors Shortest path solution
DFS Example 2
B 3 Given cost 9 D A 5 E Solution cost = 17 Start 4 Goal 7 11 C
A A B C B C D C D E C Solution: ABDE E C Solution path – trace ancestors What is optimal solution? What cost? Other Blind Searches
• Uniform-cost Search: expands the least-cost leaf node first
● Depth-limited Search: places a limit on the DFS depth
● Iterative deepening Search: calls Depth-limited search iteratively
● Bidirectional Search: searches forward (from start state) and backward (from goal state) and stop where two searches meet
Uniform Cost Search
● Expands the least expensive node first B 3 Given cost 9 D A 5 E Solution cost = 16 Start 4 Goal 7 11 C UCF gives solution with min. A cost of the path traveled so far 9 7 9 B C 7 12 3 4 11 D 11 D E 18 4 5 3 5 B E C 14 16 Solution: ACDE E Done - fail 16 17 Other Blind Searches
• Depth-limited Search (to avoid drawback of DFS) • DFS that imposes cutoff on the max depth of search path • complete if cutoff depth large enough • not optimal (like DFS)
● (Depth First) Iterative deepening Search (to avoid issue of choosing cutoffs without sacrificing efficiency)
● calls Depth-limited search iteratively for increasing cutoff depth à order of node expansion ~ BFS • combines benefits of DFS and BFS
● good for large search space with unknown solution depth
Other Blind Searches (contd)
● Bidirectional Search (to improve efficiency of BFS)
● searches forward (from start state) and backward (from goal state) and stop where two searches meet
Initial state ● Time complexity O (bd/2)
What are the requirements of problems that are applicable to this search?
Goal state Blind Search (contd)
Some comparisons Complete? Optimal?
● Breadth-first Search yes yes for unit-cost
● Depth-first Search no no
● Uniform-cost Search yes yes for non- decreasing path cost
● Depth-limited Search only if deep enough no (like DFS)
● Iterative deepening Search yes yes for unit-cost
● Bidirectional Search yes yes for unit-cost
Blind Search Issues
Problems with Brute force methods
● Time complexity grows exponentially with size of the problem Eg. Rubik’s cube: 4x1019 nodes Chess tree: 10120 nodes Combinatorial Explosion! Extremely inefficient
Solution: add knowledge to reduce complexity Heuristic Search
Luger, Ch 4 & Reference Texts
Outline
• What are heuristics and heuristic functions ? • Using heuristics in games • Heuristic search algorithms • Properties and complexity Heuristics
The term “Heuristic” means “to discover”
● “rules of thumb” that domain experts use to generate good solutions without exhaustive search (Fiegenbaum and Feldman)
● “A process that may solve a given problem, but offers no guarantees of doing so” (Newell, Shaw and Simon)
● Technique that improves the average-case performance on a problem-solving task, but not necessary improve the worst- case performance (Russell and Norvig) Using heuristics Efficiency + Accuracy (might miss optimal solution)
Heuristics in Search
Heuristic Search (or Informed search): uses Problem-specific knowledge
Evaluation function determines the order of nodes to be expanded
Heuristic evaluation function estimates merit of state with respect to the goal Heuristic functions
Examples: Let h(n) = heuristic value of state n
● Road navigation or route finding
h1(n) = Euclidean distance from n to goal state
h2(n) = Expected traveling time
Heuristic functions (contd)
● The 8 puzzle: E.g., h1(n) = the number of tiles that are out of place from the goal h2 (n) = sum of distances out of place h3 (n) = 2 × the number of direct tile reversals
5 4 1 2 3 h (n) = 7 4 2 - 1 2 2 2 6 1 8 8 4 0 3 3 h2 (n) = 18 7 3 2 7 6 5 h (n) = 0 state n Goal state 3
● Which heuristics to choose?
■ prefer global to local accounts (e.g., h1 is more global than h3 but more local than h2 ) ■ Selection of the best heuristic function is empirical and based on its performance on problem instances Heuristic functions (contd)
● A heuristic evaluation function must ■ provide a reasonable estimate of the merit of a node ■ be inexpensive to compute ■ never over estimate the merit of a node (more later)
● There are tradeoffs between ■ evaluation time ■ search time
● Heuristic sacrifices accuracy but why still heuristic? ■ rarely require optimal solution ■ worse case rarely occur ■ learning heuristic helps us understand the problem better
Outline
• What are heuristics and heuristic functions ? • Using heuristics in games • Heuristic search algorithms • Properties and issues Game playing
● Representation: Game tree
● Nodes: state of the game (e.g. board configuration)
● Branches: possible moves
● Leaves: winning states
● Game trees usually have multiple goal states
● Heuristic function evaluates game value or pay-off or utility of each node
TIC-TAC-TOE
max(x) You
x x x min(o) Your opponent xO x O x x x O x x x x x O O O O O O O O O x x
o o o o x o o x x Multiple x o x x x terminal goal states x o x x x x o o 1 = win 0 = draw -1 = loss utility Game playing program
● Full game trees are intractable, e.g., TIC-TAC-TOE
■ total # of leaves = 9!
■ reduced states by symmetry (shown in previous slide) = 12 x 7!
● Two main parts of the program:
■ plausible move generator
■ (static) evaluation function
● Search game trees
● One-person games (e.g., 8 puzzle): A*
● Two-person games (e.g., checkers, tic-tac-toe): MINIMAX
Heuristics for TIC-TAC-TOE
Heuristic function, e(n) = x(n) – o(n) x(n) = # winning lines for x, x will try to max e o(n) = # winning lines for o, o will try to min e
6-5 = 1 x x 4-6 = -2 x x x o o x x x x o o x x x x o x o x o o o o o o 5-5 = 0 6-5 = 1 5-5 = 0 4-5 = -1 5-4 = 1 6-4 = 2 5-6 = -1 6-4=2 5-6 = -1 6-6= 0 Minimax Search
● A depth-limited search procedure
■ Generate possible moves
■ Apply evaluation function for each node
■ Alternate selection of either max or min child value
■ Repeat process as deep as time allows
Minimax Search (contd.)
Let p be a search level (ply) While p > 0 do begin if p’s parent level is MIN then for each parent node pick min value of its children, else pick max value; propagate the selected value to its parent; p = p – 1 end. 1 MAX
6-5 = 1 x x 4-6 = -2 x MIN x x o -1 1 -2 o x x x x o o x x x x o x o x o o o o o o 5-5 = 0 6-5 = 1 5-5 = 0 4-5 = -1 5-4 = 1 6-4 = 2 5-6 = -1 6-4=2 5-6 = -1 6-6= 0 Minimax Search (Contd.)
● Search depth could effect results Max 2 one-ply search → second move
two-ply search → first move Min 2 3 1 5
2 7 1 8 ● Issues: ■ limited look-ahead may lead to bad states later – remedy: search deeper BUT .... ■ search deeper doesn’t necessary mean better
Alpha Beta Procedure
● Improve efficiency by pruning
Max ≥ 2 → value of this node = 2
Min 2 ≤ 1
cutoff 2 7 1 8 Alpha Beta Procedure
α = lower bound of MAX node α > β à cutoff β = upper bound of MIN node
= 2 α Min ≤ 7 β = 7 Max ≥ 2 A A
B Max B Min 2 ≤ 1 7 ≥ 9 α = 9 β = 1
α-cutoff β-cutoff 2 7 1 9 2 7 9 1 B is α-cutoff B is β-cutoff
More Examples: α-β pruning
3 MAX
3 0 2 MIN
3 7 0 7 2 6 MAX
2 3 5 7 0 7 4 2 1 5 6
Result on Minimax without pruning. Select first move for a three-ply search to obtain a game value 3 More Examples: α-β pruning
Init: α (lower bound of MAX node) = -∞ and β (upper bound of MIN node) = ∞
≥ 3 3 MAX α β -∞ ∞ 2 ∞ ≤ 3 ≤ 0 MIN 2 3 3 ≤ 2 5 3 3 3 MAX 3 0 ≥ 2 3 ≥ 5 0 ≥ 2 2 3 2
2 3 5 0 2 1
Save time on evaluation of five nodes. Result is to choose first move.
More Examples: α-β pruning (contd)
≥ 4 ≥ 5 5 MAX
8 4 ≤ 5 5 MIN ≤ ≤ 3
3 1 MAX 2 ≥ 1 ≥ ≥ ≥ 8 8 ≥ 9 ≥ 4 3 5 ≥ 9 ≥ 6 ≥ 2 3 ≥ 4 ≥
8_ 7_ _3 _9 1 6 _2 _4 _1 _1 _3 _5 _3 _9 2 _6 5 2 _1 2_ _3 9 7 2 16 6 4
Save time on evaluation of 11nodes. Result is to choose middle move. Best case pruning
≥ 9 MAX
9 ≤ 9 MIN ≤ 6 ≤ 3 MAX 9 ≥ 10 ≥ 11 6 3
9 8 7 10 11 6 5 4 3 2 1 Assume left to right evaluation. Any game tree with better pruning? What’s its characteristic?
Best case: the best child is the first one being evaluated ~ O(bd/2) # of evaluations = 2bd/2 – 1 if d even b(d+1)/2 + b(d-1)/2 – 1 if d is odd [Knuth]
Outline
• What are heuristics and heuristic functions ? • Using heuristics in games • Heuristic search algorithms • Properties and issues Heuristic Search
Basic classifications of heuristic search algorithms
● Iterative improvement algorithms, e.g.,
● Hill climbing
● Best-First Search, e.g.,
● Greedy search
● A*
● Memory bounded search, e.g.,
● Iterative deepening A* (IDA*)
● Simplified memory-bounded A* (SMA*)
Hill Climbing
Use generate and test problem-solving strategy Algorithm: (Simple) Hill Climbing 1. Let current node be an initial state. 2. If current node is a goal state, STOP (solution found) 3. If current node has no more successor, STOP (no solution found) 4. If successor is better than the current node, make the successor a current node. Go to 2.
Note: “better” can mean lower or higher value. E.g., If h(n) = cost from n to a goal state then “better” = lower value If h(n) = profit in state n then “better” = higher value Example: Hill Climbing
● h(n) = profit in state n -2 B 3 D h(E) = 5 A E 5 Start 0 Goal C 1
A A
B C B C D E Solution: ACE B E Solution: ACDE Solutions depend on order of node expansion
Gradient Search
● A variation of hill climbing (steepest ascent): Replace “better” by “best” in step 4 of the simple hill climbing algorithm. I.e., making the best successor, that is better than current node, a new current node
-2 B A 3 D A E 5 B C Start 0 Goal D E C 1 Solution: ACE
Solutions do not depend on order of node expansion Hill Climbing
● May miss optimal solution
-2 B Goal 3 D A E 5 Start 0 Goal C 1 A A
B C B C
D Solution: ACD E Solution: ACE Which is a better solution?
Hill Climbing: Example 2
A 10 What are solution paths from hill climbing B 6 C 8 D 7 algorithms?
E 8 F 7 G 5 H 4 L 1 Goal
I 6 J 3 Goal K 2 Simple hill climbing: ABGJ but not optimal Optimal solution: ADL Gradient search: ABHK miss solution If K is a goal state ... still the solution is non-optimal
Hill climbing returns “locally” optimal solution Characteristics and Issues
• Hill climbing returns “locally” optimal solution • Complexity: • Time Complexity = O(d), where d = longest path length in the tree • Space Complexity ? • Failures in hill climbing ● search is too local (more later) ● bad heuristics
A D Example: Blockworld D C
C B B A Start Goal
Characteristics and Issues (cont)
Operators: Put(X) puts block X on table A D Stack(X, Y) puts block X on top of block Y D C C B B A D Start Goal C B A
A D C C C D B D B A B A Characteristics and Issues (cont)
Heuristic1: (an object is either a block or a table) A D
● Add one for every block that is attached on the right object D C ● Subtract one for every block that is attached on the wrong object C B B A D Start Goal C 0 4 B A 2 A D C C C D B D B A B A 0 0 0
Characteristics and Issues (cont)
Heuristic 2: (a support of X is a set of blocks supporting X) A D
● For each block that has correct support, add one for every D C block in the support C B ● For each block that has an incorrect support, subtract one for each block in the support B A D Start Goal C -3 -2 -1 = -6 6 B A -3 A D C C C D B D B A B A -6 -1 -2 Characteristics and Issues (contd)
Drawbacks: situations that no progress can be made
● Foothill (local maxima): always better than neighbors but not necessary better than some other far away
● Mesa (Plateau): not possible to determine the best direction to move
● Zig-zag (Ridges): local max has a slope
can’t traverse a ridge by single moves ● ● ●
●Remedy: Random-restart hill-climbing
● Backtrack to earlier node
● Big jumps to new search space
● Move to several directions at once
Simulated Annealing
● Or Valley Descending - a variation of hill climbing where “downhill” moves may be made at the beginning
● Allows random moves to escape local max
● can temporarily move to a worse state to avoid being stuck, i.e.,
If state is better then move, else move with prob. < 1, where the prob. of the “badness” of the move decreases exponentially
● Analogous to annealing metals to cool molten metal to solid
● A transition to a higher energy state in cooling process occurs with probability p, where p = e -ΔΕ / T Note: p is propositional to T ΔΕ = +ve change in energy level T = Temperature T initially increases then decreases Simulated Annealing (contd)
Algorithm (sketched) 1. current node = an initial state. Initialize T according to the annealing schedule 2. Best-so-far = current node 3. Repeat Generate a successor X of a current state; If X is a goal state then return it and STOP else if X is better than current then begin current = X; best-so-far = X end else make X a current state only with probability p = e -ΔΕ / T where ΔΕ = change in values of current node and X; Revise T from the schedule Until a solution is found or current state has no more successor 4. Return Best-so-far (ancestors are traced for a solution path)
Simulated Annealing (contd)
Start A 0 Hill climbing: stuck at B Gradient search: stuck at H
B 3 C 5 Simulated Annealing: ABDFG (if B generates D first) ACHEG (if uses gradient search variation) D 1 E 2 H 7
F 6 G 10 Goal Heuristic Search
Basic classifications of heuristic search algorithms
● Iterative improvement algorithms, e.g.,
● Hill climbing
● Simulated annealing
● Best-First Search, e.g.,
● Greedy search
● A*
● Memory bounded search, e.g.,
● Iterative deepening A* (IDA*)
● Simplified memory-bounded A* (SMA*)
Best First Search
● Expand the node with lowest cost first to find a low-cost solution
● Uses heuristic cost evaluation function f(n) for node n
● Idea: ■ Loop until goal is found or no node left to generate – Choose the best of the nodes generated so far. If it is goal then quit. – Generate the successors of the chosen node – Add all new nodes to the set of nodes generated so far Example 1
Goal F f(A) = 25 17 B 0 D 10 f(F) = 0, etc. Start “ ” E 4 best = smallest value A 25 C 15
A 25
B 17 C 15
E 4 D 10 solution: ACEF
D 10 F 0 Goal
Best First Search Algorithm
Algorithm: f(A) = 25, f(F) = 0, etc. Goal 1 OPEN = [start]; CLOSED = []; 17 F 0 B 2 If OPEN = [], exit with FAIL; D 10 3 Choose best node from OPEN, call it X; Start E 4 4 If X is a goal node, exit with a traced solution path; A 25 C 15 5 Remove X from OPEN to CLOSED; 6 Generate successors of X (record X as their parent) X OPEN CLOSED For each successor S of X A25 - i) Evaluate f(S); A25 B17,C15 A25 ii) If S is new (i.e., not on OPEN, CLOSED), add it to OPEN C15 D10,E4,B17 C15,A25 iii) If S is not new, compare f(S) on this path to previous one E4 F0,D10,B17 E4, C15,A25 If previous is better or same, keep previous and discard S F0 F0,D10,B17 E4,C15,A25 Otherwise, replace previous by S. Goal If S is in CLOSED, move it back to OPEN 7 Go to 2 Solution ACEF Evaluation Cost Functions
Start S f(n) = cost of state n from start state to goal state g(n) = cost from start state to state n g(n) h(n) = cost from state n to goal state n In Best First Search, an evaluation cost function of state n
h(n) f ʹ(n) = g(n) + hʹ(n), where f ʹ(n) is estimate of f(n) hʹ(n) is a heuristic estimate of h(n) Goal G
Example 2
Goal 17 F 0 h (A) = 25 B ʹ 3 10 9 D 4 hʹ(F) = 0, etc. 5 Start 4 11 E 4 f ʹ(n) = g(n) + hʹ(n) A 25 7 C 15 A 25+0 solution: ACDEF
B 17+9=26 C 15+7=22
D 10+11=21 E 4+18=22
B 17+14=31 E 4+16=20
Goal F 0+20 Best First Search: Example 2
Algorithm: hʹ(A) = 25, hʹ(F) = 0, etc. 1 OPEN = [start]; CLOSED = []; Goal 17 F 0 B 3 2 If OPEN = [], exit with FAIL; 9 D 10 4 5 3 Choose best node from OPEN, call it X; Start 4 E 4 A 25 4 If X is a goal node, exit with a traced solution path; 7 11 C 15 5 Remove X from OPEN to CLOSED; 6 Generate successors of X (record X as their parent) OPEN CLOSED For each successor S of X A25 - B17+9A,C15+7A A25 i) Evaluate f(S); = g(S) + hʹ(S) D21CA,E22CA,B26A C22A,A25 ii) If S is new (i.e., not on OPEN, CLOSED), add it to OPEN A39CA E22CA,B26A D21CA,C22A,A25 iii) If S is not new, compare f(S) on this path to previous one B31DCA,E20DCA,C30DCA, If previous is better or same, keep previous and discard S F20EDCA,B26A E20DCA,D21CA, Otherwise, replace previous by S. C42EDCA,D31EDCA C22A,A25 If S is in CLOSED, move it back to OPEN Goal 7 Go to 2 Solution ACDEF
Evaluation Cost Functions & Search
Start S f(n) = cost of state n from start state to goal state g(n) = cost from start state to state n g(n) h(n) = cost from state n to goal state n In Best First Search, an evaluation cost function of state n
h(n) f ʹ(n) = g(n) + hʹ(n), where f ʹ(n) is estimate of f(n) hʹ(n) is a heuristic estimate of h(n) Goal G Special cases: • Uniform cost search: f ʹ(n) = g(n) • Breadth First Search: f ʹ(n) = g(n), where g ≡ depth
• Greedy search: f ʹ(n) = hʹ(n) • A*: f ʹ(n) = g(n) + hʹ(n) where hʹ(n) is admissible (later) Outline
• What are heuristics and heuristic functions ? • Using heuristics in games • Heuristic search algorithms • Properties and issues
Some properties
● Uniform Cost Search: ■ Minimizes g(n) ■ Expands node on the least cost path first à Gives solution with minimal distance traveled ■ Doesn’t direct search towards goal
● Greedy Search: ■ Minimizes hʹ(n) ■ Expands node closest to the goal à Reaches the goal fast ■ Directs search towards goal disregarding traveling distance à not optimal
● A*: ■ Minimizes g(n) + hʹ(n) ■ Balances both costs Admissibility
hʹ(n) is given near the node, g(n) = depth(n) A 3 2 Using f ʹ(n) = g(n) + hʹ(n): Solution ACIJ B 2 +1 C 4 +1 H is not generated Suppose F is also a goal: Solution ABDEF D 1 +2 I 1 +2 G, H, C, I, J not generated Solution is not optimal – cost 5 instead of 3 E 1 +3 J 0 +3 Goal Problem: hʹ(C) > h*(C) – hʹ overestimates h Goal F 1 +4 where h*(n) = cost on the optimal path from state n to goal state Here h*(C) = 2 from an optimal path ACIJ G 1 +5
H 0 Suppose hʹ(C) = 2 à hʹ(C) ≤ h*(C): Goal Solution ACIJ – optimal, and F, G, H not generated If hʹ(n) ≤ h*(n) ≤ h(n) for all n, then hʹ is admissible (e.g., see ACIJ)
Admissibility (contd)
■ If hʹ(n) = h*(n) then goal state is converged with no search
■ If hʹ overestimates h* à hʹ is worse (larger) than its actual optimal cost (i.e., hʹ(n) > h*(n) for some n) à hʹ is pessimistic and the node may not get chosen à could miss optimal solution (earlier example hʹ(C) = 4)
■ If hʹ never overestimates h* (i.e., hʹ(n) ≤ h*(n) for all n) à hʹ is better than its actual optimal cost admissible condition à hʹ is optimistic and the node gets chosen
• Search satisfies admissible condition is admissible
● Admissibility guarantees optimal solution if it exists • A* (satisfies admissible conditions) is complete and optimal Monotonicity
● For hʹ(goal) = 0, hʹ is monotone if for all n and its descendent m
■ hʹ(n) ≤ cost(n,m) + hʹ(m) Start S ● The above implies f ʹ(m) ≥ f ʹ(n) g(n) and thus (monotone non-decreasing gives) the name n ● Monotonicity ~ locally admissible
à reaching each state along optimal path cost(n,m)
thus, it guarantees optimal path to any state m h'(n) the first time the state is discovered
h'(m)
Goal G
Monotonicity (contd)
● Consequences of monotone heuristics in search algorithms
■ can ignore a state discovered a second time
■ no need to update the path information
● Monotonicity implies admissibility
● Uniform cost search gives optimal solution when it is monotone i.e., when cost(n,m) ≥ 0 Examples
• h1(n) = 0 for all n
• h2(n) = straight line distance from state n to a goal state
● h1 and h2 are admissible and monotonic
● The 8 puzzle: E.g.,
h3(n) = the number of tiles that are out of place from the goal h4 (n) = sum of distances out of place h5 (n) = 2 × the number of direct tile reversals
All are less than or equal to the number of moves required to move the tiles to the goal position (I.e., actual cost) à all are admissible
Informedness
● Let h1 and h2 be heuristics in two A* algorithms, h2 is more informed than h1 if (1) h1(n) ≤ h2(n) for all n, and (2) h1(m) < h2(m) for some m
E.g., h2 is more informed than h1 for h1(n) = 0 for all n, and
h2(n) = estimate distance from state n to a goal state
● More informed heuristics reduce search space A 4 Example: Consider two A* searches: B 5 C 3 D 5 1. f(n) = depth(n) + h1(n) 2. f(n) = depth(n) + h2(n) F G H 2 I 0 J Search 1 covers entire space Goal Search 2 covers partial space K L
Other heuristic searches
● Iterative improvement algorithms
● Hill climbing: moves to a better state
● Simulated annealing: random moves to escape local max
● Best-First Search
● Greedy search: expands the node closest to the goal
● A*: expands the node on the least-cost solution path
● Other search variations
■ AO*
■ Memory bounded search ● Iterative deepening A* (IDA*) ● Simplified memory-bounded A* (SMA*)
Applications of search algorithms
Two important problem classes:
● Game playing (discussed earlier)
● Constraint Satisfaction Problems (CSP) CSP
● States are defined by values of a set of variables
● Goal is a set of constraints of the values
● Solution specifies values of all variables such that the constraints are satisfied Real-world problems:
● Design VLSI layout
● Scheduling problems
CSP (contd)
1) x$2 2) x + y = z Search in CSP with Goal 3) y#z !3 4) x+y+z#12
(x, y, z) x=2 (2, y, z) propagate thru (2, y, 2+y) constraint 2) Start state Forward checking: no y satisfies 3) Backtrack x=4 (4, y, z) propagate thru (4, y, 4+y) y=2 (4, 2, 6) constraint 2) y=3 Solution
violates 4) (4, 3, 7) Arc consistency: delete y=3, z=7 Backtrack CSP (contd)
Techniques required
● Backtracking
● Forward checking
● Arc consistency which exhibits Constraint propagation Efficiency in searching in CSP depends on selecting
● which variable
● what value Heuristics in CSP:
● Most-constraining-variable less future variable choices
● Least-constraining-value more freedom for future values