Global Constraints - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

Global Constraints

Description:

5 tuple Q,Sigma,T,q0,F where. Q is finite set of states. Sigma is alphabet (from which strings formed) T is transition function: Q x Sigma - Q ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 35
Provided by: cseUn
Category:

less

Transcript and Presenter's Notes

Title: Global Constraints


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

2
Course outline
  • Introduction
  • All Different
  • Lex ordering
  • Value precedence
  • Complexity
  • GAC-Schema
  • Soft Global Constraints
  • Global Grammar Constraints
  • Roots Constraint
  • Range Constraint
  • Slide Constraint
  • Global Constraints on Sets

3
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

4
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

Global constraints meets formal language theory
5
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

6
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
  • Regular language can be specified by rules of the
    form
  • NonTerminal -gt Terminal Terminal NonTerminal

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

8
REGULAR constraint
  • Deterministic finite automation (DFA)
  • 5 tuple ltQ,Sigma,T,q0,Fgt where
  • 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

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

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

This is the CONTIGUITY global constraint
11
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

12
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

13
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

14
REGULAR constraint
  • PRECEDENCE(X1,..Xn) iff
  • min(i Xij or in1) lt min(i Xik or
    in2) for all jltk
  • DFA has one state for each value plus a single
    non-accepting state, fail
  • State 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

15
REGULAR constraint
  • PRECEDENCE(X1,..Xn) iff
  • min(i Xij or in1) lt min(i Xik or
    in2) for all jltk
  • DFA has one state for each value plus a single
    non-accepting state, fail
  • State 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)

16
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

17
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

18
NFA constraint
  • Automaton does not need to be deterministic
  • Non-deterministic finite automaton (NFA) still
    only accept regular languages
  • But may require exponentially fewer states
  • Important as O(ndQ) running time for propagator
  • E.g. 0 (12) 2 (12)k 0
  • Where 0closed, 1production, 2maintenance
  • Can use the same ternary encoding

19
Soft REGULAR constraint
  • May wish to be near to a regular string
  • Near could be
  • Hamming distance
  • Edit distance
  • SoftREGULAR(A,X1,..Xn,N) holds iff
  • X1..Xn is at distance N from a string accepted by
    the finite automaton A
  • Can encode this into a sequence of 5-ary
    constraints

20
Soft REGULAR constraint
  • SoftREGULAR(A,X1,..Xn,N)
  • Consider Hamming distance (edit distance similar
    though a little more complex)
  • Qi1 is state of automaton after the ith
    transition
  • Di1 is Hamming distance up to the ith variable
  • Post sequence of constraints
  • C(Xi,Qi,Qi1,Di,Di1) where
  • Di1Di if T(Xi,Qi)Qi1 else Di11Di

21
Soft REGULAR constraint
  • SoftREGULAR(A,X1,..Xn,N)
  • To propagate
  • Dynamic programming
  • Pass support along sequence
  • Just post the 5-ary constraints
  • Accept less than GAC
  • Tuple up the variables

22
Cyclic forms of REGULAR
  • REGULAR(A,X1,..,Xn)
  • X1 .. XnX1 is accepted by A
  • Can convert into REGULAR by increasing states by
    factor of d where d is number of initial symbols
  • qi gt (qi,d)
  • T(qi,a)qj gt T((qi,d),a)(qj,d)
  • T(q0,d)qk gt T(q0,d)(qk,d)
  • Thereby pass along value taken by X1 so it can be
    checked on last transition

23
Cyclic forms of REGULAR
  • REGULARo(A,X1,..,Xn)
  • Xi .. X1(in-1)mod n is accepted by A for each
    1ltiltn
  • Can decompose into n instances of the REGULAR
    constraint
  • However, this hinders propagation
  • Suppose A accepts just alternating sequences of 0
    and 1
  • Xi in 0,1 and REGULARo(A,X1,X2.X3)
  • Unfortunately enforcing GAC on REGULARo is
    NP-hard

24
Cyclic forms of REGULAR
  • REGULARo(A,X1,..,Xn)
  • Reduction from Hamiltonian cycle
  • Consider polynomial sized automaton A1 that
    accepts any sequence in which the 1st character
    is never repeated
  • Consider polynomial sized automaton A2 that
    accepts any walk in a graph
  • T(a,b)b iff (a,b) in edges of graph
  • Consider polynomial sized automaton A1 intersect
    A2
  • This accepts only those strings corresponding to
    Hamiltonian cycles

25
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

26
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

27
Chomsky hierarchy
  • Regular languages
  • Context-free languages
  • Context-sensitive languages
  • ..

28
Chomsky hierarchy
  • Regular languages
  • GAC propagator in O(ndQ) time
  • Conext-free languages
  • GAC propagator in O(n3) time and O(n2) space
  • Asymptotically optimal as same as parsing!
  • Conext-sensitive languages
  • Checking if a string is in the language
    PSPACE-complete
  • Undecidable to know if empty string in grammar
    and thus to detect domain wipeout and enforce GAC!

29
Context-free grammars
  • Possible applications
  • Hierarchy configuration
  • Bioinformatics
  • Natual language parsing
  • CFG(G,X1,Xn) holds iff
  • X1 .. Xn is a string accepted by the context free
    grammar G

30
Context-free grammars
  • CFG(G,X1,Xn)
  • Consider a block stacking example
  • S -gt NP P PN NPN
  • N -gt n nN
  • P -gt aa bb aPa bPb
  • These rules give n w rev(w) n where w is (ab)
  • Not expressible using a regular language
  • Chomsky normal form
  • Non-terminal -gt Terminal
  • Non-terminal -gt Non-terminal Non-terminal

31
Context-free grammars
  • CFG(G,X1,Xn)
  • Example with X1 in n,a, X2 in b, X3 in a,b
    and X4 in n,a
  • Enforcing GAC on CFG prunes X3a
  • Only supports are nbbn and abba

32
CFG propagator
  • Adapt CYK parser
  • Works on Chomsky normal form
  • Non-terminal -gt Terminal
  • Non-terminal -gt Non-terminal Non-terminal
  • Using dynamic programming
  • Computes Vi,j, set of possible parsings for the
    ith to the jth symbols

33
CFG propagator
  • Adapt CYK parser which uses dynamic programming
  • For i1 to n do
  • Vi,1A A-gta in G, a in dom(Xi)
  • For j2 to n do
  • For i1 to n-j1 do
  • Vi,j
  • For k1 to j-1 do
  • Vi,jVi,j u AA-gtBC in G,
  • B in Vi,k, C
    in Vik,j-k
  • If not(S in V1,n) then unsat

34
Conclusions
  • Global grammar constraints
  • Specify wide range of global constraints
  • Provide efficient and effective propagators
    automatically
  • Nice marriage of formal language theory and
    constraint programming!
Write a Comment
User Comments (0)
About PowerShow.com