Top Banner
CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH, A* 10/9/2013 Santiago Ontañón [email protected] https://www.cs.drexel.edu/~santi/teaching/2013/CS380/intro.html
51

CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Apr 08, 2019

Download

Documents

votruc
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED SEARCH, A*

10/9/2013 Santiago Ontañón [email protected] https://www.cs.drexel.edu/~santi/teaching/2013/CS380/intro.html

Page 2: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Clarification • Repeated-state checking:

•  When the search state is a graph strategies like DFS can get stuck in loops.

•  Algorithms need to keep a list (CLOSED) of already visited nodes.

•  In DFS: •  If we want to avoid repeating states completely, we need to keep

ALL the visited states in memory (in the CLOSED list) •  If we just want to avoid loops, we only need to remember the

current branch (linear memory as a function of “m”)

Page 3: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

• Problem Solving: •  Problem Formulation •  Finding a solution:

•  Uninformed search: •  When the agent has no additional information of the domain (DFS, BFS, ID)

•  Informed search: •  Heuristics •  Greedy-search •  A*

Page 4: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Recall: Evaluation Function •  Idea: represent the information we have about the domain

as an “evaluation function” h

• Evaluation function (heuristic): •  Given a state s •  h(s) it estimates how close or how far it is from the goal

• Example: •  In a maze solving problem: Euclidean distance to the goal

Page 5: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* • At each cycle, A* expands the node with the lowest f(n):

•  f(n) = g(n) + h(n)

•  g(n): cost of path from start to n •  h(n): evaluation function

• A* implementations assume repeated state checking (i.e. assume search space is a graph): •  OPEN: list of nodes that need to be expanded •  CLOSED: list of nodes that have already been expanded

Page 6: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Example: A*

Goal

Start

Start

Heuristic used: Manhattan Distance

OPEN = [Start] CLOSED = []

Page 7: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Example: A*

Goal

Start g = 0 h = 3

Start 3

Assigns an “estimated cost”, f, to each node:

f(n) = g(n) + h(n)

Real cost from Start to n

Heuristic

Heuristic used: Manhattan Distance

OPEN = [Start] CLOSED = []

Page 8: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Example: A*

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

C g = 1 h = 4

Start 3

A 3

B 5

C 5

Expands the node with the lowest Estimated cost first

OPEN = [A,B,C] CLOSED = [Start]

Page 9: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Example: A*

D g = 2 h = 3

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

C g = 1 h = 4

Start 3

A 3

B 5

C 5

D 5

OPEN = [B, C, D] CLOSED = [Start, A]

Page 10: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Example: A*

D g = 2 h = 3

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

E g = 2 h = 5

C g = 1 h = 4

E 7

Start 3

A 3

B 5

C 5

D 5

OPEN = [C, D, E] CLOSED = [Start, A, B]

Page 11: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Example: A*

D g = 2 h = 3

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

E g = 2 h = 5

C g = 1 h = 4

F g = 2 h = 3

G g = 2 h = 5

F 5

G 7

E 7

Start 3

A 3

B 5

C 5

D 5

OPEN = [D, E, F, G] CLOSED = [Start, A, B, C]

Page 12: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Example: A*

D g = 2 h = 3

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

E g = 2 h = 5

C g = 1 h = 4

F g = 2 h = 3

G g = 2 h = 5

F 5

G 7

E 7

Start 3

A 3

B 5

C 5

D 5

OPEN = [E, F, G] CLOSED = [Start, A, B, C, D]

Page 13: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Example: A*

D g = 2 h = 3

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

E g = 2 h = 5

C g = 1 h = 4

F g = 2 h = 3

J g = 3 h = 2

G g = 2 h = 5

I g = 3 h = 4

I 7

J 5

F 5

G 7

E 7

Start 3

A 3

B 5

C 5

D 5

OPEN = [E, G, I, J] CLOSED = [Start, A, B, C, D, F]

Page 14: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Example: A*

D g = 2 h = 3

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

L g = 4 h = 1

E g = 2 h = 5

C g = 1 h = 4

F g = 2 h = 3

J g = 3 h = 2

G g = 2 h = 5

I g = 3 h = 4

K g = 4 h = 3

I 7

J 5

F 5

G 7

E 7

Start 3

A 3

B 5

C 5

D 5

L 5

K 7

OPEN = [E, G, I, K, L] CLOSED = [Start, A, B, C, D, F, J]

Page 15: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Example: A*

D g = 2 h = 3

A g = 1 h = 2

Goal g = 5 h = 0

B g = 1 h = 4

Start g = 0 h = 3

L g = 4 h = 1

E g = 2 h = 5

C g = 1 h = 4

F g = 2 h = 3

J g = 3 h = 2

G g = 2 h = 5

I g = 3 h = 4

K g = 4 h = 3

I 7

J 5

F 5

G 7

E 7

Start 3

A 3

B 5

C 5

D 5

L 5

K 7

Goal 5

OPEN = [E, G, I, K, Goal] CLOSED = [Start, A, B, C, D, F, J, L]

Page 16: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Example: A*

D g = 2 h = 3

A g = 1 h = 2

Goal g = 5 h = 0

B g = 1 h = 4

Start g = 0 h = 3

L g = 4 h = 1

E g = 2 h = 5

C g = 1 h = 4

F g = 2 h = 3

J g = 3 h = 2

G g = 2 h = 5

I g = 3 h = 4

K g = 4 h = 3

I 7

J 5

F 5

G 7

E 7

Start 3

A 3

B 5

C 5

D 5

L 5

K 7

Goal 5

OPEN = [E, G, I, K] CLOSED = [Start, A, B, C, D, F, J, L, Goal]

Page 17: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Example: A*

D g = 2 h = 3

A g = 1 h = 2

Goal g = 5 h = 0

B g = 1 h = 4

Start g = 0 h = 3

L g = 4 h = 1

E g = 2 h = 5

C g = 1 h = 4

F g = 2 h = 3

J g = 3 h = 2

G g = 2 h = 5

I g = 3 h = 4

K g = 4 h = 3

I 7

J 5

F 5

G 7

E 7

Start 3

A 3

B 5

C 5

D 5

L 5

K 7

Goal 5

OPEN = [E, G, I, K] CLOSED = [Start, A, B, C, D, F, J, L, Goal]

Page 18: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

Page 19: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

Differences wrt Breadth First Search

Page 20: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

Goal

Start

Nodes in red are in CLOSED Nodes in grey are in OPEN

Page 21: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

Goal

Start g = 0

Nodes in red are in CLOSED Nodes in grey are in OPEN

Page 22: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

Goal

Start g = 0 h = 3

Nodes in red are in CLOSED Nodes in grey are in OPEN

Page 23: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

Goal

Start g = 0 h = 3

Nodes in red are in CLOSED Nodes in grey are in OPEN

Page 24: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

Goal

Start g = 0 h = 3

Nodes in red are in CLOSED Nodes in grey are in OPEN

Page 25: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

Goal

Start g = 0 h = 3

Nodes in red are in CLOSED Nodes in grey are in OPEN

Page 26: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

Goal

Start g = 0 h = 3

Nodes in red are in CLOSED Nodes in grey are in OPEN

N

Page 27: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

Goal

Start g = 0 h = 3

Nodes in red are in CLOSED Nodes in grey are in OPEN

N

Page 28: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

Goal

Start g = 0 h = 3

Nodes in red are in CLOSED Nodes in grey are in OPEN

N

Page 29: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

Goal

Start g = 0 h = 3

Nodes in red are in CLOSED Nodes in grey are in OPEN

N children(N)

Page 30: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

A

Goal

B

Start g = 0 h = 3

C

Nodes in red are in CLOSED Nodes in grey are in OPEN

N children(N) M

Page 31: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

A

g = 1

Goal

B

Start g = 0 h = 3

C

Nodes in red are in CLOSED Nodes in grey are in OPEN

N children(N) M

Page 32: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

A g = 1 h = 2

Goal

B

Start g = 0 h = 3

C

Nodes in red are in CLOSED Nodes in grey are in OPEN

N children(N) M

Page 33: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

A g = 1 h = 2

Goal

B

Start g = 0 h = 3

C

Nodes in red are in CLOSED Nodes in grey are in OPEN

N children(N) M

Page 34: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

C

Nodes in red are in CLOSED Nodes in grey are in OPEN

N children(N)

M

Page 35: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

C g = 1 h = 4

Nodes in red are in CLOSED Nodes in grey are in OPEN

N children(N)

M

Page 36: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

C g = 1 h = 4

Nodes in red are in CLOSED Nodes in grey are in OPEN

N

Page 37: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

C g = 1 h = 4

Nodes in red are in CLOSED Nodes in grey are in OPEN

N

Page 38: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

C g = 1 h = 4

Nodes in red are in CLOSED Nodes in grey are in OPEN

Page 39: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

C g = 1 h = 4

Nodes in red are in CLOSED Nodes in grey are in OPEN

N

Page 40: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

C g = 1 h = 4

Nodes in red are in CLOSED Nodes in grey are in OPEN

N

Page 41: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Start.g = 0; Start.h = heuristic(Start) OPEN = [Start]; CLOSED = [] WHILE OPEN is not empty

N = OPEN.removeLowestF() IF goal(N) RETURN path to N CLOSED.add(N) FOR all children M of N not in CLOSED:

M.parent = N M.g = N.g + 1; M.h = heuristic(M) OPEN.add(M)

ENDFOR ENDWHILE

A g = 1 h = 2

Goal

B g = 1 h = 4

Start g = 0 h = 3

C g = 1 h = 4

Nodes in red are in CLOSED Nodes in grey are in OPEN

N

Page 42: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Implementation Notes • Remember the distinction between state and node • State:

•  The configuration of the problem (e.g. coordinates of a robot, positions of the pieces in the 8-puzzle, etc.)

• Node: •  A state plus: current cost (g), current heuristic (h), parent node,

action that got us here form the parent node •  It is important to remember who was the parent, and which action,

so that once the solution is found, we can reconstruct the path

Page 43: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Intuition •  The heuristic biases the search of the algorithm towards

the goal:

Start

Goal

Breadth First

Search

No bias

Page 44: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Intuition •  The heuristic biases the search of the algorithm towards

the goal:

Start

Goal

Breadth First

Search

No bias

A*

Biased towards the

goal

Page 45: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Admissible Heuristics •  To ensure optimality, A* requires the heuristic to be

admissible:

•  In other words: the heuristic underestimates the actual remaining cost to the goal.

h(n) ≤ h*(n) Actual cost to the goal

Page 46: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Consistent Heuristics Proof of lemma: Consistency

A heuristic is consistent if

nc(n,a,n’)

h(n’)

h(n)

G

n’

h(n) ! c(n, a, n!) + h(n!)

If h is consistent, we have

f(n!) = g(n!) + h(n!)

= g(n) + c(n, a, n!) + h(n!)

" g(n) + h(n)

= f(n)

I.e., f(n) is nondecreasing along any path.

Chapter 4, Sections 1–2 30

Page 47: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* Optimality Proof Optimality of A! (standard proof)

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

G

n

G2

Start

f(G2) = g(G2) since h(G2) = 0

> g(G1) since G2 is suboptimal

! f(n) since h is admissible

Since f(G2) > f(n), A! will never select G2 for expansion

Chapter 4, Sections 1–2 23

Page 48: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Heuristic Dominance Dominance

If h2(n) ! h1(n) for all n (both admissible)then h2 dominates h1 and is better for search

Typical search costs:

d = 14 IDS = 3,473,941 nodesA!(h1) = 539 nodesA!(h2) = 113 nodes

d = 24 IDS " 54,000,000,000 nodesA!(h1) = 39,135 nodesA!(h2) = 1,641 nodes

Given any admissible heuristics ha, hb,

h(n) = max(ha(n), hb(n))

is also admissible and dominates ha, hb

Chapter 4, Sections 1–2 33

Page 49: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Constructing Heuristics by Relaxation Relaxed problems

Admissible heuristics can be derived from the exactsolution cost of a relaxed version of the problem

If the rules of the 8-puzzle are relaxed so that a tile can move anywhere,then h1(n) gives the shortest solution

If the rules are relaxed so that a tile can move to any adjacent square,then h2(n) gives the shortest solution

Key point: the optimal solution cost of a relaxed problemis no greater than the optimal solution cost of the real problem

Chapter 4, Sections 1–2 34

Page 50: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

A* everywhere… • Even for videogame playing:

•  http://www.youtube.com/watch?v=DlkMs4ZHHr8

Page 51: CS 380: ARTIFICIAL INTELLIGENCE PROBLEM SOLVING: INFORMED ...santi/teaching/2013/CS380/slides/CS380...Clarification • Repeated-state checking: • When the search state is a graph

Variations of A* • SMA*: A* with bounded memory usage

•  TBA*: A* for real-time domains where we have a bounded time before producing an action

•  LRTA*: another real-time version of A* (very simple, and the basis of a whole family of algorithms)

• D*: A* for dynamic domains (problem configuration can change)

•  etc.