From 375b46a355608c119a7dc44eb78468d83e0809b9 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Mon, 21 Apr 2014 21:47:34 -0700 Subject: Experiments with permutations. --- abclib.dsp | 8 +++ src/base/abci/abc.c | 5 ++ src/misc/extra/extraUtilCube.c | 140 +++++++++++++++++++++++++++++++++++++++++ src/misc/extra/module.make | 1 + 4 files changed, 154 insertions(+) create mode 100644 src/misc/extra/extraUtilCube.c diff --git a/abclib.dsp b/abclib.dsp index 8ef38d70..88928a58 100644 --- a/abclib.dsp +++ b/abclib.dsp @@ -2703,6 +2703,10 @@ SOURCE=.\src\misc\extra\extraUtilCanon.c # End Source File # Begin Source File +SOURCE=.\src\misc\extra\extraUtilCube.c +# End Source File +# Begin Source File + SOURCE=.\src\misc\extra\extraUtilDsd.c # End Source File # Begin Source File @@ -2719,6 +2723,10 @@ SOURCE=.\src\misc\extra\extraUtilMisc.c # End Source File # Begin Source File +SOURCE=.\src\misc\extra\extraUtilPerm.c +# End Source File +# Begin Source File + SOURCE=.\src\misc\extra\extraUtilProgress.c # End Source File # Begin Source File diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 6801ccaa..e918e6f3 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -10447,6 +10447,11 @@ int Abc_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv ) // extern void Ifd_ManDsdTest(); // Ifd_ManDsdTest(); } + { + extern void Abc_EnumerateCubeStates(); + Abc_EnumerateCubeStates(); + return 0; + } if ( pNtk ) { extern Abc_Ntk_t * Abc_NtkBarBufsOnOffTest( Abc_Ntk_t * pNtk ); diff --git a/src/misc/extra/extraUtilCube.c b/src/misc/extra/extraUtilCube.c new file mode 100644 index 00000000..b08a4a21 --- /dev/null +++ b/src/misc/extra/extraUtilCube.c @@ -0,0 +1,140 @@ +/**CFile**************************************************************** + + FileName [extraUtilCube.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [extra] + + Synopsis [Permutation computation.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - June 20, 2005.] + + Revision [$Id: extraUtilCube.c,v 1.0 2003/02/01 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include +#include +#include +#include +#include "misc/vec/vec.h" +#include "misc/vec/vecHsh.h" + +ABC_NAMESPACE_IMPL_START + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +static inline void Abc_StatePush( Vec_Int_t * vData, char * pState, int k ) { int i; for ( i = 0; i < 6; i++ ) Vec_IntWriteEntry(vData, 6*k+i, ((int*)pState)[i]); } +static inline void Abc_StatePerm( char * pState, char * pPerm, char * pRes ) { int i; for ( i = 0; i < 24; i++ ) pRes[i] = pState[pPerm[i]]; } +static inline void Abc_StatePrint( char * pState ) { int i; for ( i = 0; i < 24; i++ ) printf(" %2d", pState[i]); printf( "\n" ); } + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Abc_EnumerateCubeStates() +{ + int pXYZ[3][9][2] = { + { {3, 5}, {3,17}, {3,15}, {1, 6}, {1,16}, {1,14}, {2, 4}, {2,18}, {2,13} }, + { {2,14}, {2,24}, {2,12}, {3,13}, {3,23}, {3,10}, {1,15}, {1,22}, {1,11} }, + { {1,10}, {1, 7}, {1, 4}, {3,12}, {3, 9}, {3, 6}, {2,11}, {2, 8}, {2, 5} } }; + + Vec_Int_t * vData = Vec_IntStart( 6 * (1 << 22) ); + Hsh_IntMan_t * vHash = Hsh_IntManStart( vData, 6, 1 << 22 ); + int i, k, v, RetValue, Beg, End, Counter = 0; + char pStart[24], pFirst[9][24]; + abctime clk = Abc_Clock(); + printf( "Enumerating states of 2x2x2 cube.\n" ); + // init state + for ( v = 0; v < 24; v++ ) + pStart[v] = v; + Abc_StatePush( vData, pStart, Counter ); + RetValue = Hsh_IntManAdd( vHash, Counter ); + assert( RetValue == Counter ); + Counter++; + // first nine states + for ( i = 0; i < 3; i++ ) + { + memcpy( pFirst[i], pStart, 24 ); + for ( v = 0; v < 9; v++ ) + ABC_SWAP( char, pFirst[i][pXYZ[i][v][0]-1], pFirst[i][pXYZ[i][v][1]-1] ); + Abc_StatePush( vData, pFirst[i], Counter ); + RetValue = Hsh_IntManAdd( vHash, Counter ); + assert( RetValue == Counter ); + Counter++; + //Abc_StatePrint( pFirst[i] ); + + memcpy( pFirst[3+i], pFirst[i], 24 ); + for ( v = 0; v < 9; v++ ) + ABC_SWAP( char, pFirst[3+i][pXYZ[i][v][0]-1], pFirst[3+i][pXYZ[i][v][1]-1] ); + Abc_StatePush( vData, pFirst[3+i], Counter ); + RetValue = Hsh_IntManAdd( vHash, Counter ); + assert( RetValue == Counter ); + Counter++; + //Abc_StatePrint( pFirst[3+i] ); + + memcpy( pFirst[6+i], pFirst[3+i], 24 ); + for ( v = 0; v < 9; v++ ) + ABC_SWAP( char, pFirst[6+i][pXYZ[i][v][0]-1], pFirst[6+i][pXYZ[i][v][1]-1] ); + Abc_StatePush( vData, pFirst[6+i], Counter ); + RetValue = Hsh_IntManAdd( vHash, Counter ); + assert( RetValue == Counter ); + Counter++; + //Abc_StatePrint( pFirst[6+i] ); + } + printf( "Iter %2d -> %8d ", 0, 1 ); + Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); + printf( "Iter %2d -> %8d ", 1, Counter ); + Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); + Beg = 1; End = 10; + for ( i = 2; i <= 100; i++ ) + { + if ( Beg == End ) + break; + for ( k = Beg; k < End; k++ ) + for ( v = 0; v < 9; v++ ) + { + Abc_StatePerm( (char *)Vec_IntEntryP(vData, 6*k), pFirst[v], (char *)Vec_IntEntryP(vData, 6*Counter) ); + RetValue = Hsh_IntManAdd( vHash, Counter ); + if ( RetValue == Counter ) + Counter++; + if ( Counter == (1<<22) ) + { + printf( "Did not converge. " ); + Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); + return; + } + } + Beg = End; End = Counter; + printf( "Iter %2d -> %8d ", i, Counter ); + Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); + } + Hsh_IntManStop( vHash ); + Vec_IntFree( vData ); +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + +ABC_NAMESPACE_IMPL_END + diff --git a/src/misc/extra/module.make b/src/misc/extra/module.make index 9c13c146..8a66c4b7 100644 --- a/src/misc/extra/module.make +++ b/src/misc/extra/module.make @@ -8,6 +8,7 @@ SRC += src/misc/extra/extraBddAuto.c \ src/misc/extra/extraBddUnate.c \ src/misc/extra/extraUtilBitMatrix.c \ src/misc/extra/extraUtilCanon.c \ + src/misc/extra/extraUtilCube.c \ src/misc/extra/extraUtilDsd.c \ src/misc/extra/extraUtilFile.c \ src/misc/extra/extraUtilMemory.c \ -- cgit v1.2.3