Download presentation
Presentation is loading. Please wait.
Published byJasmin York Modified over 9 years ago
1
Pairwise Cardinality Networks Michael Codish and Moshe Zazon-Ivry Department of Computer Science B en-Gurion University
2
Cardinality constraints in a nutshell Satisfiability problems of the form: - conjunction of clauses - conjunction of constraints of the form is one of Typically Applications: optimization problems, Max-Sat, scheduling problems, and more. How to solve? Dedicated solvers (SMT solvers) Sat encoding BDD-like structure Sorting networks (unary ) Networks of adders (binary)
3
Focus for this talk x1x1 x2x2 x3x3 x4x4 x8x8 y1y1 y2y2 y3y3 Sorter 0 Encoding Cardinality Constraints to SAT, using sorting networks MiniSAT+, Barcelogic (and others) adapt this approach applying Batcher's Odd Even Sorting Network (from the 60’s) We propose an alternative choice of Sorting Network InputOutput x5x5 x6x6 x7x7 y5y5 y6y6 y7y7 y8y8
4
Outline of the talk Sorting networks Batcher’s Odd-Even (OE) Network An Alternative - Parberry's Pairwise (PW) Network Why an Alternative (I) - constraint propagation Understanding OE vs. PW Why an Alternative (II) - partial evaluation Conclusion
5
Sorting networks A Comparator is a device with two inputs, a and b, and two outputs, c and d comparator a b c=max(a,b) d=min(a,b) A Sorting network is a composition of wires and comparators that sorts its inputs b1b1 a1a1 a2a2 b2b2 b3b3 a3a3 a4a4 b4b4
6
Sorting networks There are “handcrafted” sorting networks And there are sorting networks based on your favorite sorting algorithm x1x1 x2x2 x3x3 x4x4 x8x8 y1y1 y2y2 y3y3 x5x5 x6x6 x7x7 y5y5 y6y6 y7y7 y8y8 x9x9 y9y9 Custom sorting network, n=9 x1x1 x2x2 x3x3 x4x4 y1y1 y2y2 y3y3 x5x5 x6x6 y5y5 y6y6 y4y4 y4y4 “Bubble sort” network
7
Sat encoding - comparators The SAT encoding of a comparator comparator(a, b, c, d) is: c d a b
8
Sat encoding – sorting networks b1b1 a1a1 t1t1 t2t2 t3t3 t4t4 t6t6 t5t5 a2a2 a3a3 a4a4 b2b2 b3b3 b4b4 The SAT encoding of a sorting network is the conjunction of the encodings of its comparators.
9
Sat encoding – cardinality constraints x1x1 x2x2 x3x3 x4x4 x5x5 x6x6 x7x7 x8x8 y1y1 y2y2 y3y3 0 Sorter(8) 0 0 0 0 Given a cardinality constraint x 1 + x 2 +…+ x n < k Set the k’th output variable to zero.
10
x1x1 x2x2 x3x3 x4x4 x5x5 x6x6 x7x7 x8x8 y1y1 y2y2 y3y3 y4y4 y5y5 y6y6 y7y7 y8y8 Sorter(n) The odd-even (OE) sorting network Sorter(n/2) OE-Merger(n) Sorter(n/4 ) OE- Merger(n/2) Sorter(n/4 )
11
OE-Merger(4) It’s all in the (OE) merger x1x1 x2x2 x3x3 x4x4 x5x5 x6x6 x7x7 x8x8 y1y1 y2y2 y3y3 y5y5 y6y6 y7y7 y8y8 y4y4 Given two sorted input sequences sorted Merge the odd input sequences Merge the even input sequences OE Merger(8) OE-Merger(4)
12
It’s all in the (OE) merger x1x1 x2x2 x3x3 x4x4 x5x5 x6x6 x7x7 x8x8 y1y1 y2y2 y3y3 y5y5 y6y6 y7y7 y8y8 y4y4 Given two sorted input sequences sorted Merge the odd input sequences Merge the even input sequences Combine the outputs into a sorted output OE-Merger(4)
13
And Then There Was … Ian Parberry devised the pairwise (PW) sorting network in 1992 Ian Parberry It has the exact same size & depth as the OE sorting network, but it is not isomorphic,… “The value of the pairwise sorting network is not that it is superior to the odd-even sorting network in any sense, but that it is the first serious rival to appear in over 20 years”
14
The pairwise sorting network x1x1 x2x2 x3x3 x4x4 x5x5 x6x6 x7x7 x8x8 y1y1 y2y2 y3y3 y4y4 y5y5 y6y6 y7y7 y8y8 A pairwise split is placed before the recursive calls and divides the network into “upper” and “lower” sub networks. “upper” Sorter(4) “upper” Sorter(4) “lower” Sorter(4) “lower” Sorter(4) OE-Merger(8) The inputs to the merger from the “upper” network have more (or equal) ones than those from the “lower” network. a1a1 a2a2 a3a3 a4a4 b1b1 b2b2 b3b3 b4b4 Starting from the OE sorting network This property enables Parberry to simplify the specification of the merger aiai bibi Splitter(8) PW-Merger(8)
15
And More! When the k’th merger output is set to zero, then the k/2 ‘th output from the “lower“ network is also set to zero. “upper” Sorter(n/2) “upper” Sorter(n/2) “lower” Sorter(n/2) “lower” Sorter(n/2) PW-Merger(n) Splitter(n) k 0 0 Constraint propagation k/2 Because
16
The pairwise (PW) sorting network Parberry’s sorting network unfolds to a network of splitters followed by simplified mergers Sorter(n/2) PW-Merger(n) Splitter(n)
17
What is the pairwise merger? x1x1 x2x2 x3x3 x4x4 y1y1 y2y2 y3y3 x5x5 x6x6 x7x7 y5y5 y6y6 y7y7 y4y4 x9x9 x 10 x 11 x 12 y9y9 y 10 y 11 x 13 x 14 x 15 y 13 y 14 y 15 y 12 x8x8 x 16 y8y8 y 16 The pairwise merger is constructed by layers of comparators Each layer reduces the “amplitude” of the sequence by half Check the Parberry paper, it’s a bit technical
18
Our take on the pairwise merger We observe that the oe-merger is exactly the composition of a splitter and a pw-merger Sorter(n/2) PW-Merger(n) Splitter(n) Sorter(n/2) OE- Merger(n) Splitter PW-Merger(n) Sorter(n/2) OE-Merger(n)
19
PW vs. OE sorting network OE-Sorting Network x1x1 x2x2 x3x3 x4x4 x5x5 x6x6 x7x7 x8x8 y1y1 y2y2 y3y3 y4y4 y5y5 y6y6 y7y7 y8y8 PW-Sorting Network x1x1 x2x2 x3x3 x4x4 x5x5 x6x6 x7x7 x8x8 y1y1 y2y2 y3y3 y4y4 y5y5 y6y6 y7y7 y8y8 Both sorting networks are composed from the same components In the PW network splitters precede pw mergers. In the OE network splitters and pw mergers alternate
20
Pairwise Cardinality Network c=max(a,b) d=min(a,b) a b 0 Advance knowledge of comparator’s input/output facilitates partial evaluation Comparators may become obsolete 0 Splitters before mergers gives more partial evaluation
21
x1x1 x2x2 x3x3 x4x4 y1y1 y2y2 y3y3 x5x5 x6x6 x7x7 x9x9 x 10 x 11 x 12 x 13 x 14 x 15 x8x8 x 16 0 0 0 0 0 0 0 0 0 0 0 0 0 Partial evaluation propagates through the network. Pairwise Cardinality Network 0 0 0 0 0 0 0 0 0 0 0 Sorter(8) Splitter(16) Sorter(8) Sorter(4) Splitter(8) PW-Merger(8) 0 0 0 0 k=4 k=2 k=1 The simplified network is of size. It can be constructed directly.
22
Comapring potential for P.E. PW cardinality network n=128,k=8 OE cardinality network n=128,k=8 massive reduction of comparators in the “lower” halves
23
Pairwise Cardinality Network Number of comparators after partial evaluation Before p.e. In the worst case no big difference.
24
Experiments ongoing... In the cardinality matrix problem the sum of each row and column is restricted between k 1 and k 2 0 00 0 0 0 0 0 0 0 0 00 1 1 1 1 1 11 1 1 1 11 Boolean Matrix M n=5, k 1 =1 & k 2 =4 3= =2=2
25
Experiments For a Boolean Matrix with n=100 Cardinality Network proposed by Asin etal [1]
26
Conclusion Propose cardinality networks based on pairwise sorting networks instead of odd-even networks Better constraint propagation Better partial evaluation Improve understanding on the relation between pairwise and odd-even networ ks Pairwise Networks are better for cardinality constraints and should be considered in tools (MiniSAT+, etc).
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.