global grammar constraints
Download
Skip this Video
Download Presentation
Global Grammar Constraints

Loading in 2 Seconds...

play fullscreen
1 / 28

Global Grammar Constraints - PowerPoint PPT Presentation


  • 438 Views
  • Uploaded on

Toby Walsh National ICT Australia and University of New South Wales www.cse.unsw.edu.au/~tw Joint work with Claude-Guy Quimper To be presented at CP06. Global Grammar Constraints . Global grammar constraints. Often easy to specify a global constraint ALLDIFFERENT([X1,..Xn]) iff

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Global Grammar Constraints' - Patman


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
global grammar constraints
Toby Walsh

National ICT Australia and

University of New South Wales

www.cse.unsw.edu.au/~tw

Joint work with Claude-Guy Quimper

To be presented at CP06

Global Grammar Constraints
global grammar constraints2
Global grammar constraints
  • Often easy to specify a global constraint
    • ALLDIFFERENT([X1,..Xn]) iff

Xi=/=Xj for i

  • Difficult to build an efficient and effective propagator
    • Especially if we want global reasoning
global grammar constraints3
Global grammar constraints
  • Promising direction initiated by Beldiceanu, Carlsson, Pesant and Petit is to specify constraints via automata/grammar
    • Sequence of variables =

string in some formal language

    • Satisfying assignment =

string accepted by the grammar/automata

regular constraint
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
    • Encoding similar to that used by Beldiceanu et al for their automata with counters
regular constraint5
REGULAR constraint
  • Deterministic finite automaton (DFA)
    • Q is finite set of states
    • Sigma is alphabet (from which strings formed)
    • T is transition function: Q x Sigma -> Q
    • q0 is starting state
    • F subseteq Q are accepting states
  • DFAs accept precisely regular languages
regular constraint6
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
regular constraint7
REGULAR constraint
  • REGULAR constraint can be encoded into ternary constraints
  • Introduce Qi+1
    • state of the DFA after the ith transition
  • Then post sequence of constraints
    • C(Xi,Qi,Qi+1) iff

DFA goes from state Qi to Qi+1 on symbol Xi

regular constraint8
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
regular constraint9
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
  • Encoding provides access to states of automata
    • Can be useful for expressing problems
    • E.g. minimizing number of times we are in a particular state
regular constraint10
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
regular constraint11
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
    • Q0=
    • T(,a)= if q+1<=longest(a)
    • T(,b)= if (a,b) in P and q>=shortest(a)
    • All states are accepting
nfa constraint
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* (1|2)^k 2 (1|2)* 2 (1|2)^k 0*
    • Where 0=closed, 1=production, 2=maintenance
  • Can use the same ternary encoding
soft regular constraint
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
soft regular constraint14
Soft REGULAR constraint
  • SoftREGULAR(A,[X1,..Xn],N)
    • Consider Hamming distance (edit distance similar though a little more complex)
    • Qi+1 is state of automaton after the ith transition
    • Di+1 is Hamming distance up to the ith variable
    • Post sequence of constraints
      • C(Xi,Qi,Qi+1,Di,Di+1) where
      • Di+1=Di if T(Xi,Qi)=Qi+1 else Di+1=1+Di
soft regular constraint15
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
cyclic forms of regular
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 => (qi,initial value)
    • T(qi,a)=qj => T((qi,b),a)=(qj,b)
    • Thereby pass along value taken by X1 so it can be checked on last transition
cyclic forms of regular17
Cyclic forms of REGULAR
  • REGULARo(A,[X1,..,Xn])
    • Xi .. X1+(i+n-1)mod n is accepted by A for each 1<=i<=n
    • 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
cyclic forms of regular18
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
other generalizations of regular
Other generalizations of REGULAR
  • REGULAR FIX(A,[X1,..Xn],[B1,..Bm]) iff
    • REGULAR(A,[X1,..Xn]) and Bi=1 iff exists j. Xj=I
    • Certain values must occur within the sequence
    • For example, there must be a maintenance shift
    • Unfortunately NP-hard to enforce GAC on this
other generalizations of regular20
Other generalizations of REGULAR
  • REGULAR FIX(A,[X1,..Xn],[B1,..Bm])
    • Simple reduction from Hamiltonian path
    • Automaton A accepts any walk on a graph
    • n=m and Bi=1 for all i
chomsky hierarchy
Chomsky hierarchy
  • Regular languages
  • Context-free languages
  • Context-sensitive languages
  • ..
chomsky hierarchy22
Chomsky hierarchy
  • Regular languages
    • GAC propagator in O(ndQ) time
  • Conext-free languages
    • GAC propagator in O(n^3) time and O(n^2) 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!
context free grammars
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
context free grammars24
Context-free grammars
  • CFG(G,[X1,…Xn])
    • Consider a block stacking example
    • S -> NP | P | PN | NPN
    • N -> n | nN
    • P -> aa | bb | aPa | bPb
    • These rules give n* w rev(w) n* where w is (a|b)*
    • Not expressible using a regular language
  • Chomsky normal form
    • Non-terminal -> Terminal
    • Non-terminal -> Non-terminal Non-terminal
cfg propagator
CFG propagator
  • Adapt CYK parser
  • Works on Chomsky normal form
    • Non-terminal -> Terminal
    • Non-terminal -> Non-terminal Non-terminal
  • Using dynamic programming to compute supports
  • Bottom up
    • Enforces GAC in Theta(n^3) time

Simultaneously and independently proposed by Sellmannn [CP06]

cfg propagator26
CFG propagator
  • Adapt Earley chart parser
    • Carry support information
  • Works on grammar in any form
  • More top down
    • Better on tightly restricted grammars
  • Enforces GAC in O(n^3) time
    • Best case is better as not Theta(n^3)
conclusions
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!
ad