Non-binary constraints - PowerPoint PPT Presentation

Non-binary constraints

1 / 92
Non-binary constraints

Non-binary constraints

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

1. Non-binary constraints Toby Walsh Cork Constraint Computation Center tw@4c.ucc.ie

2. Global constraints Toby Walsh Cork Constraint Computation Center tw@4c.ucc.ie

3. Non-exhaustive catalog • Order constraints • Constraints on values • Partitioning constraints • Timetabling constraints • Graph constraints • Scheduling constraints • Bin-packing constraints

4. Global constraints • It isn’t just all-different! • Many constraints specialized to application domains • Scheduling • Packing • ..

5. Order constraints • min(X,[Y1,..,Yn]) and max(X,[Y1,..Yn]) X <= minimum(Y1,..,Yn) X >= maximum(Y1,..Yn) n.b. min is relational not functional

6. Order constraints • min(X,[Y1,..,Yn]) and max(X,[Y1,..Yn]) X <= minimum(Y1,..,Yn) X <= maximum(Y1,..Yn) n.b. min is relational not functional • min_mod(X,[Y1,..,Yn],m) and max_mod(X,[Y1,..Yn],m) X mod m <= minimum(Y1 mod m,..,Yn mod m) X mod m <= maximum(Y1 mod m,..,Yn mod m)

7. Order constraints • min_n(X,n,[Y1,..Ym]) and max_n(X,n,[Y1,..,Ym) X is nth smallest value in Y1,..Ym X is nth largest value in Y1,..Ym

8. Order constraints • min_n(X,n,[Y1,..Ym]) and max_n(X,n,[Y1,..,Ym) X is nth smallest value in Y1,..Ym X is nth largest value in Y1,..Ym min_n(X,1,[Y1,..,Ym]) => min(X,[Y1,..,Yn]) max_n(X,1,[Y1,..,Ym]) => max(X,[Y1,..,Ym]) n.b. min_n is functional but min is relational (any X smaller than min will do!

9. Value constraints • among(N,[Y1,..,Yn],[val1,..,valm]) N vars in [Y1,..,Yn] take values val1,..valm e.g. among(2,[1,2,1,3,1,5],[3,4,5])

10. Value constraints • among(N,[Y1,..,Yn],[val1,..,valm]) N vars in [Y1,..,Yn] take values val1,..valm e.g. among(2,[1,2,1,3,1,5],[3,4,5]) • count(n,[Y1,..,Ym],op,X) where op is =,<,>,=/,<= or >= relation “Yi op X” holds n times E.g. among(n,[Y1,..,Ym],[k]) = count(n,[Y1,..,Ym],=,k)

11. Value constraints • balance(N,[Y1,..,Yn]) N = occurrence of more frequent value - occurrence of least frequent value E.g balance(2,[1,1,1,3,4,2])

12. Value constraints • balance(N,[Y1,..,Yn]) N = occurrence of more frequent value - occurrence of least frequent value E.g balance(2,[1,1,1,3,4,2]) all-different([Y1,..,Yn]) => balance(0,[Y1,..,Yn])

13. Value constraints • min_nvalue(N,[Y1,..,Yn]) and max_nvalue(N,[Y1,..,Yn]) least (most) common value in Y1,..,Yn occurs N times E.g. min_nvalue(2,[1,1,2,2,2,3,3,5,5]) Can replace multiple count or among constraints

14. Value constraints • common(X,Y,[X1,..,Xn],[Y1,..,Ym]) X vars in Xi take a value in Yi Y vars in Yi take a value in Xi E.g. common(3,4,[1,9,1,5],[2,1,9,9,6,9])

15. Value constraints • common(X,Y,[X1,..,Xn],[Y1,..,Ym]) X vars in Xi take a value in Yi Y vars in Yi take a value in Xi E.g. common(3,4,[1,9,1,5],[2,1,9,9,6,9]) among(X,[Y1,..,Yn],[val1,..,valm]) = common(X,Y,[X1,..,Yn],[val1,..,valm])

16. Value constraints • same([X1,..,Xn],[Y1,..,Yn]) Yi is a permutation of Xi

17. Value constraints • same([X1,..,Xn],[Y1,..,Yn]) Yi is a permutation of Xi • used_by([X1,..,Xn],[Y1,..,Ym]) all values in Yi are used by vars in Xi m>=m

18. Value constraints • same([X1,..,Xn],[Y1,..,Yn]) Yi is a permutation of Xi • used_by([X1,..,Xn],[Y1,..,Ym]) all values in Yi are used by vars in Xi m>=m • on n values: alldifferent([X1,..,Xn])=same([X1,..,Xn],[1,..,n]) =used_by([X1,..,Xn],[1,..,n])

19. Partitioning constraints • all-different([X1,..,Xn])

20. Partitioning constraints • all-different([X1,..,Xn]) • Other flavours all-different_except_0([X1,..,Xn]) Xi=/Xj unless Xi=Xj=0 • 0 is often used for modelling purposes as “dummy” value • Don’t use this slab • Don’t open this bin ..

21. Partitioning constraints • all-different([X1,..,Xn]) • Other flavours symmetric-all-different([X1,..,Xn]) Xi=/Xj and Xi=j iff Xj=i • Very common in practice • Team i plays j iff Team j plays i..

22. Partitioning constraints • all-different([X1,..,Xn]) • Other flavours symmetric-all-different([X1,..,Xn]) Xi=/Xj and Xi=j iff Xj=i • Very common in practice • Team i plays j iff Team j plays i.. • Regin has proposed very efficient algorithm

23. Partitioning constraints • nvalue(N,[X1,..,Xn]) Xi takes N different values all-different([X1,..,Xn]) = nvalue(n,[X1,..,Xn)

24. Partitioning constraints • nvalue(N,[X1,..,Xn]) Xi takes N different values all-different([X1,..,Xn]) = nvalue(n,[X1,..,Xn) • gcc([X1,..,Xn],Lo,Hi) values in Xi occur between Lo and Hi times all-different([X1,..,Xn])=gcc([X1,..,Xn],1,1)

25. Timetabling constraints • change(N,[X1,..,Xn]),op) where op is {=,<,>,<=,>=,/=} “Xi op Xi+1” holds N times E.g. change(3,[4,4,3,4,1],/=) • You may wish to limit the number of changes of classroom, shifts, …

26. Timetabling constraints • longest_changes(N,[X1,..,Xn]),op) where op is {=,<,>,<=,>=,/=} longest sequence “Xi op Xi+1” is of length N E.g. longest_changes(2,[4,4,4,3,3,2,4,1,1,1],=) • You may wish to limit the length of a shift without break, …

27. Graph constraints • Tours in graph a often represented by the successors: • [X1,..,Xn] means from node i we go to node Xi

28. Graph constraints • Tours in graph a often represented by the successors: • [X1,..,Xn] means from node i we go to node Xi • E.g. [2,1,5,3,4] represents the 2 cycles (1)->(2)->(1) and (3)->(5)->(4)->(3)

29. Graph constraints • cycle(N,[X1,..,Xn]) there are N cycles in Xi e.g. cycle(2,[2,1,5,3,4]) as we have the 2 cycles (1)->(2)->(1) and (3)->(5)->(4)->(3) Useful for TSP like problems (e.g. sending engineers out to repair phones)

30. Graph constraints • derangement(N,[X1,..,Xn]) there are no length 1 cycles in Xi

31. Graph constraints • derangement(N,[X1,..,Xn]) there are no length 1 cycles in Xi e.g. derangement([2,1,5,3,4]) as the 2 cycles (1)->(2)->(1) and (3)->(5)->(4)->(3) have length 2 and 3

32. Graph constraints • derangement(N,[X1,..,Xn]) there are no length 1 cycles in Xi e.g. derangement([2,1,5,3,4]) as the 2 cycles (1)->(2)->(1) and (3)->(5)->(4)->(3) have length 2 and 3 e.g. derangement([3,1,2,4]) as the 2 cycles (1)->(3)->(2)->(1) and (4)->(4) are of length 3 and 1

33. Graph constraints • We may also wish to represent predecessors • For good labelling heuristics • For ease of statement of constraints • [X1,..,Xn] means we came to node i from node Xi

34. Graph constraints • We may also wish to represent predecessors • For good labelling heuristics • For ease of statement of constraints • [X1,..,Xn] means we came to node i from node Xi • E.g. [2,1,4,5,3] now represents the 2 cycles (1)->(2)->(1) and (3)->(5)->(4)->(3)

35. Graph constraints • We may also wish to represent predecessors • For good labelling heuristics • For ease of statement of constraints • [X1,..,Xn] means we came to node i from node Xi • E.g. [2,1,4,5,3] now represents the 2 cycles (1)->(2)->(1) and (3)->(5)->(4)->(3) • In successor notation this was [2,1,5,3,4]

36. Graph constraints • We may also wish to represent predecessors • For good labelling heuristics • For ease of statement of constraints • [X1,..,Xn] means we came to node i from node Xi • E.g. [2,1,4,5,3] now represents the 2 cycles (1)->(2)->(1) and (3)->(5)->(4)->(3) • In successor notation this was [2,1,5,3,4] • How do we know they are the same?

37. Graph constraints • We may also wish to represent predecessors • For good labelling heuristics • For ease of statement of constraints • [X1,..,Xn] means we came to node i from node Xi • E.g. [2,1,4,5,3] now represents the 2 cycles (1)->(2)->(1) and (3)->(5)->(4)->(3) • In successor notation this was [2,1,5,3,4] • How do we know they are the same? • With a channelling constraint!

38. Graph constraints • Inverse([X1,..,Xn],[Y1,..,Yn]) Where [X1,..,Xn] is a successor representation of a path, and [Y1,..,Yn] is a predecessor Thus inverse([2,1,4,5,3],[2,1,5,3,4])

39. Graph constraints • Inverse([X1,..,Xn],[Y1,..,Yn]) Where [X1,..,Xn] is a successor representation of a path, and [Y1,..,Yn] is a predecessor Thus inverse([2,1,4,5,3],[2,1,5,3,4]) And inverse([2,1,5,3,4],[2,1,4,5,3])

40. Scheduling constraints • cummulative([S1,..,Sn],[D1,..,Dn],[E1,..,En],[H1,..,Hn],L) • schedules n (concurrent) jobs, each with a height Hi • ith job starts at Si, runs for Di and ends at Ei • Ei=Si+Di • at any time, accumulated height of running jobs is less than L 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

41. Scheduling constraints • coloured_cummulative([S1,..,Sn],[D1,..,Dn],[E1,..,En],[C1,..,Cn],L) • schedules n (concurrent) each with a colour Ci • no more than L colours running at any one time 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

42. Scheduling constraints • cycle_cummulative(m,[S1,..,Sn],[D1,..,Dn],[E1,..,En],[H1,..,Hn],L) • schedules n (concurrent) jobs, each with a height Hi onto a cyclic schedule of length m

43. Scheduling constraints • cummulatives([M1,,,Mn],[S1,..,Sn],[D1,..,Dn],[E1,..,En],[H1,..,Hn],[L1,..,Lm]) • schedules n (concurrent) jobs, each with a height Hi onto one of m machines • ith runs on Mi • accumulated height of running jobs on machine i <= Li

44. Scheduling constraints • cummulatives([M1,..Mn],[S1,..,Sn],[D1,..,Dn],[E1,..,En],[H1,..,Hn],[L1,..,Lm]) Machine 1 Machine 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

45. Scheduling constraints • coloured_cummulatives([M1,,,Mn],[S1,..,Sn],[D1,..,Dn],[E1,..,En],[C1,..,Cn],[L1,..,Lm]) • schedules n (concurrent) jobs, each with a colour i onto one of m machines • ith runs on Mi • number of colours of running jobs on machine i <= Li

46. Bin-packing constraints • bin_packing(capacity,[B1,..,Bn],[w1,..,wn]) for each bin j, sum_Bi=j wi <= capacity

47. Bin-packing constraints • bin_packing(capacity,[B1,..,Bn],[w1,..,wn]) for each bin j, sum_Bi=j wi <= capacity special case of cummulative with task durations=1

48. Bin-packing constraints • bin_packing(capacity,[B1,..,Bn],[w1,..,wn]) for each bin j, sum_Bi=j wi <= capacity special case of cummulative with task durations=1 unlike normal bin-packing, does not minimize the number of open bins

49. Bin-packing constraints • bin_packing(capacity,[B1,..,Bn],[w1,..,wn]) for each bin j, sum_Bi=j wi <= capacity special case of cummulative with task durations=1! unlike normal bin-packing, does not minimize the number of open bins how could we do this?

50. Bin-packing constraints • bin_packing(capacity,[B1,..,Bn],[w1,..,wn]) for each bin j, sum_Bi=j wi <= capacity special case of cummulative with task durations=1! unlike normal bin-packing, does not minimize the number of open bins Bi=j implies Open_j=1 Minimize sum_j Open_j