Presentation is loading. Please wait.

Presentation is loading. Please wait.

Alan Mishchenko University of California, Berkeley

Similar presentations


Presentation on theme: "Alan Mishchenko University of California, Berkeley"— Presentation transcript:

1 Alan Mishchenko University of California, Berkeley
Enumerating Reachable States of 2x2x2 Rubik's Cube Using Implicit and Explicit Methods Alan Mishchenko University of California, Berkeley

2 Outline Understanding decision diagrams
Designing a minimalistic ZDD package Enumerating states of a Rubik’s Cube Implicit enumeration using ZDD Explicit enumeration using bitmaps Experiment Summary

3 Decision Diagrams DDs are a useful data-structure
They are canonical and easy to use in computations In many cases (but not always), can be easily built Several flavors of DDs are available In this presentation, we focus on ZDDs, which are a good way to manipulate sparse sets A set is sparse if it contains relatively few elements out of the set of all possible elements For example, English alphabet has 26 characters but an average word is only 5 characters Various practical applications of ZDD are known We will focus on state enumeration

4 Minimalistic ZDD Package
ZDDs are maintained in a software package Building a new package is a good exercise One idea is to make it as simple as possible For this, we need to isolate what is most useful A new simple ZDD package was developed This presentation is illustrated by actual C code The code can be found at

5 Building a DD Package Define data structures
Pay special attention to memory management Write a procedure for creating a new node Develop neede traversal procedures Debug and clean up the code Develop and test application code based on the new package

6 Basic Data Structures typedef struct Abc_ZddObj_ Abc_ZddObj; // ZDD node struct Abc_ZddObj_ { unsigned Var : 31; unsigned Mark : 1; unsigned True; unsigned False; }; typedef struct Abc_ZddEnt_ Abc_ZddEnt; // cache entry struct Abc_ZddEnt_ int Arg0; int Arg1; int Arg2; int Res;

7 ZDD Manager typedef struct Abc_ZddMan_ Abc_ZddMan; struct Abc_ZddMan_
{ // ZDD package parameters int nVars; // the number of variables int nObjs; // the number of nodes used int nObjsAlloc; // the number of nodes allocated // ZDD node representation Abc_ZddObj * pObjs; // node table int * pUnique; // unique table (chained hash table) int * pNexts; // next entry in the chain unsigned nUniqueMask;// unique table mask // computed table representation Abc_ZddEnt * pCache; // computed table unsigned nCacheMask; // computed table mask };

8 Creating New Node static inline unsigned Abc_ZddHash( int Arg0, int Arg1, int Arg2 ) { return * Arg * Arg * 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; }

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

10 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 ); }

11 Case Study: Permutations
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 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 Simplified cube is 2x2x2 and has only 3,674,160 states Minato’s ZDD-based implementation takes 207 sec to enumerate states of the simplified cube on a 2.4 GHz Core2Duo PC

12 Cube’s State Enconding

13 Cube’s Transition Relation

14 Experiment from Minato’s Paper

15 Experiment: ZDD-Based Enumeration
UC Berkeley, ABC 1.01 (compiled May :30:19) abc 01> cubeenum -z Enumerating states of 2x2x2 cube. Iter 0 -> Nodes = Used = Time = sec Iter 1 -> Nodes = Used = Time = sec Iter 2 -> Nodes = Used = Time = sec Iter 3 -> Nodes = Used = Time = sec Iter 4 -> Nodes = Used = Time = sec Iter 5 -> Nodes = Used = Time = sec Iter 6 -> Nodes = Used = Time = sec Iter 7 -> Nodes = Used = Time = sec Iter 8 -> Nodes = Used = Time = sec Iter 9 -> Nodes = Used = Time = sec Iter 10 -> Nodes = Used = Time = sec Iter 11 -> Nodes = Used = Time = sec Iter 12 -> Nodes = Used = Time = sec ZDD stats: Var = 276 Obj = Alloc = Hit = Miss = Mem = MB (on Intel(R) Xeon(R) CPU E GHz)

16 Explicit Enumeration Use bitmap to remember visited states (depending on state-encoding, takes 50MB-4GB) and an array to remember states to be explored Mark the initial state, add it to the states to be explored Take one state to be explored, perform 9 transitions and check if they are visited; if not, add them to the states to be explored Stop when there is no states to be explored The code can found at

17 Experiment: Explicit Enumeration
UC Berkeley, ABC 1.01 (compiled May :30:19) abc 01> cubeenum Enumerating states of 2x2x2 cube. Iter 0 -> Time = sec Iter 1 -> Time = sec Iter 2 -> Time = sec Iter 3 -> Time = sec Iter 4 -> Time = sec Iter 5 -> Time = sec Iter 6 -> Time = sec Iter 7 -> Time = sec Iter 8 -> Time = sec Iter 9 -> Time = sec Iter 10 -> Time = sec Iter 11 -> Time = sec Iter 12 -> Time = sec (on Intel(R) Xeon(R) CPU E GHz) Memory Usage reported by command top: 1578 MB

18 Conclusion Discussed the basics of decision diagrams
Proposed a minimalistic ZDD package Considered ZDD-based manipulation of sets of permutations and applied to Rubik’s cube Compared performance of ZDD-based enumeration with the explicit implementation Open question: when and under what conditions ZDD-based implemetaiton is faster?

19 Abstract The talk discusses the design of a minimalistic ZDD package using actual C code for illustration. The ZDD package was developed and applied to enumerate reachable states of the simplified (2x2x2) Rubik's cube, as described in Minato's Pi-DD paper (ISAAC 20014). The results of this paper were reproduced and independently verified to be correct. The talk also discusses an explicit enumeration method, which does not use decision diagrams. The runtime of the explicit method is faster than the ZDD-based one. An open question remains: in what applications or under what conditions, a ZDD-based implementation is faster than an explicit implementation. Speaker's bio and CV can be found here:


Download ppt "Alan Mishchenko University of California, Berkeley"

Similar presentations


Ads by Google