@@ -1941,7 +1941,7 @@ static inline int Exa4_ManAddClause4( Exa4_Man_t * p, int Lit0, int Lit1, int Li
19411941 int pLits [4 ] = { Lit0 , Lit1 , Lit2 , Lit3 };
19421942 return Exa4_ManAddClause ( p , pLits , 4 );
19431943}
1944- int Exa4_ManGenStart ( Exa4_Man_t * p , int fOnlyAnd , int fFancy , int fOrderNodes , int fUniqFans )
1944+ int Exa4_ManGenStart ( Exa4_Man_t * p , int fOnlyAnd , int fFancy , int fOrderNodes , int fUniqFans , int fCard )
19451945{
19461946 int pLits [2 * MAJ_NOBJS ], i , j , k , n , m , nLits ;
19471947 for ( i = p -> nDivs ; i < p -> nDivs + p -> nNodes ; i ++ )
@@ -1955,9 +1955,17 @@ int Exa4_ManGenStart( Exa4_Man_t * p, int fOnlyAnd, int fFancy, int fOrderNodes,
19551955 pLits [nLits ++ ] = Abc_Var2Lit ( p -> VarMarks [i ][k ][j ], 0 );
19561956 assert ( nLits > 0 );
19571957 Exa4_ManAddClause ( p , pLits , nLits );
1958- for ( n = 0 ; n < nLits ; n ++ )
1959- for ( m = n + 1 ; m < nLits ; m ++ )
1960- Exa4_ManAddClause4 ( p , Abc_LitNot (pLits [n ]), Abc_LitNot (pLits [m ]), 0 , 0 );
1958+ if ( !fCard ) {
1959+ for ( n = 0 ; n < nLits ; n ++ )
1960+ for ( m = n + 1 ; m < nLits ; m ++ )
1961+ Exa4_ManAddClause4 ( p , Abc_LitNot (pLits [n ]), Abc_LitNot (pLits [m ]), 0 , 0 );
1962+ }
1963+ else {
1964+ fprintf ( p -> pFile , "k %d " , nLits - 1 );
1965+ for ( n = 0 ; n < nLits ; n ++ )
1966+ pLits [n ] = Abc_LitNot (pLits [n ]);
1967+ Exa4_ManAddClause ( p , pLits , nLits );
1968+ }
19611969 if ( k == 1 )
19621970 break ;
19631971 for ( j = 0 ; j < p -> nObjs ; j ++ ) if ( p -> VarMarks [i ][0 ][j ] )
@@ -2096,17 +2104,17 @@ void Exa4_ManGenMint( Exa4_Man_t * p, int iMint, int fOnlyAnd, int fFancy )
20962104 Exa4_ManAddClause4 ( p , Abc_Var2Lit (p -> VarMarks [i ][0 ][j ], 1 ), Abc_LitNotCond (VarVals [j ], n ), Abc_LitNotCond (VarVals [i ], !n ), 0 );
20972105 }
20982106}
2099- void Exa4_ManGenCnf ( Exa4_Man_t * p , char * pFileName , int fOnlyAnd , int fFancy , int fOrderNodes , int fUniqFans )
2107+ void Exa4_ManGenCnf ( Exa4_Man_t * p , char * pFileName , int fOnlyAnd , int fFancy , int fOrderNodes , int fUniqFans , int fCard )
21002108{
21012109 int m ;
21022110 assert ( p -> pFile == NULL );
21032111 p -> pFile = fopen ( pFileName , "wb" );
21042112 fputs ( "p cnf \n" , p -> pFile );
2105- Exa4_ManGenStart ( p , fOnlyAnd , fFancy , fOrderNodes , fUniqFans );
2113+ Exa4_ManGenStart ( p , fOnlyAnd , fFancy , fOrderNodes , fUniqFans , fCard );
21062114 for ( m = 1 ; m < Vec_WrdSize (p -> vSimsIn ); m ++ )
21072115 Exa4_ManGenMint ( p , m , fOnlyAnd , fFancy );
21082116 rewind ( p -> pFile );
2109- fprintf ( p -> pFile , "p cnf %d %d" , p -> nCnfVars , p -> nCnfClauses );
2117+ fprintf ( p -> pFile , "p % cnf %d %d" , fCard ? 'k' : 'c' , p -> nCnfVars , p -> nCnfClauses );
21102118 fclose ( p -> pFile );
21112119}
21122120
@@ -2130,6 +2138,8 @@ static inline int Exa4_ManFindFanin( Exa4_Man_t * p, Vec_Int_t * vValues, int i,
21302138 iVar = j ;
21312139 Count ++ ;
21322140 }
2141+ if ( Count != 1 )
2142+ printf ( "Fanin count is %d instead of %d.\n" , Count , 1 );
21332143 assert ( Count == 1 );
21342144 return iVar ;
21352145}
@@ -2268,21 +2278,27 @@ Mini_Aig_t * Exa4_ManMiniAig( Exa4_Man_t * p, Vec_Int_t * vValues, int fFancy )
22682278 SeeAlso []
22692279
22702280***********************************************************************/
2271- Mini_Aig_t * Exa4_ManGenTest ( Vec_Wrd_t * vSimsIn , Vec_Wrd_t * vSimsOut , int nIns , int nDivs , int nOuts , int nNodes , int TimeOut , int fOnlyAnd , int fFancy , int fOrderNodes , int fUniqFans , int fVerbose )
2281+ Mini_Aig_t * Exa4_ManGenTest ( Vec_Wrd_t * vSimsIn , Vec_Wrd_t * vSimsOut , int nIns , int nDivs , int nOuts , int nNodes , int TimeOut , int fOnlyAnd , int fFancy , int fOrderNodes , int fUniqFans , int fVerbose , int fCard )
22722282{
2283+ extern Vec_Int_t * Gia_RunKadical ( char * pFileNameIn , char * pFileNameOut , int nBTLimit , int TimeOut , int fVerbose , int * pStatus );
22732284 Mini_Aig_t * pMini = NULL ;
22742285 abctime clkTotal = Abc_Clock ();
22752286 Vec_Int_t * vValues = NULL ;
2276- char * pFileNameIn = "_temp_.cnf" ;
2277- char * pFileNameOut = "_temp_out.cnf" ;
2287+ srand (time (NULL ));
2288+ int Status = 0 , Rand = ((((unsigned )rand ()) << 12 ) ^ ((unsigned )rand ())) & 0xFFFFF ;
2289+ char pFileNameIn [32 ]; sprintf ( pFileNameIn , "_%05x_.cnf" , Rand );
2290+ char pFileNameOut [32 ]; sprintf ( pFileNameOut , "_%05x_.out" , Rand );
22782291 Exa4_Man_t * p = Exa4_ManAlloc ( vSimsIn , vSimsOut , nIns , nDivs , nOuts , nNodes , fVerbose );
22792292 Exa_ManIsNormalized ( vSimsIn , vSimsOut );
2280- Exa4_ManGenCnf ( p , pFileNameIn , fOnlyAnd , fFancy , fOrderNodes , fUniqFans );
2293+ Exa4_ManGenCnf ( p , pFileNameIn , fOnlyAnd , fFancy , fOrderNodes , fUniqFans , fCard );
22812294 if ( fVerbose )
22822295 printf ( "Timeout = %d. OnlyAnd = %d. Fancy = %d. OrderNodes = %d. UniqueFans = %d. Verbose = %d.\n" , TimeOut , fOnlyAnd , fFancy , fOrderNodes , fUniqFans , fVerbose );
22832296 if ( fVerbose )
22842297 printf ( "CNF with %d variables and %d clauses was dumped into file \"%s\".\n" , p -> nCnfVars , p -> nCnfClauses , pFileNameIn );
2285- vValues = Exa4_ManSolve ( pFileNameIn , pFileNameOut , TimeOut , fVerbose );
2298+ if ( fCard )
2299+ vValues = Gia_RunKadical ( pFileNameIn , pFileNameOut , 0 , TimeOut , fVerbose , & Status );
2300+ else
2301+ vValues = Exa4_ManSolve ( pFileNameIn , pFileNameOut , TimeOut , fVerbose );
22862302 if ( vValues ) pMini = Exa4_ManMiniAig ( p , vValues , fFancy );
22872303 //if ( vValues ) Exa4_ManPrintSolution( p, vValues, fFancy );
22882304 if ( vValues ) Exa_ManMiniPrint ( pMini , p -> nIns );
@@ -2310,7 +2326,7 @@ void Exa_ManExactSynthesis4_( Bmc_EsPar_t * pPars )
23102326 if ( (m >> i ) & 1 )
23112327 Abc_TtSetBit ( Vec_WrdEntryP (vSimsIn , m ), 1 + i );
23122328 }
2313- pMini = Exa4_ManGenTest ( vSimsIn , vSimsOut , 3 , 4 , 2 , pPars -> nNodes , pPars -> RuntimeLim , pPars -> fOnlyAnd , pPars -> fFewerVars , pPars -> fOrderNodes , pPars -> fUniqFans , pPars -> fVerbose );
2329+ pMini = Exa4_ManGenTest ( vSimsIn , vSimsOut , 3 , 4 , 2 , pPars -> nNodes , pPars -> RuntimeLim , pPars -> fOnlyAnd , pPars -> fFewerVars , pPars -> fOrderNodes , pPars -> fUniqFans , pPars -> fVerbose , 0 );
23142330 if ( pMini ) Mini_AigStop ( pMini );
23152331 Vec_WrdFree ( vSimsIn );
23162332 Vec_WrdFree ( vSimsOut );
@@ -2332,7 +2348,7 @@ void Exa_ManExactSynthesis4( Bmc_EsPar_t * pPars )
23322348 Abc_TtSetBit ( Vec_WrdEntryP (vSimsIn , m ), 1 + i );
23332349 }
23342350 assert ( Vec_WrdSize (vSimsIn ) == (1 << pPars -> nVars ) );
2335- pMini = Exa4_ManGenTest ( vSimsIn , vSimsOut , pPars -> nVars , 1 + pPars -> nVars , 1 , pPars -> nNodes , pPars -> RuntimeLim , pPars -> fOnlyAnd , pPars -> fFewerVars , pPars -> fOrderNodes , pPars -> fUniqFans , pPars -> fVerbose );
2351+ pMini = Exa4_ManGenTest ( vSimsIn , vSimsOut , pPars -> nVars , 1 + pPars -> nVars , 1 , pPars -> nNodes , pPars -> RuntimeLim , pPars -> fOnlyAnd , pPars -> fFewerVars , pPars -> fOrderNodes , pPars -> fUniqFans , pPars -> fVerbose , pPars -> fCard );
23362352 if ( pMini ) Mini_AigStop ( pMini );
23372353 if ( fCompl ) printf ( "The resulting circuit, if computed, will be complemented.\n" );
23382354 Vec_WrdFree ( vSimsIn );
@@ -2797,8 +2813,10 @@ Mini_Aig_t * Exa5_ManGenTest( Vec_Wrd_t * vSimsIn, Vec_Wrd_t * vSimsOut, int nIn
27972813 abctime clkTotal = Abc_Clock ();
27982814 Mini_Aig_t * pMini = NULL ;
27992815 Vec_Int_t * vValues = NULL ;
2800- char * pFileNameIn = "_temp_.cnf" ;
2801- char * pFileNameOut = "_temp_out.cnf" ;
2816+ srand (time (NULL ));
2817+ int Rand = ((((unsigned )rand ()) << 12 ) ^ ((unsigned )rand ())) & 0xFFFFF ;
2818+ char pFileNameIn [32 ]; sprintf ( pFileNameIn , "_%05x_.cnf" , Rand );
2819+ char pFileNameOut [32 ]; sprintf ( pFileNameOut , "_%05x_.out" , Rand );
28022820 Exa5_Man_t * p = Exa5_ManAlloc ( vSimsIn , vSimsOut , nIns , nDivs , nOuts , nNodes , fVerbose );
28032821 Exa_ManIsNormalized ( vSimsIn , vSimsOut );
28042822 Exa5_ManGenCnf ( p , pFileNameIn , fOnlyAnd , fFancy , fOrderNodes , fUniqFans );
@@ -3717,8 +3735,9 @@ Mini_Aig_t * Exa6_ManGenTest( Vec_Wrd_t * vSimsIn, Vec_Wrd_t * vSimsOut, int nIn
37173735 Mini_Aig_t * pMini = NULL ;
37183736 abctime clkTotal = Abc_Clock ();
37193737 Vec_Int_t * vValues = NULL ;
3720- char * pFileNameIn = "_temp_.cnf" ;
3721- char * pFileNameOut = "_temp_out.cnf" ;
3738+ int Rand = ((((unsigned )rand ()) << 12 ) ^ ((unsigned )rand ())) & 0xFFFFF ;
3739+ char pFileNameIn [32 ]; sprintf ( pFileNameIn , "_%05x_.cnf" , Rand );
3740+ char pFileNameOut [32 ]; sprintf ( pFileNameOut , "_%05x_.out" , Rand );
37223741 Exa6_Man_t * p = Exa6_ManAlloc ( vSimsIn , vSimsOut , nIns , 1 + nIns + nDivs , nOuts , nNodes , fVerbose );
37233742 Exa_ManIsNormalized ( vSimsIn , vSimsOut );
37243743 Exa6_ManGenCnf ( p , pFileNameIn , fOnlyAnd , fFancy , fOrderNodes , fUniqFans );
@@ -4016,8 +4035,9 @@ void Exa_ManExactSynthesis7( Bmc_EsPar_t * pPars, int GateSize )
40164035 int nV = pPars -> nVars + pPars -> nNodes ;
40174036 word pTruth [16 ]; Abc_TtReadHex ( pTruth , pPars -> pTtStr );
40184037 Vec_Int_t * vValues = NULL ;
4019- char * pFileNameIn = "_temp_.cnf" ;
4020- char * pFileNameOut = "_temp_out.cnf" ;
4038+ int Rand = ((((unsigned )rand ()) << 12 ) ^ ((unsigned )rand ())) & 0xFFFFF ;
4039+ char pFileNameIn [32 ]; sprintf ( pFileNameIn , "_%05x_.cnf" , Rand );
4040+ char pFileNameOut [32 ]; sprintf ( pFileNameOut , "_%05x_.out" , Rand );
40214041 int nClas = Exa7_ManGenCnf ( pFileNameIn , pTruth , pPars -> nVars , pPars -> nNodes , GateSize );
40224042 if ( pPars -> fVerbose )
40234043 printf ( "CNF with %d variables and %d clauses was dumped into file \"%s\".\n" , nMints * nV * nV , nClas , pFileNameIn );
0 commit comments