+ All Categories
Home > Documents > Csp Module

Csp Module

Date post: 02-Apr-2018
Category:
Upload: mihai-ilie
View: 229 times
Download: 0 times
Share this document with a friend

of 70

Transcript
  • 7/27/2019 Csp Module

    1/70

    Constraint Satisfaction Problems

    [Read chapter 5 of Russell & Norvig]

  • 7/27/2019 Csp Module

    2/70

    Homework #2: Formulate the

    Following Problem as a CSPGiven a set of n data points and a distance

    function d(xi, xj) between all pairs ofpoints. Partition the data set into a twosubsets so that the maximum diameter ofthe two subsets is minimized.

  • 7/27/2019 Csp Module

    3/70

    Constraint satisfaction problems

    (CSPs) Simple example of a formal representation language

    Later we'll define much more complex languages in PLand FOL. Trade-off b/w complexity and solvability

    Standard search problem: state is a "black box any datastructure that supports successor function and goal test

    state is defined by variablesXi with values from domainDi

    goal test is a set of constraints specifying allowable combinationsof values for subsets of variables

    Focus on useful general-purpose algorithms with morepower than standard search algorithms (BFS, DFS) anddon't require user generated heuristics like A*.

  • 7/27/2019 Csp Module

    4/70

    Example: Map-Coloring

    VariablesWA, NT, Q, NSW, V, SA, T

    DomainsDi = {red,green,blue} Constraints: adjacent regions must have different colors e.g., WA NT

  • 7/27/2019 Csp Module

    5/70

    Example: Map-Coloring

    Solutions are complete and consistent assignments

    e.g., WA = red, NT = green, Q = red, NSW =green,V = red,SA = blue,T = green

  • 7/27/2019 Csp Module

    6/70

    Constraint graph

    Binary CSP: each constraint relates two variables

    Constraint graph: nodes are variables, arcs are constraints

  • 7/27/2019 Csp Module

    7/70

    Varieties of CSPs

    Discrete variables finite domains:

    n variables, domain size d O(dn) complete assignments e.g., Boolean CSPs, incl. Boolean satisfiability (NP-complete)e

    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 by LP

  • 7/27/2019 Csp Module

    8/70

    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,

    Eventually we'll be able to specify constraints as a

    sentence in a logic.

  • 7/27/2019 Csp Module

    9/70

    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 involvereal-valued variables

    Related techniques involving constraints?

    Why can't we use it for our homeworkproblem?

  • 7/27/2019 Csp Module

    10/70

    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, so can also use complete-state formulation b = (n - l )d at depth l, hence n! dn leaves

  • 7/27/2019 Csp Module

    11/70

    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 ateach node

    Depth-first search for CSPs with single-variable assignments iscalled backtracking search

    Can solve n-queens for n 25

  • 7/27/2019 Csp Module

    12/70

  • 7/27/2019 Csp Module

    13/70

    Behavior of this algorithm for n=4n-queens problem

  • 7/27/2019 Csp Module

    14/70

    14

  • 7/27/2019 Csp Module

    15/70

    Backtracking example

  • 7/27/2019 Csp Module

    16/70

    Backtracking example

  • 7/27/2019 Csp Module

    17/70

    Backtracking example

  • 7/27/2019 Csp Module

    18/70

    Backtracking example

    What are the possible improvements to basic BT search?

    What guiding principles/aims can we use to help answer this question?

  • 7/27/2019 Csp Module

    19/70

    Improving backtracking efficiency

    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?

  • 7/27/2019 Csp Module

    20/70

    When Building The Tree How

    Should We Order Variables?

    What should we assign next, SA, QLD,

    NSW, VIC, TAS? Why?

  • 7/27/2019 Csp Module

    21/70

    Most constrained variable

    Most constrained variable:

    choose the variable with the fewest legal values

    a.k.a. minimum remaining values (MRV)

    heuristic

  • 7/27/2019 Csp Module

    22/70

    Will the MRV Heuristic Help Us

    Choose the Root of the Tree? If not, whats a reasonable method to choose

    and why?

  • 7/27/2019 Csp Module

    23/70

    Most constraining variable

    Tie-breaker among most constrained

    variables

    Most constraining variable:

    choose the variable with the most constraints on

    remaining variables

  • 7/27/2019 Csp Module

    24/70

    Okay. We How About Choosing

    What Values to Explore First? If we are expanding QLD which value should we

    instantiate first?

  • 7/27/2019 Csp Module

    25/70

    Least constraining value

    Given a variable, choose the leastconstraining value:

    the one that rules out the fewest values in the

    remaining variables

    Combining these heuristics makes 1000

    queens feasible.

    How is this philosophically different to our

    heuristic search with A*

  • 7/27/2019 Csp Module

    26/70

    What was nice about A*'s behavior?

  • 7/27/2019 Csp Module

    27/70

    So how can we do pruning in this context?

  • 7/27/2019 Csp Module

    28/70

    Forward checking

    Idea:

    Keep track of remaining legal values for unassigned variables

    Terminate search when any variable has no legal values

  • 7/27/2019 Csp Module

    29/70

    Forward checking

    Idea:

    Keep track of remaining legal values for unassigned variables

    Terminate search when any variable has no legal values

  • 7/27/2019 Csp Module

    30/70

    Forward checking

    Idea:

    Keep track of remaining legal values for unassigned variables

    Terminate search when any variable has no legal values

  • 7/27/2019 Csp Module

    31/70

    Forward checking

    Idea:

    Keep track of remaining legal values for unassigned variables

    Terminate search when any variable has no legal values

    Using these heuristics in combination. What node ordering

    heuristic is a natural partner to forward checking?

  • 7/27/2019 Csp Module

    32/70

    Forward Checking is an Example ofConstraint Propagation.

  • 7/27/2019 Csp Module

    33/70

  • 7/27/2019 Csp Module

    34/70

    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

  • 7/27/2019 Csp Module

    35/70

    In your Class Groups of Three

    Use the allocated technique: minimum remaining values, most constrainedvariable, least constraining value or forward checking.

    Which is the odd one out and why?

    Show the generated search tree.

  • 7/27/2019 Csp Module

    36/70

    Arc consistency

    Simplest form of propagation makes each arc consistent

    XYis consistent iff

    for every valuex ofXthere is some allowedy

  • 7/27/2019 Csp Module

    37/70

    Arc consistency Simplest form of propagation makes each arc consistent

    XYis consistent iff

    for every valuex ofXthere is some allowedy

  • 7/27/2019 Csp Module

    38/70

    Arc consistency Simplest form of propagation makes each arc consistent

    XYis consistent iff

    for every valuex ofXthere is some allowedy

    IfXloses a value, neighbors ofXneed to be rechecked

  • 7/27/2019 Csp Module

    39/70

    Arc consistency Simplest form of propagation makes each arc consistent

    XYis consistent iff

    for every valuex ofXthere is some allowedy

    IfXloses a value, neighbors ofXneed to be rechecked

    Arc consistency detects failure earlier than forward checking

    Can be run as a preprocessor or after each assignment

  • 7/27/2019 Csp Module

    40/70

    So what if we find a nodes xi and xj are not arcconsistent what should we do?

  • 7/27/2019 Csp Module

    41/70

    Arc consistency algorithm AC-3

    Time complexity: O(n2d3)

    Checking consistency of an arc is O(d2)

  • 7/27/2019 Csp Module

    42/70

  • 7/27/2019 Csp Module

    43/70

  • 7/27/2019 Csp Module

    44/70

  • 7/27/2019 Csp Module

    45/70

  • 7/27/2019 Csp Module

    46/70

  • 7/27/2019 Csp Module

    47/70

  • 7/27/2019 Csp Module

    48/70

  • 7/27/2019 Csp Module

    49/70

  • 7/27/2019 Csp Module

    50/70

  • 7/27/2019 Csp Module

    51/70

    I l CSP f l i

  • 7/27/2019 Csp Module

    52/70

    In your class groups use a CSP formulation tosolve this problem.

    Given a set of n data points and a distancefunction d(xi, xj) between all pairs ofpoints. Partition the data set into a twosubsets so that the maximum diameter ofthe two subsets is minimized.

    Hint: Construct a simple example to verifyyour algorithm.

    Is the problem solvable in polynomial timewith respect to the number of instances?

    Core Decision Problem: Boottleneck Diameter Problem (BDP):

  • 7/27/2019 Csp Module

    53/70

    Core Decision Problem: Boottleneck Diameter Problem (BDP):

    Given: Point set P = \{p_1, p_2, ..., p_n\}, the distance d(p_i,p_j) for each pair of points, a distance \alpha.

    Question: Is it possible to partition P into two sets P_1 andP_2 such that dia(P_1)

  • 7/27/2019 Csp Module

    54/70

    Putting It All Together: Sudoku

    85

    14783

    35179

    325

    1926

    849

    42853

    95162

    39

  • 7/27/2019 Csp Module

    55/70

    Sudoku

    http://www.websudoku.com/

    Each Sudoku has a unique solution that can bereached logically without guessing. Enter digitsfrom 1 to 9 into the blank spaces. Every row must

    contain one of each digit. So must every column,as must every 3x3 square.

    http://www.websudoku.com/http://en.wikipedia.org/wiki/Sudokuhttp://en.wikipedia.org/wiki/Sudokuhttp://www.websudoku.com/
  • 7/27/2019 Csp Module

    56/70

    Problem Formulation As Search

    What is the state space? What is the initial state? What is the successor function?

    What is the goal test? What is the path cost? Admissible heuristic?

    Why does using these search techniques notmake sense for this problem?

  • 7/27/2019 Csp Module

    57/70

  • 7/27/2019 Csp Module

    58/70

    Points

    Large search space

    commutativity

    what about using bfs or dfs?fixed depth

  • 7/27/2019 Csp Module

    59/70

    CSP as a Search ProblemCSP as a Search Problem

    Initial state: empty assignment

    Successor function: a value is assigned to any unassignedvariable, which does not conflict with the currently assigned

    variables Goal test: the assignment is complete

    Path cost: irrelevant

    Branching factor b at the top level is nd. b=(n-l)d at depth l, hence n!dn leaves (only dn complete

    assignments).

    We can do better.

  • 7/27/2019 Csp Module

    60/70

    What else is needed?What else is needed?

    Not just a successor function and goal test But also a means to propagate the

    constraints imposed by one move on theothers and an early failure test

    Explicit representation of constraints and

    constraint manipulation algorithms

  • 7/27/2019 Csp Module

    61/70

    Example: Sudoku CSPExample: Sudoku CSP

    variables:

    domains:

    constraints:

    Goal: Assign a value to every variable such that allconstraints are satisfied

  • 7/27/2019 Csp Module

    62/70

    Example: Sudoku CSPExample: Sudoku CSP

    variables: X11, , X99

    domains: {1,,9}

    constraints: row constraint: X11 X12, , X11 X19

    col constraint: X11 X12, , X11 X19

    block constraint: X11 X12, , X11 X33

    How do we encode existing board values as constraints?

    Goal: Assign a value to every variable such that allconstraints are satisfied

    G N D A h

  • 7/27/2019 Csp Module

    63/70

    Great. Now Do AnotherFormulation using Propositional

    Logic s_{xyz} is the proposition that tile locationx,y value is z

    Why is it so important to state our problem inpropositional or first order calculus?

    G N D A h

  • 7/27/2019 Csp Module

    64/70

    Great. Now Do AnotherFormulation using Propositional

    Logic

  • 7/27/2019 Csp Module

    65/70

  • 7/27/2019 Csp Module

    66/70

    Other techniques for CSPs

    k-consistency

    Tradeoff between propagation and branching

    Symmetry breaking

  • 7/27/2019 Csp Module

    67/70

    Structured CSPs

    Tree-structured CSPs Removes

  • 7/27/2019 Csp Module

    68/70

    Tree structured CSPs Removes

    The Need For Back-tracking

  • 7/27/2019 Csp Module

    69/70

    Algorithm for tree-structured CSPs

    Ne rl tree str ct red CSPs

  • 7/27/2019 Csp Module

    70/70

    Nearly tree-structured CSPs

    (Finding the minimum cutset is NP-complete.)


Recommended