0% found this document useful (0 votes)
51 views43 pages

Chapter 3 AI

The document discusses problem solving agents and searching for solutions. It provides an overview of uninformed search strategies, including breadth-first search, uniform-cost search, and depth-first search. Breadth-first search expands the shallowest nodes first using a FIFO queue. Uniform-cost search expands the lowest cost nodes first using a priority queue. Depth-first search expands the deepest nodes first using a LIFO queue.

Uploaded by

nebiyutora566
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)
51 views43 pages

Chapter 3 AI

The document discusses problem solving agents and searching for solutions. It provides an overview of uninformed search strategies, including breadth-first search, uniform-cost search, and depth-first search. Breadth-first search expands the shallowest nodes first using a FIFO queue. Uniform-cost search expands the lowest cost nodes first using a priority queue. Depth-first search expands the deepest nodes first using a LIFO queue.

Uploaded by

nebiyutora566
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/ 43

Overview of Last Topics

• Intelligent Agents
• Agents and Environments
• Rational Agent
• Characteristics of Rational Agent
• Structure of Agents

1/24/2024
Artificial Intelligence
Chapter 3: Solving Problems
by Searching

Teshale G. (MSc)
Email: [email protected]
Department of Computer Science
Madda Walabu University

1/24/2024 Chapter 3: Solving Problems by Searching 2


Overview
 Problem-Solving Agents
 Example Problems
 Searching for Solutions
 Uninformed Search Strategies
 Avoiding Repeated States

1/24/2024 Chapter 3: Solving Problems by Searching 3


Problem-Solving Agents
 Reach goals through sequences of actions
 Formulate the goal(s) and the problem
 Abstraction: Should be easier than original problem
 Search for a sequence of actions to reach a goal
state
 A solution is a sequence of actions from initial state to
a goal state
 Execute the sequence of actions

1/24/2024 Chapter 3: Solving Problems by Searching 4


Problem-Solving Agents

1/24/2024 Chapter 3: Solving Problems by Searching 5


Formulating the Problem
 Initial state = starting state for the agent
 Given a state and a set of actions, the
successor function gives the possible next
states
 Initial state + successor function yields the
state space
 State space = the set of all states reachable
from the initial state

1/24/2024 Chapter 3: Solving Problems by Searching 6


Formulating the Problem,
Continued
 The goal test determines if a state is a
goal state
 A path is a particular sequence of states,
connected by particular actions
 The path cost function assigns a cost to
each path
 Optimal solution: a solution with minimal path
cost

1/24/2024 Chapter 3: Solving Problems by Searching 7


Example Problems
 “Toy” Problems: Simple, but useful for
theory and analysis
 Vacuum world, Sliding-block puzzles, N-
Queens
 Real Problems: The solutions are more
useful, but not as helpful to theory
 Route-finding, touring, assembly sequencing,
Internet searching

1/24/2024 Chapter 3: Solving Problems by Searching 8


Example: The Vacuum World
 States: Location, dirt or not
 Initial State: Given by problem
 Goal: No dirt in any location
 Actions: Left, Right, Vacuum, NoOp
 Path Cost: 1 per action (0 for NoOp)

1/24/2024 Chapter 3: Solving Problems by Searching 9


State Space for the Vacuum World

1/24/2024 Chapter 3: Solving Problems by Searching 10


Example: Driving in Romania
 States: In a city
 Goal: Arrive in Bucharest
 Initial State: in Arad
 Actions: Drive from one city to another

1/24/2024 Chapter 3: Solving Problems by Searching 11


Example: Driving in Romania

1/24/2024 Chapter 3: Solving Problems by Searching 12


Searching for Solutions
 State space can be represented as a search tree
(or graph) of search nodes
 Each node represents a state
 Many nodes can represent the same state
 Each arc represents a valid action from one
state to another
 A solution is a path from initial to goal nodes

1/24/2024 Chapter 3: Solving Problems by Searching 13


Search Nodes
 A search node is a data structure that
contains
 The real-world state represented by the node
 The parent node that generated it
 The action that lead to it
 The path cost to get to it (from the initial state)
 Its depth (the number of steps to reach it from
the initial state)

1/24/2024 Chapter 3: Solving Problems by Searching 14


Searching for Solutions
 The search tree starts with just the root node,
which represents the initial state
 First, use the goal test to see if the root is a goal
 If not, expand this node, which generates new
nodes
 Use successor function to apply valid actions. The
results of these actions lead to new states,
represented by new nodes
 Nodes that are generated, but not yet expanded
are in the fringe, (physically a queue data
structure)
1/24/2024 Chapter 3: Solving Problems by Searching 15
Search Strategies
 Given several states, which to consider
(i.e., goal test, expand, etc.) first?
 This is determined by the particular search
strategy being used in the algorithm

1/24/2024 Chapter 3: Solving Problems by Searching 16


General Idea

Chapter 3: Solving Problems by


1/24/2024 Searching 17
Search Algorithm Performance
 Performance measured along four dimensions:
 Completeness: Will the algorithm always return a solution, if
one exists?
 Optimality: Will it always return the optimal solution, if one
exists?
 Time complexity: How long does it take?
 Space complexity: How much memory does it take?
 Branching factor (b), depth of shallowest goal node (d),
maximum length of any path in the state space (m)
 Search cost vs. total cost
 Tradeoffs

Chapter 3: Solving Problems by


1/24/2024 Searching 18
Uninformed Search
 Uninformed (or “blind”) search algorithms
can only generate successor nodes and
do the goal test
 No other “problem insight”, common sense,
etc. is used in finding a solution
 Search strategies differ in how they
choose which node to check/expand next

Chapter 3: Solving Problems by


1/24/2024 Searching 19
Some Uninformed Search
Algorithms
 Breadth-first search
 Uniform-cost search
 Depth-first search
 Depth-limited search
 Iterative deepening depth-first search
 Bidirectional search

Chapter 3: Solving Problems by


1/24/2024 Searching 20
Breadth-First Search (BFS)
 BFS considers all nodes at a given depth before
moving on to the next depth
 Always expands the shallowest node first
 Implemented in TREE-SEARCH using a first-in
first-out (FIFO) queue
 State to consider is pulled from front of queue
 Generated states are added at the back of the queue
 Check all successors of the root node. Then check all
of their successors, etc.
Chapter 3: Solving Problems by
1/24/2024 Searching 21
Breadth-First Search (BFS)

Chapter 3: Solving Problems by


1/24/2024 Searching 22
Performance of Breadth-First
Search
 Good news
 It is complete
 It is optimal, as long as the path cost function is non-
decreasing (e.g., if all actions have the same cost)
 Bad news
 Time and (especially) space complexity can be
prohibitively high
 Has to keep all nodes in memory: queue gets large
 If d is large, takes a long time to reach a goal

Chapter 3: Solving Problems by


1/24/2024 Searching 23
Uniform-Cost Search (UCS)
 UCS expands the closest (in terms of path cost)
node first
 Ifall step costs are equal, this is equivalent to BFS
 “Closest” means total path cost so far, which is not
necessarily the same as the number of steps
 Implemented in TREE-SEARCH using a first-in
first-out (FIFO) queue
 Stateto consider is pulled from front of queue
 Generated states are added to the queue, then
contents of queue are ordered according to path cost
Chapter 3: Solving Problems by
1/24/2024 Searching 24
Performance of Uniform-Cost
Search
 Good news
 It is complete and optimal, as long as step costs are
positive
 Bad news
 Time and (especially) space complexity can be
prohibitively high, just as with BFS
 Can get stuck in an infinite loop: zero-cost steps,
repeated states

Chapter 3: Solving Problems by


1/24/2024 Searching 25
Depth-First Search (DFS)
 DFS expands the deepest node first
 Implemented in TREE-SEARCH using a last-in
first-out (LIFO) queue
 State to consider is pulled from front of queue
 Generated states are added at the front of the queue
 Check first successor of the root node. Then check its
successor, etc.
 If a non-goal node is reached with no successors,
back up just until an unexpanded node is reached,
then continue.
Chapter 3: Solving Problems by
1/24/2024 Searching 26
Depth-First Search (DFS)

Chapter 3: Solving Problems by


1/24/2024 Searching 27
Depth-First Search (DFS)

Chapter 3: Solving Problems by


1/24/2024 Searching 28
Depth-First Search (DFS)

Chapter 3: Solving Problems by


1/24/2024 Searching 29
Depth-First Search (DFS)

Chapter 3: Solving Problems by


1/24/2024 Searching 30
Depth-First Search (DFS)

Chapter 3: Solving Problems by


1/24/2024 Searching 31
Depth-First Search (DFS)

Chapter 3: Solving Problems by


1/24/2024 Searching 32
Depth-First Search (DFS)

Chapter 3: Solving Problems by


1/24/2024 Searching 33
Depth-First Search (DFS)

Chapter 3: Solving Problems by


1/24/2024 Searching 34
Depth-First Search (DFS)

Chapter 3: Solving Problems by


1/24/2024 Searching 35
Depth-First Search (DFS)

Chapter 3: Solving Problems by


1/24/2024 Searching 36
Depth-First Search (DFS)

Chapter 3: Solving Problems by


1/24/2024 Searching 37
Performance of Depth-First Search

 Good news
 Space complexity is small
 Bad news
 Neithercomplete nor optimal
 Time complexity can be large
 Can get stuck in an infinite loop: repeated states

Chapter 3: Solving Problems by


1/24/2024 Searching 38
Depth-Limited Search (DLS)
 DLS is DFS with a depth limit, L
 Nodes at depth limit are treated as leaves
 Depth limits can come from domain knowledge
 E.g., L = diameter of state space
 Implemented same as DFS, but with depth limit
 Performance
 Incompleteif L < d
 Nonoptimal if L > d
 Time and space complexity <= DFS
Chapter 3: Solving Problems by
1/24/2024 Searching 39
Iterative Deepening Depth-First
Search (IDDFS)
 IDDFS performs DLS one or more times, each
time with a larger depth limit, l
 Start with l = 0, perform DLS
 If goal not found, repeat DLS with l = 1, and so on

 Performance
 Combines benefits of BFS (completeness, optimality)
with benefits of DFS (relatively low space complexity)
 Not as inefficient as it looks
 Repeating low-depth levels: these levels do not have
many nodes Chapter 3: Solving Problems by
1/24/2024 Searching 40
Bidirectional Search
 Perform two searches simultaneously
 One search from the initial state to a goal state
 Another search from a goal state to the initial state
 Stop searching when either search reaches a state
that is in the fringe of the other state (i.e., when they
“meet in the middle”)
 Performance
 Complete and optimal if both searches are BFS
 Not easy to generate predecessors for some goals
(e.g., checkmate)
Chapter 3: Solving Problems by
1/24/2024 Searching 41
Avoiding Repeated States
 Reaching a node with a repeated state
means that there are at least two paths to
the same state
 Can lead to infinite loops
 Keep a list of all nodes expanded so far
(called the closed list; the fringe is the
open list)
 If a generated node’s state matches a state in
the closed list, discard it rather than adding it
to the fringe Chapter 3: Solving Problems by
1/24/2024 Searching 42
End of Chapter 3

Chapter 3: Solving Problems by


1/24/2024 Searching 43

You might also like