L3 Problem Solving n Search p2

download L3 Problem Solving n Search p2

of 43

Transcript of L3 Problem Solving n Search p2

  • 8/3/2019 L3 Problem Solving n Search p2

    1/43

    241-320 Design Architecture and Engineeringfor Intelligent System

    Suntorn Witosurapot

    Contact Address:Phone: 074 287369 or

    Email: [email protected]

    October 2009

  • 8/3/2019 L3 Problem Solving n Search p2

    2/43

    New -Lecture 2:

    Problem Solving and Search

    part 2

    Uninformed Search

  • 8/3/2019 L3 Problem Solving n Search p2

    3/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 3

    Uninformed (Blind) Search

    Many problems are open to attack by search methods

    We shall analyse a number of different searchstrategies

    We begin by examining search methods that have noproblem-specific knowledge to use as guidance

  • 8/3/2019 L3 Problem Solving n Search p2

    4/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 4

    Note: Big O-Notation

    Big-O notation will be used to compare the algorithms.

    This notation defines the asymptotic upper bound ofthe algorithm given the depth (d) of the tree and thebranching factor, or the average number of branches

    (b) from each node.

    O(1) Constant (regardless of thenumber of nodes)

    O(n) Linear (consistent with thenumber of nodes)

    O(log n) Logarithmic

    O(n2) Quadratic

  • 8/3/2019 L3 Problem Solving n Search p2

    5/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 5

    Overview

    Breadth-First Search

    Uniform Cost Search

    Depth-First Search

    Depth-Limited Search

    Iterative Deepening Search

    Bidirectional Search

    Conclusion

  • 8/3/2019 L3 Problem Solving n Search p2

    6/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 6

    Breadth-First Search(BFS)

    Idea: Expand root node, then expand all children ofroot, then expand their children, . . .

    All nodes at depth dare expanded before nodes at d+1

    Can be implemented by using a queue to store frontier nodes

    Breadth-first search finds shallowest goal state

    DEPTH 0

    DEPTH 1

    DEPTH 2

  • 8/3/2019 L3 Problem Solving n Search p2

    7/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 7

    Breadth-First Search

    Expand shallowest unexpanded node

    Implementation: uses a FIFO (first-in-first-out) queue. (i.e. thenew nodes are added to end of the queue, if it is not the goal). Tocontinue the search, the oldest node is dequeued (FIFO order).

  • 8/3/2019 L3 Problem Solving n Search p2

    8/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 8

    Breadth-First Search

    Expand shallowest unexpanded node

  • 8/3/2019 L3 Problem Solving n Search p2

    9/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 9

    Breadth-First Search

    Expand shallowest unexpanded node

  • 8/3/2019 L3 Problem Solving n Search p2

    10/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 10

    Breadth-First Search

    Expand shallowest unexpanded node

  • 8/3/2019 L3 Problem Solving n Search p2

    11/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 11

    Ex: Breadth-First Search in the 8-Puzzle

  • 8/3/2019 L3 Problem Solving n Search p2

    12/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 12

    Recall: Evaluating Searching Strategies

    Strategies are evaluated along the following dimensions:

    completeness does it always find a solution if one exists?

    time complexity number of nodes generated/expanded

    space complexity

    maximum number of nodes in memory

    optimality does it always find a least-cost solution?

    Time and space complexity are measured in terms of

    b max. branching factor () of the search tree d depth of the least-cost solution

    m maximum depth () of the state space(may be )

  • 8/3/2019 L3 Problem Solving n Search p2

    13/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 13

    Breadth-First Search Analysis

    Complete: Yes(b)

    Optimality: Yes (assuming cost = 1 per step, i.e., provided pathcost is nondecreasing function of the depth of the node)

    Time complexity: 1 + b+ b2 + b3 + . . .+ bd, i,e., exponential ind

    where b= forward branching factor; d= path length to solution

    Space complexity: O(bd) (see following slides)

    keeps every node in memory This is a big problem. If we run for 24 hours and generate

    nodes at 10MB/sec, the space requirement is 864 GB

  • 8/3/2019 L3 Problem Solving n Search p2

    14/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 14

    Time complexity of breadth-first search

    If a goal node is found on depth d of the tree, all nodes up till thatdepth are created.

    mGb

    d

    Thus: O(bd)

  • 8/3/2019 L3 Problem Solving n Search p2

    15/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 15

    Space complexity of breadth-first search

    QUEUE contains all and nodes. (Thus: 4) .

    In General: bd

    Largest number of nodes in QUEUE is reached on the level d ofthe goal node.

    Gm

    b

    d

    G

  • 8/3/2019 L3 Problem Solving n Search p2

    16/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 16

    Uniform-cost search (UCS)

    The shallowest solution may not be the best,and a deeper solution with a reduced path cost

    would be better.

    Idea:Expand lowest cost (measured by path cost g(n)) node onthe frontier

    Also known as Lowest-Cost-First search

    UCS is a refinement of the breadth-first strategy:

    Breadth-first search = uniform cost search with

    path cost (g(n))=note depth(depth(n))

  • 8/3/2019 L3 Problem Solving n Search p2

    17/43

    241-320 Design Architecture &Engineering for Intelligent System

    Problem Solving and Search part 2 17

    Depth-First Search

    Idea:Always expand node at deepest level of tree and whensearch hits a dead-end return back to expand nodes at ashallower level

    Can be implemented by using a stack to store frontier nodes

    At any point depth-first search stores single path from root toleaf together with any remaining unexpanded siblings of nodesalong path

  • 8/3/2019 L3 Problem Solving n Search p2

    18/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 18

    Depth-First Search (DFS)

    Expand deepest unexpanded node

    Implementation: Nodes to be reviewed are stored in a LIFOqueue (also known as a stack), i.e., put successors at front

  • 8/3/2019 L3 Problem Solving n Search p2

    19/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 19

    Depth-First Search

    Expand deepest unexpanded node

    Implementation:Nodes to be reviewed are stored in a LIFOqueue (also known as a stack), i.e., put successors at front

  • 8/3/2019 L3 Problem Solving n Search p2

    20/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 20

    Depth-First Search

    Expand deepest unexpanded node

    Implementation: Nodes to be reviewed are stored in a LIFOqueue (also known as a stack), i.e., put successors at front

  • 8/3/2019 L3 Problem Solving n Search p2

    21/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 21

    Depth-First Search

    Expand deepest unexpanded node

    Implementation: Nodes to be reviewed are stored in a LIFOqueue (also known as a stack), i.e., put successors at front

  • 8/3/2019 L3 Problem Solving n Search p2

    22/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 22

    Depth-First Search

    Expand deepest unexpanded node

    Implementation: Nodes to be reviewed are stored in a LIFOqueue (also known as a stack), i.e., put successors at front

  • 8/3/2019 L3 Problem Solving n Search p2

    23/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 23

    Depth-First Search

    Expand deepest unexpanded node

    Implementation: Nodes to be reviewed are stored in a LIFOqueue (also known as a stack), i.e., put successors at front

  • 8/3/2019 L3 Problem Solving n Search p2

    24/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 24

    Depth-First Search

    Expand deepest unexpanded node

    Implementation: Nodes to be reviewed are stored in a LIFOqueue (also known as a stack), i.e., put successors at front

  • 8/3/2019 L3 Problem Solving n Search p2

    25/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 25

    Depth-First Search

    Expand deepest unexpanded node

    Implementation: Nodes to be reviewed are stored in a LIFOqueue (also known as a stack), i.e., put successors at front

  • 8/3/2019 L3 Problem Solving n Search p2

    26/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 26

    Depth-First Search

    Expand deepest unexpanded node

    Implementation: Nodes to be reviewed are stored in a LIFOqueue (also known as a stack), i.e., put successors at front

  • 8/3/2019 L3 Problem Solving n Search p2

    27/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 27

    Depth-First Search

    Expand deepest unexpanded node

    Implementation: Nodes to be reviewed are stored in a LIFOqueue (also known as a stack), i.e., put successors at front

  • 8/3/2019 L3 Problem Solving n Search p2

    28/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 28

    Depth-First Search

    Expand deepest unexpanded node

    Implementation: Nodes to be reviewed are stored in a LIFOqueue (also known as a stack), i.e., put successors at front

  • 8/3/2019 L3 Problem Solving n Search p2

    29/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 29

    Ex: Depth-First Search of the 8-Puzzle

  • 8/3/2019 L3 Problem Solving n Search p2

    30/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 30

    Depth-First Search Analysis

    Storage: O(bm) nodes (where m= max. depth of search tree), i.e.,linear space

    Time: O(bm)

    In cases where problem has many solutions depth-first search mayoutperform breadth-first search because there is a good chance it

    will happen upon a solution after exploring only a small part of the

    search space

    However, depth-first search may get stuck following a deep or

    infinite path even when a solution exists at a relatively shallow level

    Therefore, depth-first search is not complete and not optimal

    Avoid depth-first search for problems with deep or infinite paths

  • 8/3/2019 L3 Problem Solving n Search p2

    31/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 31

    Depth-Limited Search(DLS)

    Idea: impose bound on depth of a path

    In some problems you may know that a solution should be foundwithin a certain cost (e.g. a certain number of moves) and thereforethere is no need to search paths beyond this point for a solution

    Complete but not optimal (may not find shortest solution)

    However, if the depth limit chosen is too small a solution maynot be found and depth-limited search is incomplete in this case

    Time and space complexity similar to depth-first search (butrelative to depth limit rather than maximum depth)

    Depth-Limited Search Analysis

  • 8/3/2019 L3 Problem Solving n Search p2

    32/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 32

    Iterative Deepening Search (IDS)

    Combines the features of depth-first search with thatof breadth-first search.

    Idea:performing Dept-limited search (DLS) searcheswith increased depths until the goal is found

    The depth begins at one, and increases until the goalis found, or no further nodes can be enumerated

  • 8/3/2019 L3 Problem Solving n Search p2

    33/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 33

    Iterative deepening search l = 0

  • 8/3/2019 L3 Problem Solving n Search p2

    34/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 34

    Iterative deepening search l = 1

  • 8/3/2019 L3 Problem Solving n Search p2

    35/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 35

    Iterative deepening search l = 2

  • 8/3/2019 L3 Problem Solving n Search p2

    36/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 36

    Iterative deepening search l = 3

  • 8/3/2019 L3 Problem Solving n Search p2

    37/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 37

    Iterative Deepening Search Analysis

    IDS is advantageous because its not susceptible to cycles(this is a characteristic of DLS, upon which its based).

    It also finds the goal nearest to the root node, as does the BFSalgorithm For this reason, its a preferred algorithm when the

    depth of the solution is not known.

    The time complexity is identical to that of DFS and DLS, O(bd).

    Space complexity of IDS is O(bd).

    Unlike DFS and DLS, IDS is will always find the best solution

    and therefore, it is both complete and optimal.

    Hence, it is the preferred search strategy for a large searchspace where the solution depth is not known

  • 8/3/2019 L3 Problem Solving n Search p2

    38/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 38

    Bidirectional Search

    Idea:a derivative of BFS that operates by performingtwo breadth-first searches simultaneously,

    one beginning from the root node and

    the other from the goal node. When the two searches meet in the middle, a path can

    be reconstructed from the root to the goal. The searches meeting is determined when a common

    node is found (a node visited by both searches). This is accomplished by keeping a closed list of the nodes

    visited.

  • 8/3/2019 L3 Problem Solving n Search p2

    39/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 39

    Bidirectional Search

  • 8/3/2019 L3 Problem Solving n Search p2

    40/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 40

    Bidirectional search

    1. QUEUE1

  • 8/3/2019 L3 Problem Solving n Search p2

    41/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 41

    Bidirectional Search Analysis

    Bidirectional search is an interesting idea, but requires that weknow the goal that were seeking in the graph.

    This isn t always practical, which limits the application of thealgorithm.

    When it can be determined, the algorithm has usefulcharacteristics.

  • 8/3/2019 L3 Problem Solving n Search p2

    42/43

    241-320 Design Architecture &Engineering for Intelligent System Problem Solving and Search part 2 42

    Summary Blind Search

  • 8/3/2019 L3 Problem Solving n Search p2

    43/43

    Conclusion

    We have surveyed a variety of uninformed searchstrategies

    All can be implemented within the framework of the

    general search procedure

    There are other considerations we can make liketrying to save time by not expanding a node whichhas already been seen on some other path

    There are a number of techniques available and oftenuse is made of a hash table to store all nodesgenerated