AND/OR graphs Some problems are best represented as achieving subgoals, some of which achieved...

Post on 18-Jan-2018

212 views 0 download

description

AND/OR search  We must examine several nodes simultaneously when choosing the next move A B CD 38 E FG H I J (5) (10) (3) (4) (15)(10) A B C D (3) (4) (5) (9)

Transcript of AND/OR graphs Some problems are best represented as achieving subgoals, some of which achieved...

AND/OR graphsAND/OR graphs Some problems are best represented as Some problems are best represented as

achieving achieving subgoals, subgoals, some of which some of which achieved simultaneously and achieved simultaneously and independently (AND)independently (AND)

Up to now, only dealt with OR optionsUp to now, only dealt with OR options

Possess TV set

Steal TV Earn Money Buy TV

Searching Searching AND/OR graphsAND/OR graphs A solution in an AND-OR tree is a A solution in an AND-OR tree is a sub tree sub tree

whose whose leafsleafs are included in the goal set are included in the goal set

Cost function: sum of costs in AND nodeCost function: sum of costs in AND nodef(n) = f(nf(n) = f(n11) + f(n) + f(n22) + …. + f(n) + …. + f(nkk))

How can we extend A* to search AND/OR How can we extend A* to search AND/OR treestrees? The AO* algorithm.? The AO* algorithm.

AND/OR searchAND/OR search We must examine several nodeWe must examine several nodess

simultaneously when choosing the next simultaneously when choosing the next movemove

A

B C D38

E F G H I J17 9 27

(5) (10) (3) (4) (15) (10)

A

B C D(3)(4)

(5)(9)

AND/OR Best-First-SearchAND/OR Best-First-Search Traverse the graph (from the initial node) Traverse the graph (from the initial node)

following the best current path.following the best current path. Pick one of the unexpanded nodes on that Pick one of the unexpanded nodes on that

path and expand it. Add its successors to path and expand it. Add its successors to the graph and compute the graph and compute ff for each of themfor each of them

Change the expanded node’s Change the expanded node’s ff value to value to reflect its successors. Propagate the reflect its successors. Propagate the change up the graph. change up the graph.

Reconsider the current best solution and Reconsider the current best solution and repeatrepeat until a solution is found until a solution is found

AND/OR BestAND/OR Best-First-Search -First-Search exampleexample

A

B C D(3)(4)

(5)(9)

A(5)

2.1.

A

B CD

E F(4) (4)(10)

(3)(9)

(4)(10)

3.

AND/OR BestAND/OR Best-First-Search -First-Search exampleexample

B C D

G H E F(5) (7) (4) (4)(10)

(6)(12)

(4) (10)

4. A

A Longer path may be betterA Longer path may be better

B C D

G H E F

A

JI

Unsolvable B C D

G H E F

A

JI

Unsolvable

Interacting Sub goalsInteracting Sub goals

CD

E

A

(2)(5)

AO* algorithmAO* algorithm1.1. Let Let GG be a graph with only starting node be a graph with only starting node INIT.INIT.2.2. Repeat the followings until INIT is labeled SOLVED or Repeat the followings until INIT is labeled SOLVED or

h(INIT) > FUTILITYh(INIT) > FUTILITYa)a) Select an unexpanded node from the most promising path Select an unexpanded node from the most promising path

from from INIT (call it NODE)INIT (call it NODE)b)b) Generate successors of NODE. If there are none, set Generate successors of NODE. If there are none, set

h(NODE) = FUTILITY (i.e., NODE is unsolvable); otherwise h(NODE) = FUTILITY (i.e., NODE is unsolvable); otherwise for each SUCCESSOR that is not an ancestor of NODE do for each SUCCESSOR that is not an ancestor of NODE do the following:the following:

i.i. Add SUCCESSSOR to G.Add SUCCESSSOR to G.ii.ii. If SUCCESSOR is a terminal node, label it SOLVED and set If SUCCESSOR is a terminal node, label it SOLVED and set

h(SUCCESSOR) = 0.h(SUCCESSOR) = 0.iii.iii. If SUCCESSPR is not a terminal node, compute its hIf SUCCESSPR is not a terminal node, compute its h

AO* algorithm (Cont.)AO* algorithm (Cont.)c)c) Propagate the newly discovered information up the Propagate the newly discovered information up the

graph by doing the following: let S be set of SOLVED graph by doing the following: let S be set of SOLVED nodes or nodes whose h values have been changed nodes or nodes whose h values have been changed and need to have values propagated back to their and need to have values propagated back to their parents. Initialize S to Node. Until S is empty repeat parents. Initialize S to Node. Until S is empty repeat the followings:the followings:

i.i. Remove a node from S and call it CURRENT.Remove a node from S and call it CURRENT.ii.ii. Compute the cost of each of the arcs emerging from Compute the cost of each of the arcs emerging from

CURRENT. Assign minimum cost of its successors as its h.CURRENT. Assign minimum cost of its successors as its h.iii.iii. Mark the best path out of CURRENT by marking the arc that Mark the best path out of CURRENT by marking the arc that

had the minimum cost in step iihad the minimum cost in step iiiv.iv. Mark CURRENT as SOLVED if all of the nodes connected to Mark CURRENT as SOLVED if all of the nodes connected to

it through new labeled arc have been labeled SOLVEDit through new labeled arc have been labeled SOLVEDv.v. If CURRENT has been labeled SOLVED or its cost was just If CURRENT has been labeled SOLVED or its cost was just

changed, propagate its new cost back up through the graph. changed, propagate its new cost back up through the graph. So add all of the ancestors of CURRENT to S.So add all of the ancestors of CURRENT to S.

Real Time A*Real Time A* Considers the cost (> 0) for switching from one branch to Considers the cost (> 0) for switching from one branch to

another in the searchanother in the search Example: path finding in real lifeExample: path finding in real life

A CBDF E G

11 4 1 2 167

f(B) = 1 + 1 = 2f(B) = 1 + 1 = 2 (A) f(C) = 1 + 2 = 3 (A) f(C) = 1 + 2 = 3f(D) = 1 + 4 = 5f(D) = 1 + 4 = 5 (B) f(A) = 1 + 3 = 4 (B) f(A) = 1 + 3 = 4f(B) = 1 + 5 = 6 (A) f(C) = 1 + 2 = 3f(B) = 1 + 5 = 6 (A) f(C) = 1 + 2 = 3f(A) = 1 + 6 = 7f(A) = 1 + 6 = 7 (C) f(E) = 1 + 7 = 8 (C) f(E) = 1 + 7 = 8f(B) = 1 + 5 = 6f(B) = 1 + 5 = 6 (A) f(C) = 1 + 8 = 9 (A) f(C) = 1 + 8 = 9f(D) = 1 + 4 = 5 f(D) = 1 + 4 = 5 (B) f(A) = 1 + 9 = 10 (B) f(A) = 1 + 9 = 10f(F)=1+11= 12 (D) f(B) = 1 + 10 = 11f(F)=1+11= 12 (D) f(B) = 1 + 10 = 11

Another ExampleAnother Example

A B

C

S

(4)

(4) D

(5)2

(2)

G

(1)

E

(2)H

(0)

34

41

(5)

F2 13

2

Current State = SCurrent State = Sf(A) = 3 + 5 = 8 f(A) = 3 + 5 = 8 f(B) = 2 + 4 = 6f(B) = 2 + 4 = 6

Current State = BCurrent State = Bf(S) = 2 + 8 = 10 f(S) = 2 + 8 = 10 f(A) = 4 + 5 f(A) = 4 + 5 = 9= 9f(C) = 1 + 5 = 6f(C) = 1 + 5 = 6f(E) = 4 + 2 = 6f(E) = 4 + 2 = 6

Current State = CCurrent State = Cf(H) = 2 + 4 = 6f(H) = 2 + 4 = 6f(B) = 1 + 6 = 7f(B) = 1 + 6 = 7

Another ExampleAnother Example

A B

C

S

(4)

(4) D

(5)2

(2)

G

(1)

E

(2)H

(0)

34

41

(5)

F2 13

2

Current State = HCurrent State = Hf(C) = 2 + 7 = 9 f(C) = 2 + 7 = 9

Current State = CCurrent State = Cf(B) = 1 + 6 = 7f(B) = 1 + 6 = 7f(H) = f(H) =

Current State = BCurrent State = Bf(S) = 2 + 8 = 10f(S) = 2 + 8 = 10f(A) = 4 + 5 = 9f(A) = 4 + 5 = 9f(E) = 4 + 2 = 6f(E) = 4 + 2 = 6f(C) = f(C) =

Current State = ECurrent State = Ef(B) = 4 + 9 = 13f(B) = 4 + 9 = 13f(D) = 3 + 2 = 5f(D) = 3 + 2 = 5f(F) = 1 + 1 = 2f(F) = 1 + 1 = 2

Another ExampleAnother Example

A B

C

S

(4)

(4) D

(5)2

(2)

G

(1)

E

(2)H

(0)

34

41

(5)

F2 13

2

Current State = FCurrent State = Ff(E) = 2 + 5 = 7 f(E) = 2 + 5 = 7

Current State = ECurrent State = Ef(D) = 3 + 2 = 5f(D) = 3 + 2 = 5f(B) = 4 + 9 = 13f(B) = 4 + 9 = 13f(F) = f(F) =

Current State = DCurrent State = Df(G) = 2 + 0 = 2f(G) = 2 + 0 = 2f(E) = 3 + 13 = 16f(E) = 3 + 13 = 16

Visited Nodes =Visited Nodes =S, B, C, H, C, B, E, F, E, D, GS, B, C, H, C, B, E, F, E, D, G

Path = S, B, E, D, GPath = S, B, E, D, G