00 Uninformed Search
00 Uninformed Search
๏ Problem-solving agents use atomic representations: states of the world are considered as
wholes
•Planning agents use factored or structured representations of states
๏ Informed v.s. Uninformed algorithm: whether the agent can estimate how far it is from the
goal
6 Example: Travel in Romania
๏ Find a solution:
• Sequence of cities, e.g.,
Arad, Sibiu, Fagaras, Bucharest
7 Problem-Solving Agents
8 Problem formulation
A search problem is defined by:
1. State space
A set of possible states the environment can be in.
2. Initial state
Where the agent starts in
3. Goal test
Usually a condition, sometimes the description
of a state
4. Successor function
Include action and cost: describe how state changes
with an action, and the cost of applying action a to
transit from state s to s’
A solution is a sequence of actions (a plan) which transforms the start state to a goal state
9 What is in a State Space?
10 Abstraction
Go around the city taking each bridge once and only once?
In 1735, Euler showed that this is impossible using graph theory and topology.
Solution in graph theory: for this to be possible, each node must have an even degree.
11 Example: Route finding
Actions
13 Example: Route finding
๏ Formulate goal:
•Be in Bucharest
๏ Formulate problem:
•States: various cities
•Actions: go to adjacent city
•Goal test: whether in Bucharest
•Path cost: distance
๏ Find solution:
• Sequence of cities
• e.g., Arad, Sibiu, Fagaras, Bucharest
Formulate tasks as searching
Map?
Where is the
๏ We can rarely build this full graph in memory (it’s too big), but it’s a useful idea
17 State space graph
๏ A search tree:
•A “what if” tree of plans and their outcomes
•The start state is the root node
•Children correspond to successors
•Nodes show states, but correspond to PLANS that achieve those states
•For most problems, we can never actually build the whole tree
19 State State Spacevs.
Space Graphs Graphs vs. Search
Search Trees Trees
Each NODE in in
State Space Graph the search tree is Search Tree
an entire PATH in
the state space S
G graph. e p
a d
b c
b c e h r q
e
d f a a h r p q f
S h We construct both
on demand – and p q f q c G
p q r
we construct as q c a
G
little as possible.
a
20 Quiz:
State State
Space Space
Graphs Graphs
vs. Search vs.
Trees Search Trees
Consider this 4-state graph: How big is its search tree (from S)?
b
G
?
21 Quiz:
State State
Space Space
Graphs Graphs
vs. Search vs.
Trees Search Trees
Consider this 4-state graph: How big is its search tree (from S)?
S G
b
22 Quiz:
State State
Space Space
Graphs Graphs
vs. Search vs.
Trees Search Trees
Consider this 4-state graph: How big is its search tree (from S)?
a s
a b
S G
b G a G
b a G b G
… …
๏ Formulate problem:
• States: ?
• Actions: ?
• Goal test: ?
• Path cost: ?
25 Example: Vacuum World
๏ Formulate problem:
•States: dirt and robot location
•Actions: left (L), right (R), suck (S)
•Goal test: no dirt at all locations
•Path cost: 1 per action
26 Example: The 8-puzzle
๏ Formulate problem:
•States: location of tiles
•Actions: move blank left, right, up, down
•Goal test: given goal state
•Path cost: 1 per move
27 Example: The 8-puzzle
9! / 2
28 Example: Robotic Assembly
๏ Formulate problem:
•States: real-valued coordinates of robot
joint angles parts of the object to be
assembled
•Actions: continuous motions of robot
joints
•Goal test: complete assembly
•
•
Path cost: time to execute
29 Example: Robotic Assembly
30 Example: The 8-Queens
๏ Formulate problem:
•
States: ?
•
Actions: ?
•
Goal test: ?
๏
•
Path cost: ?
๏ Formulation 1:
•States: Any arrangement of 0 to 8
queens on the board.
•Actions: Add a queen in any square.
•Goal test: 8 queens on the board, none
attacked.
•Path cost: 1 per move.
๏ Formulation 2:
•States: Any arrangement of k = 0 to 8
queens in the k leftmost columns with
none attacked.
•Actions: Add a queen to any square in the
leftmost empty column such that it is not
attacked by any other queen.
•Goal test: 8 queens on the board, none
attacked Place 8 queens in a chessboard so that
•
•
Path cost: 1 per move no two queens are in the same row,
column, or diagonal.
! 2067 states
33 Exercise: River Crossing
34 Answer: River Crossing
๏ Robot navigation
•A generalization fo the route-finding problem.
Problem Solving by Searching
38 Searching as problem solving technique
Problem solving by searching:
๏ Searching is the process of looking for the solution of a problem through a set of possibilities
(state space).
๏ The Solution is a path from the current state to the goal state.
39 Searching as problem solving technique
Process of Searching:
๏ Basic idea:
•offline, simulated exploration of state space by generating successors of already-explored
states (a.k.a.~expanding states)
๏ A node is a data structure constituting part of a search tree, includes state, parent node, action, path
cost g(x), depth
๏ The Expand function creates new nodes, filling in the various fields and using the
SuccessorFn of the problem to create the corresponding states.
48 Fringe (Frontier)
๏ If you're performing a tree (or graph) search, then the set of all nodes at the end of all visited
paths is called the fringe, frontier or border.
Fringe
49 Fringe (Frontier)
50 Search strategies
๏ Uninformed (or blind) strategies have no clue about how close a state is to the goal(s).
๏ Informed (or heuristic) strategies exploits such information to assess that one node is “more
promising” than another.
52 Uninformed Strategies
Uninformed search strategies use only the information available in the problem definition.
๏ Breadth-First Search
๏ Depth-First Search
๏ Uniform-Cost Search
๏ Depth-Limited Search
๏ BFS first visit all the nodes at the same depth first and then proceed visiting nodes at a deeper
depth (strategy: expand a shallowest node first)
55 Breadth-First Search
https://www.codesdope.com/course/algorithms-bfs/
56 Breadth-First Search
๏ Thus after visiting a node, we first visit all its sibling and then their children.
๏ We can use a first in first out (FIFO) queue to achieve this (Fringe is a FIFO queue).
๏ Starting from the source, we can put all its adjacent nodes in a queue
57 Breadth-First Search
58 Breadth-First Search (BFS) Properties
๏ Is it complete?
• Yes. d must be finite if a solution exists.
๏ Is it optimal?
• Only if costs are all 1. d
๏ Search time? d
• shallowest solution
๏ Fringe space?
• Has roughly the last tier, so
Depth-First Search
60 Depth-First Search (DFS)
๏ DFS first explores the depth of the graph before the breadth i.e., it traverses along the
increasing depth and upon reaching the end, it backtracks to the node from which it was started
and then do the same with the sibling node.
61 Depth-First Search
๏ Similar to the BFS, we also mark the vertices white, gray and black to represent unvisited,
discovered and complete respectively.
https://www.codesdope.com/course/algorithms-dfs/
62 Depth-First Search
63 Depth-First Search (DFS) Properties
๏ Is it complete?
• m could be infinite, so only if we prevent
cycles
๏ Is it optimal?
• No, it finds the “leftmost” solution,
regardless of depth or cost
๏ Search time?
•O(bm) Terrible if m is much larger than d,
but if solutions are dense, may be much
faster than breadth-first.
๏ Fringe space?
• Only has siblings on path to root, so O(bm),
i.e., linear space!
64 Exercise: DFS vs. BFS
๏ = depth-first search with depth limit L, i.e., nodes at depth L have no successors
66 Iterative Deepening Search
๏ Idea: get DFS’s space advantage with BFS’s time / shallow-solution advantages
• Run a DFS with depth limit 1. If no solution...
• Run a DFS with depth limit 2. If no solution...
• Run a DFS with depth limit 3. .....
67 Cost-Sensitive
Cost-Sensitive Search Search
a GOAL
2 2
b c
3
2
1 8
2 e
3 d
f
9 8 2
START h
1 4 2
p 4 r
15
q
S 0
d 3 e 9 p 1
b 4 c e 5 h 17 r 11 q 16
11
Cost a 6 a h 13 r 7 p q f
contours
p q f 8 q c G
Equivalent to breadth- rst
q 11 c G 10 a if step costs all equal.
a
fi
70 Properties of Uniform-Cost Search
๏
71 Uniform-Cost Search Issues
๏ The bad:
•Explores options in every “direction”
•No information about goal location
๏ All these search algorithms are the same except for fringe strategies
•Conceptually, all fringes are priority queues (i.e. collections of nodes with attached priorities)
•Can even code one implementation that takes a variable queuing object