ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
bmcBCore.c File Reference
#include "bmc.h"
#include "sat/bsat/satSolver.h"
#include "sat/bsat/satStore.h"
Include dependency graph for bmcBCore.c:

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START Vec_Int_tBmc_ManBCoreReadPivots (char *pName)
 DECLARATIONS ///.
 
Vec_Int_tBmc_ManBCoreCollectPivots (Gia_Man_t *p, char *pName, Vec_Int_t *vVarMap)
 
void Bmc_ManBCoreCollect_rec (Gia_Man_t *p, int Id, int f, Vec_Int_t *vNodes, Vec_Int_t *vRootsNew)
 
Vec_Int_tBmc_ManBCoreCollect (Gia_Man_t *p, int iFrame, int iOut, sat_solver *pSat)
 
void Bmc_ManBCorePerform (Gia_Man_t *p, Bmc_BCorePar_t *pPars)
 MACRO DEFINITIONS ///.
 

Function Documentation

◆ Bmc_ManBCoreCollect()

Vec_Int_t * Bmc_ManBCoreCollect ( Gia_Man_t * p,
int iFrame,
int iOut,
sat_solver * pSat )

Definition at line 117 of file bmcBCore.c.

118{
119 Gia_Obj_t * pObj;
120 int f, i, iObj, nNodesOld;
121 Vec_Int_t * vNodes = Vec_IntAlloc( 100 );
122 Vec_Int_t * vRoots = Vec_IntAlloc( 100 );
123 Vec_Int_t * vRoots2 = Vec_IntAlloc( 100 );
124 assert( iFrame >= 0 && iOut >= 0 );
125 // add first variables
126 Vec_IntPush( vNodes, -1 );
127 Vec_IntPush( vNodes, -1 );
128 Bmc_ManBCoreAssignVar( p, Gia_ManPo(p, iOut), iFrame, vNodes );
129 // start with root node
130 Vec_IntPush( vRoots, Gia_ObjId(p, Gia_ManPo(p, iOut)) );
131 // iterate through time frames
132 for ( f = iFrame; f >= 0; f-- )
133 {
135 // add constant node
136 Gia_ObjSetTravIdCurrent( p, Gia_ManConst0(p) );
137 Bmc_ManBCoreAssignVar( p, Gia_ManConst0(p), f, vNodes );
138 sat_solver_add_const( pSat, Gia_ManConst0(p)->Value, 1 );
139 // collect nodes in this timeframe
140 Vec_IntClear( vRoots2 );
141 nNodesOld = Vec_IntSize(vNodes);
142 Gia_ManForEachObjVec( vRoots, p, pObj, i )
143 Bmc_ManBCoreCollect_rec( p, Gia_ObjFaninId0p(p, pObj), f, vNodes, vRoots2 );
144 if ( f == iFrame )
145 {
146 // add the final clause
147 pObj = Gia_ManPo(p, iOut);
148 assert( pObj->Value == 1 );
149 assert( Gia_ObjFanin0(pObj)->Value == 3 );
150// sat_solver_add_const( pSat, Gia_ObjFanin0(pObj)->Value, Gia_ObjFaninC0(pObj) );
151 sat_solver_add_constraint( pSat, Gia_ObjFanin0(pObj)->Value, pObj->Value, Gia_ObjFaninC0(pObj) );
152 }
153 else
154 {
155 // connect current RIs to previous ROs
156 Gia_ManForEachObjVec( vRoots, p, pObj, i )
157 sat_solver_add_buffer( pSat, pObj->Value, Gia_ObjFanin0(pObj)->Value, Gia_ObjFaninC0(pObj) );
158 }
159 Gia_ManForEachObjVec( vRoots2, p, pObj, i )
160 pObj->Value = Gia_ObjRiToRo(p, pObj)->Value;
161 // add nodes of this timeframe
162 Vec_IntForEachEntryStart( vNodes, iObj, i, nNodesOld )
163 {
164 pObj = Gia_ManObj(p, iObj); i++;
165 if ( Gia_ObjIsCi(pObj) )
166 continue;
167 assert( Gia_ObjIsAnd(pObj) );
168 sat_solver_add_and( pSat, pObj->Value, Gia_ObjFanin0(pObj)->Value, Gia_ObjFanin1(pObj)->Value, Gia_ObjFaninC0(pObj), Gia_ObjFaninC1(pObj), 0 );
169 }
170 // collect constant node
171 ABC_SWAP( Vec_Int_t *, vRoots, vRoots2 );
172 }
173 // add constraint variables for the init state
174 Gia_ManForEachObjVec( vRoots, p, pObj, i )
175 {
176 sat_solver_add_constraint( pSat, pObj->Value, Abc_Lit2Var(Vec_IntSize(vNodes)), 1 );
177 pObj = Gia_ObjRiToRo(p, pObj);
178 Bmc_ManBCoreAssignVar( p, pObj, -1, vNodes );
179 }
180 Vec_IntFree( vRoots );
181 Vec_IntFree( vRoots2 );
182 return vNodes;
183}
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
void Bmc_ManBCoreCollect_rec(Gia_Man_t *p, int Id, int f, Vec_Int_t *vNodes, Vec_Int_t *vRootsNew)
Definition bmcBCore.c:98
#define sat_solver_add_and
Definition cecSatG2.c:38
Cube * p
Definition exorList.c:222
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition gia.h:1194
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition giaUtil.c:190
unsigned Value
Definition gia.h:89
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition vecInt.h:56
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Bmc_ManBCoreCollect_rec()

void Bmc_ManBCoreCollect_rec ( Gia_Man_t * p,
int Id,
int f,
Vec_Int_t * vNodes,
Vec_Int_t * vRootsNew )

Definition at line 98 of file bmcBCore.c.

99{
100 Gia_Obj_t * pObj;
101 if ( Gia_ObjIsTravIdCurrentId(p, Id) )
102 return;
103 Gia_ObjSetTravIdCurrentId(p, Id);
104 pObj = Gia_ManObj( p, Id );
105 Bmc_ManBCoreAssignVar( p, pObj, f, vNodes );
106 if ( Gia_ObjIsPi(p, pObj) )
107 return;
108 if ( Gia_ObjIsRo(p, pObj) )
109 {
110 Vec_IntPush( vRootsNew, Gia_ObjId(p, Gia_ObjRoToRi(p, pObj)) );
111 return;
112 }
113 assert( Gia_ObjIsAnd(pObj) );
114 Bmc_ManBCoreCollect_rec( p, Gia_ObjFaninId0p(p, pObj), f, vNodes, vRootsNew );
115 Bmc_ManBCoreCollect_rec( p, Gia_ObjFaninId1p(p, pObj), f, vNodes, vRootsNew );
116}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Bmc_ManBCoreCollectPivots()

Vec_Int_t * Bmc_ManBCoreCollectPivots ( Gia_Man_t * p,
char * pName,
Vec_Int_t * vVarMap )

Definition at line 57 of file bmcBCore.c.

58{
59 Gia_Obj_t * pObj;
60 int i, iVar, iFrame;
61 Vec_Int_t * vPivots = Vec_IntAlloc( 100 );
62 Vec_Int_t * vVars = Bmc_ManBCoreReadPivots( pName );
63 Gia_ManForEachObj( p, pObj, i )
64 pObj->fMark0 = 0;
65 Vec_IntForEachEntry( vVars, iVar, i )
66 if ( iVar > 0 && iVar < Gia_ManObjNum(p) )
67 Gia_ManObj( p, iVar )->fMark0 = 1;
68 else
69 printf( "Cannot find object with Id %d in the given AIG.\n", iVar );
70 Vec_IntForEachEntryDouble( vVarMap, iVar, iFrame, i )
71 if ( Gia_ManObj( p, iVar )->fMark0 )
72 Vec_IntPush( vPivots, Abc_Lit2Var(i) );
73 Gia_ManForEachObj( p, pObj, i )
74 pObj->fMark0 = 0;
75 Vec_IntFree( vVars );
76 return vPivots;
77}
ABC_NAMESPACE_IMPL_START Vec_Int_t * Bmc_ManBCoreReadPivots(char *pName)
DECLARATIONS ///.
Definition bmcBCore.c:47
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition gia.h:1190
unsigned fMark0
Definition gia.h:81
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition vecInt.h:72
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Bmc_ManBCorePerform()

void Bmc_ManBCorePerform ( Gia_Man_t * p,
Bmc_BCorePar_t * pPars )

MACRO DEFINITIONS ///.

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 196 of file bmcBCore.c.

197{
198 clock_t clk = clock();
199 Intp_Man_t * pManProof;
200 Vec_Int_t * vVarMap, * vCore;
201 sat_solver * pSat;
202 FILE * pFile;
203 void * pSatCnf;
204 int RetValue;
205 // create SAT solver
206 pSat = sat_solver_new();
207 sat_solver_store_alloc( pSat );
208 sat_solver_setnvars( pSat, 1000 );
209 sat_solver_set_runtime_limit( pSat, pPars->nTimeOut ? pPars->nTimeOut * CLOCKS_PER_SEC + Abc_Clock(): 0 );
210 vVarMap = Bmc_ManBCoreCollect( p, pPars->iFrame, pPars->iOutput, pSat );
212 // create pivot variables
213 if ( pPars->pFilePivots )
214 {
215 Vec_Int_t * vPivots = Bmc_ManBCoreCollectPivots(p, pPars->pFilePivots, vVarMap);
216 sat_solver_set_pivot_variables( pSat, Vec_IntArray(vPivots), Vec_IntSize(vPivots) );
217 Vec_IntReleaseArray( vPivots );
218 Vec_IntFree( vPivots );
219 }
220 // solve the problem
221 RetValue = sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
222 if ( RetValue == l_Undef )
223 {
224 Vec_IntFree( vVarMap );
225 sat_solver_delete( pSat );
226 printf( "Timeout of conflict limit is reached.\n" );
227 return;
228 }
229 if ( RetValue == l_True )
230 {
231 Vec_IntFree( vVarMap );
232 sat_solver_delete( pSat );
233 printf( "The BMC problem is SAT.\n" );
234 return;
235 }
236 if ( pPars->fVerbose )
237 {
238 printf( "SAT solver returned UNSAT after %7d conflicts. ", (int)pSat->stats.conflicts );
239 Abc_PrintTime( 1, "Time", clock() - clk );
240 }
241 assert( RetValue == l_False );
242 pSatCnf = sat_solver_store_release( pSat );
243// Sto_ManDumpClauses( (Sto_Man_t *)pSatCnf, "cnf_store.txt" );
244 // derive the UNSAT core
245 clk = clock();
246 pManProof = Intp_ManAlloc();
247 vCore = (Vec_Int_t *)Intp_ManUnsatCore( pManProof, (Sto_Man_t *)pSatCnf, 1, pPars->fVerbose );
248 Intp_ManFree( pManProof );
249 if ( pPars->fVerbose )
250 {
251 printf( "UNSAT core contains %d (out of %d) learned clauses. ", Vec_IntSize(vCore), sat_solver_nconflicts(pSat) );
252 Abc_PrintTime( 1, "Time", clock() - clk );
253 }
254 // write the problem
255 Vec_IntSort( vCore, 0 );
256 pFile = pPars->pFileProof ? fopen( pPars->pFileProof, "wb" ) : stdout;
257 Intp_ManUnsatCorePrintForBmc( pFile, (Sto_Man_t *)pSatCnf, vCore, vVarMap );
258 if ( pFile != stdout )
259 fclose( pFile );
260 // cleanup
261 Sto_ManFree( (Sto_Man_t *)pSatCnf );
262 Vec_IntFree( vVarMap );
263 Vec_IntFree( vCore );
264 sat_solver_delete( pSat );
265}
Vec_Int_t * Bmc_ManBCoreCollectPivots(Gia_Man_t *p, char *pName, Vec_Int_t *vVarMap)
Definition bmcBCore.c:57
Vec_Int_t * Bmc_ManBCoreCollect(Gia_Man_t *p, int iFrame, int iOut, sat_solver *pSat)
Definition bmcBCore.c:117
#define l_True
Definition bmcBmcS.c:35
#define l_Undef
Definition bmcBmcS.c:34
#define l_False
Definition bmcBmcS.c:36
#define sat_solver
Definition cecSatG2.c:34
#define sat_solver_solve
Definition cecSatG2.c:45
void * Intp_ManUnsatCore(Intp_Man_t *p, Sto_Man_t *pCnf, int fLearned, int fVerbose)
Definition satInterP.c:963
void Intp_ManFree(Intp_Man_t *p)
Definition satInterP.c:178
void Intp_ManUnsatCorePrintForBmc(FILE *pFile, Sto_Man_t *pCnf, void *vCore0, void *vVarMap0)
Definition satInterP.c:1059
Intp_Man_t * Intp_ManAlloc()
FUNCTION DEFINITIONS ///.
Definition satInterP.c:96
sat_solver * sat_solver_new(void)
Definition satSolver.c:1137
int sat_solver_nconflicts(sat_solver *s)
Definition satSolver.c:2381
void sat_solver_setnvars(sat_solver *s, int n)
Definition satSolver.c:1272
void sat_solver_store_alloc(sat_solver *s)
Definition satSolver.c:2389
void sat_solver_store_mark_roots(sat_solver *s)
Definition satSolver.c:2412
void * sat_solver_store_release(sat_solver *s)
Definition satSolver.c:2422
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
void Sto_ManFree(Sto_Man_t *p)
Definition satStore.c:143
struct Intp_Man_t_ Intp_Man_t
Definition satStore.h:142
struct Sto_Man_t_ Sto_Man_t
Definition satStore.h:81
char * pFileProof
Definition bmc.h:176
int nTimeOut
Definition bmc.h:174
char * pFilePivots
Definition bmc.h:175
int fVerbose
Definition bmc.h:177
int iOutput
Definition bmc.h:173
stats_t stats
Definition satSolver.h:163
ABC_INT64_T conflicts
Definition satVec.h:156
Here is the call graph for this function:

◆ Bmc_ManBCoreReadPivots()

ABC_NAMESPACE_IMPL_START Vec_Int_t * Bmc_ManBCoreReadPivots ( char * pName)

DECLARATIONS ///.

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

FileName [bmcBCore.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [SAT-based bounded model checking.]

Synopsis [Performs recording of BMC core.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

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

Synopsis [Collect pivot variables.]

Description []

SideEffects []

SeeAlso []

Definition at line 47 of file bmcBCore.c.

48{
49 int Num;
50 Vec_Int_t * vPivots = Vec_IntAlloc( 100 );
51 FILE * pFile = fopen( pName, "r" );
52 while ( fscanf( pFile, "%d", &Num ) == 1 )
53 Vec_IntPush( vPivots, Num );
54 fclose( pFile );
55 return vPivots;
56}
Here is the caller graph for this function: