msakai / haskell-decision-diagrams

Binary decision diagrams (BDD) and Zero-Suppressed Binary Decision Diagrams (ZDD) in Haskell
https://hackage.haskell.org/package/decision-diagrams
BSD 3-Clause "New" or "Revised" License
13 stars 6 forks source link

visualisation via GraphViz #37

Open m4lvin opened 2 weeks ago

m4lvin commented 2 weeks ago

(First, thanks for the very nice library - it is great to have a pure Haskell BDD package!)

Would you be interested in adding function to visualize BDDs? There already is the toGraph function, but in an ongoing project I found it helpful to convert to the GraphViz types. See here for the code.

I did not make a PR immediately, as I can also imagine that adding the dependency on the Haskell library graphviz is a bit overkill for anyone not wanting to use it but just wanting to have DDs :thinking:

msakai commented 4 days ago

Thank you for using the library and suggestions.

I think basic visualization is a handy feature for BDD packages.

Can the graphviz package be built without foreign libraries and is not too large? If these are the case and the API and implementation are solid, I would like to include the feature in this package.

Below are a few quick comments on the current code:

m4lvin commented 4 days ago

I updated my fork now, see here. I added functions to show ZDDs, reworked the "remove unreachable nodes" part and for bddPdf the file name is now an argument. It is now one module Data.DecisionDiagram.Visuals instead of being BDD specific, so I kept the bdd and zdd prefixes.

Can the graphviz package be built without foreign libraries and is not too large?

Yes, I think the Haskell library graphviz even compiles when graphviz is not installed and has no non-Haskell dependencies. It does depend on a bunch of other Haskell libraries, that is what I meant with a bit overkill, as it increases the footprint of decision-diagrams.

A more naive approach would be to just create a String output instead of a proper DotGraph value - that is actually what I did in Data.HasCacBDD.Visuals, so HasCacBDD does not depend on graphviz, but it feels unsafe and wrong (and the show function there depends on a hard-coded binary location /usr/bin/dot etc 🥴)

I can make a PR later, but probably also should add tests. (For example to check that the DotGraph for specific DDs is as expected.)