abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
extraUtilPerm.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "misc/vec/vec.h"
#include "aig/gia/gia.h"

Go to the source code of this file.

Data Structures

struct  Abc_ZddObj_
 
struct  Abc_ZddEnt_
 
struct  Abc_ZddMan_
 

Typedefs

typedef struct Abc_ZddObj_ Abc_ZddObj
 
typedef struct Abc_ZddEnt_ Abc_ZddEnt
 
typedef struct Abc_ZddMan_ Abc_ZddMan
 

Enumerations

enum  Abc_ZddOper {
  ABC_ZDD_OPER_NONE, ABC_ZDD_OPER_DIFF, ABC_ZDD_OPER_UNION, ABC_ZDD_OPER_MIN_UNION,
  ABC_ZDD_OPER_INTER, ABC_ZDD_OPER_PERM, ABC_ZDD_OPER_PERM_PROD, ABC_ZDD_OPER_COF0,
  ABC_ZDD_OPER_COF1, ABC_ZDD_OPER_THRESH, ABC_ZDD_OPER_DOT_PROD, ABC_ZDD_OPER_DOT_PROD_6,
  ABC_ZDD_OPER_INSERT, ABC_ZDD_OPER_PATHS, ABC_ZDD_OPER_NODES, ABC_ZDD_OPER_ITE
}
 DECLARATIONS ///. More...
 

Functions

static int Abc_ZddIthVar (int i)
 
static unsigned Abc_ZddHash (int Arg0, int Arg1, int Arg2)
 
static Abc_ZddObjAbc_ZddNode (Abc_ZddMan *p, int i)
 
static int Abc_ZddObjId (Abc_ZddMan *p, Abc_ZddObj *pObj)
 
static int Abc_ZddObjVar (Abc_ZddMan *p, int i)
 
static void Abc_ZddSetVarIJ (Abc_ZddMan *p, int i, int j, int v)
 
static int Abc_ZddVarIJ (Abc_ZddMan *p, int i, int j)
 
static int Abc_ZddVarsClash (Abc_ZddMan *p, int v0, int v1)
 
static int Abc_ZddCacheLookup (Abc_ZddMan *p, int Arg0, int Arg1, int Arg2)
 FUNCTION DEFINITIONS ///. More...
 
static int Abc_ZddCacheInsert (Abc_ZddMan *p, int Arg0, int Arg1, int Arg2, int Res)
 
static int Abc_ZddUniqueLookup (Abc_ZddMan *p, int Var, int True, int False)
 
static int Abc_ZddUniqueCreate (Abc_ZddMan *p, int Var, int True, int False)
 
int Abc_ZddBuildSet (Abc_ZddMan *p, int *pSet, int Size)
 
Abc_ZddManAbc_ZddManAlloc (int nVars, int nObjs)
 
void Abc_ZddManCreatePerms (Abc_ZddMan *p, int nPermSize)
 
void Abc_ZddManFree (Abc_ZddMan *p)
 
int Abc_ZddDiff (Abc_ZddMan *p, int a, int b)
 
int Abc_ZddUnion (Abc_ZddMan *p, int a, int b)
 
int Abc_ZddMinUnion (Abc_ZddMan *p, int a, int b)
 
int Abc_ZddIntersect (Abc_ZddMan *p, int a, int b)
 
int Abc_ZddCof0 (Abc_ZddMan *p, int a, int Var)
 
int Abc_ZddCof1 (Abc_ZddMan *p, int a, int Var)
 
int Abc_ZddCountPaths (Abc_ZddMan *p, int a)
 
int Abc_ZddCount_rec (Abc_ZddMan *p, int i)
 
void Abc_ZddUnmark_rec (Abc_ZddMan *p, int i)
 
int Abc_ZddCountNodes (Abc_ZddMan *p, int i)
 
int Abc_ZddCountNodesArray (Abc_ZddMan *p, Vec_Int_t *vNodes)
 
int Abc_ZddThresh (Abc_ZddMan *p, int a, int b)
 
int Abc_ZddDotProduct (Abc_ZddMan *p, int a, int b)
 
int Abc_ZddDotMinProduct6 (Abc_ZddMan *p, int a, int b)
 
int Abc_ZddPerm (Abc_ZddMan *p, int a, int Var)
 
int Abc_ZddPermProduct (Abc_ZddMan *p, int a, int b)
 
void Abc_ZddPermPrint (int *pPerm, int Size)
 
void Abc_ZddCombPrint (int *pComb, int nTrans)
 
int Abc_ZddPerm2Comb (int *pPerm, int Size, int *pComb)
 
void Abc_ZddComb2Perm (int *pComb, int nTrans, int *pPerm, int Size)
 
void Abc_ZddPermCombTest ()
 
void Abc_ZddPrint_rec (Abc_ZddMan *p, int a, int *pPath, int Size)
 
void Abc_ZddPrint (Abc_ZddMan *p, int a)
 
void Abc_ZddPrintTest (Abc_ZddMan *p)
 
void Abc_ZddGiaTest (Gia_Man_t *pGia)
 
void Abc_ZddPermTestInt (Abc_ZddMan *p)
 
void Abc_ZddPermTest ()
 
void Abc_EnumerateCubeStatesZdd ()
 

Typedef Documentation

typedef struct Abc_ZddEnt_ Abc_ZddEnt

Definition at line 63 of file extraUtilPerm.c.

typedef struct Abc_ZddMan_ Abc_ZddMan

Definition at line 72 of file extraUtilPerm.c.

typedef struct Abc_ZddObj_ Abc_ZddObj

Definition at line 54 of file extraUtilPerm.c.

Enumeration Type Documentation

DECLARATIONS ///.

CFile****************************************************************

FileName [extraUtilPerm.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:
extraUtilPerm.c,v 1.0 2003/02/01 00:00:00 alanmi Exp

]

Enumerator
ABC_ZDD_OPER_NONE 
ABC_ZDD_OPER_DIFF 
ABC_ZDD_OPER_UNION 
ABC_ZDD_OPER_MIN_UNION 
ABC_ZDD_OPER_INTER 
ABC_ZDD_OPER_PERM 
ABC_ZDD_OPER_PERM_PROD 
ABC_ZDD_OPER_COF0 
ABC_ZDD_OPER_COF1 
ABC_ZDD_OPER_THRESH 
ABC_ZDD_OPER_DOT_PROD 
ABC_ZDD_OPER_DOT_PROD_6 
ABC_ZDD_OPER_INSERT 
ABC_ZDD_OPER_PATHS 
ABC_ZDD_OPER_NODES 
ABC_ZDD_OPER_ITE 

Definition at line 34 of file extraUtilPerm.c.

Function Documentation

void Abc_EnumerateCubeStatesZdd ( )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 845 of file extraUtilPerm.c.

846 {
847  int pXYZ[3][9][2] = {
848  { {3, 5}, {3,17}, {3,15}, {1, 6}, {1,16}, {1,14}, {2, 4}, {2,18}, {2,13} },
849  { {2,14}, {2,24}, {2,12}, {3,13}, {3,23}, {3,10}, {1,15}, {1,22}, {1,11} },
850  { {1,10}, {1, 7}, {1, 4}, {3,12}, {3, 9}, {3, 6}, {2,11}, {2, 8}, {2, 5} } };
851 #ifdef WIN32
852  int LogObj = 24;
853 #else
854  int LogObj = 27;
855 #endif
856  Abc_ZddMan * p;
857  int i, k, pComb[9], pPerm[24], nSize;
858  int ZddTurn1, ZddTurn2, ZddTurn3, ZddTurns, ZddAll;
859  abctime clk = Abc_Clock();
860  printf( "Enumerating states of 2x2x2 cube.\n" );
861  p = Abc_ZddManAlloc( 24 * 23 / 2, 1 << LogObj ); // finished with 2^27 (4 GB)
862  Abc_ZddManCreatePerms( p, 24 );
863  // init state
864  printf( "Iter %2d -> %8d Nodes = %7d Used = %10d ", 0, 1, 0, 2 );
865  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
866  // first 9 states
867  ZddTurns = 1;
868  for ( i = 0; i < 3; i++ )
869  {
870  for ( k = 0; k < 24; k++ )
871  pPerm[k] = k;
872  for ( k = 0; k < 9; k++ )
873  ABC_SWAP( int, pPerm[pXYZ[i][k][0]-1], pPerm[pXYZ[i][k][1]-1] );
874  nSize = Abc_ZddPerm2Comb( pPerm, 24, pComb );
875  assert( nSize == 9 );
876  for ( k = 0; k < 9; k++ )
877  pComb[k] = Abc_ZddVarIJ( p, pComb[k] >> 16, pComb[k] & 0xffff );
878  // add first turn
879  ZddTurn1 = Abc_ZddBuildSet( p, pComb, 9 );
880  ZddTurns = Abc_ZddUnion( p, ZddTurns, ZddTurn1 );
881  //Abc_ZddPrint( p, ZddTurn1 );
882  // add second turn
883  ZddTurn2 = Abc_ZddPermProduct( p, ZddTurn1, ZddTurn1 );
884  ZddTurns = Abc_ZddUnion( p, ZddTurns, ZddTurn2 );
885  //Abc_ZddPrint( p, ZddTurn2 );
886  // add third turn
887  ZddTurn3 = Abc_ZddPermProduct( p, ZddTurn2, ZddTurn1 );
888  ZddTurns = Abc_ZddUnion( p, ZddTurns, ZddTurn3 );
889  //Abc_ZddPrint( p, ZddTurn3 );
890  //printf( "\n" );
891  }
892  //Abc_ZddPrint( p, ZddTurns );
893  printf( "Iter %2d -> %8d Nodes = %7d Used = %10d ", 1, Abc_ZddCountPaths(p, ZddTurns), Abc_ZddCountNodes(p, ZddTurns), p->nObjs );
894  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
895  // other states
896  ZddAll = ZddTurns;
897  for ( i = 2; i <= 100; i++ )
898  {
899  int ZddAllPrev = ZddAll;
900  ZddAll = Abc_ZddPermProduct( p, ZddAll, ZddTurns );
901  printf( "Iter %2d -> %8d Nodes = %7d Used = %10d ", i, Abc_ZddCountPaths(p, ZddAll), Abc_ZddCountNodes(p, ZddAll), p->nObjs );
902  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
903  if ( ZddAllPrev == ZddAll )
904  break;
905  }
906  Abc_ZddManFree( p );
907 }
int Abc_ZddUnion(Abc_ZddMan *p, int a, int b)
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static abctime Abc_Clock()
Definition: abc_global.h:279
#define ABC_SWAP(Type, a, b)
Definition: abc_global.h:218
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
int Abc_ZddPermProduct(Abc_ZddMan *p, int a, int b)
int Abc_ZddBuildSet(Abc_ZddMan *p, int *pSet, int Size)
static int pPerm[13719]
Definition: rwrTemp.c:32
int Abc_ZddCountPaths(Abc_ZddMan *p, int a)
int Abc_ZddPerm2Comb(int *pPerm, int Size, int *pComb)
void Abc_ZddManCreatePerms(Abc_ZddMan *p, int nPermSize)
void Abc_ZddManFree(Abc_ZddMan *p)
#define assert(ex)
Definition: util_old.h:213
static int Abc_ZddVarIJ(Abc_ZddMan *p, int i, int j)
Abc_ZddMan * Abc_ZddManAlloc(int nVars, int nObjs)
ABC_INT64_T abctime
Definition: abc_global.h:278
int Abc_ZddCountNodes(Abc_ZddMan *p, int i)
int Abc_ZddBuildSet ( Abc_ZddMan p,
int *  pSet,
int  Size 
)

Definition at line 164 of file extraUtilPerm.c.

165 {
166  int i, Res = 1;
167  Vec_IntSelectSort( pSet, Size );
168  for ( i = Size - 1; i >= 0; i-- )
169  Res = Abc_ZddUniqueCreate( p, pSet[i], Res, 0 );
170  return Res;
171 }
static int Abc_ZddUniqueCreate(Abc_ZddMan *p, int Var, int True, int False)
static void Vec_IntSelectSort(int *pArray, int nSize)
Definition: vecInt.h:1740
static int Abc_ZddCacheInsert ( Abc_ZddMan p,
int  Arg0,
int  Arg1,
int  Arg2,
int  Res 
)
inlinestatic

Definition at line 125 of file extraUtilPerm.c.

126 {
127  Abc_ZddEnt * pEnt = p->pCache + (Abc_ZddHash(Arg0, Arg1, Arg2) & p->nCacheMask);
128  pEnt->Arg0 = Arg0; pEnt->Arg1 = Arg1; pEnt->Arg2 = Arg2; pEnt->Res = Res;
129  p->nCacheMisses++;
130  assert( Res >= 0 );
131  return Res;
132 }
static unsigned Abc_ZddHash(int Arg0, int Arg1, int Arg2)
Definition: extraUtilPerm.c:94
Abc_ZddEnt * pCache
Definition: extraUtilPerm.c:83
unsigned nCacheMask
Definition: extraUtilPerm.c:80
#define assert(ex)
Definition: util_old.h:213
static int Abc_ZddCacheLookup ( Abc_ZddMan p,
int  Arg0,
int  Arg1,
int  Arg2 
)
inlinestatic

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 119 of file extraUtilPerm.c.

120 {
121  Abc_ZddEnt * pEnt = p->pCache + (Abc_ZddHash(Arg0, Arg1, Arg2) & p->nCacheMask);
122  p->nCacheLookups++;
123  return (pEnt->Arg0 == Arg0 && pEnt->Arg1 == Arg1 && pEnt->Arg2 == Arg2) ? pEnt->Res : -1;
124 }
static unsigned Abc_ZddHash(int Arg0, int Arg1, int Arg2)
Definition: extraUtilPerm.c:94
Abc_ZddEnt * pCache
Definition: extraUtilPerm.c:83
unsigned nCacheMask
Definition: extraUtilPerm.c:80
int Abc_ZddCof0 ( Abc_ZddMan p,
int  a,
int  Var 
)

Definition at line 348 of file extraUtilPerm.c.

349 {
350  Abc_ZddObj * A;
351  int r0, r1, r;
352  if ( a < 2 ) return a;
353  A = Abc_ZddNode( p, a );
354  if ( (int)A->Var > Var )
355  return a;
356  if ( (r = Abc_ZddCacheLookup(p, a, Var, ABC_ZDD_OPER_COF0)) >= 0 )
357  return r;
358  if ( (int)A->Var < Var )
359  r0 = Abc_ZddCof0( p, A->False, Var ),
360  r1 = Abc_ZddCof0( p, A->True, Var ),
361  r = Abc_ZddUniqueCreate( p, A->Var, r1, r0 );
362  else
363  r = Abc_ZddCof0( p, A->False, Var );
364  return Abc_ZddCacheInsert( p, a, Var, ABC_ZDD_OPER_COF0, r );
365 }
unsigned True
Definition: extraUtilPerm.c:59
static int Abc_ZddCacheInsert(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2, int Res)
static int Abc_ZddUniqueCreate(Abc_ZddMan *p, int Var, int True, int False)
unsigned Var
Definition: extraUtilPerm.c:57
static int Abc_ZddCacheLookup(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2)
FUNCTION DEFINITIONS ///.
unsigned False
Definition: extraUtilPerm.c:60
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
int Var
Definition: SolverTypes.h:42
int Abc_ZddCof0(Abc_ZddMan *p, int a, int Var)
int Abc_ZddCof1 ( Abc_ZddMan p,
int  a,
int  Var 
)

Definition at line 366 of file extraUtilPerm.c.

367 {
368  Abc_ZddObj * A;
369  int r0, r1, r;
370  if ( a < 2 ) return a;
371  A = Abc_ZddNode( p, a );
372  if ( (int)A->Var > Var )
373  return a;
374  if ( (r = Abc_ZddCacheLookup(p, a, Var, ABC_ZDD_OPER_COF1)) >= 0 )
375  return r;
376  if ( (int)A->Var < Var )
377  r0 = Abc_ZddCof1( p, A->False, Var ),
378  r1 = Abc_ZddCof1( p, A->True, Var );
379  else
380  r0 = 0,
381  r1 = Abc_ZddCof1( p, A->True, Var );
382  r = Abc_ZddUniqueCreate( p, A->Var, r1, r0 );
383  return Abc_ZddCacheInsert( p, a, Var, ABC_ZDD_OPER_COF1, r );
384 }
unsigned True
Definition: extraUtilPerm.c:59
static int Abc_ZddCacheInsert(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2, int Res)
static int Abc_ZddUniqueCreate(Abc_ZddMan *p, int Var, int True, int False)
unsigned Var
Definition: extraUtilPerm.c:57
static int Abc_ZddCacheLookup(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2)
FUNCTION DEFINITIONS ///.
unsigned False
Definition: extraUtilPerm.c:60
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
int Var
Definition: SolverTypes.h:42
int Abc_ZddCof1(Abc_ZddMan *p, int a, int Var)
void Abc_ZddComb2Perm ( int *  pComb,
int  nTrans,
int *  pPerm,
int  Size 
)

Definition at line 651 of file extraUtilPerm.c.

652 {
653  int v;
654  for ( v = 0; v < Size; v++ )
655  pPerm[v] = v;
656  for ( v = nTrans-1; v >= 0; v-- )
657  ABC_SWAP( int, pPerm[pComb[v] >> 16], pPerm[pComb[v] & 0xffff] );
658 }
#define ABC_SWAP(Type, a, b)
Definition: abc_global.h:218
static int pPerm[13719]
Definition: rwrTemp.c:32
void Abc_ZddCombPrint ( int *  pComb,
int  nTrans 
)

Definition at line 627 of file extraUtilPerm.c.

628 {
629  int i;
630  if ( nTrans == 0 )
631  printf( "Empty set" );
632  for ( i = 0; i < nTrans; i++ )
633  printf( "(%d %d)", pComb[i] >> 16, pComb[i] & 0xffff );
634  printf( "\n" );
635 }
int Abc_ZddCount_rec ( Abc_ZddMan p,
int  i 
)

Definition at line 409 of file extraUtilPerm.c.

410 {
411  Abc_ZddObj * A;
412  if ( i < 2 )
413  return 0;
414  A = Abc_ZddNode( p, i );
415  if ( A->Mark )
416  return 0;
417  A->Mark = 1;
418  return 1 + Abc_ZddCount_rec(p, A->False) + Abc_ZddCount_rec(p, A->True);
419 }
unsigned Mark
Definition: extraUtilPerm.c:58
int Abc_ZddCount_rec(Abc_ZddMan *p, int i)
unsigned True
Definition: extraUtilPerm.c:59
unsigned False
Definition: extraUtilPerm.c:60
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
int Abc_ZddCountNodes ( Abc_ZddMan p,
int  i 
)

Definition at line 432 of file extraUtilPerm.c.

433 {
434  int Count = Abc_ZddCount_rec( p, i );
435  Abc_ZddUnmark_rec( p, i );
436  return Count;
437 }
int Abc_ZddCount_rec(Abc_ZddMan *p, int i)
void Abc_ZddUnmark_rec(Abc_ZddMan *p, int i)
int Abc_ZddCountNodesArray ( Abc_ZddMan p,
Vec_Int_t vNodes 
)

Definition at line 438 of file extraUtilPerm.c.

439 {
440  int i, Id, Count = 0;
441  Vec_IntForEachEntry( vNodes, Id, i )
442  Count += Abc_ZddCount_rec( p, Id );
443  Vec_IntForEachEntry( vNodes, Id, i )
444  Abc_ZddUnmark_rec( p, Id );
445  return Count;
446 }
int Abc_ZddCount_rec(Abc_ZddMan *p, int i)
void Abc_ZddUnmark_rec(Abc_ZddMan *p, int i)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
int Abc_ZddCountPaths ( Abc_ZddMan p,
int  a 
)

Definition at line 385 of file extraUtilPerm.c.

386 {
387  Abc_ZddObj * A;
388  int r;
389  if ( a < 2 ) return a;
390  if ( (r = Abc_ZddCacheLookup(p, a, 0, ABC_ZDD_OPER_PATHS)) >= 0 )
391  return r;
392  A = Abc_ZddNode( p, a );
393  r = Abc_ZddCountPaths( p, A->False ) + Abc_ZddCountPaths( p, A->True );
394  return Abc_ZddCacheInsert( p, a, 0, ABC_ZDD_OPER_PATHS, r );
395 }
unsigned True
Definition: extraUtilPerm.c:59
static int Abc_ZddCacheInsert(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2, int Res)
static int Abc_ZddCacheLookup(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2)
FUNCTION DEFINITIONS ///.
unsigned False
Definition: extraUtilPerm.c:60
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
int Abc_ZddCountPaths(Abc_ZddMan *p, int a)
int Abc_ZddDiff ( Abc_ZddMan p,
int  a,
int  b 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 253 of file extraUtilPerm.c.

254 {
255  Abc_ZddObj * A, * B;
256  int r0, r1, r;
257  if ( a == 0 ) return 0;
258  if ( b == 0 ) return a;
259  if ( a == b ) return 0;
260  if ( (r = Abc_ZddCacheLookup(p, a, b, ABC_ZDD_OPER_DIFF)) >= 0 )
261  return r;
262  A = Abc_ZddNode( p, a );
263  B = Abc_ZddNode( p, b );
264  if ( A->Var < B->Var )
265  r0 = Abc_ZddDiff( p, A->False, b ),
266  r = Abc_ZddUniqueCreate( p, A->Var, A->True, r0 );
267  else if ( A->Var > B->Var )
268  r = Abc_ZddDiff( p, a, B->False );
269  else
270  r0 = Abc_ZddDiff( p, A->False, B->False ),
271  r1 = Abc_ZddDiff( p, A->True, B->True ),
272  r = Abc_ZddUniqueCreate( p, A->Var, A->True, r0 );
273  return Abc_ZddCacheInsert( p, a, b, ABC_ZDD_OPER_DIFF, r );
274 }
int Abc_ZddDiff(Abc_ZddMan *p, int a, int b)
unsigned True
Definition: extraUtilPerm.c:59
static int Abc_ZddCacheInsert(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2, int Res)
static int Abc_ZddUniqueCreate(Abc_ZddMan *p, int Var, int True, int False)
unsigned Var
Definition: extraUtilPerm.c:57
static int Abc_ZddCacheLookup(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2)
FUNCTION DEFINITIONS ///.
unsigned False
Definition: extraUtilPerm.c:60
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
int Abc_ZddDotMinProduct6 ( Abc_ZddMan p,
int  a,
int  b 
)

Definition at line 501 of file extraUtilPerm.c.

502 {
503  Abc_ZddObj * A, * B;
504  int r0, r1, b2, t1, t2, r;
505  if ( a == 0 ) return 0;
506  if ( b == 0 ) return 0;
507  if ( a == 1 ) return b;
508  if ( b == 1 ) return a;
509  if ( a > b ) return Abc_ZddDotMinProduct6( p, b, a );
510  if ( (r = Abc_ZddCacheLookup(p, a, b, ABC_ZDD_OPER_DOT_PROD_6)) >= 0 )
511  return r;
512  A = Abc_ZddNode( p, a );
513  B = Abc_ZddNode( p, b );
514  if ( A->Var < B->Var )
515  r0 = Abc_ZddDotMinProduct6( p, A->False, b ),
516  r1 = Abc_ZddDotMinProduct6( p, A->True, b );
517  else if ( A->Var > B->Var )
518  r0 = Abc_ZddDotMinProduct6( p, a, B->False ),
519  r1 = Abc_ZddDotMinProduct6( p, a, B->True );
520  else
521  r0 = Abc_ZddDotMinProduct6( p, A->False, B->False ),
522  b2 = Abc_ZddMinUnion( p, B->False, B->True ),
523  t1 = Abc_ZddDotMinProduct6( p, A->True, b2 ),
524  t2 = Abc_ZddDotMinProduct6( p, A->False, B->True ),
525  r1 = Abc_ZddMinUnion( p, t1, t2 );
526  r1 = Abc_ZddThresh( p, r1, 5 ),
527  r1 = Abc_ZddDiff( p, r1, r0 );
528  r = Abc_ZddUniqueCreate( p, Abc_MinInt(A->Var, B->Var), r1, r0 );
529  return Abc_ZddCacheInsert( p, a, b, ABC_ZDD_OPER_DOT_PROD_6, r );
530 }
int Abc_ZddDiff(Abc_ZddMan *p, int a, int b)
unsigned True
Definition: extraUtilPerm.c:59
static int Abc_ZddCacheInsert(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2, int Res)
static int Abc_ZddUniqueCreate(Abc_ZddMan *p, int Var, int True, int False)
unsigned Var
Definition: extraUtilPerm.c:57
static int Abc_MinInt(int a, int b)
Definition: abc_global.h:239
int Abc_ZddThresh(Abc_ZddMan *p, int a, int b)
static int Abc_ZddCacheLookup(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2)
FUNCTION DEFINITIONS ///.
unsigned False
Definition: extraUtilPerm.c:60
int Abc_ZddDotMinProduct6(Abc_ZddMan *p, int a, int b)
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
int Abc_ZddMinUnion(Abc_ZddMan *p, int a, int b)
int Abc_ZddDotProduct ( Abc_ZddMan p,
int  a,
int  b 
)

Definition at line 473 of file extraUtilPerm.c.

474 {
475  Abc_ZddObj * A, * B;
476  int r0, r1, b2, t1, t2, r;
477  if ( a == 0 ) return 0;
478  if ( b == 0 ) return 0;
479  if ( a == 1 ) return b;
480  if ( b == 1 ) return a;
481  if ( a > b ) return Abc_ZddDotProduct( p, b, a );
482  if ( (r = Abc_ZddCacheLookup(p, a, b, ABC_ZDD_OPER_DOT_PROD)) >= 0 )
483  return r;
484  A = Abc_ZddNode( p, a );
485  B = Abc_ZddNode( p, b );
486  if ( A->Var < B->Var )
487  r0 = Abc_ZddDotProduct( p, A->False, b ),
488  r1 = Abc_ZddDotProduct( p, A->True, b );
489  else if ( A->Var > B->Var )
490  r0 = Abc_ZddDotProduct( p, a, B->False ),
491  r1 = Abc_ZddDotProduct( p, a, B->True );
492  else
493  r0 = Abc_ZddDotProduct( p, A->False, B->False ),
494  b2 = Abc_ZddUnion( p, B->False, B->True ),
495  t1 = Abc_ZddDotProduct( p, A->True, b2 ),
496  t2 = Abc_ZddDotProduct( p, A->False, B->True ),
497  r1 = Abc_ZddUnion( p, t1, t2 );
498  r = Abc_ZddUniqueCreate( p, Abc_MinInt(A->Var, B->Var), r1, r0 );
499  return Abc_ZddCacheInsert( p, a, b, ABC_ZDD_OPER_DOT_PROD, r );
500 }
int Abc_ZddUnion(Abc_ZddMan *p, int a, int b)
unsigned True
Definition: extraUtilPerm.c:59
static int Abc_ZddCacheInsert(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2, int Res)
static int Abc_ZddUniqueCreate(Abc_ZddMan *p, int Var, int True, int False)
int Abc_ZddDotProduct(Abc_ZddMan *p, int a, int b)
unsigned Var
Definition: extraUtilPerm.c:57
static int Abc_MinInt(int a, int b)
Definition: abc_global.h:239
static int Abc_ZddCacheLookup(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2)
FUNCTION DEFINITIONS ///.
unsigned False
Definition: extraUtilPerm.c:60
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
void Abc_ZddGiaTest ( Gia_Man_t pGia)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 743 of file extraUtilPerm.c.

744 {
745  Abc_ZddMan * p;
746  Gia_Obj_t * pObj;
747  Vec_Int_t * vNodes;
748  int i, r, Paths = 0;
749  p = Abc_ZddManAlloc( Gia_ManObjNum(pGia), 1 << 24 ); // 576 MB (36 B/node)
750  Gia_ManFillValue( pGia );
751  Gia_ManForEachCi( pGia, pObj, i )
752  pObj->Value = Abc_ZddIthVar( Gia_ObjId(pGia, pObj) );
753  vNodes = Vec_IntAlloc( Gia_ManAndNum(pGia) );
754  Gia_ManForEachAnd( pGia, pObj, i )
755  {
756  r = Abc_ZddDotMinProduct6( p, Gia_ObjFanin0(pObj)->Value, Gia_ObjFanin1(pObj)->Value );
757  r = Abc_ZddUnion( p, r, Abc_ZddIthVar(i) );
758  pObj->Value = r;
759  Vec_IntPush( vNodes, r );
760  // print
761 // printf( "Node %d:\n", i );
762 // Abc_ZddPrint( p, r );
763 // printf( "Node %d ZddNodes = %d\n", i, Abc_ZddCountNodes(p, r) );
764  }
765  Gia_ManForEachAnd( pGia, pObj, i )
766  Paths += Abc_ZddCountPaths(p, pObj->Value);
767  printf( "Paths = %d. Shared nodes = %d.\n", Paths, Abc_ZddCountNodesArray(p, vNodes) );
768  Vec_IntFree( vNodes );
769  Abc_ZddManFree( p );
770 }
int Abc_ZddUnion(Abc_ZddMan *p, int a, int b)
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Abc_ZddIthVar(int i)
Definition: extraUtilPerm.c:93
Definition: gia.h:75
#define Gia_ManForEachCi(p, pObj, i)
Definition: gia.h:1016
static int Gia_ManAndNum(Gia_Man_t *p)
Definition: gia.h:389
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
int Abc_ZddCountNodesArray(Abc_ZddMan *p, Vec_Int_t *vNodes)
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
void Gia_ManFillValue(Gia_Man_t *p)
Definition: giaUtil.c:328
int Abc_ZddDotMinProduct6(Abc_ZddMan *p, int a, int b)
int Abc_ZddCountPaths(Abc_ZddMan *p, int a)
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
void Abc_ZddManFree(Abc_ZddMan *p)
Abc_ZddMan * Abc_ZddManAlloc(int nVars, int nObjs)
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
static unsigned Abc_ZddHash ( int  Arg0,
int  Arg1,
int  Arg2 
)
inlinestatic

Definition at line 94 of file extraUtilPerm.c.

94 { return 12582917 * Arg0 + 4256249 * Arg1 + 741457 * Arg2; }
int Abc_ZddIntersect ( Abc_ZddMan p,
int  a,
int  b 
)

Definition at line 324 of file extraUtilPerm.c.

325 {
326  Abc_ZddObj * A, * B;
327  int r0, r1, r;
328  if ( a == 0 ) return 0;
329  if ( b == 0 ) return 0;
330  if ( a == b ) return a;
331  if ( a > b ) return Abc_ZddIntersect( p, b, a );
332  if ( (r = Abc_ZddCacheLookup(p, a, b, ABC_ZDD_OPER_INTER)) >= 0 )
333  return r;
334  A = Abc_ZddNode( p, a );
335  B = Abc_ZddNode( p, b );
336  if ( A->Var < B->Var )
337  r0 = Abc_ZddIntersect( p, A->False, b ),
338  r1 = A->True;
339  else if ( A->Var > B->Var )
340  r0 = Abc_ZddIntersect( p, a, B->False ),
341  r1 = B->True;
342  else
343  r0 = Abc_ZddIntersect( p, A->False, B->False ),
344  r1 = Abc_ZddIntersect( p, A->True, B->True );
345  r = Abc_ZddUniqueCreate( p, Abc_MinInt(A->Var, B->Var), r1, r0 );
346  return Abc_ZddCacheInsert( p, a, b, ABC_ZDD_OPER_INTER, r );
347 }
unsigned True
Definition: extraUtilPerm.c:59
static int Abc_ZddCacheInsert(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2, int Res)
static int Abc_ZddUniqueCreate(Abc_ZddMan *p, int Var, int True, int False)
unsigned Var
Definition: extraUtilPerm.c:57
static int Abc_MinInt(int a, int b)
Definition: abc_global.h:239
static int Abc_ZddCacheLookup(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2)
FUNCTION DEFINITIONS ///.
int Abc_ZddIntersect(Abc_ZddMan *p, int a, int b)
unsigned False
Definition: extraUtilPerm.c:60
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
static int Abc_ZddIthVar ( int  i)
inlinestatic

Definition at line 93 of file extraUtilPerm.c.

93 { return i + 2; }
Abc_ZddMan* Abc_ZddManAlloc ( int  nVars,
int  nObjs 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 184 of file extraUtilPerm.c.

185 {
186  Abc_ZddMan * p; int i;
187  p = ABC_CALLOC( Abc_ZddMan, 1 );
188  p->nVars = nVars;
189  p->nObjsAlloc = nObjs;
190  p->nUniqueMask = (1 << Abc_Base2Log(nObjs)) - 1;
191  p->nCacheMask = (1 << Abc_Base2Log(nObjs)) - 1;
192  p->pUnique = ABC_CALLOC( int, p->nUniqueMask + 1 );
193  p->pNexts = ABC_CALLOC( int, p->nObjsAlloc );
194  p->pCache = ABC_CALLOC( Abc_ZddEnt, p->nCacheMask + 1 );
196  p->nObjs = 2;
197  memset( p->pObjs, 0xff, sizeof(Abc_ZddObj) * 2 );
198  p->pObjs[0].Var = nVars;
199  p->pObjs[1].Var = nVars;
200  for ( i = 0; i < nVars; i++ )
201  Abc_ZddUniqueCreate( p, i, 1, 0 );
202  assert( p->nObjs == nVars + 2 );
203  p->nMemory = sizeof(Abc_ZddMan)/4 +
204  p->nUniqueMask + 1 + p->nObjsAlloc +
205  (p->nCacheMask + 1) * sizeof(Abc_ZddEnt)/4 +
206  p->nObjsAlloc * sizeof(Abc_ZddObj)/4;
207  return p;
208 }
char * memset()
Abc_ZddObj * pObjs
Definition: extraUtilPerm.c:84
struct Abc_ZddEnt_ Abc_ZddEnt
Definition: extraUtilPerm.c:63
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Abc_ZddEnt * pCache
Definition: extraUtilPerm.c:83
static int Abc_ZddUniqueCreate(Abc_ZddMan *p, int Var, int True, int False)
unsigned Var
Definition: extraUtilPerm.c:57
unsigned nUniqueMask
Definition: extraUtilPerm.c:79
unsigned nCacheMask
Definition: extraUtilPerm.c:80
static int Abc_Base2Log(unsigned n)
Definition: abc_global.h:251
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
#define assert(ex)
Definition: util_old.h:213
struct Abc_ZddMan_ Abc_ZddMan
Definition: extraUtilPerm.c:72
void Abc_ZddManCreatePerms ( Abc_ZddMan p,
int  nPermSize 
)

Definition at line 209 of file extraUtilPerm.c.

210 {
211  int i, j, v = 0;
212  assert( 2 * p->nVars == nPermSize * (nPermSize - 1) );
213  assert( p->nPermSize == 0 );
214  p->nPermSize = nPermSize;
215  p->pV2TI = ABC_FALLOC( int, p->nVars );
216  p->pV2TJ = ABC_FALLOC( int, p->nVars );
217  p->pT2V = ABC_FALLOC( int, p->nPermSize * p->nPermSize );
218  for ( i = 0; i < nPermSize; i++ )
219  for ( j = i + 1; j < nPermSize; j++ )
220  {
221  p->pV2TI[v] = i;
222  p->pV2TJ[v] = j;
223  Abc_ZddSetVarIJ( p, i, j, v++ );
224  }
225  assert( v == p->nVars );
226 }
static void Abc_ZddSetVarIJ(Abc_ZddMan *p, int i, int j, int v)
#define assert(ex)
Definition: util_old.h:213
#define ABC_FALLOC(type, num)
Definition: abc_global.h:231
void Abc_ZddManFree ( Abc_ZddMan p)

Definition at line 227 of file extraUtilPerm.c.

228 {
229  printf( "ZDD stats: Var = %d Obj = %d Alloc = %d Hit = %d Miss = %d ",
231  printf( "Mem = %.2f MB\n", 4.0*(int)(p->nMemory/(1<<20)) );
232  ABC_FREE( p->pT2V );
233  ABC_FREE( p->pV2TI );
234  ABC_FREE( p->pV2TJ );
235  ABC_FREE( p->pUnique );
236  ABC_FREE( p->pNexts );
237  ABC_FREE( p->pCache );
238  ABC_FREE( p->pObjs );
239  ABC_FREE( p );
240 }
Abc_ZddObj * pObjs
Definition: extraUtilPerm.c:84
Abc_ZddEnt * pCache
Definition: extraUtilPerm.c:83
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Abc_ZddMinUnion ( Abc_ZddMan p,
int  a,
int  b 
)

Definition at line 299 of file extraUtilPerm.c.

300 {
301  Abc_ZddObj * A, * B;
302  int r0, r1, r;
303  if ( a == 0 ) return b;
304  if ( b == 0 ) return a;
305  if ( a == b ) return a;
306  if ( a > b ) return Abc_ZddMinUnion( p, b, a );
307  if ( (r = Abc_ZddCacheLookup(p, a, b, ABC_ZDD_OPER_MIN_UNION)) >= 0 )
308  return r;
309  A = Abc_ZddNode( p, a );
310  B = Abc_ZddNode( p, b );
311  if ( A->Var < B->Var )
312  r0 = Abc_ZddMinUnion( p, A->False, b ),
313  r1 = A->True;
314  else if ( A->Var > B->Var )
315  r0 = Abc_ZddMinUnion( p, a, B->False ),
316  r1 = B->True;
317  else
318  r0 = Abc_ZddMinUnion( p, A->False, B->False ),
319  r1 = Abc_ZddMinUnion( p, A->True, B->True );
320  r1 = Abc_ZddDiff( p, r1, r0 ); // assume args are minimal
321  r = Abc_ZddUniqueCreate( p, Abc_MinInt(A->Var, B->Var), r1, r0 );
322  return Abc_ZddCacheInsert( p, a, b, ABC_ZDD_OPER_MIN_UNION, r );
323 }
int Abc_ZddDiff(Abc_ZddMan *p, int a, int b)
unsigned True
Definition: extraUtilPerm.c:59
static int Abc_ZddCacheInsert(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2, int Res)
static int Abc_ZddUniqueCreate(Abc_ZddMan *p, int Var, int True, int False)
unsigned Var
Definition: extraUtilPerm.c:57
static int Abc_MinInt(int a, int b)
Definition: abc_global.h:239
static int Abc_ZddCacheLookup(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2)
FUNCTION DEFINITIONS ///.
unsigned False
Definition: extraUtilPerm.c:60
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
int Abc_ZddMinUnion(Abc_ZddMan *p, int a, int b)
static Abc_ZddObj* Abc_ZddNode ( Abc_ZddMan p,
int  i 
)
inlinestatic

Definition at line 96 of file extraUtilPerm.c.

96 { return p->pObjs + i; }
Abc_ZddObj * pObjs
Definition: extraUtilPerm.c:84
static int Abc_ZddObjId ( Abc_ZddMan p,
Abc_ZddObj pObj 
)
inlinestatic

Definition at line 97 of file extraUtilPerm.c.

97 { return pObj - p->pObjs; }
Abc_ZddObj * pObjs
Definition: extraUtilPerm.c:84
static int Abc_ZddObjVar ( Abc_ZddMan p,
int  i 
)
inlinestatic

Definition at line 98 of file extraUtilPerm.c.

98 { return Abc_ZddNode(p, i)->Var; }
unsigned Var
Definition: extraUtilPerm.c:57
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
int Abc_ZddPerm ( Abc_ZddMan p,
int  a,
int  Var 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 543 of file extraUtilPerm.c.

544 {
545  Abc_ZddObj * A;
546  int r0, r1, r;
547  assert( Var < p->nVars );
548  if ( a == 0 ) return 0;
549  if ( a == 1 ) return Abc_ZddIthVar(Var);
550  if ( (r = Abc_ZddCacheLookup(p, a, Var, ABC_ZDD_OPER_PERM)) >= 0 )
551  return r;
552  A = Abc_ZddNode( p, a );
553  if ( p->pV2TI[A->Var] > p->pV2TI[Var] ) // Ai > Bi
554  r = Abc_ZddUniqueCreate( p, Var, a, 0 );
555  else if ( (int)A->Var == Var ) // Ai == Bi && Aj == Bj
556  r0 = Abc_ZddPerm( p, A->False, Var ),
557  r = Abc_ZddUnion( p, r0, A->True );
558  else
559  {
560  int VarPerm, VarTop;
561  int Ai = p->pV2TI[A->Var];
562  int Aj = p->pV2TJ[A->Var];
563  int Bi = p->pV2TI[Var];
564  int Bj = p->pV2TJ[Var];
565  assert( Ai < Aj && Bi < Bj && Ai <= Bi );
566  if ( Aj == Bi )
567  VarPerm = Var,
568  VarTop = Abc_ZddVarIJ(p, Ai, Bj);
569  else if ( Aj == Bj )
570  VarPerm = Var,
571  VarTop = Abc_ZddVarIJ(p, Ai, Bi);
572  else if ( Ai == Bi )
573  VarPerm = Abc_ZddVarIJ(p, Abc_MinInt(Aj, Bj), Abc_MaxInt(Aj, Bj)),
574  VarTop = A->Var;
575  else // no clash
576  VarPerm = Var,
577  VarTop = A->Var;
578  assert( p->pV2TI[VarPerm] > p->pV2TI[VarTop] );
579  r0 = Abc_ZddPerm( p, A->False, Var );
580  r1 = Abc_ZddPerm( p, A->True, VarPerm );
581  assert( Abc_ZddObjVar(p, r1) > VarTop );
582  if ( Abc_ZddObjVar(p, r0) > VarTop )
583  r = Abc_ZddUniqueCreate( p, VarTop, r1, r0 );
584  else
585  r1 = Abc_ZddUniqueCreate( p, VarTop, r1, 0 ),
586  r = Abc_ZddUnion( p, r0, r1 );
587  }
588  return Abc_ZddCacheInsert( p, a, Var, ABC_ZDD_OPER_PERM, r );
589 }
int Abc_ZddUnion(Abc_ZddMan *p, int a, int b)
unsigned True
Definition: extraUtilPerm.c:59
static int Abc_ZddIthVar(int i)
Definition: extraUtilPerm.c:93
static int Abc_ZddCacheInsert(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2, int Res)
static int Abc_ZddObjVar(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:98
static int Abc_ZddUniqueCreate(Abc_ZddMan *p, int Var, int True, int False)
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
unsigned Var
Definition: extraUtilPerm.c:57
static int Abc_MinInt(int a, int b)
Definition: abc_global.h:239
static int Abc_ZddCacheLookup(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2)
FUNCTION DEFINITIONS ///.
unsigned False
Definition: extraUtilPerm.c:60
int Abc_ZddPerm(Abc_ZddMan *p, int a, int Var)
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
int Var
Definition: SolverTypes.h:42
#define assert(ex)
Definition: util_old.h:213
static int Abc_ZddVarIJ(Abc_ZddMan *p, int i, int j)
int Abc_ZddPerm2Comb ( int *  pPerm,
int  Size,
int *  pComb 
)

Definition at line 636 of file extraUtilPerm.c.

637 {
638  int i, j, nTrans = 0;
639  for ( i = 0; i < Size; i++ )
640  if ( i != pPerm[i] )
641  {
642  for ( j = i+1; j < Size; j++ )
643  if ( i == pPerm[j] )
644  break;
645  pComb[nTrans++] = (i << 16) | j;
646  ABC_SWAP( int, pPerm[i], pPerm[j] );
647  assert( i == pPerm[i] );
648  }
649  return nTrans;
650 }
#define ABC_SWAP(Type, a, b)
Definition: abc_global.h:218
static int pPerm[13719]
Definition: rwrTemp.c:32
#define assert(ex)
Definition: util_old.h:213
void Abc_ZddPermCombTest ( )

Definition at line 659 of file extraUtilPerm.c.

660 {
661  int Size = 10;
662  int pPerm[10] = { 6, 5, 7, 0, 3, 2, 1, 8, 9, 4 };
663  int pComb[10], nTrans;
664  Abc_ZddPermPrint( pPerm, Size );
665  nTrans = Abc_ZddPerm2Comb( pPerm, Size, pComb );
666  Abc_ZddCombPrint( pComb, nTrans );
667  Abc_ZddComb2Perm( pComb, nTrans, pPerm, Size );
668  Abc_ZddPermPrint( pPerm, Size );
669  Size = 0;
670 }
void Abc_ZddComb2Perm(int *pComb, int nTrans, int *pPerm, int Size)
void Abc_ZddCombPrint(int *pComb, int nTrans)
static int pPerm[13719]
Definition: rwrTemp.c:32
int Abc_ZddPerm2Comb(int *pPerm, int Size, int *pComb)
void Abc_ZddPermPrint(int *pPerm, int Size)
void Abc_ZddPermPrint ( int *  pPerm,
int  Size 
)

Function*************************************************************

Synopsis [Printing permutations and transpositions.]

Description []

SideEffects []

SeeAlso []

Definition at line 619 of file extraUtilPerm.c.

620 {
621  int i;
622  printf( "{" );
623  for ( i = 0; i < Size; i++ )
624  printf( " %2d", pPerm[i] );
625  printf( " }\n" );
626 }
static int pPerm[13719]
Definition: rwrTemp.c:32
int Abc_ZddPermProduct ( Abc_ZddMan p,
int  a,
int  b 
)

Definition at line 590 of file extraUtilPerm.c.

591 {
592  Abc_ZddObj * B;
593  int r0, r1, r;
594  if ( a == 0 ) return 0;
595  if ( a == 1 ) return b;
596  if ( b == 0 ) return 0;
597  if ( b == 1 ) return a;
598  if ( (r = Abc_ZddCacheLookup(p, a, b, ABC_ZDD_OPER_PERM_PROD)) >= 0 )
599  return r;
600  B = Abc_ZddNode( p, b );
601  r0 = Abc_ZddPermProduct( p, a, B->False );
602  r1 = Abc_ZddPermProduct( p, a, B->True );
603  r1 = Abc_ZddPerm( p, r1, B->Var );
604  r = Abc_ZddUnion( p, r0, r1 );
605  return Abc_ZddCacheInsert( p, a, b, ABC_ZDD_OPER_PERM_PROD, r );
606 }
int Abc_ZddUnion(Abc_ZddMan *p, int a, int b)
unsigned True
Definition: extraUtilPerm.c:59
static int Abc_ZddCacheInsert(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2, int Res)
unsigned Var
Definition: extraUtilPerm.c:57
int Abc_ZddPermProduct(Abc_ZddMan *p, int a, int b)
static int Abc_ZddCacheLookup(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2)
FUNCTION DEFINITIONS ///.
unsigned False
Definition: extraUtilPerm.c:60
int Abc_ZddPerm(Abc_ZddMan *p, int a, int Var)
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
void Abc_ZddPermTest ( )

Definition at line 824 of file extraUtilPerm.c.

825 {
826  Abc_ZddMan * p;
827  p = Abc_ZddManAlloc( 10, 1 << 20 );
828  Abc_ZddManCreatePerms( p, 5 );
829  Abc_ZddPermTestInt( p );
830  Abc_ZddManFree( p );
831 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Abc_ZddPermTestInt(Abc_ZddMan *p)
void Abc_ZddManCreatePerms(Abc_ZddMan *p, int nPermSize)
void Abc_ZddManFree(Abc_ZddMan *p)
Abc_ZddMan * Abc_ZddManAlloc(int nVars, int nObjs)
void Abc_ZddPermTestInt ( Abc_ZddMan p)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 789 of file extraUtilPerm.c.

790 {
791  int nPerms = 3;
792  int Size = 5;
793  int pPerms[3][5] = { {1, 0, 2, 4, 3}, {1, 2, 4, 0, 3}, {0, 3, 2, 1, 4} };
794  int pComb[5], nTrans;
795  int i, k, Set, Union = 0, iPivot;
796  for ( i = 0; i < nPerms; i++ )
797  Abc_ZddPermPrint( pPerms[i], Size );
798  for ( i = 0; i < nPerms; i++ )
799  {
800  printf( "Perm %d:\n", i );
801  Abc_ZddPermPrint( pPerms[i], Size );
802  nTrans = Abc_ZddPerm2Comb( pPerms[i], Size, pComb );
803  Abc_ZddCombPrint( pComb, nTrans );
804  for ( k = 0; k < nTrans; k++ )
805  pComb[k] = Abc_ZddVarIJ( p, pComb[k] >> 16, pComb[k] & 0xFFFF );
806  Abc_ZddPermPrint( pComb, nTrans );
807  // add to ZDD
808  Set = Abc_ZddBuildSet( p, pComb, nTrans );
809  Union = Abc_ZddUnion( p, Union, Set );
810  }
811  printf( "\nResulting set of permutations:\n" );
812  Abc_ZddPrint( p, Union );
813  printf( "Nodes = %d. Path = %d.\n", Abc_ZddCountNodes(p, Union), Abc_ZddCountPaths(p, Union) );
814 
815  iPivot = Abc_ZddVarIJ( p, 3, 4 );
816  Union = Abc_ZddPerm( p, Union, iPivot );
817 
818  printf( "\nResulting set of permutations:\n" );
819  Abc_ZddPrint( p, Union );
820  printf( "Nodes = %d. Path = %d.\n", Abc_ZddCountNodes(p, Union), Abc_ZddCountPaths(p, Union) );
821  printf( "\n" );
822 }
int Abc_ZddUnion(Abc_ZddMan *p, int a, int b)
void Abc_ZddPrint(Abc_ZddMan *p, int a)
void Abc_ZddCombPrint(int *pComb, int nTrans)
int Abc_ZddBuildSet(Abc_ZddMan *p, int *pSet, int Size)
int Abc_ZddPerm(Abc_ZddMan *p, int a, int Var)
int Abc_ZddCountPaths(Abc_ZddMan *p, int a)
int Abc_ZddPerm2Comb(int *pPerm, int Size, int *pComb)
void Abc_ZddPermPrint(int *pPerm, int Size)
static int Abc_ZddVarIJ(Abc_ZddMan *p, int i, int j)
int Abc_ZddCountNodes(Abc_ZddMan *p, int i)
void Abc_ZddPrint ( Abc_ZddMan p,
int  a 
)

Definition at line 704 of file extraUtilPerm.c.

705 {
706  int * pPath = ABC_CALLOC( int, p->nVars );
707  Abc_ZddPrint_rec( p, a, pPath, 0 );
708  ABC_FREE( pPath );
709 }
void Abc_ZddPrint_rec(Abc_ZddMan *p, int a, int *pPath, int Size)
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
void Abc_ZddPrint_rec ( Abc_ZddMan p,
int  a,
int *  pPath,
int  Size 
)

Function*************************************************************

Synopsis [Printing ZDDs.]

Description []

SideEffects []

SeeAlso []

Definition at line 683 of file extraUtilPerm.c.

684 {
685  Abc_ZddObj * A;
686  if ( a == 0 ) return;
687 // if ( a == 1 ) { Abc_ZddPermPrint( pPath, Size ); return; }
688  if ( a == 1 )
689  {
690  int pPerm[24], pComb[24], i;
691  assert( p->nPermSize <= 24 );
692  for ( i = 0; i < Size; i++ )
693  pComb[i] = (p->pV2TI[pPath[i]] << 16) | p->pV2TJ[pPath[i]];
694  Abc_ZddCombPrint( pComb, Size );
695  Abc_ZddComb2Perm( pComb, Size, pPerm, p->nPermSize );
696  Abc_ZddPermPrint( pPerm, p->nPermSize );
697  return;
698  }
699  A = Abc_ZddNode( p, a );
700  Abc_ZddPrint_rec( p, A->False, pPath, Size );
701  pPath[Size] = A->Var;
702  Abc_ZddPrint_rec( p, A->True, pPath, Size + 1 );
703 }
void Abc_ZddComb2Perm(int *pComb, int nTrans, int *pPerm, int Size)
void Abc_ZddCombPrint(int *pComb, int nTrans)
unsigned True
Definition: extraUtilPerm.c:59
unsigned Var
Definition: extraUtilPerm.c:57
void Abc_ZddPrint_rec(Abc_ZddMan *p, int a, int *pPath, int Size)
unsigned False
Definition: extraUtilPerm.c:60
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
static int pPerm[13719]
Definition: rwrTemp.c:32
#define assert(ex)
Definition: util_old.h:213
void Abc_ZddPermPrint(int *pPerm, int Size)
void Abc_ZddPrintTest ( Abc_ZddMan p)

Definition at line 710 of file extraUtilPerm.c.

711 {
712 // int nSets = 2;
713 // int Size = 2;
714 // int pSets[2][2] = { {5, 0}, {3, 11} };
715  int nSets = 3;
716  int Size = 5;
717  int pSets[3][5] = { {5, 0, 2, 10, 7}, {3, 11, 10, 7, 2}, {0, 2, 5, 10, 7} };
718  int i, Set, Union = 0;
719  for ( i = 0; i < nSets; i++ )
720  {
721  Abc_ZddPermPrint( pSets[i], Size );
722  Set = Abc_ZddBuildSet( p, pSets[i], Size );
723  Union = Abc_ZddUnion( p, Union, Set );
724  }
725  printf( "Resulting set:\n" );
726  Abc_ZddPrint( p, Union );
727  printf( "\n" );
728  printf( "Nodes = %d. Path = %d.\n", Abc_ZddCountNodes(p, Union), Abc_ZddCountPaths(p, Union) );
729  Size = 0;
730 }
int Abc_ZddUnion(Abc_ZddMan *p, int a, int b)
void Abc_ZddPrint(Abc_ZddMan *p, int a)
int Abc_ZddBuildSet(Abc_ZddMan *p, int *pSet, int Size)
int Abc_ZddCountPaths(Abc_ZddMan *p, int a)
void Abc_ZddPermPrint(int *pPerm, int Size)
int Abc_ZddCountNodes(Abc_ZddMan *p, int i)
static void Abc_ZddSetVarIJ ( Abc_ZddMan p,
int  i,
int  j,
int  v 
)
inlinestatic

Definition at line 100 of file extraUtilPerm.c.

100 { assert( i < j ); p->pT2V[i * p->nPermSize + j] = v; }
#define assert(ex)
Definition: util_old.h:213
int Abc_ZddThresh ( Abc_ZddMan p,
int  a,
int  b 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 459 of file extraUtilPerm.c.

460 {
461  Abc_ZddObj * A;
462  int r0, r1, r;
463  if ( a < 2 ) return a;
464  if ( b == 0 ) return 0;
465  if ( (r = Abc_ZddCacheLookup(p, a, b, ABC_ZDD_OPER_THRESH)) >= 0 )
466  return r;
467  A = Abc_ZddNode( p, a );
468  r0 = Abc_ZddThresh( p, A->False, b ),
469  r1 = Abc_ZddThresh( p, A->True, b-1 );
470  r = Abc_ZddUniqueCreate( p, A->Var, r1, r0 );
471  return Abc_ZddCacheInsert( p, a, b, ABC_ZDD_OPER_THRESH, r );
472 }
unsigned True
Definition: extraUtilPerm.c:59
static int Abc_ZddCacheInsert(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2, int Res)
static int Abc_ZddUniqueCreate(Abc_ZddMan *p, int Var, int True, int False)
unsigned Var
Definition: extraUtilPerm.c:57
int Abc_ZddThresh(Abc_ZddMan *p, int a, int b)
static int Abc_ZddCacheLookup(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2)
FUNCTION DEFINITIONS ///.
unsigned False
Definition: extraUtilPerm.c:60
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
int Abc_ZddUnion ( Abc_ZddMan p,
int  a,
int  b 
)

Definition at line 275 of file extraUtilPerm.c.

276 {
277  Abc_ZddObj * A, * B;
278  int r0, r1, r;
279  if ( a == 0 ) return b;
280  if ( b == 0 ) return a;
281  if ( a == b ) return a;
282  if ( a > b ) return Abc_ZddUnion( p, b, a );
283  if ( (r = Abc_ZddCacheLookup(p, a, b, ABC_ZDD_OPER_UNION)) >= 0 )
284  return r;
285  A = Abc_ZddNode( p, a );
286  B = Abc_ZddNode( p, b );
287  if ( A->Var < B->Var )
288  r0 = Abc_ZddUnion( p, A->False, b ),
289  r1 = A->True;
290  else if ( A->Var > B->Var )
291  r0 = Abc_ZddUnion( p, a, B->False ),
292  r1 = B->True;
293  else
294  r0 = Abc_ZddUnion( p, A->False, B->False ),
295  r1 = Abc_ZddUnion( p, A->True, B->True );
296  r = Abc_ZddUniqueCreate( p, Abc_MinInt(A->Var, B->Var), r1, r0 );
297  return Abc_ZddCacheInsert( p, a, b, ABC_ZDD_OPER_UNION, r );
298 }
int Abc_ZddUnion(Abc_ZddMan *p, int a, int b)
unsigned True
Definition: extraUtilPerm.c:59
static int Abc_ZddCacheInsert(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2, int Res)
static int Abc_ZddUniqueCreate(Abc_ZddMan *p, int Var, int True, int False)
unsigned Var
Definition: extraUtilPerm.c:57
static int Abc_MinInt(int a, int b)
Definition: abc_global.h:239
static int Abc_ZddCacheLookup(Abc_ZddMan *p, int Arg0, int Arg1, int Arg2)
FUNCTION DEFINITIONS ///.
unsigned False
Definition: extraUtilPerm.c:60
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
static int Abc_ZddUniqueCreate ( Abc_ZddMan p,
int  Var,
int  True,
int  False 
)
inlinestatic

Definition at line 141 of file extraUtilPerm.c.

142 {
143  assert( Var >= 0 && Var < p->nVars );
144  assert( Var < Abc_ZddObjVar(p, True) );
145  assert( Var < Abc_ZddObjVar(p, False) );
146  if ( True == 0 )
147  return False;
148  {
149  int *q = p->pUnique + (Abc_ZddHash(Var, True, False) & p->nUniqueMask);
150  for ( ; *q; q = p->pNexts + *q )
151  if ( p->pObjs[*q].Var == (unsigned)Var && p->pObjs[*q].True == (unsigned)True && p->pObjs[*q].False == (unsigned)False )
152  return *q;
153  if ( p->nObjs == p->nObjsAlloc )
154  printf( "Aborting because the number of nodes exceeded %d.\n", p->nObjsAlloc ), fflush(stdout);
155  assert( p->nObjs < p->nObjsAlloc );
156  *q = p->nObjs++;
157  p->pObjs[*q].Var = Var;
158  p->pObjs[*q].True = True;
159  p->pObjs[*q].False = False;
160 // printf( "Added node %3d: Var = %3d. True = %3d. False = %3d\n", *q, Var, True, False );
161  return *q;
162  }
163 }
Abc_ZddObj * pObjs
Definition: extraUtilPerm.c:84
unsigned True
Definition: extraUtilPerm.c:59
static unsigned Abc_ZddHash(int Arg0, int Arg1, int Arg2)
Definition: extraUtilPerm.c:94
static int Abc_ZddObjVar(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:98
unsigned Var
Definition: extraUtilPerm.c:57
unsigned False
Definition: extraUtilPerm.c:60
unsigned nUniqueMask
Definition: extraUtilPerm.c:79
int Var
Definition: SolverTypes.h:42
#define True
Definition: bzlib_private.h:51
#define assert(ex)
Definition: util_old.h:213
#define False
Definition: bzlib_private.h:52
static int Abc_ZddUniqueLookup ( Abc_ZddMan p,
int  Var,
int  True,
int  False 
)
inlinestatic

Definition at line 133 of file extraUtilPerm.c.

134 {
135  int *q = p->pUnique + (Abc_ZddHash(Var, True, False) & p->nUniqueMask);
136  for ( ; *q; q = p->pNexts + *q )
137  if ( p->pObjs[*q].Var == (unsigned)Var && p->pObjs[*q].True == (unsigned)True && p->pObjs[*q].False == (unsigned)False )
138  return *q;
139  return 0;
140 }
Abc_ZddObj * pObjs
Definition: extraUtilPerm.c:84
unsigned True
Definition: extraUtilPerm.c:59
static unsigned Abc_ZddHash(int Arg0, int Arg1, int Arg2)
Definition: extraUtilPerm.c:94
unsigned Var
Definition: extraUtilPerm.c:57
unsigned False
Definition: extraUtilPerm.c:60
unsigned nUniqueMask
Definition: extraUtilPerm.c:79
int Var
Definition: SolverTypes.h:42
#define True
Definition: bzlib_private.h:51
#define False
Definition: bzlib_private.h:52
void Abc_ZddUnmark_rec ( Abc_ZddMan p,
int  i 
)

Definition at line 420 of file extraUtilPerm.c.

421 {
422  Abc_ZddObj * A;
423  if ( i < 2 )
424  return;
425  A = Abc_ZddNode( p, i );
426  if ( !A->Mark )
427  return;
428  A->Mark = 0;
429  Abc_ZddUnmark_rec( p, A->False );
430  Abc_ZddUnmark_rec( p, A->True );
431 }
unsigned Mark
Definition: extraUtilPerm.c:58
unsigned True
Definition: extraUtilPerm.c:59
unsigned False
Definition: extraUtilPerm.c:60
static Abc_ZddObj * Abc_ZddNode(Abc_ZddMan *p, int i)
Definition: extraUtilPerm.c:96
void Abc_ZddUnmark_rec(Abc_ZddMan *p, int i)
static int Abc_ZddVarIJ ( Abc_ZddMan p,
int  i,
int  j 
)
inlinestatic

Definition at line 101 of file extraUtilPerm.c.

101 { assert( i < j ); return p->pT2V[i * p->nPermSize + j]; }
#define assert(ex)
Definition: util_old.h:213
static int Abc_ZddVarsClash ( Abc_ZddMan p,
int  v0,
int  v1 
)
inlinestatic

Definition at line 102 of file extraUtilPerm.c.

102 { return p->pV2TI[v0] == p->pV2TI[v1] || p->pV2TJ[v0] == p->pV2TJ[v1] || p->pV2TI[v0] == p->pV2TJ[v1] || p->pV2TJ[v0] == p->pV2TI[v1]; }