diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2012-02-19 14:52:43 -0800 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2012-02-19 14:52:43 -0800 |
commit | 2377ae60e99fd751021cbcac880b584d57c284a1 (patch) | |
tree | 8189050d8e0e518b50437d0a5145efce679197a5 /src/aig | |
parent | ea13085fe34bed2e827fe8ec6fb7e24c6e1a5d8f (diff) | |
download | abc-2377ae60e99fd751021cbcac880b584d57c284a1.tar.gz abc-2377ae60e99fd751021cbcac880b584d57c284a1.tar.bz2 abc-2377ae60e99fd751021cbcac880b584d57c284a1.zip |
Isomorphism checking code.
Diffstat (limited to 'src/aig')
-rw-r--r-- | src/aig/gia/giaDup.c | 2 | ||||
-rw-r--r-- | src/aig/gia/giaIso.c | 145 | ||||
-rw-r--r-- | src/aig/saig/saigIso.c | 15 |
3 files changed, 144 insertions, 18 deletions
diff --git a/src/aig/gia/giaDup.c b/src/aig/gia/giaDup.c index 342332cd..577a0180 100644 --- a/src/aig/gia/giaDup.c +++ b/src/aig/gia/giaDup.c @@ -1762,7 +1762,7 @@ void Gia_ManDupCones_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Ptr_t * vLeaves, Gia_ManDupCones_rec( p, Gia_ObjFanin1(pObj), vLeaves, vNodes, vRoots ); Vec_PtrPush( vNodes, pObj ); } - else if ( Gia_ObjIsPo(p, pObj) ) + else if ( Gia_ObjIsCo(pObj) ) Gia_ManDupCones_rec( p, Gia_ObjFanin0(pObj), vLeaves, vNodes, vRoots ); else if ( Gia_ObjIsRo(p, pObj) ) Vec_PtrPush( vRoots, Gia_ObjRoToRi(p, pObj) ); diff --git a/src/aig/gia/giaIso.c b/src/aig/gia/giaIso.c index 3ff8ee2f..71733ee9 100644 --- a/src/aig/gia/giaIso.c +++ b/src/aig/gia/giaIso.c @@ -21,7 +21,7 @@ #include "gia.h" ABC_NAMESPACE_IMPL_START - + #define ISO_MASK 0xFF static int s_256Primes[ISO_MASK+1] = @@ -458,11 +458,68 @@ void Gia_IsoSort( Gia_IsoMan_t * p ) SeeAlso [] ***********************************************************************/ -void Gia_IsoTest( Gia_Man_t * pGia ) +Vec_Ptr_t * Gia_IsoCollectCos( Gia_IsoMan_t * p, int fVerbose ) +{ + Vec_Ptr_t * vGroups; + Vec_Int_t * vLevel; + Gia_Obj_t * pObj; + int i, k, iBegin, nSize; + + // add singletons + vGroups = Vec_PtrAlloc( 1000 ); + Gia_ManForEachPo( p->pGia, pObj, i ) + if ( p->pUniques[Gia_ObjId(p->pGia, pObj)] > 0 ) + { + vLevel = Vec_IntAlloc( 1 ); + Vec_IntPush( vLevel, i ); + Vec_PtrPush( vGroups, vLevel ); + } + + // add groups + Vec_IntForEachEntryDouble( p->vClasses, iBegin, nSize, i ) + { + for ( k = 0; k < nSize; k++ ) + { + pObj = Gia_ManObj( p->pGia, Gia_IsoGetItem(p,iBegin+k) ); + if ( Gia_ObjIsPo(p->pGia, pObj) ) + break; + } + if ( k == nSize ) + continue; + vLevel = Vec_IntAlloc( 8 ); + for ( k = 0; k < nSize; k++ ) + { + pObj = Gia_ManObj( p->pGia, Gia_IsoGetItem(p,iBegin+k) ); + if ( Gia_ObjIsPo(p->pGia, pObj) ) + Vec_IntPush( vLevel, Gia_ObjCioId(pObj) ); + } + Vec_PtrPush( vGroups, vLevel ); + } + // canonicize order + Vec_PtrForEachEntry( Vec_Int_t *, vGroups, vLevel, i ) + Vec_IntSort( vLevel, 0 ); + Vec_VecSortByFirstInt( (Vec_Vec_t *)vGroups, 0 ); +// Vec_VecFree( (Vec_Vec_t *)vGroups ); +// return NULL; + return vGroups; +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Ptr_t * Gia_IsoDeriveEquivPos( Gia_Man_t * pGia, int fVerbose ) { - int fVerbose = 1; - int nIterMax = 50; + Vec_Ptr_t * vEquivs; Gia_IsoMan_t * p; + int nIterMax = 1000; int i, clk = clock(), clkTotal = clock(); Gia_ManCleanValue( pGia ); @@ -470,9 +527,9 @@ void Gia_IsoTest( Gia_Man_t * pGia ) Gia_IsoPrepare( p ); Gia_IsoAssignUnique( p ); p->timeStart = clock() - clk; - // Gia_IsoPrintClasses( p ); - Gia_IsoPrint( p, 0, clock() - clkTotal ); + if ( fVerbose ) + Gia_IsoPrint( p, 0, clock() - clkTotal ); for ( i = 0; i < nIterMax; i++ ) { clk = clock(); @@ -484,11 +541,11 @@ void Gia_IsoTest( Gia_Man_t * pGia ) p->timeRefine += clock() - clk; // Gia_IsoPrintClasses( p ); - Gia_IsoPrint( p, i+1, clock() - clkTotal ); + if ( fVerbose ) + Gia_IsoPrint( p, i+1, clock() - clkTotal ); if ( p->nSingles == 0 ) break; } - if ( fVerbose ) { p->timeTotal = clock() - clkTotal; @@ -501,11 +558,81 @@ void Gia_IsoTest( Gia_Man_t * pGia ) ABC_PRTP( "Other ", p->timeOther, p->timeTotal ); ABC_PRTP( "TOTAL ", p->timeTotal, p->timeTotal ); } - + vEquivs = Gia_IsoCollectCos( p, fVerbose ); Gia_IsoManStop( p ); + return vEquivs; +} + + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Gia_Man_t * Gia_ManIsoReduce( Gia_Man_t * pGia, Vec_Ptr_t ** pvPosEquivs, int fVerbose ) +{ + Gia_Man_t * pPart; + Vec_Ptr_t * vEquivs; + Vec_Int_t * vRemain, * vLevel; + int i, clk = clock(); + // create equivalences + vEquivs = Gia_IsoDeriveEquivPos( pGia, fVerbose ); + // collect the first ones + vRemain = Vec_IntAlloc( 100 ); + Vec_PtrForEachEntry( Vec_Int_t *, vEquivs, vLevel, i ) + Vec_IntPush( vRemain, Vec_IntEntry(vLevel, 0) ); + // derive the resulting AIG + pPart = Gia_ManDupCones( pGia, Vec_IntArray(vRemain), Vec_IntSize(vRemain) ); + Vec_IntFree( vRemain ); + // report the results + printf( "Reduced %d outputs to %d outputs. ", Gia_ManPoNum(pGia), Gia_ManPoNum(pPart) ); + Abc_PrintTime( 1, "Time", clock() - clk ); + if ( fVerbose ) + { + printf( "Nontrivial classes:\n" ); + Vec_VecPrintInt( (Vec_Vec_t *)vEquivs, 1 ); + } + if ( pvPosEquivs ) + *pvPosEquivs = vEquivs; + else + Vec_VecFree( (Vec_Vec_t *)vEquivs ); +// Gia_ManStopP( &pPart ); + return pPart; } +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Gia_IsoTest( Gia_Man_t * pGia, int fVerbose ) +{ + Vec_Ptr_t * vEquivs; + int clk = clock(); + vEquivs = Gia_IsoDeriveEquivPos( pGia, fVerbose ); + printf( "Reduced %d outputs to %d. ", Gia_ManPoNum(pGia), Vec_PtrSize(vEquivs) ); + Abc_PrintTime( 1, "Time", clock() - clk ); + if ( fVerbose ) + { + printf( "Nontrivial classes:\n" ); + Vec_VecPrintInt( (Vec_Vec_t *)vEquivs, 1 ); + } + Vec_VecFree( (Vec_Vec_t *)vEquivs ); +} + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// diff --git a/src/aig/saig/saigIso.c b/src/aig/saig/saigIso.c index 95d0cdae..c3d1af9d 100644 --- a/src/aig/saig/saigIso.c +++ b/src/aig/saig/saigIso.c @@ -428,6 +428,7 @@ Aig_Man_t * Iso_ManFilterPos( Aig_Man_t * pAig, Vec_Ptr_t ** pvPosEquivs, int fV Vec_Str_t * vStr, * vPrev; int i, nPos, nUnique = 0, clk = clock(); int clkDup = 0, clkAig = 0, clkIso = 0, clk2; + *pvPosEquivs = NULL; // derive AIG for each PO nPos = Aig_ManPoNum(pAig) - Aig_ManRegNum(pAig); @@ -521,13 +522,6 @@ Aig_Man_t * Iso_ManFilterPos( Aig_Man_t * pAig, Vec_Ptr_t ** pvPosEquivs, int fV // return (Vec_Vec_t *)vClasses; // Vec_VecFree( (Vec_Vec_t *)vClasses ); *pvPosEquivs = vClasses; - if ( fVerbose && vClasses ) - { - printf( "Non-trivial equivalence clases of primary outputs:\n" ); - Vec_VecPrintInt( (Vec_Vec_t *)vClasses, 1 ); - } - -// printf( "The number of all checks %d. Complex checks %d.\n", nPos*(nPos-1)/2, s_Counter ); return pPart; } @@ -570,7 +564,12 @@ Aig_Man_t * Saig_ManIsoReduce( Aig_Man_t * pAig, Vec_Ptr_t ** pvPosEquivs, int f pPart = Iso_ManFilterPos( pAig, pvPosEquivs, fVerbose ); printf( "Reduced %d outputs to %d outputs. ", Saig_ManPoNum(pAig), Saig_ManPoNum(pPart) ); Abc_PrintTime( 1, "Time", clock() - clk ); -// Aig_ManStop( pPart ); + if ( fVerbose && *pvPosEquivs ) + { + printf( "Nontrivial classes:\n" ); + Vec_VecPrintInt( (Vec_Vec_t *)*pvPosEquivs, 1 ); + } +// Aig_ManStopP( &pPart ); return pPart; } |