ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
int2Core.c
Go to the documentation of this file.
1
20
21#include "int2Int.h"
22
24
25
29
33
46{
47 memset( p, 0, sizeof(Int2_ManPars_t) );
48 p->nBTLimit = 0; // limit on the number of conflicts
49 p->nFramesS = 1; // the starting number timeframes
50 p->nFramesMax = 0; // the max number timeframes to unroll
51 p->nSecLimit = 0; // time limit in seconds
52 p->nFramesK = 1; // the number of timeframes to use in induction
53 p->fRewrite = 0; // use additional rewriting to simplify timeframes
54 p->fTransLoop = 0; // add transition into the init state under new PI var
55 p->fDropInvar = 0; // dump inductive invariant into file
56 p->fVerbose = 0; // print verbose statistics
57 p->iFrameMax = -1;
58}
59
71{
72 Gia_Man_t * pFrames, * pTemp;
73 Gia_Obj_t * pObj;
74 int i, f;
75 assert( Gia_ManRegNum(pAig) > 0 );
76 pFrames = Gia_ManStart( Gia_ManObjNum(pAig) );
77 pFrames->pName = Abc_UtilStrsav( pAig->pName );
78 pFrames->pSpec = Abc_UtilStrsav( pAig->pSpec );
79 Gia_ManHashAlloc( pFrames );
80 Gia_ManConst0(pAig)->Value = 0;
81 for ( f = 0; f < nFrames; f++ )
82 {
83 Gia_ManForEachRo( pAig, pObj, i )
84 pObj->Value = f ? Gia_ObjRoToRi( pAig, pObj )->Value : 0;
85 Gia_ManForEachPi( pAig, pObj, i )
86 pObj->Value = Gia_ManAppendCi( pFrames );
87 Gia_ManForEachAnd( pAig, pObj, i )
88 pObj->Value = Gia_ManHashAnd( pFrames, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
89 Gia_ManForEachRi( pAig, pObj, i )
90 pObj->Value = Gia_ObjFanin0Copy(pObj);
91 }
92 Gia_ManForEachRi( pAig, pObj, i )
93 Gia_ManAppendCo( pFrames, pObj->Value );
94 Gia_ManHashStop( pFrames );
95 pFrames = Gia_ManCleanup( pTemp = pFrames );
96 Gia_ManStop( pTemp );
97 return pFrames;
98}
100{
101 Gia_Man_t * pPref, * pNew;
102 sat_solver * pSat;
103 // create subset of the timeframe
104 pPref = Int2_ManUnroll( p, f );
105 // create SAT solver
106 pNew = Jf_ManDeriveCnf( pPref, 0 );
107 pCnf = (Cnf_Dat_t *)pPref->pData; pPref->pData = NULL;
108 Gia_ManStop( pPref );
109 // derive the SAT solver
110 pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, 1, 0 );
111 // collect indexes of CO variables
112 *pvCiMap = Vec_IntAlloc( 100 );
113 Gia_ManForEachPo( pNew, pObj, i )
114 Vec_IntPush( *pvCiMap, pCnf->pVarNums[ Gia_ObjId(pNew, pObj) ] );
115 // cleanup
116 Cnf_DataFree( pCnf );
117 Gia_ManStop( pNew );
118 return pSat;
119}
120
132sat_solver * Int2_ManPrepareSuffix( Gia_Man_t * p, Vec_Int_t * vImageOne, Vec_Int_t * vImagesAll, Vec_Int_t ** pvCoMap, Gia_Man_t ** ppSuff )
133{
134 Gia_Man_t * pSuff, * pNew;
135 Gia_Obj_t * pObj;
136 Cnf_Dat_t * pCnf;
137 sat_solver * pSat;
138 Vec_Int_t * vLits;
139 int i, Lit, Limit;
140 // create subset of the timeframe
141 pSuff = Int2_ManProbToGia( p, vImageOne );
142 assert( Gia_ManPiNum(pSuff) == Gia_ManCiNum(p) );
143 // create SAT solver
144 pNew = Jf_ManDeriveCnf( pSuff, 0 );
145 pCnf = (Cnf_Dat_t *)pSuff->pData; pSuff->pData = NULL;
146 Gia_ManStop( pSuff );
147 // derive the SAT solver
148 pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, 1, 0 );
149 // create new constraints
150 vLits = Vec_IntAlloc( 1000 );
151 Vec_IntForEachEntryStart( vImagesAll, Limit, i, 1 )
152 {
153 Vec_IntClear( vLits );
154 for ( k = 0; k < Limit; k++ )
155 {
156 i++;
157 Lit = Vec_IntEntry( vSop, i + k );
158 Vec_IntPush( vLits, Abc_LitNot(Lit) );
159 }
160 if ( !sat_solver_addclause( pSat, Vec_IntArray(vLits), Vec_IntArray(vLits) + Vec_IntSize(vLits) ) ) // UNSAT
161 {
162 Vec_IntFree( vLits );
163 Cnf_DataFree( pCnf );
164 Gia_ManStop( pNew );
165 *pvCoMap = NULL;
166 return NULL;
167 }
168 }
169 Vec_IntFree( vLits );
170 // collect indexes of CO variables
171 *pvCoMap = Vec_IntAlloc( 100 );
172 Gia_ManForEachRo( p, pObj, i )
173 {
174 pObj = Gia_ManPi( pNew, i + Gia_ManPiNum(p) );
175 Vec_IntPush( *pvCoMap, pCnf->pVarNums[ Gia_ObjId(pNew, pObj) ] );
176 }
177 // cleanup
178 Cnf_DataFree( pCnf );
179 if ( ppSuff )
180 *ppSuff = pNew;
181 else
182 Gia_ManStop( pNew );
183 return pSat;
184}
185
197Vec_Int_t * Int2_ManComputePreimage( Gia_Man_t * pSuff, sat_solver * pSatPref, sat_solver * pSatSuff, Vec_Int_t * vCiMap, Vec_Int_t * vCoMap, Vec_Int_t * vPrio )
198{
199 int i, iVar, status;
200 Vec_IntClear( p->vImage );
201 while ( 1 )
202 {
203 // run suffix solver
204 status = sat_solver_solve( p->pSatSuff, NULL, NULL, 0, 0, 0, 0 );
205 if ( status == l_Undef )
206 return NULL; // timeout
207 if ( status == l_False )
208 return INT2_COMPUTED;
209 assert( status == l_True );
210 // collect assignment
211 Vec_IntClear( p->vAssign );
212 Vec_IntForEachEntry( p->vCiMap, iVar, i )
213 Vec_IntPush( p->vAssign, sat_solver_var_value(p->pSatSuff, iVar) );
214 // derive initial cube
215 vCube = Int2_ManRefineCube( p->pSuff, p->vAssign, p->vPrio );
216 // expend the cube using prefix
217 status = sat_solver_solve( p->pSatPref, Vec_IntArray(vCube), Vec_IntArray(vCube) + Vec_IntSize(vCube), 0, 0, 0, 0 );
218 if ( status == l_False )
219 {
220 int k, nCoreLits, * pCoreLits;
221 nCoreLits = sat_solver_final( p->pSatPref, &pCoreLits );
222 // create cube
223 Vec_IntClear( vCube );
224 Vec_IntPush( vImage, nCoreLits );
225 for ( k = 0; k < nCoreLits; k++ )
226 {
227 Vec_IntPush( vCube, pCoreLits[k] );
228 Vec_IntPush( vImage, pCoreLits[k] );
229 }
230 // add cube to the solver
231 if ( !sat_solver_addclause( p->pSatSuff, Vec_IntArray(vCube), Vec_IntArray(vCube) + Vec_IntSize(vCube) ) )
232 {
233 Vec_IntFree( vCube );
234 return INT2_COMPUTED;
235 }
236 }
237 Vec_IntFree( vCube );
238 if ( status == l_Undef )
239 return INT2_TIME_OUT;
240 if ( status == l_True )
241 return INT2_FALSE_NEG;
242 assert( status == l_False );
243 continue;
244 }
245 return p->vImage;
246}
247
260{
261 Int2_Man_t * p;
262 int f, i, RetValue = -1;
263 abctime clk, clkTotal = Abc_Clock(), timeTemp = 0;
264 abctime nTimeToStop = pPars->nSecLimit ? pPars->nSecLimit * CLOCKS_PER_SEC + Abc_Clock() : 0;
265
266 // sanity checks
267 assert( Gia_ManPiNum(pInit) > 0 );
268 assert( Gia_ManPoNum(pInit) > 0 );
269 assert( Gia_ManRegNum(pInit) > 0 );
270
271 // create manager
272 p = Int2_ManCreate( pInit, pPars );
273
274 // create SAT solver
275 p->pSatPref = sat_solver_new();
276 sat_solver_setnvars( p->pSatPref, 1000 );
277 sat_solver_set_runtime_limit( p->pSatPref, nTimeToStop );
278
279 // check outputs in the first frame
280 for ( i = 0; i < Gia_ManPoNum(pInit); i++ )
281 Vec_IntPush( p->vPrefCos, i );
282 Int2_ManCreateFrames( p, 0, p->vPrefCos );
283 RetValue = Int2_ManCheckBmc( p, NULL );
284 if ( RetValue != 1 )
285 return RetValue;
286
287 // create original image
288 for ( f = pPars->nFramesS; f < p->nFramesMax; f++ )
289 {
290 for ( i = 0; i < p->nFramesMax; i++ )
291 {
292 p->pSatSuff = Int2_ManPrepareSuffix( p, vImageOne. vImagesAll, &vCoMap, &pGiaSuff );
293 sat_solver_set_runtime_limit( p->pSatSuff, nTimeToStop );
294 Vec_IntFreeP( &vImageOne );
295 vImageOne = Int2_ManComputePreimage( pGiaSuff, p->pSatPref, p->pSatSuff, vCiMap, vCoMap );
296 Vec_IntFree( vCoMap );
297 Gia_ManStop( pGiaSuff );
298 if ( nTimeToStop && Abc_Clock() > nTimeToStop )
299 return -1;
300 if ( vImageOne == NULL )
301 {
302 if ( i == 0 )
303 {
304 printf( "Satisfiable in frame %d.\n", f );
305 Vec_IntFree( vCiMap );
306 sat_solver_delete( p->pSatPref ); p->pSatPref = NULL;
307 return 0;
308 }
309 f += i;
310 break;
311 }
312 Vec_IntAppend( vImagesAll, vImageOne );
313 sat_solver_delete( p->pSatSuff ); p->pSatSuff = NULL;
314 }
315 Vec_IntFree( vCiMap );
316 sat_solver_delete( p->pSatPref ); p->pSatPref = NULL;
317 }
318 Abc_PrintTime( "Time", Abc_Clock() - clk );
319
320
321p->timeSatPref += Abc_Clock() - clk;
322
323 Int2_ManStop( p );
324 return RetValue;
325}
326
327
328
332
333
335
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
#define l_True
Definition bmcBmcS.c:35
#define l_Undef
Definition bmcBmcS.c:34
#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
struct Cnf_Dat_t_ Cnf_Dat_t
Definition cnf.h:52
void Cnf_DataFree(Cnf_Dat_t *p)
Definition cnfMan.c:207
Cube * p
Definition exorList.c:222
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
#define Gia_ManForEachRo(p, pObj, i)
Definition gia.h:1252
#define Gia_ManForEachPo(p, pObj, i)
Definition gia.h:1250
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition giaHash.c:105
#define Gia_ManForEachPi(p, pObj, i)
Definition gia.h:1248
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
void Gia_ManHashStop(Gia_Man_t *p)
Definition giaHash.c:149
#define Gia_ManForEachRi(p, pObj, i)
Definition gia.h:1254
Gia_Man_t * Jf_ManDeriveCnf(Gia_Man_t *p, int fCnfObjIds)
Definition giaJf.c:1749
void Int2_ManCreateFrames(Int2_Man_t *p, int iFrame, Vec_Int_t *vPrefCos)
Definition int2Bmc.c:219
int Int2_ManCheckBmc(Int2_Man_t *p, Vec_Int_t *vCube)
Definition int2Bmc.c:318
Gia_Man_t * Int2_ManUnroll(Gia_Man_t *p, int nFrames)
Definition int2Core.c:70
Vec_Int_t * Int2_ManComputePreimage(Gia_Man_t *pSuff, sat_solver *pSatPref, sat_solver *pSatSuff, Vec_Int_t *vCiMap, Vec_Int_t *vCoMap, Vec_Int_t *vPrio)
Definition int2Core.c:197
sat_solver * Int2_ManPrepareSuffix(Gia_Man_t *p, Vec_Int_t *vImageOne, Vec_Int_t *vImagesAll, Vec_Int_t **pvCoMap, Gia_Man_t **ppSuff)
Definition int2Core.c:132
ABC_NAMESPACE_IMPL_START void Int2_ManSetDefaultParams(Int2_ManPars_t *p)
DECLARATIONS ///.
Definition int2Core.c:45
sat_solver * Int2_ManPreparePrefix(Gia_Man_t *p, int f, Vec_Int_t **pvCiMap)
Definition int2Core.c:99
int Int2_ManPerformInterpolation(Gia_Man_t *pInit, Int2_ManPars_t *pPars)
Definition int2Core.c:259
typedefABC_NAMESPACE_HEADER_START struct Int2_Man_t_ Int2_Man_t
INCLUDES ///.
Definition int2Int.h:45
Vec_Int_t * Int2_ManRefineCube(Gia_Man_t *p, Vec_Int_t *vAssign, Vec_Int_t *vPrio)
Definition int2Refine.c:104
Gia_Man_t * Int2_ManProbToGia(Gia_Man_t *p, Vec_Int_t *vSop)
Definition int2Util.c:98
typedefABC_NAMESPACE_HEADER_START struct Int2_ManPars_t_ Int2_ManPars_t
INCLUDES ///.
Definition int2.h:50
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
Definition cnfMan.c:579
sat_solver * sat_solver_new(void)
Definition satSolver.c:1137
void sat_solver_setnvars(sat_solver *s, int n)
Definition satSolver.c:1272
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
int * pVarNums
Definition cnf.h:63
char * pSpec
Definition gia.h:100
void * pData
Definition gia.h:198
char * pName
Definition gia.h:99
unsigned Value
Definition gia.h:89
#define assert(ex)
Definition util_old.h:213
char * memset()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition vecInt.h:56