ai 13lect.ppt
TRANSCRIPT
![Page 1: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/1.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 1
Artificial IntelligenceRepresentation and Search
Techniques
L. Manevitz
![Page 2: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/2.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 2
Goals of Lecture
• Representing Problems :– Various Issues and Considerations.– Production Systems.
• Production systems :– State Space.– Goals.– Transformation Rules.– Control (Search Techniques).
![Page 3: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/3.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 3
Elements of Production Systems
• Representation :– State Space.– Goal States.– Initial States.– Transformation Rules.
• Search Algorithms :– Uninformed.– “Heuristic”.
![Page 4: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/4.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 4
Examples of Problems
• “Toy” Problems :
– Water jug.
– Cannibals.
– 8 – Queens.
– 8 Puzzle.
![Page 5: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/5.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 5
Examples of Problems cont.
• “Real” Problems :• Schedules.• Traveling Salesman.• Robot navigation.• Language Analysis (Parsers,
Grammars).• VLSI design.
![Page 6: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/6.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 6
Points to Consider when Representing Problems
• Decomposable ?
• Can partial steps be ignored or undone ?
• Predictable ?
A
ABCB
C
Theorem proving vs. chess
Bridge
![Page 7: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/7.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 7
Points to Consider when Representing Problems cont.
• Is “good” solution easily recognizable ?
• Is Knowledge Base consistent ?
• How much Knowledge is needed ?
• Stand–alone vs. Inter–active.
Traveling Salesman
Big Data Base and limitations of logic
Chess, Newspaper-Understanding
![Page 8: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/8.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 8
Control
DATA
Rules
![Page 9: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/9.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 9
Issues In Representing Problem
1) Choice of representation of Data Base.1) Specify initial states2) Specify goal states
2) Appropriate Rules.1) Issues:
1) Assumptions in problem2) How general3) How much work pre-computed and put into rules
3) Control (later)
![Page 10: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/10.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 10
Water Jug Problem
3 liters 4 liters
<x, y> x, y real numbers
<x, y> x integers between 0 and 4
x, y between 0 and 4
![Page 11: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/11.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 11
Water Jugs cont.
• Rules :– <x,y> x<4 <4,y> ( Fill 4 liters )
– <x,y> y<3 <x,3> ( Fill 3 liters )
– <x,y> <o,y> ( Dump 4 liters )
– <x,y> <x,0> ( Dump 3 liters )
– <x,y> | x+y >= 4 <4,y-(4-x)>
– <x,y> | x+y >= 3 <x-(3-y),y>
– <x,y> | x+y <= 4 <x+y,0>
– <x,y> | x+y <= 3 <0,x+y>
![Page 12: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/12.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 12
Example no.1
• CHESS :– R1 – If pawn not blocked then move it
one space forward.
– R2 – If pawn in original position and not blocked for two spaces move it two spaces.
– Etc.
![Page 13: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/13.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 13
Example no.2
• SPEECH:
– R1 – If input not analyzed try and identify phonemes.
– R2 – Take some possible syllables and try and form words.
– Etc.
![Page 14: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/14.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 14
Production
1. DATA initial database.2. Until DATA satisfies termination
condition do:3. begin:
Select some rule, R, in the set of rules that can be applied to DATA.
DATA result of applying R to DATA.
4. end.
![Page 15: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/15.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 15
Problem Description
1) Define State Space containing all possible configurations of relevant objects.
2) Specify some states as initial states.
3) Specify some states as goal states.
4) Specify Rules
![Page 16: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/16.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 16
Search Through State-Space
Initial state
Goal state
![Page 17: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/17.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 17
Control Strategies
• What do we want?– Cause motion
– Be systematic
Examples
Breadth first
Depth first
Back Tracking
Hill Climbing
Best First
![Page 18: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/18.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 18
Control via Search Techniques
• “Uninformed” :– Breadth – First.– Depth – First.– Backtracking.
• “Informed” – Heuristic :– Hill Climbing.– Best First, A*.
![Page 19: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/19.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 19
Costs of Production System
Level of “Informedness”
CostRules
Control
Total Cost
![Page 20: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/20.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 20
Breadth First cont.
![Page 21: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/21.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 21
Breadth First
b = branching factor d=depth
1 + b + b + … + b
Time Complexity – O(b )
Space Complexity – O(b )
2 d
d
d
![Page 22: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/22.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 22
Breadth First fix exponents
Depth Nodes Time Memory
2 111 .1 sec 1 kb
4 11,111 11 sec 1 mega
6 10**6 18 min 111 mega
8 10**8 31 hours 11 giga
10 10**10 128 days 1 tera
12 10**12 35 years 111 tera
14 10**14 3500 years 11,111 tera
![Page 23: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/23.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 23
Depth First cont.
![Page 24: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/24.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 24
Depth First (some adjustments needed for depth bound)
DEPTH FIRST (INITIAL DATA)1. DATA INITIAL DATA2. IF DATA = GOAL THEN EXIT WITH NULL3. RULES APPRULES (DATA)4. IF RULES = NULL EXIT WITH FAILURE5. R FIRST (RULES)6. DATA R (DATA)7. IF DATA AT GOAL EXIT WITH R8. PATH DEPTH FIRST (DATA)9. IF PATH = FAILURE EXIT WITH FAILURE10. EXIT WITH R^PATH
![Page 25: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/25.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 25
Backtracking cont.
![Page 26: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/26.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 26
Backtracking Algorithm
BACKTRACK (DATA)1. IF TERMINAL (DATA) RETURN NULL2. IF DEADEND (DATA) RETURN FAIL3. RULES APPRULES (DATA)4. LOOP : IF RULES = NULL RETURN FAIL5. R BEST (RULES,DATA)6. RULES RULES – {R}7. NEWDATA R (DATA)8. PATH BACKTRACK (NEWDATA)9. IF PATH = FAIL THEN GO TO LOOP10. RETURN R^PATH
![Page 27: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/27.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 27
Backtracking
• Works like Depth First.• Stores only last path. • Disadvantages :
– May never terminate –• New nonterminal database always generates.
• Cycle.
– However can apply heuristics to choose –• Best rule.
• Better heuristics – less backtracking.
![Page 28: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/28.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 28
Backtracking cont.
Try a rule – if not successful go back and try a different one.
Example – try rules in this order: L, U, R, D.
Back up if – 1. Repeat position on path –
back to initial / state.
2. Whenever have already applied # of rules – depth bound.
3. When no more rules can be found.
![Page 29: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/29.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 29
Backtracking1 Algorithm(checking for loops)
BACKTRACK1 (DATALIST)1. DATA FIRST (DATALIST)2. IF MEMBER (DATA,TAIL(DATALIST)) RETURN FAIL3. IF TERMINAL (DATA) RETURN NULL4. IF DEADEND (DATA) RETURN FAIL5. IF LENGTH (DATALIST) > BOUND RETURN FAIL6. RULES APPRULES (DATA)7. LOOP : IF RULES = NULL RETURN FAIL8. R FIRST (RULES)9. RULES RULES -R10. RDATA R (DATA)11. RDATALIST CONS (RDATA,DATALIST)12. PATH BACKTRACK1 (RDATALIST)13. IF PATH = FAIL THEN GO TO LOOP14. RETURN CONS (R,PATH)
![Page 30: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/30.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 30
Search Tree
R1
R1
R2
R3
R5
R2
R1
R3 R2
R1
R2 R5
R3
R3
R1 R5
goal
![Page 31: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/31.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 31
8 Puzzle
• Problem :
• Data Base : 3x3 Matrix or a Vector with length 9.
• Rules : Precondition :1) Move Blank Left Not at extreme left2) Move Blank Right Not at extreme right3) Move Blank Up Not at top row4) Move Blank Down Not at bottom row
1 32
54
7
6
8 1 32
54
7 68
![Page 32: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/32.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 32
8 Puzzle cont.
• Initial State :Move Blank Up
Move Blank Up
Move Blank Left
Move Blank Down
Move Blank Right
• Goal State :
6 45
31
8
7
2
1 32
54
7 68
![Page 33: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/33.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 33
Hill Climbing
1) Use heuristic function as measure of how far off the number of tiles out of place.
2) Choose rule giving best increase in function.
![Page 34: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/34.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 34
Example
6 45
31
8
7
2
645
31
8
7
2
645
31 87
2
-4 -3 -3
U U L
645
31 87
2
645
318
7
2
645
3187
2
-2 -1 0
D R
![Page 35: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/35.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 35
Hill Climbing cont.
Problems :
1) Local Maxima – Initial Goal
2) Plateaus.
3) Ridge.
643
517
8
2
645
317
8
2
![Page 36: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/36.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 36
Control
Data Base (state) Data Base
Data BaseData Base
R2? R3?
R5?
![Page 37: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/37.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 37
Graphs - Digraphs
• Graph – Nodes and Edges.
• Digraph – Nodes and directed arcs.
• Tree – each Node has one parent :– Root – no parent.– Leaf – no successors.
• Path – n1…nk .
![Page 38: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/38.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 38
Graphs – Digraphs cont.
Implicit vs. Explicit Graph
generally, make explicit sub-graph of implicit graph.
Implicit Graph
Explicit Graph
![Page 39: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/39.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 39
Graph Search – Data Structures
• 2 List of “discovered nodes”– Open (not yet “expanded”)
– Closed (already “expanded”)
• Graph• Pointers on Graph (like “Hansel and Gretel”)
• The graph grows as nodes are expanded– Explicit versus Implicit Graph
![Page 40: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/40.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 40
Graph Search
1. G s ; Open s ; Closed NULL
2. LOOP: EXIT WITH FAILURE IF Open=NULL.
1. Take first node n from Open , Add to Closed.
2. If n is goal exit with SUCCESS. (solution obtained by pointer path from n to s).
3. Expand n : generate M set of Successors + add to G as successors to n.
![Page 41: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/41.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 41
Graph Search
4. For each m from M :1. If m is new add to Open and pointer back to n.
2. If m is already on Open, see if to redirect pointer to n.
3. If m already on Closed, see if to redirect pointer to n. Then check all descendants as well.
5. Reorder Open.
6. Go to LOOP.
![Page 42: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/42.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 42
Example
A node with not yet checked successors
A node with checked successors
![Page 43: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/43.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 43
Example cont.
The changes in the graph are :
![Page 44: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/44.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 44
Disadvantage of Graphs
1) Have to verify that a new node hasn’t appeared before (expensive).
2) If don’t verify – then redundant successor computations.
![Page 45: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/45.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 45
Ordering of Nodes (in Graph Search)
• Descending Order (expand deepest first) – Depth First Search (with cut-off).
• Ascending Order – Breadth First Search.
• Heuristic Best First - h(n) = g*(n) + d*(n)
A* Algorithm
![Page 46: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/46.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 46
Tree Search
• Form a Queue consisting of root node• Until Queue = Null or Goal achieved
– See if 1st element is goal. Do nothing if yes– If not, remove element from queue and add its
children• in back of queue (breadth-first)• in front of queue (depth-first)• re-sort queue (best-first)• front of queue (sorted by estimate) hill-climbing
![Page 47: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/47.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 47
A* Algorithm
• Two Lists –– Open.– Closed.
• Parent List.
• Heuristic Function
f*(n) = g*(n) + h*(n)
(cost of solution constrained through n)
![Page 48: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/48.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 48
A* Algorithm cont.
• Open = {s}; g*(s) = 0; f*(s) = h*(s)
Closed = NULL
• Open = NULL Return Failure
• Bestnode Best (Open)
• Open Open – {Bestnode}
• Goal (Bestnode) Return Solution
• Successors Successor (Bestnode)
![Page 49: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/49.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 49
A* Algorithm cont.
• For each S Successors Do:∈– Parent (S) Bestnode– g*(S) = g*(Bestnode) + c(Bestnode,S)– Does S Open ? (i.e. identify with OLD)∈
• Add OLD to Children (Bestnode)
• If g*(S) < g*(OLD)– g*(OLD) g*(S)
– Parent (OLD) Bestnode
– f*(OLD) g*(OLD) + h*(OLD)
![Page 50: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/50.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 50
A* Algorithm cont.
– Does S Closed ?∈• No
Add S to Children (Bestnode)
• Yes (identified with OLD)
Add OLD to Children (Bestnode)
• If g*(S) < g*(OLD)– g*(OLD) g*(S)
– Parent (OLD) Bestnode
– f*(OLD) g*(OLD) + h*(OLD)
![Page 51: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/51.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 51
A* Algorithm cont.
– Propagate change downwards
– Do Depth First traversal from OLD
– Terminate if g*(node) <= path from OLD
or w/o successors
or on Open
– Otherwise change g*(node)
f*(node)
change Parent (node)
![Page 52: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/52.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 52
Optimality of A*
• Heuristics: f(x) = g(x) +h(x)
• Here g(x) is estimate of g*(x) the actual cost to get to x from s.
• h(x) is estimate of h*(x) the miniml cost to get to any goal from x.– Choose g(x) to be cost in EXPLICIT GRAPH– Choose h(x) such that h(x) <= h*(x)
![Page 53: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/53.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 53
• In such a circumstance A* returns optimal path.
• Examples:• h(x) = 0 • For 8 puzzle h(x) = number of tiles in
wrong position• For 8 puzzle h(x) = sum of distances
each tile is from home• sequence scores P(x) + 3 S(x)
![Page 54: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/54.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 54
Proof of Optimality
ON Blackboard.Main points: If doesn’t terminate,
eventually all points in open have very large f value since they will have large g value.
But always a point in OPEN on optimal path;thus f value bounded.
Moreover just prior to termination, must choose a nodewith small f value; so cant terminate erroneously.
![Page 55: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/55.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 55
Proof (in more detail)
• Assuming there is a solution and an optimal one: • Let (s = n0, n1, n2, …, nk = goal) be an
optimal path.• Fact 1: There is always one element on the
optimal path on OPEN before success, for which all predecessors in this path are in CLOSED.– Proof: Initially s is on OPEN, then its children; if no
goal then let n be first one on path with this condition.
![Page 56: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/56.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 56
• Fact 2: For an element on optimal path in OPEN whose predecessors on path are in CLOSED,
f*(n) = g*(n) + h*(n) = g (n) +h*(n) < g(n)+h(n) = f (n) = f (s).
So always an element in OPEN with value smaller than true optimal cost from start (s).
![Page 57: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/57.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 57
• Fact 3: Each step in path takes at least an e >0.• So if node has shortest path to it of length d,
g*(n) > de.• So, if it does not terminate, eventually all nodes
on OPEN have arbitrarily large g*(n); hence f*(n)
• Hence eventually expands all nodes of each length (like breadth first).
![Page 58: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/58.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 58
• Fact 2 + Fact 3 means A* finds a solution.
• It is optimal solution since A* terminates either because OPEN is empty (FAILURE) or finds a Goal. By Fact 1, found a goal
• No non-optimal path: – Otherwise, last choice of node from OPEN with f(n)
=g(n) > f*(s). But by Fact 1, there was a better choice than n on optimal path and would not have chosen n.
– QED
![Page 59: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/59.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 59
AND/OR GRAPHS
• Hypergraphs.
• Hyperarcs connects node with SET of nodes.
• Connectors are 1-ary, 2-ary and so on.
![Page 60: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/60.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 60
Solution subgraph G’ of G from node n to N terminals
• If n in N, G’ is just n• If n has outgoing connector to set of nodes
a, b, c … such that there is solution graph from each of a, b ,c separately to N;
then G’ consists of n, connector, a, b, c, …
and each of the solution graphs from a, b,c…
Otherwise no solution graph exists
![Page 61: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/61.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 61
Costs
• Include cost of connector.
• Then cost from node n to N, k(n,N) is defined recursively by – if n in N k(n,N) = 0– n has connector to a, b, c … in solution graph
with cost c• k(n,N) = c + k(a, N) + k(b, N) + k (c, N) + …
![Page 62: AI 13Lect.ppt](https://reader034.vdocuments.mx/reader034/viewer/2022052216/543db056b1af9f3d0a8b496e/html5/thumbnails/62.jpg)
copyright 2005 all rights reserved
L. Manevitz Lecture 2 62
• Create a search graph G, consisting solely of start node, s. Put s on list OPEN
• Create a list called CLOSED = Null• LOOP: if OPEN = Null, exit FAILURE
– Move 1st node of OPEN, n, to CLOSED– If n GOAL exit with solution via pointers from n to s. (pointers
placed later)– Let M be set of successors of n, place in G– Make a pointer to n from members of M not already in G. Add
these members to OPEN.– For members of M already on OPEN decide if to change pointer to
n.– For members of M already on CLOSED
• Decide if to change pointer to n• Decide for each of its descendents in G whether to change pointer
Reorder OPENGO LOOP