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

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START
Vec_Ptr_t
Saig_ManFindPrimes (Aig_Man_t *pAig, int nLits, int fVerbose)
 DECLARATIONS ///. More...
 
Aig_Man_tSaig_ManDecPropertyOutput (Aig_Man_t *pAig, int nLits, int fVerbose)
 

Function Documentation

Aig_Man_t* Saig_ManDecPropertyOutput ( Aig_Man_t pAig,
int  nLits,
int  fVerbose 
)

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

Synopsis [Performs decomposition of the property output.]

Description []

SideEffects []

SeeAlso []

Definition at line 150 of file saigOutDec.c.

151 {
152  Aig_Man_t * pAigNew = NULL;
153  Aig_Obj_t * pObj, * pMiter;
154  Vec_Ptr_t * vPrimes;
155  Vec_Int_t * vCube;
156  int i, k, Lit;
157 
158  // compute primes of the comb output function
159  vPrimes = Saig_ManFindPrimes( pAig, nLits, fVerbose );
160 
161  // start the new manager
162  pAigNew = Aig_ManStart( Aig_ManNodeNum(pAig) );
163  pAigNew->pName = Abc_UtilStrsav( pAig->pName );
164  pAigNew->nConstrs = pAig->nConstrs;
165  // map the constant node
166  Aig_ManConst1(pAig)->pData = Aig_ManConst1( pAigNew );
167  // create variables for PIs
168  Aig_ManForEachCi( pAig, pObj, i )
169  pObj->pData = Aig_ObjCreateCi( pAigNew );
170  // add internal nodes of this frame
171  Aig_ManForEachNode( pAig, pObj, i )
172  pObj->pData = Aig_And( pAigNew, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) );
173  // create original POs of the circuit
174  Saig_ManForEachPo( pAig, pObj, i )
175  Aig_ObjCreateCo( pAigNew, Aig_ObjChild0Copy(pObj) );
176  // create prime POs of the circuit
177  if ( vPrimes )
178  Vec_PtrForEachEntry( Vec_Int_t *, vPrimes, vCube, k )
179  {
180  pMiter = Aig_ManConst1( pAigNew );
181  Vec_IntForEachEntry( vCube, Lit, i )
182  {
183  pObj = Aig_NotCond( Aig_ObjCopy(Aig_ManObj(pAig, Abc_Lit2Var(Lit))), Abc_LitIsCompl(Lit) );
184  pMiter = Aig_And( pAigNew, pMiter, pObj );
185  }
186  Aig_ObjCreateCo( pAigNew, pMiter );
187  }
188  // transfer to register outputs
189  Saig_ManForEachLi( pAig, pObj, i )
190  Aig_ObjCreateCo( pAigNew, Aig_ObjChild0Copy(pObj) );
191  Aig_ManCleanup( pAigNew );
192  Aig_ManSetRegNum( pAigNew, Aig_ManRegNum(pAig) );
193 
194  Vec_VecFreeP( (Vec_Vec_t **)&vPrimes );
195  return pAigNew;
196 }
Aig_Obj_t * Aig_ObjCreateCo(Aig_Man_t *p, Aig_Obj_t *pDriver)
Definition: aigObj.c:66
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition: vecVec.h:42
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
void * pData
Definition: aig.h:87
Aig_Man_t * Aig_ManStart(int nNodesMax)
DECLARATIONS ///.
Definition: aigMan.c:47
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
Aig_Obj_t * Aig_ObjCreateCi(Aig_Man_t *p)
DECLARATIONS ///.
Definition: aigObj.c:45
static Aig_Obj_t * Aig_ManObj(Aig_Man_t *p, int i)
Definition: aig.h:270
static int Aig_ManNodeNum(Aig_Man_t *p)
Definition: aig.h:256
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition: aigOper.c:104
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
void Aig_ManSetRegNum(Aig_Man_t *p, int nRegs)
Definition: aigMan.c:438
#define Saig_ManForEachLi(p, pObj, i)
Definition: saig.h:98
if(last==0)
Definition: sparse_int.h:34
static Aig_Obj_t * Aig_ObjChild1Copy(Aig_Obj_t *pObj)
Definition: aig.h:313
Definition: aig.h:69
static Aig_Obj_t * Aig_ObjChild0Copy(Aig_Obj_t *pObj)
Definition: aig.h:312
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
static Aig_Obj_t * Aig_ObjCopy(Aig_Obj_t *pObj)
Definition: aig.h:318
static int Aig_ManRegNum(Aig_Man_t *p)
Definition: aig.h:260
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
ABC_NAMESPACE_IMPL_START Vec_Ptr_t * Saig_ManFindPrimes(Aig_Man_t *pAig, int nLits, int fVerbose)
DECLARATIONS ///.
Definition: saigOutDec.c:47
static void Vec_VecFreeP(Vec_Vec_t **p)
Definition: vecVec.h:367
#define Saig_ManForEachPo(p, pObj, i)
Definition: saig.h:93
static Aig_Obj_t * Aig_NotCond(Aig_Obj_t *p, int c)
Definition: aig.h:248
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
int Aig_ManCleanup(Aig_Man_t *p)
Definition: aigMan.c:265
ABC_NAMESPACE_IMPL_START Vec_Ptr_t* Saig_ManFindPrimes ( Aig_Man_t pAig,
int  nLits,
int  fVerbose 
)

DECLARATIONS ///.

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

FileName [saigOutDec.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Sequential AIG package.]

Synopsis [Output cone decomposition.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
saigOutDec.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

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

Synopsis [Performs decomposition of the property output.]

Description []

SideEffects []

SeeAlso []

Definition at line 47 of file saigOutDec.c.

48 {
49  Cnf_Dat_t * pCnf;
50  sat_solver * pSat;
51  Aig_Obj_t * pObj0, * pObj1, * pRoot, * pMiter;
52  Vec_Ptr_t * vPrimes, * vNodes;
53  Vec_Int_t * vCube, * vMarks;
54  int i0, i1, m, RetValue, Lits[10];
55  int fCompl0, fCompl1, nNodes1, nNodes2;
56  assert( nLits == 1 || nLits == 2 );
57  assert( nLits < 10 );
58 
59  // create SAT solver
60  pCnf = Cnf_DeriveSimple( pAig, Aig_ManCoNum(pAig) );
61  pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, 1, 0 );
62 
63  // collect nodes in the property output cone
64  pMiter = Aig_ManCo( pAig, 0 );
65  pRoot = Aig_ObjFanin0( pMiter );
66  vNodes = Aig_ManDfsNodes( pAig, &pRoot, 1 );
67  // sort nodes by level and remove the last few
68 
69  // try single nodes
70  vPrimes = Vec_PtrAlloc( 100 );
71  // create assumptions
72  vMarks = Vec_IntStart( Vec_PtrSize(vNodes) );
73  Lits[0] = toLitCond( pCnf->pVarNums[Aig_ObjId(pMiter)], 1 );
74  Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pObj0, i0 )
75  if ( pObj0 != pRoot )
76  {
77  // create assumptions
78  Lits[1] = toLitCond( pCnf->pVarNums[Aig_ObjId(pObj0)], pObj0->fPhase );
79  // solve the problem
80  RetValue = sat_solver_solve( pSat, Lits, Lits+2, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
81  if ( RetValue == l_False )
82  {
83  vCube = Vec_IntAlloc( 1 );
84  Vec_IntPush( vCube, toLitCond(Aig_ObjId(pObj0), pObj0->fPhase) );
85  Vec_PtrPush( vPrimes, vCube );
86  if ( fVerbose )
87  printf( "Adding prime %d%c\n", Aig_ObjId(pObj0), pObj0->fPhase?'-':'+' );
88  Vec_IntWriteEntry( vMarks, i0, 1 );
89  }
90  }
91  nNodes1 = Vec_PtrSize(vPrimes);
92  if ( nLits > 1 )
93  {
94  // try adding second literal
95  Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pObj0, i0 )
96  if ( pObj0 != pRoot )
97  Vec_PtrForEachEntryStart( Aig_Obj_t *, vNodes, pObj1, i1, i0+1 )
98  if ( pObj1 != pRoot )
99  {
100  if ( Vec_IntEntry(vMarks,i0) || Vec_IntEntry(vMarks,i1) )
101  continue;
102  for ( m = 0; m < 3; m++ )
103  {
104  fCompl0 = m & 1;
105  fCompl1 = (m >> 1) & 1;
106  // create assumptions
107  Lits[1] = toLitCond( pCnf->pVarNums[Aig_ObjId(pObj0)], fCompl0 ^ pObj0->fPhase );
108  Lits[2] = toLitCond( pCnf->pVarNums[Aig_ObjId(pObj1)], fCompl1 ^ pObj1->fPhase );
109  // solve the problem
110  RetValue = sat_solver_solve( pSat, Lits, Lits+3, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
111  if ( RetValue == l_False )
112  {
113  vCube = Vec_IntAlloc( 2 );
114  Vec_IntPush( vCube, toLitCond(Aig_ObjId(pObj0), fCompl0 ^ pObj0->fPhase) );
115  Vec_IntPush( vCube, toLitCond(Aig_ObjId(pObj1), fCompl1 ^ pObj1->fPhase) );
116  Vec_PtrPush( vPrimes, vCube );
117  if ( fVerbose )
118  printf( "Adding prime %d%c %d%c\n",
119  Aig_ObjId(pObj0), (fCompl0 ^ pObj0->fPhase)?'-':'+',
120  Aig_ObjId(pObj1), (fCompl1 ^ pObj1->fPhase)?'-':'+' );
121  break;
122  }
123  }
124  }
125  }
126  nNodes2 = Vec_PtrSize(vPrimes) - nNodes1;
127 
128  printf( "Property cone size = %6d 1-lit primes = %5d 2-lit primes = %5d\n",
129  Vec_PtrSize(vNodes), nNodes1, nNodes2 );
130 
131  // clean up
132  sat_solver_delete( pSat );
133  Cnf_DataFree( pCnf );
134  Vec_PtrFree( vNodes );
135  Vec_IntFree( vMarks );
136  return vPrimes;
137 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition: vecPtr.h:57
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
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
void sat_solver_delete(sat_solver *s)
Definition: satSolver.c:1141
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
int * pVarNums
Definition: cnf.h:63
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
Definition: cnf.h:56
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Vec_Ptr_t * Aig_ManDfsNodes(Aig_Man_t *p, Aig_Obj_t **ppNodes, int nNodes)
Definition: aigDfs.c:333
static lit toLitCond(int v, int c)
Definition: satVec.h:143
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static Aig_Obj_t * Aig_ManCo(Aig_Man_t *p, int i)
Definition: aig.h:267
unsigned int fPhase
Definition: aig.h:78
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
Definition: cnfMan.c:463
Cnf_Dat_t * Cnf_DeriveSimple(Aig_Man_t *p, int nOutputs)
Definition: cnfWrite.c:587
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define l_False
Definition: SolverTypes.h:85
void Cnf_DataFree(Cnf_Dat_t *p)
Definition: cnfMan.c:180
static int Aig_ObjId(Aig_Obj_t *pObj)
Definition: aig.h:286
#define assert(ex)
Definition: util_old.h:213
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223