AI Searching Methods
AI Searching Methods
Basics
• In-order to the reach goal, Agent has to plan ahead.
• Agent takes sequence of actions from Start to goal state.
searching Def: A Problem Solving agent considers a sequence of actions to reach goal state by
performing searching. Any problem should have:
1 2
• The state space search approach searches through all possible states of a • Completeness:
problem to find a solution. If a solution exists, state space search will find it.
3 4
1
07-May-24
Steps followed in State Space Search Steps followed in State Space Search
• To begin the search process, we set the current state to the initial state.
• We then check if the current state is the goal state. If it is, we terminate the
algorithm and return the result.
• If the current state is not the goal state, we generate the set of possible
successor states that can be reached from the current state.
• For each successor state, we check if it has already been visited. If it has,
we skip it, else we add it to the queue of states to be visited.
• Next, we set the next state in the queue as the current state and check if it's
the goal state. If it is, we return the result. If not, we repeat the previous
step until we find the goal state or explore all the states.
• If all possible states have been explored and the goal state still needs to be
found, we return with no solution.
5 6
2
07-May-24
9 10
11 12
3
07-May-24
Example: Vacuum world state space graph Example: Vacuum world state space graph
• states?
• actions? • states? integer dirt and robot location
• goal test? • actions? Left, Right, Suck
• path cost? • goal test? no dirt at all locations
• path cost? 1 per action
13 14
• path cost?
15 16
4
07-May-24
• 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 Note: this is offline problem solving; solution executed “eyes closed.”
17 18
Graph
Representation
19 20
5
07-May-24
Mathematical Representations
Tree
Representation
21 22
23 24
6
07-May-24
A
Example B C
D E F
BFS DFS
• Finding a path from the • Finding a path from the
initial state (A) to the goal initial state (A) to the goal
Uninformed Search Methods state (F). state (F).
• Explores level by level. • Explores path by path.
• A->B->C->D->E->F • A -> B -> D -> E -> C -> F.
25 26
27 28
7
07-May-24
29 30
8
07-May-24
33 34
9
07-May-24
37 38
10
07-May-24
Example Example
Ignored
Path
41 42
43 44
11
07-May-24
Example
A*
• f(n) = g(n) + h(n)
– g(n) = “cost from the starting node to reach n”
– h(n) = “estimate of the cost of the cheapest path from
n to the goal node”
h(n)
20
g(n)
15 n
10 5
15
18
20
25
12
07-May-24
Example:8-Puzzle problem
49 50
13
07-May-24
53 54
14