Download - CS 385 Fall 2006 Chapter 3
![Page 1: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/1.jpg)
1
CS 385 Fall 2006Chapter 3
Structures and Strategies for State Space Search
![Page 2: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/2.jpg)
2
Where are we?
Predicate calculus: – a way to describe objects and relationships
Inference rules: – a way to infer new knowledge, defining a state space that is
searched to find a solution to a problem
Strategy– generate all possible elements of the state space and see if your
answer is there
– works for tic-tac-toe
– doesn't work for chess
Goal: intelligent ways to search a state space
Tool: state space graphs.
![Page 3: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/3.jpg)
3
Famous example: Konigsburg bridge problem
Is there a walk that crosses each bridge exactly once?
Can we represent this in a better way?
![Page 4: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/4.jpg)
4
Graph of the Königsberg bridge system:
Predicate calculus representation: connect(i1,i2, b1) ....
![Page 5: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/5.jpg)
5
Euler's Proof
A node is odd or even depending on the number of arcs leading into it
Odd degree nodes can only be at the beginning of the path
A walk must contain 0 or 2 odd nodes (why?)
Is there a path?
Does predicate calculus suffice for this argument?
No, no notion of odd/even
We need graph theory to do more with this.
![Page 6: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/6.jpg)
6
What are N, A, S, and GD for tic-tac-toe?N could be all possible configurations of 0s and 1s or just reachable ones.A: allowable moves between boardsS: empty board, GD winning boards
![Page 7: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/7.jpg)
7
The 8 Puzzle
N = 3 x 3 configurations of tiles 1-8 and 1 blank
Start state:
Goal state:
Arcs: move the blank up/down/left/right
![Page 8: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/8.jpg)
8
Figure 3.6: State space of the 8-puzzle generated by “move blank” operations.
Is this like tic-tac toe? No, you might go around in circles
![Page 9: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/9.jpg)
9
Traveling Salesperson
N= cities
A = paths between cities with weights (mileage, time, cost)
S = home
GD = home
Path: visit each exactly once
Goal: minimize something
![Page 10: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/10.jpg)
10
Figure 3.8: Search of the traveling salesperson problem. Each arc is marked with the total weight of all paths from the start node (A) to its endpoint.
![Page 11: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/11.jpg)
11
Traveling Salesperson
How many potential paths?
Can we solve this for 50 states?
Of great interest to people who like algorithms because it gets large so fast.
Exhaustive search out of the question
![Page 12: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/12.jpg)
12
Figure 3.9: The traveling salesperson problem with the nearest neighbor path in bold. Note that this path (A, E, D, B, C, A), at a cost of 550, is not the shortest. The comparatively high cost of arc (C, A) defeated the heuristic.
![Page 13: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/13.jpg)
13
Data- versus Goal-Driven for Finding a Route from Aurora to LA
Where you start. E.g. routes from Aurora to LA
Data driven (forward chaining)From Aurora one can get to x, y, z...
From x one can get to ..
From y one can get to ...
Keep checking to see if LA ends up in one of the destinations
Goal driven (backward chaining)One can get to LA from x, y, z...
One can get to x from ..
One can get to y from
Keep checking to see if Aurora ends up in one of the sources
![Page 14: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/14.jpg)
14
Better examples
Lineage: am I related to Reverend Thomas Carter?
Which is better, data or goal driven?
Could I prune extraneous paths?
Is this the same as "Am I related to Thomas Jefferson"?
![Page 15: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/15.jpg)
15
Medical Diagnosis
"Do I have strep throat" vs. "What disease do I have"
strep symptoms vs. lots of symptoms
take a culture vs. run a spectrum of tests
Which is data-driven/forward chaining?
Which is goal-driven/backward chaining?
![Page 16: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/16.jpg)
16
Backtracking
A technique for systematically trying all paths through a state space.
Begin at start and pursue a path until goal or dead end
If dead end, backtrack to most recent node with unexamined siblings
E.g. is 6 in this tree?
1 Possible trials:
1 2 4 5 3 6
2 3 1 3 7 6
1 3 6
4 5 6 7 How do we pick the "best" path?
![Page 17: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/17.jpg)
17
Function backtrack algorithm (general, no examination order specified)
CS: current stateSL: states in current pathNSL states awaiting evaluationDE: dead ends
typo in book, p should be ≠
![Page 18: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/18.jpg)
18
A trace of backtrack on the graph of figure 3.12
![Page 19: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/19.jpg)
19
A trace of backtrack on the graph of figure 3.12
![Page 20: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/20.jpg)
20
A trace of backtrack on the graph of figure 3.12
![Page 21: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/21.jpg)
21
A trace of backtrack on the graph of figure 3.12
![Page 22: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/22.jpg)
22
Observations
No order is specified for adding nodes to NSL (opportunity for intelligence)
SL gives us the path to the current solution(hence to the goal at the end)
When C is the current state, F is not added to NSL (because it is in DE)
![Page 23: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/23.jpg)
23
How used on a maze?ifgoal return successelse try north try east try south try west backtrack
Track:• where you are• where you can go from each state• where you came from• visited states
![Page 24: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/24.jpg)
24
Function breadth_first search algorithm
X is CS in backtrack, closed = DE + SL
![Page 25: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/25.jpg)
25
breadth_first_search on Figure 3.13
open closed[A] [ ][B C D] [A][C D E F] [B A][D E F G H] [C B A][E F G H I J] [D C B A][F G H I J K L] [E D C B A][G H I J K L M] [F E D C B A][H I J K L M N] [G F E D B C A][I J K L M N O P] [F T L S K E B A][J K L M N O P Q] [M F T L S K E B A][K L M N O P Q R] [J M F T L S K E B A]
![Page 26: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/26.jpg)
26
Observations
Cleaner
But no path to start state
Solution: associate the parent with each node. E.g. [B, C, D] → [(B,A), (C,A), (D,A)]
[C, D, E, F] → [(C,A), (D,A), (B,A), (F, B)]
Is the first algorithm ever better?
![Page 27: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/27.jpg)
27
depth_first_search on Figure 3.13
Put new nodes at the beginning
of the open list.
open closed
[A] [ ]
[B C D] [A]
[E F C D] [B A]
[K L F C D] [E B A]
[S L F C D] [K E B A]
[L F C D] [S K E B A]
[T F C D] [L S K E B A]
[F C D] [T L S K E B A]
[M C D] [F T L S K E B A]
[C D] [M F T L S K E B A]
[G H D] [C M F T L S K E B A]
![Page 28: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/28.jpg)
28
Comparison
BFS finds the shortest path
DFS gets quickly into a deep search space
good if you know the solution is "far away"
wrong path: inefficient
DFS with iterative deepeninguse a depth bound
retreat at the bound
no luck: increase the bound
Later: use knowledge about the problem to order nodes on the open list
![Page 29: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/29.jpg)
29
Using State Space to Represent Predicate Calculus
node: state of the problem
arc: inference
search: to decide if an assertion is implied by others
q → p p
r → p
v → q q r u
s → r
t → r v t s
s → u
s, t Determining truth: path from boxed nodes to proposition
Data-driven: start with boxed; goal-driven: start with goal.
DFS or BFS?
![Page 30: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/30.jpg)
30
Is p true?
BFS
open closed
[t s] []
[s r] [t]
[r u] [s t]
[u p] [r s t]
[p] [u r s t]
p
q r u
v t s
![Page 31: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/31.jpg)
31
Is p true?
DFS
open closed
[t s] []
[r s] [t]
[p u] [r t]
p
q r u
v t s
![Page 32: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/32.jpg)
32
And/Or Graphs
in the graph above t s →r: r
t s
To express t s →r, connect incoming arcs
r
t s
![Page 33: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/33.jpg)
33
Example 3.3.2
a
b
c
a b → d
a c → e
b d → f
f → g
a e → h
Graph?
![Page 34: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/34.jpg)
34
Example 3.3.2
a
b
c
a b → d
a c → e
b d → f
f → g
a e → h
![Page 35: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/35.jpg)
35
Search for h:
Goal-directed:
h: try to prove a and e
a is true
e is true if c and a
a is true
c is true
← e is true
← h is true
Data-directed:
a, b, c are true
a and b → d
a and c → e
a and e → h
![Page 36: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/36.jpg)
36
Symbolic Integration
MACSYMA Symbolic algebra, including integration
http://integrals.wolfram.com/index.jsp
How do you think this works?
Decomposition using and/or graphs
∫f + g decomposes to ∫f and ∫g
More complicated expressions decompose into possible transformations
Graph is generated on the fly
Goal-directed
How is it searched? BFS? DFS?
![Page 37: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/37.jpg)
37
Figure 3.24:
![Page 38: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/38.jpg)
38
And/Or for Financial Advisor?
![Page 39: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/39.jpg)
39
Figure 3.26: And/or graph for the financial advisor
![Page 40: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/40.jpg)
40
Five rules for a simple subset of English grammar (rewrite rules):
Does 1 look like AND?
Do 2 and 3 this look like OR?
Construct the graph
![Page 41: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/41.jpg)
41
Figure 3.27: And/or graph for the grammar of Example 3.3.6.
How do we use this?A sentence is well-formed if it consistsof terminal symbols and there is a series of substitutions that reduce it to the sentence symbol
![Page 42: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/42.jpg)
42
Figure 3.28: Parse tree for “The dog bites the man.” Note that this is a subtree Figure 3.26.
![Page 43: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/43.jpg)
43
Parse "the dog bites the man"
7: art ↔ the gives art dog bites the man
7: art ↔ the gives art dog bites art man
8: n ↔ man gives art dog bites art n*
3: np ↔ art n gives art dog bites np**
9: n ↔ dog gives art n bites np
3: np↔ art n gives np bites np
11: v ↔ bites gives np v bites
5: vp ↔ v np gives np vp
1: sentence ↔ np vp ...
* Why isn't dog rewritten first?
** Why didn't 11 fire instead:
v ↔ bites gives art n v the man
![Page 44: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/44.jpg)
44
Parse "dog the man"
7: art ↔ the gives dog art man
8: n ↔ man gives dog art man
9: n ↔ dog gives n art n
There are no rules that rewrite this
How does the C++ compiler work?
Can you write a grammer for C++?program ↔ declarations body
...
![Page 45: CS 385 Fall 2006 Chapter 3](https://reader036.vdocument.in/reader036/viewer/2022081519/56814548550346895db21765/html5/thumbnails/45.jpg)
45
Figure 3.29: