@@ -1941,7 +1941,7 @@ static inline int Exa4_ManAddClause4( Exa4_Man_t * p, int Lit0, int Lit1, int Li
1941
1941
int pLits [4 ] = { Lit0 , Lit1 , Lit2 , Lit3 };
1942
1942
return Exa4_ManAddClause ( p , pLits , 4 );
1943
1943
}
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 )
1945
1945
{
1946
1946
int pLits [2 * MAJ_NOBJS ], i , j , k , n , m , nLits ;
1947
1947
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,
1955
1955
pLits [nLits ++ ] = Abc_Var2Lit ( p -> VarMarks [i ][k ][j ], 0 );
1956
1956
assert ( nLits > 0 );
1957
1957
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
+ }
1961
1969
if ( k == 1 )
1962
1970
break ;
1963
1971
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 )
2096
2104
Exa4_ManAddClause4 ( p , Abc_Var2Lit (p -> VarMarks [i ][0 ][j ], 1 ), Abc_LitNotCond (VarVals [j ], n ), Abc_LitNotCond (VarVals [i ], !n ), 0 );
2097
2105
}
2098
2106
}
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 )
2100
2108
{
2101
2109
int m ;
2102
2110
assert ( p -> pFile == NULL );
2103
2111
p -> pFile = fopen ( pFileName , "wb" );
2104
2112
fputs ( "p cnf \n" , p -> pFile );
2105
- Exa4_ManGenStart ( p , fOnlyAnd , fFancy , fOrderNodes , fUniqFans );
2113
+ Exa4_ManGenStart ( p , fOnlyAnd , fFancy , fOrderNodes , fUniqFans , fCard );
2106
2114
for ( m = 1 ; m < Vec_WrdSize (p -> vSimsIn ); m ++ )
2107
2115
Exa4_ManGenMint ( p , m , fOnlyAnd , fFancy );
2108
2116
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 );
2110
2118
fclose ( p -> pFile );
2111
2119
}
2112
2120
@@ -2130,6 +2138,8 @@ static inline int Exa4_ManFindFanin( Exa4_Man_t * p, Vec_Int_t * vValues, int i,
2130
2138
iVar = j ;
2131
2139
Count ++ ;
2132
2140
}
2141
+ if ( Count != 1 )
2142
+ printf ( "Fanin count is %d instead of %d.\n" , Count , 1 );
2133
2143
assert ( Count == 1 );
2134
2144
return iVar ;
2135
2145
}
@@ -2268,21 +2278,27 @@ Mini_Aig_t * Exa4_ManMiniAig( Exa4_Man_t * p, Vec_Int_t * vValues, int fFancy )
2268
2278
SeeAlso []
2269
2279
2270
2280
***********************************************************************/
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 )
2272
2282
{
2283
+ extern Vec_Int_t * Gia_RunKadical ( char * pFileNameIn , char * pFileNameOut , int nBTLimit , int TimeOut , int fVerbose , int * pStatus );
2273
2284
Mini_Aig_t * pMini = NULL ;
2274
2285
abctime clkTotal = Abc_Clock ();
2275
2286
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 );
2278
2291
Exa4_Man_t * p = Exa4_ManAlloc ( vSimsIn , vSimsOut , nIns , nDivs , nOuts , nNodes , fVerbose );
2279
2292
Exa_ManIsNormalized ( vSimsIn , vSimsOut );
2280
- Exa4_ManGenCnf ( p , pFileNameIn , fOnlyAnd , fFancy , fOrderNodes , fUniqFans );
2293
+ Exa4_ManGenCnf ( p , pFileNameIn , fOnlyAnd , fFancy , fOrderNodes , fUniqFans , fCard );
2281
2294
if ( fVerbose )
2282
2295
printf ( "Timeout = %d. OnlyAnd = %d. Fancy = %d. OrderNodes = %d. UniqueFans = %d. Verbose = %d.\n" , TimeOut , fOnlyAnd , fFancy , fOrderNodes , fUniqFans , fVerbose );
2283
2296
if ( fVerbose )
2284
2297
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 );
2286
2302
if ( vValues ) pMini = Exa4_ManMiniAig ( p , vValues , fFancy );
2287
2303
//if ( vValues ) Exa4_ManPrintSolution( p, vValues, fFancy );
2288
2304
if ( vValues ) Exa_ManMiniPrint ( pMini , p -> nIns );
@@ -2310,7 +2326,7 @@ void Exa_ManExactSynthesis4_( Bmc_EsPar_t * pPars )
2310
2326
if ( (m >> i ) & 1 )
2311
2327
Abc_TtSetBit ( Vec_WrdEntryP (vSimsIn , m ), 1 + i );
2312
2328
}
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 );
2314
2330
if ( pMini ) Mini_AigStop ( pMini );
2315
2331
Vec_WrdFree ( vSimsIn );
2316
2332
Vec_WrdFree ( vSimsOut );
@@ -2332,7 +2348,7 @@ void Exa_ManExactSynthesis4( Bmc_EsPar_t * pPars )
2332
2348
Abc_TtSetBit ( Vec_WrdEntryP (vSimsIn , m ), 1 + i );
2333
2349
}
2334
2350
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 );
2336
2352
if ( pMini ) Mini_AigStop ( pMini );
2337
2353
if ( fCompl ) printf ( "The resulting circuit, if computed, will be complemented.\n" );
2338
2354
Vec_WrdFree ( vSimsIn );
@@ -2797,8 +2813,10 @@ Mini_Aig_t * Exa5_ManGenTest( Vec_Wrd_t * vSimsIn, Vec_Wrd_t * vSimsOut, int nIn
2797
2813
abctime clkTotal = Abc_Clock ();
2798
2814
Mini_Aig_t * pMini = NULL ;
2799
2815
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 );
2802
2820
Exa5_Man_t * p = Exa5_ManAlloc ( vSimsIn , vSimsOut , nIns , nDivs , nOuts , nNodes , fVerbose );
2803
2821
Exa_ManIsNormalized ( vSimsIn , vSimsOut );
2804
2822
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
3717
3735
Mini_Aig_t * pMini = NULL ;
3718
3736
abctime clkTotal = Abc_Clock ();
3719
3737
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 );
3722
3741
Exa6_Man_t * p = Exa6_ManAlloc ( vSimsIn , vSimsOut , nIns , 1 + nIns + nDivs , nOuts , nNodes , fVerbose );
3723
3742
Exa_ManIsNormalized ( vSimsIn , vSimsOut );
3724
3743
Exa6_ManGenCnf ( p , pFileNameIn , fOnlyAnd , fFancy , fOrderNodes , fUniqFans );
@@ -4016,8 +4035,9 @@ void Exa_ManExactSynthesis7( Bmc_EsPar_t * pPars, int GateSize )
4016
4035
int nV = pPars -> nVars + pPars -> nNodes ;
4017
4036
word pTruth [16 ]; Abc_TtReadHex ( pTruth , pPars -> pTtStr );
4018
4037
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 );
4021
4041
int nClas = Exa7_ManGenCnf ( pFileNameIn , pTruth , pPars -> nVars , pPars -> nNodes , GateSize );
4022
4042
if ( pPars -> fVerbose )
4023
4043
printf ( "CNF with %d variables and %d clauses was dumped into file \"%s\".\n" , nMints * nV * nV , nClas , pFileNameIn );
0 commit comments