90static inline int Cbs_VarIsAssigned(
Gia_Obj_t * pVar ) {
return pVar->
fMark0; }
95static inline int Cbs_VarIsJust(
Gia_Obj_t * pVar ) {
return Gia_ObjIsAnd(pVar) && !Cbs_VarIsAssigned(Gia_ObjFanin0(pVar)) && !Cbs_VarIsAssigned(Gia_ObjFanin1(pVar)); }
96static inline int Cbs_VarFanin0Value(
Gia_Obj_t * pVar ) {
return !Cbs_VarIsAssigned(Gia_ObjFanin0(pVar)) ? 2 : (Cbs_VarValue(Gia_ObjFanin0(pVar)) ^ Gia_ObjFaninC0(pVar)); }
97static inline int Cbs_VarFanin1Value(
Gia_Obj_t * pVar ) {
return !Cbs_VarIsAssigned(Gia_ObjFanin1(pVar)) ? 2 : (Cbs_VarValue(Gia_ObjFanin1(pVar)) ^ Gia_ObjFaninC1(pVar)); }
102static inline int Cbs_ClauseDecLevel(
Cbs_Man_t *
p,
int hClause ) {
return Cbs_VarDecLevel(
p,
p->pClauses.pData[hClause] ); }
104#define Cbs_QueForEachEntry( Que, pObj, i ) \
105 for ( i = (Que).iHead; (i < (Que).iTail) && ((pObj) = (Que).pData[i]); i++ )
107#define Cbs_ClauseForEachVar( p, hClause, pObj ) \
108 for ( (p)->pIter = (p)->pClauses.pData + hClause; (pObj = *pIter); (p)->pIter++ )
109#define Cbs_ClauseForEachVar1( p, hClause, pObj ) \
110 for ( (p)->pIter = (p)->pClauses.pData+hClause+1; (pObj = *pIter); (p)->pIter++ )
130 pPars->nBTLimit = 1000;
131 pPars->nJustLimit = 100;
132 pPars->fUseHighest = 1;
133 pPars->fUseLowest = 0;
134 pPars->fUseMaxFF = 0;
139 p->Pars.nBTLimit = Num;
157 p->pProp.nSize =
p->pJust.nSize =
p->pClauses.nSize = 10000;
161 p->pClauses.iHead =
p->pClauses.iTail = 1;
162 p->vModel = Vec_IntAlloc( 1000 );
163 p->vLevReas = Vec_IntAlloc( 1000 );
164 p->vTemp = Vec_PtrAlloc( 1000 );
183 Vec_IntFree(
p->vLevReas );
184 Vec_IntFree(
p->vModel );
185 Vec_PtrFree(
p->vTemp );
222static inline int Cbs_ManCheckLimits(
Cbs_Man_t *
p )
224 return p->Pars.nJustThis >
p->Pars.nJustLimit ||
p->Pars.nBTThis >
p->Pars.nBTLimit;
242 Vec_IntClear( vCex );
245 if ( Gia_ObjIsCi(pVar) )
247 Vec_IntPush( vCex, Abc_Var2Lit(Gia_ObjCioId(pVar), !Cbs_VarValue(pVar)) );
253 Vec_IntClear( vCex );
256 Vec_IntPush( vCex, Abc_Var2Lit(Gia_ObjId(
p->pAig,pVar), !Cbs_VarValue(pVar)) );
270static inline int Cbs_QueIsEmpty(
Cbs_Que_t *
p )
272 return p->iHead ==
p->iTail;
288 assert( !Gia_IsComplement(pObj) );
289 if (
p->iTail ==
p->nSize )
294 p->pData[
p->iTail++] = pObj;
329static inline void Cbs_QueStore(
Cbs_Que_t *
p,
int * piHeadOld,
int * piTailOld )
332 *piHeadOld =
p->iHead;
333 *piTailOld =
p->iTail;
334 for ( i = *piHeadOld; i < *piTailOld; i++ )
335 Cbs_QuePush(
p,
p->pData[i] );
336 p->iHead = *piTailOld;
350static inline void Cbs_QueRestore(
Cbs_Que_t *
p,
int iHeadOld,
int iTailOld )
367static inline int Cbs_QueFinish(
Cbs_Que_t *
p )
369 int iHeadOld =
p->iHead;
371 Cbs_QuePush(
p, NULL );
391 assert( !Gia_IsComplement(pObj) );
392 assert( Gia_ObjIsAnd(pObj) );
393 Count0 = Gia_ObjRefNum(
p->pAig, Gia_ObjFanin0(pObj) );
394 Count1 = Gia_ObjRefNum(
p->pAig, Gia_ObjFanin1(pObj) );
395 return Abc_MaxInt( Count0, Count1 );
414 if ( pObjMax == NULL || pObjMax < pObj )
435 if ( pObjMin == NULL || pObjMin > pObj )
454 int i, iMaxFF = 0, iCurFF;
455 assert(
p->pAig->pRefs != NULL );
458 iCurFF = Cbs_VarFaninFanoutMax(
p, pObj );
460 if ( iMaxFF < iCurFF )
482static inline void Cbs_ManCancelUntil(
Cbs_Man_t *
p,
int iBound )
486 assert( iBound <= p->pProp.iTail );
487 p->pProp.iHead = iBound;
489 Cbs_VarUnassign( pVar );
490 p->pProp.iTail = iBound;
491 Vec_IntShrink(
p->vLevReas, 3*iBound );
510 assert( Gia_ObjIsCand(pObjR) );
511 assert( !Cbs_VarIsAssigned(pObjR) );
512 Cbs_VarAssign( pObjR );
513 Cbs_VarSetValue( pObjR, !Gia_IsComplement(pObj) );
515 pObjR->
Value =
p->pProp.iTail;
516 Cbs_QuePush( &
p->pProp, pObjR );
517 Vec_IntPush(
p->vLevReas, Level );
518 Vec_IntPush(
p->vLevReas, pRes0 ? pRes0-pObjR : 0 );
519 Vec_IntPush(
p->vLevReas, pRes1 ? pRes1-pObjR : 0 );
520 assert( Vec_IntSize(
p->vLevReas) == 3 *
p->pProp.iTail );
537static inline int Cbs_ManClauseSize(
Cbs_Man_t *
p,
int hClause )
541 for ( pIter = pQue->
pData + hClause; *pIter; pIter++ );
542 return pIter - pQue->
pData - hClause ;
556static inline void Cbs_ManPrintClause(
Cbs_Man_t *
p,
int Level,
int hClause )
561 assert( Cbs_QueIsEmpty( pQue ) );
562 printf(
"Level %2d : ", Level );
563 for ( i = hClause; (pObj = pQue->
pData[i]); i++ )
564 printf(
"%d=%d(%d) ", Gia_ObjId(
p->pAig, pObj), Cbs_VarValue(pObj), Cbs_VarDecLevel(
p, pObj) );
579static inline void Cbs_ManPrintClauseNew(
Cbs_Man_t *
p,
int Level,
int hClause )
584 assert( Cbs_QueIsEmpty( pQue ) );
585 printf(
"Level %2d : ", Level );
586 for ( i = hClause; (pObj = pQue->
pData[i]); i++ )
587 printf(
"%c%d ", Cbs_VarValue(pObj)?
'+':
'-', Gia_ObjId(
p->pAig, pObj) );
602static inline void Cbs_ManDeriveReason(
Cbs_Man_t *
p,
int Level )
617 Vec_PtrClear(
p->vTemp );
618 for ( i = k = pQue->
iHead + 1; i < pQue->iTail; i++ )
620 pObj = pQue->
pData[i];
625 Vec_PtrPush(
p->vTemp, pObj );
627 iLitLevel = Cbs_VarDecLevel(
p, pObj );
628 if ( iLitLevel < Level )
630 pQue->
pData[k++] = pObj;
633 assert( iLitLevel == Level );
634 pReason = Cbs_VarReason0(
p, pObj );
635 if ( pReason == pObj )
641 Cbs_QuePush( pQue, pReason );
642 pReason = Cbs_VarReason1(
p, pObj );
643 if ( pReason != pObj )
644 Cbs_QuePush( pQue, pReason );
667 assert( Cbs_VarIsAssigned(pVar) );
668 assert( Cbs_VarIsAssigned(pFan0) );
669 assert( pFan1 == NULL || Cbs_VarIsAssigned(pFan1) );
670 assert( Cbs_QueIsEmpty( pQue ) );
671 Cbs_QuePush( pQue, NULL );
672 Cbs_QuePush( pQue, pVar );
673 Cbs_QuePush( pQue, pFan0 );
675 Cbs_QuePush( pQue, pFan1 );
676 Cbs_ManDeriveReason(
p, Level );
677 return Cbs_QueFinish( pQue );
692static inline int Cbs_ManResolve(
Cbs_Man_t *
p,
int Level,
int hClause0,
int hClause1 )
696 int i, LevelMax = -1, LevelCur;
705 assert( Cbs_QueIsEmpty( pQue ) );
706 Cbs_QuePush( pQue, NULL );
707 for ( i = hClause0 + 1; (pObj = pQue->
pData[i]); i++ )
713 Cbs_QuePush( pQue, pObj );
714 LevelCur = Cbs_VarDecLevel(
p, pObj );
715 if ( LevelMax < LevelCur )
718 for ( i = hClause1 + 1; (pObj = pQue->
pData[i]); i++ )
724 Cbs_QuePush( pQue, pObj );
725 LevelCur = Cbs_VarDecLevel(
p, pObj );
726 if ( LevelMax < LevelCur )
729 for ( i = pQue->
iHead + 1; i < pQue->iTail; i++ )
731 Cbs_ManDeriveReason(
p, LevelMax );
732 return Cbs_QueFinish( pQue );
749 assert( !Gia_IsComplement(pVar) );
750 assert( Cbs_VarIsAssigned(pVar) );
751 if ( Gia_ObjIsCi(pVar) )
753 assert( Gia_ObjIsAnd(pVar) );
754 Value0 = Cbs_VarFanin0Value(pVar);
755 Value1 = Cbs_VarFanin1Value(pVar);
756 if ( Cbs_VarValue(pVar) )
758 if ( Value0 == 0 || Value1 == 0 )
760 if ( Value0 == 0 && Value1 != 0 )
761 return Cbs_ManAnalyze(
p, Level, pVar, Gia_ObjFanin0(pVar), NULL );
762 if ( Value0 != 0 && Value1 == 0 )
763 return Cbs_ManAnalyze(
p, Level, pVar, Gia_ObjFanin1(pVar), NULL );
764 assert( Value0 == 0 && Value1 == 0 );
765 return Cbs_ManAnalyze(
p, Level, pVar, Gia_ObjFanin0(pVar), Gia_ObjFanin1(pVar) );
768 Cbs_ManAssign(
p, Gia_ObjChild0(pVar), Level, pVar, NULL );
770 Cbs_ManAssign(
p, Gia_ObjChild1(pVar), Level, pVar, NULL );
774 if ( Value0 == 0 || Value1 == 0 )
776 if ( Value0 == 1 && Value1 == 1 )
777 return Cbs_ManAnalyze(
p, Level, pVar, Gia_ObjFanin0(pVar), Gia_ObjFanin1(pVar) );
778 if ( Value0 == 1 || Value1 == 1 )
781 Cbs_ManAssign(
p, Gia_Not(Gia_ObjChild0(pVar)), Level, pVar, Gia_ObjFanin1(pVar) );
783 Cbs_ManAssign(
p, Gia_Not(Gia_ObjChild1(pVar)), Level, pVar, Gia_ObjFanin0(pVar) );
786 assert( Cbs_VarIsJust(pVar) );
787 assert( !Cbs_QueHasNode( &
p->pJust, pVar ) );
788 Cbs_QuePush( &
p->pJust, pVar );
806 assert( !Gia_IsComplement(pVar) );
807 assert( Gia_ObjIsAnd(pVar) );
808 assert( Cbs_VarIsAssigned(pVar) );
809 assert( !Cbs_VarValue(pVar) );
810 Value0 = Cbs_VarFanin0Value(pVar);
811 Value1 = Cbs_VarFanin1Value(pVar);
813 if ( Value0 == 0 || Value1 == 0 )
815 if ( Value0 == 1 && Value1 == 1 )
816 return Cbs_ManAnalyze(
p, Level, pVar, Gia_ObjFanin0(pVar), Gia_ObjFanin1(pVar) );
817 assert( Value0 == 1 || Value1 == 1 );
819 Cbs_ManAssign(
p, Gia_Not(Gia_ObjChild0(pVar)), Level, pVar, Gia_ObjFanin1(pVar) );
821 Cbs_ManAssign(
p, Gia_Not(Gia_ObjChild1(pVar)), Level, pVar, Gia_ObjFanin0(pVar) );
845 if ( (hClause = Cbs_ManPropagateOne(
p, pVar, Level )) )
848 p->pProp.iHead =
p->pProp.iTail;
852 if ( Cbs_VarIsJust( pVar ) )
853 p->pJust.pData[k++] = pVar;
854 else if ( (hClause = Cbs_ManPropagateTwo(
p, pVar, Level )) )
857 if ( k ==
p->pJust.iTail )
879 int hClause, hLearn0, hLearn1;
880 int iPropHead, iJustHead, iJustTail;
882 assert( !Cbs_QueIsEmpty(&
p->pProp) );
886 assert( Cbs_QueIsEmpty(&
p->pProp) );
887 if ( Cbs_QueIsEmpty(&
p->pJust) )
890 p->Pars.nJustThis = Abc_MaxInt(
p->Pars.nJustThis,
p->pJust.iTail -
p->pJust.iHead );
891 if ( Cbs_ManCheckLimits(
p ) )
894 iPropHead =
p->pProp.iHead;
895 Cbs_QueStore( &
p->pJust, &iJustHead, &iJustTail );
897 if (
p->Pars.fUseHighest )
898 pVar = Cbs_ManDecideHighest(
p );
899 else if (
p->Pars.fUseLowest )
900 pVar = Cbs_ManDecideLowest(
p );
901 else if (
p->Pars.fUseMaxFF )
902 pVar = Cbs_ManDecideMaxFF(
p );
904 assert( Cbs_VarIsJust( pVar ) );
906 if ( Gia_ObjRefNum(
p->pAig, Gia_ObjFanin0(pVar)) > Gia_ObjRefNum(
p->pAig, Gia_ObjFanin1(pVar)) )
907 pDecVar = Gia_Not(Gia_ObjChild0(pVar));
909 pDecVar = Gia_Not(Gia_ObjChild1(pVar));
913 Cbs_ManAssign(
p, pDecVar, Level+1, NULL, NULL );
916 if ( pQue->
pData[hLearn0] != Gia_Regular(pDecVar) )
918 Cbs_ManCancelUntil(
p, iPropHead );
919 Cbs_QueRestore( &
p->pJust, iJustHead, iJustTail );
921 Cbs_ManAssign(
p, Gia_Not(pDecVar), Level+1, NULL, NULL );
924 if ( pQue->
pData[hLearn1] != Gia_Regular(pDecVar) )
926 hClause = Cbs_ManResolve(
p, Level, hLearn0, hLearn1 );
951 assert( !
p->pProp.iHead && !
p->pProp.iTail );
952 assert( !
p->pJust.iHead && !
p->pJust.iTail );
953 assert(
p->pClauses.iHead == 1 &&
p->pClauses.iTail == 1 );
954 p->Pars.nBTThis =
p->Pars.nJustThis =
p->Pars.nBTThisNc = 0;
955 Cbs_ManAssign(
p, pObj, 0, NULL, NULL );
957 Cbs_ManSaveModel(
p,
p->vModel );
960 Cbs_ManCancelUntil(
p, 0 );
961 p->pJust.iHead =
p->pJust.iTail = 0;
962 p->pClauses.iHead =
p->pClauses.iTail = 1;
963 p->Pars.nBTTotal +=
p->Pars.nBTThis;
964 p->Pars.nJustTotal = Abc_MaxInt(
p->Pars.nJustTotal,
p->Pars.nJustThis );
965 if ( Cbs_ManCheckLimits(
p ) )
974 assert( !
p->pProp.iHead && !
p->pProp.iTail );
975 assert( !
p->pJust.iHead && !
p->pJust.iTail );
976 assert(
p->pClauses.iHead == 1 &&
p->pClauses.iTail == 1 );
977 p->Pars.nBTThis =
p->Pars.nJustThis =
p->Pars.nBTThisNc = 0;
978 Cbs_ManAssign(
p, pObj, 0, NULL, NULL );
980 Cbs_ManAssign(
p, pObj2, 0, NULL, NULL );
982 Cbs_ManSaveModelAll(
p,
p->vModel );
985 Cbs_ManCancelUntil(
p, 0 );
986 p->pJust.iHead =
p->pJust.iTail = 0;
987 p->pClauses.iHead =
p->pClauses.iTail = 1;
988 p->Pars.nBTTotal +=
p->Pars.nBTThis;
989 p->Pars.nJustTotal = Abc_MaxInt(
p->Pars.nJustTotal,
p->Pars.nJustThis );
990 if ( Cbs_ManCheckLimits(
p ) )
1009 printf(
"CO = %8d ", Gia_ManCoNum(
p->pAig) );
1010 printf(
"AND = %8d ", Gia_ManAndNum(
p->pAig) );
1011 printf(
"Conf = %6d ",
p->Pars.nBTLimit );
1012 printf(
"JustMax = %5d ",
p->Pars.nJustLimit );
1014 printf(
"Unsat calls %6d (%6.2f %%) Ave conf = %8.1f ",
1015 p->nSatUnsat,
p->nSatTotal? 100.0*
p->nSatUnsat/
p->nSatTotal :0.0,
p->nSatUnsat? 1.0*
p->nConfUnsat/
p->nSatUnsat :0.0 );
1016 ABC_PRTP(
"Time",
p->timeSatUnsat,
p->timeTotal );
1017 printf(
"Sat calls %6d (%6.2f %%) Ave conf = %8.1f ",
1018 p->nSatSat,
p->nSatTotal? 100.0*
p->nSatSat/
p->nSatTotal :0.0,
p->nSatSat? 1.0*
p->nConfSat/
p->nSatSat : 0.0 );
1019 ABC_PRTP(
"Time",
p->timeSatSat,
p->timeTotal );
1020 printf(
"Undef calls %6d (%6.2f %%) Ave conf = %8.1f ",
1021 p->nSatUndec,
p->nSatTotal? 100.0*
p->nSatUndec/
p->nSatTotal :0.0,
p->nSatUndec? 1.0*
p->nConfUndec/
p->nSatUndec : 0.0 );
1022 ABC_PRTP(
"Time",
p->timeSatUndec,
p->timeTotal );
1023 ABC_PRT(
"Total time",
p->timeTotal );
1042 Vec_Int_t * vCex, * vVisit, * vCexStore;
1046 abctime clk, clkTotal = Abc_Clock();
1047 assert( Gia_ManRegNum(pAig) == 0 );
1057 p->Pars.nBTLimit = nConfs;
1059 vStatus = Vec_StrAlloc( Gia_ManPoNum(pAig) );
1060 vCexStore = Vec_IntAlloc( 10000 );
1061 vVisit = Vec_IntAlloc( 100 );
1068 Vec_IntClear( vCex );
1069 if ( Gia_ObjIsConst0(Gia_ObjFanin0(pRoot)) )
1071 if ( Gia_ObjFaninC0(pRoot) )
1075 Vec_StrPush( vStatus, 0 );
1080 Vec_StrPush( vStatus, 1 );
1085 p->Pars.fUseHighest = 1;
1086 p->Pars.fUseLowest = 0;
1097 Vec_StrPush( vStatus, (
char)status );
1101 p->nConfUndec +=
p->Pars.nBTThis;
1103 p->timeSatUndec += Abc_Clock() - clk;
1109 Gia_ManPatchCoDriver( pAig, i, 0 );
1111 p->nConfUnsat +=
p->Pars.nBTThis;
1112 p->timeSatUnsat += Abc_Clock() - clk;
1116 p->nConfSat +=
p->Pars.nBTThis;
1119 p->timeSatSat += Abc_Clock() - clk;
1121 Vec_IntFree( vVisit );
1122 p->nSatTotal = Gia_ManPoNum(pAig);
1123 p->timeTotal = Abc_Clock() - clkTotal;
1128 *pvStatus = vStatus;
#define ABC_ALLOC(type, num)
#define ABC_PRTP(a, t, T)
#define ABC_REALLOC(type, obj, num)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct Vec_Str_t_ Vec_Str_t
void Cec_ManSatAddToStore(Vec_Int_t *vCexStore, Vec_Int_t *vCex, int Out)
int Cbs_ManPropagate(Cbs_Man_t *p, int Level)
void Cbs_ManSatPrintStats(Cbs_Man_t *p)
int Cbs_ManSolve_rec(Cbs_Man_t *p, int Level)
Cbs_Man_t * Cbs_ManAlloc(Gia_Man_t *pGia)
Vec_Int_t * Cbs_ManSolveMiterNc(Gia_Man_t *pAig, int nConfs, Vec_Str_t **pvStatus, int f0Proved, int fVerbose)
typedefABC_NAMESPACE_IMPL_START struct Cbs_Par_t_ Cbs_Par_t
DECLARATIONS ///.
int Cbs_ManSolve2(Cbs_Man_t *p, Gia_Obj_t *pObj, Gia_Obj_t *pObj2)
#define Cbs_QueForEachEntry(Que, pObj, i)
Vec_Int_t * Cbs_ReadModel(Cbs_Man_t *p)
int Cbs_ManSolve(Cbs_Man_t *p, Gia_Obj_t *pObj)
struct Cbs_Que_t_ Cbs_Que_t
void Cbs_ManSetConflictNum(Cbs_Man_t *p, int Num)
void Cbs_ManStop(Cbs_Man_t *p)
void Cbs_SetDefaultParams(Cbs_Par_t *pPars)
FUNCTION DEFINITIONS ///.
void Gia_ManCollectTest(Gia_Man_t *p)
struct Cbs_Man_t_ Cbs_Man_t
struct Gia_Obj_t_ Gia_Obj_t
void Gia_ManFillValue(Gia_Man_t *p)
struct Gia_Man_t_ Gia_Man_t
void Gia_ManCleanMark0(Gia_Man_t *p)
void Gia_ManCreateRefs(Gia_Man_t *p)
#define Gia_ManForEachCo(p, pObj, i)
void Gia_ManSetPhase(Gia_Man_t *p)
void Gia_ManCleanMark1(Gia_Man_t *p)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.