58
From Constraints to Finite Automata to Filtering Algorithms Mats Carlsson, SICS Nicolas Beldiceanu, EMN [email protected] [email protected]

From Constraints to Finite Automata to Filtering Algorithms

  • Upload
    nassor

  • View
    59

  • Download
    0

Embed Size (px)

DESCRIPTION

From Constraints to Finite Automata to Filtering Algorithms. Mats Carlsson, SICS Nicolas Beldiceanu, EMN [email protected] [email protected]. Outline. Constraint Propagation: Example & Model Constraints and Key Notions Case Study: X  lex Y Definition and signature Finite automaton - PowerPoint PPT Presentation

Citation preview

Page 1: From Constraints to Finite Automata to Filtering Algorithms

From Constraintsto Finite Automata

to Filtering Algorithms

Mats Carlsson, SICSNicolas Beldiceanu, EMN

[email protected]

[email protected]

Page 2: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Outline Constraint Propagation: Example &

Model Constraints and Key Notions Case Study: X lex Y

Definition and signature Finite automaton Filtering algorithm

Case Study: lex_chain(X0,…,Xm-1) Definition and signature Finite automaton Filtering algorithm

Conclusion

Page 3: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Example

x + y = 9 2x + 4y = 24

x 0 1 2 3 4 5 6 7 8 9

y 0 1 2 3 4 5 6 7 8 9

Page 4: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Example

x + y = 9 2x + 4y = 24

x 0 1 2 3 4 5 6 7 8 9

y 0 1 2 3 4 5 6 7 8 9

Page 5: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Example

x + y = 9 2x + 4y = 24

x 0 1 2 3 4 5 6 7 8 9

y 0 1 2 3 4 5 6 7 8 9

Page 6: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Example

x + y = 9 2x + 4y = 24

x 0 1 2 3 4 5 6 7 8 9

y 0 1 2 3 4 5 6 7 8 9

Page 7: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Example

x + y = 9 2x + 4y = 24

x 0 1 2 3 4 5 6 7 8 9

y 0 1 2 3 4 5 6 7 8 9

Page 8: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Example

x + y = 9 2x + 4y = 24

x 0 1 2 3 4 5 6 7 8 9

y 0 1 2 3 4 5 6 7 8 9

Page 9: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Example

x + y = 9 2x + 4y = 24

x 0 1 2 3 4 5 6 7 8 9

y 0 1 2 3 4 5 6 7 8 9

Page 10: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Constraint Propagation Variables

feature variable domain (finite set of integers)

Propagators implement constraints

Propagation loop execute propagators until simultaneous

fixpoint

Page 11: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Propagator Propagator p is a procedure

(coroutine) implements constraint con(p)

its semantics (set of tuples) computes on set of variables var(p)

Execution of propagator p filters domains of variables in var(p) signals failure signals entailment

Page 12: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Propagators Are Intensional Propagators implement filtering

aka: narrowing, domain reduction, value removal

No extensional representation of con(p) impractical in most cases (space)

Extensional representation of constraint can be provided by special propagator often: “element” constraint, “relation” constraint,

Page 13: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Propagation Events

Normally, a propagator p is resumed whenever some value in a domain of var(p) has been removed.

In some cases, some events (e.g. removing internal values) are irrelevant whilst other (bounds adjustments) are relevant.

Page 14: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Idempotent Propagators A propagator is idempotent if it

always computes a fixpoint.

Most constraint programming systems can accommodate both idempotent and non-idempotent propagators.

Page 15: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Implementing Propagators Implementation uses operations on

variables reading domain information filtering domains (removing values)

Variables are the only communication channels between propagators

Algorithms for Domain filtering Failure detection Entailment detection

Page 16: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Outline Constraint Propagation: Example &

Model Constraints and Key Notions Case Study: X lex Y

Definition and signature Finite automaton Filtering algorithm

Case Study: lex_chain(X0,…,Xm-1) Definition and signature Finite automaton Filtering algorithm

Conclusion

Page 17: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Classes of Constraints Basic constraints

Constraints for which the solver is complete x D, x = v, x = y (variable aliasing)

Primitive constraints (need propagators) Non-decomposable constraints

x<y, xy, x+y = z, x*y = z, …

Global constraints (need propagators) Subsume a set of basic or primitive

constraints, usually providing stronger consistency

Page 18: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Support and Consistency Given: constraint C, variable x var(C),

its domain D(x), integer v. x=v has support for C iff

v D(x) C has a solution such that x=v

C is hyperarc consistent iff x var(C) v D(x) x=v has support for C

Maintaining hyperarc consistency may not be possible with polynomial algorithms (e.g. diophantine equations)

Page 19: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Entailment A constraint con(p) is entailed if it

holds for any combination of values in the current domains.

Consequences for its propagator p: It has no more work to do It should not be resumed any more (up to

backtracking) It is usually reponsible for detecting

entailment

Page 20: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Failure A constraint con(p) is false if it does

not hold for any combination of values in the current domains.

Consequences for its propagator p: It should signal inconsistency, e.g. by

instigating backtracking It is reponsible for detecting failure

Page 21: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Notation

Vectors and subvectors X = (x0,…,xn-1) X[0,r) = (x0,…,xr-1), r n

Domain variables D(x), the domain of x (set of integers) min(x), lower bound of x, O(1) max(x), upper bound of x, O(1) prev(x,b) = max{y D(x) | y<b}, O(d) next(x,b) = min{y D(x) | y>b}, O(d)

Page 22: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Constraint Signatures The constraint store is the set of all

domains D(x) For alphabet A, constraint C,

constraint store G, let S(C,G,A) be the signature of C wrt. G and A.

The filtering algorithm is derived from a finite automaton for signatures.

Page 23: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Outline Constraint Propagation: Example &

Model Constraints and Key Notions Case Study: X lex Y

Definition and signature Finite automaton Filtering algorithm

Case Study: lex_chain(X0,…,Xm-1) Definition and signature Finite automaton Filtering algorithm

Conclusion

Page 24: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Definition:X lex Y Let:

X = (x0,…,xn-1) Y = (y0,…,yn-1) xi, yi domain variables or integers

X lex Y holds iff n=0, or x0<y0, or x0=y0 (x1,…,xn-1) lex(y1,…,yn-1).

Page 25: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Signature: X lex Y

Letter

Condition

< max(xi)<min(yi)

= xi = yi, integers

> min(xi)>max(yi)

max(xi)=min(yi)min(xi)<max(yi)

min(xi)=max(yi)max(xi)>min(yi)

? otherwise

$ End of string

Page 26: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Signature example: X lex Y

X 3..3

3..4

4..5

4..5

3..3

4..4

Y 3..3

4..5

3..4

4..5

4..4

3..3

S = ? < > $

Page 27: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Poset of signature letters

< = >

?

E.g., a becomes a < or a = in a ground store.

Page 28: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Outline Constraint Propagation: Example &

Model Constraints and Key Notions Case Study: X lex Y

Definition and signature Finite automaton Filtering algorithm

Case Study: lex_chain(X0,…,Xm-1) Definition and signature Finite automaton Filtering algorithm

Conclusion

Page 29: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Finite Automaton for X lex Y

1 2 3 4

T1 T3 T2

F1 D1 D3 D2

$

$ $ $

Page 30: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Success State T1

1

T1

$

Enforce xi=yi in the leading prefix for C to hold.Afterwards, the leading prefix is ground and equal.

Page 31: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Success State T2

1 2 4

T2

<q

Enforce xq<yq in order for there to be at least one < preceding the first >.

Page 32: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Success State T3

1 2 3

T3

$ $

q

Only enforce xqyq , for < can appear in a later position.

Page 33: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Delay States

1 2 3 4

T3 T2

D1 D3 D2

$

$ $

q

Not yet enough information to know what to do at position q.

T1

$

Page 34: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Outline Constraint Propagation: Example &

Model Constraints and Key Notions Case Study: X lex Y

Definition and signature Finite automaton Filtering algorithm

Case Study: lex_chain(X0,…,Xm-1) Definition and signature Finite automaton Filtering algorithm

Conclusion

Page 35: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Filtering Algorithms Non-incremental, O(n)

Run finite automaton from scratch Consider all letters from scratch

Incremental, amortized O(1) Deal with one letter change at a time Needs to know what letter has

changed, in what state

Page 36: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Incremental Restart 1

1 2 3 4

T1 T3 T2

F1 D1 D3 D2

$

$ $ $

Resume in state 1.

Page 37: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Incremental Restart 2

1 2 3 4

T1 T3 T2

F1 D1 D3 D2

$

$ $ $

Resume in state 2.

Page 38: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Incremental Restart 3

1 2 3 4

T1 T3 T2

F1 D1 D3 D2

$

$ $ $

Resume in state 3 or 4, resp.

Page 39: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Incremental Restart 4

1 2 3 4

T1 T3 T2

F1 D1 D3 D2

$

$ $ $

If changed to =, no-op. Otherwise, resume in state 3 or 4, resp.

Page 40: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Finite Automaton for X <lex Y

1 2 3 4

T1 T3 T2

F1 D1 D3 D2

$ $ $ $

Page 41: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Outline Constraint Propagation: Example &

Model Constraints and Key Notions Case Study: X lex Y

Definition and signature Finite automaton Filtering algorithm

Case Study: lex_chain(X0,…,Xm-1) Definition and signature Finite automaton Filtering algorithm

Conclusion

Page 42: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Definition:lex_chain(X0,…,Xm-1)

Let: Xi = (xi0,…,xin-1) xij domain variables or integers

lex_chain(X0,…,Xm-1) holds iff

X0 lex … lex Xm-1

Page 43: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Internal constraint:between(A,X,B) Preconditions:

A = (a0,…,an-1), B = (b0,…,bn-1) X = (x0,…,xn-1) ai,bi integers; xi domain variables i[0,n) : ai D(xi), bi D(xi)

Holds iff:A lex X lex B

Page 44: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Signature:between(A,X,B)

Letter

Condition

< ai<bi next(xi,ai)bi

« ai<bi next(xi,ai)<bi

= min(xi)=ai=bi=max(xi)

# min(xi)ai=bi max(xi)ai=bi

> ai>bi bimin(xi)max(xi)ai

» ai>bi (min(xi)<biai<max(xi))

$ End of string

Page 45: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Signature example: between(A,X,B)

A 5 4 6 6

X 4..6 4..6 4..6 3..7

B 5 5 4 4

S # < > » $

X’ 5..5 4..5 {4,6}

{3,4,6,7}

Page 46: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Outline Constraint Propagation: Example &

Model Constraints and Key Notions Case Study: X lex Y

Definition and signature Finite automaton Filtering algorithm

Case Study: lex_chain(X0,…,Xm-1) Definition and signature Finite automaton Filtering algorithm

Conclusion

Page 47: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Finite Automaton:between(A,X,B)

1 2

T1 T2

F1

=#

«$ <«»#$

>=

<

State 1 denotes a prefix in which ai=bi. Hence we must enforce xi=ai=bi there.

Page 48: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Success State T1:between(A,X,B)

1

T1

=#

«$Either q=n or xq=v has support for all aqvbq.Hence we enforce aqxqbq.

q

Page 49: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Success State T2:between(A,X,B)

1 2

T2

=#

<«»#$

>=

<

We have:X[0,r)=A[0,r)X[0,r)=B[0,r)

Hence we enforce:aixibi for i[0,r).

Either r=n or xr=v has support for all vbr var.

Hence we enforce:xrbr xrar.

r

Page 50: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Outline Constraint Propagation: Example &

Model Constraints and Key Notions Case Study: X lex Y

Definition and signature Finite automaton Filtering algorithm

Case Study: lex_chain(X0,…,Xm-1) Definition and signature Finite automaton Filtering algorithm

Conclusion

Page 51: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Feasible Upper Bound:Problem Given X and B, compute the

lexicographically largest U such that:

U lex B i[0,n) : ui D(xi)

Similarly for feasible lowest bound

Page 52: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Feasible Upper Bound:Algorithm

Compute as the smallest i such thatU[0,i)B[0,i)

Compute: ui = bi, if i < ui = prev(xi,bi), if i =

ui = max(xi), if i > Similarly for feasible lowest bound

Page 53: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Filtering:lex_chain(X0,…,Xm-1)

1. Compute feasible upper bound Bi for Xi from i=m-1 down to i=0.

2. Compute feasible lower bound Ai for Xi from i=0 to i=m-1.

3. Enforce Ai lex Xi lex Bi for all i.

Arc-consistency in O(nmd) time.

Page 54: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Outline Constraint Propagation: Example &

Model Constraints and Key Notions Case Study: X lex Y

Definition and signature Finite automaton Filtering algorithm

Case Study: lex_chain(X0,…,Xm-1) Definition and signature Finite automaton Filtering algorithm

Conclusion

Page 55: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Results An approach to designing filtering

algorithms by derivation from FAs on constraint signatures

Case studies and hyperarc consistency algorithms for two constraints: X lex Y, running in amortized O(1) time per

propagation event lex_chain(X0,…,Xm-1), running in O(nmd)

time per invocation

Page 56: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Future Work What constraints are amenable to the

approach? Where does the alphabet come from? Where does the automaton come from? Where do the pruning rules come from? How do we make the algorithms

incremental?

Page 57: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

References and proofs SICS T2002-17: Revisiting the

Lexicographic Ordering Constraint, Mats Carlsson, Nicolas Beldiceanu.

SICS T2002-18: Arc-Consistency for a Chain of Lexicographic Ordering Constraints, Mats Carlsson, Nicolas Beldiceanu.

http://www.sics.se/libindex.html

Page 58: From Constraints to Finite Automata to Filtering Algorithms

ESOP, March 29, 2004

Related Work Global constraints for

lexicographic orderings. A. Frisch, B. Hnich, Z. Kızıltan, I. Miguel, T. Walsh. Proc. CP’2002. LNCS 2470, pp. 93-108, Springer, 2002.