abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bbrCex.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [bbrCex.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [BDD-based reachability analysis.]
8 
9  Synopsis [Procedures to derive a satisfiable counter-example.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: bbrCex.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "bbr.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 extern DdNode * Bbr_bddComputeRangeCube( DdManager * dd, int iStart, int iStop );
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 /**Function*************************************************************
37 
38  Synopsis [Derives the counter-example using the set of reached states.]
39 
40  Description []
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
48  DdNode ** pbParts, Vec_Ptr_t * vOnionRings, DdNode * bCubeFirst,
49  int iOutput, int fVerbose, int fSilent )
50 {
51  Abc_Cex_t * pCex;
52  Aig_Obj_t * pObj;
53  Bbr_ImageTree_t * pTree;
54  DdNode * bCubeNs, * bState, * bImage;
55  DdNode * bTemp, * bVar, * bRing;
56  int i, v, RetValue, nPiOffset;
57  char * pValues;
58  abctime clk = Abc_Clock();
59 //printf( "\nDeriving counter-example.\n" );
60 
61  // allocate room for the counter-example
62  pCex = Abc_CexAlloc( Saig_ManRegNum(p), Saig_ManPiNum(p), Vec_PtrSize(vOnionRings)+1 );
63  pCex->iFrame = Vec_PtrSize(vOnionRings);
64  pCex->iPo = iOutput;
65  nPiOffset = Saig_ManRegNum(p) + Saig_ManPiNum(p) * Vec_PtrSize(vOnionRings);
66 
67  // create the cube of NS variables
68  bCubeNs = Bbr_bddComputeRangeCube( dd, Saig_ManCiNum(p), Saig_ManCiNum(p)+Saig_ManRegNum(p) ); Cudd_Ref( bCubeNs );
69  pTree = Bbr_bddImageStart( dd, bCubeNs, Saig_ManRegNum(p), pbParts, Saig_ManCiNum(p), dd->vars, 100000000, fVerbose );
70  Cudd_RecursiveDeref( dd, bCubeNs );
71  if ( pTree == NULL )
72  {
73  if ( !fSilent )
74  printf( "BDDs blew up during qualitification scheduling. " );
75  return NULL;
76  }
77 
78  // allocate room for the cube
79  pValues = ABC_ALLOC( char, dd->size );
80 
81  // get the last cube
82  RetValue = Cudd_bddPickOneCube( dd, bCubeFirst, pValues );
83  assert( RetValue );
84 
85  // write PIs of counter-example
86  Saig_ManForEachPi( p, pObj, i )
87  if ( pValues[i] == 1 )
88  Abc_InfoSetBit( pCex->pData, nPiOffset + i );
89  nPiOffset -= Saig_ManPiNum(p);
90 
91  // write state in terms of NS variables
92  bState = (dd)->one; Cudd_Ref( bState );
93  Saig_ManForEachLo( p, pObj, i )
94  {
95  bVar = Cudd_NotCond( dd->vars[Saig_ManCiNum(p)+i], pValues[Saig_ManPiNum(p)+i] != 1 );
96  bState = Cudd_bddAnd( dd, bTemp = bState, bVar ); Cudd_Ref( bState );
97  Cudd_RecursiveDeref( dd, bTemp );
98  }
99 
100  // perform backward analysis
101  Vec_PtrForEachEntryReverse( DdNode *, vOnionRings, bRing, v )
102  {
103  // compute the next states
104  bImage = Bbr_bddImageCompute( pTree, bState );
105  if ( bImage == NULL )
106  {
107  Cudd_RecursiveDeref( dd, bState );
108  if ( !fSilent )
109  printf( "BDDs blew up during image computation. " );
110  Bbr_bddImageTreeDelete( pTree );
111  ABC_FREE( pValues );
112  return NULL;
113  }
114  Cudd_Ref( bImage );
115  Cudd_RecursiveDeref( dd, bState );
116 
117  // intersect with the previous set
118  bImage = Cudd_bddAnd( dd, bTemp = bImage, bRing ); Cudd_Ref( bImage );
119  Cudd_RecursiveDeref( dd, bTemp );
120 
121  // find any assignment of the BDD
122  RetValue = Cudd_bddPickOneCube( dd, bImage, pValues );
123  assert( RetValue );
124  Cudd_RecursiveDeref( dd, bImage );
125 
126  // write PIs of counter-example
127  Saig_ManForEachPi( p, pObj, i )
128  if ( pValues[i] == 1 )
129  Abc_InfoSetBit( pCex->pData, nPiOffset + i );
130  nPiOffset -= Saig_ManPiNum(p);
131 
132  // check that we get the init state
133  if ( v == 0 )
134  {
135  Saig_ManForEachLo( p, pObj, i )
136  assert( pValues[Saig_ManPiNum(p)+i] == 0 );
137  break;
138  }
139 
140  // write state in terms of NS variables
141  bState = (dd)->one; Cudd_Ref( bState );
142  Saig_ManForEachLo( p, pObj, i )
143  {
144  bVar = Cudd_NotCond( dd->vars[Saig_ManCiNum(p)+i], pValues[Saig_ManPiNum(p)+i] != 1 );
145  bState = Cudd_bddAnd( dd, bTemp = bState, bVar ); Cudd_Ref( bState );
146  Cudd_RecursiveDeref( dd, bTemp );
147  }
148  }
149  // cleanup
150  Bbr_bddImageTreeDelete( pTree );
151  ABC_FREE( pValues );
152  // verify the counter example
153  if ( Vec_PtrSize(vOnionRings) < 1000 )
154  {
155  RetValue = Saig_ManVerifyCex( p, pCex );
156  if ( RetValue == 0 && !fSilent )
157  printf( "Aig_ManVerifyUsingBdds(): Counter-example verification has FAILED.\n" );
158  }
159  if ( fVerbose && !fSilent )
160  {
161  ABC_PRT( "Counter-example generation time", Abc_Clock() - clk );
162  }
163  return pCex;
164 }
165 
166 ////////////////////////////////////////////////////////////////////////
167 /// END OF FILE ///
168 ////////////////////////////////////////////////////////////////////////
169 
170 
172 
ABC_NAMESPACE_IMPL_START DdNode * Bbr_bddComputeRangeCube(DdManager *dd, int iStart, int iStop)
DECLARATIONS ///.
Definition: bbrReach.c:74
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Cudd_bddPickOneCube(DdManager *ddm, DdNode *node, char *string)
Definition: cuddUtil.c:1221
#define Vec_PtrForEachEntryReverse(Type, vVec, pEntry, i)
Definition: vecPtr.h:63
ABC_NAMESPACE_IMPL_START Abc_Cex_t * Abc_CexAlloc(int nRegs, int nRealPis, int nFrames)
DECLARATIONS ///.
Definition: utilCex.c:51
int size
Definition: cuddInt.h:361
int Saig_ManVerifyCex(Aig_Man_t *pAig, Abc_Cex_t *p)
Definition: saigDup.c:279
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Bbr_ImageTree_t * Bbr_bddImageStart(DdManager *dd, DdNode *bCare, int nParts, DdNode **pbParts, int nVars, DdNode **pbVars, int nBddMax, int fVerbose)
Definition: bbrImage.c:168
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
void Bbr_bddImageTreeDelete(Bbr_ImageTree_t *pTree)
Definition: bbrImage.c:307
static DdNode * one
Definition: cuddDecomp.c:112
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Definition: aig.h:69
#define Saig_ManForEachLo(p, pObj, i)
Definition: saig.h:96
static int Saig_ManCiNum(Aig_Man_t *p)
Definition: saig.h:75
static int Saig_ManRegNum(Aig_Man_t *p)
Definition: saig.h:77
Abc_Cex_t * Aig_ManVerifyUsingBddsCountExample(Aig_Man_t *p, DdManager *dd, DdNode **pbParts, Vec_Ptr_t *vOnionRings, DdNode *bCubeFirst, int iOutput, int fVerbose, int fSilent)
FUNCTION DEFINITIONS ///.
Definition: bbrCex.c:47
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void Abc_InfoSetBit(unsigned *p, int i)
Definition: abc_global.h:259
DdNode * bImage
Definition: bbrImage.c:1217
static int Saig_ManPiNum(Aig_Man_t *p)
MACRO DEFINITIONS ///.
Definition: saig.h:73
DdNode * Bbr_bddImageCompute(Bbr_ImageTree_t *pTree, DdNode *bCare)
Definition: bbrImage.c:253
#define ABC_FREE(obj)
Definition: abc_global.h:232
DdNode ** vars
Definition: cuddInt.h:390
#define ABC_PRT(a, t)
Definition: abc_global.h:220
DdManager * dd
Definition: bbrImage.c:1214
#define Cudd_NotCond(node, c)
Definition: cudd.h:383
DdNode * Cudd_bddAnd(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:314
#define assert(ex)
Definition: util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
Definition: utilCex.h:39
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
ABC_INT64_T abctime
Definition: abc_global.h:278
#define Saig_ManForEachPi(p, pObj, i)
Definition: saig.h:91