![Page 1: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/1.jpg)
1
Solving Problems by Searching
![Page 2: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/2.jpg)
2
Terminology
• State• State Space• Goal• Action• Cost• State Change Function• Problem-Solving Agent• State-Space Search
![Page 3: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/3.jpg)
3
Formal State-Space ModelProblem = (S, s, A, f, g, c)
S = state spaces = initial stateA = actionsf = state change function f: S x A -> Sg = goal test function g: S -> {true,false}c = cost function c: S x A x S -> R
x ya • How do we define a solution?
• How about an optimal solution?
![Page 4: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/4.jpg)
4
3 Coins ProblemA Very Small State Space Problem
• There are 3 (distinct) coins: coin1, coin2, coin3.
• The initial state is H H T
• The legal operations are to turn over exactly one coin.– 1 (flip coin1), 2 (flip coin2), 3 (flip coin3)
• There are two goal states: H H H T T T
What are S, s, A, f, g, c ?
![Page 5: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/5.jpg)
5
State-Space Graph
HTT
TTT
THH
HHH
HHT THT
TTH HTH
1
2
1
3
1
2
1
3
3
3
2
2
• What are some solutions?• What if the problem is changed to allow only 3 actions?
![Page 6: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/6.jpg)
6
Modified State-Space Problem
• How would you define a state for the new problem?
• How do you define the operations (1, 2, 3) with this new state definition?
• What do the paths to the goal states look like now?
![Page 7: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/7.jpg)
7
How do we build a search tree for the modified 3 coins problem?
initialstate
1 2 3
![Page 8: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/8.jpg)
8
The 8-Puzzle Problem
7 2 45 B 68 3 1
B 1 23 4 56 7 8
oneinitialstate
goalstate
B=blank
1. Formalize a state as a data structure2. Show how start and goal states are represented.3. How many possible states are there?4. How would you specify the state-change function?5. What is the goal test?6. What is the path cost function?7. What is the complexity of the search?
![Page 9: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/9.jpg)
9
Search Tree Example: Fragment of 8-Puzzle Problem Space
![Page 10: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/10.jpg)
10
Another Example: N Queens• Input:
– Set of states
– Operators [and costs]
– Start state
– Goal state (test)
• Output
Q
Q
Q
Q
![Page 11: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/11.jpg)
11
Example: Route Planning
• Input:– Set of states
– Operators [and costs]
– Start state
– Goal state (test)
• Output:
![Page 12: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/12.jpg)
12
Search Strategies
• Blind Search (Ch 3)
• Informed Search (Ch 4)
• Constraint Satisfaction (Ch 5)
– Depth first search– Breadth first search– Depth limited search– Iterative deepening search
![Page 13: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/13.jpg)
13
Depth First Search
a
b
c d
e
f g h
• Maintain stack of nodes to visit
• Evaluation– Complete?
– Time Complexity?
– Space ?Not for infinite spaces
O(b^d)
O(d)
![Page 14: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/14.jpg)
14
Breadth First Search
a
b c
d e f g h
• Maintain queue of nodes to visit
• Evaluation– Complete?
– Time Complexity?
– Space?
Yes
O(b^d)
O(b^d)
![Page 15: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/15.jpg)
15
The Missionaries and Cannibals Problem(from text problem 3.9)
• Three missionaries and three cannibals are on one side of a river, along with a boat that can hold one or two people.
• If there are ever more cannibals than missionaries on one side of the river, the cannibals will eat the missionaries. (We call this a “dead” state.)
• Find a way to get everyone to the other side, without anyone getting eaten.
![Page 16: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/16.jpg)
16
Missionaries and Cannibals Problem
![Page 17: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/17.jpg)
17
Missionaries and Cannibals Problem
Left Bank Right Bank
River
![Page 18: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/18.jpg)
18
Missionary and Cannibals Notes
• Define your state as (M,C,S)– M: number of missionaries on left bank– C: number of cannibals on left bank– S: side of the river that the boat is on
• When the boat is moving, we are in between states. When it arrives, everyone gets out.
![Page 19: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/19.jpg)
19
When is a state considered “DEAD”?
1. There are more cannibals than missionaries on the left bank. (Bunga-Bunga)
2. There are more cannibals than missionaries on the right bank. (Bunga-Bunga)
3. There is an ancestor state of this state that is exactly the same as this state. (Why?)
![Page 20: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/20.jpg)
20
Assignment
• Implement and solve the problem with a depth-first search using a stack and/or recursion. – Find and print all 4 solutions. (See web page.)– Keep track of the total number of states searched.– When you get to a dead state, count it and then back
up to its parent.
• You may use the computer language of your choice for this assignment.– Java– C++
![Page 21: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/21.jpg)
21
Is memory a limitation in search?
• Suppose:• 2 GHz CPU• 1 GB main memory• 100 instructions / expansion• 5 bytes / node
• 200,000 expansions / sec• Memory filled in 100 sec … < 2 minutes
![Page 22: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/22.jpg)
22
Iterative Deepening Search
a b
c d
e
f
g h
• DFS with limit; incrementally grow limit• Evaluation
– Complete?
– Time Complexity?
– Space Complexity?
Yes
O(b^d)
O(d)
j
i
k l
![Page 23: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/23.jpg)
23
Cost of Iterative Deepeningb ratio ID to DFS
2 3
3 2
5 1.5
10 1.2
25 1.08
100 1.02
![Page 24: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/24.jpg)
24
Forwards vs. Backwardsst
art
end
![Page 25: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/25.jpg)
25
vs. Bidirectional
![Page 26: 1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search](https://reader030.vdocument.in/reader030/viewer/2022032600/56649da95503460f94a95f82/html5/thumbnails/26.jpg)
26
Problem
• All these methods are too slow for real applications (blind)
• Solution add guidance
• “informed search”