Title: Chapter 3 Solving Problems by Searching
1Chapter 3 Solving Problems by Searching
2Outline
- Problem-solving agents
- Problem formulation
- Example problems
- Uninformed search algorithms
- Avoiding repeated states
- Searching with partial information
3Example Romania
An agent is on holiday in Romania currently in
Arad. Flight leaves tomorrow from Bucharest
4Problem-solving agents
5Problem formulation - Definition
- A problem is defined by four components
- initial state where the agent starts
- e.g., x In(Arad)
- successor function SUCCESSOR-FN(x) set of
action-state pairs - e.g., ltGo(Sibiu), In(Sibiu)gt,
ltGo(Timisoara), In(Timisoara)gt, - state space states reachable from the initial
state graph node state, arc action. - path a sequence of states connected by a
sequence of actions - goal test determines if the current state is a
goal state - e.g., In(Bucharest)
- path cost additive numeric cost to the path the
performance measure - e.g., sum of distance or time, number of actions
executed. - step cost c(x,a,y) taking action a to go from
state x to state y (nonnegative!) - solution a path from the initial state to a goal
state - optimal solution the solution having the lowest
path cost
6Problem formulation - Abstraction
7Example Toy problems vacuum world
states? integer dirt and agent locations
successor function? Left, Right, Suck, NoOp
goal test? no dirt
path cost? 1 per action (0 for NoOp)
8Example Toy problems 8-puzzle
states? integer locations of tiles
successor function? move blank left, right, up,
down
goal test? given goal state
path cost? 1 per move
Optimal solution of sliding-block puzzles is
NP-hard!
9Example Toy problems 8-queens
Incremental formulation
Complete state formulation
n-queens Family
states? Any arrangement of 0 to 8 queens
successor function? Add a queen to any empty
square
goal test? 8 queens are on the board, none
attacked
path cost? no interest
10Example Real world problems
- Route-finding problem
- Special locations and transitions along links
between them - Commercial travel advice systems
- Touring problem
- Visit each city at least once
- State includes the current location and the set
of cities visited -
- Traveling salesperson problem (TSP)
- A touring problem each city must be visited
exactly once - Find the shortest tour NP-hard!
- Other problems
11Solving the problem using a search tree
- Search tree
- Search graph the same state can be reached from
multiple paths - Root is a search node corresponding to the
initial state In(Arad)
12Solving the problem using a search tree (contd)
- Expanding applying the successor function to the
current state - Generating a new set of states In(Sibiu),
In(Timisoara), In(Zerind)
13Solving the problem using a search tree (contd)
- Fringe the set of nodes generated but not yet
expanded - Leaf node each element of the fringe
14General tree search
- Strategy determine the choice of which state to
expand - Search algorithms
15States vs. Nodes
- A state is a representation (configuration) of
the world - A node is a data structure constituting part of
the search tree
- State the state to which the node corresponds
- Parent-node the node that generated this node
- Action the action (applied to parent) that
generated this node - Path-cost g(n) the cost of the path from the
initial state to this node - Depth the number of steps along the path from
the initial state
- Two different nodes can contain the same world
state (different paths)!
16General tree search Implementation
- Assume the fringe is implemented as a queue
- Operations on a queue
- Make-Queue(element, )
- Creates a queue with the given element(s)
- Empty?(queue)
- Returns true if no more elements in the queue
- First(element)
- Returns the first element of the queue
- Remove-First(queue)
- Returns the first element of the queue and remove
it from the queue - Insert(element, queue)
- Inserts an element into the queue and returns the
resulting queue - First-in-first-out (FIFO) or last-in-first-out
(LIFO) (stack) - Insert-All(elements, queue)
- Inserts a set of elements into the queue and
returns the resulting queue
17General tree search Implementation (contd)
- The EXPAND function creates new nodes, filling in
the various fields using the SUCCESSOR-FN of the
problem to create corresponding states
18Performance evaluation of the strategy
- A strategy (algorithm) picks the order of node
expansion - Strategies are evaluated in four ways
- Completeness Does it always find a solution if
there is one? - Optimality Does it find a solution having lowest
cost path? - Time complexity How long does it take to find a
solution - Number of nodes generated/expanded
- Space complexity How much memory is needed
during the search - Maximum number of nodes in memory
- Time and space complexity are measured in terms
of - b the branching factor maximum number of
successors of any node - d the depth of the shallowest goal node
- m the maximum length of any path in the state
space - Total cost search cost path cost
19Uninformed search strategies
- Uninformed search uses only the information
available in the problem definition - Breadth-first search
- Uniform-cost search
- Depth-first search
- Depth-limited search
- Iterative deepening search
- Bidirectional search
20Breadth-first search (BFS)
- Expand the shallowest unexpanded node
- Implementation
- fringe is a FIFO queue, i.e., new successors go
at end
21Properties of BFS
- Complete?
- Optimal?
- Time?
- Space?
Yes (if b is finite)
Yes (if the path cost is nondecreasing function
of the depth of the node)e.g., cost 1 per step
22Uniform-cost search
- Expand the node with lowest path cost
- fringe is a queue, ordered by path cost
- Equivalent to BFS if all step costs are equal
23Properties of uniform-cost search
- Complete?
- Optimal?
- Time?
- Space?
24Depth-first search (DFS)
- Expand the deepest unexpanded node
- Implementation
- fringe is a LIFO queue, i.e., put successors at
front
25Depth-first search (DFS) (contd)
26Depth-first search (DFS) (contd)
27Properties of DFS
- Complete?
- Optimal?
- Time?
- Space?
No
O(bm), i.e., linear space!
O(m) when backtracking only one successor is
generated expanded node remembers which
successor to generate next.
28Depth-limited search
- Nodes at depth l have no successors
- Equivalent to DFS with depth limit l
29Properties of Depth-limited search
- Complete?
- Optimal?
- Time?
- Space?
No if l lt d
No
O(bl)
30Iterative-deepening search (IDS)
- Iterative deepening depth-first search
- Combines the benefits of breadth-first and
depth-first search
31Iterative-deepening search (contd)
Limit 0
32Iterative-deepening search (contd)
33Iterative-deepening search (contd)
34Iterative-deepening search (contd)
35Properties of IDS
- Complete?
- Optimal?
- Time?
- Space?
Yes
Yes
O(bd)
36Bidirectional search
- Run two simultaneous searches
- one forward from the initial state and the other
backward from the goal - stop when the two searches meet in the middle
- Properties
- complete and optimal if both searches are
breadth-first - both time complexity and space complexity are
37Comparing uninformed search strategies
1. complete if b is finite 2. complete if step
costs for positive 3. optimal if step costs are
all identical 4. if both directions use
breadth-first search
b branching factor d depth of the
shallowest solution m maximum depth of the
search tree l depth limit
38Avoiding repeat states
- Detecting states that have already been expanded
before - if there is more than one path to each state
graph - where the actions are reversible route-finding
problem and sliding-blocks puzzles
State space d1 states
Search tree branches
- Prune the repeated states
- cut infinite (exponential) search tree down to
finite size (polynomial)
39General graph search
- Algorithms that forget their history are doomed
to repeat it! - open list (fringe of unexpanded nodes) and closed
list (set of all expanded nodes) - The current node is discarded is it matches a
node on the closed list.
- Optimal solution?
- newly discovered path is always discarded miss
an optimal solution if it is shorter - optimality breadth-first search and
uniform-cost search with constant step costs - depth-first search and iterative deepening search
no longer have linear space
40Searching with partial information
Problem types
The agent must reason about sets of states that
it might get to Each such set of states is a
belief state. e.g. vacuum agent knows the
effects of its actions, but has no sensors.
41Reachable belief state space for sensorless
vacuum world
belief state space belief states 12
reachable
physical state space S 8 states
42Searching with partial information
Problem types
The agent must reason about sets of states that
it might get to Each such set of states is a
belief state. e.g. vacuum agent knows the
effects of its actions, but has no sensors.
Adversarial if the uncertainty is caused by the
actions of another agent e.g., game