0% found this document useful (0 votes)
7 views

AI Searching Methods

Uploaded by

Kushwanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

AI Searching Methods

Uploaded by

Kushwanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

07-May-24

Basics
• In-order to the reach goal, Agent has to plan ahead.
• Agent takes sequence of actions from Start to goal state.

AI: Solving Problems by • Hence a Problem Solving Agent is required.

searching Def: A Problem Solving agent considers a sequence of actions to reach goal state by
performing searching. Any problem should have:

A set of possible states that the environment can be in.


A set of one or more goal states information
The actions available to the agent.

1 2

State Space Search Features of State Space Search


• State space search is a problem-solving technique used in Artificial • Exhaustiveness:
Intelligence (AI) to find the solution path from the initial state to the State space search explores all possible states of a problem to find a
goal state by exploring the various states. solution.

• 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.

• It is an essential part of Artificial Intelligence and is used in various • Optimality:


applications, from game-playing algorithms to natural language processing. Searching through a state space results in an optimal solution.

• Uninformed and Informed Search:


State space search in artificial intelligence can be classified as uninformed
if it provides additional information about the problem.

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

State Space Representation Example: 8 Puzzle Problem


State space Representation involves defining an INITIAL STATE and a GOAL STATE and
then determining a sequence of actions, called states, to follow.
State:
A state can be an Initial State, a Goal State, or any other possible state that can be generated
by applying rules between them.
Space:
In an AI problem, space refers to the exhaustive collection of all conceivable states.
Search:
This technique moves from the beginning state to the desired state by applying good rules
while traversing the space of all possible states.
Search Tree:
To visualize the search issue, a search tree is used, which is a tree-like structure that
represents the problem. The initial state is represented by the root node of the search tree,
which is the starting point of the tree.
Transition Model:
This describes what each action does, while Path Cost assigns a cost value to each path, an
activity sequence that connects the beginning node to the end node. The optimal option has
the lowest cost among all alternatives.
7 8

2
07-May-24

Example: 8 Puzzle Problem Example: Romania


Move from Arad to Bucharest

Abstraction: The process of removing details from a representation


Is the map a good representation of the problem? What is a good replacement?

9 10

Example: Romania Single-state problem formulation


On holiday in Romania; currently in Arad. A problem is defined by four items:
Flight leaves tomorrow from Bucharest
1. initial state e.g., "at Arad“
Formulate goal:
2. actions or successor function S(x) = set of action–state pairs
be in Bucharest – e.g., S(Arad) = {<Arad Zerind, Zerind>, … }

Formulate problem: 3. goal test, can be


– explicit, e.g., x = "at Bucharest"
states: various cities – implicit, e.g., Checkmate(x)
actions: drive between cities 4. path cost (additive)
– e.g., sum of distances, number of actions executed, etc.
Find solution: – c(x,a,y) is the step cost, assumed to be ≥ 0
Many sequence of cities. • A solution is
But the optimal is: Arad, Sibiu, Fagaras, Bucharest – a sequence of actions leading from the initial state to a goal state

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

Example: The 8-puzzle Example: The 8-puzzle

• states? locations of tiles


• states? • actions? move blank left, right, up, down
• goal test? = goal state (given)
• actions? • path cost? 1 per move

• goal test? [Note: optimal solution of n-Puzzle family is NP-hard]

• path cost?

15 16

4
07-May-24

Example: robotic assembly Problem-solving agents

• 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

How to represent State Space Search


for solving it Mathematically

State space search can be represented mathematically


using a graph or tree structure. Here's a basic
mathematical representation:

19 20

5
07-May-24

Mathematical Representations

Tree
Representation

21 22

Solving??? This state space search searches the


solution in two different ways:

Uninformed Search Informed Search


Once represented mathematically • Breadth First Search (BFS) • Greedy Best First Search
• Depth First Search (DFS) • A* Search
how to solve??? • Depth Limited Search
• Iterative Deeping DFS
• Bidirectional Search
• Uniform Cost Search
Which Algorithm? No information about the number A cleverer strategy that searches
of steps or the path cost from the toward the goal, based on the
Which Model? current state to the goal search the information from the current state
state space blindly . so far.
Why?

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

Advantages and Disadvantages of BFS Advantages and Disadvantages of DFS


Advantages Disadvantages Advantages Disadvantages
• Completeness: BFS is complete, meaning • Memory Intensive: Requires a lot of • Memory Efficiency: DFS is memory- • Completeness Not Guaranteed: DFS is not
if a solution exists, BFS will find it. memory as it stores all generated nodes at efficient as it only needs to store a stack of complete; it might get stuck in infinite loops
• Optimality: When the cost between nodes each level. nodes along the current path. or paths.
is uniform, BFS guarantees the shortest • Slower for Deep and Branching Search • Speed: In certain cases, DFS can be faster • Not Optimal: DFS does not guarantee the
path. Spaces: In search spaces with high than BFS, especially when the solution is shortest path.
• No Heuristic Required: It does not branching factors or deep levels, BFS can deep. • Can Get Trapped in Infinite Branches: In
be slow and inefficient. spaces with infinite branching (like in some
require a heuristic function. • Simplicity: The algorithm is simple to
game trees), DFS might get trapped in deep
• Guaranteed Solution: If a solution is • Not Suitable for Infinite Spaces: In implement using recursion or a stack.
branches.
reachable within a finite number of steps, spaces with infinite branching or depth, • Can Find Solutions Deep in the Tree: • Not Suitable for Finding Shortest Paths:
BFS will find it. BFS may not terminate. DFS goes deep into a branch before Since DFS doesn't consider all paths at a
• Suitable for Finding Shortest Paths: • Not Suitable for Non-Uniform Cost backtracking, which can be advantageous given level, it might not find the shortest path.
Because BFS explores all nodes at a given Problems: In cases where the cost in certain cases. • Dependent on Path Length: The solution
depth before moving to the next level, it is between nodes varies, BFS may not find • Suitable for Infinite Spaces: DFS can be found by DFS depends on the path length; if a
well-suited for finding the shortest path. the optimal solution. used in infinite spaces, like in games with shorter path exists, but it is not on the
• Avoids Repetition: BFS doesn't revisit large or infinite state spaces. explored path, DFS will not find it.
nodes it has already visited.

27 28

7
07-May-24

Depth Limited Search Advantages and Disadvantages of DLS


Depth-Limited Search (DLS) is a modification of Depth-First Search
(DFS) where a depth limit is imposed on the search.
Advantages Disadvantages
• This limit restricts the depth of the search, preventing the algorithm from going • Avoids infinite loops in search • The depth limit must be chosen
too deep into the search tree or graph. spaces with infinite branching. carefully to balance efficiency and
• If the depth limit is reached and the goal is not found, the algorithm backtracks • Saves memory by not storing completeness.
as in traditional DFS. unnecessary paths. • Not suitable if the optimal
• Can be more efficient than DFS in solution lies beyond the depth
Depth-first with depth cutoff k (maximal depth below which nodes are
certain scenarios with a limited limit.
not expanded)
search depth. • Can miss solutions if the depth
• Three possible outcomes: limit is too low.
– Solution
– Failure (no solution)
– Cutoff (no solution within cutoff)

29 30

Iterative Deepening DFS (IDDFS) Advantages and Disadvantages of


IDDFS
Iterative Deepening Depth-First Search (IDDFS) is a combination of Depth-
First Search (DFS) and Breadth-First Search (BFS). It addresses the main
drawback of regular DFS, which is its lack of completeness and optimality
Advantages Disadvantages
when the depth of the solution is unknown. IDDFS repeatedly performs • Complete: IDDFS is complete, • Inefficient for large branching factors:
DFS with increasing depth limits until a solution is found. meaning it will find a solution if one The number of nodes explored can be
exists. large for high branching factors.
• Optimal: When path costs are non- • Redundant work: IDDFS may repeat
decreasing, IDDFS finds the optimal work at each depth level.
solution.
• Memory Efficiency: It is memory
efficient as it explores nodes level by
level.
• Does not need to store the entire
search tree in memory.
IDDFS calls DFS for different depths starting from an initial value. In every call,
DFS is restricted from going beyond given depth. So basically we do DFS in a BFS
fashion.
31 32

8
07-May-24

Advantages and Disadvantages of


Bidirectional Search
Bidirectional Search
Bidirectional Search is a search algorithm that operates simultaneously from
the start and goal states, aiming to find a path between them.
Advantages Disadvantages
• Efficient for large search spaces. • Requires bidirectional connections
How Bidirectional Search • Reduces the search space by meeting between start and goal states.
Works: in the middle. • Requires more memory for storing
• Can be more time-efficient than visited nodes in both directions.
Start:
traditional searches. • Complex to implement compared to
Begin from both the start and goal
• Guarantees optimality if both traditional single-ended searches.
states.
Expand: searches use an optimal algorithm. • In some cases, might not be more
Simultaneously expand nodes from efficient than single-ended searches
both ends. due to overhead.
Intersect:
When the two searches meet in the
middle, a path is found.

33 34

Uniform Cost Search Example: Uniform Cost Search


Uniform Cost Search (UCS) is a search algorithm used for finding the
lowest-cost path to a goal state in a weighted graph. It expands nodes based
on their path cost from the initial state and always selects the node with the
lowest total cost.

How this Search Works:

Start: Begin at the initial state.


Expand Nodes: Expand nodes based on their total cost from the initial state.
Priority Queue: Use a priority queue to keep track of nodes, with the lowest-
cost node having the highest priority.
Update Costs: Update the cost of reaching each node as the search S to be the start node and G to be the goal state.
progresses. Always chooses the best minimum cost path from current path.
Goal Test: When a goal state is reached, terminate the search and return S-> G = 12
the lowest-cost path. S->A->C->D->G = 1+1+1+3 = 6
Here, the optimal solution in S->A->C->G = 1+1+2 = 4, but the UCS has
Uniform-Cost Search is a variant of Dijikstra’s algorithm. failed to find it.
35 36

9
07-May-24

Advantages and Disadvantages of


Uniform Cost Search
Advantages Disadvantages
• Optimality: Guarantees finding the • Time Complexity: Can be high due to
exploring all possible paths.
shortest path in terms of total path
• Space Complexity: Requires storing
cost.
• Completeness: Will find a solution if

information about all explored nodes and
costs.
Inefficient for Large Graphs: May become
Informed Searching methods
one exists. inefficient in large graphs.
• Flexibility: Handles graphs with • Not Suitable for Uninformed Search: Lacks
varying edge costs. domain-specific knowledge or heuristics.
• Handling Negative Edge Costs: Does not
• No Heuristic Required: Does not handle negative edge costs well.
need a heuristic function, simplifying • Potential for Endless Search: Can get stuck
implementation. in infinite loops in certain graph structures.
• Requires Complete Information: Assumes
complete knowledge of graph, including edge
costs.

37 38

Greedy Best First Search Algorithm


• Initialize a tree with the
• Greedy best-first search is an informed search algorithm root node being the start
node in the open list.
where the evaluation function is strictly equal to the heuristic • If the open list is empty,
function, disregarding the edge weights in a weighted graph return a failure,
because only the heuristic value is considered. otherwise, add the
current node to the
• In order to search for a goal node it expands the node that is closed list.
closest to the goal as determined by the heuristic function. • Remove the node with
the lowest h(x) value
• This approach assumes that it is likely to lead to a solution from the open list for
quickly. exploration.
• However, the solution from a greedy best-first search may not • If a child node is the
target, return a success.
be optimal since a shorter path may exist. Otherwise, if the node
has not been in either the
open or closed list, add
it to the open list for
39 40
exploration.

10
07-May-24

Example Example
Ignored
Path

41 42

Advantages and Disadvantages of


A* Search
Greedy Best First Search
Advantages Disadvantages A* search is a graph search algorithm that evaluates nodes by
• Efficiency: GBFS is generally more efficient • Completeness: GBFS is not guaranteed to find a a function f(n), which combines a new term, g(n), or the cost
than uninformed search algorithms like BFS solution even if one exists. It can get stuck in local
or DFS because it uses heuristic information optima, especially if the heuristic is not admissible. to reach the node, and h(n), the cost to get from the node to the
to guide the search. • Optimality: It does not guarantee the optimal
• Domain-Specific Knowledge: It can make
solution. GBFS can find a solution quickly, but it
might not be the shortest path if the heuristic is not
goal.
use of domain-specific knowledge through accurate.
the heuristic function, which can lead to more • Heuristic Quality: The performance of GBFS – Uses heuristic to guide search
informed search decisions. heavily depends on the quality of the heuristic
• Memory Efficiency: It does not require as function. An inaccurate heuristic can lead to
inefficient search or incorrect results.
– While ensuring that it will compute a path with minimum
much memory as algorithms like A* because
it does not need to store the entire path from • Local Optima: GBFS tends to get stuck in local
optima because it always chooses the node that
cost
the start node to the current node. appears closest to the goal at each step, without
• Quick Initial Solution: GBFS can find a considering the overall path cost. “estimated cost”
solution quickly, especially when the heuristic • No Backtracking: Since GBFS does not keep track
provides good guidance towards the goal. of the entire path, it cannot backtrack and explore
other paths if it gets stuck. • A* computes the function f(n) = g(n) + h(n)
• Incomplete: If the heuristic function is not
admissible, GBFS might fail to find a solution even
if one exists.
“actual cost”

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

A*: minimize f(n) = g(n) + h(n)


33

Heuristic can be used to control A*’s behavior Properties of A*


• A* generates an optimal solution if h(n) is an admissible heuristic
• At one extreme, if h(n) is 0, then only g(n) plays a role, and A* turns into Dijkstra’s and the search space is a tree:
Algorithm, which is guaranteed to find a shortest path.
• If h(n) is always lower than (or equal to) the cost of moving from n to the goal, then
– h(n) is admissible if it never overestimates the cost to reach the
A* is guaranteed to find a shortest path. The lower h(n) is, the more node A* destination node
expands, making it slower. • A* generates an optimal solution if h(n) is a consistent heuristic and
• If h(n) is exactly equal to the cost of moving from n to the goal, then A* will only the search space is a graph:
follow the best path and never expand anything else, making it very fast.
Although you can’t make this happen in all cases, you can make it exact in some – h(n) is consistent if for every node n and for every successor node n’
special cases. It’s nice to know that given perfect information, A* will behave of n:
perfectly.
h(n)
• If h(n) is sometimes greater than the cost of moving from n to the goal, then A* is h(n) ≤ c(n, n’) + h(n’) n
not guaranteed to find a shortest path, but it can run faster. d
• At the other extreme, if h(n) is very high relative to g(n), then only h(n) plays a role, c(n,n’) h(n’)
and A* turns into Greedy Best-First-Search. n’
• If h(n) is consistent then h(n) is admissible
• Frequently when h(n) is admissible, it is also consistent
47

12
07-May-24

Example:8-Puzzle problem

49 50

Consider the following graph:


Solution:
1. The numbers written on edges represent the distance between the nodes. i.e. g(n)
At A: we have B and F to move
2. The numbers written on nodes represent the heuristic value. i.e. h(n)
Therefore:
3. Find the most cost-effective path to reach from start state A to final state J using A* Algorithm.
For F(B) = g(n) +h(n)
= 6 + 8 = 14
For F(F) = g(n) +h(n)
=3+6=9
So, We choose F.
At F: we have G and H to move
Therefore:
For F(G) = g(n) +h(n)
= (3+1) + 5 = 9 At I: we have E, H and J to move
For F(H) = g(n) +h(n) Therefore:
= (3+7) + 3 = 13 For F(E) = g(n) +h(n)
So, We choose G. = (3+1+3+5) + 3 = 15
For F(H) = g(n) +h(n)
At G: we have only I to move = (3+1+3+2) + 3 = 12
Therefore: For F(J) = g(n) +h(n)
For F(G) = g(n) +h(n) = (3+1+3+3) + 0 = 10
= (3+1+3) + 1 = 8 So, We choose J.
So, We choose I.
51 52

13
07-May-24

Advantages and Disadvantages of A*


Search Algorithm
Advantages Disadvantages
• Completeness: A* is complete, meaning it is guaranteed • Heuristic Quality: A* heavily relies on the quality of the
to find a solution if one exists, provided certain heuristic function. If the heuristic function is poorly designed
conditions are met (such as finite search space and or not admissible, A* may not perform optimally and could
appropriate heuristic). potentially expand more nodes than necessary.
• Optimality: When the heuristic function is admissible • Memory Usage: A* maintains a priority queue of nodes to
(never overestimates the true cost) and the cost function be explored, which can lead to high memory usage,
satisfies the triangle inequality, A* is optimal, meaning especially in cases of large search spaces or when using
it finds the shortest path from the start to the goal node. complex data structures to store node information.
• Efficiency: A* is generally more efficient than • Time Complexity: While A* is generally efficient, its time
uninformed search algorithms like breadth-first search or complexity can be high in certain scenarios, particularly
uniform cost search because it incorporates domain- when the heuristic function is not well-suited to the problem
specific information through the heuristic function, domain or when the search space is vast.
guiding the search towards the goal.
• Complexity Analysis: Analyzing the computational
• Flexibility: A* can be adapted to various problem
complexity of A* can be challenging, as it depends not only
domains by modifying the heuristic function to suit
on the size of the search space but also on the characteristics
specific requirements, making it a versatile algorithm.
of the heuristic function and the cost function.

53 54

14

You might also like