Presentation is loading. Please wait.

Presentation is loading. Please wait.

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,

Similar presentations


Presentation on theme: "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,"— 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() : boolean -> let Q := {} in for (i,j)  {(i,j) | C ij in C} do let delta := arcCons(i,j) in d[i] := d[i] \ delta Q := enqueue(i,delta,Q) while Q ≠ {} 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, a sketch ac5 has 2 phases Phase 1, lines to - revise all the constraints - build up the Q of tuples (i,j,w) Phase 2, lines to -process the queue - propagate effect of deleted values - exploit knowledge of semantics of constraints - add new deletion tuples to Q

7 ac5, the algorithm This is just like revise, but delivers the set s of unsupported values in d[i] over the constraint C ij s is the set of disallowed values in d[i] remember check(i,x,j,y) is shorthand for C ij (x,y) [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] Can be specialised!

8 ac5, the algorithm [localArcCons(i,j,w) : set -> arcCons(i,j)] Ignores the value w and becomes revise! We can specialise this method if we know something about the semantics of C ij 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!) Revise the constraint C ij because d[j] lost the value w

9 [enqueue(i,delta,q) : set -> for (k,i)  {(k,i) | C ki in C} do for w  delta do q := q  {(k,i,w} return q] ac5, the algorithm 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 C ki in C

10 [ac5() : boolean -> let Q := {} in for (i,j)  {(i,j) | C ij 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, the algorithm 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(d 2 ) and localArcCons is O(d) then ac5 is O(e.d 2 ) 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.d 3 ) - ac4 is O(e.d 2 )

12

13

14

15 Functional constraints

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

17 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 := C ij in for x  d[i] do if f(x)  d[j] then s := s  {x} return s] 5 4 2 1 3 5 4 2 1 3

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

19 Anti-functional constraints

20 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 := C ij g := C ji in if card(d[i]) = 1 & {g(w)} = d[i] then return d[i] else return {}] 5 4 2 1 3 5 4 2 1 3 If d[i] has more than one value, no problem!

21 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

22

23 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! AIJ57

24 A choco example NOTE: old version of choco

25

26

27

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

29 The lower bound of vars[idx] has increased vars[0] cannot take a value less than that Therefore vars[0].setInf(vars[idx].getInf())

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

31 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]

32 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

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

34 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]

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

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

37

38

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

40 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

41

42 The complexity of ac3A beautiful proof A constraint C ij is revised iff it enters the Q C ij enters Q iff some value in d[j] is deleted C ij 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(d 2 )  the complexity of ac3 is then O(e.d 3 )

43 [revise(d:array,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)] When searching for a support for x in d[j] we always start from scratch This is naïve.

44 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

45 [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) //

46 [existsY(d:array,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 //

47 [revise(d:array,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)]

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

49 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!

50 MAC What’s that then

51 Maintain arc-consistency Instantiate a variable v[i] := x impose unary constraint d[i] = {x} make future problem ac if domain wipe out backtrack and impose constraint d[i]  x make future ac and so on pb.solve(false)

52 Maintain arc-consistency why use instantiation? Domain splitting? resolve disjunctions first for example (V1 < V2 OR V2 < V1)

53 You now know enough to go out and build a reasonably efficient and useful CP toolkit

54 Now its time to start using a CP toolkit

55

56


Download ppt "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,"

Similar presentations


Ads by Google