trivialib.bdd
2021-12-09
BDD and ZDD implementation using Trivia
1Trivialib.Bdd
Functional implementation of (Ordered) Binary Decision Diagram (BDD) and Zero-suppressed Binary Decision Diagram (ZDD).
- Bryant, Randal E. "Graph-based algorithms for boolean functionmanipulation." Computers, IEEE Transactions on 100.8 (1986): 677-691.
- Minato, Shin-ichi. "Zero-suppressed BDDs for set manipulation incombinatorial problems." Design Automation, 1993. 30th Conferenceon. IEEE, 1993.
Tutorial slide on Symbolic Methods for Hybrid Inference, Optimization, and Decision-making at AAAI 2016, by Scott Sanner
2FEATURES
Based on structures --- moderately fast
Weak hash table --- GC-aware, moderate memory usage
Pattern matching --- functional, clean implementation
3TODOs
- more useful interfaces for set manipulation, function manipulation
- speed
- extension to ADD (Algebraic Decision Diagram) --- mostly trivial
- extension to XADD (algebraic decision diagram)
- extension to MV-DDs (multi-valued decision diagram)
- extension to AADDs (affine algebrainc decision diagram) --- for representing formula
- extension to XADDs (continuous variable extension of algebrainc decision diagram) --- for continuous range
- extension to SDD (sentensial decision diagram)
4Usage
Web API Documentation will be available at http://quickdocs.org/trivialib.bdd/
;; Knuth Chapter 4, figure 12 (and 122), rightmost ("kernel")
;; represent a set {{1,3,5},{1,4},{2,4,6},{2,5},{3,6}}
(labels ((add2 (dd1 dd2) (odd-apply dd1 dd2 (lambda (a b) (or a b))))
(mul2 (dd1 dd2) (odd-apply dd1 dd2 (lambda (a b) (and a b))))
(add (dd1 dd2 &rest args)
(if args
(apply #'add (add2 dd1 dd2) args)
(add2 dd1 dd2)))
(mul (dd1 dd2 &rest args)
(if args
(apply #'mul (mul2 dd1 dd2) args)
(mul2 dd1 dd2)))
(o (x) (odd (unit x)))
(x (x) (odd (!unit x)))
(change-many (node &rest args) (reduce #'change args :initial-value node)))
(with-odd-context (:variable '(a b c d e f))
;; stored into VARIABLES slot of an ODD. ^^^
;; Different variable orderings make ODDs incompatible.
(gcprint
;; using BDD reduction rule: 15 nodes
(add (mul (o 1) (x 2) (o 3) (x 4) (o 5) (x 6))
(mul (o 1) (x 2) (x 3) (o 4) (x 5) (x 6))
(mul (x 1) (o 2) (x 3) (o 4) (x 5) (o 6))
(mul (x 1) (o 2) (x 3) (x 4) (o 5) (x 6))
(mul (x 1) (x 2) (o 3) (x 4) (x 5) (o 6)))))
(with-odd-context (:operation #'zdd-apply)
;; Different reduction rule also make ODDs incompatible.
(gcprint
;; using Zero-suppressed reduction rule: 8 nodes
(add (odd (change-many (leaf t) 1 3 5))
(odd (change-many (leaf t) 1 4))
(odd (change-many (leaf t) 2 4 6))
(odd (change-many (leaf t) 2 5))
(odd (change-many (leaf t) 3 6)))))
(with-odd-context (:operation #'zdd-apply)
;; using a utility function for ZDD
(gcprint
(add (odd (make-set '(1 3 5)))
(odd (make-set '(1 4)))
(odd (make-set '(2 4 6)))
(odd (make-set '(2 5)))
(odd (make-set '(3 6))))))
(with-odd-context (:operation #'zdd-apply)
;; using a utility function for ZDD
(gcprint
(odd (make-family '((1 3 5)
(1 4)
(2 4 6)
(2 5)
(3 6)))))))
4.1Dependencies
This library is at least tested on implementation listed below:
- SBCL 1.2.8 on X86-64 Linux 3.13.0-46-generic (author's environment)
Also, it depends on the following libraries:
- alexandria by
- Alexandria is a collection of portable public domain utilities.
- trivia by Masataro Asai
- NON-optimized pattern matcher compatible with OPTIMA, with extensible optimizer interface and clean codebase
- immutabe-struct by Masataro Asai
- trivial-garbage
- For handling weak hash tables.
4.2Author
- Masataro Asai (guicho2.71828@gmail.com)
5Copyright
Copyright (c) 2015 Masataro Asai (guicho2.71828@gmail.com)
6License
Licensed under the LLGPL License.