1 / 16

Developing a Simple ZDD Package

Developing a Simple ZDD Package. Alan Mishchenko University of California, Berkeley. Outline. Decision diagrams ZDD package Experiment Summary. Decision Diagrams. DDs are a useful data-structure It is a good exercise to build a new DD package

geneviever
Télécharger la présentation

Developing a Simple ZDD Package

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Developing a Simple ZDD Package Alan Mishchenko University of California, Berkeley

  2. Outline • Decision diagrams • ZDD package • Experiment • Summary

  3. Decision Diagrams • DDs are a useful data-structure • It is a good exercise to build a new DD package • This presentation is based on real code without any simplification • The code can be found athttps://bitbucket.org/alanmi/abc/src/4dc7e5aa7805931d35ba1c310f90f5baed74d859/src/misc/extra/extraUtilPerm.c

  4. Building a DD Package • Define data structures • Consider memory management • Write a procedure for creating a new node • Develop traversal procedures • Debug and clean up the code • Develop and test application code based on the new package

  5. Basic Data Structures typedef struct Abc_ZddObj_ Abc_ZddObj; struct Abc_ZddObj_ { unsigned Var : 31; unsigned Mark : 1; unsigned True; unsigned False; }; typedef struct Abc_ZddEnt_ Abc_ZddEnt; struct Abc_ZddEnt_ { int Arg0; int Arg1; int Arg2; int Res; };

  6. ZDD Manager typedef struct Abc_ZddMan_ Abc_ZddMan; struct Abc_ZddMan_ { int nVars; int nObjs; int nObjsAlloc; int nPermSize; unsigned nUniqueMask; unsigned nCacheMask; int * pUnique; int * pNexts; Abc_ZddEnt * pCache; Abc_ZddObj * pObjs; int nCacheLookups; int nCacheMisses; word nMemory; int * pV2TI; int * pV2TJ; int * pT2V; };

  7. Creating New Node static inline unsigned Abc_ZddHash( int Arg0, int Arg1, int Arg2 ) { return 12582917 *Arg0+ 4256249 *Arg1+ 741457 *Arg2; } static inline int Abc_ZddUniqueCreate( Abc_ZddMan * p, int Var, int True, int False ) { if ( True == 0 ) return False; else { int *q = p->pUnique + (Abc_ZddHash(Var, True, False) & p->nUniqueMask); for ( ; *q; q = p->pNexts + *q ) if ( p->pObjs[*q].Var == Var && p->pObjs[*q].True == True && p->pObjs[*q].False == False ) return *q; assert( p->nObjs < p->nObjsAlloc ); *q = p->nObjs++; p->pObjs[*q].Var = Var; p->pObjs[*q].True = True; p->pObjs[*q].False = False; return *q; } }

  8. Traversal Procedures • Set operations • Union, difference, intersection • Product operations • Dot-product, cross-product • Counting operations • Count the number of nodes and paths • Permutation operations • Transposition, permutation product

  9. ZDD Union int Abc_ZddUnion( Abc_ZddMan * p, int a, int b ) { Abc_ZddObj * A, * B; int r0, r1, r; if ( a == 0 ) return b; if ( b == 0 ) return a; if ( a == b ) return a; if ( a > b ) return Abc_ZddUnion( p, b, a ); if ( (r = Abc_ZddCacheLookup(p, a, b, ABC_ZDD_OPER_UNION)) >= 0 ) return r; A = Abc_ZddNode( p, a ); B = Abc_ZddNode( p, b ); if ( A->Var < B->Var ) r0 = Abc_ZddUnion( p, A->False, b ), r1 = A->True; else if ( A->Var > B->Var ) r0 = Abc_ZddUnion( p, a, B->False ), r1 = B->True; else r0 = Abc_ZddUnion( p, A->False, B->False ), r1 = Abc_ZddUnion( p, A->True, B->True ); r = Abc_ZddUniqueCreate( p, Abc_MinInt(A->Var, B->Var), r1, r0 ); return Abc_ZddCacheInsert( p, a, b, ABC_ZDD_OPER_UNION, r ); }

  10. Experiment • Shin-ichi Minato proposed PiDDs, a ZDD-based data-structure to represent and manipulate permutations • Shin-ichi Minato, "PiDD: A new decision diagram for efficient problem solving in permutation space,“ Proc. SAT’11, pp. 90-104 • One of the applications cited in the paper, is enumeration of reachable states of a simplified Rubik’s cube • Traditional cube is 3x3x3 and has 4.3*10^19 states • http://en.wikipedia.org/wiki/Rubiks_Cube • Simplified cube is 2x2x2 and has only 3,674,160 states • http://en.wikipedia.org/wiki/Pocket_cube • Minato’s ZDD-based implementation takes 207 sec to enumerate states of the simplified cube on a 2.4 GHz Core2Duo PC

  11. Cube’s State Enconding

  12. Cube’s Transition Relation

  13. Experiment from Minato’s Paper

  14. Experiment: ZDD-Based Enumeration UC Berkeley, ABC 1.01 (compiled May 14 2014 04:30:19) abc 01> cubeenum -z Enumerating states of 2x2x2 cube. Iter 0 -> 1 Nodes = 0 Used = 2 Time = 0.00 sec Iter 1 -> 10 Nodes = 63 Used = 577 Time = 0.00 sec Iter 2 -> 64 Nodes = 443 Used = 4349 Time = 0.03 sec Iter 3 -> 385 Nodes = 2018 Used = 26654 Time = 0.12 sec Iter 4 -> 2232 Nodes = 7451 Used = 119442 Time = 0.43 sec Iter 5 -> 12224 Nodes = 25178 Used = 490038 Time = 1.07 sec Iter 6 -> 62360 Nodes = 83955 Used = 1919750 Time = 1.77 sec Iter 7 -> 289896 Nodes = 290863 Used = 7182932 Time = 3.16 sec Iter 8 -> 1159968 Nodes = 614845 Used = 25301123 Time = 8.18 sec Iter 9 -> 3047716 Nodes = 585664 Used = 66228369 Time = 20.72 sec Iter 10 -> 3671516 Nodes = 19430 Used = 102292452 Time = 34.28 sec Iter 11 -> 3674160 Nodes = 511 Used = 103545878 Time = 34.80 sec Iter 12 -> 3674160 Nodes = 511 Used = 103566266 Time = 34.81 sec ZDD stats: Var = 276 Obj = 103566266 Alloc = 134217728 Hit = 63996630 Miss = 141768893 Mem = 4608.00 MB

  15. Experiment: Explicit Enumeration UC Berkeley, ABC 1.01 (compiled May 14 2014 04:30:19) abc 01> cubeenum Enumerating states of 2x2x2 cube. Iter 0 -> 1 Time = 0.00 sec Iter 1 -> 10 Time = 0.00 sec Iter 2 -> 64 Time = 0.00 sec Iter 3 -> 385 Time = 0.00 sec Iter 4 -> 2232 Time = 0.01 sec Iter 5 -> 12224 Time = 0.03 sec Iter 6 -> 62360 Time = 0.09 sec Iter 7 -> 289896 Time = 0.18 sec Iter 8 -> 1159968 Time = 0.36 sec Iter 9 -> 3047716 Time = 1.02 sec Iter 10 -> 3671516 Time = 2.44 sec Iter 11 -> 3674160 Time = 2.93 sec Iter 12 -> 3674160 Time = 2.93 sec

  16. Conclusion • Discussed basics of decision diagrams • Proposed a simple ZDD package • Analyzed performance of ZDDs vs explicit method for a state enumeration problem

More Related