abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fraIndVer.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [fraIndVer.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [New FRAIG package.]
8 
9  Synopsis [Verification of the inductive invariant.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 30, 2007.]
16 
17  Revision [$Id: fraIndVer.c,v 1.00 2007/06/30 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "fra.h"
22 #include "sat/cnf/cnf.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 ////////////////////////////////////////////////////////////////////////
32 /// FUNCTION DEFINITIONS ///
33 ////////////////////////////////////////////////////////////////////////
34 
35 /**Function*************************************************************
36 
37  Synopsis [Verifies the inductive invariant.]
38 
39  Description []
40 
41  SideEffects []
42 
43  SeeAlso []
44 
45 ***********************************************************************/
46 int Fra_InvariantVerify( Aig_Man_t * pAig, int nFrames, Vec_Int_t * vClauses, Vec_Int_t * vLits )
47 {
48  Cnf_Dat_t * pCnf;
49  sat_solver * pSat;
50  int * pStart;
51  int RetValue, Beg, End, i, k;
52  int CounterBase = 0, CounterInd = 0;
53  abctime clk = Abc_Clock();
54 
55  if ( nFrames != 1 )
56  {
57  printf( "Invariant verification: Can only verify for K = 1\n" );
58  return 1;
59  }
60 
61  // derive CNF
62  pCnf = Cnf_DeriveSimple( pAig, Aig_ManCoNum(pAig) );
63 /*
64  // add the property
65  {
66  Aig_Obj_t * pObj;
67  int Lits[1];
68 
69  pObj = Aig_ManCo( pAig, 0 );
70  Lits[0] = toLitCond( pCnf->pVarNums[pObj->Id], 1 );
71 
72  Vec_IntPush( vLits, Lits[0] );
73  Vec_IntPush( vClauses, Vec_IntSize(vLits) );
74  printf( "Added the target property to the set of clauses to be inductively checked.\n" );
75  }
76 */
77  // derive initialized frames for the base case
78  pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, nFrames, 1 );
79  // check clauses in the base case
80  Beg = 0;
81  pStart = Vec_IntArray( vLits );
82  Vec_IntForEachEntry( vClauses, End, i )
83  {
84  // complement the literals
85  for ( k = Beg; k < End; k++ )
86  pStart[k] = lit_neg(pStart[k]);
87  RetValue = sat_solver_solve( pSat, pStart + Beg, pStart + End, 0, 0, 0, 0 );
88  for ( k = Beg; k < End; k++ )
89  pStart[k] = lit_neg(pStart[k]);
90  Beg = End;
91  if ( RetValue == l_False )
92  continue;
93 // printf( "Clause %d failed the base case.\n", i );
94  CounterBase++;
95  }
96  sat_solver_delete( pSat );
97 
98  // derive initialized frames for the base case
99  pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, nFrames + 1, 0 );
100  assert( pSat->size == 2 * pCnf->nVars );
101  // add clauses to the first frame
102  Beg = 0;
103  pStart = Vec_IntArray( vLits );
104  Vec_IntForEachEntry( vClauses, End, i )
105  {
106  RetValue = sat_solver_addclause( pSat, pStart + Beg, pStart + End );
107  Beg = End;
108  if ( RetValue == 0 )
109  {
110  Cnf_DataFree( pCnf );
111  sat_solver_delete( pSat );
112  printf( "Invariant verification: SAT solver is unsat after adding a clause.\n" );
113  return 0;
114  }
115  }
116  // simplify the solver
117  if ( pSat->qtail != pSat->qhead )
118  {
119  RetValue = sat_solver_simplify(pSat);
120  assert( RetValue != 0 );
121  assert( pSat->qtail == pSat->qhead );
122  }
123 
124  // check clauses in the base case
125  Beg = 0;
126  pStart = Vec_IntArray( vLits );
127  Vec_IntForEachEntry( vClauses, End, i )
128  {
129  // complement the literals
130  for ( k = Beg; k < End; k++ )
131  {
132  pStart[k] += 2 * pCnf->nVars;
133  pStart[k] = lit_neg(pStart[k]);
134  }
135  RetValue = sat_solver_solve( pSat, pStart + Beg, pStart + End, 0, 0, 0, 0 );
136  for ( k = Beg; k < End; k++ )
137  {
138  pStart[k] = lit_neg(pStart[k]);
139  pStart[k] -= 2 * pCnf->nVars;
140  }
141  Beg = End;
142  if ( RetValue == l_False )
143  continue;
144 // printf( "Clause %d failed the inductive case.\n", i );
145  CounterInd++;
146  }
147  sat_solver_delete( pSat );
148  Cnf_DataFree( pCnf );
149  if ( CounterBase )
150  printf( "Invariant verification: %d clauses (out of %d) FAILED the base case.\n", CounterBase, Vec_IntSize(vClauses) );
151  if ( CounterInd )
152  printf( "Invariant verification: %d clauses (out of %d) FAILED the inductive case.\n", CounterInd, Vec_IntSize(vClauses) );
153  if ( CounterBase || CounterInd )
154  return 0;
155  printf( "Invariant verification: %d clauses verified correctly. ", Vec_IntSize(vClauses) );
156  ABC_PRT( "Time", Abc_Clock() - clk );
157  return 1;
158 }
159 
160 ////////////////////////////////////////////////////////////////////////
161 /// END OF FILE ///
162 ////////////////////////////////////////////////////////////////////////
163 
164 
166 
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
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
int nVars
Definition: cnf.h:59
void sat_solver_delete(sat_solver *s)
Definition: satSolver.c:1141
static abctime Abc_Clock()
Definition: abc_global.h:279
Definition: cnf.h:56
static lit lit_neg(lit l)
Definition: satVec.h:144
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
ABC_NAMESPACE_IMPL_START int Fra_InvariantVerify(Aig_Man_t *pAig, int nFrames, Vec_Int_t *vClauses, Vec_Int_t *vLits)
DECLARATIONS ///.
Definition: fraIndVer.c:46
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int sat_solver_simplify(sat_solver *s)
Definition: satSolver.c:1276
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
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
#define ABC_PRT(a, t)
Definition: abc_global.h:220
#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
ABC_INT64_T abctime
Definition: abc_global.h:278
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54