Chapter3 UnInformed Search-lastModified
Chapter3 UnInformed Search-lastModified
2
Imagine a World Without Search Algorithms
3
Why Is Problem Solving Important in AI?
4
Solving Problems by Searching
Since AI agents do not always know the correct answer immediately, they must
search for a solution among possible alternatives.
Problems are solved by searching among alternative choices
Reflex agent is simple
◼ base their actions on a direct mapping from states to actions, but cannot work
well in environments:
which this mapping would be too large to store
and would take too long to learn
Hence, goal-based agent is used in solving problems.
5
Which Agent Type?
6
Tic Tac
7
How Human beings think?
"Human beings do not search the entire state space (exhaustive search)."
• Exhaustive search means checking every possible option before making a decision.
• Humans don’t do this because it would take too much time and effort.
• Instead, humans use experience and intuition to focus on relevant choices rather than
checking all possibilities.
Example:
• Imagine you are searching for a book in a library.
• Exhaustive search: Checking every single book one by one.
• Human thinking: Going directly to the category or section where the book is likely
to be.
8
Humans Explore Only Useful Alternatives
9
Humans Use Heuristics (Judgmental Rules)
10
What Are Heuristics?
11
Problems in AI
12
Problem-solving agent
13
Problem-solving agent terminologies
14
Goal formulation (modeling)
15
Problem formulation
16
Search&Execution
Third phase of agent design
The state space of the problem is the set of all states reachable from initial state by any
sequence of actions.
The states can be represented as a directed graph where the nodes are the states and links
between nodes are actions.
Because there are many ways to achieve the same goal
◼ Those ways are together expressed as a tree
◼ Multiple options of unknown value at a point,
the agent can examine different possible sequences of actions, and choose the best
◼ This process of looking for the best sequence is called search
◼ The best sequence is then a list of actions, called solution
◼
17
Search algorithm
19
Well-defined problems and solutions cont.
20
Example:
21
Romania’s problem formulation:
A problem is defined by four items:
22
The successor function
23
Abstraction
24
Example of problems
Toy problems
◼ those intended to illustrate or exercise various problem-solving
methods
◼ E.g., puzzle, chess, etc.
Real-world problems
◼ tend to be more difficult and whose solutions people actually
care about
◼ E.g., Design, planning, etc.
25
Toy problems: Example vacuum world
Number of states: 8
Initial state: Any
Number of actions: 4
⚫ left, right, suck,
noOp
Goal: clean up all dirt
⚫ Goal states: {7, 8}
⚫ Path Cost:
⚫ Each step costs 1
26
27
The 8-puzzle
28
The 8-puzzle
States:
◼ a state description specifies the location of each of the
eight tiles and blank in one of the nine squares
Initial State:
◼ Any state in state space
Successor function:
◼ the blank moves Left, Right, Up, or Down
Goal test:
◼ current state matches the goal configuration
Path cost:
◼ each step costs 1, so the path cost is just the length of
the path
29
A portion of the state space of a 8-Puzzle
problem
5 4
6 1 8
7 3 2
5 4 548
618 61
732 732
514 54
6 8 618
732 732
514
68
732
30
2- Searching for solutions
31
Search tree
Initial state
◼ The root of the search tree is a search node
Expanding
◼ applying successor function to the current state, thereby
generating a new set of states
leaf nodes
◼ the states having no successors or they haven’t yet been
expanded (fringe)
Refer to next figure
32
Tree search example
33
Tree search example
34
Search tree
35
2.1 Infrastructure for search algorithms
◼ PATH-COST: the cost, g(n), from initial state to the node n itself
◼ DEPTH: number of steps along the path from the initial state
36
Implementation: states vs. nodes
A state is a (representation of) a physical configuration
A node is a data structure constituting part of a search tree
includes state, parent node, action, path cost g(x), depth
Figure 3.10
Completeness
◼ Guarantees finding a solution whenever one exists
Time Complexity
◼ How long (worst or average case) does it take to find
a solution? Usually measured in terms of the number
of nodes expanded
Space Complexity
◼ How much space is used by the algorithm? Usually
measured in terms of the maximum size that the
“OPEN" list becomes during the search
Optimality/Admissibility
◼ If a solution is found, is it guaranteed to be an
optimal one? For example, is it the one with minimum
cost? 38
Measuring problem-solving performance cont.
39
Search strategies
40
Uninformed search strategies
41
42
Breadth-first search:
Move
A D downwards,
level by level,
B D A E until goal is
reached.
C E E B B F
D F B F C E A C G
G C G F
G
Queue(fringe): A
Expanded:0
Level: 0
44
Breadth-first search
Queue: B C
Expanded:1- A
45
Breadth-first search
Queue: B C
Expanded:1- A
Level: 1
46
Breadth-first search
Queue: C D E
Expanded:2- A B
Queue: D E F G
Expanded:2- A B
Queue: G
Expanded:- A B
47
Breadth-first search (Analysis)
Breadth-first search
◼ Complete – find the solution eventually
◼ Optimal, if the path cost is a non-decreasing function of the
depth of the node
The disadvantage
◼ if the branching factor of a node is large,
◼ for even small instances (e.g., chess)
the space complexity and the time complexity are enormous
هائل
48
49
Uniform cost search
51
Example: Finding the Shortest Path in a Graph
52
Depth-first search
Always expands one of the nodes at the deepest level of the tree
Only when the search hits a dead end
◼ goes back and expands nodes at shallower levels
◼ Dead end → leaf nodes but not the goal
Backtracking search
◼ only one successor is generated on expansion
◼ rather than all successors
◼ fewer memory
53
DFS Example:
Graph Traversal
54
Depth-first search
55
Depth-first search
56
Depth-first search
57
Depth-first search
58
Depth-first search
59
Depth-first search
60
Depth-first search
61
Depth-first search
62
Depth-first search
63
Depth-first search
64
Depth-first search
65
Depth-first search
66
67
Depth-first search (Analysis)
Not complete
◼ because a path may be infinite or looping
◼ then the path will never fail and go back try another option
Not optimal
◼ it doesn't guarantee the best solution
It overcomes
◼ the time and space complexities
68
DFS vs BFS
69
Depth-limited search
It is depth-first search
◼ with a predefined maximum depth
◼ However, it is usually not easy to define the suitable
maximum depth
◼ too small → no solution can be found
◼ too large → the same problems are suffered from
Anyway the search is
◼ complete
◼ but still not optimal
70
Example : (BFS and DFS)
Initial state
A
B C D E F
Goal state
G H I J K L M N O P
Q R S T U V W X Y Z
Press space to see a BFS of the example
71
node set
We
Thethensearch
Node
backtrack
B
then
is expanded
moves
to expand
to then
the A We
This
Node
begin
node
Awith
isisremoved
then
our expanded
initial
fromstate:
the
to
first
removed
node
nodefrom
in
C,the
andthe
queue.
the
queue.
process
Press
The thequeue.
reveal
node labeled
further
Each revealed
A.
(unexpanded)
Pressnode
spaceis
revealedcontinues.
nodes
space
are to
Press
added
continue.
space
to the added to the ENDnodes.ofPress
tothe
continue
queue.
space
ENDBof the queue. C Press space. D PressEspace to continue F the
search.
G H I J K L M N O P
Press
Press space
space to
to continue
begin thethe
search
search
Size
SizeofofQueue:
Queue:0987651 Queue:
Queue:
Queue:
Queue:
Queue:
K,
L,
J,
G,
H,
I,Queue:
K,
J,
L,
M,
H,
I,
F,
Queue:
K,
J,
L,
M,
G,
I,
N,
Queue:
E,K,
L,
M,
J,
H,
N,
O,
F,
D,
K,
M,
L,
C,
N,
I,
O,
G,
P,
Queue:
E,M,
L,
J,
N,
D,
B,
Q,
O,
P,
H,
F,K,
M,
N,
O,
E,
C,
Q,
R,
P,
Queue:
G,
I,L,
N,
F,
O,
Q,
P,
D,
J,
R,
Empty
S,
H,M,
G,
Q,
K,
O,
T,
P,
E,
R,
S,I,Q
H
A
N
R
U L
T
F
P
SJ
10 Current
Nodes FINISHED
Action:
Current
SEARCH
Expanding
Action: Current Currentlevel:
level:210
expanded:
expanded:10119876543210 Backtracking
BREADTH-FIRST SEARCH PATTERN n/a
72
The process
Node search
B is expanded
then
nowmoves
continues
andtoremoved
the
until
first
thefrom
node Node
We
Thisbegin
node
A is with
removed
is then
ourexpanded
initial
from the
state:
to
Stack.
reveal
the node
Each
in the
the
goalStack.
state
Stack.
isRevealed
achieved.
Press space
nodes
Press
toare
continue
space.
added to A labeled A.
further
revealed(unexpanded)
node
Press
is space
addednodes.
totocontinue
the Press
FRONT space.
of
the FRONT of the Stack. Press space. the Stack. Press space to continue.
B C D E F
Q R S T U
73
DEPTH-FIRST SEARCH PATTERN
Iterative deepening search
74
Iterative deepening search
75
Iterative deepening search (Analysis)
optimal
complete
Time and space complexities
◼ reasonable
suitable for the problem
◼ having a large search space
◼ and the depth of the solution is not known
76
Iterative lengthening search
77
78
Bidirectional search
79
80
81
When to use what
Depth-First Search:
◼ Many solutions exist
◼ Know (or have a good estimate of) the depth of solution
Breadth-First Search:
◼ Some solutions are known to be shallow
Uniform-Cost Search:
◼ Actions have varying costs
◼ Least cost solution is required
This is the only uninformed search that worries about costs.
Iterative-Deepening Search:
◼ Space is limited and the shortest solution path is required
82
Avoiding repeated states
83
Avoiding repeated states
84