Constraint Satisfaction - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Constraint Satisfaction

Description:

... Sudoku. 3. 1. 1. 4. 3. 4. 1. 2. 4. 13. Running example: Sudoku ... Generate and test: Sudoku. Try each possible combination until you find one that works: ... – PowerPoint PPT presentation

Number of Views:98
Avg rating:3.0/5.0
Slides: 28
Provided by: marie262
Category:

less

Transcript and Presenter's Notes

Title: Constraint Satisfaction


1
Constraint Satisfaction
CMSC 471
  • Chapter 5

Adapted from slides by Tim Finin and Marie
desJardins.
Some material adopted from notes by Charles R.
Dyer, University of Wisconsin-Madison
2
Overview
  • Constraint satisfaction offers a powerful
    problem-solving paradigm
  • View a problem as a set of variables to which we
    have to assign values that satisfy a number of
    problem-specific constraints.

3
Informal example Map coloring
  • Color the following map using three colors (red,
    green, blue) such that no two adjacent regions
    have the same color.

4
Map coloring II
  • Variables A, B, C, D, E all of domain RGB
  • Domains RGB red, green, blue
  • Constraints A?B, A?C,A ? E, A ? D, B ? C, C ? D,
    D ? E
  • One solution Ared, Bgreen, Cblue, Dgreen,
    Eblue


5
Informal definition of CSP
  • CSP Constraint Satisfaction Problem
  • Given
  • (1) a finite set of variables
  • (2) each with a domain of possible values (often
    finite)
  • (3) a set of constraints that limit the values
    the variables can take on
  • A solution is an assignment of a value to each
    variable such that the constraints are all
    satisfied.
  • Tasks might be to decide if a solution exists, to
    find a solution, to find all solutions, or to
    find the best solution according to some metric
    (objective function).

6
Example SATisfiability
  • Given a set of propositions containing variables,
    find an assignment of the variables to
    false,true that satisfies them.
  • For example, the clauses
  • (A ? B ? C) ? ( A ? D)
  • (equivalent to (C ? A) ? (B ? D ? A)
  • are satisfied by
  • A false
  • B true
  • C false
  • D false

7
Real-world problems
  • Scheduling
  • Temporal reasoning
  • Building design
  • Planning
  • Optimization/satisfaction
  • Vision
  • Graph layout
  • Network management
  • Natural language processing
  • Molecular biology / genomics
  • VLSI design

8
Formal definition of a constraint network (CN)
  • A constraint network (CN) consists of
  • a set of variables X x1, x2, xn
  • each with an associated domain of values d1, d2,
    dn.
  • the domains are typically finite
  • a set of constraints c1, c2 cm where
  • each constraint defines a predicate which is a
    relation over a particular subset of X.
  • Unary constraint only involves one variable
  • Binary constraint only involves two variables

9
Formal definition of a CN (cont.)
  • Instantiations
  • An instantiation of a subset of variables S is an
    assignment of a value in its domain to each
    variable in S
  • An instantiation is legal if and only if it does
    not violate any constraints.
  • A solution is an instantiation of all of the
    variables in the network.

10
Typical tasks for CSP
  • Solutions
  • Does a solution exist?
  • Find one solution
  • Find all solutions
  • Given a partial instantiation, do any of the
    above
  • Transform the CN into an equivalent CN that is
    easier to solve.

11
Binary CSP
  • A binary CSP is a CSP in which all of the
    constraints are binary or unary.
  • Any non-binary CSP can be converted into a binary
    CSP by introducing additional variables.
  • A binary CSP can be represented as a constraint
    graph, which has a node for each variable and an
    arc between two nodes if and only there is a
    constraint involving the two variables.
  • Unary constraint appears as a self-referential arc

12
Example Sudoku
13
Running example Sudoku
  • Variables and their domains
  • vij is the value in the jth cell of the ith row
  • Dij D 1, 2, 3, 4
  • Blocks
  • B1 11, 12, 21, 22
  • ...
  • B4 33, 34, 43, 44
  • Constraints (implicit/intensional)
  • CR ?i, ?j vij D (every value appears in
    every row)
  • CC ?j, ?j vij D (every value appears in
    every column)
  • CB ?k, ? (vij ij ?Bk) D (every value
    appears in every block)
  • Alternative representation pairwise inequality
    constraints
  • IR ?i, j?j vij ? vij (no value appears
    twice in any row)
  • IC ?j, i?i vij ? vij (no value appears
    twice in any column)
  • IB ?k, ij ? Bk, ij ? Bk, ij ? ij vij ?
    vij (no value appears twice in any block)
  • Advantage of the second representation all
    binary constraints!

14
Sudoku constraint network
15
Generate and test Sudoku
  • Try each possible combination until you find one
    that works
  • 1, 1, 1, 1, 1, 1, 1
  • 1, 1, 1, 1, 1, 1, 2
  • 4, 4, 4, 4, 4, 4, 4
  • Doesnt check constraints until all variables
    have been instantiated
  • Very inefficient way to explore the space of
    possibilities
  • 47 16,384 for this trivial problem, most are
    illegal
  • 412 17M for a typical starting board (with four
    cells filled in)
  • 416 4.3B for an empty board
  • But... if we apply the constraints first, we only
    have 8 choices to try
  • ? When should we apply constraints?

16
Systematic search Backtracking(a.k.a.
depth-first search!)
  • Consider the variables in some order
  • Pick an unassigned variable and give it a
    provisional value such that it is consistent with
    all of the constraints
  • If no such assignment can be made, weve reached
    a dead end and need to backtrack to the previous
    variable
  • Continue this process until a solution is found
    or we backtrack to the initial variable and have
    exhausted all possible values

17
Backtracking Sudoku
18
Problems with backtracking
  • Thrashing keep repeating the same failed
    variable assignments
  • Consistency checking can help
  • Intelligent backtracking schemes can also help
  • Inefficiency can explore areas of the search
    space that arent likely to succeed
  • Variable ordering can help

19
MRV Heuristic
  • Minimum Remaining Values - variable with fewest
    remaining legal values.most likely to cause a
    failure

19
20
Degree Heuristic
  • Degree Heuristic - Pick variables involved in the
    largest number of constraints
  • Reduce branching factor of future choices
  • MRV usually better, but good for tie-breaking

20
21
LCV Heuristic
  • Least-constraining value heuristic - pick the
    value that rules out the fewest choices for
    neighbors
  • Leave maximum flexibility
  • Note if trying to find all solutions, it doesnt
    matter what order we find them in

21
22
Forward Checking
  • When assigning a value to a variable X, remove
    neighbors inconsistencies.
  • Detects inconsistencies earlier.
  • When neighbor variables are reduced to a single
    value, no need to branch on these variables.
  • Works well with minimum-remaining-values (MRV)
    heuristic

22
23
Constraint Propagation
  • View constraint problem as a graph (constraints
    are edges)
  • Systematically removes non-arc-consistent
    assignments
  • ExampleX,Y 0, 1, 2, 3, 4, 5, C X20,
    XY4X 0, 2, 4 because of X2
    0Then,Y 0, 2, 4 because 04, 22, 40 4

24
Consistency
  • Node consistency
  • A node X is node-consistent if every value in the
    domain of X is consistent with Xs unary
    constraints
  • A graph is node-consistent if all nodes are
    node-consistent
  • Arc consistency
  • An arc (X, Y) is arc-consistent if, for every
    value x of X, there is a value y for Y that
    satisfies the constraint represented by the arc.
  • A graph is arc-consistent if all arcs are
    arc-consistent.
  • To create arc consistency, we perform constraint
    propagation that is, we repeatedly reduce the
    domain of each variable to be consistent with its
    arcs

25
Constraint propagation Sudoku
Exercise Use elimination to solve the puzzle.
26
Min-conflicts heuristic
  • Iterative repair method
  • Find some reasonably good initial solution
  • Find a variable in conflict (randomly)
  • Select a new value that minimizes the number of
    constraint violations
  • Repeat steps 2 and 3 until done

27
Min-conflicts
  • Sosic and Gu showed min-conflicts could solve
    3million queens in less than a minute (in 1994)
  • Almost all CSP are trivial
  • If roughly half of the problems are solvable, the
    problem becomes hard (Cheeseman 1991)

27
Write a Comment
User Comments (0)
About PowerShow.com