AND/OR graphs
 Some problems are best represented asSome problems are best represented as
achieving subgoals, some of whichachieving subgoals, some of which
achieved simultaneously andachieved 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 AND/OR graphs
 A solution in an AND-OR tree is aA solution in an AND-OR tree is a sub treesub tree
whosewhose leafsleafs are included in the goal setare included in the goal set
 Cost function: sum of costs in AND nodeCost function: sum of costs in AND node
f(n) = f(nf(n) = f(n11) + f(n) + f(n22) + …. + f(n) + …. + f(nkk))
 How can we extend A* to search AND/ORHow can we extend A* to search AND/OR
trees? The AO* algorithm.trees? The AO* algorithm.
AND/OR search
 We must examine several nodesWe must examine several nodes
simultaneously when choosing the nextsimultaneously when choosing the next
movemove
A
B C D
38
E F G H I J
17 9 27
(5) (10) (3) (4) (15) (10)
A
B C
D(3)
(4)
(5)
(9)
AND/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 thatPick one of the unexpanded nodes on that
path and expand it. Add its successors topath and expand it. Add its successors to
the graph and computethe graph and compute ff for each of themfor each of them
 Change the expanded node’sChange the expanded node’s ff value tovalue to
reflect its successors. Propagate thereflect its successors. Propagate the
change up the graph.change up the graph.
 Reconsider the current best solution andReconsider the current best solution and
repeat until a solution is foundrepeat until a solution is found
AND/OR Best-First-Search
example
A
B C
D(3)
(4)
(5)
(9)
A
(5)
2.1.
A
B C
D
E F(4) (4)
(10)
(3)
(9)
(4)
(10)
3.
AND/OR Best-First-Search
example
B C D
G H E F(5) (7) (4) (4)
(10)
(6)
(12)
(4) (10)
4.
A
A 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 goals
C
D
E
A
(2)(5)
AO* algorithm
1.1. LetLet GG be a graph with only starting nodebe a graph with only starting node INIT.INIT.
2.2. Repeat the followings until INIT is labeledRepeat the followings until INIT is labeled
SOLVED or h(INIT) > FUTILITYSOLVED or h(INIT) > FUTILITY
a)a) Select an unexpanded node from the most promisingSelect an unexpanded node from the most promising
path from INIT (call it NODE)path from INIT (call it NODE)
b)b) Generate successors of NODE. If there are none, setGenerate successors of NODE. If there are none, set
h(NODE) = FUTILITY (i.e., NODE is unsolvable);h(NODE) = FUTILITY (i.e., NODE is unsolvable);
otherwise for each SUCCESSOR that is not an ancestorotherwise for each SUCCESSOR that is not an ancestor
of NODE do the following:of NODE do the following:
i.i. Add SUCCESSSOR to G.Add SUCCESSSOR to G.
ii.ii. If SUCCESSOR is a terminal node, label it SOLVED andIf SUCCESSOR is a terminal node, label it SOLVED and
set h(SUCCESSOR) = 0.set 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.)
c)c) Propagate the newly discovered information up thePropagate the newly discovered information up the
graph by doing the following: let S be set of SOLVEDgraph by doing the following: let S be set of SOLVED
nodes or nodes whose h values have been changednodes or nodes whose h values have been changed
and need to have values propagated back to theirand need to have values propagated back to their
parents. Initialize S to Node. Until S is empty repeatparents. 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 fromCompute 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 thatMark the best path out of CURRENT by marking the arc that
had the minimum cost in step iihad the minimum cost in step ii
iv.iv. Mark CURRENT as SOLVED if all of the nodes connected toMark 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 SOLVED
v.v. If CURRENT has been labeled SOLVED or its cost was justIf 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.
An Example
An Example
A(8)
An Example
C
DB
A
(8)(1)
(2)
[12]
4 5
5
[13]
An Example
C
DB
A
(8)(4)
(2)
[15]
4 5
5
[13]
2
An Example
C
DB
A
(3)(4)
G
E
(2)
(1)
(0)
[15]
4 5
5
2
2
4
[8]
An Example
C
DB
A
(4)(4)
G
E
(2)
(3)
(0)
[15]
4 5
5
2
2
2
4
[9]
3
An Example
C
DB
A
(4)
G
E
(2)
(3)
(0)
[15]
4 5
5
2
2
2
4
Solved
3
Solved
Solved
 Considers the cost (> 0) for switching from one branch toConsiders 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 = 3
f(D) = 1 + 4 = 5f(D) = 1 + 4 = 5 (B) f(A) = 1 + 3 = 4(B) f(A) = 1 + 3 = 4
f(B) = 1 + 5 = 6 (A) f(C) = 1 + 2 = 3f(B) = 1 + 5 = 6 (A) f(C) = 1 + 2 = 3
f(A) = 1 + 6 = 7f(A) = 1 + 6 = 7 (C) f(E) = 1 + 7 = 8(C) f(E) = 1 + 7 = 8
f(B) = 1 + 5 = 6f(B) = 1 + 5 = 6 (A) f(C) = 1 + 8 = 9(A) f(C) = 1 + 8 = 9
f(D) = 1 + 4 = 5f(D) = 1 + 4 = 5 (B) f(A) = 1 + 9 = 10(B) f(A) = 1 + 9 = 10
f(F)=1+11= 12 (D) f(B) = 1 + 10 = 11f(F)=1+11= 12 (D) f(B) = 1 + 10 = 11
Real Time A*
 Considers the cost (> 0) for switching from one branch toConsiders 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 = 3
f(D) = 1 + 4 = 5f(D) = 1 + 4 = 5 (B) f(A) = 1 + 3 = 4(B) f(A) = 1 + 3 = 4
f(B) = 1 + 5 = 6 (A) f(C) = 1 + 2 = 3f(B) = 1 + 5 = 6 (A) f(C) = 1 + 2 = 3
f(A) = 1 + 6 = 7f(A) = 1 + 6 = 7 (C) f(E) = 1 + 7 = 8(C) f(E) = 1 + 7 = 8
f(B) = 1 + 5 = 6f(B) = 1 + 5 = 6 (A) f(C) = 1 + 8 = 9(A) f(C) = 1 + 8 = 9
f(D) = 1 + 4 = 5f(D) = 1 + 4 = 5 (B) f(A) = 1 + 9 = 10(B) f(A) = 1 + 9 = 10
f(F)=1+11= 12 (D) f(B) = 1 + 10 = 11f(F)=1+11= 12 (D) f(B) = 1 + 10 = 11
Another Example
Current State = SCurrent State = S
f(A) = 3 + 5 = 8f(A) = 3 + 5 = 8
f(B) = 2 + 4 = 6f(B) = 2 + 4 = 6
Current State = BCurrent State = B
f(S) = 2 + 8 = 10f(S) = 2 + 8 = 10
f(A) = 4 + 5 = 9f(A) = 4 + 5 = 9
f(C) = 1 + 5 = 6f(C) = 1 + 5 = 6
f(E) = 4 + 2 = 6f(E) = 4 + 2 = 6
Current State = CCurrent State = C
f(H) = 2 + 4 = 6f(H) = 2 + 4 = 6
f(B) = 1 + 6 = 7f(B) = 1 + 6 = 7
A B
C
S
(4)
(4) D
(5)
2
(2)
G
(1)
E
(2)H
(0)
3
4
41
(5)
F
2 13
2
Current State = HCurrent State = H
f(C) = 2 + 7 = 9f(C) = 2 + 7 = 9
Current State = CCurrent State = C
f(B) = 1 + 6 = 7f(B) = 1 + 6 = 7
f(H) =f(H) = ∞∞
Current State = BCurrent State = B
f(S) = 2 + 8 = 10f(S) = 2 + 8 = 10
f(A) = 4 + 5 = 9f(A) = 4 + 5 = 9
f(E) = 4 + 2 = 6f(E) = 4 + 2 = 6
f(C) =f(C) = ∞∞
Current State = ECurrent State = E
f(B) = 4 + 9 = 13f(B) = 4 + 9 = 13
f(D) = 3 + 2 = 5f(D) = 3 + 2 = 5
A B
C
S
(4)
(4) D
(5)
2
(2)
G
(1)
E
(2)H
(0)
3
4
41
(5)
F
2 13
2
Another Example
A B
C
S
(4)
(4) D
(5)
2
(2)
G
(1)
E
(2)H
(0)
3
4
41
(5)
F
2 13
2
Current State = FCurrent State = F
f(E) = 1 + 5 = 6f(E) = 1 + 5 = 6
Current State = ECurrent State = E
f(D) = 3 + 2 = 5f(D) = 3 + 2 = 5
f(B) = 4 + 9 = 13f(B) = 4 + 9 = 13
f(F) =f(F) = ∞∞
Current State = DCurrent State = D
f(G) = 2 + 0 = 2f(G) = 2 + 0 = 2
f(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
Another Example

Ai4 heuristic2

  • 1.
    AND/OR graphs  Someproblems are best represented asSome problems are best represented as achieving subgoals, some of whichachieving subgoals, some of which achieved simultaneously andachieved 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
  • 2.
    Searching AND/OR graphs A solution in an AND-OR tree is aA solution in an AND-OR tree is a sub treesub tree whosewhose leafsleafs are included in the goal setare included in the goal set  Cost function: sum of costs in AND nodeCost function: sum of costs in AND node f(n) = f(nf(n) = f(n11) + f(n) + f(n22) + …. + f(n) + …. + f(nkk))  How can we extend A* to search AND/ORHow can we extend A* to search AND/OR trees? The AO* algorithm.trees? The AO* algorithm.
  • 3.
    AND/OR search  Wemust examine several nodesWe must examine several nodes simultaneously when choosing the nextsimultaneously when choosing the next movemove A B C D 38 E F G H I J 17 9 27 (5) (10) (3) (4) (15) (10) A B C D(3) (4) (5) (9)
  • 4.
    AND/OR Best-First-Search  Traversethe 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 thatPick one of the unexpanded nodes on that path and expand it. Add its successors topath and expand it. Add its successors to the graph and computethe graph and compute ff for each of themfor each of them  Change the expanded node’sChange the expanded node’s ff value tovalue to reflect its successors. Propagate thereflect its successors. Propagate the change up the graph.change up the graph.  Reconsider the current best solution andReconsider the current best solution and repeat until a solution is foundrepeat until a solution is found
  • 5.
  • 6.
    AND/OR Best-First-Search example B CD G H E F(5) (7) (4) (4) (10) (6) (12) (4) (10) 4. A
  • 7.
    A Longer pathmay be better B C D G H E F A JI Unsolvable B C D G H E F A JI Unsolvable
  • 8.
  • 9.
    AO* algorithm 1.1. LetLetGG be a graph with only starting nodebe a graph with only starting node INIT.INIT. 2.2. Repeat the followings until INIT is labeledRepeat the followings until INIT is labeled SOLVED or h(INIT) > FUTILITYSOLVED or h(INIT) > FUTILITY a)a) Select an unexpanded node from the most promisingSelect an unexpanded node from the most promising path from INIT (call it NODE)path from INIT (call it NODE) b)b) Generate successors of NODE. If there are none, setGenerate successors of NODE. If there are none, set h(NODE) = FUTILITY (i.e., NODE is unsolvable);h(NODE) = FUTILITY (i.e., NODE is unsolvable); otherwise for each SUCCESSOR that is not an ancestorotherwise for each SUCCESSOR that is not an ancestor of NODE do the following:of NODE do the following: i.i. Add SUCCESSSOR to G.Add SUCCESSSOR to G. ii.ii. If SUCCESSOR is a terminal node, label it SOLVED andIf SUCCESSOR is a terminal node, label it SOLVED and set h(SUCCESSOR) = 0.set h(SUCCESSOR) = 0. iii.iii. If SUCCESSPR is not a terminal node, compute its hIf SUCCESSPR is not a terminal node, compute its h
  • 10.
    AO* algorithm (Cont.) c)c)Propagate the newly discovered information up thePropagate the newly discovered information up the graph by doing the following: let S be set of SOLVEDgraph by doing the following: let S be set of SOLVED nodes or nodes whose h values have been changednodes or nodes whose h values have been changed and need to have values propagated back to theirand need to have values propagated back to their parents. Initialize S to Node. Until S is empty repeatparents. 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 fromCompute 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 thatMark the best path out of CURRENT by marking the arc that had the minimum cost in step iihad the minimum cost in step ii iv.iv. Mark CURRENT as SOLVED if all of the nodes connected toMark 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 SOLVED v.v. If CURRENT has been labeled SOLVED or its cost was justIf 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.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
     Considers thecost (> 0) for switching from one branch toConsiders 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 = 3 f(D) = 1 + 4 = 5f(D) = 1 + 4 = 5 (B) f(A) = 1 + 3 = 4(B) f(A) = 1 + 3 = 4 f(B) = 1 + 5 = 6 (A) f(C) = 1 + 2 = 3f(B) = 1 + 5 = 6 (A) f(C) = 1 + 2 = 3 f(A) = 1 + 6 = 7f(A) = 1 + 6 = 7 (C) f(E) = 1 + 7 = 8(C) f(E) = 1 + 7 = 8 f(B) = 1 + 5 = 6f(B) = 1 + 5 = 6 (A) f(C) = 1 + 8 = 9(A) f(C) = 1 + 8 = 9 f(D) = 1 + 4 = 5f(D) = 1 + 4 = 5 (B) f(A) = 1 + 9 = 10(B) f(A) = 1 + 9 = 10 f(F)=1+11= 12 (D) f(B) = 1 + 10 = 11f(F)=1+11= 12 (D) f(B) = 1 + 10 = 11 Real Time A*  Considers the cost (> 0) for switching from one branch toConsiders 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 = 3 f(D) = 1 + 4 = 5f(D) = 1 + 4 = 5 (B) f(A) = 1 + 3 = 4(B) f(A) = 1 + 3 = 4 f(B) = 1 + 5 = 6 (A) f(C) = 1 + 2 = 3f(B) = 1 + 5 = 6 (A) f(C) = 1 + 2 = 3 f(A) = 1 + 6 = 7f(A) = 1 + 6 = 7 (C) f(E) = 1 + 7 = 8(C) f(E) = 1 + 7 = 8 f(B) = 1 + 5 = 6f(B) = 1 + 5 = 6 (A) f(C) = 1 + 8 = 9(A) f(C) = 1 + 8 = 9 f(D) = 1 + 4 = 5f(D) = 1 + 4 = 5 (B) f(A) = 1 + 9 = 10(B) f(A) = 1 + 9 = 10 f(F)=1+11= 12 (D) f(B) = 1 + 10 = 11f(F)=1+11= 12 (D) f(B) = 1 + 10 = 11
  • 19.
    Another Example Current State= SCurrent State = S f(A) = 3 + 5 = 8f(A) = 3 + 5 = 8 f(B) = 2 + 4 = 6f(B) = 2 + 4 = 6 Current State = BCurrent State = B f(S) = 2 + 8 = 10f(S) = 2 + 8 = 10 f(A) = 4 + 5 = 9f(A) = 4 + 5 = 9 f(C) = 1 + 5 = 6f(C) = 1 + 5 = 6 f(E) = 4 + 2 = 6f(E) = 4 + 2 = 6 Current State = CCurrent State = C f(H) = 2 + 4 = 6f(H) = 2 + 4 = 6 f(B) = 1 + 6 = 7f(B) = 1 + 6 = 7 A B C S (4) (4) D (5) 2 (2) G (1) E (2)H (0) 3 4 41 (5) F 2 13 2
  • 20.
    Current State =HCurrent State = H f(C) = 2 + 7 = 9f(C) = 2 + 7 = 9 Current State = CCurrent State = C f(B) = 1 + 6 = 7f(B) = 1 + 6 = 7 f(H) =f(H) = ∞∞ Current State = BCurrent State = B f(S) = 2 + 8 = 10f(S) = 2 + 8 = 10 f(A) = 4 + 5 = 9f(A) = 4 + 5 = 9 f(E) = 4 + 2 = 6f(E) = 4 + 2 = 6 f(C) =f(C) = ∞∞ Current State = ECurrent State = E f(B) = 4 + 9 = 13f(B) = 4 + 9 = 13 f(D) = 3 + 2 = 5f(D) = 3 + 2 = 5 A B C S (4) (4) D (5) 2 (2) G (1) E (2)H (0) 3 4 41 (5) F 2 13 2 Another Example
  • 21.
    A B C S (4) (4) D (5) 2 (2) G (1) E (2)H (0) 3 4 41 (5) F 213 2 Current State = FCurrent State = F f(E) = 1 + 5 = 6f(E) = 1 + 5 = 6 Current State = ECurrent State = E f(D) = 3 + 2 = 5f(D) = 3 + 2 = 5 f(B) = 4 + 9 = 13f(B) = 4 + 9 = 13 f(F) =f(F) = ∞∞ Current State = DCurrent State = D f(G) = 2 + 0 = 2f(G) = 2 + 0 = 2 f(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 Another Example