ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
fraIndVer.c
Go to the documentation of this file.
1
20
21#include "fra.h"
22#include "sat/cnf/cnf.h"
23
25
26
30
34
46int 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
163
164
166
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
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
#define l_False
Definition bmcBmcS.c:36
#define sat_solver_addclause
Definition cecSatG2.c:37
#define sat_solver
Definition cecSatG2.c:34
#define sat_solver_solve
Definition cecSatG2.c:45
Cnf_Dat_t * Cnf_DeriveSimple(Aig_Man_t *p, int nOutputs)
Definition cnfWrite.c:587
struct Cnf_Dat_t_ Cnf_Dat_t
Definition cnf.h:52
void Cnf_DataFree(Cnf_Dat_t *p)
Definition cnfMan.c:207
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
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
Definition cnfMan.c:579
int sat_solver_simplify(sat_solver *s)
Definition satSolver.c:1515
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
int nVars
Definition cnf.h:59
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54