Global Constraints - PowerPoint PPT Presentation

About This Presentation
Title:

Global Constraints

Description:

Berge acyclicity. Graph does not contain any cycles (tree) ... Berge acyclic constraint graph. Can be generalized in many directions. Partial interchangeability, ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 94
Provided by: cseUn
Category:

less

Transcript and Presenter's Notes

Title: Global Constraints


1
Global Constraints
  • Toby Walsh
  • NICTA and University of New South Wales
  • www.cse.unsw.edu.au/tw

2
Overview a tale of 3 global constraints
  • Value PRECEDENCE
  • Symmetry breaking
  • Decomposition does not hinder propagation
  • NVALUES
  • Computational complexity to the rescue
  • REGULAR
  • Formal languages to the rescue

3
Why GLOBAL constraints?
  • The one thing that people in LP most envy about
    CP!
  • Capture common patterns
  • E.g. AllDifferent variables take all different
    values
  • Each queen must be on a different column

4
Why GLOBAL constraints?
  • The one thing that people in LP most envy about
    CP!
  • Capture common patterns
  • Provide effective pruning
  • E.g. complex pigeonhole arguments (these 4
    variables have just 4 values between them so
    other variables must take values outside)

5
Why GLOBAL constraints?
  • The one thing that people in LP most envy about
    CP!
  • Capture common patterns
  • Provide effective pruning
  • E.g. complex pigeonhole arguments (these 4
    variables have just 4 values between them so
    other variables must take values outside)
  • Do so efficiently
  • E.g. O(n log n) time to enforce BC on AllDifferent

6
Typical CP solver
  • Backtracking search
  • Try Queen1col1
  • Try Queen2col3
  • Else Queen2col4
  • Else
  • Else Queen1col2
  • Try Queen2col4
  • Else Queen2col5
  • Else Queen1col3

7
Typical CP solver
  • Backtracking search
  • Try Queen1col1
  • Constraint pruning removes
  • Queen2col1
  • Queen2col2
  • Queen3col1
  • Queen3col3

8
Search tree
  • Branching
  • Queen1col1
  • Queen2col3
  • ..
  • Propagation
  • AllDifferent(Queen1,..,Queen8)

9
Propagators
  • Effective pruning
  • Enforce GAC or BC
  • Complex pigeonhole arguments
  • X1, X3, X6 ? 1,2,3 then X2 ? 1,2,3
  • Efficiently
  • BC on AllDifferent in O(n log n) time
  • GAC on AllDifferent on O(n2.5) time
  • Called each node in a potentially exponential
    sized search tree!

10
Propagators
  • Incremental
  • Each time we call them only a little changes
    (i.e. one variable is instantiated)
  • On backtracking, need to restore their state
    quickly (efficient data structures to do so like
    watched literals)

11
Propagation
  • GAC
  • Each value for each variable can be extended to a
    satisfying assignment (aka support) of the global
    constraint
  • E.g. AllDifferent(1,2,1,2,1,2,3)

12
Propagation
  • GAC
  • Each value for each variable can be extended to a
    satisfying assignment (aka support) of the global
    constraint
  • AC
  • GAC on binary constraints

13
Propagation
  • GAC
  • Each value for each variable can be extended to a
    satisfying assignment (aka support) of the global
    constraint
  • BC
  • Max and min can be extended to a bound support
    (assignment between max and min)

14
Global constraint
  • Constraint over parameterized number of variables
  • E.g. AllDifferent(X1,..,Xn)
  • n is not fixed
  • Compare binary constraint
  • X lt Y
  • Fixed to 2 variables

15
Global constraint
  • Constraint over parameterized number of variables
  • E.g. AllDifferent(X1,..,Xn)
  • n is not fixed
  • Cannot use brute force to make GAC
  • dn possible supports to try out in general
  • Must use smart algorithms!

16
Value PRECEDENCE
  • Global constraint for dealing with symmetry in a
    problem

17
Value precedence
  • Used to deal with value symmetry
  • Prevent us finding symmetric (equivalent)
    solutions
  • Good example of global constraint where we can
    use an efficient encoding
  • Encoding gives us GAC
  • Asymptotically optimal, achieve GAC in O(nd) time
  • Good incremental complexity

18
Value symmetry
  • Decision variables
  • ColItaly, ColFrance, ColAustria ...
  • Domain of values
  • red, yellow, green, ...
  • Constraints
  • ColItaly/ColFrance
  • ColItaly/ColAustria

19
Value symmetry
  • Solution
  • ColItalygreen ColFrancered
  • ColSpaingreen
  • Values (colours) are interchangeable
  • Swap red with green everywhere will still give us
    a solution

20
Value symmetry
  • Solution
  • ColItalyred ColFrancegreen
  • ColSpainred
  • Values (colours) are interchangeable
  • Swap red with green everywhere will still give us
    a solution

21
Value precedence
  • Old idea
  • Used in bin-packing and graph colouring
    algorithms
  • Only open the next new bin
  • Only use one new colour
  • Applied now to constraint satisfaction

22
Value precedence
  • Suppose all values from 1 to m are
    interchangeable
  • Might as well let X11

23
Value precedence
  • Suppose all values from 1 to m are
    interchangeable
  • Might as well let X11
  • For X2, we need only consider two choices
  • X21 or X22

24
Value precedence
  • Suppose all values from 1 to m are
    interchangeable
  • Might as well let X11
  • For X2, we need only consider two choices
  • Suppose we try X22

25
Value precedence
  • Suppose all values from 1 to m are
    interchangeable
  • Might as well let X11
  • For X2, we need only consider two choices
  • Suppose we try X22
  • For X3, we need only consider three choices
  • X31, X32, X33

26
Value precedence
  • Suppose all values from 1 to m are
    interchangeable
  • Might as well let X11
  • For X2, we need only consider two choices
  • Suppose we try X22
  • For X3, we need only consider three choices
  • Suppose we try X32

27
Value precedence
  • Suppose all values from 1 to m are
    interchangeable
  • Might as well let X11
  • For X2, we need only consider two choices
  • Suppose we try X22
  • For X3, we need only consider three choices
  • Suppose we try X32
  • For X4, we need only consider three choices
  • X41, X42, X43

28
Value precedence
  • Global constraint
  • Precedence(X1,..Xn) iff
  • min(i Xij or in1) lt
  • min(i Xik or in2)
  • for
    all jltk
  • In other words
  • The first time we use j is before the first time
    we use k
  • Now cannot swap j with k so symmetry is broken

29
Value precedence
  • Global constraint
  • Precedence(X1,..Xn) iff
  • min(i Xij or in1) lt
  • min(i Xik or in2)
  • E.g
  • Precedence(1,1,2,1,3,2,4,2,3)
  • But not Precedence(1,1,2,1,4)

30
Value precedence
  • Global constraint
  • Precedence(X1,..Xn) iff
  • min(i Xij or in1) lt
  • min(i Xik or in2)
  • Propagator proposed by Law and Lee 2004
  • Pointer based propagator but only for two
    interchangeable values at a time

31
Value precedence
  • Precedence(j,k,X1,..Xn) iff
  • min(i Xij or
    in1) lt
  • min(i Xik or
    in2)
  • Of course
  • Precedence(X1,..Xn) iff Precedence(i,j,X1,..X
    n) for all iltj

32
Value precedence
  • Precedence(j,k,X1,..Xn) iff
  • min(i Xij or
    in1) lt
  • min(i Xik or
    in2)
  • Of course
  • Precedence(X1,..Xn) iff Precedence(i,i1,X1,
    ..Xn) for all i

33
Value precedence
  • Precedence(j,k,X1,..Xn) iff
  • min(i Xij or
    in1) lt
  • min(i Xik or
    in2)
  • But this hinders propagation
  • GAC(Precedence(X1,..Xn)) does strictly more
    pruning than GAC(Precedence(i,j,X1,..Xn)) for
    all iltj
  • Consider
  • X11, X2 in 1,2, X3 in 1,3 and X4 in 3,4

34
Pugets method
  • Introduce Zj to record first time we use j
  • Add constraints
  • Xij implies Zj lt i
  • Zji implies Xij
  • Zi lt Zi1

35
Pugets method
  • Introduce Zj to record first time we use j
  • Add constraints
  • Xij implies Zj lt i
  • Zji implies Xij
  • Zi lt Zi1
  • Binary constraints
  • easy to implement

36
Pugets method
  • Introduce Zj to record first time we use j
  • Add constraints
  • Xij implies Zj lt I
  • Zji implies Xij
  • Zi lt Zi1
  • Unfortunately hinders propagation
  • AC on encoding may not give GAC on
    Precedence(X1,..Xn)
  • Consider X11, X2 in 1,2, X3 in 1,3, X4 in
    3,4, X52, X63, X74

37
Propagating Precedence
  • Simple ternary encoding
  • Introduce Yi1 for largest value used up to Xi
  • Post sequence of constraints
  • C(Xi,Yi,Yi1) for each 1ltiltn
  • These hold iff
  • Xilt1Yi and Yi1max(Yi,Xi)

38
Propagating Precedence
  • Post sequence of constraints
  • C(Xi,Yi,Yi1) for each 1ltiltn
  • These hold iff Xilt1Yi and Yi1max(Yi,Xi)
  • Consider Y10, X1 in 1,2,3, X2 in 1,2,3 and
    X33

39
Propagating Precedence
  • Post sequence of constraints
  • C(Xi,Yi,Yi1) for each 1ltiltn
  • These hold iff Xilt1Yi and Yi1max(Yi,Xi)
  • Decomposition does not hinder propagation
  • Enforcing GAC on decomposition makes
    Precedence(X1,,Xn) GAC
  • Reason constraint graph is Berge-acyclic

40
Berge acyclicity
  • Constraint graph
  • Node for each variable
  • Edge between variables in the same constraint
  • Berge acyclicity
  • Graph does not contain any cycles (tree)
  • Local consistency global consistency
  • Trees are our friends

41
Partial value precedence
  • Values may partition into equivalence classes
  • Values within each equivalence class are
    interchangeable
  • E.g.
  • Shift1nursePaul, Shift2nursePeter,
    Shift3nurseJane, Shift4nursePaul ..

42
Partial value precedence
  • Shift1nursePaul, Shift2nursePeter,
    Shift3nurseJane, Shift4nursePaul ..
  • If Paul and Jane have the same skills, we can
    swap them (but not with Peter who is less
    qualified)
  • Shift1nurseJane, Shift2nursePeter,
    Shift3nursePaul, Shift4nurseJane

43
Partial value precedence
  • Values may partition into equivalence classes
  • Value precedence easily generalized to cover this
    case
  • Within each equivalence class, vi occurs before
    vj for all iltj (ignore values from other
    equivalence classes)

44
Partial value precedence
  • Values may partition into equivalence classes
  • Value precedence easily generalized to cover this
    case
  • Within each equivalence class, vi occurs before
    vj for all iltj (ignore values from other
    equivalence classes)
  • For example
  • Suppose vi are one equivalence class, and ui
    another

45
Partial value precedence
  • Values may partition into equivalence classes
  • Value precedence easily generalized to cover this
    case
  • Within each equivalence class, vi occurs before
    vj for all iltj (ignore values from other
    equivalence classes)
  • For example
  • Suppose vi are one equivalence class, and ui
    another
  • X1v1, X2u1, X3v2, X4v1, X5u2

46
Partial value precedence
  • Values may partition into equivalence classes
  • Value precedence easily generalized to cover this
    case
  • Within each equivalence class, vi occurs before
    vj for all iltj (ignore values from other
    equivalence classes)
  • For example
  • Suppose vi are one equivalence class, and ui
    another
  • X1v1, X2u1, X3v2, X4v1, X5u2
  • Since v1, v2, v1 and u1, u2,

47
Conclusions
  • Symmetry of interchangeable values can be broken
    with value precedence constraints
  • Value precedence can be decomposed into ternary
    constraints
  • Efficient and effective method to propagate
  • Berge acyclic constraint graph
  • Can be generalized in many directions
  • Partial interchangeability,

48
NVALUES
  • Computational complexity to the rescue!

49
Global constraints
  • Hardcore algorithms
  • Data structures
  • Graph theory
  • Flow theory
  • Combinatorics
  • Computational complexity
  • Global constraints are often balanced on the
    limits of tractability!

50
Computational complexity 101
  • Some problems are essentially easy
  • Multiplication, O(n1.58)
  • Sorting, O(n log n)
  • Regular language membership, O(n)
  • Context free language membership, O(n3) ..
  • P (for polynomial)
  • Class of decision problems recognized by
    deterministic Turing Machine in polynomial number
    of steps
  • Decision problem
  • Question with yes/no answer? E.g. is this string
    in the regular language? Is this list sorted?

51
NP
  • NP
  • Class of decision problems recognized by
    non-deterministic Turing Machine in polynomial
    number of steps
  • Guess solution, check in polynomial time
  • E.g. is propositional formula ? satisfiable?
    (SAT)
  • Guess model (truth assignment)
  • Check if it satisfies formulae in polynomial time

52
NP
  • Problems in NP
  • Multiplication
  • Sorting
  • ..
  • SAT
  • 3-SAT
  • Number partitioning
  • K-Colouring
  • Constraint satisfaction

53
NP-completeness
  • Some problems are computationally as hard as any
    problem in NP
  • If we had a fast (polynomial) method to solve one
    of these, we could solve any problem in NP in
    polynomial time
  • These are the NP-complete problems
  • SAT (Cooks theorem non-deterministic TM gt SAT)
  • 3-SAT
  • .

54
NP-completeness
  • To demonstrate a problem is NP-complete, there
    are two proof obligations
  • in NP
  • NP-hard (its as hard as anything else in NP)

55
NP-completeness
  • To demonstrate a problem is NP-complete, there
    are two proof obligations
  • in NP
  • Polynomial witness for a solution
  • E.g. SAT, 3-SAT, number partitioning,
    k-Colouring,
  • NP-hard (its as hard as anything else in NP)

56
NP-completeness
  • To demonstrate a problem is NP-complete, there
    are two proof obligations
  • NP-hard (its as hard as anything else in NP)
  • Reduce some other NP-complete to it
  • That is, show how we can use our problem to solve
    some other NP-complete problem
  • At most, a polynomial change in size of problem

57
Global constraints are NP-hard
  • Can solve SAT using a single global constraint!
  • Given SAT problem in N vars
  • SAT(X1,Xn)
  • Constraint holds iff X1N
  • X_1i is 0/1 representing value assigned to SAT
    variable xi
  • X_N2 to Xn represent clauses
  • E.g. X_N2 -1, X_N3 3, X_N4 0 then we
    have in our SAT problem the clause (-x1 or x3)

58
Our hammer
  • Use the tools of computational complexity to
    study global constraints used in practice
  • Not just artificial examples like the one we saw
    on the last slide!

59
Constraints in practice
  • Some constraints proposed in the past are
    intractable
  • NValues(N,X1,..,Xm)
  • Extended GCC(X1,..,Xn,O1,..,Om)

60
NValues
  • NValues(N,X1,..,Xm)
  • N values used in X1,,Xm
  • Useful for resource allocation
  • Strict generalization of AllDifferent

61
NValues
  • NValues(N,X1,..,Xm)
  • N values used in X1,,Xm
  • Useful for resource allocation
  • Strict generalization of AllDifferent
  • NValues(m,X1,..,Xm) iff AllDifferent(X1,..,Xm)

62
NValues
  • NValues(N,X1,..,Xm)
  • Reduction of SAT to NValues
  • SAT problem in n vars, l clauses
  • Xi in i,-i for 1 i n
  • XNs in i,-j,k if s-th clause is (i or -j or
    k)
  • Nn
  • Hence SAT has a solution ltgt NValues has a
    solution

63
NValues
  • NValues(N,X1,..,Xm)
  • Reduction of SAT to NValues
  • SAT problem in n vars, l clauses
  • Xi in i,-i for 1 i n
  • XNs in i,-j,k if s-th clause is (i or -j or
    k)
  • Nn
  • Hence SAT has a solution ltgt NValues has a
    solution ltgt Enforcing GAC does not domain wipeout

64
NValues
  • NValues(N,X1,..,Xm)
  • Reduction of SAT to NValues
  • SAT problem in n vars, l clauses
  • Xi in i,-i for 1 i n
  • XNs in i,-j,k if s-th clause is (i or -j or
    k)
  • Nn
  • Enforcing GAC on NVALUES decides SAT (and hence
    is NP-hard itself)

65
NValues
  • NValues(N,X1,..,Xm)
  • Reduction of SAT to NValues
  • SAT problem in n vars, l clauses
  • Xi in i,-i for 1 i n
  • Xns in i,-j,k if s-th clause is (i or -j or
    k)
  • N n
  • Enforcing GAC is NP-hard
  • Enforce lesser level of local consistency (e.g.
    BC)

66
Conclusions
  • Computational complexity is a useful hammer to
    study global constraints
  • Uncovers fundamental limits of reasoning with
    global constraints
  • Lesser consistency needs to be enforced
  • Generalization intractable
  • ..

67
REGULAR
  • Formal languages to the rescue!

68
Global grammar constraints
  • Often easy to specify a global constraint
  • ALLDIFFERENT(X1,..Xn) iff
  • Xi/Xj for iltj
  • Difficult to build an efficient and effective
    propagator
  • Especially if we want global reasoning

69
Global grammar constraints
  • Promising direction initiated is to specify
    constraints via automata/grammar
  • Sequence of variables
  • string in some formal language
  • Satisfying assignment
  • string accepted by the
    grammar/automata

70
REGULAR constraint
  • REGULAR(A,X1,..Xn) holds iff
  • X1 .. Xn is a string accepted by the
    deterministic finite automaton A
  • Proposed by Pesant at CP 2004
  • GAC algorithm using dynamic programming
  • However, DP is not needed since simple ternary
    encoding is just as efficient and effective

71
REGULAR constraint
  • DFAs accept precisely regular languages
  • Regular language can be specified
  • by rules of the form
  • NonTerminal -gt Terminal
  • NonTerminal -gt Terminal NonTerminal NonTerminal
    NonTerminal NonTerminal Terminal
  • Alternatively given by regular expressions
  • More limited than BNF which can express
    context-free grammars

72
REGULAR constraint
  • Regular language
  • S -gt 0 0A AB 1B 1
  • A -gt 0 0A
  • B -gt 1 1B 1A

73
REGULAR constraint
  • Deterministic finite automaton (DFA)
  • ltQ,Sigma,T,q0,Fgt
  • Q is finite set of states
  • Sigma is alphabet (from which strings formed)
  • T is transition function Q x Sigma -gt Q
  • q0 is starting state
  • F subseteq Q are accepting states
  • DFAs accept precisely regular languages

74
REGULAR constraint
  • Regular language
  • S -gt 0 0A AB 1B 1
  • A -gt 0 0A
  • B -gt 1 1B 1A
  • DFA
  • Qq0,q1,q2
  • Sigma0.1
  • T(q0,0)q0. T(q0,1)q1
  • T(q1,0)q2, T(q1,1)q1
  • T(q2,0)q2
  • Fq0,q1,q2

CONTIGUITY constraint
75
REGULAR constraint
  • Many global constraints are instances of REGULAR
  • AMONG, CONTIGUITY, LEX, PRECEDENCE, STRETCH, ..
  • Domain consistency can be enforced in O(ndQ) time
    using dynamic programming
  • Contiguity example 0,1, 0, 1, 0,1, 1

76
REGULAR constraint
  • REGULAR constraint can be encoded into ternary
    constraints
  • Introduce Qi1
  • state of the DFA after the ith transition
  • Then post sequence of constraints
  • C(Xi,Qi,Qi1) iff
  • DFA goes from state Qi to Qi1 on symbol Xi

77
REGULAR constraint
  • REGULAR constraint can be encoded into ternary
    constraints
  • Constraint graph is Berge-acyclic
  • Constraints only overlap on one variable
  • Enforcing GAC on ternary constraints achieves GAC
    on REGULAR in O(ndQ) time

78
REGULAR constraint
  • PRECEDENCE(X1,..Xn) iff
  • min(i Xij or in1) lt min(i Xik or
    in2) for all jltk
  • States of DFA represents largest value so far
    used
  • T(Si,vj)Si if jlti
  • T(Si,vj)Sj if ji1
  • T(Si,vj)fail if jgti1
  • T(fail,v)fail

79
REGULAR constraint
  • PRECEDENCE(X1,..Xn) iff
  • min(i Xij or in1) lt min(i Xik or
    in2) for all jltk
  • States of DFA represents largest value so far
    used
  • T(Si,vj)Si if jlti
  • T(Si,vj)Sj if ji1
  • T(Si,vj)fail if jgti1
  • T(fail,v)fail
  • REGULAR encoding of this is just these transition
    constraints (can ignore fail)

80
REGULAR constraint
  • STRETCH(X1,..Xn) holds iff
  • Any stretch of consecutive values is between
    shortest(v) and longest(v) length
  • Any change (v1,v2) is in some permitted set, P
  • For example, you can only have 3 consecutive
    night shifts and a night shift must be followed
    by a day off

81
REGULAR constraint
  • STRETCH(X1,..Xn) holds iff
  • Any stretch of consecutive values is between
    shortest(v) and longest(v) length
  • Any change (v1,v2) is in some permitted set, P
  • DFA
  • Qi is ltlast value, length of current stretchgt
  • Q0 ltdummy,0gt
  • T(lta,qgt,a)lta,q1gt if q1ltlongest(a)
  • T(lta,qgt,b)ltb,1gt if (a,b) in P and qgtshortest(a)
  • All states are accepting

82
Other generalizations of REGULAR
  • REGULAR FIX(A,X1,..Xn,B1,..Bm) iff
  • REGULAR(A,X1,..Xn) and Bi1 iff exists j. Xji
  • Certain values must occur within the sequence
  • For example, there must be a maintenance shift
  • Unfortunately NP-hard to enforce GAC on this

83
Other generalizations of REGULAR
  • REGULAR FIX(A,X1,..Xn,B1,..Bm)
  • Simple reduction from Hamiltonian path
  • Automaton A accepts any walk on a graph
  • nm and Bi1 for all i

84
Beyond REGULAR
  • Chomsky hierarchy
  • REGULAR
  • CONTEXT FREE
  • CONTEXT SENSITIVE
  • RECURSIVELY ENUMERABLE

85
Beyond REGULAR
  • Chomsky hierarchy
  • REGULAR, O(n) parse, O(n) propagate
  • CONTEXT FREE
  • CONTEXT SENSITIVE
  • RECURSIVELY ENUMERABLE

86
Beyond REGULAR
  • Chomsky hierarchy
  • REGULAR, O(n) parse, O(n) propagate
  • CONTEXT FREE, anbn (or nn) not REGULAR!
  • CONTEXT SENSITIVE
  • RECURSIVELY ENUMERABLE

87
Beyond REGULAR
  • Chomsky hierarchy
  • REGULAR, O(n) parse, O(n) propagate
  • CONTEXT FREE, O(n3) parse, O(n3) propagate
  • CONTEXT SENSITIVE
  • RECURSIVELY ENUMERABLE

88
Beyond REGULAR
  • Chomsky hierarchy
  • REGULAR, O(n) parse, O(n) propagate
  • CONTEXT FREE, O(n3) parse, O(n3) propagate
  • CONTEXT SENSITIVE, PSPACE-complete to test
    membership
  • RECURSIVELY ENUMERABLE

89
Beyond REGULAR
  • Chomsky hierarchy
  • REGULAR, O(n) parse, O(n) propagate
  • CONTEXT FREE, O(n3) parse, O(n3) propagate
  • But we only have fixed length strings!
  • Any fixed length language is REGULAR

90
Beyond REGULAR
  • Chomsky hierarchy
  • REGULAR, O(n) parse, O(n) propagate
  • CONTEXT FREE, O(n3) parse, O(n3) propagate
  • But we only have fixed length strings!
  • Any fixed length language is REGULAR
  • Never forget your hidden constants
  • REGULAR is O(ndQ) where Q is number of states of
    DFA
  • CONTEXT FREE is O(n3G) where G is size of grammar
  • G can be much smaller than Q!

91
Beyond REGULAR
  • Some constraints dont have a small automaton
  • E.g. AllDifferent
  • What is the smallest DFA?
  • What is the smallest CFG?
  • Specialized propagators will always be needed!

92
Conclusions
  • REGULAR constraint
  • Specify wide range of global constraints
  • Provides efficient and effective propagator
    automatically
  • Nice marriage of formal language theory and
    constraint programming!

93
Conclusions
  • PRECEDENCE
  • Breaking value symmetry
  • Not all decompositions hinder propagation
  • Berge-acyclicity
  • NVALUES
  • Computational complexity to the resuce!
  • REGULAR
  • Formal languages to the rescue!
Write a Comment
User Comments (0)
About PowerShow.com