1 / 56

Arc consistency

Arc consistency. AC5, AC2001, MAC. AC5. A generic arc-consistency algorithm and its specializations AIJ 57 (2-3) October 1992 P. Van Hentenryck, Y. Deville, and C.M. Teng. ac5. Ac5 is a “generic” ac algorithm and can be specialised for

sherry
Download Presentation

Arc consistency

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Arc consistency AC5, AC2001, MAC

  2. AC5 A generic arc-consistency algorithm and its specializations AIJ 57 (2-3) October 1992 P. Van Hentenryck, Y. Deville, and C.M. Teng

  3. ac5 Ac5 is a “generic” ac algorithm and can be specialised for special constraints (i.e. made more efficient when we know something about the constraints) Ac5 is at the heart of constraint programming It can be “tweaked” to become ac3, or “tweaked” to become ac4 But, it can exploit the semantics of constraints, and there’s the win

  4. ac5 • ac5 processes a queue of tuples (i,j,w) • w has been removed from Dj • we now need to reconsider constraint Cij • to determine the unsupported values in Di • A crucial difference between ac3 and ac5 • ac3 • revise(i,j) because Dj has lost some values • seek support for each and every value in Di • ac5 • process(i,j,w) because Dj has lost the value w (very specific) • seek support, possibly, for select few (1?) value in Di Therefore, by having a queue of (i,j,w) we might be able to do things much more efficiently

  5. ac5, the intuition • take an OOP approach • constraint is a class that can then be specialised • have a method to revise a constraint object • allow specialisation • have basic methods such as • revise when lwb increases • revise when upb decreases • revise when a value is lost • revise when variable instantiated • revise initially • methods take as arguments • the variable in the constraint that has changed • possibly, what values have been lost Example: IntDomainVar x = pb.makeBoundIntVar(“x”,1,10); IntDomainVar y = pb.makeBoundIntVar(“y”,1,10); Constraint c = pb.lt(x,y);

  6. ac5, a sketch [ac5() : boolean -> let Q := {} <1> in for (i,j)  {(i,j) | Cij in C} <2> do let delta := arcCons(i,j) <3> in d[i] := d[i] \ delta <4> Q := enqueue(i,delta,Q) <5> while Q ≠ {} <6> do let (i,j,w) := dequeue(Q) <7> delta := localArcCons(i,j,w) <8> in Q := enqueue(i,delta,Q) <9> d[i] := d[i] \ delta <10> return allDomainsNonEmpty(d)] <11> • ac5 has 2 phases • Phase 1, lines <1> to <5> • - revise all the constraints • - build up the Q of tuples (i,j,w) • Phase 2, lines <6> to <10> • process the queue • - propagate effect of deleted values • - exploit knowledge of semantics of constraints • - add new deletion tuples to Q

  7. ac5, the algorithm [arcCons(i,j) : set -> let s := {} in for x  d[i] do let supported := false in for y  d[j] while ¬supported do supported := check(i,x,j,y) if ¬supported then s := s  {x} return s] This is just like revise, but delivers the set s of unsupported values in d[i] over the constraint Cij Can be specialised! s is the set of disallowed values in d[i] remember check(i,x,j,y) is shorthand for Cij(x,y)

  8. ac5, the algorithm [localArcCons(i,j,w) : set -> arcCons(i,j)] Revise the constraint Cij because d[j] lost the value w Ignores the value w and becomes revise! We can specialise this method if we know something about the semantics of Cij We might then do much better that arcCons in terms of complexity What we have above is the dummy’s version, or when we know nothing about the constraint (and we get AC3!)

  9. ac5, the algorithm [enqueue(i,delta,q) : set -> for (k,i)  {(k,i) | Cki in C} do for w  delta do q := q  {(k,i,w} return q] • The domain d[i] has lost values delta • Add to the queue of “things to do” the tuple (k,i,w) • For all w is in delta • For all Cki in C

  10. ac5, the algorithm [ac5() : boolean -> let Q := {} in for (i,j)  {(i,j) | Cij in C} phase 1 do let delta := arcCons(i,j) in d[i] := d[i] \ delta Q := enqueue(i,delta,Q) while Q ≠ {} phase 2 do let (i,j,w) := dequeue(Q) delta := localArcCons(i,j,w) in Q := enqueue(i,delta,Q) d[i] := d[i] \ delta return allDomainsNonEmpty(d)] ac5 has 2 phases - revise all the constraints and build up the Q using arcCons - process the queue and propagate using localArcCons, exploiting knowledge on deleted values and the semantics of constraints

  11. Complexity of ac5 If arcCons is O(d2) and localArcCons is O(d) then ac5 is O(e.d2) If arcCons is O(d) and localArcCons is O() then ac5 is O(e.d) See AIJ 57 (2-3) page 299 Remember - ac3 is O(e.d3) - ac4 is O(e.d2)

  12. Functional constraints

  13. 1 1 2 2 3 3 4 4 5 5 If c is functional We can specialise arcCons and localArcCons for functional constraints • A constraint C_i,j is functional, with respect to a domainD, if and only if • for all x in D[i] • there exists at most one value y in D[j] such that • Cij(x,y) holds • and • for all y in D[j] • there exists at most one value in D[i] such that • Cji(y,x) holds • The relation is a bijection An example: 3.x = y

  14. 1 1 2 2 3 3 4 4 5 5 If c is functional Let f(x) = y and f’(y) = x (f’ is the inverse of f) [arcCons(i,j) : set -> let s := {} f := Cij in for x  d[i] do if f(x)  d[j] then s := s  {x} return s]

  15. 1 1 2 2 3 3 4 4 5 5 If c is functional Let inverse(f) deliver the f’, the inverse of function f [localArcCons(i,j,w) : set -> let f := Cij g := Cji in if g(w)  d[i]) then return {g(w)} else return {}] • In our picture, • assume d[j] looses the value 2 • g(2) = 3 • localArcCons(i,j,2) = {3}

  16. Anti-functional constraints

  17. 1 1 2 2 3 3 4 4 5 5 If c is anti-functional The value w in d[j] conflicts with only one value in d[i] an example: x + 4 ≠ y [localArcCons(i,j,w) : set -> let f := Cij g := Cji in if card(d[i]) = 1 & {g(w)} = d[i] then return d[i] else return {}] If d[i] has more than one value, no problem!

  18. Other kinds of constraints that can be specialised • monotonic •     • localArcCons tops and tails domains • but domains must be ordered • piecewise functional • piecewise anti-functional • piecewise monotonic See: AIJ 57 & AR33 section 7

  19. AIJ57 • The AIJ57 paper by van Hentenryck, Deville, and Teng is a remarkable paper • they tell us how to build a constraint programming language • they tell us all the data structures we need • for representing variables, their domains, etc • they introduce efficient algorithms for arc-consistency • they show us how to recognise special constraints and how we should process them • they show us how to incorporate ac5 into the search process • they explain all of this in easy to understand, well written English • It is a classic paper, in my book!

  20. A choco example NOTE: old version of choco

  21. x[0] = max(x[1],x[2],…,x[n-1])

  22. x[0] = max(x[1],x[2],…,x[n-1]) The lower bound of vars[idx] has increased vars[0] cannot take a value less than that Therefore vars[0].setInf(vars[idx].getInf())

  23. x[0] = max(x[1],x[2],…,x[n-1]) The upper bound of vars[idx] has decreased

  24. x[0] = max(x[1],x[2],…,x[n-1]) idx > 0 Find the largest upper bound of variables vars[1] to vars[n-1]

  25. x[0] = max(x[1],x[2],…,x[n-1]) idx > 0 Find the largest upper bound of variables vars[1] to vars[n-1] Reduce the upper bound of vars[idx] to be the largest upper bound

  26. x[0] = max(x[1],x[2],…,x[n-1]) idx = 0 and upper bound of vars[idx] has decreased

  27. x[0] = max(x[1],x[2],…,x[n-1]) No variable vars[1] to vars[n-1] can take a value greater than upper bound of vars[0]

  28. x[0] = max(x[1],x[2],…,x[n-1]) On first posting the constraint, at top of search

  29. x[0] = max(x[1],x[2],…,x[n-1]) Variable vars[idx] is instantiated

  30. Challenge/Homework Using only toolkit constraints such as leq, geq, … model x = max(y,z) where x, y, and z are constrained integer variables

  31. AC2001 Taken from IJCAI01 “Making AC-3 an Optimal Algorithm” by Y Zhang and R. Yap and “Refining the basic constraint propagation algorithm” by Christian Bessiere & Jean-Charles Regin

  32. The complexity of ac3 A beautiful proof • A constraint Cij is revised iff it enters the Q • Cij enters Q iff some value in d[j] is deleted • Cij can enter Q at most d times (the size of domain d[j]) •  A constraint can be revised at most d times • There are e constraints in C (the set of constraints) •  revise is executed at most e.d times • the complexity of revise is O(d2) •  the complexity of ac3 is then O(e.d3)

  33. When searching for a support for x in d[j] we always start from scratch This is naïve. [revise(d:array<set>,c:tuple,i:integer,j:integer) : boolean ->let revised := false in (for x in copy(d[i]) (let supported := false in (for y in d[j] // this is naive (if check(c,x,y) (supported := true, return())), if not(supported) (delete(d[i],x), revised := true))), CONSISTENT := d[i] != {}, revised)]

  34. Assume domains are totally ordered • Let resumePoint[i,j,x] = y • where y is the first value in d[j] that supports x in d[i] • i.e. C_i,j is satisfied by the pair (x,y) • Assume succ(y,d) delivers the successor of y in domain d • (and nil if no successor exists) • When we revise constraint C_i,j, we look for support for x in d[j] • get the resumePoint for x in domain d[j] over the constraint • call this value y • if y is in d[j] then x is supported! Do nothing! • If y is not in d[j] then • we search through the remainder of d[j] looking for support • we use a successor function to get next y in d[j] • if we find a y that satisfies the constraint set resumePoint[i,j,x] = y

  35. [succ(x:integer,l:list) : integer -> if (l = nil) -1 else if (l[1] > x) l[1] else succ(x,cdr(l))] // // find the successor of x in ordered list l // NOTE: in the ac2001 algorithms we assume // we can do this in O(1) //

  36. [existsY(d:array<set>,c:tuple,i:integer,j:integer,x:integer) : boolean -> let y := RP[i][j][x] in (if (y % d[j]) true else let supported := false in (y := succ(y,list!(d[j])), while (y > 0 & not(supported)) (if check(c,x,y) (RP[i][j][x] := y, supported := true) else y := succ(y,list!(d[j]))), supported))] // // find the first value y in d[j] that supports x in d[i] // if found return true otherwise false //

  37. [revise(d:array<set>,c:tuple,i:integer,j:integer) : boolean -> let revised := false in (for x in copy(d[i]) (if not(existsY(d,c,i,j,x)) (delete(d[i],x), revised := true)), revised)]

  38. In the two papers, the algorithm is shown to be optimal, for arbitrary binary csp’s

  39. arc-consistency is at the heart of constraint programming • it is the inferencing step used inside search • it has to be efficient • data structures and algorithms are crucial to success • ac is established possibly millions of times when solving • it has to be efficient • we have had an optimal algorithm many times • ac4, ac6, ac7, ac2001 • ease of implementation is an issue • we like simple things • but we might still resort to empirical study!

  40. MAC What’s that then

More Related