The document discusses problem solving by searching. It describes problem solving agents and how they formulate goals and problems, search for solutions, and execute solutions. Tree search algorithms like breadth-first search, uniform-cost search, and depth-first search are described. Example problems discussed include the 8-puzzle, 8-queens, and route finding problems. The strategies of different uninformed search algorithms are explained.
IntroductionIntroduction
In this topic,we see how an agent can find
a sequence of actions that achieves its
goals, when no single action will do.
3
Majidur RahmanMajidur Rahman
4.
Problem-SolvingProblem-Solving AgentAgent
Four generalsteps in problem solving:
• Goal formulation
– What are the successful world states
• Problem formulation
– What actions and states to consider given the goal
• Search
– Examine different possible sequences of actions that
lead to states of known value and then choose the
best sequence
• Execute
– Perform actions on the basis of the solution
4
Majidur RahmanMajidur Rahman
Example: RomaniaExample: Romania
Onholiday the agent is in Romania visiting in
Arad. Flight leaves tomorrow from Bucharest.
• Formulate goal
– Be in Bucharest
• Formulate problem
– States: various cities
– Actions: drive between cities
• Find solution
– Sequence of cities; e.g. Arad, Sibiu, Fagaras,
Bucharest,…
6
Majidur RahmanMajidur Rahman
7.
Problem TypeProblem Type
Givenhow we have defined the problem:
• Environment is fully observable
• Environment is deterministic
• Environment is sequential
• Environment is static
• Environment is discrete
• Environment is single-agent
7
Majidur RahmanMajidur Rahman
8.
Problem FormulationProblem Formulation
Aproblem is defined by:
An initial state, e.g. In(Arad)
A successor function S(x) = set of action-state pairs
• S(In(Arad)) = {(Go(Sibiu), In(Sibiu)), (Go(Zerind), In(Zerind)),
(Go(Timisoara), In(Timisoara))}
• initial state + successor function = state space
Goal test
• Explicit, e.g. x=‘In(Bucharest)’
Path cost (assume additive)
• e.g. sum of distances, number of actions executed, …
A solution is a sequence of actions from initial to
goal state
the optimal solution has the lowest path cost
8
Majidur RahmanMajidur Rahman
Example ProblemsExample Problems
Theproblem-solving approach has been applied to
a vast array of task environments.
Some of the best known are listed here,
distinguishing between toy and real-world problems.
A toy problem is intended to illustrate or exercise
various problem-solving methods.
It is usable by different researchers to compare the
performance of algorithms.
A real-world problem is one whose solutions
people actually care about.
We will mainly focus on toy problems in this topic.
10
Majidur RahmanMajidur Rahman
11.
Toy Problems: 8-PuzzleToyProblems: 8-Puzzle
States: location of each tile plus blank
Initial state: Any state can be initial
Actions: Move blank {Left, Right, Up, Down}
Goal test: Check whether goal configuration is reached
Path cost: Number of actions to reach goal
11
Majidur RahmanMajidur Rahman
12.
Toy Problems: 8-QueensToyProblems: 8-Queens
Place eight queens on a chessboard such that
no queen attacks any other.
Two kinds of problem formulation:
• Complete-state formulation
• Incremental formulation
12
Majidur RahmanMajidur Rahman
13.
Toy Problems: 8-QueensToyProblems: 8-Queens
Complete-state formulation
• States: Any arrangement of 0 to 8 queens on the board
• Initial state: No queens
• Actions: Add queen to any empty square
• Goal test: 8 queens on board and none attacked
• Path cost: N/A
64.63.62…..57 ≈ 3 x 1014
possible sequences to investigate
13Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
14.
Incremental formulation
• States:n (0 to 8) queens on the board, one per column in
the n leftmost columns with no queen attacking any other
• Actions: Add queen in leftmost empty column such that
the queen is not attacking any other queen
• 2057 possible sequences to investigate; solutions are
easy to find
But with 100 queens the problem is much harder
14
Toy Problems: 8-QueensToy Problems: 8-Queens
15.
Real-World ProblemsReal-World Problems
Route-finding problems
Touring problems
Traveling Salesman problem
VLSI layout problem
Robot navigation
Automatic assembly sequencing
Internet searching
15
Majidur RahmanMajidur Rahman
16.
Basic Search AlgorithmsBasicSearch Algorithms
How do we find the solutions of previous
problems?
• Search the state space
– State space can be represented by a search tree
– Root of the tree is the initial state
– Children generated through successor function
• In general we may have a search graph rather
than tree (same state can be reached through
multiple paths)
16
Majidur RahmanMajidur Rahman
17.
Simple Tree SearchExampleSimple Tree Search Example
17
Majidur RahmanMajidur Rahman
18.
Simple Tree SearchExampleSimple Tree Search Example
18
Majidur RahmanMajidur Rahman
19.
Simple Tree SearchExampleSimple Tree Search Example
19
Majidur RahmanMajidur Rahman
20.
State Space vs.Search TreeState Space vs. Search Tree
• A state corresponds
to a configuration of
the world
• A node is a data
structure in a search
tree
– e.g. node = <state,
parent-node, action,
path-cost, depth>
20
Majidur RahmanMajidur Rahman
21.
Search StrategiesSearch Strategies
A search strategy is defined by picking the order of node
expansion
Problem-solving performance is measured in four ways:
• Completeness: Is a solution found if one exists?
• Optimality: Does the strategy find the optimal solution?
• Time Complexity: How long does it take to find a solution?
• Space Complexity: How much memory is needed to perform
the search?
Time and space complexity are measured in terms of
problem difficulty defined by:
• b - branching factor of the search tree
• d - depth of the shallowest goal node
• m - maximum length of any path in the state space
21
Majidur RahmanMajidur Rahman
22.
Uninformed Search StrategiesUninformedSearch Strategies
• Uninformed search (or blind search)
– Strategies have no additional information about states beyond
that provided in the problem definition
• Informed (or heuristic) search
– Search strategies know whether one state is more promising
than another
• Uninformed strategies (defined by order in which nodes
are expanded):
– Breadth-first search
– Uniform-cost search
– Depth-first search
– Depth-limited search
– Iterative deepening search
– Bidirectional search
22
Majidur RahmanMajidur Rahman
23.
Breadth-First SearchBreadth-First Search
•Expand shallowest unexpanded node
• Fringe is the collection of nodes that have been generated
but not yet expanded.
• The set of all leaf nodes available for expansion at any
given point is called the frontier.
• Implementation: fringe/frontier is a FIFO queue
23
Breadth-First SearchBreadth-First Search
•Completeness: is a solution always found
if one exists?
– YES
• If shallowest goal node is at some finite depth d
• If branching factor b is finite
• BF search is optimal if the path cost is a
non-decreasing function of the depth of
the node
27
Majidur RahmanMajidur Rahman
28.
Breadth-First SearchBreadth-First Search
•Time complexity: Assume a state space where
every state has b successors
– Assume solution is at depth d
– Worst case: expand all but the last node at depth d
– Total number of nodes generated:
– b + b2
+ b3
+ ...+ bd
+ (bd +1
− b) = O(bd +1
)
• Space complexity: every node generated must
remain in memory, so same as time complexity
28
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
•Extension of BF-search:
– Expand node with lowest path cost
• Implementation: fringe = queue ordered by
path cost
• UC-search is the same as BF-search
when all step costs are equal
30
Majidur RahmanMajidur Rahman
31.
Uniform-Cost SearchUniform-Cost Search
Let us consider the following search tree, where A
and G are the initial and goal node, respectively.
31
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
Let us consider the another search tree, where A
and G are the initial and goal node, respectively.
37
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
•Completeness:
– YES, if step-cost > some small positive constant ε
• Optimality:
– nodes expanded in order of increasing path cost
– YES, if complete
• Time and space complexity:
– Uniform-cost search is guided by path costs rather than
depths, so its complexity cannot easily be characterized
in terms of b and d.
– Instead, assume C* is the cost of the optimal solution
– Assume that every action costs at least ε
– Worst-case: O(bC*/ε
)
42
Majidur RahmanMajidur Rahman
DF-Search: EvaluationDF-Search: Evaluation
•Completeness:
– Is a solution always found if one exists?
– No (unless search space is finite and no loops
are possible)
• Optimality:
– Is the least-cost solution always found?
– No
55
Majidur RahmanMajidur Rahman
56.
DF-Search: EvaluationDF-Search: Evaluation
•Time complexity: O(bm
)
• In general, time is terrible if m (maximal
depth) is much larger than d (depth of
shallowest solution)
– But if there exist many solutions then faster
than BF-search
• Space complexity: O(bm)
– Backtracking search uses even less memory
(one successor instead of all b)
56
Majidur RahmanMajidur Rahman
57.
Depth-Limited SearchDepth-Limited Search
•DF-search with depth limit l
– i.e. nodes at depth l have no successors
– Problem knowledge can be used
• Solves the infinite-path problem
• If l < d then incompleteness results
• Time complexity: O(bl
)
• Space complexity: O(bl)
57
Majidur RahmanMajidur Rahman
Iterative Deepening SearchIterativeDeepening Search
• A general strategy to find best depth limit l
– Goal is found at depth d, the depth of the
shallowest goal-node
– Often used in combination with DF-search
• Combines benefits of DF- and BF-search
62
Majidur RahmanMajidur Rahman
Bidirectional SearchBidirectional Search
Twosimultaneous searches run from start and goal.
– Motivation:
– One forward from the initial state
– Other backward from goal
– Stops when the two searches meet in the middle
• Check whether the node belongs to the other fringe before
expansion
67
bd/2
+bd/2
≠bd
68.
Bidirectional SearchBidirectional Search
Timecomplexity: O(bd/2
)
Space complexity: O(bd/2
)
– This space complexity is the most significant
weakness of bidirectional search.
Completeness and Optimality: Yes
– If step costs are uniform
– If both searches are breadth-first search.
68Majidur RahmanMajidur Rahman
69.
The reduction intime complexity makes
bidirectional search attractive, but how do we
search backwards?
The predecessor of each node should be
efficiently computable.
– When actions are easily reversible.
Bidirectional SearchBidirectional Search
Majidur RahmanMajidur Rahman