Symmetry Breaking Constraints in Constraint Programming

advertisement
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
2
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
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
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
–
–
•
A = set of assignments
made so far
var = val
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
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
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
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
r90(r[i]=j) → r[j] = n−i+1
y(r[i]=j) → r[i]=n−j+1
r180(r[i]=j) → r[n−i+1]=n−j+1
d1(r[i]=j) → r[j]=i
r270(r[i]=j) → r[n−j+1]=i
d2(r[i]=j) → r[n−j+1]=n−i+i
Oberwolfach August 2010
8
Symmetry Breaking During Search
(SBDS)
A = set of assignments
made so far
var = val
var ≠ val
+ g(var!= val) for any unbroken
symmetry g, i.e. if g(A) is
(or will be) true
Oberwolfach August 2010
9
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
r[1]=2
r[2]=4
x
x
x
x
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
Oberwolfach August 2010
10
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
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
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
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
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
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 lexleader constraint has one pair of variables for each
2-cycle
• Reduction rules for sets of lex-leader
constraints as well
Oberwolfach August 2010
16
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
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
0
0
0
0
0
0
0
1
0
1
0
0
0
1
0
1
1
0
1
0
1
0
0
0
1
0
1
1
0
1
1
1
1
0
1
1
1
0
1
1
1
0
0
0
0
1
1
1
1
1
18
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
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
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
x11
… x1j
x1,j+1
… x1n
…
……
…
… …
xi1
… xij
xi,j+1
… xin
…
……
…
… …
• i.e. row i ≤lex row i+1
xn1
… xnj
xn,j+1
… xnn
xi+1,1 … xi+1,j xi+1,j+1 … xi+1,n
Oberwolfach August 2010
21
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
x11
… x1j
x1,j+1
… x1n
…
……
…
… …
xi1
… xij
xi,j+1
… xin
…
……
…
… …
• i.e. column j ≤lex column
j+1
xn1
… xnj
xn,j+1
… xnn
xi+1,1 … xi+1,j xi+1,j+1 … xi+1,n
Oberwolfach August 2010
22
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
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
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
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
bt
sec.
699 0.2
k
b
10
10
11
12
12
11
12
2782
12
2788
12
5991
13 187470
swapNext
swapAny
bt
sec.
616 0.2
bt
sec.
535 1.2
0.9
1.3
3.8
2042 0.8
2043 1.0
4398 2.8
157
77383 61.5
Oberwolfach August 2010
1461 3.9
1462 6.1
3381 20.5
>300
26
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
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
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, rowwise 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) symmetrybreaking
Oberwolfach August 2010
29
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
30
Download