Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/guicho271828/trivialib.bdd

BDD and ZDD
https://github.com/guicho271828/trivialib.bdd

Last synced: 29 days ago
JSON representation

BDD and ZDD

Awesome Lists containing this project

README

        

* Trivialib.Bdd

Functional implementation of (Ordered) Binary Decision Diagram (BDD) and Zero-suppressed Binary Decision Diagram (ZDD).

+ Bryant, Randal E. "Graph-based algorithms for boolean function
manipulation." Computers, IEEE Transactions on 100.8 (1986): 677-691.
+ Minato, Shin-ichi. "Zero-suppressed BDDs for set manipulation in
combinatorial problems." Design Automation, 1993. 30th Conference
on. IEEE, 1993.

[[http://users.cecs.anu.edu.au/~ssanner/AAAI16/][Tutorial slide]] on Symbolic Methods for Hybrid Inference, Optimization, and Decision-making at AAAI 2016, by [[http://users.cecs.anu.edu.au/~ssanner/][Scott Sanner]]

* FEATURES

Based on structures --- moderately fast

Weak hash table --- GC-aware, moderate memory usage

Pattern matching --- functional, clean implementation

* TODOs

+ 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)

* Usage

Web API Documentation will be available at http://quickdocs.org/trivialib.bdd/

#+BEGIN_SRC lisp

;; 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)))))))
#+END_SRC

** Dependencies

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.

** Author

+ Masataro Asai ([email protected])

* Copyright

Copyright (c) 2015 Masataro Asai ([email protected])

* License

Licensed under the LLGPL License.