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

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START int Aig_ManScanMapping_rec (Cnf_Man_t *p, Aig_Obj_t *pObj, Vec_Ptr_t *vMapped)
 DECLARATIONS ///. More...
 
Vec_Ptr_tAig_ManScanMapping (Cnf_Man_t *p, int fCollect)
 
int Cnf_ManScanMapping_rec (Cnf_Man_t *p, Aig_Obj_t *pObj, Vec_Ptr_t *vMapped, int fPreorder)
 
Vec_Ptr_tCnf_ManScanMapping (Cnf_Man_t *p, int fCollect, int fPreorder)
 
Vec_Int_tCnf_DataCollectCiSatNums (Cnf_Dat_t *pCnf, Aig_Man_t *p)
 
Vec_Int_tCnf_DataCollectCoSatNums (Cnf_Dat_t *pCnf, Aig_Man_t *p)
 
unsigned char * Cnf_DataDeriveLitPolarities (Cnf_Dat_t *p)
 
Cnf_Dat_tCnf_DataReadFromFile (char *pFileName)
 
int Cnf_DataSolveFromFile (char *pFileName, int nConfLimit, int fVerbose)
 

Function Documentation

Vec_Ptr_t* Aig_ManScanMapping ( Cnf_Man_t p,
int  fCollect 
)

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

Synopsis [Computes area, references, and nodes used in the mapping.]

Description [Collects the nodes in reverse topological order.]

SideEffects []

SeeAlso []

Definition at line 90 of file cnfUtil.c.

91 {
92  Vec_Ptr_t * vMapped = NULL;
93  Aig_Obj_t * pObj;
94  int i;
95  // clean all references
96  Aig_ManForEachObj( p->pManAig, pObj, i )
97  pObj->nRefs = 0;
98  // allocate the array
99  if ( fCollect )
100  vMapped = Vec_PtrAlloc( 1000 );
101  // collect nodes reachable from POs in the DFS order through the best cuts
102  p->aArea = 0;
103  Aig_ManForEachCo( p->pManAig, pObj, i )
104  p->aArea += Aig_ManScanMapping_rec( p, Aig_ObjFanin0(pObj), vMapped );
105 // printf( "Variables = %6d. Clauses = %8d.\n", vMapped? Vec_PtrSize(vMapped) + Aig_ManCiNum(p->pManAig) + 1 : 0, p->aArea + 2 );
106  return vMapped;
107 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
ABC_NAMESPACE_IMPL_START int Aig_ManScanMapping_rec(Cnf_Man_t *p, Aig_Obj_t *pObj, Vec_Ptr_t *vMapped)
DECLARATIONS ///.
Definition: cnfUtil.c:46
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
ABC_NAMESPACE_IMPL_START int Aig_ManScanMapping_rec ( Cnf_Man_t p,
Aig_Obj_t pObj,
Vec_Ptr_t vMapped 
)

DECLARATIONS ///.

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

FileName [cnfUtil.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:
cnfUtil.c,v 1.00 2007/04/28 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Computes area, references, and nodes used in the mapping.]

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file cnfUtil.c.

47 {
48  Aig_Obj_t * pLeaf;
49  Dar_Cut_t * pCutBest;
50  int aArea, i;
51  if ( pObj->nRefs++ || Aig_ObjIsCi(pObj) || Aig_ObjIsConst1(pObj) )
52  return 0;
53  assert( Aig_ObjIsAnd(pObj) );
54  // collect the node first to derive pre-order
55  if ( vMapped )
56  Vec_PtrPush( vMapped, pObj );
57  // visit the transitive fanin of the selected cut
58  if ( pObj->fMarkB )
59  {
60  Vec_Ptr_t * vSuper = Vec_PtrAlloc( 100 );
61  Aig_ObjCollectSuper( pObj, vSuper );
62  aArea = Vec_PtrSize(vSuper) + 1;
63  Vec_PtrForEachEntry( Aig_Obj_t *, vSuper, pLeaf, i )
64  aArea += Aig_ManScanMapping_rec( p, Aig_Regular(pLeaf), vMapped );
65  Vec_PtrFree( vSuper );
66  ////////////////////////////
67  pObj->fMarkB = 1;
68  }
69  else
70  {
71  pCutBest = Dar_ObjBestCut( pObj );
72  aArea = Cnf_CutSopCost( p, pCutBest );
73  Dar_CutForEachLeaf( p->pManAig, pCutBest, pLeaf, i )
74  aArea += Aig_ManScanMapping_rec( p, pLeaf, vMapped );
75  }
76  return aArea;
77 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
int Aig_ObjCollectSuper(Aig_Obj_t *pObj, Vec_Ptr_t *vSuper)
Definition: aigDfs.c:1097
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Cnf_CutSopCost(Cnf_Man_t *p, Dar_Cut_t *pCut)
Definition: cnf.h:99
unsigned int fMarkB
Definition: aig.h:80
ABC_NAMESPACE_IMPL_START int Aig_ManScanMapping_rec(Cnf_Man_t *p, Aig_Obj_t *pObj, Vec_Ptr_t *vMapped)
DECLARATIONS ///.
Definition: cnfUtil.c:46
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static int Aig_ObjIsConst1(Aig_Obj_t *pObj)
Definition: aig.h:274
else
Definition: sparse_int.h:55
Definition: aig.h:69
static Dar_Cut_t * Dar_ObjBestCut(Aig_Obj_t *pObj)
Definition: cnf.h:97
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define Dar_CutForEachLeaf(p, pCut, pLeaf, i)
Definition: darInt.h:124
#define assert(ex)
Definition: util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static int Aig_ObjIsCi(Aig_Obj_t *pObj)
Definition: aig.h:275
unsigned int nRefs
Definition: aig.h:81
static int Aig_ObjIsAnd(Aig_Obj_t *pObj)
Definition: aig.h:278
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
Vec_Int_t* Cnf_DataCollectCiSatNums ( Cnf_Dat_t pCnf,
Aig_Man_t p 
)

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

Synopsis [Returns the array of CI IDs.]

Description []

SideEffects []

SeeAlso []

Definition at line 200 of file cnfUtil.c.

201 {
202  Vec_Int_t * vCiIds;
203  Aig_Obj_t * pObj;
204  int i;
205  vCiIds = Vec_IntAlloc( Aig_ManCiNum(p) );
206  Aig_ManForEachCi( p, pObj, i )
207  Vec_IntPush( vCiIds, pCnf->pVarNums[pObj->Id] );
208  return vCiIds;
209 }
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
Vec_Int_t* Cnf_DataCollectCoSatNums ( Cnf_Dat_t pCnf,
Aig_Man_t p 
)

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

Synopsis [Returns the array of CI IDs.]

Description []

SideEffects []

SeeAlso []

Definition at line 222 of file cnfUtil.c.

223 {
224  Vec_Int_t * vCoIds;
225  Aig_Obj_t * pObj;
226  int i;
227  vCoIds = Vec_IntAlloc( Aig_ManCoNum(p) );
228  Aig_ManForEachCo( p, pObj, i )
229  Vec_IntPush( vCoIds, pCnf->pVarNums[pObj->Id] );
230  return vCoIds;
231 }
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_ManForEachCo(p, pObj, i)
Definition: aig.h:398
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
unsigned char* Cnf_DataDeriveLitPolarities ( Cnf_Dat_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 244 of file cnfUtil.c.

245 {
246  int i, c, iClaBeg, iClaEnd, * pLit;
247  unsigned * pPols0 = ABC_CALLOC( unsigned, Aig_ManObjNumMax(p->pMan) );
248  unsigned * pPols1 = ABC_CALLOC( unsigned, Aig_ManObjNumMax(p->pMan) );
249  unsigned char * pPres = ABC_CALLOC( unsigned char, p->nClauses );
250  for ( i = 0; i < Aig_ManObjNumMax(p->pMan); i++ )
251  {
252  if ( p->pObj2Count[i] == 0 )
253  continue;
254  iClaBeg = p->pObj2Clause[i];
255  iClaEnd = p->pObj2Clause[i] + p->pObj2Count[i];
256  // go through the negative polarity clauses
257  for ( c = iClaBeg; c < iClaEnd; c++ )
258  for ( pLit = p->pClauses[c]+1; pLit < p->pClauses[c+1]; pLit++ )
259  if ( Abc_LitIsCompl(p->pClauses[c][0]) )
260  pPols0[Abc_Lit2Var(*pLit)] |= (unsigned)(2 - Abc_LitIsCompl(*pLit)); // taking the opposite (!) -- not the case
261  else
262  pPols1[Abc_Lit2Var(*pLit)] |= (unsigned)(2 - Abc_LitIsCompl(*pLit)); // taking the opposite (!) -- not the case
263  // record these clauses
264  for ( c = iClaBeg; c < iClaEnd; c++ )
265  for ( pLit = p->pClauses[c]+1; pLit < p->pClauses[c+1]; pLit++ )
266  if ( Abc_LitIsCompl(p->pClauses[c][0]) )
267  pPres[c] = (unsigned char)( (unsigned)pPres[c] | (pPols0[Abc_Lit2Var(*pLit)] << (2*(pLit-p->pClauses[c]-1))) );
268  else
269  pPres[c] = (unsigned char)( (unsigned)pPres[c] | (pPols1[Abc_Lit2Var(*pLit)] << (2*(pLit-p->pClauses[c]-1))) );
270  // clean negative polarity
271  for ( c = iClaBeg; c < iClaEnd; c++ )
272  for ( pLit = p->pClauses[c]+1; pLit < p->pClauses[c+1]; pLit++ )
273  pPols0[Abc_Lit2Var(*pLit)] = pPols1[Abc_Lit2Var(*pLit)] = 0;
274  }
275  ABC_FREE( pPols0 );
276  ABC_FREE( pPols1 );
277 /*
278 // for ( c = 0; c < p->nClauses; c++ )
279  for ( c = 0; c < 100; c++ )
280  {
281  printf( "Clause %6d : ", c );
282  for ( i = 0; i < 4; i++ )
283  printf( "%d ", ((unsigned)pPres[c] >> (2*i)) & 3 );
284  printf( " " );
285  for ( pLit = p->pClauses[c]; pLit < p->pClauses[c+1]; pLit++ )
286  printf( "%6d ", *pLit );
287  printf( "\n" );
288  }
289 */
290  return pPres;
291 }
int nClauses
Definition: cnf.h:61
Aig_Man_t * pMan
Definition: cnf.h:58
int * pObj2Clause
Definition: cnf.h:64
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
int ** pClauses
Definition: cnf.h:62
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
int * pObj2Count
Definition: cnf.h:65
Cnf_Dat_t* Cnf_DataReadFromFile ( char *  pFileName)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 304 of file cnfUtil.c.

305 {
306  int MaxLine = 1000000;
307  int Var, Lit, nVars = -1, nClas = -1, i, Entry, iLine = 0;
308  Cnf_Dat_t * pCnf = NULL;
309  Vec_Int_t * vClas = NULL;
310  Vec_Int_t * vLits = NULL;
311  char * pBuffer, * pToken;
312  FILE * pFile = fopen( pFileName, "rb" );
313  if ( pFile == NULL )
314  {
315  printf( "Cannot open file \"%s\" for writing.\n", pFileName );
316  return NULL;
317  }
318  pBuffer = ABC_ALLOC( char, MaxLine );
319  while ( fgets(pBuffer, MaxLine, pFile) != NULL )
320  {
321  iLine++;
322  if ( pBuffer[0] == 'c' )
323  continue;
324  if ( pBuffer[0] == 'p' )
325  {
326  pToken = strtok( pBuffer+1, " \t" );
327  if ( strcmp(pToken, "cnf") )
328  {
329  printf( "Incorrect input file.\n" );
330  goto finish;
331  }
332  pToken = strtok( NULL, " \t" );
333  nVars = atoi( pToken );
334  pToken = strtok( NULL, " \t" );
335  nClas = atoi( pToken );
336  if ( nVars <= 0 || nClas <= 0 )
337  {
338  printf( "Incorrect parameters.\n" );
339  goto finish;
340  }
341  // temp storage
342  vClas = Vec_IntAlloc( nClas+1 );
343  vLits = Vec_IntAlloc( nClas*8 );
344  continue;
345  }
346  pToken = strtok( pBuffer, " \t\r\n" );
347  if ( pToken == NULL )
348  continue;
349  Vec_IntPush( vClas, Vec_IntSize(vLits) );
350  while ( pToken )
351  {
352  Var = atoi( pToken );
353  if ( Var == 0 )
354  break;
355  Lit = (Var > 0) ? Abc_Var2Lit(Var-1, 0) : Abc_Var2Lit(-Var-1, 1);
356  if ( Lit >= 2*nVars )
357  {
358  printf( "Literal %d is out-of-bound for %d variables.\n", Lit, nVars );
359  goto finish;
360  }
361  Vec_IntPush( vLits, Lit );
362  pToken = strtok( NULL, " \t\r\n" );
363  }
364  if ( Var != 0 )
365  {
366  printf( "There is no zero-terminator in line %d.\n", iLine );
367  goto finish;
368  }
369  }
370  // finalize
371  if ( Vec_IntSize(vClas) != nClas )
372  printf( "Warning! The number of clauses (%d) is different from declaration (%d).\n", Vec_IntSize(vClas), nClas );
373  Vec_IntPush( vClas, Vec_IntSize(vLits) );
374  // create
375  pCnf = ABC_CALLOC( Cnf_Dat_t, 1 );
376  pCnf->nVars = nVars;
377  pCnf->nClauses = nClas;
378  pCnf->nLiterals = Vec_IntSize(vLits);
379  pCnf->pClauses = ABC_ALLOC( int *, Vec_IntSize(vClas) );
380  pCnf->pClauses[0] = Vec_IntReleaseArray(vLits);
381  Vec_IntForEachEntry( vClas, Entry, i )
382  pCnf->pClauses[i] = pCnf->pClauses[0] + Entry;
383 finish:
384  fclose( pFile );
385  Vec_IntFreeP( &vClas );
386  Vec_IntFreeP( &vLits );
387  ABC_FREE( pBuffer );
388  return pCnf;
389 }
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
char * strtok()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Definition: cnf.h:56
int strcmp()
int ** pClauses
Definition: cnf.h:62
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static void Vec_IntFreeP(Vec_Int_t **p)
Definition: vecInt.h:289
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
int Var
Definition: SolverTypes.h:42
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
int nLiterals
Definition: cnf.h:60
static int * Vec_IntReleaseArray(Vec_Int_t *p)
Definition: extraZddTrunc.c:89
int Cnf_DataSolveFromFile ( char *  pFileName,
int  nConfLimit,
int  fVerbose 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 402 of file cnfUtil.c.

403 {
404  abctime clk = Abc_Clock();
405  Cnf_Dat_t * pCnf = Cnf_DataReadFromFile( pFileName );
406  sat_solver * pSat;
407  int status, RetValue = -1;
408  if ( pCnf == NULL )
409  return -1;
410  if ( fVerbose )
411  {
412  printf( "CNF stats: Vars = %6d. Clauses = %7d. Literals = %8d. ", pCnf->nVars, pCnf->nClauses, pCnf->nLiterals );
413  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
414  }
415  // convert into SAT solver
416  pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, 1, 0 );
417  Cnf_DataFree( pCnf );
418  if ( pSat == NULL )
419  {
420  printf( "The problem is trivially UNSAT.\n" );
421  return 1;
422  }
423  // solve the miter
424 // if ( fVerbose )
425 // pSat->verbosity = 1;
426  status = sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)nConfLimit, 0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
427  if ( status == l_Undef )
428  RetValue = -1;
429  else if ( status == l_True )
430  RetValue = 0;
431  else if ( status == l_False )
432  RetValue = 1;
433  else
434  assert( 0 );
435  if ( fVerbose )
436  Sat_SolverPrintStats( stdout, pSat );
437  sat_solver_delete( pSat );
438  if ( RetValue == -1 )
439  Abc_Print( 1, "UNDECIDED " );
440  else if ( RetValue == 0 )
441  Abc_Print( 1, "SATISFIABLE " );
442  else
443  Abc_Print( 1, "UNSATISFIABLE " );
444  //Abc_Print( -1, "\n" );
445  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
446  return RetValue;
447 }
#define l_Undef
Definition: SolverTypes.h:86
int nClauses
Definition: cnf.h:61
int sat_solver_solve(sat_solver *s, lit *begin, lit *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
Definition: satSolver.c:1700
int nVars
Definition: cnf.h:59
void sat_solver_delete(sat_solver *s)
Definition: satSolver.c:1141
#define l_True
Definition: SolverTypes.h:84
static abctime Abc_Clock()
Definition: abc_global.h:279
Definition: cnf.h:56
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
Definition: cnfMan.c:463
#define l_False
Definition: SolverTypes.h:85
void Cnf_DataFree(Cnf_Dat_t *p)
Definition: cnfMan.c:180
#define assert(ex)
Definition: util_old.h:213
void Sat_SolverPrintStats(FILE *pFile, sat_solver *p)
Definition: satUtil.c:188
ABC_INT64_T abctime
Definition: abc_global.h:278
int nLiterals
Definition: cnf.h:60
Cnf_Dat_t * Cnf_DataReadFromFile(char *pFileName)
Definition: cnfUtil.c:304
Vec_Ptr_t* Cnf_ManScanMapping ( Cnf_Man_t p,
int  fCollect,
int  fPreorder 
)

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

Synopsis [Computes area, references, and nodes used in the mapping.]

Description [Collects the nodes in reverse topological order.]

SideEffects []

SeeAlso []

Definition at line 170 of file cnfUtil.c.

171 {
172  Vec_Ptr_t * vMapped = NULL;
173  Aig_Obj_t * pObj;
174  int i;
175  // clean all references
176  Aig_ManForEachObj( p->pManAig, pObj, i )
177  pObj->nRefs = 0;
178  // allocate the array
179  if ( fCollect )
180  vMapped = Vec_PtrAlloc( 1000 );
181  // collect nodes reachable from POs in the DFS order through the best cuts
182  p->aArea = 0;
183  Aig_ManForEachCo( p->pManAig, pObj, i )
184  p->aArea += Cnf_ManScanMapping_rec( p, Aig_ObjFanin0(pObj), vMapped, fPreorder );
185 // printf( "Variables = %6d. Clauses = %8d.\n", vMapped? Vec_PtrSize(vMapped) + Aig_ManCiNum(p->pManAig) + 1 : 0, p->aArea + 2 );
186  return vMapped;
187 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
int Cnf_ManScanMapping_rec(Cnf_Man_t *p, Aig_Obj_t *pObj, Vec_Ptr_t *vMapped, int fPreorder)
Definition: cnfUtil.c:120
int Cnf_ManScanMapping_rec ( Cnf_Man_t p,
Aig_Obj_t pObj,
Vec_Ptr_t vMapped,
int  fPreorder 
)

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

Synopsis [Computes area, references, and nodes used in the mapping.]

Description []

SideEffects []

SeeAlso []

Definition at line 120 of file cnfUtil.c.

121 {
122  Aig_Obj_t * pLeaf;
123  Cnf_Cut_t * pCutBest;
124  int aArea, i;
125  if ( pObj->nRefs++ || Aig_ObjIsCi(pObj) || Aig_ObjIsConst1(pObj) )
126  return 0;
127  assert( Aig_ObjIsAnd(pObj) );
128  assert( pObj->pData != NULL );
129  // add the node to the mapping
130  if ( vMapped && fPreorder )
131  Vec_PtrPush( vMapped, pObj );
132  // visit the transitive fanin of the selected cut
133  if ( pObj->fMarkB )
134  {
135  Vec_Ptr_t * vSuper = Vec_PtrAlloc( 100 );
136  Aig_ObjCollectSuper( pObj, vSuper );
137  aArea = Vec_PtrSize(vSuper) + 1;
138  Vec_PtrForEachEntry( Aig_Obj_t *, vSuper, pLeaf, i )
139  aArea += Cnf_ManScanMapping_rec( p, Aig_Regular(pLeaf), vMapped, fPreorder );
140  Vec_PtrFree( vSuper );
141  ////////////////////////////
142  pObj->fMarkB = 1;
143  }
144  else
145  {
146  pCutBest = (Cnf_Cut_t *)pObj->pData;
147 // assert( pCutBest->nFanins > 0 );
148  assert( pCutBest->Cost < 127 );
149  aArea = pCutBest->Cost;
150  Cnf_CutForEachLeaf( p->pManAig, pCutBest, pLeaf, i )
151  aArea += Cnf_ManScanMapping_rec( p, pLeaf, vMapped, fPreorder );
152  }
153  // add the node to the mapping
154  if ( vMapped && !fPreorder )
155  Vec_PtrPush( vMapped, pObj );
156  return aArea;
157 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
int Aig_ObjCollectSuper(Aig_Obj_t *pObj, Vec_Ptr_t *vSuper)
Definition: aigDfs.c:1097
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned int fMarkB
Definition: aig.h:80
void * pData
Definition: aig.h:87
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
char Cost
Definition: cnf.h:74
Definition: cnf.h:71
#define Cnf_CutForEachLeaf(p, pCut, pLeaf, i)
Definition: cnf.h:121
if(last==0)
Definition: sparse_int.h:34
static int Aig_ObjIsConst1(Aig_Obj_t *pObj)
Definition: aig.h:274
else
Definition: sparse_int.h:55
Definition: aig.h:69
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
int Cnf_ManScanMapping_rec(Cnf_Man_t *p, Aig_Obj_t *pObj, Vec_Ptr_t *vMapped, int fPreorder)
Definition: cnfUtil.c:120
#define assert(ex)
Definition: util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static int Aig_ObjIsCi(Aig_Obj_t *pObj)
Definition: aig.h:275
unsigned int nRefs
Definition: aig.h:81
static int Aig_ObjIsAnd(Aig_Obj_t *pObj)
Definition: aig.h:278
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223