Professional Documents
Culture Documents
3
Problem solving by search
4
Search by generating states
2 3
1 100
5 4
6
1 --> 2 2 --> 5
1 -->6 3 --> 5
2 --> 3 5 --> 4
5
Basic concepts (1)
9
Vacuum World State Space
10
Example 1: water jug (1)
Given 4 and 3 liter jugs, a water pump, and a sink,
how do you get exactly two liters into the 4 liter jug?
4 3
Jug 1 Jug 2 Pump Sink
• State: (x,y) for liters in jugs 1 and 2, integers 0 to 4
• Operations: empty jug, fill jug, pour water between jugs
11
• Initial state: (0,0); Goal state: (2,n)
Water jug Successor functions
1. (x, y | x < 4) (4, y) Fill 4 a move
2. (x, y | y < 3) (x, 3) Fill 3 b move
3. (x, y | x > 0) (0, y) Dump 4
4. (x, y | y > 0) (x, 0) Dump 3
5. (x, y | x+y >=4 and y>0) (4, y - (4 - x))
Pour from 3 to 4 until 4 is full
6. (x, y | x+y >=3 and x>0) (x - (3 - y), 3)
Pour from 4 to 3 until 3 is full
7. (x, y | x+y <=4 and y>0) (x+y, 0)
Pour all water from 3 to 4
12
Water Jug Problem: one
solution
Gallons in y Trasition Rule
0
2 fill 3
3
7 pour from 3 to 4
0 2 fill 3
3 5 pour from 3 to 4
until 4 is full
2 3 dump 4
2 7 pour from 3 to 4
13
0
Example 2: Cryptoarithmetic
Assign numbers to letters so that the sum is correct
FO RTY 29786 Solution
F=2, O=9
+ TEN + 850 R=7, T=8
+ TEN + 850 Y=6, E=5
S I XTY 31486 N=0, I=1
X=4
• State: a matrix, with letters and numbers
• Operations: replace all occurrences of a letter with a
digit not already there
• Goal test: only digits, sum is correct 14
Example 3: 8-puzzle
16
Some of Real Problems
route-finding problem
Touring problems
traveling salesperson problem
VLSI layout
Robot navigation
Automatic assembly sequencing
protein design
In- Internet searching,
17
Graph representation
18
Graph characteristics
b a
(4,3) (0,0) (1,3) (4,3) (0,0) (3,0)
(2,0) (2,3)
20
Water jug problem: graph
(0,0)
(4,0) (0,3)
21
Data Structures
23
24
Search issues: graph
generation
Tree vs. graph
how to handle state repetitions?
what to do with infinite branches?
How to select the next state to expand
uninformed vs. informed heuristic search
Direction of expansion
from start to goal, from goal to start, both.
Efficiency
What is the most efficient way to search?
25
Measuring problem-solving
performance
Completeness
guarantees to find a solution if a solution
exists, or return fail if none exists
Time complexity
# of operations applied in the search
Space complexity
# of nodes stored during the search
Optimality
Does the strategy find the highest-quality?
26
Measuring problem-solving
performance
Search Cost
Time & Memory
Path Cost
Total cost = Search Cost + Path Cost
27
Factors that affect search
efficiency
1. More start or goal states? Move towards the
larger set
G I
G G
I I
G I
28
Factors that affect search
efficiency
2. Branching factor: move in the direction with the
lower branching factor
G
I
G I
29
Uninformed search methods
No a-priori knowledge on which node is
best to expand (ex: crypto-arithmetic
problem)
Depth-first search (DFS)
Breath-first search (BFS)
Uniform cost method
Depth-limited search
Iterative deepening search
Bidirectional search
30
A graph search problem...
4 4
A B C
3
S 5 G
5
G
4
3
D E F
2 4
31
… becomes a tree
S
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
32
Breath-first search
Expand the tree in successive layers, uniformly looking
at all nodes at level n before progressing to level n+1
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
34
BFS, example
35
BFS performance
36
Uniform Cost search
Breadth-first search is optimal when all step
costs are equal
Uniform Cost function: an algorithm that is
optimal with any step cost function.
expands the node n with the lowest path cost.
Uniform-cost search does not care about the
number of steps a path has, but only about their
total cost.
Infinite loop if there is zero-cost action(NoOP
action)
37
Uniform Cost search
Complete & Optimal if every step is
greater than or equal to some small
positive constant
Worst-case time & space complexity is
38
Depth first search
Dive into the search tree as far as you can, backing up
only when there is no way to proceed
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
40
41
Backtracking search
A variant of depth-first search called
backtracking search uses still less
memory.
only one successor is generated at a
time rather than all successors
Memory : O(m) compare to DFS O(bm)
Not optimal …
42
Depth-limited search
Like DFS, but the search is limited to a predefined depth
(L).
The depth of each state is recorded as it is generated.
When picking the next state to expand, only those with
depth less or equal than the current depth are expanded.
Once all the nodes of a given depth are explored, the
current depth is incremented.
Complete if L>d
Time Complexity: O(bL)
Space complexity: O(bL)
L = : DFS
43
Depth-limited search
S depth = 3
A D 3
6
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
44
Limit can be based on
knowledge of problem
L can be determined
based on the
problem.
Routing in Romania
with 20 cities has
L = 19
But each cites can be
reached via 9 cities :
L = 9 (Diameter)
45
IDS: Iterative deepening
search
Problem: what is a good depth limit?
Answer: make it adaptive!
Generate solutions at depth 1, 2, ….
function Iterative-Deepening-Search(problem) returns solution
nodes := Make-Queue(Make-Node(Initial-State(problem)
for depth := 0 to infinity
if Depth-Limited-Search(problem, depth) succeeds
then return its result
end
46
return failure
Iterative deepening search
S S
S
A D
Limit = 0
Limit = 1
S S S
A D A D
B D A E
Limit = 2 47
IDS properties
Like depth-first search, its memory
requirements are O(bd)
Like breadth-first search, it is complete
when the branching factor is finite and
optimal when the path cost is a
nondecreasing function of the depth of
the node.
48
Iterative search is not as wasteful
as it might seem
The root subtree is computed every time
instead of storing it!
BFS: b + b2 + …+ bd+ (bd+1 – b)= O(bd+1)
Repeating the search takes:
(d+1)1 + (d)b + (d - 1)b2 + … (1)bd =
O(bd)
IDS is faster than BFS
For b = 10 and d = 5 the number of nodes
searched in DFS is 111,111 regular vs.
123,456 repeated (only 11% more) !!
49
50
Bidirectional search
Expand nodes from the start and goal state
simultaneously. Check at each stage if the nodes of
one have been generated by the other. If so, the
path concatenation is the solution
• The operators must be reversible
52
Bidirectional search
Search can be done by checking each node in both
queues …
Complexity: O(bd/2) + O(bd/2) = O(bd/2)
E.g.: d=6, b=10 and both sides are BFS
22,200 node generation compare to 11,110,000 node in BFS
One of the queue should stay in memory and
membership checking is done by hashing (O(1)) so,
Space complexity O(bd/2)
Actions should be reversible …
What is the goal: if you have multiple goals ,
generate a dummy goal and link all other goals to
this node
53
Bidirectional search
S
Forward
A D Backwards
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
54
Comparing search strategies
55
Repeated states
Repeated states can the source of great
inefficiency: identical subtrees will be
explored many times!
A A
B B B
C C C C C
56
d State Vs 2d
Repeated states, Example
58
Graph Search Vs Tree Search
59
Strategies for repeated states
Do not expand the state that was just generated
constant time, prevents cycles of length one, ie.,
A,B,A,B….
Do not expand states that appear in the path
depth of node, prevents some cycles of the type
A,B,C,D,A
Do not expand states that were expanded before
can be expensive! Use hash table to avoid looking at all
nodes every time.
60
Searching in Partial
Information
Different types of incompleteness lead
to three distinct problem types:
Sensorless problems (conformant): If the
agent has no sonsors at all
Contingency problem: if the environment if
partially observable or if action are
uncertain (adversarial)
Exploration problems: When the states and
actions of the environment are unknown.
61
Sensorless problems
No sensor
Initial State(1,2,3,4,5,6,7,8)
After action [Right] the state
(2,4,6,8)
After action [Suck] the state (4, 8)
After action [Left] the state (3,7)
After action [Suck] the state (8)
Answer : [Right,Suck,Left,Suck]
coerce the world into state 7 without
any sensor
Belief State: Such state that agent belief to
be there
In observable : Belief state correspond to
one physical state
62
For S physical State : 2S belief state
Summary: uninformed search
Problem formulation and representation is key!
Implementation as expanding directed graph of
states and transitions
Appropriate for problems where no solution is
known and many combinations must be tried
Problem space is of exponential size in the
number of world states -- NP-hard problems
Fails due to lack of space and/or time.
63
64