Upload
ilene-casey
View
213
Download
0
Embed Size (px)
Citation preview
Developing Developing
a Simple ZDD Packagea Simple ZDD Package
Alan MishchenkoAlan Mishchenko
University of California, BerkeleyUniversity of California, Berkeley
22
OutlineOutline Decision diagramsDecision diagrams ZDD packageZDD package ExperimentExperiment SummarySummary
33
Decision DiagramsDecision Diagrams
DDs are a useful data-structureDDs are a useful data-structure It is a good exercise to build a new DD packageIt is a good exercise to build a new DD package This presentation is based on real code without This presentation is based on real code without
any simplificationany simplification The code can be found atThe code can be found at
https://bitbucket.org/alanmi/abc/src/4dc7e5aa7805931d35ba1c310fhttps://bitbucket.org/alanmi/abc/src/4dc7e5aa7805931d35ba1c310f90f5baed74d859/src/misc/extra/extraUtilPerm.c90f5baed74d859/src/misc/extra/extraUtilPerm.c
44
Building a DD PackageBuilding a DD Package
Define data structuresDefine data structuresConsider memory managementConsider memory management
Write a procedure for creating a new nodeWrite a procedure for creating a new nodeDevelop traversal proceduresDevelop traversal proceduresDebug and clean up the codeDebug and clean up the codeDevelop and test application code based Develop and test application code based
on the new packageon the new package
55
Basic Data StructuresBasic Data Structurestypedef struct Abc_ZddObj_ Abc_ZddObj;typedef struct Abc_ZddObj_ Abc_ZddObj;struct Abc_ZddObj_ struct Abc_ZddObj_ {{ unsigned Var : 31;unsigned Var : 31; unsigned Mark : 1;unsigned Mark : 1; unsigned True;unsigned True; unsigned False;unsigned False;}; };
typedef struct Abc_ZddEnt_ Abc_ZddEnt;typedef struct Abc_ZddEnt_ Abc_ZddEnt;struct Abc_ZddEnt_ struct Abc_ZddEnt_ {{ int Arg0;int Arg0; int Arg1;int Arg1; int Arg2;int Arg2; int Res;int Res;};};
66
ZDD ManagerZDD Managertypedef struct Abc_ZddMan_ Abc_ZddMan;typedef struct Abc_ZddMan_ Abc_ZddMan;struct Abc_ZddMan_ struct Abc_ZddMan_ {{ int nVars;int nVars; int nObjs;int nObjs; int nObjsAlloc;int nObjsAlloc; int nPermSize;int nPermSize; unsigned nUniqueMask;unsigned nUniqueMask; unsigned nCacheMask;unsigned nCacheMask; int * pUnique;int * pUnique; int * pNexts;int * pNexts; Abc_ZddEnt * pCache;Abc_ZddEnt * pCache; Abc_ZddObj * pObjs;Abc_ZddObj * pObjs; int nCacheLookups;int nCacheLookups; int nCacheMisses;int nCacheMisses; word nMemory;word nMemory; int * pV2TI;int * pV2TI; int * pV2TJ;int * pV2TJ; int * pT2V;int * pT2V;};};
77
Creating New NodeCreating New Nodestatic inline unsigned Abc_ZddHash( int static inline unsigned Abc_ZddHash( int Arg0, int , int Arg1, int , int Arg2 ) ) { return 12582917 { return 12582917 * Arg0 + 4256249 4256249 * Arg1 + 741457 741457 * Arg2; } ; }
static inline int Abc_ZddUniqueCreate( static inline int Abc_ZddUniqueCreate( Abc_ZddMan * p, int Var, int True, int False )Abc_ZddMan * p, int Var, int True, int False ){{ if ( True == 0 ) if ( True == 0 ) return False;return False; elseelse {{ int *q = p->pUnique + (Abc_ZddHash(Var, True, False) & p->nUniqueMask);int *q = p->pUnique + (Abc_ZddHash(Var, True, False) & p->nUniqueMask); for ( ; *q; q = p->pNexts + *q )for ( ; *q; q = p->pNexts + *q ) if ( p->pObjs[*q].Var == Var && if ( p->pObjs[*q].Var == Var && p->pObjs[*q].True == True && p->pObjs[*q].True == True && p->pObjs[*q].False == False )p->pObjs[*q].False == False ) return *q;return *q; assert( p->nObjs < p->nObjsAlloc ); assert( p->nObjs < p->nObjsAlloc ); *q = p->nObjs++;*q = p->nObjs++; p->pObjs[*q].Var = Var;p->pObjs[*q].Var = Var; p->pObjs[*q].True = True;p->pObjs[*q].True = True; p->pObjs[*q].False = False;p->pObjs[*q].False = False; return *q;return *q; }}}}
88
Traversal ProceduresTraversal Procedures
Set operationsSet operationsUnion, difference, intersection Union, difference, intersection
Product operationsProduct operationsDot-product, cross-productDot-product, cross-product
Counting operationsCounting operationsCount the number of nodes and pathsCount the number of nodes and paths
Permutation operationsPermutation operationsTransposition, permutation productTransposition, permutation product
99
ZDD UnionZDD Unionint Abc_ZddUnion( Abc_ZddMan * p, int a, int b )int Abc_ZddUnion( Abc_ZddMan * p, int a, int b ){{ Abc_ZddObj * A, * B; Abc_ZddObj * A, * B; int r0, r1, r;int r0, r1, r; if ( a == 0 ) return b;if ( a == 0 ) return b; if ( b == 0 ) return a;if ( b == 0 ) return a; if ( a == b ) return a;if ( a == b ) return a; if ( a > b ) return Abc_ZddUnion( p, b, a );if ( a > b ) return Abc_ZddUnion( p, b, a ); if ( (r = Abc_ZddCacheLookup(p, a, b, ABC_ZDD_OPER_UNION)) >= 0 )if ( (r = Abc_ZddCacheLookup(p, a, b, ABC_ZDD_OPER_UNION)) >= 0 ) return r;return r; A = Abc_ZddNode( p, a );A = Abc_ZddNode( p, a ); B = Abc_ZddNode( p, b );B = Abc_ZddNode( p, b ); if ( A->Var < B->Var )if ( A->Var < B->Var ) r0 = Abc_ZddUnion( p, A->False, b ), r0 = Abc_ZddUnion( p, A->False, b ), r1 = A->True;r1 = A->True; else if ( A->Var > B->Var )else if ( A->Var > B->Var ) r0 = Abc_ZddUnion( p, a, B->False ), r0 = Abc_ZddUnion( p, a, B->False ), r1 = B->True;r1 = B->True; elseelse r0 = Abc_ZddUnion( p, A->False, B->False ), r0 = Abc_ZddUnion( p, A->False, B->False ), r1 = Abc_ZddUnion( p, A->True, B->True );r1 = Abc_ZddUnion( p, A->True, B->True ); r = Abc_ZddUniqueCreate( p, Abc_MinInt(A->Var, B->Var), r1, r0 );r = Abc_ZddUniqueCreate( p, Abc_MinInt(A->Var, B->Var), r1, r0 ); return Abc_ZddCacheInsert( p, a, b, ABC_ZDD_OPER_UNION, r );return Abc_ZddCacheInsert( p, a, b, ABC_ZDD_OPER_UNION, r );}}
1010
ExperimentExperiment
Shin-ichi Minato proposed PiDDs, a ZDD-based data-Shin-ichi Minato proposed PiDDs, a ZDD-based data-structure to represent and manipulate permutationsstructure to represent and manipulate permutations Shin-ichi Minato, "PiDD: A new decision diagram for efficient Shin-ichi Minato, "PiDD: A new decision diagram for efficient
problem solving in permutation space,“ Proc. SAT’11, pp. 90-104problem solving in permutation space,“ Proc. SAT’11, pp. 90-104
One of the applications cited in the paper, is enumeration One of the applications cited in the paper, is enumeration of reachable states of a simplified Rubik’s cubeof reachable states of a simplified Rubik’s cube Traditional cube is 3x3x3 and has 4.3*10^19 statesTraditional cube is 3x3x3 and has 4.3*10^19 states
http://en.wikipedia.org/wiki/Rubiks_Cubehttp://en.wikipedia.org/wiki/Rubiks_Cube Simplified cube is 2x2x2 and has only 3,674,160 statesSimplified cube is 2x2x2 and has only 3,674,160 states
http://en.wikipedia.org/wiki/Pocket_cubehttp://en.wikipedia.org/wiki/Pocket_cube Minato’s ZDD-based implementation takes 207 sec to enumerate Minato’s ZDD-based implementation takes 207 sec to enumerate
states of the simplified cube on a 2.4 GHz Core2Duo PCstates of the simplified cube on a 2.4 GHz Core2Duo PC
1111
Cube’s State EncondingCube’s State Enconding
1212
Cube’s Transition RelationCube’s Transition Relation
1313
Experiment from Minato’s PaperExperiment from Minato’s Paper
1414
Experiment: ZDD-Based EnumerationExperiment: ZDD-Based Enumeration
UC Berkeley, ABC 1.01 (compiled May 14 2014 04:30:19)UC Berkeley, ABC 1.01 (compiled May 14 2014 04:30:19)abc 01> cubeenum -zabc 01> cubeenum -zEnumerating states of 2x2x2 cube.Enumerating states of 2x2x2 cube.Iter 0 -> 1 Nodes = 0 Used = 2 Time = 0.00 secIter 0 -> 1 Nodes = 0 Used = 2 Time = 0.00 secIter 1 -> 10 Nodes = 63 Used = 577 Time = 0.00 secIter 1 -> 10 Nodes = 63 Used = 577 Time = 0.00 secIter 2 -> 64 Nodes = 443 Used = 4349 Time = 0.03 secIter 2 -> 64 Nodes = 443 Used = 4349 Time = 0.03 secIter 3 -> 385 Nodes = 2018 Used = 26654 Time = 0.12 secIter 3 -> 385 Nodes = 2018 Used = 26654 Time = 0.12 secIter 4 -> 2232 Nodes = 7451 Used = 119442 Time = 0.43 secIter 4 -> 2232 Nodes = 7451 Used = 119442 Time = 0.43 secIter 5 -> 12224 Nodes = 25178 Used = 490038 Time = 1.07 secIter 5 -> 12224 Nodes = 25178 Used = 490038 Time = 1.07 secIter 6 -> 62360 Nodes = 83955 Used = 1919750 Time = 1.77 secIter 6 -> 62360 Nodes = 83955 Used = 1919750 Time = 1.77 secIter 7 -> 289896 Nodes = 290863 Used = 7182932 Time = 3.16 secIter 7 -> 289896 Nodes = 290863 Used = 7182932 Time = 3.16 secIter 8 -> 1159968 Nodes = 614845 Used = 25301123 Time = 8.18 secIter 8 -> 1159968 Nodes = 614845 Used = 25301123 Time = 8.18 secIter 9 -> 3047716 Nodes = 585664 Used = 66228369 Time = 20.72 secIter 9 -> 3047716 Nodes = 585664 Used = 66228369 Time = 20.72 secIter 10 -> 3671516 Nodes = 19430 Used = 102292452 Time = 34.28 secIter 10 -> 3671516 Nodes = 19430 Used = 102292452 Time = 34.28 secIter 11 -> 3674160 Nodes = 511 Used = 103545878 Time = 34.80 secIter 11 -> 3674160 Nodes = 511 Used = 103545878 Time = 34.80 secIter 12 -> 3674160 Nodes = 511 Used = 103566266 Time = 34.81 secIter 12 -> 3674160 Nodes = 511 Used = 103566266 Time = 34.81 secZDD stats: Var = 276 Obj = 103566266 Alloc = 134217728 ZDD stats: Var = 276 Obj = 103566266 Alloc = 134217728 Hit = 63996630 Miss = 141768893 Mem = 4608.00 MBHit = 63996630 Miss = 141768893 Mem = 4608.00 MB
1515
Experiment: Explicit EnumerationExperiment: Explicit Enumeration
UC Berkeley, ABC 1.01 (compiled May 14 2014 04:30:19)UC Berkeley, ABC 1.01 (compiled May 14 2014 04:30:19)abc 01> cubeenumabc 01> cubeenumEnumerating states of 2x2x2 cube.Enumerating states of 2x2x2 cube.Iter 0 -> 1 Time = 0.00 secIter 0 -> 1 Time = 0.00 secIter 1 -> 10 Time = 0.00 secIter 1 -> 10 Time = 0.00 secIter 2 -> 64 Time = 0.00 secIter 2 -> 64 Time = 0.00 secIter 3 -> 385 Time = 0.00 secIter 3 -> 385 Time = 0.00 secIter 4 -> 2232 Time = 0.01 secIter 4 -> 2232 Time = 0.01 secIter 5 -> 12224 Time = 0.03 secIter 5 -> 12224 Time = 0.03 secIter 6 -> 62360 Time = 0.09 secIter 6 -> 62360 Time = 0.09 secIter 7 -> 289896 Time = 0.18 secIter 7 -> 289896 Time = 0.18 secIter 8 -> 1159968 Time = 0.36 secIter 8 -> 1159968 Time = 0.36 secIter 9 -> 3047716 Time = 1.02 secIter 9 -> 3047716 Time = 1.02 secIter 10 -> 3671516 Time = 2.44 secIter 10 -> 3671516 Time = 2.44 secIter 11 -> 3674160 Time = 2.93 secIter 11 -> 3674160 Time = 2.93 secIter 12 -> 3674160 Time = 2.93 secIter 12 -> 3674160 Time = 2.93 sec
1616
ConclusionConclusion Discussed basics of decision diagramsDiscussed basics of decision diagrams Proposed a simple ZDD packageProposed a simple ZDD package Analyzed performance of ZDDs vs explicit Analyzed performance of ZDDs vs explicit
method for a state enumeration problemmethod for a state enumeration problem