Informed and Uninformed Search

download Informed and Uninformed Search

of 74

Transcript of Informed and Uninformed Search

  • 8/9/2019 Informed and Uninformed Search

    1/74

    Lecture 2

    Solving Problems by Searching

    Marco Chiarandini

    Department of Mathematics & Computer ScienceUniversity of Southern Denmark

    Slides by Stuart Russell and Peter Norvig

  • 8/9/2019 Informed and Uninformed Search

    2/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleLast Time

    Agents are used to provide a consistent viewpoint on various topics inthe field AI

    Essential concepts:

    Agents intereact with environment by means of  sensors and actuators.A rational agent does “the right thing”  ≡  maximizes a performancemeasure PEAS

    Environment types: observable, deterministic, episodic, static, discrete,single agent

    Agent types: table driven (rule based), simple reflex, model-based reflex,goal-based, utility-based, learning agent

    2

  • 8/9/2019 Informed and Uninformed Search

    3/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleStructure of Agents

    Agent = Architecture + Program

    Architecture

    operating platform of the agent

    computer system, specific hardware, possibly OS

    Program

    function that implements the mapping from percepts to actions

    This course is about the program,not the architecture

    3

  • 8/9/2019 Informed and Uninformed Search

    4/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleOutline

    1.  Problem Solving Agents

    2.  Search

    3.  Uninformed search algorithms

    4.   Informed search algorithms

    5.  Constraint Satisfaction Problem

    5

  • 8/9/2019 Informed and Uninformed Search

    5/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleOutline

    1.  Problem Solving Agents

    2.  Search

    3.  Uninformed search algorithms

    4.   Informed search algorithms

    5.  Constraint Satisfaction Problem

    6

  • 8/9/2019 Informed and Uninformed Search

    6/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleOutline

    ♦   Problem-solving agents

    ♦   Problem types♦   Problem formulation♦   Example problems♦  Basic search algorithms

    7

  • 8/9/2019 Informed and Uninformed Search

    7/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleProblem-solving agents

    Restricted form of general agent:

    function  Simple-Problem-Solving-Agent( percept )   returns  an actionstatic:   seq , an action sequence, initially empty

    state , some description of the current world stategoal , a goal, initially nullproblem, a problem formulation

    state ←Update-State(state,percept )if  seq  is empty  then

    goal ←Formulate-Goal(state )problem←Formulate-Problem(state,goal )

    seq ←Search(problem)action←Recommendation(seq, state )seq ←Remainder(seq, state )return  action

    Note: this is offline problem solving; solution executed “eyes closed.”

    Online problem solving involves acting without complete knowledge.8

  • 8/9/2019 Informed and Uninformed Search

    8/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleExample: Romania

    On holiday in Romania; currently in Arad.Flight leaves tomorrow from Bucharest

    Formulate goal:

    be in Bucharest

    Formulate problem:states: various citiesactions: drive between cities

    Find solution:sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest

    9

  • 8/9/2019 Informed and Uninformed Search

    9/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleExample: Romania

    Giurgiu

    UrziceniHirsova

    Eforie

    NeamtOradea

    Zerind

    Arad

    Timisoara

    Lugoj

    Mehadia

    Dobreta

    Craiova

    Sibiu  Fagaras

    Pitesti

    Vaslui

    Iasi

    Rimnicu Vilcea

    Bucharest

    71

    75

    118

    111

    70

    75

    120

    151

    140

    99

    80

    97

    101

    211

    138

    146   85

    90

    98

    142

    92

    87

    86

    10

  • 8/9/2019 Informed and Uninformed Search

    10/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleState space Problem formulation

    A problem is defined by five items:

    1.   initial state   e.g., “at Arad”

    2.   actions defining the other states, e.g.,  Go(Arad)

    3.   transition model  res(x, a)e.g.,  res(In(Arad), Go(Zerind)) = In(Zerind)

    alternatively: set of action–state pairs:{(In(Arad), Go(Zerind)), In(Zerind), . . .}

    4.   goal test, can beexplicit, e.g.,  x = “at Bucharest”implicit, e.g.,  NoDirt(x)

    5.   path cost (additive)e.g., sum of distances, number of actions executed, etc.c(x,a,y)   is the step cost, assumed to be  ≥ 0

    A solution is a sequence of actions

    leading from the initial state to a goal state11

  • 8/9/2019 Informed and Uninformed Search

    11/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleSelecting a state space

    Real world is complex⇒  state space must be  abstracted  for problem solving

    (Abstract) state = set of real states

    (Abstract) action = complex combination of real actions

    e.g., “Arad  →  Zerind” represents a complex setof possible routes, detours, rest stops, etc.

    For guaranteed realizability,  any  real state “in Arad”must get to some real state “in Zerind”

    (Abstract) solution =

    set of real paths that are solutions in the real world

    Each abstract action should be “easier” than the original problem!

    Atomic representation

    12

  • 8/9/2019 Informed and Uninformed Search

    12/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleVacuum world state space graph

    Example

    R

    L

    S   S

    S S

    R

    L

    R

    L

    R

    L

    S

    SS

    S

    L

    L

    LL R

    R

    R

    R

    states??: integer dirt and robot locations (ignore dirt  amounts etc.)actions??:   Left,  Right,  Suck,  NoOptransition model??: arcs in the digraphgoal test??: no dirtpath cost??: 1 per action (0 for  NoOp)

    13

    bl l

  • 8/9/2019 Informed and Uninformed Search

    13/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleExample: The 8-puzzle

    2

    Start State Goal State

    51 3

    4 6

    7 8

    5

    1

    2

    3

    4

    6

    7

    8

    5

    states??: integer locations of tiles (ignore intermediate positions)

    actions??: move blank left, right, up, down (ignore unjamming etc.)transition model??: effect of the actionsgoal test??: = goal state (given)path cost??: 1 per move

    [Note: optimal solution of  n-Puzzle family is NP-hard]

    14

    P bl S l i A

  • 8/9/2019 Informed and Uninformed Search

    14/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleExample: robotic assembly

    R

    RR

    P

    R   R

    states??: real-valued coordinates of robot joint angles

    parts of the object to be assembledactions??: continuous motions of robot jointsgoal test??: complete assembly  with no robot included!path cost??: time to execute

    15

    P bl S l i A t

  • 8/9/2019 Informed and Uninformed Search

    15/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleProblem types

    Deterministic, fully observable, known, discrete  =⇒  state space problemAgent knows exactly which state it will be in; solution is a sequence

    Non-observable  =⇒  conformant problem

    Agent may have no idea where it is; solution (if any) is a sequence

    Nondeterministic and/or partially observable  =⇒  contingency problempercepts provide  new  information about current statesolution is a contingent plan or a policyoften   interleave   search, execution

    Unknown state space  =⇒  exploration problem (“online”)

    16

    Problem Solving Agents

  • 8/9/2019 Informed and Uninformed Search

    16/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleExample: vacuum world

    State space, start in #5.   Solution??[Right, Suck]

    Non-observable, start in  {1, 2, 3, 4, 5, 6, 7, 8}

    e.g.,  Right  goes to  {2, 4, 6, 8}.   Solution??[Right, Suck, Lef t, Suck]

    Contingency, start in #5Murphy’s Law:   Suck  can dirty a clean carpet

    Local sensing: dirt, location only.Solution??

    [Right, if   dirt  then  Suck]

    1 2

    3 4

    5 6

    7 8

    17

    Problem Solving Agents

  • 8/9/2019 Informed and Uninformed Search

    17/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleExample Problems

    Toy problems

    vacuum cleaner agent8-puzzle8-queens

    cryptarithmeticmissionaries and cannibals

    Real-world problems

    route finding

    traveling salespersonVLSI layoutrobot navigationassembly sequencing

    18

    Problem Solving Agents

  • 8/9/2019 Informed and Uninformed Search

    18/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleOutline

    1.  Problem Solving Agents

    2.  Search

    3.  Uninformed search algorithms

    4.   Informed search algorithms

    5.  Constraint Satisfaction Problem

    19

    Problem Solving Agents

  • 8/9/2019 Informed and Uninformed Search

    19/74

    g gSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleObjectives

    Formulate appropriate problems in optimization and planning (sequenceof actions to achive a goal) as search tasks:initial state, operators, goal test, path cost

    Know the fundamental search strategies and algorithms

    uninformed searchbreadth-first, depth-first, uniform-cost, iterative deepening, bi-

    directional

    informed search

    best-first (greedy, A*), heuristics, memory-bounded

    Evaluate the suitability of a search strategy for a problem

    completeness, optimality, time & space complexity

    20

    Problem Solving Agents

  • 8/9/2019 Informed and Uninformed Search

    20/74

    g gSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleSearching for Solutions

    Traversal of some search spacefrom the initial state to a goal statelegal sequence of actions as defined by operators

    The search can be performed on

    On a search tree derived fromexpanding the current state using the possible operatorsTree-Search algorithm

    A graph representingthe state spaceGraph-Search algorithm

    22

    Problem Solving Agentsh

  • 8/9/2019 Informed and Uninformed Search

    21/74

    SearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleSearch: Terminology

    23

    Problem Solving AgentsS h

  • 8/9/2019 Informed and Uninformed Search

    22/74

    SearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleExample: Route Finding

    Giurgiu

    UrziceniHirsova

    Eforie

    Neamt

    Oradea

    Zerind

    Arad

    Timisoara

    Lugoj

    Mehadia

    Dobreta

    Craiova

    Sibiu   Fagaras

    Pitesti

    Vaslui

    Iasi

    Rimnicu Vilcea

    Bucharest

    71

    75

    118

    111

    70

    75

    120

    151

    140

    99

    80

    97

    101

    211

    138

    146   85

    90

    98

    142

    92

    87

    86

    24

    Problem Solving AgentsS h

  • 8/9/2019 Informed and Uninformed Search

    23/74

    SearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleTree search example

    Lugoj AradArad OradeaRimnicu Vilcea

    Zerind

    Arad

    Sibiu

    Arad Fagaras Oradea

    Timisoara

    25

    Problem Solving AgentsSearch

  • 8/9/2019 Informed and Uninformed Search

    24/74

    SearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleGeneral tree search

    26

    Problem Solving AgentsSearch

  • 8/9/2019 Informed and Uninformed Search

    25/74

    SearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleImplementation: states vs. nodes

    A state  is a (representation of) a physical configurationA node is a data structure constituting part of a search tree

    includes state, parent, action, path cost  g(x)States do not have parents, children, depth, or path cost!

    1

    23

    45

    6

    7

    81

    23

    45

    6

    7

    8

    State Nodedepth = 6

    g = 6

     s t a t e

    parent, action

    The Expand function creates new nodes, filling in the various fields using theTransition Model of the problem to create the corresponding states.

    27

    Problem Solving AgentsSearch

  • 8/9/2019 Informed and Uninformed Search

    26/74

    SearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleImplementation: general tree search

    function Tree-Search( problem, fringe )  returns  a solution, or failure

    fringe ← Insert(Make-Node(Initial-State[problem]), fringe )loop do

    if   fringe   is empty  then return   failurenode ←Remove-Front(fringe )if  Goal-Test(problem, State(node ))  then return  node fringe ← InsertAll(Expand(node ,problem), fringe )

    function Expand( node,problem)  returns  a set of nodessuccessors ← the empty setfor each  action, result   in   Successor-Fn(problem, State[node ])  do

    s ← a new NodeParent-Node[s ]← node ; Action[s ]← action; State[s ]← result 

    Path-Cost[s ]←Path-Cost[node ] + Step-Cost(State[node ], action,result )

    Depth[s ]←Depth[node ] + 1add  s  to  successors 

    return  successors 

    28

    Problem Solving AgentsSearch

  • 8/9/2019 Informed and Uninformed Search

    27/74

    Uninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleSearch strategies

    A strategy is defined by picking the  order of node expansion

    function Tree-Search( problem, fringe )  returns  a solution, or failurefringe ←   Insert(Make-Node(Initial-State[problem]), fringe )loop do

    if   fringe   is empty  then return   failurenode ←   Remove-Front(fringe )

    if  Goal-Test(problem, State(node ))  then return  node fringe ←   InsertAll(Expand(node ,problem), fringe )

    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 memoryoptimality—does it always find a least path cost solution?

    Time and space complexity are measured in terms of b—maximum branching factor of the search treed—depth of the least-cost solutionm—maximum depth of the state space (may be  ∞)

    29

    Problem Solving AgentsSearch

  • 8/9/2019 Informed and Uninformed Search

    28/74

    Uninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleOutline

    1.  Problem Solving Agents

    2.  Search

    3.  Uninformed search algorithms

    4.   Informed search algorithms

    5.  Constraint Satisfaction Problem

    30

  • 8/9/2019 Informed and Uninformed Search

    29/74

    Problem Solving AgentsSearchU i f d h l i h

  • 8/9/2019 Informed and Uninformed Search

    30/74

    Uninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleBreadth-first search

    Expand shallowest unexpanded node (shortest path in the frontier)

     A

     B C 

     D E F G

     A

     B

     D E F 

    Implementation:fringe  is a FIFO queue, i.e., new successors go at end

    32

    Problem Solving AgentsSearchU i f d h l ith

  • 8/9/2019 Informed and Uninformed Search

    31/74

    Uninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleProperties of breadth-first search

    Complete??  Yes (if  b   is finite)Optimal??  Yes (if cost = 1 per step); not optimal in general

    Time??   1 + b + b2 + b3 + . . . + bd + b(bd − 1) = O(bd+1), i.e., exp. in  dSpace??   bd−1 + bd = O(bd)  (explored + frontier)

    Space  is the big problem; can easily generate nodes at 100MB/secso 24hrs = 8640GB.

    33

    Problem Solving AgentsSearchUninformed search algorithms

  • 8/9/2019 Informed and Uninformed Search

    32/74

    Uninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleUniform-cost search

    Expand first least-cost path

    (Equivalent to breadth-first if step costs all equal)

    Implementation:

    fringe  = priority queue ordered by path cost, lowest first,

    Complete??  Yes, if step cost  ≥ Optimal??Yes—nodes expanded in increasing order of  g(n)

    Time??  # of nodes with  g ≤   cost of optimal solution,  O(b1+C ∗/

    )where  C ∗ is the cost of the optimal solution

    Space??# of nodes with  g ≤   cost of optimal solution,  O(b1+C ∗/)

    34

    Problem Solving AgentsSearchUninformed search algorithms

  • 8/9/2019 Informed and Uninformed Search

    33/74

    Uninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleDepth-first search

    Expand deepest unexpanded node

     A

     B C 

     D E F G

     H I J K L M    N O

    Implementation:fringe  = LIFO queue, i.e., put successors at front

    35

    Problem Solving AgentsSearchUninformed search algorithms

  • 8/9/2019 Informed and Uninformed Search

    34/74

    Uninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleProperties of depth-first search

    Complete??  No: fails in infinite-depth spaces, or spaces with loopsModify to avoid repeated states along path

    ⇒  complete in finite spacesOptimal??   NoTime??   O(bm): terrible if  m   is much larger than  d

    but if solutions are dense, may be much faster than breadth-firstSpace??   O(bm), i.e., linear space!

    36

    Problem Solving AgentsSearchUninformed search algorithms

  • 8/9/2019 Informed and Uninformed Search

    35/74

    gInformed search algorithmsConstraint Satisfaction ProbleDepth-limited search

    = depth-first search with depth limit   l,i.e., nodes at depth   l  have no successorsRecursive implementation:

    function Depth-Limited-Search( problem, limit )  returns   soln/fail/cutoff Recursive-DLS(Make-Node(Initial-State[problem]),problem, limit )

    function Recursive-DLS(node ,problem, limit )  returns   soln/fail/cutoff cutoff-occurred? ← falseif  Goal-Test(problem, State[node ])  then return  node else if  Depth[node ] =   limit  then return  cutoff  else for each  successor   in  Expand(node ,problem)  do

    result ←Recursive-DLS(successor ,problem, limit )if   result  =  cutoff   then   cutoff-occurred? ← trueelse if   result  =   failure  then return   result 

    if   cutoff-occurred?  then return  cutoff   else return   failure 

    37

    Problem Solving AgentsSearchUninformed search algorithms

  • 8/9/2019 Informed and Uninformed Search

    36/74

    gInformed search algorithmsConstraint Satisfaction ProbleIterative deepening search

    function  Iterative-Deepening-Search( problem)  returns  a solutioninputs:   problem, a problem

    for depth←   0  to  ∞  doresult ←Depth-Limited-Search(problem,depth)if   result  =  cutoff  then return   result 

    end

    38

  • 8/9/2019 Informed and Uninformed Search

    37/74

    Problem Solving AgentsSearchUninformed search algorithmsI f d h l i h

  • 8/9/2019 Informed and Uninformed Search

    38/74

    Informed search algorithmsConstraint Satisfaction ProbleProperties of iterative deepening search

    Complete??   YesOptimal??  Yes, if step cost = 1

    Can be modified to explore uniform-cost treeTime??   (d + 1)b0 + db1 + (d − 1)b2 + . . . + bd = O(bd)Space??   O(bd)

    Numerical comparison in time for  b = 10  and  d = 5, solution at far right leaf:

    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

    IDS does better because other nodes at depth  d  are not expandedBFS can be modified to apply goal test when a node is  generatedIterative lenghtening not as successul as IDS

    40

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithms

  • 8/9/2019 Informed and Uninformed Search

    39/74

    Informed search algorithmsConstraint Satisfaction ProbleBidirectional Search

    Search simultaneously (using breadth-first search)from goal to startfrom start to goal

    Stop when the two search trees intersects

    41

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithms

    iffi i i idi i h

  • 8/9/2019 Informed and Uninformed Search

    40/74

    Informed search algorithmsConstraint Satisfaction ProbleDifficulties in Bidirectional Search

    If applicable, may lead to substantial savings

    Predecessors of a (goal) state must be generatedNot always possible, eg. when we do not know the optimal stateexplicitly

    Search must be coordinated between the two search processes.

    What if many goal states?

    One search must keep all nodes in memory

    42

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithms

    S f l i h

  • 8/9/2019 Informed and Uninformed Search

    41/74

    Informed search algorithmsConstraint Satisfaction ProbleSummary of algorithms

    Criterion Breadth- Uniform- Depth- Depth- IterativeFirst Cost First Limited Deepening

    Complete? Yes∗ Yes∗ No Yes, if    l ≥ d   YesTime   bd+1 b1+C 

    ∗/ bm bl bd

    Space   bd+1 b1+C ∗/ bm bl bd

    Optimal? Yes∗ Yes No No Yes∗

    43

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithms

    S

  • 8/9/2019 Informed and Uninformed Search

    42/74

    Informed search algorithmsConstraint Satisfaction ProbleSummary

    Problem formulation usually requires abstracting away real-world detailsto define a state space that can feasibly be explored

    Variety of uninformed search strategies

    Iterative deepening search uses only linear spaceand not much more time than other uninformed algorithms

    Graph search can be exponentially more efficient than tree search

    46

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithms

    O tli

  • 8/9/2019 Informed and Uninformed Search

    43/74

    gConstraint Satisfaction ProbleOutline

    1.  Problem Solving Agents

    2.  Search

    3.  Uninformed search algorithms

    4.   Informed search algorithms

    5.  Constraint Satisfaction Problem

    47

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithms

    f blR i T h

  • 8/9/2019 Informed and Uninformed Search

    44/74

    Constraint Satisfaction ProbleReview: Tree search

    function Tree-Search( problem, fringe )  returns  a solution, or failurefringe ← Insert(Make-Node(Initial-State[problem]), fringe )loop do

    if   fringe   is empty  then return   failurenode ←Remove-Front(fringe )if  Goal-Test[problem] applied to State(node ) succeeds  return  node fringe ← InsertAll(Expand(node ,problem), fringe )

    A strategy is defined by picking the  order of node expansion

    48

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsC i S i f i blI f d h t t

  • 8/9/2019 Informed and Uninformed Search

    45/74

    Constraint Satisfaction ProbleInformed search strategy

    Informed strategies use agent’s background information about the problemmap, costs of actions, approximation of solutions, ...

    best-first search

    greedy searchA∗search

    local search (not in this course)

    Hill-climbing

    Simulated annealingGenetic algorithmsLocal search in continuous spaces

    49

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsC t i t S ti f ti P blBest first search

  • 8/9/2019 Informed and Uninformed Search

    46/74

    Constraint Satisfaction ProbleBest-first search

    Idea: use an evaluation function for each node– estimate of “desirability”

    ⇒  Expand most desirable unexpanded node

    Implementation:fringe   is a queue sorted in decreasing order of desirability

    Special cases:greedy search

    A∗ search

    50

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleRomania with step costs in km

  • 8/9/2019 Informed and Uninformed Search

    47/74

    Constraint Satisfaction ProbleRomania with step costs in km

    Bucharest

    Giurgiu

    Urziceni

    Hirsova

    Eforie

    NeamtOradea

    Zerind

    Arad

    Timisoara

    LugojMehadia

    DobretaCraiova

    Sibiu

    Fagaras

    PitestiRimnicu Vilcea

    Vaslui

    Iasi

    Straight−line distanceto Bucharest

     0

    160

    242

    161

    77

    151

    241

    366

    193

    178

    253

    329

    80

    199

    244

    380

    226

    234

    374

    98

    Giurgiu

    UrziceniHirsova

    Eforie

    Neamt

    Oradea

    Zerind

    Arad

    Timisoara

    Lugoj

    Mehadia

    Dobreta

    Craiova

    Sibiu   Fagaras

    Pitesti

    Vaslui

    Iasi

    Rimnicu Vilcea

    Bucharest

    71

    75

    118

    111

    70

    75

    120

    151

    140

    99

    80

    97

    101

    211

    138

    146   85

    90

    98

    142

    92

    87

    86

    51

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleGreedy search

  • 8/9/2019 Informed and Uninformed Search

    48/74

    Constraint Satisfaction ProbleGreedy search

    Evaluation function  h(n)  (heuristic)= estimate of cost from  n  to the closest goal

    E.g.,  hSLD(n)  = straight-line distance from  n  to Bucharest

    Greedy search expands the node that  appears  to be closest to goal

    52

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleGreedy search example

  • 8/9/2019 Informed and Uninformed Search

    49/74

    Constraint Satisfaction ProbleGreedy search example

    Arad

    366

    53

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleProperties of greedy search

  • 8/9/2019 Informed and Uninformed Search

    50/74

    Constraint Satisfaction ProbleProperties of greedy search

    Complete??  No–can get stuck in loops, e.g., from Iasi to FargasIasi →  Neamt  →  Iasi →  Neamt  →

    Complete in finite space with repeated-state checkingOptimal??   NoTime??   O(bm), but a good heuristic can give dramatic improvementSpace??   O(bm)

    54

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleA∗ search

  • 8/9/2019 Informed and Uninformed Search

    51/74

    A search

    Idea: avoid expanding paths that are already expensiveEvaluation function  f (n) = g(n) + h(n)

    g(n)  = cost so far to reach  nh(n)  = estimated cost to goal from  n

    f (n)  = estimated total cost of path through  n  to goal

    A∗ search uses an admissible heuristici.e.,  h(n) ≤ h∗(n)  where  h∗(n)   is the  true  cost from  n.(Also require  h(n) ≥ 0, so  h(G) = 0  for any goal  G.)

    E.g.,  hSLD(n)  never overestimates the actual road distanceTheorem: A∗ search is optimal

    55

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleA∗ search example

  • 8/9/2019 Informed and Uninformed Search

    52/74

    A search example

    Zerind

    Arad

    Sibiu

    Arad

    Timisoara

    Sibiu Bucharest

    Rimnicu VilceaFagaras   Oradea

    Craiova Pitesti Sibiu

    Bucharest Craiova Rimnicu Vilcea

    418=418+0

    447=118+329 449=75+374

    646=280+366

    591=338+253 450=450+0   526=366+160   553=300+253

    615=455+160 607=414+193

    671=291+380

    56

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleOptimality of A∗ (standard proof)

  • 8/9/2019 Informed and Uninformed Search

    53/74

    Optimality of A (standard proof)

    Suppose some suboptimal goal  G2  has been generated and is in the queue.Let  n  be an unexpanded node on a shortest path to an optimal goal  G1.

    G

    n

    G2

    Start 

    f (G2) =   g(G2) since  h(G2) = 0> g(G1) since  G2   is suboptimal

    ≥   f (n) since  h  is admissible

    Since  f (G2) > f (n), A∗ will never select  G2   for expansion

    57

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleOptimality of A∗ (more useful)

  • 8/9/2019 Informed and Uninformed Search

    54/74

    Optimality of A (more useful)

    Lemma: A∗ expands nodes in order of increasing  f   value∗

    Gradually adds “f -contours” of nodes (cf. breadth-first adds layers)Contour  i  has all nodes with  f  = f i, where  f i  < f i+1

    O

    Z

    A

    T

    L

    M

    D

    C

    R

    F

    P

    G

    B

    U

    H

    E

    V

    I

    N

    380

    400

    420

    S

    58

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleAstar vs. Depth search

  • 8/9/2019 Informed and Uninformed Search

    55/74

    sta s. Dept sea c

    59

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleProperties of A∗

  • 8/9/2019 Informed and Uninformed Search

    56/74

    p

    Complete??  Yes, unless there are infinitely many nodes with  f  ≤ f (G)Optimal??  Yes—cannot expand  f i+1  until  f i   is finished

    A

    expands all nodes with f 

    (n

    ) < C ∗

    A∗ expands some nodes with  f (n) = C ∗

    A∗ expands no nodes with  f (n) > C ∗

    Time??  Exponential in [relative error in  h  ×  length of sol.]Space??  Keeps all nodes in memory

    60

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleProof of lemma: Consistency

  • 8/9/2019 Informed and Uninformed Search

    57/74

    y

    A heuristic is consistent if 

    n

    c(n,a,n’)

    h(n’)

    h(n)

    G

    n’

    h(n) ≤ c(n,a,n) + h(n)

    If  h   is consistent, we have

    f (n) =   g(n) + h(n)

    =   g(n) + c(n,a,n) + h(n)

    ≥   g(n) + h(n)

    =   f (n)

    I.e., f (n)   is nondecreasing along any path.

    61

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleAdmissible heuristics

  • 8/9/2019 Informed and Uninformed Search

    58/74

    E.g., for the 8-puzzle:

    h1(n)  = number of misplaced tilesh2(n)  = total Manhattan distance

    (i.e., no. of squares from desired location of each tile)

    2

    Start State Goal State

    51 3

    4 6

    7 8

    5

    1

    2

    3

    4

    6

    7

    8

    5

    h1(S )  =??h2(S )  =??

    62

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleAdmissible heuristics

  • 8/9/2019 Informed and Uninformed Search

    59/74

    E.g., for the 8-puzzle:

    h1(n)  = number of misplaced tilesh2(n)  = total Manhattan distance

    (i.e., no. of squares from desired location of each tile)

    2

    Start State Goal State

    51 3

    4 6

    7 8

    5

    1

    2

    3

    4

    6

    7

    8

    5

    h1(S )  =??   6h2(S )  =??  4+0+3+3+1+0+2+1 = 14

    63

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleDominance

  • 8/9/2019 Informed and Uninformed Search

    60/74

    If  h2(n) ≥ h1(n)  for all  n  (both admissible)then  h2  dominates  h1  and is better for search

    Typical search costs:

    d = 14   IDS = 3,473,941 nodesA∗(h1)  = 539 nodes

    A∗(h2)  = 113 nodesd = 24   IDS  ≈  54,000,000,000 nodes

    A∗(h1)  = 39,135 nodesA∗(h2)  = 1,641 nodes

    Given any admissible heuristics  ha,  hb,

    h(n) = max(ha(n), hb(n))

    is also admissible and dominates  ha,  hb

    64

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleRelaxed problems

  • 8/9/2019 Informed and Uninformed Search

    61/74

    Admissible heuristics can be derived from the  exactsolution cost of a  relaxed  version of the problem

    If the rules of the 8-puzzle are relaxed so that a tile can move

    anywhere, then  h1(n)  gives the shortest solution

    If the rules are relaxed so that a tile can move to   any adjacent square,then  h2(n)  gives the shortest solution

    Key point: the optimal solution cost of a relaxed problemis no greater than the optimal solution cost of the real problem

    65

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleMemory-Bounded Heuristic Search

  • 8/9/2019 Informed and Uninformed Search

    62/74

    Try to reduce memory needs

    Take advantage of heuristic to improve performance

    Iterative-deepening A∗(IDA∗)

    SMA∗

    67

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleIterative Deepening A∗

  • 8/9/2019 Informed and Uninformed Search

    63/74

    Uniformed Iterative Deepening (repetition)

    depth-first search where the max depth is iteratively increased

    IDA∗

    depth-first search, but only nodes with  f -cost less than or equal tosmallest  f -cost of nodes expanded at last iteration

    was the "best" search algorithm for many practical problems

    68

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleProperties of IDA∗

  • 8/9/2019 Informed and Uninformed Search

    64/74

    Complete??   Yes

    Time complexity??   Still exponentialSpace complexity??   linearOptimal??   Yes. Also optimal in the absence of monotonicity

    69

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleSimple Memory-Bounded A∗

  • 8/9/2019 Informed and Uninformed Search

    65/74

    Use all available memory

    Follow A∗algorithm and fill memory with new expanded nodes

    If new node does not fitremove stored node with worst  f -valuepropagate  f -value of removed node to parent

    SMA∗will regenerate a subtree only when it is needed

    the path through subtree is unknown, but cost is known

    70

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProblePropeties of SMA∗

  • 8/9/2019 Informed and Uninformed Search

    66/74

    Complete??  yes, if there is enough memory for the shortest solution pathTime??  same as A∗if enough memory to store the tree

    Space??  use available memoryOptimal??  yes, if enough memory to store the best solution path

    In practice, often better than A∗and IDA∗trade-off between time and spacerequirements

    71

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleRecursive Best First Search

  • 8/9/2019 Informed and Uninformed Search

    67/74

    72

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleRecursive Best First Search

  • 8/9/2019 Informed and Uninformed Search

    68/74

    Zerind

    Arad

    Sibiu

    Arad   Fagaras   Oradea

    Craiova Sibiu

    Bucharest Craiova Rimnicu Vilcea

    Zerind

    Arad

    Sibiu

    Arad

    Sibiu Bucharest

    Rimnicu VilceaOradea

    Zerind

    Arad

    Sibiu

    Arad

    Timisoara

    Timisoara

    Timisoara

    Fagaras Oradea Rimnicu Vilcea

    Craiova Pitesti Sibiu

    646   415   671

    526   553

    646   671

    450591

    646 671

    526   553

    418  615   607

    447 449

    447

    447 449

    449

    366

    393

    366

    393

    413

    413 417415

    366

    393

    415 450  417

    Rimnicu Vilcea

    Fagaras

    447

    415

    447

    447

    417

    (a) After expanding Arad, Sibiu,

    and Rimnicu Vilcea

    (c) After switching back to Rimnicu Vilcea  and expanding Pitesti

    (b) After unwinding back to Sibiuand expanding Fagaras

    447

    447

    417

    417

    Pitesti

    73

  • 8/9/2019 Informed and Uninformed Search

    69/74

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleConstraint Satisfaction Problem (CSP)

  • 8/9/2019 Informed and Uninformed Search

    70/74

    Standard search problem:state is a “black box”—any old data structure

    that supports goal test, eval, successor

    CSP:

    state is defined by variables  X i   with values from domain  Di

    goal test is a set of  constraints specifyingallowable combinations of values for subsets of variables

    Simple example of a  formal representation language

    Allows useful   general-purpose  algorithms with more powerthan standard search algorithms

    76

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleStandard search formulation

  • 8/9/2019 Informed and Uninformed Search

    71/74

    States are defined by the values assigned so far♦   Initial state: the empty assignment,  { }

    ♦   Successor function: assign a value to an unassigned variablethat does not conflict with current assignment.=⇒   fail if no legal assignments (not fixable!)

    ♦   Goal test: the current assignment is complete

    1) This is the same for all CSPs!2) Every solution appears at depth  n  with  n  variables

    =⇒  use depth-first search3) Path is irrelevant, so can also use complete-state formulation4)  b = (n − )d  at depth  , hence  n!dn leaves!!!!

    77

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleBacktracking search

  • 8/9/2019 Informed and Uninformed Search

    72/74

    Variable assignments are commutative, i.e.,[W A = red  then  N T  = green] same as[N T  = green  then  W A = red]

    Only need to consider assignments to a single variable at each node

    =⇒   b = d  and there are  dn leaves

    Depth-first search for CSPs with single-variable assignmentsis called backtracking searchBacktracking search is the basic uninformed algorithm for CSPs

    Can solve  n-queens for  n ≈ 25

    78

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleBacktracking search

  • 8/9/2019 Informed and Uninformed Search

    73/74

    function  Backtracking-Search(csp )  returns  solution/failurereturn  Recursive-Backtracking({ }, csp )

    function   Recursive-Backtracking(assignment , csp )   returns   soln/fail-ure

    if  assignment  is complete   then return  assignment 

    var ←Select-Unassigned-Variable(Variables[csp ], assignment , csp )for each  value   in  Order-Domain-Values(var , assignment , csp )  doif  value   is consistent with  assignment  given Constraints[csp ]

    then

    add {var  =  value } to  assignment result ←Recursive-Backtracking(assignment , csp )if  result  =  failure  then return  result remove {var  =  value } from  assignment 

    return  failure 

    79

    Problem Solving AgentsSearchUninformed search algorithmsInformed search algorithmsConstraint Satisfaction ProbleSummary

  • 8/9/2019 Informed and Uninformed Search

    74/74

    Uninformed Search

    Breadth-first search

    Uniform-cost search

    Depth-first search

    Depth-limited search

    Iterative deepening search

    Bidirectional Search

    Informed Search

    best-first search

    greedy searchA∗searchIterative Deepening A∗

    Memory bounded A∗

    Recursive best first

    Constraint Satisfaction and Backtracking

    80