abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cnfMan.c File Reference
#include "cnf.h"
#include "sat/bsat/satSolver.h"
#include "sat/bsat/satSolver2.h"
#include "misc/zlib/zlib.h"

Go to the source code of this file.

Functions

static ABC_NAMESPACE_IMPL_START int Cnf_Lit2Var (int Lit)
 DECLARATIONS ///. More...
 
static int Cnf_Lit2Var2 (int Lit)
 
Cnf_Man_tCnf_ManStart ()
 FUNCTION DEFINITIONS ///. More...
 
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)
 
void Cnf_DataFree (Cnf_Dat_t *p)
 
void Cnf_DataLift (Cnf_Dat_t *p, int nVarsPlus)
 
void Cnf_DataFlipLastLiteral (Cnf_Dat_t *p)
 
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_DataWriteIntoFile (Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
 
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

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 688 of file cnfMan.c.

689 {
690  lit Lits[3];
691  assert( iVarA > 0 && iVarB > 0 && iVarC > 0 );
692 
693  Lits[0] = toLitCond( iVarA, 1 );
694  Lits[1] = toLitCond( iVarB, 1 );
695  Lits[2] = toLitCond( iVarC, 1 );
696  if ( !sat_solver_addclause( (sat_solver *)pSat, Lits, Lits + 3 ) )
697  return 0;
698 
699  Lits[0] = toLitCond( iVarA, 1 );
700  Lits[1] = toLitCond( iVarB, 0 );
701  Lits[2] = toLitCond( iVarC, 0 );
702  if ( !sat_solver_addclause( (sat_solver *)pSat, Lits, Lits + 3 ) )
703  return 0;
704 
705  Lits[0] = toLitCond( iVarA, 0 );
706  Lits[1] = toLitCond( iVarB, 1 );
707  Lits[2] = toLitCond( iVarC, 0 );
708  if ( !sat_solver_addclause( (sat_solver *)pSat, Lits, Lits + 3 ) )
709  return 0;
710 
711  Lits[0] = toLitCond( iVarA, 0 );
712  Lits[1] = toLitCond( iVarB, 0 );
713  Lits[2] = toLitCond( iVarC, 1 );
714  if ( !sat_solver_addclause( (sat_solver *)pSat, Lits, Lits + 3 ) )
715  return 0;
716 
717  return 1;
718 }
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
int lit
Definition: satVec.h:130
static lit toLitCond(int v, int c)
Definition: satVec.h:143
#define assert(ex)
Definition: util_old.h:213
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 126 of file cnfMan.c.

127 {
128  Cnf_Dat_t * pCnf;
129  int i;
130  pCnf = ABC_ALLOC( Cnf_Dat_t, 1 );
131  memset( pCnf, 0, sizeof(Cnf_Dat_t) );
132  pCnf->pMan = pAig;
133  pCnf->nVars = nVars;
134  pCnf->nClauses = nClauses;
135  pCnf->nLiterals = nLiterals;
136  pCnf->pClauses = ABC_ALLOC( int *, nClauses + 1 );
137  pCnf->pClauses[0] = ABC_ALLOC( int, nLiterals );
138  pCnf->pClauses[nClauses] = pCnf->pClauses[0] + nLiterals;
139  pCnf->pVarNums = ABC_ALLOC( int, Aig_ManObjNumMax(pAig) );
140 // memset( pCnf->pVarNums, 0xff, sizeof(int) * Aig_ManObjNumMax(pAig) );
141  for ( i = 0; i < Aig_ManObjNumMax(pAig); i++ )
142  pCnf->pVarNums[i] = -1;
143  return pCnf;
144 }
char * memset()
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
int * pVarNums
Definition: cnf.h:63
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Aig_Man_t * pMan
Definition: cnf.h:58
Definition: cnf.h:56
int ** pClauses
Definition: cnf.h:62
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
int nLiterals
Definition: cnf.h:60
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  Vec_Int_t * vCiIds;
107  Aig_Obj_t * pObj;
108  int i;
109  vCiIds = Vec_IntAlloc( Aig_ManCiNum(p) );
110  Aig_ManForEachCi( p, pObj, i )
111  Vec_IntPush( vCiIds, pCnf->pVarNums[pObj->Id] );
112  return vCiIds;
113 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Aig_ManCiNum(Aig_Man_t *p)
Definition: aig.h:251
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
Cnf_Dat_t* Cnf_DataDup ( Cnf_Dat_t p)

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

Synopsis [Allocates the new CNF.]

Description []

SideEffects []

SeeAlso []

Definition at line 157 of file cnfMan.c.

158 {
159  Cnf_Dat_t * pCnf;
160  int i;
161  pCnf = Cnf_DataAlloc( p->pMan, p->nVars, p->nClauses, p->nLiterals );
162  memcpy( pCnf->pClauses[0], p->pClauses[0], sizeof(int) * p->nLiterals );
163  memcpy( pCnf->pVarNums, p->pVarNums, sizeof(int) * Aig_ManObjNumMax(p->pMan) );
164  for ( i = 1; i < p->nClauses; i++ )
165  pCnf->pClauses[i] = pCnf->pClauses[0] + (p->pClauses[i] - p->pClauses[0]);
166  return pCnf;
167 }
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
int * pVarNums
Definition: cnf.h:63
char * memcpy()
Aig_Man_t * pMan
Definition: cnf.h:58
Definition: cnf.h:56
int ** pClauses
Definition: cnf.h:62
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
Cnf_Dat_t * Cnf_DataAlloc(Aig_Man_t *pAig, int nVars, int nClauses, int nLiterals)
Definition: cnfMan.c:126
int nLiterals
Definition: cnf.h:60
void Cnf_DataFlipLastLiteral ( Cnf_Dat_t p)

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 230 of file cnfMan.c.

231 {
232  p->pClauses[0][p->nLiterals-1] = lit_neg( p->pClauses[0][p->nLiterals-1] );
233 }
static lit lit_neg(lit l)
Definition: satVec.h:144
int ** pClauses
Definition: cnf.h:62
int nLiterals
Definition: cnf.h:60
void Cnf_DataFree ( Cnf_Dat_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 180 of file cnfMan.c.

181 {
182  if ( p == NULL )
183  return;
184  Vec_IntFreeP( &p->vMapping );
185  ABC_FREE( p->pClaPols );
186  ABC_FREE( p->pObj2Clause );
187  ABC_FREE( p->pObj2Count );
188  ABC_FREE( p->pClauses[0] );
189  ABC_FREE( p->pClauses );
190  ABC_FREE( p->pVarNums );
191  ABC_FREE( p );
192 }
Vec_Int_t * vMapping
Definition: cnf.h:67
unsigned char * pClaPols
Definition: cnf.h:66
int * pVarNums
Definition: cnf.h:63
int * pObj2Clause
Definition: cnf.h:64
int ** pClauses
Definition: cnf.h:62
static void Vec_IntFreeP(Vec_Int_t **p)
Definition: vecInt.h:289
#define ABC_FREE(obj)
Definition: abc_global.h:232
int * pObj2Count
Definition: cnf.h:65
void Cnf_DataLift ( Cnf_Dat_t p,
int  nVarsPlus 
)

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 205 of file cnfMan.c.

206 {
207  Aig_Obj_t * pObj;
208  int v;
209  if ( p->pMan )
210  {
211  Aig_ManForEachObj( p->pMan, pObj, v )
212  if ( p->pVarNums[pObj->Id] >= 0 )
213  p->pVarNums[pObj->Id] += nVarsPlus;
214  }
215  for ( v = 0; v < p->nLiterals; v++ )
216  p->pClauses[0][v] += 2*nVarsPlus;
217 }
Aig_Man_t * pMan
Definition: cnf.h:58
for(p=first;p->value< newval;p=p->next)
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
void Cnf_DataPrint ( Cnf_Dat_t p,
int  fReadable 
)

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 246 of file cnfMan.c.

247 {
248  FILE * pFile = stdout;
249  int * pLit, * pStop, i;
250  fprintf( pFile, "p cnf %d %d\n", p->nVars, p->nClauses );
251  for ( i = 0; i < p->nClauses; i++ )
252  {
253  for ( pLit = p->pClauses[i], pStop = p->pClauses[i+1]; pLit < pStop; pLit++ )
254  fprintf( pFile, "%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) );
255  fprintf( pFile, "\n" );
256  }
257  fprintf( pFile, "\n" );
258 }
static ABC_NAMESPACE_IMPL_START int Cnf_Lit2Var(int Lit)
DECLARATIONS ///.
Definition: cnfMan.c:33
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
int ** pClauses
Definition: cnf.h:62
static int Cnf_Lit2Var2(int Lit)
Definition: cnfMan.c:34
void Cnf_DataTranformPolarity ( Cnf_Dat_t pCnf,
int  fTransformPos 
)

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

Synopsis [Transforms polarity of the internal veriables.]

Description []

SideEffects []

SeeAlso []

Definition at line 652 of file cnfMan.c.

653 {
654  Aig_Obj_t * pObj;
655  int * pVarToPol;
656  int i, iVar;
657  // create map from the variable number to its polarity
658  pVarToPol = ABC_CALLOC( int, pCnf->nVars );
659  Aig_ManForEachObj( pCnf->pMan, pObj, i )
660  {
661  if ( !fTransformPos && Aig_ObjIsCo(pObj) )
662  continue;
663  if ( pCnf->pVarNums[pObj->Id] >= 0 )
664  pVarToPol[ pCnf->pVarNums[pObj->Id] ] = pObj->fPhase;
665  }
666  // transform literals
667  for ( i = 0; i < pCnf->nLiterals; i++ )
668  {
669  iVar = lit_var(pCnf->pClauses[0][i]);
670  assert( iVar < pCnf->nVars );
671  if ( pVarToPol[iVar] )
672  pCnf->pClauses[0][i] = lit_neg( pCnf->pClauses[0][i] );
673  }
674  ABC_FREE( pVarToPol );
675 }
static int lit_var(lit l)
Definition: satVec.h:145
int nVars
Definition: cnf.h:59
int * pVarNums
Definition: cnf.h:63
Aig_Man_t * pMan
Definition: cnf.h:58
static lit lit_neg(lit l)
Definition: satVec.h:144
int ** pClauses
Definition: cnf.h:62
Definition: aig.h:69
unsigned int fPhase
Definition: aig.h:78
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
#define assert(ex)
Definition: util_old.h:213
int nLiterals
Definition: cnf.h:60
int Id
Definition: aig.h:85
static int Aig_ObjIsCo(Aig_Obj_t *pObj)
Definition: aig.h:276
int Cnf_DataWriteAndClauses ( void *  p,
Cnf_Dat_t pCnf 
)

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

Synopsis [Adds the OR-clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 627 of file cnfMan.c.

628 {
629  sat_solver * pSat = (sat_solver *)p;
630  Aig_Obj_t * pObj;
631  int i, Lit;
632  Aig_ManForEachCo( pCnf->pMan, pObj, i )
633  {
634  Lit = toLitCond( pCnf->pVarNums[pObj->Id], 0 );
635  if ( !sat_solver_addclause( pSat, &Lit, &Lit+1 ) )
636  return 0;
637  }
638  return 1;
639 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
int * pVarNums
Definition: cnf.h:63
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
Aig_Man_t * pMan
Definition: cnf.h:58
static lit toLitCond(int v, int c)
Definition: satVec.h:143
Definition: aig.h:69
int Id
Definition: aig.h:85
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 318 of file cnfMan.c.

319 {
320  FILE * pFile;
321  int * pLit, * pStop, i, VarId;
322  if ( !strncmp(pFileName+strlen(pFileName)-3,".gz",3) )
323  {
324  Cnf_DataWriteIntoFileGz( p, pFileName, fReadable, vForAlls, vExists );
325  return;
326  }
327  pFile = fopen( pFileName, "w" );
328  if ( pFile == NULL )
329  {
330  printf( "Cnf_WriteIntoFile(): Output file cannot be opened.\n" );
331  return;
332  }
333  fprintf( pFile, "c Result of efficient AIG-to-CNF conversion using package CNF\n" );
334  fprintf( pFile, "p cnf %d %d\n", p->nVars, p->nClauses );
335  if ( vForAlls )
336  {
337  fprintf( pFile, "a " );
338  Vec_IntForEachEntry( vForAlls, VarId, i )
339  fprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
340  fprintf( pFile, "0\n" );
341  }
342  if ( vExists )
343  {
344  fprintf( pFile, "e " );
345  Vec_IntForEachEntry( vExists, VarId, i )
346  fprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
347  fprintf( pFile, "0\n" );
348  }
349  for ( i = 0; i < p->nClauses; i++ )
350  {
351  for ( pLit = p->pClauses[i], pStop = p->pClauses[i+1]; pLit < pStop; pLit++ )
352  fprintf( pFile, "%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) );
353  fprintf( pFile, "0\n" );
354  }
355  fprintf( pFile, "\n" );
356  fclose( pFile );
357 }
static ABC_NAMESPACE_IMPL_START int Cnf_Lit2Var(int Lit)
DECLARATIONS ///.
Definition: cnfMan.c:33
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
for(p=first;p->value< newval;p=p->next)
int ** pClauses
Definition: cnf.h:62
static int Cnf_Lit2Var2(int Lit)
Definition: cnfMan.c:34
if(last==0)
Definition: sparse_int.h:34
void Cnf_DataWriteIntoFileGz(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
Definition: cnfMan.c:271
int strncmp()
int strlen()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
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 271 of file cnfMan.c.

272 {
273  gzFile pFile;
274  int * pLit, * pStop, i, VarId;
275  pFile = gzopen( pFileName, "wb" );
276  if ( pFile == NULL )
277  {
278  printf( "Cnf_WriteIntoFile(): Output file cannot be opened.\n" );
279  return;
280  }
281  gzprintf( pFile, "c Result of efficient AIG-to-CNF conversion using package CNF\n" );
282  gzprintf( pFile, "p cnf %d %d\n", p->nVars, p->nClauses );
283  if ( vForAlls )
284  {
285  gzprintf( pFile, "a " );
286  Vec_IntForEachEntry( vForAlls, VarId, i )
287  gzprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
288  gzprintf( pFile, "0\n" );
289  }
290  if ( vExists )
291  {
292  gzprintf( pFile, "e " );
293  Vec_IntForEachEntry( vExists, VarId, i )
294  gzprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
295  gzprintf( pFile, "0\n" );
296  }
297  for ( i = 0; i < p->nClauses; i++ )
298  {
299  for ( pLit = p->pClauses[i], pStop = p->pClauses[i+1]; pLit < pStop; pLit++ )
300  gzprintf( pFile, "%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) );
301  gzprintf( pFile, "0\n" );
302  }
303  gzprintf( pFile, "\n" );
304  gzclose( pFile );
305 }
static ABC_NAMESPACE_IMPL_START int Cnf_Lit2Var(int Lit)
DECLARATIONS ///.
Definition: cnfMan.c:33
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
ABC_NAMESPACE_IMPL_START int ZEXPORT gzclose(gzFile file)
Definition: gzclose.c:18
voidp gzFile
Definition: zlib.h:1173
for(p=first;p->value< newval;p=p->next)
int ** pClauses
Definition: cnf.h:62
static int Cnf_Lit2Var2(int Lit)
Definition: cnfMan.c:34
if(last==0)
Definition: sparse_int.h:34
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
gzFile ZEXPORT gzopen(const char *path, const char *mode)
Definition: gzlib.c:198
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
void* Cnf_DataWriteIntoSolver ( Cnf_Dat_t p,
int  nFrames,
int  fInit 
)

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 463 of file cnfMan.c.

464 {
465  return Cnf_DataWriteIntoSolverInt( sat_solver_new(), p, nFrames, fInit );
466 }
void * Cnf_DataWriteIntoSolverInt(void *pSolver, Cnf_Dat_t *p, int nFrames, int fInit)
Definition: cnfMan.c:370
sat_solver * sat_solver_new(void)
Definition: satSolver.c:1001
void* Cnf_DataWriteIntoSolver2 ( Cnf_Dat_t p,
int  nFrames,
int  fInit 
)

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 479 of file cnfMan.c.

480 {
481  sat_solver2 * pSat;
482  int i, f, status;
483  assert( nFrames > 0 );
484  pSat = sat_solver2_new();
485  sat_solver2_setnvars( pSat, p->nVars * nFrames );
486  for ( i = 0; i < p->nClauses; i++ )
487  {
488  if ( !sat_solver2_addclause( pSat, p->pClauses[i], p->pClauses[i+1], 0 ) )
489  {
490  sat_solver2_delete( pSat );
491  return NULL;
492  }
493  }
494  if ( nFrames > 1 )
495  {
496  Aig_Obj_t * pObjLo, * pObjLi;
497  int nLitsAll, * pLits, Lits[2];
498  nLitsAll = 2 * p->nVars;
499  pLits = p->pClauses[0];
500  for ( f = 1; f < nFrames; f++ )
501  {
502  // add equality of register inputs/outputs for different timeframes
503  Aig_ManForEachLiLoSeq( p->pMan, pObjLi, pObjLo, i )
504  {
505  Lits[0] = (f-1)*nLitsAll + toLitCond( p->pVarNums[pObjLi->Id], 0 );
506  Lits[1] = f *nLitsAll + toLitCond( p->pVarNums[pObjLo->Id], 1 );
507  if ( !sat_solver2_addclause( pSat, Lits, Lits + 2, 0 ) )
508  {
509  sat_solver2_delete( pSat );
510  return NULL;
511  }
512  Lits[0]++;
513  Lits[1]--;
514  if ( !sat_solver2_addclause( pSat, Lits, Lits + 2, 0 ) )
515  {
516  sat_solver2_delete( pSat );
517  return NULL;
518  }
519  }
520  // add clauses for the next timeframe
521  for ( i = 0; i < p->nLiterals; i++ )
522  pLits[i] += nLitsAll;
523  for ( i = 0; i < p->nClauses; i++ )
524  {
525  if ( !sat_solver2_addclause( pSat, p->pClauses[i], p->pClauses[i+1], 0 ) )
526  {
527  sat_solver2_delete( pSat );
528  return NULL;
529  }
530  }
531  }
532  // return literals to their original state
533  nLitsAll = (f-1) * nLitsAll;
534  for ( i = 0; i < p->nLiterals; i++ )
535  pLits[i] -= nLitsAll;
536  }
537  if ( fInit )
538  {
539  Aig_Obj_t * pObjLo;
540  int Lits[1];
541  Aig_ManForEachLoSeq( p->pMan, pObjLo, i )
542  {
543  Lits[0] = toLitCond( p->pVarNums[pObjLo->Id], 1 );
544  if ( !sat_solver2_addclause( pSat, Lits, Lits + 1, 0 ) )
545  {
546  sat_solver2_delete( pSat );
547  return NULL;
548  }
549  }
550  }
551  status = sat_solver2_simplify(pSat);
552  if ( status == 0 )
553  {
554  sat_solver2_delete( pSat );
555  return NULL;
556  }
557  return pSat;
558 }
int nClauses
Definition: cnf.h:61
void sat_solver2_delete(sat_solver2 *s)
Definition: satSolver2.c:1225
int nVars
Definition: cnf.h:59
int * pVarNums
Definition: cnf.h:63
sat_solver2 * sat_solver2_new(void)
Definition: satSolver2.c:1109
int sat_solver2_addclause(sat_solver2 *s, lit *begin, lit *end, int Id)
Definition: satSolver2.c:1287
Aig_Man_t * pMan
Definition: cnf.h:58
void sat_solver2_setnvars(sat_solver2 *s, int n)
Definition: satSolver2.c:1170
int ** pClauses
Definition: cnf.h:62
int sat_solver2_simplify(sat_solver2 *s)
Definition: satSolver2.c:996
#define Aig_ManForEachLiLoSeq(p, pObjLi, pObjLo, k)
Definition: aig.h:450
static lit toLitCond(int v, int c)
Definition: satVec.h:143
Definition: aig.h:69
#define Aig_ManForEachLoSeq(p, pObj, i)
Definition: aig.h:441
#define assert(ex)
Definition: util_old.h:213
int nLiterals
Definition: cnf.h:60
int Id
Definition: aig.h:85
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 370 of file cnfMan.c.

371 {
372  sat_solver * pSat = (sat_solver *)pSolver;
373  int i, f, status;
374  assert( nFrames > 0 );
375  assert( pSat );
376 // pSat = sat_solver_new();
377  sat_solver_setnvars( pSat, p->nVars * nFrames );
378  for ( i = 0; i < p->nClauses; i++ )
379  {
380  if ( !sat_solver_addclause( pSat, p->pClauses[i], p->pClauses[i+1] ) )
381  {
382  sat_solver_delete( pSat );
383  return NULL;
384  }
385  }
386  if ( nFrames > 1 )
387  {
388  Aig_Obj_t * pObjLo, * pObjLi;
389  int nLitsAll, * pLits, Lits[2];
390  nLitsAll = 2 * p->nVars;
391  pLits = p->pClauses[0];
392  for ( f = 1; f < nFrames; f++ )
393  {
394  // add equality of register inputs/outputs for different timeframes
395  Aig_ManForEachLiLoSeq( p->pMan, pObjLi, pObjLo, i )
396  {
397  Lits[0] = (f-1)*nLitsAll + toLitCond( p->pVarNums[pObjLi->Id], 0 );
398  Lits[1] = f *nLitsAll + toLitCond( p->pVarNums[pObjLo->Id], 1 );
399  if ( !sat_solver_addclause( pSat, Lits, Lits + 2 ) )
400  {
401  sat_solver_delete( pSat );
402  return NULL;
403  }
404  Lits[0]++;
405  Lits[1]--;
406  if ( !sat_solver_addclause( pSat, Lits, Lits + 2 ) )
407  {
408  sat_solver_delete( pSat );
409  return NULL;
410  }
411  }
412  // add clauses for the next timeframe
413  for ( i = 0; i < p->nLiterals; i++ )
414  pLits[i] += nLitsAll;
415  for ( i = 0; i < p->nClauses; i++ )
416  {
417  if ( !sat_solver_addclause( pSat, p->pClauses[i], p->pClauses[i+1] ) )
418  {
419  sat_solver_delete( pSat );
420  return NULL;
421  }
422  }
423  }
424  // return literals to their original state
425  nLitsAll = (f-1) * nLitsAll;
426  for ( i = 0; i < p->nLiterals; i++ )
427  pLits[i] -= nLitsAll;
428  }
429  if ( fInit )
430  {
431  Aig_Obj_t * pObjLo;
432  int Lits[1];
433  Aig_ManForEachLoSeq( p->pMan, pObjLo, i )
434  {
435  Lits[0] = toLitCond( p->pVarNums[pObjLo->Id], 1 );
436  if ( !sat_solver_addclause( pSat, Lits, Lits + 1 ) )
437  {
438  sat_solver_delete( pSat );
439  return NULL;
440  }
441  }
442  }
443  status = sat_solver_simplify(pSat);
444  if ( status == 0 )
445  {
446  sat_solver_delete( pSat );
447  return NULL;
448  }
449  return pSat;
450 }
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
void sat_solver_delete(sat_solver *s)
Definition: satSolver.c:1141
int * pVarNums
Definition: cnf.h:63
Aig_Man_t * pMan
Definition: cnf.h:58
int ** pClauses
Definition: cnf.h:62
#define Aig_ManForEachLiLoSeq(p, pObjLi, pObjLo, k)
Definition: aig.h:450
static lit toLitCond(int v, int c)
Definition: satVec.h:143
void sat_solver_setnvars(sat_solver *s, int n)
Definition: satSolver.c:1072
Definition: aig.h:69
int sat_solver_simplify(sat_solver *s)
Definition: satSolver.c:1276
#define Aig_ManForEachLoSeq(p, pObj, i)
Definition: aig.h:441
#define assert(ex)
Definition: util_old.h:213
int nLiterals
Definition: cnf.h:60
int Id
Definition: aig.h:85
int Cnf_DataWriteOrClause ( void *  p,
Cnf_Dat_t pCnf 
)

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

Synopsis [Adds the OR-clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 571 of file cnfMan.c.

572 {
573  sat_solver * pSat = (sat_solver *)p;
574  Aig_Obj_t * pObj;
575  int i, * pLits;
576  pLits = ABC_ALLOC( int, Aig_ManCoNum(pCnf->pMan) );
577  Aig_ManForEachCo( pCnf->pMan, pObj, i )
578  pLits[i] = toLitCond( pCnf->pVarNums[pObj->Id], 0 );
579  if ( !sat_solver_addclause( pSat, pLits, pLits + Aig_ManCoNum(pCnf->pMan) ) )
580  {
581  ABC_FREE( pLits );
582  return 0;
583  }
584  ABC_FREE( pLits );
585  return 1;
586 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Aig_Man_t * pMan
Definition: cnf.h:58
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
static lit toLitCond(int v, int c)
Definition: satVec.h:143
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Cnf_DataWriteOrClause2 ( void *  p,
Cnf_Dat_t pCnf 
)

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

Synopsis [Adds the OR-clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 599 of file cnfMan.c.

600 {
601  sat_solver2 * pSat = (sat_solver2 *)p;
602  Aig_Obj_t * pObj;
603  int i, * pLits;
604  pLits = ABC_ALLOC( int, Aig_ManCoNum(pCnf->pMan) );
605  Aig_ManForEachCo( pCnf->pMan, pObj, i )
606  pLits[i] = toLitCond( pCnf->pVarNums[pObj->Id], 0 );
607  if ( !sat_solver2_addclause( pSat, pLits, pLits + Aig_ManCoNum(pCnf->pMan), 0 ) )
608  {
609  ABC_FREE( pLits );
610  return 0;
611  }
612  ABC_FREE( pLits );
613  return 1;
614 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int sat_solver2_addclause(sat_solver2 *s, lit *begin, lit *end, int Id)
Definition: satSolver2.c:1287
Aig_Man_t * pMan
Definition: cnf.h:58
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
static lit toLitCond(int v, int c)
Definition: satVec.h:143
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
#define ABC_FREE(obj)
Definition: abc_global.h:232
static ABC_NAMESPACE_IMPL_START int Cnf_Lit2Var ( int  Lit)
inlinestatic

DECLARATIONS ///.

CFile****************************************************************

FileName [cnfMan.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [AIG-to-CNF conversion.]

Synopsis []

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - April 28, 2007.]

Revision [

Id:
cnfMan.c,v 1.00 2007/04/28 00:00:00 alanmi Exp

]

Definition at line 33 of file cnfMan.c.

33 { return (Lit & 1)? -(Lit >> 1)-1 : (Lit >> 1)+1; }
static int Cnf_Lit2Var2 ( int  Lit)
inlinestatic

Definition at line 34 of file cnfMan.c.

34 { return (Lit & 1)? -(Lit >> 1) : (Lit >> 1); }
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 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int Abc_TruthWordNum(int nVars)
Definition: abc_global.h:256
void Cnf_ReadMsops(char **ppSopSizes, char ***ppSops)
FUNCTION DEFINITIONS ///.
Definition: cnfData.c:4537
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Aig_MmFlex_t * Aig_MmFlexStart()
Definition: aigMem.c:305
typedefABC_NAMESPACE_HEADER_START struct Cnf_Man_t_ Cnf_Man_t
INCLUDES ///.
Definition: cnf.h:51
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 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Aig_MmFlexStop(Aig_MmFlex_t *p, int fVerbose)
Definition: aigMem.c:337
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235