82static inline int Aig_Gla1AddConst(
sat_solver * pSat,
int iVar,
int fCompl )
84 lit Lit = toLitCond( iVar, fCompl );
101static inline int Aig_Gla1AddBuffer(
sat_solver * pSat,
int iVar0,
int iVar1,
int fCompl )
105 Lits[0] = toLitCond( iVar0, 0 );
106 Lits[1] = toLitCond( iVar1, !fCompl );
110 Lits[0] = toLitCond( iVar0, 1 );
111 Lits[1] = toLitCond( iVar1, fCompl );
129static inline int Aig_Gla1AddNode(
sat_solver * pSat,
int iVar,
int iVar0,
int iVar1,
int fCompl0,
int fCompl1 )
133 Lits[0] = toLitCond( iVar, 1 );
134 Lits[1] = toLitCond( iVar0, fCompl0 );
138 Lits[0] = toLitCond( iVar, 1 );
139 Lits[1] = toLitCond( iVar1, fCompl1 );
143 Lits[0] = toLitCond( iVar, 0 );
144 Lits[1] = toLitCond( iVar0, !fCompl0 );
145 Lits[2] = toLitCond( iVar1, !fCompl1 );
194 Vec_IntClear(
p->vPis );
195 Vec_IntClear(
p->vPPis );
196 Vec_IntClear(
p->vFlops );
197 Vec_IntClear(
p->vNodes );
200 pObj = Aig_ManObj(
p->pAig, Entry );
201 if ( Saig_ObjIsPi(
p->pAig, pObj) )
202 Vec_IntPush(
p->vPis, Aig_ObjId(pObj) );
203 else if ( !Vec_IntEntry(
p->vIncluded, Aig_ObjId(pObj)) )
204 Vec_IntPush(
p->vPPis, Aig_ObjId(pObj) );
205 else if ( Aig_ObjIsNode(pObj) )
206 Vec_IntPush(
p->vNodes, Aig_ObjId(pObj) );
207 else if ( Saig_ObjIsLo(
p->pAig, pObj) )
208 Vec_IntPush(
p->vFlops, Aig_ObjId(pObj) );
209 else assert( Aig_ObjIsConst1(pObj) );
228 assert( Aig_ObjIsNode(pObj) );
231 pObj->
pData =
Aig_And( pNew, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) );
250 assert( Saig_ManPoNum(
p->pAig) == 1 );
253 pNew->pName = Abc_UtilStrsav(
p->pAig->pName );
256 Aig_ManConst1(
p->pAig)->pData = Aig_ManConst1(pNew);
276 assert( Saig_ObjIsLo(
p->pAig, pObj) );
277 pObj = Saig_ObjLoToLi(
p->pAig, pObj );
284 printf(
"Aig_Gla1DeriveAbs(): Internal error! Object count mismatch.\n" );
303 iVecId = Vec_IntEntry(
p->vObj2Vec, Aig_ObjId(pObj) );
306 iVecId = Vec_IntSize(
p->vVec2Var ) /
p->nFrames;
307 for ( i = 0; i <
p->nFrames; i++ )
308 Vec_IntPush(
p->vVec2Var, 0 );
309 Vec_IntWriteEntry(
p->vObj2Vec, Aig_ObjId(pObj), iVecId );
310 Vec_IntPushOrderReverse(
p->vAssigned, Aig_ObjId(pObj) );
330 iVecId = Aig_Gla1FetchVecId(
p, pObj );
331 iSatVar = Vec_IntEntry(
p->vVec2Var, iVecId *
p->nFrames + k );
334 iSatVar = Vec_IntSize(
p->vVar2Inf ) / 2;
335 Vec_IntPush(
p->vVar2Inf, Aig_ObjId(pObj) );
336 Vec_IntPush(
p->vVar2Inf, k );
337 Vec_IntWriteEntry(
p->vVec2Var, iVecId *
p->nFrames + k, iSatVar );
356 if ( k ==
p->nFrames )
358 int i, j, nVecIds = Vec_IntSize(
p->vVec2Var ) /
p->nFrames;
359 Vec_Int_t * vVec2VarNew = Vec_IntAlloc( 4 * nVecIds *
p->nFrames );
360 for ( i = 0; i < nVecIds; i++ )
362 for ( j = 0; j <
p->nFrames; j++ )
363 Vec_IntPush( vVec2VarNew, Vec_IntEntry(
p->vVec2Var, i *
p->nFrames + j ) );
364 for ( j = 0; j <
p->nFrames; j++ )
365 Vec_IntPush( vVec2VarNew, i ? 0 : -1 );
367 Vec_IntFree(
p->vVec2Var );
368 p->vVec2Var = vVec2VarNew;
372 assert( Vec_IntEntry(
p->vIncluded, Aig_ObjId(pObj)) );
373 if ( Aig_ObjIsConst1(pObj) )
374 return Aig_Gla1AddConst(
p->pSat, Aig_Gla1FetchVar(
p, pObj, k), 0 );
375 if ( Saig_ObjIsLo(
p->pAig, pObj) )
377 Aig_Obj_t * pObjLi = Saig_ObjLoToLi(
p->pAig, pObj);
380 Aig_Gla1FetchVecId(
p, Aig_ObjFanin0(pObjLi) );
381 return Aig_Gla1AddConst(
p->pSat, Aig_Gla1FetchVar(
p, pObj, k), 1 );
383 return Aig_Gla1AddBuffer(
p->pSat, Aig_Gla1FetchVar(
p, pObj, k),
384 Aig_Gla1FetchVar(
p, Aig_ObjFanin0(pObjLi), k-1),
385 Aig_ObjFaninC0(pObjLi) );
391 assert( Aig_ObjIsNode(pObj) );
392 if (
p->vObj2Cnf == NULL )
393 return Aig_Gla1AddNode(
p->pSat, Aig_Gla1FetchVar(
p, pObj, k),
394 Aig_Gla1FetchVar(
p, Aig_ObjFanin0(pObj), k),
395 Aig_Gla1FetchVar(
p, Aig_ObjFanin1(pObj), k),
396 Aig_ObjFaninC0(pObj), Aig_ObjFaninC1(pObj) );
399 vClauses = (
Vec_Int_t *)Vec_PtrEntry(
p->vObj2Cnf, Aig_ObjId(pObj) );
400 if ( vClauses == NULL )
402 Vec_PtrWriteEntry(
p->vObj2Cnf, Aig_ObjId(pObj), (vClauses = Vec_IntAlloc(16)) );
408 Aig_Gla1FetchVar(
p, pObj, k );
410 assert( Vec_IntSize(vClauses) >= 2 );
411 assert( Vec_IntEntry(vClauses, 0) == 0 );
416 Vec_IntClear(
p->vLits );
419 Vec_IntPush(
p->vLits, (Entry & 1) ^ (2 * Aig_Gla1FetchVar(
p, Aig_ManObj(
p->pAig, Entry >> 1), k)) );
420 if ( i == Vec_IntSize(vClauses) - 1 || Vec_IntEntry(vClauses, i+1) == 0 )
450 pObj = Aig_ManObj(
p->pAig, i );
451 Aig_Gla1FetchVecId(
p, pObj );
452 if ( Aig_ObjIsNode(pObj) )
454 Aig_Gla1FetchVecId(
p, Aig_ObjFanin0(pObj) );
455 Aig_Gla1FetchVecId(
p, Aig_ObjFanin1(pObj) );
457 else if ( Saig_ObjIsLo(
p->pAig, pObj) )
458 Aig_Gla1FetchVecId(
p, Aig_ObjFanin0(Saig_ObjLoToLi(
p->pAig, pObj)) );
459 else assert( Aig_ObjIsConst1(pObj) );
484 p->vObj2Vec = Vec_IntStart( Aig_ManObjNumMax(pAig) );
485 p->vVec2Var = Vec_IntAlloc( 1 << 20 );
486 p->vVar2Inf = Vec_IntAlloc( 1 << 20 );
489 for ( i = 0; i <
p->nFrames; i++ )
490 Vec_IntPush(
p->vVec2Var, -1 );
492 Vec_IntPush(
p->vVar2Inf, -1 );
493 Vec_IntPush(
p->vVar2Inf, -1 );
496 p->vAssigned = Vec_IntAlloc( 1000 );
497 if ( vGateClassesOld )
499 p->vIncluded = Vec_IntDup( vGateClassesOld );
504 p->vIncluded = Vec_IntStart( Aig_ManObjNumMax(pAig) );
507 p->vPis = Vec_IntAlloc( 1000 );
508 p->vPPis = Vec_IntAlloc( 1000 );
509 p->vFlops = Vec_IntAlloc( 1000 );
510 p->vNodes = Vec_IntAlloc( 1000 );
515 p->vLeaves = Vec_PtrAlloc( 100 );
516 p->vVolume = Vec_PtrAlloc( 100 );
517 p->vCover = Vec_IntAlloc( 1 << 16 );
518 p->vObj2Cnf = Vec_PtrStart( Aig_ManObjNumMax(pAig) );
519 p->vLits = Vec_IntAlloc( 100 );
543 Vec_IntFreeP( &
p->vObj2Vec );
544 Vec_IntFreeP( &
p->vVec2Var );
545 Vec_IntFreeP( &
p->vVar2Inf );
547 Vec_IntFreeP( &
p->vAssigned );
548 Vec_IntFreeP( &
p->vIncluded );
550 Vec_IntFreeP( &
p->vPis );
551 Vec_IntFreeP( &
p->vPPis );
552 Vec_IntFreeP( &
p->vFlops );
553 Vec_IntFreeP( &
p->vNodes );
557 Vec_PtrFreeP( &
p->vLeaves );
558 Vec_PtrFreeP( &
p->vVolume );
559 Vec_IntFreeP( &
p->vCover );
561 Vec_IntFreeP( &
p->vLits );
585 int i, f, iVecId, iSatId;
586 pCex =
Abc_CexAlloc( Vec_IntSize(
p->vFlops), Vec_IntSize(
p->vPis) + Vec_IntSize(
p->vPPis), iFrame+1 );
587 pCex->iFrame = iFrame;
590 iVecId = Vec_IntEntry(
p->vObj2Vec, Aig_ObjId(pObj) );
592 for ( f = 0; f <= iFrame; f++ )
594 iSatId = Vec_IntEntry(
p->vVec2Var, iVecId *
p->nFrames + f );
598 if ( sat_solver_var_value(
p->pSat, iSatId) )
599 Abc_InfoSetBit( pCex->pData, pCex->nRegs + f * pCex->nPis + i );
604 iVecId = Vec_IntEntry(
p->vObj2Vec, Aig_ObjId(pObj) );
606 for ( f = 0; f <= iFrame; f++ )
608 iSatId = Vec_IntEntry(
p->vVec2Var, iVecId *
p->nFrames + f );
612 if ( sat_solver_var_value(
p->pSat, iSatId) )
613 Abc_InfoSetBit( pCex->pData, pCex->nRegs + f * pCex->nPis + Vec_IntSize(
p->vPis) + i );
633 printf(
"== %3d ==", f );
636 printf(
" %4d PI =%6d PPI =%6d FF =%6d Node =%6d Var =%7d Conf =%6d\n",
637 r, Vec_IntSize(
p->vPis), Vec_IntSize(
p->vPPis), Vec_IntSize(
p->vFlops), Vec_IntSize(
p->vNodes), v, c );
657 if ( !Vec_IntEntry(
p->vIncluded, i ) )
662 assert( Aig_ObjId(pObj) <= i );
663 Vec_IntWriteEntry(
p->vIncluded, Aig_ObjId(pObj), 1 );
689 int f, g, r, i, iSatVar, Lit, Entry, RetValue;
690 int nConfBef, nConfAft;
691 clock_t clk, clkTotal = clock();
692 clock_t nTimeToStop = TimeLimit ? TimeLimit * CLOCKS_PER_SEC + clock(): 0;
693 assert( Saig_ManPoNum(pAig) == 1 );
695 if ( nFramesMax == 0 )
701 printf(
"Abstracting from frame %d to frame %d with timeout %d sec.\n", nStart, nFramesMax, TimeLimit );
703 printf(
"Abstracting from frame %d to frame %d with no timeout.\n", nStart, nFramesMax );
708 p->nFramesMax = nFramesMax;
709 p->nConfLimit = nConfLimit;
710 p->fVerbose = fVerbose;
713 Vec_IntWriteEntry(
p->vIncluded, 0, 1 );
714 Aig_Gla1FetchVecId(
p, Aig_ManConst1(pAig) );
718 sat_solver_set_runtime_limit(
p->pSat, nTimeToStop );
721 for ( f = 0; f < nFramesMax; f++ )
725 if ( Vec_IntEntry(
p->vIncluded, Aig_ObjId(pObj)) )
727 printf(
"Error! SAT solver became UNSAT.\n" );
734 pObj = Aig_ManCo( pAig, 0 );
735 iSatVar = Aig_Gla1FetchVar(
p, Aig_ObjFanin0(pObj), f );
736 Lit = toLitCond( iSatVar, Aig_ObjFaninC0(pObj) );
744 nConfBef =
p->pSat->stats.conflicts;
746 (ABC_INT64_T)nConfLimit, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
747 nConfAft =
p->pSat->stats.conflicts;
748 p->timeSat += clock() - clk;
754 printf(
"== %3d ==", f );
757 if ( TimeLimit && clock() > nTimeToStop )
758 printf(
" SAT solver timed out after %d seconds.\n", TimeLimit );
759 else if ( RetValue !=
l_False )
760 printf(
" SAT solver returned UNDECIDED after %5d conflicts.\n", nConfAft - nConfBef );
763 printf(
" SAT solver returned UNSAT after %5d conflicts. ", nConfAft - nConfBef );
764 Abc_PrintTime( 1,
"Total time", clock() - clkTotal );
777 printf(
"Error! CEX is invalid.\n" );
782 pObj = Aig_ManObj( pAig, Vec_IntEntry(
p->vPPis, Entry) );
783 assert( Aig_ObjIsNode(pObj) || Saig_ObjIsLo(
p->pAig, pObj) );
784 assert( Vec_IntEntry(
p->vIncluded, Aig_ObjId(pObj) ) == 0 );
785 Vec_IntWriteEntry(
p->vIncluded, Aig_ObjId(pObj), 1 );
786 for ( g = 0; g <= f; g++ )
788 printf(
"Error! SAT solver became UNSAT.\n" );
790 if ( Vec_IntSize(vPPiRefine) == 0 )
792 Vec_IntFreeP( &
p->vIncluded );
793 Vec_IntFree( vPPiRefine );
798 Vec_IntFree( vPPiRefine );
801 p->timeRef += clock() - clk;
811 p->timeTotal = clock() - clkTotal;
812 if ( f == nFramesMax )
813 printf(
"Finished %d frames without exceeding conflict limit (%d).\n", f, nConfLimit );
814 else if (
p->vIncluded == NULL )
815 printf(
"The problem is SAT in frame %d. The CEX is currently not produced.\n", f );
817 printf(
"Ran out of conflict limit (%d) at frame %d.\n", nConfLimit, f );
824 ABC_PRTP(
"Total ",
p->timeTotal,
p->timeTotal );
827 if ( !fNaiveCnf &&
p->vIncluded )
829 vResult =
p->vIncluded;
p->vIncluded = NULL;
#define ABC_PRTP(a, t, T)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Vec_Int_t * Saig_ManCbaFilterInputs(Aig_Man_t *pAig, int iFirstFlopPi, Abc_Cex_t *pCex, int fVerbose)
void Aig_ManSetRegNum(Aig_Man_t *p, int nRegs)
void Aig_ManCleanMarkA(Aig_Man_t *p)
void Aig_ManStop(Aig_Man_t *p)
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Aig_Obj_t * Aig_ObjCreateCo(Aig_Man_t *p, Aig_Obj_t *pDriver)
struct Aig_Obj_t_ Aig_Obj_t
Aig_Man_t * Aig_ManStart(int nNodesMax)
DECLARATIONS ///.
#define Aig_ManForEachNode(p, pObj, i)
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
int Aig_ManCleanup(Aig_Man_t *p)
Aig_Obj_t * Aig_ObjCreateCi(Aig_Man_t *p)
DECLARATIONS ///.
#define Aig_ManForEachObjVec(vIds, p, pObj, i)
void Aig_ManCleanData(Aig_Man_t *p)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
#define sat_solver_addclause
void Cnf_ComputeClauses(Aig_Man_t *p, Aig_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vNodes, Vec_Int_t *vMap, Vec_Int_t *vCover, Vec_Int_t *vClauses)
void Cnf_CollectLeaves(Aig_Obj_t *pRoot, Vec_Ptr_t *vSuper, int fStopCompl)
void Cnf_DeriveFastMark(Aig_Man_t *p)
void Aig_Gla1CollectAssigned(Aig_Gla1Man_t *p, Vec_Int_t *vGateClasses)
typedefABC_NAMESPACE_IMPL_START struct Aig_Gla1Man_t_ Aig_Gla1Man_t
DECLARATIONS ///.
int Aig_Gla1ObjAddToSolver(Aig_Gla1Man_t *p, Aig_Obj_t *pObj, int k)
Aig_Gla1Man_t * Aig_Gla1ManStart(Aig_Man_t *pAig, Vec_Int_t *vGateClassesOld, int fNaiveCnf)
void Aig_Gla1CollectAbstr(Aig_Gla1Man_t *p)
Aig_Man_t * Aig_Gla1DeriveAbs(Aig_Gla1Man_t *p)
void Aig_Gla1DeriveAbs_rec(Aig_Man_t *pNew, Aig_Obj_t *pObj)
Abc_Cex_t * Aig_Gla1DeriveCex(Aig_Gla1Man_t *p, int iFrame)
Vec_Int_t * Aig_Gla1ManPerform(Aig_Man_t *pAig, Vec_Int_t *vGateClassesOld, int nStart, int nFramesMax, int nConfLimit, int TimeLimit, int fNaiveCnf, int fVerbose, int *piFrame)
void Aig_Gla1ExtendIncluded(Aig_Gla1Man_t *p)
void Aig_Gla1ManStop(Aig_Gla1Man_t *p)
void Aig_Gla1PrintAbstr(Aig_Gla1Man_t *p, int f, int r, int v, int c)
#define Saig_ManForEachPo(p, pObj, i)
int Saig_ManVerifyCex(Aig_Man_t *pAig, Abc_Cex_t *p)
sat_solver * sat_solver_new(void)
void sat_solver_setnvars(sat_solver *s, int n)
void sat_solver_delete(sat_solver *s)
void Abc_CexFree(Abc_Cex_t *p)
ABC_NAMESPACE_IMPL_START Abc_Cex_t * Abc_CexAlloc(int nRegs, int nRealPis, int nFrames)
DECLARATIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryReverse(vVec, pEntry, i)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.