Global%20Constraints - PowerPoint PPT Presentation

About This Presentation
Title:

Global%20Constraints

Description:

Global Constraints – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 63
Provided by: cseUn
Category:

less

Transcript and Presenter's Notes

Title: Global%20Constraints


1
Global Constraints
  • Toby Walsh
  • NICTA and University of New South Wales
  • www.cse.unsw.edu.au/tw

2
Quick advert
  • UNSW is in Sydney
  • Regularly voted in top 10 cities in World
  • UNSW is one of top universities in Australia
  • In top 100 universities in world
  • Talk to me about our PhD programme!
  • Also happy to have PhDs/PostDocs visit for
    weeks/months/years

3
Quick advert
  • UNSW is in Sydney
  • Regularly voted in top 10 cities in World
  • UNSW is one of top universities in Australia
  • In top 100 universities in world
  • Talk to me about our PhD programme!
  • Also happy to have PhDs/PostDocs visit for
    weeks/months/years
  • Attend CP/KR/ICAPS in Sept

4
Constraint programming
  • Constraint programming represents one of the
    closest approaches computer science has yet made
    to the Holy Grail of programming the user states
    the problem, the computer solves it.
  • Gene Freuder, Constraints, April 1997

5
Suduko
  • Puzzle
  • X11,X12,X13, X19,
  • X21,X22, X29,
  • ..
  • X91,X92, .X99
  • Puzzle 1..9
  • alldifferent(X11,..X19)
  • alldifferent(X21,..X29)
  • ..
  • alldifferent(X11,..X91)
  • ..
  • alldifferent(X11,..X33)
  • ..

6
Comparison with OR
  • CP
  • rich modelling language
  • many different global constraints
  • fast local inference on these global constraints
  • good for finding feasible and tightly constrained
    solutions
  • (I)LP
  • everything has to be a linear inequality
  • limited range of solution methods (simplex, ...)
  • good at proving optimality

7
Global constraints
  • Any non-binary constraint
  • AllDifferent
  • Nvalues
  • Element
  • Lex ordering
  • Stretch constraint
  • Sequence constraint
  • ...
  • Each comes with an efficient propagator ...

8
All Different
9
Golomb rulers
  • Mark ticks on a rule
  • Distance between any two ticks (not just
    neighbouring) is distinct
  • Special type of graceful graph
  • Applications
  • Radio-astronomy, crystallorgraphy, ...
  • Prob006 in CSPLib

10
Golomb rulers
  • Simple solution
  • Exponentially long ruler
  • Ticks at 0, 1, 3, 7, 15, 31, ...
  • Goal is to find minimal length ruler
  • Sequence of optimization problems
  • Is there a ruler of length m?
  • Is there a ruler of length m-1?
  • ...

11
Optimal Golomb rulers
  • Known for up to 23 ticks
  • Distributed internet project to find larger
  • 0,1
  • 0,1,3
  • 0,1,4,6
  • 0,1,4,9,11
  • 0,1,4,10,12,17
  • Solutions grow as approximately O(n2)

12
Golomb rulers as CSP
  • Variable Xi for each tick
  • Value is position
  • Auxiliary variable Dij for each inter-tick
    distance
  • DijXi-Xj
  • Two (global) constraints
  • X1ltX2lt..Xn
  • AllDifferent(D11,D12,D13,...)

13
Golomb ruler as CSP
  • Not yet achieved dream of declarative
    programming
  • Need to break symmetry of inverting ruler
  • D12lt Dn-1n
  • Add implied constraints
  • D12ltD13 ...
  • Pure declarative specifications not quite enough!

14
AllDifferent
  • AllDifferent(X1,..Xn) iff Xi/Xj for iltj
  • Useful in wide range of applications
  • Timetabling (exams with common student must occur
    at different times)
  • Production (each product must be produced at a
    different time)
  • ...
  • Can propagate just using binary inequalities
  • But this decomposition hurts propagation

15
AllDifferent
  • AllDifferent(X1,..Xn) iff Xi/Xj for iltj
  • Can propagate just using binary inequalities
  • But this decomposition hurts propagation
  • X1 in 1,2, X2 in 1,2, X3 in 1,2,3
  • X3 cannot be 1 or 2
  • How can we automate such reasoning?
  • How can we do this efficiently (less than O(n2)
    time)

16
AllDifferent
  • One of the oldest global constraints
  • In ALICE language Lauriere 78
  • Found in every constraint solver today
  • GAC algorithm based on matching theory due to
    Regin AAAI 94, runs in O(dn3/2)
  • BC algorithm using combinatorics due to Puget
    AAAI98, runs in O(nlogn)

17
BC on AllDifferent
  • Application of Hall's Theorem
  • Sometimes called the marriage theorem
  • Given k sets
  • Then there is an unique and distinct element in
    each set iff any union of j of the sets has at
    least j elements for 0ltjltk
  • E.g. S11,2, S21,2 but not S11,2,S21,2
    and S31,2

18
Hall's theorem
  • You wish to marry n men and women
  • Each woman declares who they are willing to marry
    (some set of men)
  • Each man will be happy with whoever is willing
    to marry them
  • Given any subset of j women, the number of men
    they are willing to marry must be j or more (thus
    this condition is necessary)
  • What is surprising is that it is also sufficient!

19
BC on AllDifferent
  • Hall Interval
  • Interval of values in which as many variables as
    domain values
  • E.g. X1 in 1,2,3, X2 in 1,2, X3 in 1,2,3
  • 3 variables in the interval 1..3
  • AllDifferent(X1,..Xn) is BC iff
  • Each interval, the number of vars it covers is
    less than or equal to the width of the interval
  • No variable outside a Hall Interval has a value
    within it

20
BC on AllDifferent
  • Consider X1 in 1,2, X2 in 1,2, X3 in 1,2,3

21
BC on AllDifferent
  • Consider X1 in 1,2, X2 in 1,2, X3 in 1,2,3
  • Then 1..2 is a Hall Interval covered by X1 and
    X2
  • X3 has values inside this Hall Interval
  • We can prune these and make AllDifferent BC

22
BC on AllDifferent
  • Naïve algorithm considers O(n2) intervals
  • Puget orders intervals
  • Ordering has O(nlogn) cost
  • Then can go through them in order

23
Beyond AllDifferent
  • NValues(X1,...,Xn,M) iff j
    XijM
  • AllDifferent is special case when Mn
  • Useful when values represent a resource
  • Minimize the number of resources used

24
Beyond AllDifferent
  • Global cardinality constraint
  • GCC(X1,..Xn,a1,..am,b1,...bm) iff
    aj lt i Xij lt bj for
    all j
  • In other words, j occurs between aj and bj times
  • Again useful when values represent a resource
  • You have at least one night shift but no more
    than four each week

25
Conclusions
  • AllDifferent is one of the oldest (and most
    useful) global constraints
  • Efficient propagators exist for achieving GAC and
    BC
  • When to choose BC over GAC?
  • Heuristic choice BC often best when many more
    values than variables, GAC when we are close to a
    permutation (number of varsnumber of values)

26
Lex ordering
  • Widely useful
  • Especially for symmetry breaking
  • Breaking row and column symmetry in matrix models
  • Available in most (all?) solvers
  • Good example of pointer based global constraint
  • Pointers save re-doing work
  • Good incremental behaviour
  • O(n) in general, but amortised O(n) cost down a
    branch

27
Motivation
  • Many problems can be modelled by matrices of
    decision variables.

28
Motivation
  • Many problems can be modelled by matrices of
    decision variables.
  • E.g. Combinatorial Problems
  • Balanced Incomplete Block Design.
  • Xi,j0 or 1
  • 0 1 1 0 0 1 0
  • 1 0 1 0 1 0 0
  • 0 0 1 1 0 0 1
  • 1 1 0 0 0 0 1 Parameters
    (7,7,3,3,1)
  • 0 0 0 0 1 1 1
  • 1 0 0 1 0 1 0
  • 0 1 0 1 1 0 0

0 1 1 0 0 1 0 1 0 1 0 1 0 0 0 0 1 1 0 0 1 1 1 0 0
0 0 1 0 0 0 0 1 1 1 1 0 0 1 0 1 0 0 1 0 1 1
0 0
29
Motivation
  • Many problems can be modelled by matrices of
    decision variables
  • Frequently these matrices exhibit row and/or
    column symmetry

30
Motivation
  • Many problems can be modelled by matrices of
    decision variables
  • Frequently these matrices exhibit row and/or
    column symmetry
  • We can permute the rows/columns in any
    (non)solution to obtain another (non)solution

31
Motivation
  • When rows and columns can be permuted
  • An n by m matrix model with row and column
    symmetry has
  • n! m! symmetries
  • grows super-exponentially
  • Too many symmetric search states
  • It can be very expensive to visit all the
    symmetric branches of a search tree

32
Motivation
  • Breaking symmetry is very important!
  • Breaking all row and column symmetries is
    difficult
  • No one has an effective way of dealing with all
    row and column symmetries.
  • Symmetry breaking methods have to deal with very
    large number of symmetries.
  • The effort required could easily be exponential.

33
Symmetry in CP
  • Add symmetry breaking constraints
  • Leave at least one solution
  • Eliminate some/all symmetric solutions
  • Modify search algorithm
  • Ignore symmetric parts of the search space
  • Adapt branching heuristic
  • To explore branches which are most likely not to
    be symmetric

34
Example
  • Consider 2 identical bins

B
A
35
Example
  • Consider 2 identical bins

B
A
  • We must pack 6 items

3
4
1
6
5
2
36
Example
  • Here is one solution

6
5
3
4
1
2
B
A
37
Example
  • Here is another

5
6
3
4
1
2
B
A
38
Example
  • Is there any fundamental difference?

5
6
a)
3
4
1
2
A
B
5
6
b)
3
4
1
2
B
A
39
Example
  • Consider a matrix model

1 2 3 4 5 6 A 1 0 1 0
1 0 B 0 1 0 1 0 1
5
6
a)
3
4
1
2
A
B
1 2 3 4 5 6 A 0 1 0 1
0 1 B 1 0 1 0 1 0
5
6
b)
3
4
1
2
B
A
40
Example
  • Consider a matrix model

1 2 3 4 5 6 A 1 0 1 0
1 0 B 0 1 0 1 0 1
1 2 3 4 5 6 A 0 1 0 1
0 1 B 1 0 1 0 1 0
5
6
b)
3
4
1
2
B
A
41
Example
  • Notice that items 3 and 4 are identical.

1 2 3 4 5 6 A 1 0 1 0
1 0 B 0 1 0 1 0 1
5
6
b)
3
4
1
2
B
A
1 2 3 4 5 6 A 0 1 1 0
0 1 B 1 0 0 1 1 0
5
6
c)
4
3
1
2
42
Example
  • Notice that items 3 and 4 are identical.

1 2 3 4 5 6 A 1 0 1 0
1 0 B 0 1 0 1 0 1
5
6
b)
3
4
1
2
B
A
1 2 3 4 5 6 A 0 1 1 0
0 1 B 1 0 0 1 1 0
43
Lexicographic Ordering
  • Used to order dictionaries
  • A,B,C lex D,E,F
  • AltD or
  • (AD and BltE ) or
  • (AD and BE and CltF) or
  • (AD and BE and CF)

44
Breaking Row (Column) Symmetry
  • Lexicographic ordering is total
  • Forcing the rows to be lexicographically ordered
    breaks all row symmetry

lexicographic ordering
A B C
D E F
G H I
A B C ? lex D E F ? lex G H I
anti-lexicographic ordering
G H I
45
Breaking Row and Column Symmetries
  • Breaking both row and column symmetries is
    difficult
  • Rows and columns intersect
  • After constraining the rows to be
    lexicographically ordered
  • we distinguish the columns
  • the columns are not symmetric
    anymore!

46
Good News ?
  • Each symmetry class of assignments has at least
    one element where both the rows and the columns
    are lexicographically ordered
  • But there may be no element with rows lex ordered
    and columns anti-lex ordered
  • To break row and column symmetries, we can insist
    that the rows and columns are both
    lexicographically ordered (double-lex)
  • Extends to higher dimensions

47
Bad News ?
  • A symmetry class of assignments may have more
    than one element where both the rows and the
    columns are lexicographically ordered
  • Double-lex does not break all row and column
    symmetries

1
0
1
0
1
0
0
1
swap the columns swap row 1 and row 3
0
1
0
1
48
GACLex
  • A new family of global constraints.

49
GACLex
  • A new family of global constraints.

Non-binary constraint. Specialised propagator.
50
GACLex
  • A new family of global constraints
  • Linear time complexity

51
GACLex
  • A new family of global constraints
  • Linear time complexity
  • Ensures that a pair of vectors of variables are
    lexicographically ordered.

0 1 4 2
? lex
2 9 8 7
52
How GACLex Works
  • Consider the following example

x 2 1,3,4 2,3,4 1 3,4,5
y 0,1,2 1 1,2,3 0 0,1,2
  • We want to enforce GAC on x ?lex y.

53
A Tale of Two Pointers
  • We use two pointers, alpha and beta, to avoid
    repeatedly traversing the vectors

54
A Tale of Two Pointers
x 2 1,3,4 2,3,4 1 3,4,5
y 0,1,2 1 1,2,3 0 0,1,2
Most significant index
Alpha all variables at more significant indices
are ground and equal
55
A Tale of Two Pointers
x 2 1,3,4 2,3,4 1 3,4,5
y 0,1,2 1 1,2,3 0 0,1,2
  • beta most significant index from which the two
    vectors tails necessarily violate the constraint.

56
Pointer initialization
  • alpha
  • Scan through vector from start
  • At most O(n) time
  • beta
  • Scan through vector from end
  • At most O(n) time

57
Failure
Inconsistent if beta lt alpha.
  • alpha index such that all variables at more
    significant indices are ground and equal.
  • beta most significant index from which the two
    vectors tails necessarily violate the constraint.

58
How GACLex Works
We maintain alpha and beta as assignments made.
  • alpha index such that all variables at more
    significant indices are ground and equal.
  • beta most significant index from which the two
    vectors tails necessarily violate the constraint.

59
How GACLex Wroks
We maintain alpha and beta as assignments
made. When beta alpha 1 we enforce bounds
consistency on xalpha lt yalpha
  • alpha index such that all variables at more
    significant indices are ground and equal.
  • beta most significant index from which the two
    vectors tails necessarily violate the constraint.

60
How GACLex Works
We maintain alpha and beta as assignments
made. When beta alpha 1 we enforce bounds
consistency on xalpha lt yalpha When beta gt alpha
1 we enforce bounds consistency on xalpha lt
yalpha
  • alpha index such that all variables at more
    significant indices are ground and equal.
  • beta most significant index from which the two
    vectors tails necessarily violate the constraint.

61
Complexity
  • Initialisation O(n)
  • Propagation
  • We enforce bounds consistency between at most n
    pairs of variables xalpha lt yalpha or xalpha ?
    yalpha.
  • Cost b. Overall cost O(nb).
  • Complexity can be amortized down branch of search
    tree
  • alpha and beta move at most O(n) steps

62
Conclusions
  • Global constraints
  • One of the special features of constraint
    programming
  • Interesting meeting point for algorithms,
    combinatorics, computational complexity, formal
    languages,
Write a Comment
User Comments (0)
About PowerShow.com