ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
bmcMaxi.c
Go to the documentation of this file.
1
20
21#include "bmc.h"
22#include "sat/cnf/cnf.h"
23#include "sat/bsat/satStore.h"
24#include "aig/gia/giaAig.h"
25
27
28
32
36
48static inline Cnf_Dat_t * Cnf_DeriveGiaRemapped( Gia_Man_t * p )
49{
50 Cnf_Dat_t * pCnf;
51 Aig_Man_t * pAig = Gia_ManToAigSimple( p );
52 pAig->nRegs = 0;
53 pCnf = Cnf_Derive( pAig, Aig_ManCoNum(pAig) );
54 Aig_ManStop( pAig );
55 return pCnf;
56}
57
69Gia_Man_t * Gia_ManMaxiUnfold( Gia_Man_t * p, int nFrames, int fUseVars, Vec_Int_t * vInit )
70{
71 Gia_Man_t * pNew, * pTemp;
72 Gia_Obj_t * pObj;
73 int i, f;
74 pNew = Gia_ManStart( fUseVars * 2 * Gia_ManRegNum(p) + nFrames * Gia_ManObjNum(p) );
75 pNew->pName = Abc_UtilStrsav( p->pName );
76 Gia_ManHashAlloc( pNew );
77 Gia_ManConst0(p)->Value = 0;
78 // control/data variables
79 Gia_ManForEachRo( p, pObj, i )
80 Gia_ManAppendCi( pNew );
81 Gia_ManForEachRo( p, pObj, i )
82 Gia_ManAppendCi( pNew );
83 // build timeframes
84 assert( !vInit || Vec_IntSize(vInit) == Gia_ManRegNum(p) );
85 Gia_ManForEachRo( p, pObj, i )
86 {
87 int Value = Vec_IntEntry( vInit, i );
88 int iCtrl = Gia_ManCiLit( pNew, i );
89 int iData = Gia_ManCiLit( pNew, Gia_ManRegNum(p)+i );
90 // decide based on Value
91 if ( Value == 0 )
92 pObj->Value = fUseVars ? Gia_ManHashAnd(pNew, iCtrl, iData) : 0;
93 else if ( Value == 1 )
94 pObj->Value = fUseVars ? Gia_ManHashOr(pNew, Abc_LitNot(iCtrl), iData) : 1;
95 else if ( Value == 2 )
96 pObj->Value = Gia_ManHashAnd(pNew, iCtrl, iData);
97 else if ( Value == 3 )
98 pObj->Value = Gia_ManHashOr(pNew, Abc_LitNot(iCtrl), iData);
99 else if ( Value == 4 )
100 pObj->Value = 0;
101 else if ( Value == 5 )
102 pObj->Value = 1;
103 else assert( 0 );
104 }
105 for ( f = 0; f < nFrames; f++ )
106 {
107 Gia_ManForEachPi( p, pObj, i )
108 pObj->Value = Gia_ManAppendCi( pNew );
109 Gia_ManForEachAnd( p, pObj, i )
110 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
111 Gia_ManForEachRi( p, pObj, i )
112 pObj->Value = Gia_ObjFanin0Copy(pObj);
113 Gia_ManForEachRo( p, pObj, i )
114 pObj->Value = Gia_ObjRoToRi(p, pObj)->Value;
115 }
116 Gia_ManForEachRi( p, pObj, i )
117 pObj->Value = Gia_ManAppendCo( pNew, pObj->Value );
118 pNew = Gia_ManCleanup( pTemp = pNew );
119 Gia_ManStop( pTemp );
120 assert( Gia_ManPiNum(pNew) == 2 * Gia_ManRegNum(p) + nFrames * Gia_ManPiNum(p) );
121 return pNew;
122}
123
124
136Vec_Int_t * Gia_ManMaxiPerform( Gia_Man_t * p, Vec_Int_t * vInit, int nFrames, int nTimeOut, int fVerbose )
137{
138 int nIterMax = 1000000;
139 int i, iLit, Iter, status;
140 int nLits, * pLits;
141 abctime clkTotal = Abc_Clock();
142 abctime clkSat = 0;
143 Vec_Int_t * vLits, * vMap;
144 sat_solver * pSat;
145 Gia_Obj_t * pObj;
146 Gia_Man_t * p0 = Gia_ManMaxiUnfold( p, nFrames, 0, vInit );
147 Gia_Man_t * p1 = Gia_ManMaxiUnfold( p, nFrames, 1, vInit );
148 Gia_Man_t * pM = Gia_ManMiter( p0, p1, 0, 0, 0, 0, 0 );
149 Cnf_Dat_t * pCnf = Cnf_DeriveGiaRemapped( pM );
150 Gia_ManStop( p0 );
151 Gia_ManStop( p1 );
152 assert( Gia_ManRegNum(p) > 0 );
153 if ( fVerbose )
154 printf( "Running with %d frames and %sgiven init state.\n", nFrames, vInit ? "":"no " );
155
156 pSat = sat_solver_new();
157 sat_solver_setnvars( pSat, pCnf->nVars );
158 sat_solver_set_runtime_limit( pSat, nTimeOut ? nTimeOut * CLOCKS_PER_SEC + Abc_Clock(): 0 );
159 for ( i = 0; i < pCnf->nClauses; i++ )
160 if ( !sat_solver_addclause( pSat, pCnf->pClauses[i], pCnf->pClauses[i+1] ) )
161 assert( 0 );
162
163 // add one large OR clause
164 vLits = Vec_IntAlloc( Gia_ManCoNum(p) );
165 Gia_ManForEachCo( pM, pObj, i )
166 Vec_IntPush( vLits, Abc_Var2Lit(pCnf->pVarNums[Gia_ObjId(pM, pObj)], 0) );
167 sat_solver_addclause( pSat, Vec_IntArray(vLits), Vec_IntArray(vLits) + Vec_IntSize(vLits) );
168
169 // create assumptions
170 Vec_IntClear( vLits );
171 Gia_ManForEachPi( pM, pObj, i )
172 if ( i == Gia_ManRegNum(p) )
173 break;
174 else if ( Vec_IntEntry(vInit, i) == 0 || Vec_IntEntry(vInit, i) == 1 )
175 Vec_IntPush( vLits, Abc_Var2Lit(pCnf->pVarNums[Gia_ObjId(pM, pObj)], 1) );
176
177 if ( fVerbose )
178 {
179 printf( "Iter%6d : ", 0 );
180 printf( "Var =%10d ", sat_solver_nvars(pSat) );
181 printf( "Clause =%10d ", sat_solver_nclauses(pSat) );
182 printf( "Conflict =%10d ", sat_solver_nconflicts(pSat) );
183 printf( "Subset =%6d ", Vec_IntSize(vLits) );
184 Abc_PrintTime( 1, "Time", clkSat );
185// ABC_PRTr( "Solver time", clkSat );
186 }
187 for ( Iter = 0; Iter < nIterMax; Iter++ )
188 {
189 abctime clk = Abc_Clock();
190 status = sat_solver_solve( pSat, Vec_IntArray(vLits), Vec_IntArray(vLits) + Vec_IntSize(vLits), (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
191 clkSat += Abc_Clock() - clk;
192 if ( status == l_Undef )
193 {
194// if ( fVerbose )
195// printf( "\n" );
196 printf( "Timeout reached after %d seconds and %d iterations. ", nTimeOut, Iter );
197 break;
198 }
199 if ( status == l_True )
200 {
201// if ( fVerbose )
202// printf( "\n" );
203 printf( "The problem is SAT after %d iterations. ", Iter );
204 break;
205 }
206 assert( status == l_False );
207 nLits = sat_solver_final( pSat, &pLits );
208 if ( fVerbose )
209 {
210 printf( "Iter%6d : ", Iter+1 );
211 printf( "Var =%10d ", sat_solver_nvars(pSat) );
212 printf( "Clause =%10d ", sat_solver_nclauses(pSat) );
213 printf( "Conflict =%10d ", sat_solver_nconflicts(pSat) );
214 printf( "Subset =%6d ", nLits );
215 Abc_PrintTime( 1, "Time", clkSat );
216// ABC_PRTr( "Solver time", clkSat );
217 }
218 if ( Vec_IntSize(vLits) == nLits )
219 {
220// if ( fVerbose )
221// printf( "\n" );
222 printf( "Reached fixed point with %d entries after %d iterations. ", Vec_IntSize(vLits), Iter+1 );
223 break;
224 }
225 // collect used literals
226 Vec_IntClear( vLits );
227 for ( i = 0; i < nLits; i++ )
228 Vec_IntPush( vLits, Abc_LitNot(pLits[i]) );
229 }
230 // create map
231 vMap = Vec_IntStart( pCnf->nVars );
232 Vec_IntForEachEntry( vLits, iLit, i )
233 Vec_IntWriteEntry( vMap, Abc_Lit2Var(iLit), 1 );
234
235 // create output
236 Vec_IntFree( vLits );
237 vLits = Vec_IntDup(vInit);
238 Gia_ManForEachPi( pM, pObj, i )
239 if ( i == Gia_ManRegNum(p) )
240 break;
241 else if ( Vec_IntEntry(vLits, i) == 4 || Vec_IntEntry(vLits, i) == 5 )
242 Vec_IntWriteEntry( vLits, i, Vec_IntEntry(vLits, i) );
243 else if ( (Vec_IntEntry(vLits, i) == 0 || Vec_IntEntry(vLits, i) == 1) && !Vec_IntEntry(vMap, pCnf->pVarNums[Gia_ObjId(pM, pObj)]) )
244 Vec_IntWriteEntry( vLits, i, Vec_IntEntry(vLits, i) | 2 );
245 Vec_IntFree( vMap );
246
247 // cleanup
248 sat_solver_delete( pSat );
249 Cnf_DataFree( pCnf );
250 Gia_ManStop( pM );
251 Abc_PrintTime( 1, "Total runtime", Abc_Clock() - clkTotal );
252 return vLits;
253}
254
266Vec_Int_t * Gia_ManMaxiTest( Gia_Man_t * p, Vec_Int_t * vInit0, int nFrames, int nWords, int nTimeOut, int fSim, int fVerbose )
267{
268 Vec_Int_t * vRes, * vInit;
269 vInit = vInit0 ? vInit0 : Vec_IntStart( Gia_ManRegNum(p) );
270 vRes = Gia_ManMaxiPerform( p, vInit, nFrames, nTimeOut, fVerbose );
271 if ( vInit != vInit0 )
272 Vec_IntFree( vInit );
273 return vRes;
274}
275
279
280
282
int nWords
Definition abcNpn.c:127
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Aig_ManStop(Aig_Man_t *p)
Definition aigMan.c:187
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_True
Definition bmcBmcS.c:35
#define l_Undef
Definition bmcBmcS.c:34
#define l_False
Definition bmcBmcS.c:36
Vec_Int_t * Gia_ManMaxiPerform(Gia_Man_t *p, Vec_Int_t *vInit, int nFrames, int nTimeOut, int fVerbose)
Definition bmcMaxi.c:136
Gia_Man_t * Gia_ManMaxiUnfold(Gia_Man_t *p, int nFrames, int fUseVars, Vec_Int_t *vInit)
Definition bmcMaxi.c:69
Vec_Int_t * Gia_ManMaxiTest(Gia_Man_t *p, Vec_Int_t *vInit0, int nFrames, int nWords, int nTimeOut, int fSim, int fVerbose)
Definition bmcMaxi.c:266
#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_Derive(Aig_Man_t *pAig, int nOutputs)
Definition cnfCore.c:165
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
Aig_Man_t * Gia_ManToAigSimple(Gia_Man_t *p)
Definition giaAig.c:408
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
#define Gia_ManForEachRo(p, pObj, i)
Definition gia.h:1252
#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
int Gia_ManHashOr(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:621
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
Gia_Man_t * Gia_ManMiter(Gia_Man_t *pAig0, Gia_Man_t *pAig1, int nInsDup, int fDualOut, int fSeq, int fImplic, int fVerbose)
Definition giaDup.c:2983
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
#define Gia_ManForEachRi(p, pObj, i)
Definition gia.h:1254
sat_solver * sat_solver_new(void)
Definition satSolver.c:1137
int sat_solver_nconflicts(sat_solver *s)
Definition satSolver.c:2381
int sat_solver_nclauses(sat_solver *s)
Definition satSolver.c:2375
void sat_solver_setnvars(sat_solver *s, int n)
Definition satSolver.c:1272
int sat_solver_nvars(sat_solver *s)
Definition satSolver.c:2369
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
int nVars
Definition cnf.h:59
int * pVarNums
Definition cnf.h:63
int ** pClauses
Definition cnf.h:62
int nClauses
Definition cnf.h:61
char * pName
Definition gia.h:99
unsigned Value
Definition gia.h:89
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54