feat(encode): add pigeonhole principle generator
This commit is contained in:
1 parent
8af1fa439a
commit
ec9edca5fa
1 file changed
+20
@@ -0,0 +1,20 @@
|
||||
module Sift.Pigeonhole
|
||||
( pigeonhole
|
||||
) where
|
||||
|
||||
import Sift.Types
|
||||
|
||||
-- pigeonhole pigeons holes encodes: every pigeon sits in some hole, and no two
|
||||
-- pigeons share a hole. With pigeons > holes the formula is UNSAT.
|
||||
pigeonhole :: Int -> Int -> CNF
|
||||
pigeonhole pigeons holes = CNF (atLeastOne ++ atMostOne)
|
||||
where
|
||||
cell p h = Var ((p - 1) * holes + h)
|
||||
atLeastOne =
|
||||
[ [ posLit (cell p h) | h <- [1 .. holes] ]
|
||||
| p <- [1 .. pigeons] ]
|
||||
atMostOne =
|
||||
[ [ negLit (cell p h), negLit (cell q h) ]
|
||||
| h <- [1 .. holes]
|
||||
, p <- [1 .. pigeons]
|
||||
, q <- [p + 1 .. pigeons] ]
|
||||
Reference in new issue
Block a user