diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2008-07-05 08:01:00 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2008-07-05 08:01:00 -0700 |
commit | 7b734f23fc23694ccffdb7e3cd31335ffe6cb272 (patch) | |
tree | d6df566bac26ffb6af1eb01d215d6c4f9785dfa9 /src/aig/cnf | |
parent | 17ab7c7135befeb4e1d33385496959a16bd55054 (diff) | |
download | abc-7b734f23fc23694ccffdb7e3cd31335ffe6cb272.tar.gz abc-7b734f23fc23694ccffdb7e3cd31335ffe6cb272.tar.bz2 abc-7b734f23fc23694ccffdb7e3cd31335ffe6cb272.zip |
Version abc80705
Diffstat (limited to 'src/aig/cnf')
-rw-r--r-- | src/aig/cnf/cnf.h | 2 | ||||
-rw-r--r-- | src/aig/cnf/cnfMan.c | 93 | ||||
-rw-r--r-- | src/aig/cnf/cnfUtil.c | 1 |
3 files changed, 95 insertions, 1 deletions
diff --git a/src/aig/cnf/cnf.h b/src/aig/cnf/cnf.h index bf109b17..5c742f5d 100644 --- a/src/aig/cnf/cnf.h +++ b/src/aig/cnf/cnf.h @@ -140,6 +140,8 @@ extern void Cnf_DataPrint( Cnf_Dat_t * p, int fReadable ); extern void Cnf_DataWriteIntoFile( Cnf_Dat_t * p, char * pFileName, int fReadable ); extern void * Cnf_DataWriteIntoSolver( Cnf_Dat_t * p, int nFrames, int fInit ); extern int Cnf_DataWriteOrClause( void * pSat, Cnf_Dat_t * pCnf ); +extern int Cnf_DataWriteAndClauses( void * p, Cnf_Dat_t * pCnf ); +extern void Cnf_DataTranformPolarity( Cnf_Dat_t * pCnf ); /*=== cnfMap.c ========================================================*/ extern void Cnf_DeriveMapping( Cnf_Man_t * p ); extern int Cnf_ManMapForCnf( Cnf_Man_t * p ); diff --git a/src/aig/cnf/cnfMan.c b/src/aig/cnf/cnfMan.c index fc71f936..e3e6bfe1 100644 --- a/src/aig/cnf/cnfMan.c +++ b/src/aig/cnf/cnfMan.c @@ -20,6 +20,7 @@ #include "cnf.h" #include "satSolver.h" +#include "zlib.h" //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// @@ -237,7 +238,7 @@ void Cnf_DataPrint( Cnf_Dat_t * p, int fReadable ) SeeAlso [] ***********************************************************************/ -void Cnf_DataWriteIntoFile( Cnf_Dat_t * p, char * pFileName, int fReadable ) +void Cnf_DataWriteIntoFile_old( Cnf_Dat_t * p, char * pFileName, int fReadable ) { FILE * pFile; int * pLit, * pStop, i; @@ -270,6 +271,39 @@ void Cnf_DataWriteIntoFile( Cnf_Dat_t * p, char * pFileName, int fReadable ) SeeAlso [] ***********************************************************************/ +void Cnf_DataWriteIntoFile( Cnf_Dat_t * p, char * pFileName, int fReadable ) +{ + gzFile pFile; + int * pLit, * pStop, i; + pFile = gzopen( pFileName, "wb" ); + if ( pFile == NULL ) + { + printf( "Cnf_WriteIntoFile(): Output file cannot be opened.\n" ); + return; + } + gzprintf( pFile, "c Result of efficient AIG-to-CNF conversion using package CNF\n" ); + gzprintf( pFile, "p cnf %d %d\n", p->nVars, p->nClauses ); + for ( i = 0; i < p->nClauses; i++ ) + { + for ( pLit = p->pClauses[i], pStop = p->pClauses[i+1]; pLit < pStop; pLit++ ) + gzprintf( pFile, "%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) ); + gzprintf( pFile, "0\n" ); + } + gzprintf( pFile, "\n" ); + gzclose( pFile ); +} + +/**Function************************************************************* + + Synopsis [Writes CNF into a file.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ void * Cnf_DataWriteIntoSolver( Cnf_Dat_t * p, int nFrames, int fInit ) { sat_solver * pSat; @@ -379,6 +413,63 @@ int Cnf_DataWriteOrClause( void * p, Cnf_Dat_t * pCnf ) return 1; } +/**Function************************************************************* + + Synopsis [Adds the OR-clause.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Cnf_DataWriteAndClauses( void * p, Cnf_Dat_t * pCnf ) +{ + sat_solver * pSat = p; + Aig_Obj_t * pObj; + int i, Lit; + Aig_ManForEachPo( pCnf->pMan, pObj, i ) + { + Lit = toLitCond( pCnf->pVarNums[pObj->Id], 0 ); + if ( !sat_solver_addclause( pSat, &Lit, &Lit+1 ) ) + return 0; + } + return 1; +} + +/**Function************************************************************* + + Synopsis [Transforms polarity of the internal veriables.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Cnf_DataTranformPolarity( Cnf_Dat_t * pCnf ) +{ + Aig_Obj_t * pObj; + int * pVarToPol; + int i, iVar; + // create map from the variable number to its polarity + pVarToPol = CALLOC( int, pCnf->nVars ); + Aig_ManForEachObj( pCnf->pMan, pObj, i ) + if ( !Aig_ObjIsPo(pObj) && pCnf->pVarNums[pObj->Id] >= 0 ) + pVarToPol[ pCnf->pVarNums[pObj->Id] ] = pObj->fPhase; + // transform literals + for ( i = 0; i < pCnf->nLiterals; i++ ) + { + iVar = lit_var(pCnf->pClauses[0][i]); + assert( iVar < pCnf->nVars ); + if ( pVarToPol[iVar] ) + pCnf->pClauses[0][i] = lit_neg( pCnf->pClauses[0][i] ); + } + free( pVarToPol ); +} + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// diff --git a/src/aig/cnf/cnfUtil.c b/src/aig/cnf/cnfUtil.c index cd47cb58..3738fee5 100644 --- a/src/aig/cnf/cnfUtil.c +++ b/src/aig/cnf/cnfUtil.c @@ -140,6 +140,7 @@ int Cnf_ManScanMapping_rec( Cnf_Man_t * p, Aig_Obj_t * pObj, Vec_Ptr_t * vMapped else { pCutBest = pObj->pData; +// assert( pCutBest->nFanins > 0 ); assert( pCutBest->Cost < 127 ); aArea = pCutBest->Cost; Cnf_CutForEachLeaf( p->pManAig, pCutBest, pLeaf, i ) |