Constraint Satisfaction Problems - PowerPoint PPT Presentation

1 / 48
About This Presentation
Title:

Constraint Satisfaction Problems

Description:

Not just a successor function and goal test ... Set of variables {X1, X2, ..., Xn} Each variable Xi has a domain Di of possible values ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 49
Provided by: JeanClaud85
Category:

less

Transcript and Presenter's Notes

Title: Constraint Satisfaction Problems


1
Constraint Satisfaction Problems
  • Russell and Norvig Chapter 5.1-3

2
Intro Example 8-Queens
Generate-and-test, 88 combinations
3
Intro Example 8-Queens
4
What is Needed?
  • Not just a successor function and goal test
  • But also a means to propagate the constraints
    imposed by one queen on the others and an early
    failure test
  • ? Explicit representation of constraints and
    constraint manipulation algorithms

5
Constraint Satisfaction Problem
  • Set of variables X1, X2, , Xn
  • Each variable Xi has a domain Di of possible
    values
  • Usually Di is discrete and finite
  • Set of constraints C1, C2, , Cp
  • Each constraint Ck involves a subset of variables
    and specifies the allowable combinations of
    values of these variables
  • Assign a value to every variable such that all
    constraints are satisfied

6
Example 8-Queens Problem
  • 8 variables Xi, i 1 to 8
  • Domain for each variable 1,2,,8
  • Constraints are of the forms
  • Xi k ? Xj ? k for all j 1 to 8, j?i
  • Xi ki, Xj kj ?i-j ? ki - kj
  • for all j 1 to 8, j?i

7
Example Map Coloring
  • 7 variables WA,NT,SA,Q,NSW,V,T
  • Each variable has the same domain red, green,
    blue
  • No two adjacent variables have the same value
  • WA?NT, WA?SA, NT?SA, NT?Q, SA?Q, SA?NSW,
    SA?V,Q?NSW, NSW?V

8
Example Task Scheduling
T1 must be done during T3 T2 must be achieved
before T1 starts T2 must overlap with T3 T4 must
start after T1 is complete
9
Constraint Graph
  • Binary constraints

Two variables are adjacent or neighbors if
they are connected by an edge or an arc
10
CSP as a Search Problem
  • Initial state empty assignment
  • Successor function a value is assigned to any
    unassigned variable, which does not conflict with
    the currently assigned variables
  • Goal test the assignment is complete
  • Path cost irrelevant

11
Remark
  • Finite CSP include 3SAT as a special case
  • 3SAT is known to be NP-complete
  • So, in the worst-case, we cannot expect to solve
    a finite CSP in less than exponential time

12
Backtracking example
13
Backtracking example
14
Backtracking example
15
Backtracking example
16
Backtracking Algorithm
  • CSP-BACKTRACKING(PartialAssignment a)
  • If a is complete then return a
  • X ? select an unassigned variable
  • D ? select an ordering for the domain of X
  • For each value v in D do
  • If v is consistent with a then
  • Add (X v) to a
  • result ? CSP-BACKTRACKING(a)
  • If result ? failure then return result
  • Remove (X v) from a
  • Return failure
  • Start with CSP-BACKTRACKING()

17
Improving backtracking efficiency
  • Which variable should be assigned next?
  • In what order should its values be tried?
  • Can we detect inevitable failure early?

18
Most constrained variable
  • Most constrained variable
  • choose the variable with the fewest legal values
  • a.k.a. minimum remaining values (MRV) heuristic

19
Most constraining variable
  • Tie-breaker among most constrained variables
  • Most constraining variable
  • choose the variable involved in largest of
    constraints on remaining variables

20
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

21
Forward Checking
  • After a variable X is assigned a value v, look
    at each unassigned variable Y that is connected
    to X by a constraint and deletes from Ys domain
    any value that is inconsistent with v

22
Forward checking
23
Forward checking
24
Forward checking
25
Forward checking
26
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!

27
Definition (Arc consistency)
  • A constraint C_xy is said to be arc consistent
    w.r.t. x if for each value v of x
  • there is an allowed value of y.
  • Similarly, we define that C_xy is arc consistent
    w.r.t. y.
  • A binary CSP is arc consistent iff every
    constraint C_xy is arc consistent wrt x
  • as well as wrt y.

28
  • When a CSP is not arc consistent, we can make it
    arc consistent, e.g. by using AC3.
  • This is also called enforcing arc
    consistency.

29
Example
  • Let domains be
  • D_x 1,2,3, D_y 3,4,5,6
  • A constaint
  • C_xy (1,3),(1,5),(3,3),(3,6)
  • C_xy is not arc consistent w.r.t. x, neither
    w.r.t. y. By enforcing arc consistency, we get
    reduced domains
  • D_x 1,3, D_y3,5,6

30
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

31
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

32
Arc consistency
  • If X loses a value, neighbors of X need to be
    rechecked

33
Arc consistency
  • Arc consistency detects failure earlier than
    forward checking
  • Can be run as a preprocessor or after each
    assignment

34
Example domain reduction
  • Consider constraints
  • X gt Y, Y gt Z
  • Domains
  • Dx Dy Dz 1,2,3
  • - 1 in Dx is removed by maintaining arc
    consistency, w.r.t. the constraint X lt Y.
  • - You work out the rest. The resulting domains
    are
  • Dx 1, Dy 2, Dz 3
  • No search is needed

35
General CP for Binary Constraints
  • Algorithm AC3
  • contradiction ? false
  • Q ? stack of all variables
  • while Q is not empty and not contradiction do
  • X ? UNSTACK(Q)
  • For every variable Y adjacent to X do
  • If REMOVE-ARC-INCONSISTENCIES(X,Y) then
  • If Ys domain is non-empty then STACK(Y,Q)
  • Else return false

36
Complexity Analysis of AC3
  • e number of constraints (edges)
  • (or n2 where n is the of variables)
  • d number of values per variable
  • Each variable is inserted in Q up to d times
  • REMOVE-ARC-INCONSISTENCY takes O(d2) time
  • AC3 takes O(ed3) time to run

37
Solving a CSP
  • Search
  • can find solutions, but must examine
    non-solutions along the way
  • Constraint Propagation
  • can rule out non-solutions, but this is not the
    same as finding solutions
  • Interweave constraint propagation and search
  • Perform constraint propagation at each search
    step.

38
4-Queens Problem
39
4-Queens Problem
40
4-Queens Problem
41
4-Queens Problem
42
4-Queens Problem
43
4-Queens Problem
44
4-Queens Problem
45
4-Queens Problem
46
4-Queens Problem
47
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

48
Summary
  • Constraint Satisfaction Problems (CSP)
  • CSP as a search problem
  • Backtracking algorithm
  • General heuristics
  • Forward checking
  • Constraint propagation (Arc consistency)
  • Interweaving CP and backtracking
Write a Comment
User Comments (0)
About PowerShow.com