minibdd minibdd
play

miniBDD miniBDD For teaching/learning purposes Designed for ease - PowerPoint PPT Presentation

A Minimalistic BDD Library miniBDD miniBDD For teaching/learning purposes Designed for ease of use (there are more efficient libraries) only 556 lines of C++ (compare to cudd, which has 117k lines) D. Kroening: Computer-Aided Formal


  1. A Minimalistic BDD Library miniBDD miniBDD ◮ For teaching/learning purposes ◮ Designed for ease of use (there are more efficient libraries) ◮ only 556 lines of C++ (compare to cudd, which has 117k lines) D. Kroening: Computer-Aided Formal Verification (MT 2009) 1

  2. Data Structures ◮ A class for nodes ◮ With pointers to the two children ◮ With a reference counter ◮ The nodes are stored in a list of nodes in a BDD manager class ◮ The manager also contains: ◮ A list of the variables (with a label) ◮ The hash table for the nodes D. Kroening: Computer-Aided Formal Verification (MT 2009) 2

  3. The BDD Node Class class BDDnode { 1 class miniBDD mgr ∗ mgr ; 2 unsigned var , node number , re fe r en ce c ou nte r ; 3 BDD low , high ; 4 5 inline void add reference ( ) ; 6 void remove reference ( ) ; 7 } ; 8 There is also a (trivial) constructor. D. Kroening: Computer-Aided Formal Verification (MT 2009) 3

  4. The BDD Manager Class class miniBDD mgr { 1 public : 2 BDD Var( const std : : s t r i n g &l a b e l ) ; 3 4 inline const BDD &True ( ) ; 5 inline const BDD &False ( ) ; 6 7 protected : 8 typedef std : : l i s t < BDDnode > nodest ; 9 nodest nodes ; 10 11 v a r t a b l e e n t r y t { std : : s t r i n g l a b e l ; } ; struct 12 typedef std : : vector < var table entryt > v a r t a b l e t ; 13 v a r t a b l e t var table ; 14 . . . 15 There is also a constructor (which sets up True/False), and some methods to dump the node table. D. Kroening: Computer-Aided Formal Verification (MT 2009) 4

  5. The BDD Manager Class (Part II) class miniBDD mgr { 1 . . . 2 3 // t h i s i s our reverse − map for nodes 4 reverse keyt { struct 5 unsigned var , low , high ; 6 } ; 7 8 std : : map < reverse keyt , BDDnode ∗ > reverse map ; 9 10 // create a node ( consulting the reverse − map) 11 BDD mk( unsigned var , 12 const BDD &low , const BDD &high ) ; 13 } ; 14 D. Kroening: Computer-Aided Formal Verification (MT 2009) 5

  6. The Interface (Part I) class BDD { 1 public : 2 // Boolean operators on BDDs 3 BDD operator ! ( ) const ; 4 BDD operator ˆ( const BDD &) const ; 5 6 // copy operator 7 inline BDD & operator =( const BDD &); 8 9 protected : 10 class BDDnode ∗ node ; 11 } ; 12 There are more Boolean operators ( & , | , == ). This is essentially only one pointer, so copying is inexpensive. D. Kroening: Computer-Aided Formal Verification (MT 2009) 6

  7. The Interface (Part II) There are also some methods to obtain information about a BDD: class BDD { 1 public : 2 . . . 3 inline bool i s c o n s t a n t () const ; 4 inline bool i s t r u e () const ; 5 i s f a l s e () const ; inline bool 6 7 inline unsigned var () const ; 8 inline const BDD &low () const ; 9 inline const BDD &high () const ; 10 inline unsigned node number () const ; 11 . . . 12 } ; 13 D. Kroening: Computer-Aided Formal Verification (MT 2009) 7

  8. Using the Interface This produces: #include ”miniBDD . h” 1 y 2 int main () { 3 miniBDD mgr mgr ; 4 x 5 BDD f i n a l= 6 1 mgr . Var( ”x” ) & mgr . Var( ”y” ) ; 7 Warning: The mgr.Var(...) method doesn’t hash, so calling mgr.Var(”x”) twice will produce two different variables, both labelled ”x”. D. Kroening: Computer-Aided Formal Verification (MT 2009) 8

  9. Using the Interface You can look at the BDDs or the node table with: void DumpDot( std : : ostream &out ) const ; 1 void DumpTikZ( std : : ostream &out ) const ; 2 void DumpTable( std : : ostream &out ) const ; 3 This produces: # var low high y y 4 4 0 3 1 3 x x 3 3 2 − − − 3 2 x 0 1 0 1 0 1 4 1 y 0 3 D. Kroening: Computer-Aided Formal Verification (MT 2009) 9

  10. The Implementation of mk BDD miniBDD mgr : : mk( unsigned var , BDD low , BDD high ) { 1 i f ( low . node number()==high . node number ( ) ) 2 return low ; 3 4 reverse keyt reverse key ( var , low , high ) ; 5 reverse mapt : : c o n s t i t e r a t o r i t= 6 reverse map . find ( reverse key ) ; 7 8 i f ( i t != reverse map . end ( ) ) return BDD( it − > second ) ; 9 10 unsigned new number=nodes . back ( ) . node number+1; 11 nodes . push back ( 12 BDDnode( this , var , new number , low , high ) ) ; 13 reverse map [ reverse key]=&nodes . back ( ) ; 14 return BDD(&nodes . back ( ) ) ; 15 } 16 D. Kroening: Computer-Aided Formal Verification (MT 2009) 10

  11. The Implementation of apply BDD apply ( bool ( ∗ fkt )( bool x , bool y ) , 1 BDD x , BDD y) 2 { 3 miniBDD mgr ∗ mgr=x . node − > mgr ; 4 5 BDD u ; 6 7 i f (x . i s c o n s t a n t () && y . i s c o n s t a n t ( ) ) 8 u= BDD( fkt (x . i s t r u e () , y . i s t r u e ( ) ) ? 9 mgr − > true bdd : mgr − > false bdd ) ; 10 i f (x . var()==y . var ( ) ) else 11 u=mgr − > mk(x . var () , 12 apply ( fkt , x . low () , y . low ( ) ) , 13 apply ( fkt , x . high () , y . high ( ) ) ) ; 14 . . . 15 return u ; 16 } 17 D. Kroening: Computer-Aided Formal Verification (MT 2009) 11

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend