CSC344: AI for Games Lecture 4: Informed search

31
CSC344: AI for Games Lecture 4: Informed search Patrick Olivier [email protected]

description

CSC344: AI for Games Lecture 4: Informed search. Patrick Olivier [email protected]. Depth-first. Iterative deepening. Breadth-first. Uninformed search: summary. Informed search strategies. Best-first search Greedy best-first search A* search Heuristics Local search algorithms - PowerPoint PPT Presentation

Transcript of CSC344: AI for Games Lecture 4: Informed search

Page 1: CSC344: AI for Games Lecture 4: Informed search

CSC344: AI for Games

Lecture 4: Informed search

Patrick Olivier

[email protected]

Page 2: CSC344: AI for Games Lecture 4: Informed search

Uninformed search: summary

Breadth-first

Depth-first Iterative deepening

Page 3: CSC344: AI for Games Lecture 4: Informed search

Informed search strategies Best-first search Greedy best-first search A* search Heuristics Local search algorithms Hill-climbing search Simulated annealing search Local beam search Genetic algorithms

Page 4: CSC344: AI for Games Lecture 4: Informed search

Best-first search Important: A search strategy is defined by

picking the order of node expansion Uniform cost search uses cost so far: g(n) Best first search uses:

evaluation function: f(n) expand most desirable unexpanded node implementation: order the nodes in fringe in

decreasing order of f(n) Special cases:

greedy best-first search A* search

Page 5: CSC344: AI for Games Lecture 4: Informed search

Greedy best-first search Evaluation function f(n) = h(n) Heuristics are rules-of-thumb that are

likely (but not guaranteed) to help in problem solving

For example: hSLD(n) = straight-line distance from n to

Bucharest Greedy best-first search expands the

node that appears to be closest to goal

Page 6: CSC344: AI for Games Lecture 4: Informed search

Greedy search: Arad Bucharest

Straight line distance to Bucharest

Page 7: CSC344: AI for Games Lecture 4: Informed search

Greedy search: Arad Bucharest

Page 8: CSC344: AI for Games Lecture 4: Informed search

Greedy search: Arad Bucharest

Page 9: CSC344: AI for Games Lecture 4: Informed search

Greedy search: Arad Bucharest

Page 10: CSC344: AI for Games Lecture 4: Informed search

Greedy search: Arad Bucharest

Page 11: CSC344: AI for Games Lecture 4: Informed search

Properties of greedy search Complete?

In finite space if modified to detect repeated states

e.g., Iasi Neamt Iasi Neamt … Time?

O(bm) a good heuristic gives dramatic improvement

Space? O(bm) keeps all nodes in memory

Optimal? No

Page 12: CSC344: AI for Games Lecture 4: Informed search

A* search Idea: don’t just use estimate of distance to

the goal, but the cost of paths so far Evaluation function: f(n) = g(n) + h(n)

g(n) = cost so far to reach n h(n) = estimated cost from n to goal f(n) is estimated cost of path through n to goal

Class exercise: Arad Bucharest using A* and the staight line distance as hSLD(n)

Page 13: CSC344: AI for Games Lecture 4: Informed search

A* search: Arad Bucharest

Page 14: CSC344: AI for Games Lecture 4: Informed search

A* search: Arad Bucharest

Page 15: CSC344: AI for Games Lecture 4: Informed search

A* search: Arad Bucharest

Page 16: CSC344: AI for Games Lecture 4: Informed search

A* search: Arad Bucharest

Page 17: CSC344: AI for Games Lecture 4: Informed search

A* search: Arad Bucharest

Page 18: CSC344: AI for Games Lecture 4: Informed search

A* search: Arad Bucharest

Page 19: CSC344: AI for Games Lecture 4: Informed search

Admissible heuristics A heuristic h(n) is admissible if for every

node n, h(n) ≤ h*(n), where h*(n) is the true cost to reach the goal state from n.

An admissible heuristic never overestimates the cost to reach the goal, i.e. it is optimistic

Example: hSLD(n) (never overestimates the actual road distance)

Theorem: If h(n) is admissible, A* using tree-search is optimal

Page 20: CSC344: AI for Games Lecture 4: Informed search

Suppose some suboptimal goal G2 has been generated and is in the fringe. Let n be an unexpanded node in the fringe such that n is on a shortest path to an optimal goal G.

f(G2) = g(G2) since h(G2) = 0 g(G2) > g(G) since G2 is suboptimal f(G) = g(G) since h(G) = 0 f(G2) > f(G) from above

Proof of A* optimality of A* (1)

Page 21: CSC344: AI for Games Lecture 4: Informed search

Suppose some suboptimal goal G2 has been generated and is in the fringe. Let n be an unexpanded node in the fringe such that n is on a shortest path to an optimal goal G.

f(G2) > f(G) from above h(n) ≤ h^*(n) since h is admissibleg(n) + h(n) ≤ g(n) + h*(n) f(n) ≤ f(G)

Hence f(G2) > f(n), and A* will never select G2 for expansion

Proof of A* optimality of A* (2)

Page 22: CSC344: AI for Games Lecture 4: Informed search

Complete? Yes – unless there are infinitely many nodes f(n) ≤

f(G) Time?

Exponential unless the error in the heuristic grows no faster that the logarithm of the actual path cost

A* is an optimally efficient (no other algorithm is guaranteed to expand less nodes for the same heuristic)

Space? All nodes in memory (same as time complexity)

Optimal? Yes

Properties of A* search

)(log)()( ** nhOnhnh

Page 23: CSC344: AI for Games Lecture 4: Informed search

Heuristic functions sample heuristics for 8-puzzle:

h1(n) = number of misplaced tiles h2(n) = total Manhattan distance

h1(S) = ? h2(S) = ?

Page 24: CSC344: AI for Games Lecture 4: Informed search

Heuristic functions sample heuristics for 8-puzzle:

h1(n) = number of misplaced tiles h2(n) = total Manhattan distance

h1(S) = 8 h2(S) = 3+1+2+2+2+3+3+2 = 18 dominance:

h2(n) ≥ h1(n) for all n (both admissible) h2 is better for search (closer to

perfect) less nodes need to be expanded

Page 25: CSC344: AI for Games Lecture 4: Informed search

Example of dominance randomly generate 8-puzzle problems 100 examples for each solution depth contrast behaviour of heuristics &

strategies

d 2 4 6 8 10 12 14 16 18 20 22 24

IDS 10 112 680 6384 47127 … … … … … … …

A*(h1) 6 13 20 39 93 227 539 1301 3056 7276 18094 39135

A*(h2) 6 12 18 25 39 73 113 211 363 676 1219 1641

Page 26: CSC344: AI for Games Lecture 4: Informed search

Local search algorithms In many optimisation problems, paths

are irrelevant; goal state the solution State space = set of "complete"

configurations Find configuration satisfying

constraints, e.g., n-queens: n queens on an n ×n board with no two queens on the same row, column, or diagonal

Use local search algorithms which keep a single "current" state and try to improve it

Page 27: CSC344: AI for Games Lecture 4: Informed search

Hill-climbing search "climbing Everest in thick fog with

amnesia” we can set up an objective function to be

“best” when large (perform hill climbing)

…or we can use the previous formulation of heuristic and minimise the objective function (perform gradient descent)

Page 28: CSC344: AI for Games Lecture 4: Informed search

Local maxima/minina Problem: depending on

initial state, can get stuck in local maxima/minina

1/(1+H(n)) = 1/17

1/(1+H(n)) = 1/2

Local minima

Page 29: CSC344: AI for Games Lecture 4: Informed search

Simulated annealing search Idea: escape local maxima by allowing

some "bad" moves but gradually decrease their frequency and range (VSLI layout, scheduling)

Page 30: CSC344: AI for Games Lecture 4: Informed search

Local beam search Keep track of k states rather than just

one Start with k randomly generated states At each iteration, all the successors of

all k states are generated If any one is a goal state, stop; else

select the k best successors from the complete list and repeat.

Page 31: CSC344: AI for Games Lecture 4: Informed search

Genetic algorithm search A successor state is generated by

combining two parent states Start with k randomly generated states

(population) A state is represented as a string over a

finite alphabet (often a string of 0s and 1s) Evaluation function (fitness function).

Higher values for better states. Produce the next generation of states by

selection, crossover, and mutation