300 likes | 587 Views
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.
E N D
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 Oberwolfach August 2010
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
Constraint Examples • ax < by + c • arithmetic constraints involving variables and constants • either x1 < y1or x2 < y2 • logical constraints can express the logic of the problem directly • x = (y < z) • reified constraints • ixi jyi≥ dj(xij , yi , djconstants or variables) • constraints on arrays of variables • allDifferent(x1, x2, …, xn) • (the number of variables in x1, x2, …, xnwith value c) < a Oberwolfach August 2010
A = set of assignments made so far var = val var ≠ val 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 constraintvar = 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
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
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
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) 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 Oberwolfach August 2010
A = set of assignments made so far var = val var ≠ val Symmetry Breaking During Search (SBDS) + g(var!= val) for any unbroken symmetry g, i.e. if g(A) is (or will be) true Oberwolfach August 2010
r[2]=4 r[2] ≠ 4 SBDS Example – 8 queens x: r[8]=2 y: r[1]=7 d1: r[2]=1 d2: r[7]=8 r90: r[2]=8 r180: r[8]=7 r270: r[7]=1 x x x x r[1]=2 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 Oberwolfach August 2010
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
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
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
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≤lexxσ(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
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≤lexxσ(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
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
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
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 Oberwolfach August 2010
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
Double Lex Ordering • Choose the symmetries that swap adjacent rows or adjacent columns • Choose row-wise variable order Oberwolfach August 2010
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 ≤lexxi+1,1…xi+1,j xi+1,j+1…xi+1,n • i.e. row i≤lex row i+1 Oberwolfach August 2010
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 ≤lexx1,j+1 … xi,j+1xi+1,j+1… xn,j+1 • i.e. column j ≤lex column j+1 Oberwolfach August 2010
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
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
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
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 Oberwolfach August 2010
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
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
Example • Find symmetrically distinct n × n binary matrices • When n = 4, there are 317 • Use lex2constraints • 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
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 THE END Oberwolfach August 2010