Problem Solving - PowerPoint PPT Presentation

1 / 85
About This Presentation
Title:

Problem Solving

Description:

States: various cities. Actions: drive between cities. Find solution: ... Time complexity number of nodes generated/expanded ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 86
Provided by: LiseG
Learn more at: http://www.cs.umd.edu
Category:
Tags: problem | solving

less

Transcript and Presenter's Notes

Title: Problem Solving


1
Problem Solving
  • Russell and Norvig Chapter 3
  • CSMSC 421 Fall 2006

2
Problem-Solving Agent
3
Problem-Solving Agent
4
Example Route finding
5
Holiday Planning
  • On holiday in Romania Currently in Arad. Flight
    leaves tomorrow from Bucharest.
  • Formulate Goal
  • Be in Bucharest
  • Formulate Problem
  • States various cities
  • Actions drive between cities
  • Find solution
  • Sequence of cities Arad, Sibiu, Fagaras,
    Bucharest

6
Problem Solving
7
Vacuum World
8
Problem-solving agent
  • Four general steps in problem solving
  • Goal formulation
  • What are the successful world states
  • Problem formulation
  • What actions and states to consider given the
    goal
  • Search
  • Determine the possible sequence of actions that
    lead to the states of known values and then
    choosing the best sequence.
  • Execute
  • Give the solution perform the actions.

9
Problem-solving agent
  • function SIMPLE-PROBLEM-SOLVING-AGENT(percept)
    return an action
  • static seq, an action sequence
  • state, some description of the current world
    state
  • goal, a goal
  • problem, 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 ? FIRST(seq)
  • seq ? REST(seq)
  • return action

10
Assumptions Made (for now)
  • The environment is static
  • The environment is discretizable
  • The environment is observable
  • The actions are deterministic

11
Problem formulation
  • A problem is defined by
  • An initial state, e.g. Arad
  • Successor function S(X) set of action-state
    pairs
  • e.g. S(Arad)ltArad ? Zerind, Zerindgt,
  • intial state successor function state space
  • Goal test, can be
  • Explicit, e.g. xat bucharest
  • Implicit, e.g. checkmate(x)
  • Path cost (additive)
  • e.g. sum of distances, number of actions
    executed,
  • c(x,a,y) is the step cost, assumed to be gt 0
  • A solution is a sequence of actions from initial
    to goal state.
  • Optimal solution has the lowest path cost.

12
Selecting a state space
  • Real world is absurdly complex.
  • State space must be abstracted for problem
    solving.
  • State set of real states.
  • Action complex combination of real actions.
  • e.g. Arad ?Zerind represents a complex set of
    possible routes, detours, rest stops, etc.
  • The abstraction is valid if the path between two
    states is reflected in the real world.
  • Solution set of real paths that are solutions
    in the real world.
  • Each abstract action should be easier than the
    real problem.

13
Example vacuum world
  • States??
  • Initial state??
  • Actions??
  • Goal test??
  • Path cost??

14
Example vacuum world
  • States?? two locations with or without dirt 2 x
    228 states.
  • Initial state?? Any state can be initial
  • Actions?? Left, Right, Suck
  • Goal test?? Check whether squares are clean.
  • Path cost?? Number of actions to reach goal.

15
Example 8-puzzle
  • States??
  • Initial state??
  • Actions??
  • Goal test??
  • Path cost??

16
Example 8-puzzle
  • States?? Integer location of each tile
  • Initial state?? Any state can be initial
  • Actions?? Left, Right, Up, Down
  • Goal test?? Check whether goal configuration is
    reached
  • Path cost?? Number of actions to reach goal

17
Example 8-puzzle
18
Example 8-puzzle
19
Example 8-puzzle
Size of the state space 9!/2
181,440 15-puzzle ? .65 x 1012 24-puzzle ?
.5 x 1025
20
Example 8-queens
Place 8 queens in a chessboard so that no two
queens are in the same row, column, or diagonal.
A solution
Not a solution
21
Example 8-queens problem
  • Incremental formulation vs. complete-state
    formulation
  • States??
  • Initial state??
  • Actions??
  • Goal test??
  • Path cost??

22
Example 8-queens
  • Formulation 1
  • States any arrangement of
  • 0 to 8 queens on the board
  • Initial state 0 queens on the
  • board
  • Actions add a
  • queen in any square
  • Goal test 8 queens on the
  • board, none attacked
  • Path cost none

? 648 states with 8 queens
23
Example 8-queens
  • Formulation 2
  • States any arrangement of
  • k 0 to 8 queens in the k
  • leftmost columns with none
  • attacked
  • Initial state 0 queens on the
  • board
  • Successor function add a
  • queen to any square in the leftmost empty
    column such that it is not attacked
  • by any other queen
  • Goal test 8 queens on the
  • board

? 2,067 states
24
Real-world Problems
  • Route finding
  • Touring problems
  • VLSI layout
  • Robot Navigation
  • Automatic assembly sequencing
  • Drug design
  • Internet searching

25
Example robot assembly
  • States??
  • Initial state??
  • Actions??
  • Goal test??
  • Path cost??

26
Example robot assembly
  • States?? Real-valued coordinates of robot joint
    angles parts of the object to be assembled.
  • Initial state?? Any arm position and object
    configuration.
  • Actions?? Continuous motion of robot joints
  • Goal test?? Complete assembly (without robot)
  • Path cost?? Time to execute

27
Basic search algorithms
  • How do we find the solutions of previous
    problems?
  • Search the state space (remember complexity of
    space depends on state representation)
  • Here search through explicit tree generation
  • ROOT initial state.
  • Nodes and leafs generated through successor
    function.
  • In general search generates a graph (same state
    through multiple paths)

28
Simple Tree Search Algorithm
  • function TREE-SEARCH(problem, strategy) return
    solution
  • or failure
  • Initialize search tree to the initial state of
    the problem
  • do
  • if no candidates for expansion then return
    failure
  • choose leaf node for expansion according to
    strategy
  • if node contains goal state then return
    solution
  • else expand the node and add resulting nodes to
    the
  • search tree
  • enddo

29
Exercise 1 Getting an Intro
  • Aka the art of schmoozing

30
Take home points
  • Difference between State Space and Search Tree

31
Search of State Space
32
Search of State Space
33
Search State Space
34
Search of State Space
35
Search of State Space
36
Search of State Space
? search tree
37
Take home points
  • Difference between State Space and Search Tree
  • Blind Search
  • Learn names, ?

38
State space vs. search tree
  • A state is a (representation of) a physical
    configuration
  • A node is a data structure belong to a search
    tree
  • A node has a parent, children, and ncludes path
    cost, depth,
  • Here node ltstate, parent-node, action,
    path-cost, depthgt
  • FRINGE contains generated nodes which are not
    yet expanded.

39
Tree search algorithm
  • function TREE-SEARCH(problem,fringe) return a
    solution or failure
  • fringe ? INSERT(MAKE-NODE(INITIAL-STATEproblem)
    , fringe)
  • loop do
  • if EMPTY?(fringe) then return failure
  • node ? REMOVE-FIRST(fringe)
  • if GOAL-TESTproblem applied to STATEnode
    succeeds
  • then return SOLUTION(node)
  • fringe ? INSERT-ALL(EXPAND(node, problem),
    fringe)

40
Tree search algorithm (2)
  • function EXPAND(node,problem) return a set of
    nodes
  • successors ? the empty set
  • for each ltaction, resultgt in SUCCESSOR-FNproblem
    (STATEnode) do
  • s ? a new NODE
  • STATEs ? result
  • PARENT-NODEs ? node
  • ACTIONs ? action
  • PATH-COSTs ? PATH-COSTnode
    STEP-COST(node, action,s)
  • DEPTHs ? DEPTHnode1
  • add s to successors
  • return successors

41
Search Strategies
  • A strategy is defined by picking the order of
    node expansion
  • Performance Measures
  • 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 maximum branching factor of the search tree
  • d depth of the least-cost solution
  • m maximum depth of the state space (may be 8)

42
Uninformed search strategies
  • (a.k.a. blind search) use only information
    available in problem definition.
  • When strategies can determine whether one
    non-goal state is better than another ? informed
    search.
  • Categories defined by expansion algorithm
  • Breadth-first search
  • Uniform-cost search
  • Depth-first search
  • Depth-limited search
  • Iterative deepening search.
  • Bidirectional search

43
Breadth-First Strategy
  • Expand shallowest unexpanded node
  • Implementation fringe is a FIFO queue
  • New nodes are inserted at the end of the queue

FRINGE (1)
9
8
44
Breadth-First Strategy
  • Expand shallowest unexpanded node
  • Implementation fringe is a FIFO queue
  • New nodes are inserted at the end of the queue

FRINGE (2, 3)
9
8
45
Breadth-First Strategy
  • Expand shallowest unexpanded node
  • Implementation fringe is a FIFO queue
  • New nodes are inserted at the end of the queue

FRINGE (3, 4, 5)
9
8
46
Breadth-First Strategy
  • Expand shallowest unexpanded node
  • Implementation fringe is a FIFO queue
  • New nodes are inserted at the end of the queue

FRINGE (4, 5, 6, 7)
9
8
47
Breadth-First Strategy
  • Expand shallowest unexpanded node
  • Implementation fringe is a FIFO queue
  • New nodes are inserted at the end of the queue

1
FRINGE (5, 6, 7, 8)
2
3
4
5
6
7
9
8
48
Breadth-First Strategy
  • Expand shallowest unexpanded node
  • Implementation fringe is a FIFO queue
  • New nodes are inserted at the end of the queue

1
FRINGE (6, 7, 8)
2
3
4
5
6
7
9
8
49
Breadth-First Strategy
  • Expand shallowest unexpanded node
  • Implementation fringe is a FIFO queue
  • New nodes are inserted at the end of the queue

1
FRINGE (7, 8, 9)
2
3
4
5
6
7
9
8
50
Breadth-First Strategy
  • Expand shallowest unexpanded node
  • Implementation fringe is a FIFO queue
  • New nodes are inserted at the end of the queue

1
FRINGE (8, 9)
2
3
4
5
6
7
9
8
51
Breadth-first search evaluation
  • Completeness
  • Does it always find a solution if one exists?
  • YES
  • If shallowest goal node is at some finite depth d
  • Condition If b is finite
  • (maximum num. of succ. nodes is finite)

52
Breadth-first search evaluation
  • Completeness
  • YES (if b is finite)
  • Time complexity
  • Assume a state space where every state has b
    successors.
  • root has b successors, each node at the next
    level has again b successors (total b2),
  • Assume solution is at depth d
  • Worst case expand all but the last node at depth
    d
  • Total numb. of nodes generated
  • 1 b b2 bd b(bd-1) O(bd1)

53
Breadth-first search evaluation
  • Completeness
  • YES (if b is finite)
  • Time complexity
  • Total numb. of nodes generated
  • 1 b b2 bd b(bd-1) O(bd1)
  • Space complexityO(bd1)

54
Breadth-first search evaluation
  • Completeness
  • YES (if b is finite)
  • Time complexity
  • Total numb. of nodes generated
  • 1 b b2 bd b(bd-1) O(bd1)
  • Space complexityO(bd1)
  • Optimality
  • Does it always find the least-cost solution?
  • In general YES
  • unless actions have different cost.

55
Breadth-first search evaluation
  • lessons
  • Memory requirements are a bigger problem than
    execution time.
  • Exponential complexity search problems cannot be
    solved by uninformed search methods for any but
    the smallest instances.

DEPTH NODES TIME MEMORY
2 1100 0.11 seconds 1 megabyte
4 111100 11 seconds 106 megabytes
6 107 19 minutes 10 gigabytes
8 109 31 hours 1 terabyte
10 1011 129 days 101 terabytes
12 1013 35 years 10 petabytes
14 1015 3523 years 1 exabyte
Assumptions b 10 10,000 nodes/sec 1000
bytes/node
56
Uniform-cost search
  • Extension of BF-search
  • Expand node with lowest path cost
  • Implementation fringe queue ordered by path
    cost.
  • UC-search is the same as BF-search when all
    step-costs are equal.

57
Uniform-cost search
  • Completeness
  • YES, if step-cost gt ? (smal positive constant)
  • Time complexity
  • Assume C the cost of the optimal solution.
  • Assume that every action costs at least ?
  • Worst-case
  • Space complexity
  • Idem to time complexity
  • Optimality
  • nodes expanded in order of increasing path cost.
  • YES, if complete.

58
Depth-First Strategy
  • Expand deepest unexpanded node
  • Implementation fringe is a LIFO queue (stack)

1
59
Depth-First Strategy
  • Expand deepest unexpanded node
  • Implementation fringe is a LIFO queue (stack)

1
60
Depth-First Strategy
  • Expand deepest unexpanded node
  • Implementation fringe is a LIFO queue (stack)

1
61
Depth-First Strategy
  • Expand deepest unexpanded node
  • Implementation fringe is a LIFO queue (stack)

1
62
Depth-First Strategy
  • Expand deepest unexpanded node
  • Implementation fringe is a LIFO queue (stack)

1
63
Depth-First Strategy
  • Expand deepest unexpanded node
  • Implementation fringe is a LIFO queue (stack)

1
64
Depth-First Strategy
  • Expand deepest unexpanded node
  • Implementation fringe is a LIFO queue (stack)

1
65
Depth-First Strategy
  • Expand deepest unexpanded node
  • Implementation fringe is a LIFO queue (stack)

1
66
Depth-First Strategy
  • Expand deepest unexpanded node
  • Implementation fringe is a LIFO queue (stack)

1
67
Depth-First Strategy
  • Expand deepest unexpanded node
  • Implementation fringe is a LIFO queue (stack)

1
68
Depth-First Strategy
  • Expand deepest unexpanded node
  • Implementation fringe is a LIFO queue (stack)

1
69
Depth-First Strategy
  • Expand deepest unexpanded node
  • Implementation fringe is a LIFO queue (stack)

1
70
Depth-First Strategy
  • Expand deepest unexpanded node
  • Implementation fringe is a LIFO queue (stack)

1
71
Depth-first search evaluation
  • Completeness
  • Does it always find a solution if one exists?
  • NO
  • unless search space is finite and no loops are
    possible.

72
Depth-first search evaluation
  • Completeness
  • NO unless search space is finite.
  • Time complexity
  • Terrible if m is much larger than d (depth of
    optimal solution)
  • But if many solutions, then faster than BFS

73
Depth-first search evaluation
  • Completeness
  • NO unless search space is finite.
  • Time complexity
  • Space complexity
  • Backtracking search uses even less memory
  • One successor instead of all b.

74
Depth-first search evaluation
  • Completeness
  • NO unless search space is finite.
  • Time complexity
  • Space complexity
  • Optimality No

75
Depth-Limited Strategy
  • Depth-first with depth cutoff k (maximal depth
    below which nodes are not expanded)
  • Three possible outcomes
  • Solution
  • Failure (no solution)
  • Cutoff (no solution within cutoff)
  • Solves the infinite-path problem.
  • If klt d then incompleteness results.
  • If kgt d then not optimal.
  • Time complexity O(bk)
  • Space complexity O(bk)

76
Iterative Deepening Strategy
  • Repeat for k 0, 1, 2,
  • Perform depth-first with depth cutoff k
  • Complete
  • Optimal if step cost 1
  • Time complexity is (d1)(1) db (d-1)b2
    (1) bd O(bd)
  • Space complexity is O(bd)

77
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

78
Bidirectional Strategy
2 fringe queues FRINGE1 and FRINGE2
Time and space complexity O(bd/2) ltlt O(bd) The
predecessor of each node should be efficiently
computable.
79
Summary of algorithms
Criterion Breadth-First Uniform-cost Depth-First Depth-limited Iterative deepening Bidirectional search
Complete? YES YES NO YES, if l ? d YES YES
Time bd1 bC/e bm bl bd bd/2
Space bd1 bC/e bm bl bd bd/2
Optimal? YES YES NO NO YES YES
80
Repeated states
  • Failure to detect repeated states can turn a
    solvable problems into unsolvable ones.

81
Avoiding Repeated States
  • Requires comparing state descriptions
  • Breadth-first strategy
  • Keep track of all generated states
  • If the state of a new node already exists, then
    discard the node

82
Avoiding Repeated States
  • Depth-first strategy
  • Solution 1
  • Keep track of all states associated with nodes in
    current tree
  • If the state of a new node already exists, then
    discard the node
  • ? Avoids loops
  • Solution 2
  • Keep track of all states generated so far
  • If the state of a new node has already been
    generated, then discard the node
  • ? Space complexity of breadth-first

83
Graph search algorithm
  • Closed list stores all expanded nodes
  • function GRAPH-SEARCH(problem,fringe) return a
    solution or failure
  • closed ? an empty set
  • fringe ? INSERT(MAKE-NODE(INITIAL-STATEproblem)
    , fringe)
  • loop do
  • if EMPTY?(fringe) then return failure
  • node ? REMOVE-FIRST(fringe)
  • if GOAL-TESTproblem applied to STATEnode
    succeeds
  • then return SOLUTION(node)
  • if STATEnode is not in closed then
  • add STATEnode to closed
  • fringe ? INSERT-ALL(EXPAND(node, problem),
    fringe)

84
Graph search, evaluation
  • Optimality
  • GRAPH-SEARCH discard newly discovered paths.
  • This may result in a sub-optimal solution
  • YET when uniform-cost search or BF-search with
    constant step cost
  • Time and space complexity,
  • proportional to the size of the state space
  • (may be much smaller than O(bd)).
  • DF- and ID-search with closed list no longer has
    linear space requirements since all nodes are
    stored in closed list!!

85
Summary
  • Problem Formulation state space, initial state,
    successor function, goal test, path cost
  • Search tree ? state space
  • Evaluation of strategies completeness,
    optimality, time and space complexity
  • Uninformed search strategies breadth-first,
    depth-first, and variants
  • Avoiding repeated states
Write a Comment
User Comments (0)
About PowerShow.com