30
Symmetry Breaking Constraints in Constraint Programming Barbara Smith

Symmetry Breaking Constraints in Constraint Programming

  • Upload
    lore

  • View
    78

  • Download
    0

Embed Size (px)

DESCRIPTION

Symmetry Breaking Constraints in Constraint Programming. Barbara Smith. Outline. Constraint satisfaction problems Symmetry in CSPs Symmetry breaking approaches Symmetry breaking constraints Lex leader constraints Partial symmetry breaking Matrix models. - PowerPoint PPT Presentation

Citation preview

Page 1: Symmetry Breaking Constraints in Constraint Programming

Symmetry Breaking Constraints in Constraint Programming

Barbara Smith

Page 2: Symmetry Breaking Constraints in Constraint Programming

Outline

• Constraint satisfaction problems

• Symmetry in CSPs

• Symmetry breaking approaches

• Symmetry breaking constraints– Lex leader constraints

• Partial symmetry breaking– Matrix models

Oberwolfach August 2010 2

Page 3: Symmetry Breaking Constraints in Constraint Programming

Introduction to Constraint Satisfaction Problems

• A CSP consists of:– A set of variables – Each with a finite set of possible values, its domain– A set of constraints: each constraint acts on a subset of the variables and

restricts the possible assignments to those variables

• Formally, a constraint is a subset of the possible assignments to the variables in its scope– In practice, constraints are usually stated intensionally, e.g. x < y

• A solution to a CSP is an assignment of a value from its domain to every variable, that satisfies all the constraints

• Optimization

Oberwolfach August 2010 3

Page 4: Symmetry Breaking Constraints in Constraint Programming

Constraint Examples

• ax < by + c– arithmetic constraints involving variables and constants

• either x1 < y1 or x2 < y2 – logical constraints can express the logic of the problem directly

• x = (y < z) – reified constraints

• i xi jyi ≥ dj (xij , yi , dj constants or variables)– constraints on arrays of variables

• allDifferent(x1, x2, …, xn)• (the number of variables in x1, x2, …, xn with value c) < a

Oberwolfach August 2010 4

Page 5: Symmetry Breaking Constraints in Constraint Programming

Solving CSPs• Find a solution by combining systematic

search and constraint propagation• At each search node, choose a variable not yet

assigned (var) and assign it a value from its domain (val)

• Create a choice between var = val and var ≠ val

• On the left branch, propagate the constraint var = val – domain pruning: remove values from the domains of

future variables that are no longer valid– consider all problem constraints in turn

• If any future variable has an empty domain, backtrack to try the choice var ≠ val– or if a solution has been found but we want all of

them

Oberwolfach August 2010 5

A = set of assignmentsmade so far

var = val var ≠ val

Page 6: Symmetry Breaking Constraints in Constraint Programming

Symmetry

• A (constraint) symmetry of a CSP P is a permutation of the variable-value pairs that preserves (the constraints of) P– and hence also preserves the solutions of P

• A symmetry σ maps any variable-value pair (xi, j) to another, σ(xi, j)

• A variable symmetry affects only the variables, so that (xi, j) is mapped to (xσ(i) , j) – if the variables are x1, x2 …, xn, σ permutes the index set {1,2,

…,n}

• Here, I assume that we know the symmetry of the CSP (through inspection, intuition, inspiration, …)

Oberwolfach August 2010 6

Page 7: Symmetry Breaking Constraints in Constraint Programming

Symmetry Breaking Approaches

• reformulate the problem (symmetry avoidance?)

• modify the search algorithm (dynamic symmetry breaking) – e.g. add constraints on backtracking to a choice

point to rule out symmetric equivalents in the future

– often uses computational group theory

• add constraints to the CSP before search

Oberwolfach August 2010 7

Page 8: Symmetry Breaking Constraints in Constraint Programming

Symmetry Breaking During Search (SBDS)

• A symmetry can be eliminated by describing its effect on a variable-value assignment

• e.g. for n-queens, we can completely eliminate all symmetry by describing the 7 symmetries

– we can ignore the 8th symmetry (identity)• Variable r[i] represents the queen on row i • its values represent the columns (1 to n)

Oberwolfach August 2010 8

x(r[i]=j) → r[n−i+1]=j

y(r[i]=j) → r[i]=n−j+1

d1(r[i]=j) → r[j]=i

d2(r[i]=j) → r[n−j+1]=n−i+i

r90(r[i]=j) → r[j] = n−i+1

r180(r[i]=j) → r[n−i+1]=n−j+1

r270(r[i]=j) → r[n−j+1]=i

Page 9: Symmetry Breaking Constraints in Constraint Programming

Symmetry Breaking During Search (SBDS)

Oberwolfach August 2010 9

A = set of assignmentsmade so far

var = val var ≠ val

+ g(var!= val) for any unbroken symmetry g, i.e. if g(A) is (or will be) true

Page 10: Symmetry Breaking Constraints in Constraint Programming

SBDS Example – 8 queens

Oberwolfach August 2010 10

r[1]=2

x: r[8]=2y: r[1]=7d1: r[2]=1d2: r[7]=8r90: r[2]=8r180: r[8]=7r270: r[7]=1

xxxx

r[2]=4 r[2] ≠ 4

r90: if r[2]=8 then r[4] ≠ 7 r180: if r[8]=7 then r[7] ≠ 5 r270: if r[7]=1 then r[5] ≠ 2

Page 11: Symmetry Breaking Constraints in Constraint Programming

SBDS Pros and Cons

• For complete symmetry breaking, SBDS needs a separate function for each symmetry

– The symmetry group can be enormous

• In a few special cases, complete symmetry breaking can be achieved with a small set of SBDS functions

– e.g. if the variables represent n interchangeable objects, we can eliminate the symmetry with SBDS functions for the transpositions of pairs of objects, rather than all n! elements of the group

• Otherwise, we can specify a subset of the symmetry functions and get partial symmetry breaking

– Still useful to reduce search

• Or we can link SBDS to something like GAP

Oberwolfach August 2010 11

Page 12: Symmetry Breaking Constraints in Constraint Programming

Symmetry Breaking Constraints

• Add constraints to the CSP that will be satisfied by (ideally) only one assignment in any equivalence class

• Creates a new CSP, with fewer solutions• Disadvantages:

– Dangerous, unless done systematically– Can conflict with the search order

• Advantage:– Constraints are useful & can lead to domain pruning– Anyone can do it

Oberwolfach August 2010 12

Page 13: Symmetry Breaking Constraints in Constraint Programming

Lex-Leader Constraints

• Crawford, Ginsberg, Luks & Roy (KR96) introduced a symmetry-breaking method (in SAT) that is easily adapted to variable symmetries

• Choose an order of the variables, say x1, x2 …, xn

– and the values, but here we assume that domains are integer

• Defines a lexicographic order on complete assignments to the variables

• Add constraints to allow only the smallest element in each symmetry equivalence class, the lex-leader– or the largest

Oberwolfach August 2010 13

Page 14: Symmetry Breaking Constraints in Constraint Programming

Lex-Leader Constraints (II)

• For each variable symmetry σ, add a constraint:– the assignment to x1, x2 …, xn is lexicographically smaller than the

assignment to xσ(1) , xσ(2) ,…, xσ(n) , i.e.

– x1 ≤ xσ(1) ;

– if x1 = xσ(1) then x2 ≤ xσ(2) ;

– if x1 = xσ(1) and x2 = xσ(2) then x3 ≤ xσ(3) ;…..

– if xi = xσ(i) for 1 ≤ i < n then xn ≤ xσ(n)

– x1 x2 … xn ≤lex xσ(1) xσ(2) … xσ(n)

• Frisch et al. (CP02, AIJ 2006) give a propagator for the ≤lex constraint – Linear in the length of the constraint

Oberwolfach August 2010 14

Page 15: Symmetry Breaking Constraints in Constraint Programming

Lex Constraint Example

• Suppose a CSP has variables x1, x2 …, x6

• A variable symmetry σ is a permutation of {1,2,3,4,5,6}, say (1 3) (2 6 5)

• Choose the variable order x1, x2 …, x6

• The lex-leader constraint for σ is:– x1 x2 … x6 ≤lex xσ(1) xσ(2) … xσ(6)

– x1 x2 x3 x4 x5 x6 ≤lex x3 x6 x1 x4 x2 x5

– x1 x2 x5 ≤lex x3 x6 x2 Oberwolfach August 2010 15

Page 16: Symmetry Breaking Constraints in Constraint Programming

Simplifying Lex-Leader Constraints

• The lex-leader constraint for σ can be reduced (Flener & Pearson, SymCon02)– If a variable is not affected by σ, remove it – If σ contains a cycle of variable indices, remove

the last pair of variables from this cycle – NB If σ contains only 2-cycles, the reduced lex-

leader constraint has one pair of variables for each 2-cycle

• Reduction rules for sets of lex-leader constraints as well

Oberwolfach August 2010 16

Page 17: Symmetry Breaking Constraints in Constraint Programming

Consistency and Completeness

• If we add a lex-leader constraint for every symmetry of the CSP, we are guaranteed:– Consistency: at least one solution in every equivalence

class of solutions– Completeness: at most one solution in every equivalence

class• But if the symmetry group is too big, we can add

some lex-leader constraints - partial symmetry breaking – May have to sacrifice completeness – Sometimes, a small set of lex-leader constraints does give

complete symmetry breaking, e.g. if variables x1 , x2 , … , xn are interchangeable, add x1 ≤ x2 ≤ … ≤ xn

Oberwolfach August 2010 17

Page 18: Symmetry Breaking Constraints in Constraint Programming

Matrix Models

• Many problems can be modelled as CSPs with a matrix of variables

• e.g. the covering array problem– In a b × 5 array, every subset of 3

columns must contain every combination of 0s and 1s

– Minimize b

• The rows and columns can be permuted

• A typical case for partial symmetry breaking

0 0 0 0 0

0 0 0 1 1

0 0 1 0 1

0 1 0 0 1

0 1 1 1 0

1 0 0 0 1

1 0 1 1 0

1 1 0 1 0

1 1 1 0 0

1 1 1 1 1

Oberwolfach August 2010 18

Page 19: Symmetry Breaking Constraints in Constraint Programming

Row and Column Symmetries

• For an m × n matrix with row and column symmetry there are m! n! symmetries

• Too many to introduce a ≤lex constraint for each one

• A practical approach: introduce ≤lex constraints for some of the symmetries

• Which ones?

• Need to strike a balance between– Breaking more symmetry → reducing search

– Adding more constraints → increasing propagation effort

Oberwolfach August 2010 19

Page 20: Symmetry Breaking Constraints in Constraint Programming

Double Lex Ordering

• Choose the symmetries that swap adjacent rows or adjacent columns

• Choose row-wise variable order

x11 … x1j x1,j+1 … x1n

… … … … … …

xi1 … xij xi,j+1 … xin

xi+1,1 … xi+1,j xi+1,j+1 … xi+1,n

… … … … … …

xn1 … xnj xn,j+1 … xnn

Oberwolfach August 2010 20

Page 21: Symmetry Breaking Constraints in Constraint Programming

Double Lex Ordering

• Choose the symmetries that swap adjacent rows or adjacent columns

• Choose row-wise variable order

• Swap rows i and i+1:

• xi1…xij xi,j+1 …xin ≤lex xi+1,1…xi+1,j xi+1,j+1…xi+1,n

• i.e. row i ≤lex row i+1

x11 … x1j x1,j+1 … x1n

… … … … … …

xi1 … xij xi,j+1 … xin

xi+1,1 … xi+1,j xi+1,j+1 … xi+1,n

… … … … … …

xn1 … xnj xn,j+1 … xnn

Oberwolfach August 2010 21

Page 22: Symmetry Breaking Constraints in Constraint Programming

Double Lex Ordering

• Choose the symmetries that swap adjacent rows or adjacent columns

• Choose row-wise variable order

• Swap columns j and j+1:

• x1j…xij xi+1,j… xnj ≤lex x1,j+1 … xi,j+1 xi+1,j+1… xn,j+1

• i.e. column j ≤lex column j+1

x11 … x1j x1,j+1 … x1n

… … … … … …

xi1 … xij xi,j+1 … xin

xi+1,1 … xi+1,j xi+1,j+1 … xi+1,n

… … … … … …

xn1 … xnj xn,j+1 … xnn

Oberwolfach August 2010 22

Page 23: Symmetry Breaking Constraints in Constraint Programming

Double Lex Ordering

• i.e. the rows must be in increasing lexicographic order and so must the columns

• Lex order is transitive, so constraints from the symmetries that swap non-adjacent rows or columns would be redundant – An example of reducing a set of constraints

• Double-lex (lex2) constraints are commonly used in matrix models with row & column symmetry

• They break row and column symmetry separately, but not symmetries that permute both rows and columns

Oberwolfach August 2010 23

Page 24: Symmetry Breaking Constraints in Constraint Programming

Lex-Leader Constraints & Partial Symmetry Breaking

• Given the symmetry group of a CSP, or a subset of the symmetries…

• …and a variable order…

• …we can construct the lex-leader constraints systematically

• e.g. double–lex constraints for matrix models with row & column symmetry are constructed from– The symmetries that swap adjacent rows or adjacent columns

– Row-wise variable order

Oberwolfach August 2010 24

Page 25: Symmetry Breaking Constraints in Constraint Programming

Breaking More Symmetry in Matrices

• Next step: consider symmetries that combine a row permutation and a column permutation

• Which ones? Will it be quicker?

• Symmetries that swap pairs of variables give compact lex-leader constraints

• swapNext: the set of symmetries that swap a pair of adjacent rows and a pair of adjacent columns– mn − 1 constraints for an m × n matrix

– each with m+n − 2 pairs of variables

• swapAny: symmetries that swap any pair of rows and any pair of columns– O(m2n2) constraints

Oberwolfach August 2010 25

Page 26: Symmetry Breaking Constraints in Constraint Programming

Example: Covering Arrays• In a b × k array, every subset of 3 columns must contain

every combination of 0s and 1s– Minimize b

– Try increasing values of b until there is a solution

lex2 swapNext swapAny

k b bt sec. bt sec. bt sec.

10 11 699 0.2 616 0.2 535 1.2

10 12 2782 0.9 2042 0.8 1461 3.9

11 12 2788 1.3 2043 1.0 1462 6.1

12 12 5991 3.8 4398 2.8 3381 20.5

12 13 187470 157 77383 61.5 >300Oberwolfach August 2010 26

Page 27: Symmetry Breaking Constraints in Constraint Programming

Are they worthwhile?

• Compared to lex2 :– Breaking the swapNext and swapAny symmetries

can reduce search by a lot

– Can reduce the run-time, if matrices are not too large

• Maybe we can be more selective and choose a subset of the swapAny symmetries?

Oberwolfach August 2010 27

Page 28: Symmetry Breaking Constraints in Constraint Programming

Variable Order

• To construct a set of lex-leader constraints, we have to choose a variable order

• With a complete set of lex-leader constraints, we get exactly one solution from every equivalence class

• With a partial set, we can get more than one• How many more?

– It depends on chosen symmetries– …and on the variable order

Oberwolfach August 2010 28

Page 29: Symmetry Breaking Constraints in Constraint Programming

Example

• Find symmetrically distinct n × n binary matrices• When n = 4, there are 317• Use lex2 constraints

– Symmetries swap a pair of adjacent rows or adjacent columns, row-wise variable order

– → 650 matrices

• Use same symmetries, a different variable order– same number of lex-leader constraints, same size– → 10,354 matrices

• Changing the variable order can give less (or more) symmetry-breaking

Oberwolfach August 2010 29

Page 30: Symmetry Breaking Constraints in Constraint Programming

Conclusions

• Adding constraints to the CSP is a common way to reduce or eliminate symmetry

• Almost all symmetry breaking constraints are lex-leader constraints

• If we cannot break all the symmetry, there are choices to be made– Which symmetries to break– Variable order – Lex-smallest v. lex-largest

• All can affect the number of solutions to the new CSP– Hence how close we come to complete symmetry breaking

• Needs more work to understand these choices

Oberwolfach August 2010 30

THE END