27
Pairwise Cardinality Networks Michael Codish and Moshe Zazon-Ivry Department of Computer Science Ben-Gurion University

Pairwise Cardinality Networks Michael Codish and Moshe Zazon-Ivry

  • Upload
    zalman

  • View
    22

  • Download
    0

Embed Size (px)

DESCRIPTION

Pairwise Cardinality Networks Michael Codish and Moshe Zazon-Ivry Department of Computer Science B en-Gurion University. Cardinality constraints in a nutshell. Satisfiability problems of the form: - conjunction of clauses - conjunction of constraints of the form - PowerPoint PPT Presentation

Citation preview

Page 1: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

Pairwise Cardinality Networks

Michael Codish and Moshe Zazon-IvryDepartment of Computer Science

Ben-Gurion University

Page 2: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

Cardinality constraints in a nutshellSatisfiability 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)

kx

n

ii

1

nk ,,,,

Page 3: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

Focus for this talk

x1x2x3x4

x8

y1y2y3

Sorter 0

Encoding Cardinality Constraints to SAT, using sorting networksMiniSAT+, 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

Input Output

x5x6x7

y5y6y7y8

48

1

i

ix

Page 4: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

Outline of the talkSorting networksBatcher’s Odd-Even (OE) NetworkAn Alternative - Parberry's Pairwise (PW)

Network Why an Alternative (I) - constraint

propagationUnderstanding OE vs. PW Why an Alternative (II) - partial evaluationConclusion

Page 5: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

Sorting networksA 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

b1a1a2 b2

b3a3

a4 b4

Page 6: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

Sorting networksThere are “handcrafted” sorting networks

And there are sorting networks based on your favorite sorting algorithm

x1x2x3x4

x8

y1y2y3

x5x6x7

y5y6y7y8

x9 y9

Custom sorting network, n=9

x1x2x3x4

y1y2y3

x5x6

y5y6

y4

y4

“Bubble sort” network

Page 7: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

Sat encoding - comparators

The SAT encoding of a comparator comparator(a, b, c, d) is: dba

cb

ca

c

d

a

b

cba

db

da

Page 8: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

Sat encoding – sorting networksb1a

1

t1

t2

t3

t4

t6

t5a2

a3

a4

b2

b3

b4

The SAT encoding of a sorting network is the conjunction of the encodings of its comparators.

),,,(

...

),,,(

),,,(

3265

4343

2121

bbttcomparator

ttaacomparator

ttaacomparator

Page 9: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

Sat encoding – cardinality constraintsx1

x2

x3

x4

x5

x6

x7

x8

y1

y2

y3

0 Sorter(8)

0 0 0 0

48

1

i

ix 48

1

i

iyky

Given a cardinality constraint x1+ x2+…+ xn < k

Set the k’th output variable to zero.

48

1

i

ix

Page 10: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

x1

x2

x3

x4

x5

x6

x7

x8

y1

y2

y3

y4

y5

y6

y7

y8

Sorter(n)

The odd-even (OE) sorting network

Sorter(n/2)

Sorter(n/2)

OE

-M

erg

er(

n)

Sorter(n/4)

OE

-M

erg

er(

n/2

)}

),...,1(

),...,12

(

)2

,...,1(

{ )(

nmerge

nn

sort

nsort

nsort

OE

-M

erg

er(

n/2

)

Sorter(n/4)

Sorter(n/4)

Sorter(n/4)

Page 11: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

OE

-Merg

er(

4)

It’s all in the (OE) mergerx1

x2

x3

x4

x5

x6

x7

x8

y1

y2

y3

y5

y6

y7

y8

y4

Given two sorted input sequences sorte

d

sorted

Merge the odd input sequences

Merge the even input sequences

OEMerger(8

)OE

-Merg

er(

4)

Page 12: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

It’s all in the (OE) mergerx1

x2

x3

x4

x5

x6

x7

x8

y1

y2

y3

y5

y6

y7

y8

y4

Given two sorted input sequences sorte

d

sorted

Merge the odd input sequences

Merge the even input sequences

Combine the outputs into a sorted output

OE

-Merg

er(

4)

OE

-Merg

er(

4)

Page 13: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

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”

Page 14: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

The pairwise sorting network

x1

x2

x3

x4

x5

x6

x7

x8

y1

y2

y3

y4

y5

y6

y7

y8

A pairwise split is placed before the recursive calls and divides the network into “upper” and “lower” sub networks . “upper”

Sorter(4)

“lower”Sorter(4)

OE

-M

erg

er(

8)

The inputs to the merger from the “upper” network have more (or equal) ones than those from the “lower” network.

a1

a2

a3

a4

b1b2b3b4

Starting from the OE sorting network

4

1

4

1

ii

This property enables Parberry to simplify the specification of the merger

ai bi

Sp

litt

er(

8)

PW

-Merg

er(

8)

Page 15: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

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)

“lower”Sorter(n/2) P

W-M

erg

er(

n)

Sp

litt

er(

n)

k

0

0

Constraint propagation

k/2

Because 1y)a (b kk/2k/2

Page 16: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

The pairwise (PW) sorting network

Parberry’s sorting network unfolds to a network of splitters followed by simplified mergers

Sorter(n/2)

Sorter(n/2)

PW

-Merg

er(

n)

Sp

litt

er(

n)

Page 17: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

What is the pairwise merger?

x1x2x3x4

y1y2y3

x5x6x7

y5y6y7

y4

x9x1

0x1

1x1

2

y9y1

0y1

1x1

3x1

4x1

5

y1

3y1

4y1

5

y1

2

x8

x1

6

y8

y1

6

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

Page 18: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

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

-M

erg

er(

n)

Sp

litt

er(

n)

Sorter(n/2)

OE

-M

erg

er(

n)

Sp

litt

er

PW

-Merg

er(

n)

Sorter(n/2)

Sorter(n/2) OE

-Merg

er(

n)

Page 19: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

PW vs. OE sorting network

OE-Sorting Networkx1

x2

x3

x4

x5

x6

x7

x8

y1

y2

y3

y4

y5

y6

y7

y8

PW-Sorting Networkx1

x2

x3

x4

x5

x6

x7

x8

y1

y2

y3

y4

y5

y6

y7

y8

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

Page 20: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

Pairwise Cardinality Network c=max(a,b)d=min(a,b)

a

b

0Advance knowledge of comparator’s input/output facilitates partial evaluation

Comparators may become obsolete

0

Splitters before mergers gives more partial evaluation

Page 21: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

x1x2x3x4

y1y2y3

x5x6x7

x9x1

0x1

1x1

2x1

3x1

4x1

5

x8

x1

6

0000000000000

Partial evaluation propagates through the network.

Pairwise Cardinality Network

0

000

0000000

Sorter(8)

Sp

litt

er(

16)

Sorter(8)Sorter(

4)

Sorter(4)

Sp

litt

er(

8)

PW

-M

erg

er(

8)

000

0

k=4

k=2

k=1

The simplified network is of size . It can be constructed directly.

)log( 2 knO

Page 22: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

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

Page 23: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

Pairwise Cardinality Network

Number of comparators after partial evaluation

Before p.e. In the worst case no big difference.

Page 24: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

Experimentsongoing...

In the cardinality matrix problem the sum of each row and column is restricted between k1 and k2

0 0 00 0

00 00 0 0

0 0

1 11 1 1

1 11 1

1 1 1

Boolean Matrix Mn=5, k1=1 & k2=4

3=

=2

Page 25: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

ExperimentsFor a Boolean Matrix with

n=100

Cardinality Network proposed by Asin etal [1]

Page 26: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry

ConclusionPropose cardinality networks based on pairwise

sorting networks instead of odd-even networksBetter constraint propagationBetter partial evaluation

Improve understanding on the relationbetween pairwise and odd-even networ ks

Pairwise Networks are better for cardinality constraints and should be considered in tools (MiniSAT+, etc).

Page 27: Pairwise Cardinality Networks Michael  Codish   and  Moshe Zazon-Ivry