Lec04

Download as pdf or txt
Download as pdf or txt
You are on page 1of 72

(TES3111 / TIC3151)

Artificial Intelligence
Lecture 4
Solving Problems by Searching
(Part II)
1

Contents
4.1 Uninformed Search Strategy
4.1.1 Breadth-first search
4.1.2 Uniform-cost search
4.1.3 Depth-first search
4.1.4 Depth-limited search
4.1.5 Iterative deepening search
4.1.6 Bidirectional search
4.2 Comparison of Search Algorithms
4.3 Application of Breadth-first/Depth-first Search to 8- Puzzle
Problem
4.4 Techniques for Avoiding Repeated States
4.5 Searching With Partial Information
2

Uninformed Search Strategies


Uninformed (blind) search
use only the information available in the problem definition
has no additional information about states beyond that
provided in the problem definition
it can distinguish a goal state from non-goal state
Informed search techniques which might have additional
information
Lecture 5

Uninformed Search Strategies


Breadth-first search
Uniform-cost search
Depth-first search

Depth-limited search
Iterative deepening search

Bidirectional search

Uninformed Search Strategies


The general tree-search algorithm
Initialize: put the start node into OPEN
while OPEN is not empty
take a node N from OPEN
if N is a goal node, report success
else
put the children of N onto OPEN
Report failure
If OPEN is a stack, this is a depth-first search
If OPEN is a queue, this is a breadth-first search

If OPEN is a priority queue, sorted according to most promising


first, we have a best-first search
5

Breadth-first search
Root node is expanded first

All the successors of the root node are expanded next


then their successors and so on.

Breadth-first search
Implementation:
Use first-in-first-out (FIFO) queue to ensure that nodes that are
visited first will be expanded first
FIFO queue puts all newly generated nodes (successors) at the end
of the queue
shallow nodes are expanded before deeper nodes

Breadth-first search
Implementation:
Implementation: fringe is a FIFO queue
Fringe - nodes in a queue
waiting to be explored

1
2
4

FRINGE = (1)

3
5

7
Goal

9
8

Breadth-first search
Implementation:

1
2
4

FRINGE = (2, 3)

3
5

9
9

Breadth-first search
Implementation:

1
2
4

FRINGE = (3, 4, 5)

3
5

9
10

Breadth-first search
Implementation:

1
2
4

FRINGE = (4, 5, 6, 7)

3
5

9
11

Breadth-first search
Implementation:

1
2
4

FRINGE = (5, 6, 7, 8)

3
5

9
12

Breadth-first search
Implementation:

1
2
4

FRINGE = (6, 7, 8)

3
5

9
13

Breadth-first search
Implementation:

1
2
4

FRINGE = (7, 8, 9)

3
5

9
14

Breadth-first search
Implementation:

1
2
4

FRINGE = (8, 9)

3
5

7
Goal

9
15

Breadth-first search
Properties of breath-first search
Completeness: Yes (if b is finite, d is finite)
Optimality: Yes (when all actions have the same cost); not in
general

Time Complexity: b + b2 + b3 + b4 + + bd+1 - b = O(bd+1)


Space Complexity: O(bd+1) (Keeps every node in memory)

16

Breadth-first search
Time and Memory Requirements
is the no. of its
Assumptions:
neighbors
Branching factor b =10;
Time 10,000 nodes generated/ second;
Space - 1000 bytes / node

17

Uniform-cost Search (Dijkstra, 1959)


Extension of BF-search
Expand node n with lowest path cost (least-cost path)
Uniform-cost search does not care about the number of steps a
path has, but only about their total cost

Implementation: fringe = queue ordered by path cost

18

Uniform-cost Search (Dijkstra, 1959)


Let g(n) be path cost of node n from the initial state.
Expand the node (unexpanded node) n with the lowest path cost
- QueuingFn: insert in order of increasing path length
Arad
75

Zerind
75

140

118

Sibiu
140

75

71

Arad
150

Oradea
146

Timisoara
118
118

Arad
236
19

111

Lugoj
229

Uniform-cost Search (Dijkstra, 1959)


Uniform-cost algorithm expands nodes in order of increasing path
cost

Find the shortest route


from Sibiu to
Bucharest (goal state)

Part of the Romania state space


20

Uniform-cost Search (Dijkstra, 1959)

80 < 99

Part of the Romania state space


21

Uniform-cost Search (Dijkstra, 1959)


But, Sibiu-Fagaras = 99;
The least-code node is now Fagaras
Sibiu-Fagaras-Bucharest = 99+211 = 310

Cost = 80 + 97 = 177

Part of the Romania state space


22

Uniform-cost Search (Dijkstra, 1959)


Although goal is generated (Sibiu-Fagaras-Bucharest), uniformcost search keeps going; choosing Pitesti for expansion.

Sibiu-Fagaras-Bucharest
= 99+211 = 310

Sibiu-Rimnicu Vilcea-Pitesti
= 80+97+101 = 278

Part of the Romania state space


23

Uniform-cost Search (Dijkstra, 1959)


Compare which path is better?
Sibiu-Fagaras-Bucharest
= 99+211 = 310

Discard
this path

Sibiu-Rimnicu Vilcea-Pitesti
= 80+97+101 = 278

g-cost = 278;

Part of the Romania state space


24

Uniform-cost Search (Dijkstra, 1959)


Properties of Uniform-Cost Search

o Completeness: Yes; if every step cost > (positive constant)


o Optimality: Yes
o Time Complexity: O(b1 C / )
*

where C* is the cost of the


optimal solution, and
assume that every action
costs at least .

o Space Complexity: O(b1 C / )


*

Note:
Uniform-cost search is guided by path costs rather than depths, so its
complexity cannot be categorized in terms of b and d.

25

Uniform-cost Search (Dijkstra, 1959)


Uniform-cost is equivalent to breadth-first when the step cost is
equivalent

Breadth-first search stops as soon as it generates a goal


Uniform-cost search examines all the nodes at the goals
depth to see if one has a lower cost
does more work by expanding nodes at depth d
unnecessarily

26

Depth-first Search
Always expands one of the nodes at the deepest level of the tree.
Only when the search hits a deadend (a non-goal node with no
expansion) search goes back and expands nodes at shallower levels.

Nodes at depth 3 are assumed to have no successors


27

Depth-first Search
Expand deepest unexpanded node.
Implementation: fringe is a LIFO (Last In First Out) queue
(also known as stack)
- QueueingFn: put successors at the front of the queue (LIFO)
Arad
Zerind
Arad
Zerind Sibiu

Sibiu

Timisoara
Note: Depth-first search can
perform infinite cycles excursions.
Need a finite, non-cyclic search
space or repeated-state checking.

Oradea

Timisoara
28

Depth-first Search

29

Depth-first Search

30

Depth-first Search

31

Depth-first Search

32

Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)

33

Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)

34

Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)

35

Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)

36

Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)

37

Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)

38

Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)

39

Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)

Goal node
40

41

Depth-first Search
Implementation
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue (=stack)
1
2
4

FRINGE = (1)

Goal node
42

Depth-first Search
Implementation

1
2

FRINGE = (2, 3)

43

Depth-first Search
Implementation
Depth-first search uses
LIFO queue (stack)

1
2

FRINGE = (4, 5, 3)

44

Depth-first Search
Implementation

1
2

45

Depth-first Search
Implementation

1
2

46

Depth-first Search
Implementation

1
2

47

Depth-first Search
Implementation

1
2

48

Depth-first Search
Implementation

1
2

49

Depth-first Search
Implementation

1
2

50

Depth-first Search
Implementation

1
2

51

Depth-first Search
Implementation

1
2

52

Depth-first Search
Implementation

1
2

53

Depth-first Search
Implementation

1
2

Goal node
54

Depth-first Search
Properties of depth-first search
Complete? No: fails in infinite-depth spaces, spaces with loops
Modify to avoid repeated states along path
complete in finite spaces
Time? O(bm): terrible if m is much larger than d
but if solutions are dense, may be much faster than breadthfirst
m is the maximum depth of any node
Space? O(bm), i.e., linear space!
Optimal? No
If the left subtree is of unbounded depth but contains no solution,
depth-first search would never terminate and so it is not complete.
55

Depth-limited search
Supply depth-first search with a predetermined depth limit l
Solves the infinite-path problem of depth-first search.
But, introduces incompleteness:
if l < d (the shallowest goal is beyond the depth limit) then
incompleteness results
k

Time complexity: O(b )

if l > d then not optimal

Space complexity: O(bk)

Three possible outcomes:


Solution
Standard failure (no solution)
Cutoff (no solution within the depth limit)
56

Depth-limited search
Recursive implementation of depth-limited search

57

Iterative Deepening Search


Breadth-First (BF) and Depth-First (DF) both have exponential
time complexity O(bd)

BF is complete but has exponential space complexity

DF has space efficiency but is incomplete

Can we have an algorithm that

is complete?
Has linear space complexity?
Has time complexity of O(bd)?

58

Iterative Deepening Search


By Korf in 1985
Iterative deepening search finds the best depth limit
It does by gradually increasing the limit first 0, then 1, then 2,
and so on until a goal is found
It terminates when a solution is found or if the depth-limited
search returns failure, meaning that no solution exists.

59

Four iterations of iterative deepening


search on a binary tree
60

Iterative Deepening Search


No. of nodes generated:
N(IDS) = (d)b + (d-1)b2 + + (1)bd
N(BFS) = b + b2 + + bd + (bd+1-b)

Let b = 10 and d = 5,
N(IDS) = 50 + 400 + 3,000 + 20,000 + 100,000 = 123,450
N(BFS) = 10 + 100 + 1,000 + 10,000 + 100,000 + 999,990 = 1,111, 100

There is a real saving in memory.


Iterative deepening is preferred when there is a large search space
and depth of the solution is not known.
61

Iterative Deepening Search


Properties of Iterative Deepening Search

Complete: Yes
Optimal:
Yes for constant edge cost
Time:
db1 + (d-1)b2 + +3b d-2+2b d-1+ 1bd = O(bd)
Space:
O(bd)

Notes:
Maximum space is same as depth-first
Time complexity is the same order as breadth-first, and when branching factor
is large, time is very close even with repeated searches
62

Iterative Deepening Search


Comparison of Strategies
Breadth-first is complete and optimal, but has high space
complexity
Depth-first is space efficient, but neither complete nor optimal
Iterative deepening combines benefits of DFS and BFS and is
asymptotically optimal

63

Bidirectional Search

Initial State

Final State

* Completeness: yes
d/2

* Optimality: yes

* Time complexity: O(bd/2)

* Space complexity: O(bd/2)

O(bd) vs. O(bd/2) ? with b=10 and d=6 results in 1,111,111 vs. 2,222
64

Comparison of Search Algorithms

b: Branching factor (maximum number of successors of any node)

d: Depth of solution (the depth of the shallowest goal node)


m: Maximum depth (the maximum length of any path in the state space
l : Depth Limit

65

Techniques for Avoiding Repeated States


Failure to detect repeated states can turn a solvable problems
into unsolvable ones.

There are two possible actions leading from A to B, two from


B to C, and so on.
66

Techniques for Avoiding Repeated States


Solution for repeated states problem:
Modify the Tree-Search algorithm to include the data structure:
Closed list stores every expanded nodes
If the current node matches a node on the closed list,
it is discarded!
Open list stores the fringe of unexpanded nodes (i.e., stores the
frontier of the search).
Frontier: the set of all leaf
nodes available for expansion
at any given point is

67

Techniques for Avoiding Repeated States


Solution for repeated states problem:

68

Searching with Partial Information


Properties of the task environment
The assumptions made about the environment so far:
Single-state problem

- Fully observable
- Deterministic

Agent knows exactly which state it will be in;


solution is a sequence actions.
Percepts provide no new information after each
action

What happens when the knowledge of


the states / actions is incomplete?
69

Searching with Partial Information


Three types of incompleteness
Sensorless/conformant problems
Contingency problems
Exploration problems

70

Searching with Partial Information


Sensorless/conformant problems non-observable
Agent may have no idea where it is; each action might lead to one of
several possible successor states

Contingency problems Nondeterministic and/or partially


observable
Percepts provide new information about current state;
Each possible percept defines a contingency that must be planned for

Exploration problem (online) Unknown state space (states


and actions)
When states and actions of the environment are unknown;
agent must act to discover them

71

The End

72

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy