ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cnfMan.c File Reference
#include "cnf.h"
#include "sat/bsat/satSolver.h"
#include "sat/bsat/satSolver2.h"
#include "misc/zlib/zlib.h"
Include dependency graph for cnfMan.c:

Go to the source code of this file.

Functions

Cnf_Man_tCnf_ManStart ()
 FUNCTION DEFINITIONS ///.
 
void Cnf_ManStop (Cnf_Man_t *p)
 
Vec_Int_tCnf_DataCollectPiSatNums (Cnf_Dat_t *pCnf, Aig_Man_t *p)
 
Cnf_Dat_tCnf_DataAlloc (Aig_Man_t *pAig, int nVars, int nClauses, int nLiterals)
 
Cnf_Dat_tCnf_DataDup (Cnf_Dat_t *p)
 
Cnf_Dat_tCnf_DataDupCof (Cnf_Dat_t *p, int Lit)
 
Cnf_Dat_tCnf_DataDupCofArray (Cnf_Dat_t *p, Vec_Int_t *vLits)
 
void Cnf_DataFree (Cnf_Dat_t *p)
 
void Cnf_DataLift (Cnf_Dat_t *p, int nVarsPlus)
 
void Cnf_DataCollectFlipLits (Cnf_Dat_t *p, int iFlipVar, Vec_Int_t *vFlips)
 
void Cnf_DataLiftAndFlipLits (Cnf_Dat_t *p, int nVarsPlus, Vec_Int_t *vLits)
 
void Cnf_DataPrint (Cnf_Dat_t *p, int fReadable)
 
void Cnf_DataWriteIntoFileGz (Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
 
void Cnf_DataWriteIntoFileInvGz (Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vExists1, Vec_Int_t *vForAlls, Vec_Int_t *vExists2)
 
void Cnf_DataWriteIntoFile (Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
 
void Cnf_DataWriteIntoFileInv (Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vExists1, Vec_Int_t *vForAlls, Vec_Int_t *vExists2)
 
void * Cnf_DataWriteIntoSolverInt (void *pSolver, Cnf_Dat_t *p, int nFrames, int fInit)
 
void * Cnf_DataWriteIntoSolver (Cnf_Dat_t *p, int nFrames, int fInit)
 
void * Cnf_DataWriteIntoSolver2 (Cnf_Dat_t *p, int nFrames, int fInit)
 
int Cnf_DataWriteOrClause (void *p, Cnf_Dat_t *pCnf)
 
int Cnf_DataWriteOrClause2 (void *p, Cnf_Dat_t *pCnf)
 
int Cnf_DataWriteAndClauses (void *p, Cnf_Dat_t *pCnf)
 
void Cnf_DataTranformPolarity (Cnf_Dat_t *pCnf, int fTransformPos)
 
int Cnf_DataAddXorClause (void *pSat, int iVarA, int iVarB, int iVarC)
 

Function Documentation

◆ Cnf_DataAddXorClause()

int Cnf_DataAddXorClause ( void * pSat,
int iVarA,
int iVarB,
int iVarC )

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

Synopsis [Adds constraints for the two-input AND-gate.]

Description []

SideEffects []

SeeAlso []

Definition at line 804 of file cnfMan.c.

805{
806 lit Lits[3];
807 assert( iVarA > 0 && iVarB > 0 && iVarC > 0 );
808
809 Lits[0] = toLitCond( iVarA, 1 );
810 Lits[1] = toLitCond( iVarB, 1 );
811 Lits[2] = toLitCond( iVarC, 1 );
812 if ( !sat_solver_addclause( (sat_solver *)pSat, Lits, Lits + 3 ) )
813 return 0;
814
815 Lits[0] = toLitCond( iVarA, 1 );
816 Lits[1] = toLitCond( iVarB, 0 );
817 Lits[2] = toLitCond( iVarC, 0 );
818 if ( !sat_solver_addclause( (sat_solver *)pSat, Lits, Lits + 3 ) )
819 return 0;
820
821 Lits[0] = toLitCond( iVarA, 0 );
822 Lits[1] = toLitCond( iVarB, 1 );
823 Lits[2] = toLitCond( iVarC, 0 );
824 if ( !sat_solver_addclause( (sat_solver *)pSat, Lits, Lits + 3 ) )
825 return 0;
826
827 Lits[0] = toLitCond( iVarA, 0 );
828 Lits[1] = toLitCond( iVarB, 0 );
829 Lits[2] = toLitCond( iVarC, 1 );
830 if ( !sat_solver_addclause( (sat_solver *)pSat, Lits, Lits + 3 ) )
831 return 0;
832
833 return 1;
834}
#define sat_solver_addclause
Definition cecSatG2.c:37
#define sat_solver
Definition cecSatG2.c:34
int lit
Definition satVec.h:130
#define assert(ex)
Definition util_old.h:213
Here is the caller graph for this function:

◆ Cnf_DataAlloc()

Cnf_Dat_t * Cnf_DataAlloc ( Aig_Man_t * pAig,
int nVars,
int nClauses,
int nLiterals )

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

Synopsis [Allocates the new CNF.]

Description []

SideEffects []

SeeAlso []

Definition at line 124 of file cnfMan.c.

125{
126 Cnf_Dat_t * pCnf;
127 pCnf = ABC_CALLOC( Cnf_Dat_t, 1 );
128 pCnf->pMan = pAig;
129 pCnf->nVars = nVars;
130 pCnf->nClauses = nClauses;
131 pCnf->nLiterals = nLiterals;
132 pCnf->pClauses = ABC_ALLOC( int *, nClauses + 1 );
133 pCnf->pClauses[0] = ABC_ALLOC( int, nLiterals );
134 pCnf->pClauses[nClauses] = pCnf->pClauses[0] + nLiterals;
135 if ( pCnf->pVarNums )
136 pCnf->pVarNums = ABC_FALLOC( int, Aig_ManObjNumMax(pAig) );
137 return pCnf;
138}
#define ABC_FALLOC(type, num)
Definition abc_global.h:266
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
struct Cnf_Dat_t_ Cnf_Dat_t
Definition cnf.h:52
int nVars
Definition cnf.h:59
int nLiterals
Definition cnf.h:60
int * pVarNums
Definition cnf.h:63
int ** pClauses
Definition cnf.h:62
int nClauses
Definition cnf.h:61
Aig_Man_t * pMan
Definition cnf.h:58
Here is the caller graph for this function:

◆ Cnf_DataCollectFlipLits()

void Cnf_DataCollectFlipLits ( Cnf_Dat_t * p,
int iFlipVar,
Vec_Int_t * vFlips )

Definition at line 245 of file cnfMan.c.

246{
247 int v;
248 assert( p->pMan == NULL );
249 Vec_IntClear( vFlips );
250 for ( v = 0; v < p->nLiterals; v++ )
251 if ( Abc_Lit2Var(p->pClauses[0][v]) == iFlipVar )
252 Vec_IntPush( vFlips, v );
253}
Cube * p
Definition exorList.c:222
Here is the caller graph for this function:

◆ Cnf_DataCollectPiSatNums()

Vec_Int_t * Cnf_DataCollectPiSatNums ( Cnf_Dat_t * pCnf,
Aig_Man_t * p )

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

Synopsis [Returns the array of CI IDs.]

Description []

SideEffects []

SeeAlso []

Definition at line 104 of file cnfMan.c.

105{
106 Aig_Obj_t * pObj; int i;
107 Vec_Int_t * vCiIds = Vec_IntAlloc( Aig_ManCiNum(p) );
108 Aig_ManForEachCi( p, pObj, i )
109 Vec_IntPush( vCiIds, pCnf->pVarNums[pObj->Id] );
110 return vCiIds;
111}
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition aig.h:393
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
int Id
Definition aig.h:85
Here is the caller graph for this function:

◆ Cnf_DataDup()

Cnf_Dat_t * Cnf_DataDup ( Cnf_Dat_t * p)

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

Synopsis [Allocates the new CNF.]

Description []

SideEffects []

SeeAlso []

Definition at line 151 of file cnfMan.c.

152{
153 Cnf_Dat_t * pCnf;
154 int i;
155 pCnf = Cnf_DataAlloc( p->pMan, p->nVars, p->nClauses, p->nLiterals );
156 memcpy( pCnf->pClauses[0], p->pClauses[0], sizeof(int) * p->nLiterals );
157 if ( p->pVarNums )
158 memcpy( pCnf->pVarNums, p->pVarNums, sizeof(int) * Aig_ManObjNumMax(p->pMan) );
159 for ( i = 1; i < p->nClauses; i++ )
160 pCnf->pClauses[i] = pCnf->pClauses[0] + (p->pClauses[i] - p->pClauses[0]);
161 return pCnf;
162}
Cnf_Dat_t * Cnf_DataAlloc(Aig_Man_t *pAig, int nVars, int nClauses, int nLiterals)
Definition cnfMan.c:124
char * memcpy()
Here is the call graph for this function:

◆ Cnf_DataDupCof()

Cnf_Dat_t * Cnf_DataDupCof ( Cnf_Dat_t * p,
int Lit )

Definition at line 163 of file cnfMan.c.

164{
165 Cnf_Dat_t * pCnf;
166 int i;
167 pCnf = Cnf_DataAlloc( p->pMan, p->nVars, p->nClauses+1, p->nLiterals+1 );
168 memcpy( pCnf->pClauses[0], p->pClauses[0], sizeof(int) * p->nLiterals );
169 if ( pCnf->pVarNums )
170 memcpy( pCnf->pVarNums, p->pVarNums, sizeof(int) * Aig_ManObjNumMax(p->pMan) );
171 for ( i = 1; i < p->nClauses; i++ )
172 pCnf->pClauses[i] = pCnf->pClauses[0] + (p->pClauses[i] - p->pClauses[0]);
173 pCnf->pClauses[p->nClauses] = pCnf->pClauses[0] + p->nLiterals;
174 pCnf->pClauses[p->nClauses][0] = Lit;
175 assert( pCnf->pClauses[p->nClauses+1] == pCnf->pClauses[0] + p->nLiterals+1 );
176 return pCnf;
177}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cnf_DataDupCofArray()

Cnf_Dat_t * Cnf_DataDupCofArray ( Cnf_Dat_t * p,
Vec_Int_t * vLits )

Definition at line 178 of file cnfMan.c.

179{
180 Cnf_Dat_t * pCnf;
181 int i, iLit;
182 pCnf = Cnf_DataAlloc( p->pMan, p->nVars, p->nClauses+Vec_IntSize(vLits), p->nLiterals+Vec_IntSize(vLits) );
183 memcpy( pCnf->pClauses[0], p->pClauses[0], sizeof(int) * p->nLiterals );
184 if ( pCnf->pVarNums )
185 memcpy( pCnf->pVarNums, p->pVarNums, sizeof(int) * Aig_ManObjNumMax(p->pMan) );
186 for ( i = 1; i < p->nClauses; i++ )
187 pCnf->pClauses[i] = pCnf->pClauses[0] + (p->pClauses[i] - p->pClauses[0]);
188 Vec_IntForEachEntry( vLits, iLit, i ) {
189 pCnf->pClauses[p->nClauses+i] = pCnf->pClauses[0] + p->nLiterals+i;
190 pCnf->pClauses[p->nClauses+i][0] = iLit;
191 }
192 assert( pCnf->pClauses[p->nClauses+Vec_IntSize(vLits)] == pCnf->pClauses[0] + p->nLiterals+Vec_IntSize(vLits) );
193 return pCnf;
194}
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cnf_DataFree()

void Cnf_DataFree ( Cnf_Dat_t * p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 207 of file cnfMan.c.

208{
209 if ( p == NULL )
210 return;
211 Vec_IntFreeP( &p->vMapping );
212 ABC_FREE( p->pClaPols );
213 ABC_FREE( p->pObj2Clause );
214 ABC_FREE( p->pObj2Count );
215 ABC_FREE( p->pClauses[0] );
216 ABC_FREE( p->pClauses );
217 ABC_FREE( p->pVarNums );
218 ABC_FREE( p );
219}
#define ABC_FREE(obj)
Definition abc_global.h:267

◆ Cnf_DataLift()

void Cnf_DataLift ( Cnf_Dat_t * p,
int nVarsPlus )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 232 of file cnfMan.c.

233{
234 Aig_Obj_t * pObj;
235 int v;
236 if ( p->pMan )
237 {
238 Aig_ManForEachObj( p->pMan, pObj, v )
239 if ( p->pVarNums[pObj->Id] >= 0 )
240 p->pVarNums[pObj->Id] += nVarsPlus;
241 }
242 for ( v = 0; v < p->nLiterals; v++ )
243 p->pClauses[0][v] += 2*nVarsPlus;
244}
#define Aig_ManForEachObj(p, pObj, i)
Definition aig.h:403
Here is the caller graph for this function:

◆ Cnf_DataLiftAndFlipLits()

void Cnf_DataLiftAndFlipLits ( Cnf_Dat_t * p,
int nVarsPlus,
Vec_Int_t * vLits )

Definition at line 254 of file cnfMan.c.

255{
256 int i, iLit;
257 assert( p->pMan == NULL );
258 Vec_IntForEachEntry( vLits, iLit, i )
259 p->pClauses[0][iLit] = Abc_LitNot(p->pClauses[0][iLit]) + 2*nVarsPlus;
260}
Here is the caller graph for this function:

◆ Cnf_DataPrint()

void Cnf_DataPrint ( Cnf_Dat_t * p,
int fReadable )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 273 of file cnfMan.c.

274{
275 FILE * pFile = stdout;
276 int * pLit, * pStop, i;
277 fprintf( pFile, "p cnf %d %d\n", p->nVars, p->nClauses );
278 for ( i = 0; i < p->nClauses; i++ )
279 {
280 for ( pLit = p->pClauses[i], pStop = p->pClauses[i+1]; pLit < pStop; pLit++ )
281 fprintf( pFile, "%s%d ", Abc_LitIsCompl(*pLit) ? "-":"", fReadable? Abc_Lit2Var(*pLit) : Abc_Lit2Var(*pLit)+1 );
282 fprintf( pFile, "\n" );
283 }
284 fprintf( pFile, "\n" );
285}

◆ Cnf_DataTranformPolarity()

void Cnf_DataTranformPolarity ( Cnf_Dat_t * pCnf,
int fTransformPos )

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

Synopsis [Transforms polarity of the internal veriables.]

Description []

SideEffects []

SeeAlso []

Definition at line 768 of file cnfMan.c.

769{
770 Aig_Obj_t * pObj;
771 int * pVarToPol;
772 int i, iVar;
773 // create map from the variable number to its polarity
774 pVarToPol = ABC_CALLOC( int, pCnf->nVars );
775 Aig_ManForEachObj( pCnf->pMan, pObj, i )
776 {
777 if ( !fTransformPos && Aig_ObjIsCo(pObj) )
778 continue;
779 if ( pCnf->pVarNums[pObj->Id] >= 0 )
780 pVarToPol[ pCnf->pVarNums[pObj->Id] ] = pObj->fPhase;
781 }
782 // transform literals
783 for ( i = 0; i < pCnf->nLiterals; i++ )
784 {
785 iVar = lit_var(pCnf->pClauses[0][i]);
786 assert( iVar < pCnf->nVars );
787 if ( pVarToPol[iVar] )
788 pCnf->pClauses[0][i] = lit_neg( pCnf->pClauses[0][i] );
789 }
790 ABC_FREE( pVarToPol );
791}
unsigned int fPhase
Definition aig.h:78
Here is the caller graph for this function:

◆ Cnf_DataWriteAndClauses()

int Cnf_DataWriteAndClauses ( void * p,
Cnf_Dat_t * pCnf )

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

Synopsis [Adds the OR-clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 743 of file cnfMan.c.

744{
745 sat_solver * pSat = (sat_solver *)p;
746 Aig_Obj_t * pObj;
747 int i, Lit;
748 Aig_ManForEachCo( pCnf->pMan, pObj, i )
749 {
750 Lit = toLitCond( pCnf->pVarNums[pObj->Id], 0 );
751 if ( !sat_solver_addclause( pSat, &Lit, &Lit+1 ) )
752 return 0;
753 }
754 return 1;
755}
#define Aig_ManForEachCo(p, pObj, i)
Definition aig.h:398
Here is the caller graph for this function:

◆ Cnf_DataWriteIntoFile()

void Cnf_DataWriteIntoFile ( Cnf_Dat_t * p,
char * pFileName,
int fReadable,
Vec_Int_t * vForAlls,
Vec_Int_t * vExists )

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 387 of file cnfMan.c.

388{
389 FILE * pFile;
390 int * pLit, * pStop, i, VarId;
391 if ( !strncmp(pFileName+strlen(pFileName)-3,".gz",3) )
392 {
393 Cnf_DataWriteIntoFileGz( p, pFileName, fReadable, vForAlls, vExists );
394 return;
395 }
396 pFile = fopen( pFileName, "w" );
397 if ( pFile == NULL )
398 {
399 printf( "Cnf_WriteIntoFile(): Output file cannot be opened.\n" );
400 return;
401 }
402 fprintf( pFile, "c Result of efficient AIG-to-CNF conversion using package CNF\n" );
403 fprintf( pFile, "p cnf %d %d\n", p->nVars, p->nClauses );
404 if ( vForAlls )
405 {
406 fprintf( pFile, "a " );
407 Vec_IntForEachEntry( vForAlls, VarId, i )
408 fprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
409 fprintf( pFile, "0\n" );
410 }
411 if ( vExists )
412 {
413 fprintf( pFile, "e " );
414 Vec_IntForEachEntry( vExists, VarId, i )
415 fprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
416 fprintf( pFile, "0\n" );
417 }
418 for ( i = 0; i < p->nClauses; i++ )
419 {
420 for ( pLit = p->pClauses[i], pStop = p->pClauses[i+1]; pLit < pStop; pLit++ )
421 fprintf( pFile, "%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) );
422 fprintf( pFile, "0\n" );
423 }
424 fprintf( pFile, "\n" );
425 fclose( pFile );
426}
void Cnf_DataWriteIntoFileGz(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
Definition cnfMan.c:298
int strncmp()
int strlen()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cnf_DataWriteIntoFileGz()

void Cnf_DataWriteIntoFileGz ( Cnf_Dat_t * p,
char * pFileName,
int fReadable,
Vec_Int_t * vForAlls,
Vec_Int_t * vExists )

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 298 of file cnfMan.c.

299{
300 gzFile pFile;
301 int * pLit, * pStop, i, VarId;
302 pFile = gzopen( pFileName, "wb" );
303 if ( pFile == NULL )
304 {
305 printf( "Cnf_WriteIntoFile(): Output file cannot be opened.\n" );
306 return;
307 }
308 gzprintf( pFile, "c Result of efficient AIG-to-CNF conversion using package CNF\n" );
309 gzprintf( pFile, "p cnf %d %d\n", p->nVars, p->nClauses );
310 if ( vForAlls )
311 {
312 gzprintf( pFile, "a " );
313 Vec_IntForEachEntry( vForAlls, VarId, i )
314 gzprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
315 gzprintf( pFile, "0\n" );
316 }
317 if ( vExists )
318 {
319 gzprintf( pFile, "e " );
320 Vec_IntForEachEntry( vExists, VarId, i )
321 gzprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
322 gzprintf( pFile, "0\n" );
323 }
324 for ( i = 0; i < p->nClauses; i++ )
325 {
326 for ( pLit = p->pClauses[i], pStop = p->pClauses[i+1]; pLit < pStop; pLit++ )
327 gzprintf( pFile, "%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) );
328 gzprintf( pFile, "0\n" );
329 }
330 gzprintf( pFile, "\n" );
331 gzclose( pFile );
332}
ABC_NAMESPACE_IMPL_START int ZEXPORT gzclose(gzFile file)
Definition gzclose.c:18
gzFile ZEXPORT gzopen(const char *path, const char *mode)
Definition gzlib.c:198
int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20)
Definition gzwrite.c:347
voidp gzFile
Definition zlib.h:1173
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cnf_DataWriteIntoFileInv()

void Cnf_DataWriteIntoFileInv ( Cnf_Dat_t * p,
char * pFileName,
int fReadable,
Vec_Int_t * vExists1,
Vec_Int_t * vForAlls,
Vec_Int_t * vExists2 )

Definition at line 427 of file cnfMan.c.

428{
429 FILE * pFile;
430 int * pLit, * pStop, i, VarId;
431 if ( !strncmp(pFileName+strlen(pFileName)-3,".gz",3) )
432 {
433 Cnf_DataWriteIntoFileInvGz( p, pFileName, fReadable, vExists1, vForAlls, vExists2 );
434 return;
435 }
436 pFile = fopen( pFileName, "w" );
437 if ( pFile == NULL )
438 {
439 printf( "Cnf_WriteIntoFile(): Output file cannot be opened.\n" );
440 return;
441 }
442 fprintf( pFile, "c Result of efficient AIG-to-CNF conversion using package CNF\n" );
443 fprintf( pFile, "p cnf %d %d\n", p->nVars, p->nClauses );
444 if ( vExists1 )
445 {
446 fprintf( pFile, "e " );
447 Vec_IntForEachEntry( vExists1, VarId, i )
448 fprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
449 fprintf( pFile, "0\n" );
450 }
451 if ( vForAlls )
452 {
453 fprintf( pFile, "a " );
454 Vec_IntForEachEntry( vForAlls, VarId, i )
455 fprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
456 fprintf( pFile, "0\n" );
457 }
458 if ( vExists2 )
459 {
460 fprintf( pFile, "e " );
461 Vec_IntForEachEntry( vExists2, VarId, i )
462 fprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
463 fprintf( pFile, "0\n" );
464 }
465 for ( i = 0; i < p->nClauses; i++ )
466 {
467 for ( pLit = p->pClauses[i], pStop = p->pClauses[i+1]; pLit < pStop; pLit++ )
468 fprintf( pFile, "%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) );
469 fprintf( pFile, "0\n" );
470 }
471 fprintf( pFile, "\n" );
472 fclose( pFile );
473}
void Cnf_DataWriteIntoFileInvGz(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vExists1, Vec_Int_t *vForAlls, Vec_Int_t *vExists2)
Definition cnfMan.c:333
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cnf_DataWriteIntoFileInvGz()

void Cnf_DataWriteIntoFileInvGz ( Cnf_Dat_t * p,
char * pFileName,
int fReadable,
Vec_Int_t * vExists1,
Vec_Int_t * vForAlls,
Vec_Int_t * vExists2 )

Definition at line 333 of file cnfMan.c.

334{
335 gzFile pFile;
336 int * pLit, * pStop, i, VarId;
337 pFile = gzopen( pFileName, "wb" );
338 if ( pFile == NULL )
339 {
340 printf( "Cnf_WriteIntoFile(): Output file cannot be opened.\n" );
341 return;
342 }
343 gzprintf( pFile, "c Result of efficient AIG-to-CNF conversion using package CNF\n" );
344 gzprintf( pFile, "p cnf %d %d\n", p->nVars, p->nClauses );
345 if ( vExists1 )
346 {
347 gzprintf( pFile, "e " );
348 Vec_IntForEachEntry( vExists1, VarId, i )
349 gzprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
350 gzprintf( pFile, "0\n" );
351 }
352 if ( vForAlls )
353 {
354 gzprintf( pFile, "a " );
355 Vec_IntForEachEntry( vForAlls, VarId, i )
356 gzprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
357 gzprintf( pFile, "0\n" );
358 }
359 if ( vExists2 )
360 {
361 gzprintf( pFile, "e " );
362 Vec_IntForEachEntry( vExists2, VarId, i )
363 gzprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
364 gzprintf( pFile, "0\n" );
365 }
366 for ( i = 0; i < p->nClauses; i++ )
367 {
368 for ( pLit = p->pClauses[i], pStop = p->pClauses[i+1]; pLit < pStop; pLit++ )
369 gzprintf( pFile, "%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) );
370 gzprintf( pFile, "0\n" );
371 }
372 gzprintf( pFile, "\n" );
373 gzclose( pFile );
374}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cnf_DataWriteIntoSolver()

void * Cnf_DataWriteIntoSolver ( Cnf_Dat_t * p,
int nFrames,
int fInit )

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 579 of file cnfMan.c.

580{
581 return Cnf_DataWriteIntoSolverInt( sat_solver_new(), p, nFrames, fInit );
582}
void * Cnf_DataWriteIntoSolverInt(void *pSolver, Cnf_Dat_t *p, int nFrames, int fInit)
Definition cnfMan.c:486
sat_solver * sat_solver_new(void)
Definition satSolver.c:1137
Here is the call graph for this function:

◆ Cnf_DataWriteIntoSolver2()

void * Cnf_DataWriteIntoSolver2 ( Cnf_Dat_t * p,
int nFrames,
int fInit )

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 595 of file cnfMan.c.

596{
597 sat_solver2 * pSat;
598 int i, f, status;
599 assert( nFrames > 0 );
600 pSat = sat_solver2_new();
601 sat_solver2_setnvars( pSat, p->nVars * nFrames );
602 for ( i = 0; i < p->nClauses; i++ )
603 {
604 if ( !sat_solver2_addclause( pSat, p->pClauses[i], p->pClauses[i+1], 0 ) )
605 {
606 sat_solver2_delete( pSat );
607 return NULL;
608 }
609 }
610 if ( nFrames > 1 )
611 {
612 Aig_Obj_t * pObjLo, * pObjLi;
613 int nLitsAll, * pLits, Lits[2];
614 nLitsAll = 2 * p->nVars;
615 pLits = p->pClauses[0];
616 for ( f = 1; f < nFrames; f++ )
617 {
618 // add equality of register inputs/outputs for different timeframes
619 Aig_ManForEachLiLoSeq( p->pMan, pObjLi, pObjLo, i )
620 {
621 Lits[0] = (f-1)*nLitsAll + toLitCond( p->pVarNums[pObjLi->Id], 0 );
622 Lits[1] = f *nLitsAll + toLitCond( p->pVarNums[pObjLo->Id], 1 );
623 if ( !sat_solver2_addclause( pSat, Lits, Lits + 2, 0 ) )
624 {
625 sat_solver2_delete( pSat );
626 return NULL;
627 }
628 Lits[0]++;
629 Lits[1]--;
630 if ( !sat_solver2_addclause( pSat, Lits, Lits + 2, 0 ) )
631 {
632 sat_solver2_delete( pSat );
633 return NULL;
634 }
635 }
636 // add clauses for the next timeframe
637 for ( i = 0; i < p->nLiterals; i++ )
638 pLits[i] += nLitsAll;
639 for ( i = 0; i < p->nClauses; i++ )
640 {
641 if ( !sat_solver2_addclause( pSat, p->pClauses[i], p->pClauses[i+1], 0 ) )
642 {
643 sat_solver2_delete( pSat );
644 return NULL;
645 }
646 }
647 }
648 // return literals to their original state
649 nLitsAll = (f-1) * nLitsAll;
650 for ( i = 0; i < p->nLiterals; i++ )
651 pLits[i] -= nLitsAll;
652 }
653 if ( fInit )
654 {
655 Aig_Obj_t * pObjLo;
656 int Lits[1];
657 Aig_ManForEachLoSeq( p->pMan, pObjLo, i )
658 {
659 Lits[0] = toLitCond( p->pVarNums[pObjLo->Id], 1 );
660 if ( !sat_solver2_addclause( pSat, Lits, Lits + 1, 0 ) )
661 {
662 sat_solver2_delete( pSat );
663 return NULL;
664 }
665 }
666 }
667 status = sat_solver2_simplify(pSat);
668 if ( status == 0 )
669 {
670 sat_solver2_delete( pSat );
671 return NULL;
672 }
673 return pSat;
674}
#define Aig_ManForEachLoSeq(p, pObj, i)
Definition aig.h:441
#define Aig_ManForEachLiLoSeq(p, pObjLi, pObjLo, k)
Definition aig.h:450
void sat_solver2_delete(sat_solver2 *s)
int sat_solver2_simplify(sat_solver2 *s)
Definition satSolver2.c:996
sat_solver2 * sat_solver2_new(void)
void sat_solver2_setnvars(sat_solver2 *s, int n)
int sat_solver2_addclause(sat_solver2 *s, lit *begin, lit *end, int Id)
struct sat_solver2_t sat_solver2
Definition satSolver2.h:44
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cnf_DataWriteIntoSolverInt()

void * Cnf_DataWriteIntoSolverInt ( void * pSolver,
Cnf_Dat_t * p,
int nFrames,
int fInit )

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 486 of file cnfMan.c.

487{
488 sat_solver * pSat = (sat_solver *)pSolver;
489 int i, f, status;
490 assert( nFrames > 0 );
491 assert( pSat );
492// pSat = sat_solver_new();
493 sat_solver_setnvars( pSat, p->nVars * nFrames );
494 for ( i = 0; i < p->nClauses; i++ )
495 {
496 if ( !sat_solver_addclause( pSat, p->pClauses[i], p->pClauses[i+1] ) )
497 {
498 sat_solver_delete( pSat );
499 return NULL;
500 }
501 }
502 if ( nFrames > 1 )
503 {
504 Aig_Obj_t * pObjLo, * pObjLi;
505 int nLitsAll, * pLits, Lits[2];
506 nLitsAll = 2 * p->nVars;
507 pLits = p->pClauses[0];
508 for ( f = 1; f < nFrames; f++ )
509 {
510 // add equality of register inputs/outputs for different timeframes
511 Aig_ManForEachLiLoSeq( p->pMan, pObjLi, pObjLo, i )
512 {
513 Lits[0] = (f-1)*nLitsAll + toLitCond( p->pVarNums[pObjLi->Id], 0 );
514 Lits[1] = f *nLitsAll + toLitCond( p->pVarNums[pObjLo->Id], 1 );
515 if ( !sat_solver_addclause( pSat, Lits, Lits + 2 ) )
516 {
517 sat_solver_delete( pSat );
518 return NULL;
519 }
520 Lits[0]++;
521 Lits[1]--;
522 if ( !sat_solver_addclause( pSat, Lits, Lits + 2 ) )
523 {
524 sat_solver_delete( pSat );
525 return NULL;
526 }
527 }
528 // add clauses for the next timeframe
529 for ( i = 0; i < p->nLiterals; i++ )
530 pLits[i] += nLitsAll;
531 for ( i = 0; i < p->nClauses; i++ )
532 {
533 if ( !sat_solver_addclause( pSat, p->pClauses[i], p->pClauses[i+1] ) )
534 {
535 sat_solver_delete( pSat );
536 return NULL;
537 }
538 }
539 }
540 // return literals to their original state
541 nLitsAll = (f-1) * nLitsAll;
542 for ( i = 0; i < p->nLiterals; i++ )
543 pLits[i] -= nLitsAll;
544 }
545 if ( fInit )
546 {
547 Aig_Obj_t * pObjLo;
548 int Lits[1];
549 Aig_ManForEachLoSeq( p->pMan, pObjLo, i )
550 {
551 Lits[0] = toLitCond( p->pVarNums[pObjLo->Id], 1 );
552 if ( !sat_solver_addclause( pSat, Lits, Lits + 1 ) )
553 {
554 sat_solver_delete( pSat );
555 return NULL;
556 }
557 }
558 }
559 status = sat_solver_simplify(pSat);
560 if ( status == 0 )
561 {
562 sat_solver_delete( pSat );
563 return NULL;
564 }
565 return pSat;
566}
int sat_solver_simplify(sat_solver *s)
Definition satSolver.c:1515
void sat_solver_setnvars(sat_solver *s, int n)
Definition satSolver.c:1272
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cnf_DataWriteOrClause()

int Cnf_DataWriteOrClause ( void * p,
Cnf_Dat_t * pCnf )

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

Synopsis [Adds the OR-clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 687 of file cnfMan.c.

688{
689 sat_solver * pSat = (sat_solver *)p;
690 Aig_Obj_t * pObj;
691 int i, * pLits;
692 pLits = ABC_ALLOC( int, Aig_ManCoNum(pCnf->pMan) );
693 Aig_ManForEachCo( pCnf->pMan, pObj, i )
694 pLits[i] = toLitCond( pCnf->pVarNums[pObj->Id], 0 );
695 if ( !sat_solver_addclause( pSat, pLits, pLits + Aig_ManCoNum(pCnf->pMan) ) )
696 {
697 ABC_FREE( pLits );
698 return 0;
699 }
700 ABC_FREE( pLits );
701 return 1;
702}
Here is the caller graph for this function:

◆ Cnf_DataWriteOrClause2()

int Cnf_DataWriteOrClause2 ( void * p,
Cnf_Dat_t * pCnf )

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

Synopsis [Adds the OR-clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 715 of file cnfMan.c.

716{
717 sat_solver2 * pSat = (sat_solver2 *)p;
718 Aig_Obj_t * pObj;
719 int i, * pLits;
720 pLits = ABC_ALLOC( int, Aig_ManCoNum(pCnf->pMan) );
721 Aig_ManForEachCo( pCnf->pMan, pObj, i )
722 pLits[i] = toLitCond( pCnf->pVarNums[pObj->Id], 0 );
723 if ( !sat_solver2_addclause( pSat, pLits, pLits + Aig_ManCoNum(pCnf->pMan), 0 ) )
724 {
725 ABC_FREE( pLits );
726 return 0;
727 }
728 ABC_FREE( pLits );
729 return 1;
730}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cnf_ManStart()

Cnf_Man_t * Cnf_ManStart ( )

FUNCTION DEFINITIONS ///.

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

Synopsis [Starts the fraiging manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 51 of file cnfMan.c.

52{
53 Cnf_Man_t * p;
54 int i;
55 // allocate the manager
56 p = ABC_ALLOC( Cnf_Man_t, 1 );
57 memset( p, 0, sizeof(Cnf_Man_t) );
58 // derive internal data structures
59 Cnf_ReadMsops( &p->pSopSizes, &p->pSops );
60 // allocate memory manager for cuts
61 p->pMemCuts = Aig_MmFlexStart();
62 p->nMergeLimit = 10;
63 // allocate temporary truth tables
64 p->pTruths[0] = ABC_ALLOC( unsigned, 4 * Abc_TruthWordNum(p->nMergeLimit) );
65 for ( i = 1; i < 4; i++ )
66 p->pTruths[i] = p->pTruths[i-1] + Abc_TruthWordNum(p->nMergeLimit);
67 p->vMemory = Vec_IntAlloc( 1 << 18 );
68 return p;
69}
Aig_MmFlex_t * Aig_MmFlexStart()
Definition aigMem.c:305
void Cnf_ReadMsops(char **ppSopSizes, char ***ppSops)
FUNCTION DEFINITIONS ///.
Definition cnfData.c:4537
typedefABC_NAMESPACE_HEADER_START struct Cnf_Man_t_ Cnf_Man_t
INCLUDES ///.
Definition cnf.h:51
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cnf_ManStop()

void Cnf_ManStop ( Cnf_Man_t * p)

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

Synopsis [Stops the fraiging manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 82 of file cnfMan.c.

83{
84 Vec_IntFree( p->vMemory );
85 ABC_FREE( p->pTruths[0] );
86 Aig_MmFlexStop( p->pMemCuts, 0 );
87 ABC_FREE( p->pSopSizes );
88 ABC_FREE( p->pSops[1] );
89 ABC_FREE( p->pSops );
90 ABC_FREE( p );
91}
void Aig_MmFlexStop(Aig_MmFlex_t *p, int fVerbose)
Definition aigMem.c:337
Here is the call graph for this function:
Here is the caller graph for this function: