global constraints toby walsh national ict australia and university of new south wales tw/global

57
Global Constraints Toby Walsh National ICT Australia and University of New South Wales www.cse.unsw.edu.au/~tw/global/

Upload: estefania-shutts

Post on 01-Apr-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Global Constraints

Toby WalshNational ICT Australia and

University of New South Waleswww.cse.unsw.edu.au/~tw/global/

Page 2: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Course outline● Introduction● All Different● Lex ordering● Value precedence● Complexity● GAC-Schema● Soft Global Constraints● Global Grammar Constraints● Roots Constraint● Range Constraint● Slide Constraint● Global Constraints on Sets

Page 3: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

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(1) cost at each node

down a branch

Page 4: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Motivation

● Many problems can be modelled by matrices of decision variables.

Page 5: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Motivation

● Many problems can be modelled by matrices of decision variables.

● E.g. Combinatorial Problems– Balanced Incomplete Block Design.

0 1 1 0 0 1 01 0 1 0 1 0 00 0 1 1 0 0 11 1 0 0 0 0 1 <7,7,3,3,1>0 0 0 0 1 1 11 0 0 1 0 1 00 1 0 1 1 0 0

Page 6: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Motivation

● Many problems can be modelled by matrices of decision variables.

● E.g. Configuration Problems:– Rack Configuration– Matrix is Xij iff jth card on ith rack

Page 7: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Motivation

● Many problems can be modelled by matrices of decision variables.

● E.g. Scheduling Problems:– Social Golfers– 32 golfers want to play in 8 foursomes each day of the

week– No two golfers shall meet twice in a foursome– Matrix is Pijk=1 iff player i plays in jth foursome on day

k

Page 8: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Motivation

● Many problems can be modelled by matrices of decision variables.

● E.g. Design Problems:– Steel Mill Slab Design– Slab[o,j] iff order o is on jth slab– IBM solved this problem for the largest steel maker in

Korea

Page 9: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Motivation

● Many problems can be modelled by matrices of decision variables.

● Frequently these matrices exhibit row and/or column symmetry.

Page 10: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

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.

Page 11: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Motivation

● An important class of symmetries in CP– matrices of decision variables– rows/columns represent indistinguishable objects, hence symmetric

● Rows and columns are subject to permutation

● An n X m matrix model with row and column symmetry has n! X 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

Page 12: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

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.

Page 13: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Symmetry

• Frequently occurs– Combinatorial problems like

covering arrays• Rows and columns can be

permuted

– Messy real world problems like nurse rostering

• Nurses with same skills can be swapped

• Tough for IP– Very active research area within

CP– Some effective techniques have

been developed

Page 14: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Modelling adds symmetry

• Divide 32 golfers into 8 foursomes so that each week they play with different players– Xijk = ith player in jth group in

kth week

• In this model, we can permute– players within group– groups – weeks

Representing a set like a foursome by 4 variables, introduces symmetries (their permutations)!

Page 15: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

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

Page 16: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Example

● Consider 2 identical bins:

BA

Page 17: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Example

● Consider 2 identical bins:

• We must pack 6 items: 3 41 652

BA

Page 18: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Example

● Here is one solution:

1 2

3

65

4

BA

Page 19: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Example

● Here is another:

BA

1

3

5

2

6

4

Page 20: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Example

● Is there any fundamental difference?

135

2

64a)

b)

A B

BA135

2

64

Page 21: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Example

● Consider a matrix model:

135

2

64a)

b)

A B

BA135

2

64

Page 22: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Example

● Consider a matrix model:

135

2

64a)

b)

A B

BA135

2

64

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

Page 23: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Example

● Consider a matrix model:

If we insist that row A lex row B,

we remove a) from the solution set.

b)

BA135

2

64

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

Page 24: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Example

● Notice that items 3 and 4 are identical.

b)

BA135

2

64

c)145

2

63

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 1 0 0 1

B 1 0 0 1 1 0

Page 25: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Example

● Notice that items 3 and 4 are identical.

b)

BA135

2

64

If we insist that col 3 lex col 4,

we remove c) from the solution set.

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 1 0 0 1

B 1 0 0 1 1 0

Page 26: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Lexicographic Ordering

• Used to order dictionaries

[A,B,C] ≤ lex [D,E,F]

– A<D or

– (A=D and B<E ) or

– (A=D and B=E and C<F) or

– (A=D and B=E and C=F)

Page 27: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

● Lexicographic ordering is total● Forcing the rows to be lexicographically ordered breaks all row

symmetry

Breaking Row (Column) Symmetry

A B C

D E F

G H I[A B C] lex [D E F] lex [G H I] [G H I] lex [D E F] lex [A B C]

lexicographic ordering anti-lexicographic ordering

Page 28: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

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!

Page 29: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

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

Page 30: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

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

01

01

10

01

10

10

swap the columnsswap row 1 and row 3

Page 31: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Special Cases

● All symmetry can be broken– When variables take distinct values

● Simply push largest value to a particular corner● Order 1st row and 1st col

– 0/1 variables, 1 occurs once in each row/col● Double LEX then leaves an unique solution

Page 32: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

GACLex

● A new family of global constraints.

Page 33: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

GACLex

● A new family of global constraints.

Non-binary constraint. Specialised propagator.

Page 34: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

GACLex

● A new family of global constraints.● Linear time complexity.

Page 35: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

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

2 9 8 7

lex

Page 36: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

How GACLex Works

x {2} {1,3,4} {2,3,4} {1} {3,4,5}

y {0,1,2} {1} {1,2,3} {0} {0,1,2}

Page 37: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

How GACLex Works

● Consider the following example.● We have two vectors of decision variables:

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.

Page 38: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

A Tale of Two Pointers

● We use two pointers, alpha and beta, to avoid repeatedly traversing the vectors

Page 39: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

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

Page 40: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

A Tale of Two Pointers

• alpha: index such that all variables at more significant indices are ground and equal.

x {2} {1,3,4} {2,3,4} {1} {3,4,5}

y {0,1,2} {1} {1,2,3} {0} {0,1,2}

Page 41: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

A Tale of Two Pointers

● We use two pointers, alpha and beta, to avoid repeatedly traversing the vectors.

• beta: most significant index from which the two vectors’ tails necessarily violate the constraint.

x {2} {1,3,4} {2,3,4} {1} {3,4,5}

y {0,1,2} {1} {1,2,3} {0} {0,1,2}

Page 42: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Pointer initialization

● alpha– Scan through vector from start– At most O(n) time

● beta– Scan through vector from end– At most O(n) time

Page 43: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Failure

● Inconsistent if beta 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.

Page 44: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

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.

Page 45: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

How GACLex Wroks

● We maintain alpha and beta as assignments made.

● When beta = alpha + 1 we enforce bounds consistency on: xalpha < 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.

Page 46: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

How GACLex Works

● We maintain alpha and beta as assignments made.

● When beta = alpha + 1 we enforce bounds consistency on: xalpha < yalpha

● When beta > alpha + 1 we enforce bounds consistency on: xalpha 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.

Page 47: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Complexity

● Initialisation: O(n)● Propagation:

• We enforce bounds consistency between at most n pairs of variables: xalpha < yαalpha or xalpha yαalpha.

• Cost: b. Overall cost: O(nb).

Page 48: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Why Have a Global LEX Constraint?

● Two alternatives– Arithmetic constraint– Logical decomposition

● Both limit problem size– And both can be slower!

● Both do less pruning than GAC(X0<lex X1 <lex ... <lex Xn)

Page 49: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Arithmetic Constraint

● GivenA=[a1,...,an] B=[b1,...,bn]taking values from {1,...d}

A ≤lex B iff (dn-1 a1 + ... + d0 an

) ≤ (dn-1 b1 + ... + d0 bn

) ● BC(≤) iff GAC(≤lex) ● When n and d are large, dn-1 is greater than the word size

of the computer.● This method is only feasible for small vectors/domain

size.

Page 50: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Logical Decompositions

● Or decompositionA ≤lex B iff (a1 < b1) Or(a1 = b1 And a2 < b2 )...(a1 = b1 And a2 = b2 ... an ≤ bn

)

● And decompositionA ≤lex B iff(a1 ≤ b1) And(a1 = b1 -> a2 ≤ b2 )...(a1 = b1 And a2 = b2 ... -> an ≤ bn

)

• Many solvers use FC– Less pruning than GAC

• GAC schema is expensive

• They are also cumbersome.

Page 51: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Results: BIBD

● Standard combinatorial problem.

0 0 0 0 1 1 1

0 0 1 1 0 0 1

0 1 0 1 0 1 0

0 1 1 0 1 0

0

1 0 0 1 1 0 0

1 0 1 0 0 1 0

1 1 0 0 0 0 1

• v rows.

• b columns.

• r 1s per row.

• k 1s per column.

• λ is scalar product between every pair of rows.

Symmetrical rows and columns

Page 52: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Results:BIBD

• Decomposition takes About 9 times longer on each of these instances.

Time(s)

1

10

100

1000

10000

1 10 100 1000 10000

GACLex

Decomposition

Page 53: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Results: Social Golfers

● Schedule a golf tournament of w weeks.● In each week, divide golfers into g groups, size s.● Every golfer plays once per week.● Every pair of golfers can meet at most once.● 3d 0/1 matrix model:

Groups

Weeks

PlayersPlayers, groups and weeks all symmetrical

Page 54: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Results: Social Golfers

Time(s)

0.1

1

10

100

1000

10000

0.1 1 10 100 1000 10000

GACLex

Decomposition

Decomposition takes between 10 and 56 times longer (at least) on these instances.

Page 55: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Value Symmetry

● Often values (as well as variables) are symmetric– E.g. Xijk = name of ith golfer, in jth group, in kth week– Values (names of golfer) can be permuted

● Value symmetry can be mapped to variable symmetry– Xijk = m maps to Yijkm = 1– Can now break this symmetry by LEX ordering m

dimension

Page 56: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Symmetry Breaking Constraints

● Where do they come from in general?– General method due to Crawford, Ginsberg and Luks

● Will break all symmetries● But may give exponential number of constraints

– Well known special cases● E.g. row & col symmetry● Crawford et al’s method gives exponential number of

constraints with such symmetries– Black art

Page 57: Global Constraints Toby Walsh National ICT Australia and University of New South Wales tw/global

Conclusion

● Identification of row and column symmetry● Lexicographic ordering constraints

– Double-lex– Value symmetry– Higher dimension

● Global constraints for lexicographic orderings.– Maintain GAC– Linear time complexity.– Decompositions carry a penalty in the amount or cost of

propagation.