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

Go to the source code of this file.

Data Structures

struct  Ccf_Man_t_
 

Typedefs

typedef
typedefABC_NAMESPACE_IMPL_START
struct Ccf_Man_t_ 
Ccf_Man_t
 DECLARATIONS ///. More...
 

Functions

Ccf_Man_tCcf_ManStart (Gia_Man_t *pGia, int nFrameMax, int nConfMax, int nTimeMax, int fVerbose)
 FUNCTION DEFINITIONS ///. More...
 
void Ccf_ManStop (Ccf_Man_t *p)
 
void Gia_ManCofExtendSolver (Ccf_Man_t *p)
 
static int Gia_Obj0Copy (Vec_Int_t *vCopies, int Fan0, int fCompl0)
 
static int Gia_Obj1Copy (Vec_Int_t *vCopies, int Fan1, int fCompl1)
 
void Gia_ManCofOneDerive_rec (Ccf_Man_t *p, int Id)
 
int Gia_ManCofOneDerive (Ccf_Man_t *p, int LitProp)
 
int Gia_ManCofGetReachable (Ccf_Man_t *p, int Lit)
 
Gia_Man_tGia_ManCofTest (Gia_Man_t *pGia, int nFrameMax, int nConfMax, int nTimeMax, int fVerbose)
 

Typedef Documentation

typedef typedefABC_NAMESPACE_IMPL_START struct Ccf_Man_t_ Ccf_Man_t

DECLARATIONS ///.

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

FileName [giaCCof.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Scalable AIG package.]

Synopsis [Backward reachability using circuit cofactoring.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

]

Definition at line 31 of file giaCCof.c.

Function Documentation

Ccf_Man_t* Ccf_ManStart ( Gia_Man_t pGia,
int  nFrameMax,
int  nConfMax,
int  nTimeMax,
int  fVerbose 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Create manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 62 of file giaCCof.c.

63 {
64  static Gia_ParFra_t Pars, * pPars = &Pars;
65  Ccf_Man_t * p;
66  assert( nFrameMax > 0 );
67  p = ABC_CALLOC( Ccf_Man_t, 1 );
68  p->pGia = pGia;
69  p->nFrameMax = nFrameMax;
70  p->nConfMax = nConfMax;
71  p->nTimeMax = nTimeMax;
72  p->fVerbose = fVerbose;
73  // create unrolling manager
74  memset( pPars, 0, sizeof(Gia_ParFra_t) );
75  pPars->fVerbose = fVerbose;
76  pPars->nFrames = nFrameMax;
77  pPars->fSaveLastLit = 1;
78  p->pUnr = Gia_ManUnrollStart( pGia, pPars );
79  p->vCopies = Vec_IntAlloc( 1000 );
80  // internal data
81  p->pSat = sat_solver_new();
82 // sat_solver_setnvars( p->pSat, 10000 );
83  return p;
84 }
char * memset()
int nFrames
Definition: gia.h:227
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int fSaveLastLit
Definition: gia.h:229
typedefABC_NAMESPACE_IMPL_START struct Ccf_Man_t_ Ccf_Man_t
DECLARATIONS ///.
Definition: giaCCof.c:31
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
int fVerbose
Definition: gia.h:232
sat_solver * sat_solver_new(void)
Definition: satSolver.c:1001
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
int fVerbose
Definition: gia.h:174
#define assert(ex)
Definition: util_old.h:213
void * Gia_ManUnrollStart(Gia_Man_t *pAig, Gia_ParFra_t *pPars)
Definition: giaFrames.c:402
void Ccf_ManStop ( Ccf_Man_t p)

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

Synopsis [Delete manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 97 of file giaCCof.c.

98 {
99  Vec_IntFree( p->vCopies );
100  Gia_ManUnrollStop( p->pUnr );
101  sat_solver_delete( p->pSat );
102  Gia_ManStopP( &p->pFrames );
103  ABC_FREE( p );
104 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void sat_solver_delete(sat_solver *s)
Definition: satSolver.c:1141
void Gia_ManStopP(Gia_Man_t **p)
Definition: giaMan.c:177
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Gia_ManUnrollStop(void *pMan)
Definition: giaFrames.c:310
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
void Gia_ManCofExtendSolver ( Ccf_Man_t p)

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

Synopsis [Extends the solver.]

Description []

SideEffects []

SeeAlso []

Definition at line 118 of file giaCCof.c.

119 {
120  Gia_Obj_t * pObj;
121  int i;
122  // add SAT clauses
123  for ( i = sat_solver_nvars(p->pSat); i < Gia_ManObjNum(p->pFrames); i++ )
124  {
125  pObj = Gia_ManObj( p->pFrames, i );
126  if ( Gia_ObjIsAnd(pObj) )
127  sat_solver_add_and( p->pSat, i,
128  Gia_ObjFaninId0(pObj, i),
129  Gia_ObjFaninId1(pObj, i),
130  Gia_ObjFaninC0(pObj),
131  Gia_ObjFaninC1(pObj), 0 );
132  }
133  sat_solver_setnvars( p->pSat, Gia_ManObjNum(p->pFrames) );
134 }
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static Gia_Obj_t * Gia_ManObj(Gia_Man_t *p, int v)
Definition: gia.h:402
Definition: gia.h:75
void sat_solver_setnvars(sat_solver *s, int n)
Definition: satSolver.c:1072
int sat_solver_nvars(sat_solver *s)
Definition: satSolver.c:1896
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
static int Gia_ObjFaninId1(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:461
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
static int Gia_ObjFaninId0(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:460
static int sat_solver_add_and(sat_solver *pSat, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1, int fCompl)
Definition: satSolver.h:324
int Gia_ManCofGetReachable ( Ccf_Man_t p,
int  Lit 
)

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

Synopsis [Enumerates backward reachable states.]

Description [Return -1 if resource limit is reached. Returns 1 if computation converged (there is no more reachable states). Returns 0 if no more states to enumerate.]

SideEffects []

SeeAlso []

Definition at line 220 of file giaCCof.c.

221 {
222  int ObjPrev = 0, ConfPrev = 0;
223  int Count = 0, LitOut, RetValue;
224  abctime clk;
225  // try solving for the first time and quit if converged
226  RetValue = sat_solver_solve( p->pSat, &Lit, &Lit + 1, p->nConfMax, 0, 0, 0 );
227  if ( RetValue == l_False )
228  return 1;
229  // iterate circuit cofactoring
230  while ( RetValue == l_True )
231  {
232  clk = Abc_Clock();
233  // derive cofactor
234  LitOut = Gia_ManCofOneDerive( p, Lit );
235  // add the blocking clause
236  RetValue = sat_solver_addclause( p->pSat, &LitOut, &LitOut + 1 );
237  assert( RetValue );
238  // try solving again
239  RetValue = sat_solver_solve( p->pSat, &Lit, &Lit + 1, p->nConfMax, 0, 0, 0 );
240  // derive cofactors
241  if ( p->fVerbose )
242  {
243  printf( "%3d : AIG =%7d Conf =%7d. ", Count++,
244  Gia_ManObjNum(p->pFrames) - ObjPrev, sat_solver_nconflicts(p->pSat) - ConfPrev );
245  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
246  ObjPrev = Gia_ManObjNum(p->pFrames);
247  ConfPrev = sat_solver_nconflicts(p->pSat);
248  }
249  }
250  if ( RetValue == l_Undef )
251  return -1;
252  return 0;
253 }
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 l_Undef
Definition: SolverTypes.h:86
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 sat_solver_nconflicts(sat_solver *s)
Definition: satSolver.c:1908
#define l_True
Definition: SolverTypes.h:84
static abctime Abc_Clock()
Definition: abc_global.h:279
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
#define l_False
Definition: SolverTypes.h:85
#define assert(ex)
Definition: util_old.h:213
ABC_INT64_T abctime
Definition: abc_global.h:278
int Gia_ManCofOneDerive(Ccf_Man_t *p, int LitProp)
Definition: giaCCof.c:191
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
int Gia_ManCofOneDerive ( Ccf_Man_t p,
int  LitProp 
)

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

Synopsis [Cofactor the circuit w.r.t. the given assignment.]

Description [Assumes that the solver has just returned SAT.]

SideEffects []

SeeAlso []

Definition at line 191 of file giaCCof.c.

192 {
193  int LitOut;
194  // derive the cofactor of the property node
195  Vec_IntFill( p->vCopies, Gia_ManObjNum(p->pFrames), -1 );
197  LitOut = Vec_IntEntry( p->vCopies, Abc_Lit2Var(LitProp) );
198  LitOut = Abc_LitNotCond( LitOut, Abc_LitIsCompl(LitProp) );
199  // add new PO for the cofactor
200  Gia_ManAppendCo( p->pFrames, LitOut );
201  // add SAT clauses
203  // return negative literal of the cofactor
204  return Abc_LitNot(LitOut);
205 }
static int Gia_ManAppendCo(Gia_Man_t *p, int iLit0)
Definition: gia.h:703
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:356
static int Abc_LitNot(int Lit)
Definition: abc_global.h:266
void Gia_ManCofOneDerive_rec(Ccf_Man_t *p, int Id)
Definition: giaCCof.c:153
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
void Gia_ManCofExtendSolver(Ccf_Man_t *p)
Definition: giaCCof.c:118
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
void Gia_ManCofOneDerive_rec ( Ccf_Man_t p,
int  Id 
)

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

Synopsis [Cofactor the circuit w.r.t. the given assignment.]

Description [Assumes that the solver has just returned SAT.]

SideEffects []

SeeAlso []

Definition at line 153 of file giaCCof.c.

154 {
155  Gia_Obj_t * pObj;
156  int Res;
157  if ( Vec_IntEntry(p->vCopies, Id) != -1 )
158  return;
159  pObj = Gia_ManObj(p->pFrames, Id);
160  assert( Gia_ObjIsCi(pObj) || Gia_ObjIsAnd(pObj) );
161  if ( Gia_ObjIsAnd(pObj) )
162  {
163  int fCompl0 = Gia_ObjFaninC0(pObj);
164  int fCompl1 = Gia_ObjFaninC1(pObj);
165  int Fan0 = Gia_ObjFaninId0p(p->pFrames, pObj);
166  int Fan1 = Gia_ObjFaninId1p(p->pFrames, pObj);
167  Gia_ManCofOneDerive_rec( p, Fan0 );
168  Gia_ManCofOneDerive_rec( p, Fan1 );
169  Res = Gia_ManHashAnd( p->pFrames,
170  Gia_Obj0Copy(p->vCopies, Fan0, fCompl0),
171  Gia_Obj1Copy(p->vCopies, Fan1, fCompl1) );
172  }
173  else if ( Gia_ObjCioId(pObj) >= Gia_ManRegNum(p->pGia) ) // PI
174  Res = sat_solver_var_value( p->pSat, Id );
175  else
176  Res = Abc_Var2Lit( Id, 0 );
177  Vec_IntWriteEntry( p->vCopies, Id, Res );
178 }
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
static int Gia_ObjFaninId1p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:464
static int Gia_Obj1Copy(Vec_Int_t *vCopies, int Fan1, int fCompl1)
Definition: giaCCof.c:139
static Gia_Obj_t * Gia_ManObj(Gia_Man_t *p, int v)
Definition: gia.h:402
Definition: gia.h:75
static int sat_solver_var_value(sat_solver *s, int v)
Definition: satSolver.h:200
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
void Gia_ManCofOneDerive_rec(Ccf_Man_t *p, int Id)
Definition: giaCCof.c:153
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
static int Gia_ObjFaninId0p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:463
#define assert(ex)
Definition: util_old.h:213
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
static int Gia_ObjIsCi(Gia_Obj_t *pObj)
Definition: gia.h:420
static int Gia_Obj0Copy(Vec_Int_t *vCopies, int Fan0, int fCompl0)
Definition: giaCCof.c:136
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:572
static int Gia_ObjCioId(Gia_Obj_t *pObj)
Definition: gia.h:411
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387
Gia_Man_t* Gia_ManCofTest ( Gia_Man_t pGia,
int  nFrameMax,
int  nConfMax,
int  nTimeMax,
int  fVerbose 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 266 of file giaCCof.c.

267 {
268  Gia_Man_t * pNew;
269  Ccf_Man_t * p;
270  Gia_Obj_t * pObj;
271  int f, i, Lit, RetValue = -1, fFailed = 0;
272  abctime nTimeToStop = Abc_Clock() + nTimeMax * CLOCKS_PER_SEC;
273  abctime clk = Abc_Clock();
274  assert( Gia_ManPoNum(pGia) == 1 );
275 
276  // create reachability manager
277  p = Ccf_ManStart( pGia, nFrameMax, nConfMax, nTimeMax, fVerbose );
278 
279  // set runtime limit
280  if ( nTimeMax )
281  sat_solver_set_runtime_limit( p->pSat, nTimeToStop );
282 
283  // perform backward image computation
284  for ( f = 0; f < nFrameMax; f++ )
285  {
286  if ( fVerbose )
287  printf( "ITER %3d :\n", f );
288  // add to the mapping of nodes
289  p->pFrames = (Gia_Man_t *)Gia_ManUnrollAdd( p->pUnr, f+1 );
290  // add SAT clauses
292  // return output literal
293  Lit = Gia_ManUnrollLastLit( p->pUnr );
294  // derives cofactors of the property literal till all states are blocked
295  RetValue = Gia_ManCofGetReachable( p, Lit );
296  if ( RetValue )
297  break;
298 
299  // check the property output
300  Gia_ManSetPhase( p->pFrames );
301  Gia_ManForEachPo( p->pFrames, pObj, i )
302  if ( pObj->fPhase )
303  {
304  printf( "Property failed in frame %d.\n", f );
305  fFailed = 1;
306  break;
307  }
308  if ( i < Gia_ManPoNum(p->pFrames) )
309  break;
310  }
311 
312  // report the result
313  if ( nTimeToStop && Abc_Clock() > nTimeToStop )
314  printf( "Runtime limit (%d sec) is reached after %d frames. ", nTimeMax, f );
315  else if ( f == nFrameMax )
316  printf( "Completed %d frames without converging. ", f );
317  else if ( RetValue == 1 )
318  printf( "Backward reachability converged after %d iterations. ", f-1 );
319  else if ( RetValue == -1 )
320  printf( "Conflict limit or timeout is reached after %d frames. ", f-1 );
321  Abc_PrintTime( 1, "Runtime", Abc_Clock() - clk );
322 
323  if ( !fFailed && RetValue == 1 )
324  printf( "Property holds.\n" );
325  else if ( !fFailed )
326  printf( "Property is undecided.\n" );
327 
328  // get the resulting AIG manager
329  Gia_ManHashStop( p->pFrames );
330  pNew = p->pFrames; p->pFrames = NULL;
331  Ccf_ManStop( p );
332 
333  // cleanup
334 // if ( fVerbose )
335 // Gia_ManPrintStats( pNew, 0 );
336  pNew = Gia_ManCleanup( pGia = pNew );
337  Gia_ManStop( pGia );
338 // if ( fVerbose )
339 // Gia_ManPrintStats( pNew, 0 );
340  return pNew;
341 }
static abctime sat_solver_set_runtime_limit(sat_solver *s, abctime Limit)
Definition: satSolver.h:233
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void * Gia_ManUnrollAdd(void *pMan, int fMax)
Definition: giaFrames.c:437
void Ccf_ManStop(Ccf_Man_t *p)
Definition: giaCCof.c:97
static abctime Abc_Clock()
Definition: abc_global.h:279
Definition: gia.h:75
typedefABC_NAMESPACE_IMPL_START struct Ccf_Man_t_ Ccf_Man_t
DECLARATIONS ///.
Definition: giaCCof.c:31
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
if(last==0)
Definition: sparse_int.h:34
Ccf_Man_t * Ccf_ManStart(Gia_Man_t *pGia, int nFrameMax, int nConfMax, int nTimeMax, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: giaCCof.c:62
Definition: gia.h:95
int Gia_ManUnrollLastLit(void *pMan)
Definition: giaFrames.c:490
#define assert(ex)
Definition: util_old.h:213
void Gia_ManSetPhase(Gia_Man_t *p)
Definition: giaUtil.c:379
int Gia_ManCofGetReachable(Ccf_Man_t *p, int Lit)
Definition: giaCCof.c:220
ABC_INT64_T abctime
Definition: abc_global.h:278
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition: giaScl.c:84
#define Gia_ManForEachPo(p, pObj, i)
Definition: gia.h:1036
void Gia_ManCofExtendSolver(Ccf_Man_t *p)
Definition: giaCCof.c:118
void Gia_ManHashStop(Gia_Man_t *p)
Definition: giaHash.c:142
static int Gia_Obj0Copy ( Vec_Int_t vCopies,
int  Fan0,
int  fCompl0 
)
inlinestatic

Definition at line 136 of file giaCCof.c.

137 { return Abc_LitNotCond( Vec_IntEntry(vCopies, Fan0), fCompl0 ); }
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static int Gia_Obj1Copy ( Vec_Int_t vCopies,
int  Fan1,
int  fCompl1 
)
inlinestatic

Definition at line 139 of file giaCCof.c.

140 { return Abc_LitNotCond( Vec_IntEntry(vCopies, Fan1), fCompl1 ); }
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268