Changing command &permute to generate random NPNP transformations.

This commit is contained in:
Alan Mishchenko 2023-07-21 16:15:34 -07:00
parent 623d0f3c9f
commit 55ed1e6698
2 changed files with 73 additions and 8 deletions

View File

@ -1069,6 +1069,51 @@ Gia_Man_t * Gia_ManDupPiPerm( Gia_Man_t * p )
return pNew;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Int_t * Gia_ManCreatePerm( int n )
{
Vec_Int_t * vPerm = Vec_IntStartNatural( n );
int i, * pPerm = Vec_IntArray( vPerm );
for ( i = 0; i < n; i++ )
{
int j = Abc_Random(0) % n;
ABC_SWAP( int, pPerm[i], pPerm[j] );
}
return vPerm;
}
Gia_Man_t * Gia_ManDupRandPerm( Gia_Man_t * p )
{
Vec_Int_t * vPiPerm = Gia_ManCreatePerm( Gia_ManCiNum(p) );
Vec_Int_t * vPoPerm = Gia_ManCreatePerm( Gia_ManCoNum(p) );
Gia_Man_t * pNew;
Gia_Obj_t * pObj;
int i;
pNew = Gia_ManStart( Gia_ManObjNum(p) );
pNew->pName = Abc_UtilStrsav( p->pName );
pNew->pSpec = Abc_UtilStrsav( p->pSpec );
Gia_ManConst0(p)->Value = 0;
Gia_ManForEachPi( p, pObj, i )
Gia_ManPi(p, Vec_IntEntry(vPiPerm,i))->Value = Gia_ManAppendCi(pNew) ^ (Abc_Random(0) & 1);
Gia_ManForEachAnd( p, pObj, i )
pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
Gia_ManForEachPo( p, pObj, i )
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(Gia_ManPo(p, Vec_IntEntry(vPoPerm,i))) ^ (Abc_Random(0) & 1) );
Vec_IntFree( vPiPerm );
Vec_IntFree( vPoPerm );
return pNew;
}
/**Function*************************************************************
Synopsis [Appends second AIG without any changes.]

View File

@ -7380,7 +7380,7 @@ int Abc_CommandOrchestrate( Abc_Frame_t * pAbc, int argc, char ** argv )
int fVerbose; //rewrite/rs/rf verbose
int fVeryVerbose; //very verbose option for all
size_t NtkSize;
//size_t NtkSize;
extern void Rwr_Precompute();
//local greedy
@ -43941,14 +43941,25 @@ usage:
***********************************************************************/
int Abc_CommandAbc9Permute( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern Gia_Man_t * Gia_ManDupPiPerm( Gia_Man_t * p );
extern Gia_Man_t * Gia_ManDupRandPerm( Gia_Man_t * p );
Gia_Man_t * pTemp;
int c, fVerbose = 0;
int c, RandSeed = 0, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "Svh" ) ) != EOF )
{
switch ( c )
{
case 'S':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
goto usage;
}
RandSeed = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( RandSeed < 0 )
goto usage;
break;
case 'v':
fVerbose ^= 1;
break;
@ -43960,16 +43971,25 @@ int Abc_CommandAbc9Permute( Abc_Frame_t * pAbc, int argc, char ** argv )
}
if ( pAbc->pGia == NULL )
{
Abc_Print( -1, "Abc_CommandAbc9Posplit(): There is no AIG.\n" );
Abc_Print( -1, "Abc_CommandAbc9Permute(): There is no AIG.\n" );
return 1;
}
pTemp = Gia_ManDupPiPerm( pAbc->pGia );
if ( Gia_ManRegNum(pAbc->pGia) > 0 )
{
Abc_Print( -1, "Abc_CommandAbc9Permute(): This command does not work for sequential AIGs.\n" );
return 1;
}
Abc_Random(1);
for ( c = 0; c < RandSeed; c++ )
Abc_Random(0);
pTemp = Gia_ManDupRandPerm( pAbc->pGia );
Abc_FrameUpdateGia( pAbc, pTemp );
return 0;
usage:
Abc_Print( -2, "usage: &permute [-vh]\n" );
Abc_Print( -2, "\t permutes primary inputs\n" );
Abc_Print( -2, "usage: &permute [-S num] [-vh]\n" );
Abc_Print( -2, "\t generates a random NPNP transformation of the combinational AIG\n" );
Abc_Print( -2, "\t-S num : the seed used to randomize the process [default = %d]\n", RandSeed );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;