1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
module Dimacs.Pretty ( showDimacs, prettyDimacs, prettySolution )
where
import Text.Pretty
import Dimacs.Types
import Dimacs.Build
showDimacs :: Boolean -> String
showDimacs b = prettyDimacs (maxVar b) b
prettyDimacs :: Int -> Boolean -> String
prettyDimacs nv = pPrint . (ppDimacs nv) . toCNF
prettySolution :: Boolean -> String
prettySolution = pPrint . (line <>) . ppCNF
ppDimacs :: Int -> Boolean -> Doc
ppDimacs nv b =
let nd = case b of
Or _ -> 1
And l -> length l
_ -> error "Dimacs.Pretty: need formula in CNF"
in (text "p cnf" <+> int nv <+> int nd) $$ (ppCNF b)
ppCNF :: Boolean -> Doc
ppCNF b = case b of
Var i -> int i
Not n -> text "-" <> ppCNF n
And bs -> vsep $ map ppCNF bs
Or bs -> (hsep $ map ppCNF bs) <+> text "0"
|