COMP3170 Search 2 - PowerPoint PPT Presentation

1 / 59
About This Presentation
Title:

COMP3170 Search 2

Description:

Arc consistency detects failure earlier than forward checking ... Constraint propagation (e.g., arc consistency) does additional work to constrain ... – PowerPoint PPT presentation

Number of Views:56
Avg rating:3.0/5.0
Slides: 60
Provided by: pin8
Category:

less

Transcript and Presenter's Notes

Title: COMP3170 Search 2


1
COMP3170 Search (2)
  • Lecture 3
  • Hong Kong Baptist University

2
Last week
  • Problem formulation
  • Uninformed search
  • BFS
  • uniform cost search
  • DFS
  • depth-limited search
  • Iterative deepening search
  • Informed search Best first search
  • TODAY more on informed search (A, local search)
    and Constraint satisfaction problems (CSP)

3
A search (4.1)
  • Idea avoid expanding paths that are already
    expensive
  • Evaluation function f(n) g(n) h(n)
  • g(n) cost so far to reach n
  • h(n) estimated cost from n to goal
  • f(n) estimated total cost of path through n to
    goal

4
A search example
5
A search example
6
A search example
7
A search example
8
A search example
9
A search example
10
Admissible heuristics
  • A heuristic h(n) is admissible if for every node
    n,
  • h(n) h(n), where h(n) is the true cost to
    reach the goal state from n.
  • An admissible heuristic never overestimates the
    cost to reach the goal, i.e., it is optimistic
  • Example hSLD(n) (never overestimates the actual
    road distance)
  • Theorem If h(n) is admissible, A using
    TREE-SEARCH is optimal

11
Consistent heuristics
  • A heuristic is consistent if for every node n,
    every successor n' of n generated by any action
    a,
  • 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 non-decreasing along any path.
  • Theorem If h(n) is consistent, A using
    GRAPH-SEARCH is optimal

12
Properties of A
  • Complete? Yes (unless there are infinitely many
    nodes with f f(G) )
  • Time? Exponential
  • Space? Keeps all nodes in memory
  • Optimal? Yes

13
Admissible heuristics (4.2)
  • E.g., for the 8-puzzle
  • h1(n) number of misplaced tiles
  • h2(n) total Manhattan distance
  • (i.e., no. of squares from desired location of
    each tile)
  • h1(S) ?
  • h2(S) ?

14
Admissible heuristics
  • E.g., for the 8-puzzle
  • h1(n) number of misplaced tiles
  • h2(n) total Manhattan distance
  • (i.e., no. of squares from desired location of
    each tile)
  • h1(S) ? 8
  • h2(S) ? 31222332 18

15
Dominance
  • If h2(n) h1(n) for all n (both admissible)
  • then h2 dominates h1
  • h2 is better for search
  • Typical search costs (average number of nodes
    expanded)
  • d12 IDS 3,644,035 nodes A(h1) 227 nodes
    A(h2) 73 nodes
  • d24 IDS too many nodes A(h1) 39,135 nodes
    A(h2) 1,641 nodes

16
Relaxed problems
  • A problem with fewer restrictions on the actions
    is called a relaxed problem
  • The cost of an optimal solution to a relaxed
    problem is an admissible heuristic for the
    original 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

17
Local search algorithms (4.3)
  • In many optimization problems, the path to the
    goal is irrelevant the goal state itself is the
    solution
  • State space set of "complete" configurations
  • Find configuration satisfying constraints, e.g.,
    n-queens
  • In such cases, we can use local search algorithms
  • keep a single "current" state, try to improve it

18
Example n-queens
  • Put n queens on an n n board with no two queens
    on the same row, column, or diagonal

19
Hill-climbing search
  • "Like climbing Everest in thick fog with amnesia"

20
Hill-climbing search
  • Problem depending on initial state, can get
    stuck in local maxima

21
Hill-climbing search 8-queens problem
  • h number of pairs of queens that are attacking
    each other, either directly or indirectly
  • h 17 for the above state

22
Hill-climbing search 8-queens problem
  • A local minimum with h 1

23
Local beam search
  • Keep track of k states rather than just one
  • Start with k randomly generated states
  • At each iteration, all the successors of all k
    states are generated
  • If any one is a goal state, stop else select the
    k best successors from the complete list and
    repeat.

24
Constraint Satisfaction Problems
  • Chapter 5
  • Section 1 3

25
Outline
  • Constraint Satisfaction Problems (CSP)
  • Backtracking search for CSPs
  • Local search for CSPs

26
Constraint satisfaction problems (CSPs)
  • Standard search problem
  • state is a black box any data structure that
    supports successor function, heuristic function,
    and goal test
  • CSP
  • state is defined by variables Xi with values from
    domain Di
  • goal test is a set of constraints specifying
    allowable combinations of values for subsets of
    variables
  • Allows useful general-purpose algorithms with
    more power than standard search algorithms

27
Example Map-Coloring
  • Variables WA, NT, Q, NSW, V, SA, T
  • Domains Di red,green,blue
  • Constraints adjacent regions must have different
    colors
  • e.g., WA ? NT, or (WA,NT) in (red,green),(red,blu
    e),(green,red), (green,blue),(blue,red),(blue,gree
    n)

28
Example Map-Coloring
Does not violate constraint
All variables are used
  • Solutions are complete and consistent
    assignments, e.g., WA red, NT green,Q
    red,NSW green,V red,SA blue,T green

29
Constraint graph
  • Binary CSP each constraint relates two variables
  • Constraint graph nodes are variables, arcs are
    constraints

30
Varieties of CSPs
  • Discrete variables
  • finite domains
  • n variables, domain size d ? O(dn) complete
    assignments
  • e.g., map coloring, Boolean CSPs (NP-complete)
  • infinite domains
  • integers, strings, etc.
  • e.g., job scheduling, variables are start/end
    days for each job
  • need a constraint language, e.g., StartJob1 5
    StartJob3
  • Continuous variables
  • e.g., start/end times for Hubble Space Telescope
    observations
  • linear constraints solvable in polynomial time
    (w.r.t. the number of variables) by linear
    programming

Linear constraint
31
Varieties of constraints
  • Unary constraints involve a single variable,
  • e.g., SA ? green
  • Binary constraints involve pairs of variables,
  • e.g., SA ? WA
  • Higher-order constraints involve 3 or more
    variables,
  • e.g., cryptarithmetic column constraints

32
Example of Higher-Order Constraints
Cryptarithmetic
  • Variables F T U W R O X1 X2 X3
  • Domains 0,1,2,3,4,5,6,7,8,9
  • Constraints Alldiff (F,T,U,W,R,O)
  • O O R 10 X1
  • X1 W W U 10 X2
  • X2 T T O 10 X3
  • X3 F, T ? 0, F ? 0

X1 X2 X3 are auxiliary variables 0, 1
Every higher-order, finite domain constraint can
be reduced to a set of binary constraints if
enough aux. variables are introduced
33
Real-world CSPs
  • Assignment problems
  • e.g., who teaches what class
  • Timetabling problems
  • e.g., which class is offered when and where?
  • Transportation scheduling
  • Factory scheduling
  • Notice that many real-world problems involve
    real-valued variables

34
Standard search formulation (incremental)
  • Let's start with the straightforward approach,
    then fix it
  • States are defined by the values assigned so far
  • Initial state the empty assignment
  • Successor function assign a value to an
    unassigned variable that does not conflict with
    current assignment
  • ? fail if no legal assignments
  • Goal test the current assignment is complete
  • This is the same for all CSPs
  • Every solution appears at depth n with n
    variables? use depth-first search
  • Path is irrelevant
  • b (n - l )d at depth l, hence n! dn leaves

35
Outline
  • Constraint Satisfaction Problems (CSP)
  • Backtracking search for CSPs
  • Local search for CSPs

36
Backtracking search
  • Variable assignments are commutative, i.e.,
  • WA red then NT green same as
  • NT green then WA 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
    assignments is called backtracking search
  • Backtracking search is the basic uninformed
    algorithm for CSPs

37
Backtracking search
38
Backtracking example
39
Backtracking example
40
Backtracking example
41
Backtracking example
42
Improving backtracking efficiency
  • Plain backtracking is not effective for large
    problems!
  • Can we improve it without any domain-specific
    information?
  • General-purpose methods can give huge gains in
    speed
  • Which variable should be assigned next?
  • In what order should its values be tried?
  • Can we detect inevitable failure early?

Variable and value ordering Propagation
information
43
Minimum Remaining Values (MRV)
  • choose the variable with the fewest legal values,
    e.g. red, green, blue
  • a.k.a. most constrained variable heuristic

44
Minimum Remaining Values (MRV)Degree Heuristic
  • Tie-breaker among most constrained variables
  • Most constraining variable
  • choose the variable with the most constraints on
    remaining variables

45
Least constraining value
  • Given a variable, choose the least constraining
    value
  • the one that rules out the fewest values in the
    remaining variables
  • Combining these heuristics makes 1000 queens
    feasible

46
Propagation Information Forward checking
  • Idea
  • Keep track of remaining legal values for
    unassigned variables
  • Terminate search when any variable has no legal
    values

47
Forward checking
  • Idea
  • Keep track of remaining legal values for
    unassigned variables
  • Terminate search when any variable has no legal
    values

48
Forward checking
  • Idea
  • Keep track of remaining legal values for
    unassigned variables
  • Terminate search when any variable has no legal
    values

49
Forward checking
  • Idea
  • Keep track of remaining legal values for
    unassigned variables
  • Terminate search when any variable has no legal
    values

50
Another Propagation Information Constraint
propagation
  • Forward checking propagates information from
    assigned to unassigned variables, but doesn't
    provide early detection for all failures
  • NT and SA cannot both be blue!
  • Constraint propagation repeatedly enforces
    constraints locally

51
Constraint PropagationArc consistency
  • Simplest form of propagation makes each arc
    consistent
  • X ?Y is consistent iff
  • for every value x of X there is some allowed y

52
Arc consistency
  • Simplest form of propagation makes each arc
    consistent
  • X ?Y is consistent iff
  • for every value x of X there is some allowed y

53
Arc consistency
  • Simplest form of propagation makes each arc
    consistent
  • X ?Y is consistent iff
  • for every value x of X there is some allowed y
  • If X loses a value, neighbors of X need to be
    rechecked

54
Arc consistency
  • Simplest form of propagation makes each arc
    consistent
  • X ?Y is consistent iff
  • for every value x of X there is some allowed y
  • If X loses a value, neighbors of X need to be
    rechecked
  • Arc consistency detects failure earlier than
    forward checking
  • Can be run as a preprocessor or after each
    assignment

55
Arc consistency algorithm AC-3
  • Time complexity O(n2d3)

56
Outline
  • Constraint Satisfaction Problems (CSP)
  • Backtracking search for CSPs
  • Local search for CSPs

57
Local search for CSPs
  • Hill-climbing, simulated annealing typically work
    with "complete" states, i.e., all variables
    assigned
  • To apply to CSPs
  • allow states with unsatisfied constraints
  • operators reassign variable values
  • Variable selection randomly select any
    conflicted variable
  • Value selection by min-conflicts heuristic
  • choose value that violates the fewest constraints
  • i.e., hill-climb with h(n) total number of
    violated constraints

58
Example 4-Queens
  • States 4 queens in 4 columns (44 256 states)
  • Actions move queen in column
  • Goal test no attacks
  • Evaluation h(n) number of attacks
  • Given random initial state, can solve n-queens in
    almost constant time for arbitrary n with high
    probability (e.g., n 10,000,000)

59
Summary
  • CSPs are a special kind of problem
  • states defined by values of a fixed set of
    variables
  • goal test defined by constraints on variable
    values
  • Backtracking depth-first search with one
    variable assigned per node
  • Variable ordering and value selection heuristics
    help significantly
  • Forward checking prevents assignments that
    guarantee later failure
  • Constraint propagation (e.g., arc consistency)
    does additional work to constrain values and
    detect inconsistencies
  • Iterative min-conflicts is usually effective in
    practice
Write a Comment
User Comments (0)
About PowerShow.com