103static inline int Cbs3_VarUnused(
Cbs3_Man_t *
p,
int iVar ) {
return Vec_IntEntry(&
p->vLevReason, 3*iVar) == -1; }
104static inline void Cbs3_VarSetUnused(
Cbs3_Man_t *
p,
int iVar ) { Vec_IntWriteEntry(&
p->vLevReason, 3*iVar, -1); }
106static inline int Cbs3_VarMark0(
Cbs3_Man_t *
p,
int iVar ) {
return Vec_StrEntry(&
p->vMark, iVar); }
107static inline void Cbs3_VarSetMark0(
Cbs3_Man_t *
p,
int iVar,
int Value ) { Vec_StrWriteEntry(&
p->vMark, iVar, (
char)Value); }
109static inline int Cbs3_VarIsAssigned(
Cbs3_Man_t *
p,
int iVar ) {
return Vec_StrEntry(&
p->vAssign, iVar) < 2; }
110static inline void Cbs3_VarUnassign(
Cbs3_Man_t *
p,
int iVar ) {
assert( Cbs3_VarIsAssigned(
p, iVar)); Vec_StrWriteEntry(&
p->vAssign, iVar, (
char)(2+Vec_StrEntry(&
p->vAssign, iVar))); Cbs3_VarSetUnused(
p, iVar); }
112static inline int Cbs3_VarValue(
Cbs3_Man_t *
p,
int iVar ) {
return Vec_StrEntry(&
p->vAssign, iVar); }
113static inline void Cbs3_VarSetValue(
Cbs3_Man_t *
p,
int iVar,
int v ) {
assert( !Cbs3_VarIsAssigned(
p, iVar)); Vec_StrWriteEntry(&
p->vAssign, iVar, (
char)v); }
115static inline int Cbs3_VarLit0(
Cbs3_Man_t *
p,
int iVar ) {
return Vec_IntEntry( &
p->vFans, Abc_Var2Lit(iVar, 0) ); }
116static inline int Cbs3_VarLit1(
Cbs3_Man_t *
p,
int iVar ) {
return Vec_IntEntry( &
p->vFans, Abc_Var2Lit(iVar, 1) ); }
117static inline int Cbs3_VarIsPi(
Cbs3_Man_t *
p,
int iVar ) {
return Vec_IntEntry( &
p->vFans, Abc_Var2Lit(iVar, 0) ) == 0; }
118static inline int Cbs3_VarIsJust(
Cbs3_Man_t *
p,
int iVar ) {
int * pLits = Vec_IntEntryP(&
p->vFans, Abc_Var2Lit(iVar, 0));
return pLits[0] > 0 && Cbs3_VarValue(
p, Abc_Lit2Var(pLits[0])) >= 2 && Cbs3_VarValue(
p, Abc_Lit2Var(pLits[1])) >= 2; }
120static inline int Cbs3_VarDecLevel(
Cbs3_Man_t *
p,
int iVar ) {
assert( !Cbs3_VarUnused(
p, iVar) );
return Vec_IntEntry(&
p->vLevReason, 3*iVar); }
121static inline int Cbs3_VarReason0(
Cbs3_Man_t *
p,
int iVar ) {
assert( !Cbs3_VarUnused(
p, iVar) );
return Vec_IntEntry(&
p->vLevReason, 3*iVar+1); }
122static inline int Cbs3_VarReason1(
Cbs3_Man_t *
p,
int iVar ) {
assert( !Cbs3_VarUnused(
p, iVar) );
return Vec_IntEntry(&
p->vLevReason, 3*iVar+2); }
123static inline int * Cbs3_VarReasonP(
Cbs3_Man_t *
p,
int iVar ) {
assert( !Cbs3_VarUnused(
p, iVar) );
return Vec_IntEntryP(&
p->vLevReason, 3*iVar+1); }
124static inline int Cbs3_ClauseDecLevel(
Cbs3_Man_t *
p,
int hClause ) {
return Cbs3_VarDecLevel(
p,
p->pClauses.pData[hClause] ); }
126static inline int Cbs3_ClauseSize(
Cbs3_Man_t *
p,
int hClause ) {
return p->pClauses.pData[hClause]; }
127static inline int * Cbs3_ClauseLits(
Cbs3_Man_t *
p,
int hClause ) {
return p->pClauses.pData+hClause+1; }
128static inline int Cbs3_ClauseLit(
Cbs3_Man_t *
p,
int hClause,
int i ) {
return p->pClauses.pData[hClause+1+i]; }
129static inline int * Cbs3_ClauseNext1p(
Cbs3_Man_t *
p,
int hClause ) {
return p->pClauses.pData+hClause+Cbs3_ClauseSize(
p, hClause)+2; }
131static inline void Cbs3_ClauseSetSize(
Cbs3_Man_t *
p,
int hClause,
int x ) {
p->pClauses.pData[hClause] = x; }
132static inline void Cbs3_ClauseSetLit(
Cbs3_Man_t *
p,
int hClause,
int i,
int x ) {
p->pClauses.pData[hClause+i+1] = x; }
133static inline void Cbs3_ClauseSetNext(
Cbs3_Man_t *
p,
int hClause,
int n,
int x ){
p->pClauses.pData[hClause+Cbs3_ClauseSize(
p, hClause)+1+n] = x; }
136#define Cbs3_QueForEachEntry( Que, iObj, i ) \
137 for ( i = (Que).iHead; (i < (Que).iTail) && ((iObj) = (Que).pData[i]); i++ )
139#define Cbs3_ClauseForEachEntry( p, hClause, iObj, i ) \
140 for ( i = 1; i <= Cbs3_ClauseSize(p, hClause) && (iObj = (p)->pClauses.pData[hClause+i]); i++ )
141#define Cbs3_ClauseForEachEntry1( p, hClause, iObj, i ) \
142 for ( i = 2; i <= Cbs3_ClauseSize(p, hClause) && (iObj = (p)->pClauses.pData[hClause+i]); i++ )
162 pPars->nBTLimit = 1000;
163 pPars->nJustLimit = 500;
164 pPars->nRestLimit = 10;
169 p->Pars.nBTLimit = Num;
187 p->pProp.nSize =
p->pJust.nSize =
p->pClauses.nSize = 10000;
190 p->pClauses.pData =
ABC_ALLOC(
int,
p->pClauses.nSize );
191 p->pClauses.iHead =
p->pClauses.iTail = 1;
192 p->vModel = Vec_IntAlloc( 1000 );
193 p->vTemp = Vec_IntAlloc( 1000 );
197 Vec_IntPush( &
p->vMap, -1 );
198 Vec_IntPush( &
p->vRef, -1 );
199 Vec_IntPushTwo( &
p->vFans, -1, -1 );
200 Vec_WecPushLevel( &
p->vImps );
201 Vec_WecPushLevel( &
p->vImps );
204 p->nVarsAlloc = 1000;
205 Vec_StrFill( &
p->vAssign,
p->nVarsAlloc, 2 );
206 Vec_StrFill( &
p->vMark,
p->nVarsAlloc, 0 );
207 Vec_IntFill( &
p->vLevReason, 3*
p->nVarsAlloc, -1 );
208 Vec_IntFill( &
p->vActs,
p->nVarsAlloc, 0 );
209 Vec_IntFill( &
p->vWatches, 2*
p->nVarsAlloc, 0 );
210 Vec_IntGrow( &
p->vWatchUpds, 1000 );
215 assert(
p->nVars == Vec_IntSize(&
p->vMap) );
216 Vec_IntShrink( &
p->vMap, 1 );
217 Vec_IntShrink( &
p->vRef, 1 );
218 Vec_IntShrink( &
p->vFans, 2 );
219 Vec_WecShrink( &
p->vImps, 2 );
224 if (
p->nVarsAlloc <
p->nVars )
226 p->nVarsAlloc = 2*
p->nVars;
227 Vec_StrFill( &
p->vAssign,
p->nVarsAlloc, 2 );
228 Vec_StrFill( &
p->vMark,
p->nVarsAlloc, 0 );
229 Vec_IntFill( &
p->vLevReason, 3*
p->nVarsAlloc, -1 );
230 Vec_IntFill( &
p->vActs,
p->nVarsAlloc, 0 );
231 Vec_IntFill( &
p->vWatches, 2*
p->nVarsAlloc, 0 );
249 Vec_IntErase( &
p->vMap );
250 Vec_IntErase( &
p->vRef );
251 Vec_IntErase( &
p->vFans );
252 Vec_WecErase( &
p->vImps );
254 Vec_StrErase( &
p->vAssign );
255 Vec_StrErase( &
p->vMark );
256 Vec_IntErase( &
p->vLevReason );
257 Vec_IntErase( &
p->vActs );
258 Vec_IntErase( &
p->vWatches );
259 Vec_IntErase( &
p->vWatchUpds );
260 Vec_IntFree(
p->vModel );
261 Vec_IntFree(
p->vTemp );
270 nMem += (int)Vec_IntMemory( &
p->vMap );
271 nMem += (int)Vec_IntMemory( &
p->vRef );
272 nMem += (int)Vec_IntMemory( &
p->vFans );
273 nMem += (int)Vec_WecMemory( &
p->vImps );
274 nMem += (int)Vec_StrMemory( &
p->vAssign );
275 nMem += (int)Vec_StrMemory( &
p->vMark );
276 nMem += (int)Vec_IntMemory( &
p->vActs );
277 nMem += (int)Vec_IntMemory( &
p->vWatches );
278 nMem += (int)Vec_IntMemory( &
p->vWatchUpds );
279 nMem += (int)Vec_IntMemory(
p->vModel );
280 nMem += (int)Vec_IntMemory(
p->vTemp );
281 nMem += 4*
p->pClauses.nSize;
282 nMem += 4*
p->pProp.nSize;
283 nMem += 4*
p->pJust.nSize;
320 int i, * pAct = Vec_IntArray(&
p->vActs);
321 for ( i = 0; i <
p->nVars; i++ )
323 p->var_inc = (1 << 5);
325static inline void Cbs3_ActRescale(
Cbs3_Man_t *
p )
327 int i, * pAct = Vec_IntArray(&
p->vActs);
328 for ( i = 0; i <
p->nVars; i++ )
331 p->var_inc = Abc_MaxInt( (
unsigned)
p->var_inc, (1<<5) );
333static inline void Cbs3_ActBumpVar(
Cbs3_Man_t *
p,
int iVar )
335 int * pAct = Vec_IntArray(&
p->vActs);
336 pAct[iVar] +=
p->var_inc;
337 if ((
unsigned)pAct[iVar] & 0x80000000)
342 p->var_inc += (
p->var_inc >> 4);
345static inline void Cbs3_ActReset(
Cbs3_Man_t *
p ) {}
346static inline void Cbs3_ActRescale(
Cbs3_Man_t *
p ) {}
347static inline void Cbs3_ActBumpVar(
Cbs3_Man_t *
p,
int iVar ) {}
348static inline void Cbs3_ActDecay(
Cbs3_Man_t *
p ) {}
363static inline int Cbs3_ManCheckLimits(
Cbs3_Man_t *
p )
365 p->nFails[0] +=
p->Pars.nJustThis >
p->Pars.nJustLimit;
366 p->nFails[1] +=
p->Pars.nBTThis >
p->Pars.nBTLimit;
367 return p->Pars.nJustThis >
p->Pars.nJustLimit ||
p->Pars.nBTThis >
p->Pars.nBTLimit;
384 Vec_IntClear( vCex );
387 if ( Cbs3_VarIsPi(
p, Abc_Lit2Var(iLit)) )
388 Vec_IntPush( vCex, Abc_Lit2LitV(Vec_IntArray(&
p->vMap), iLit)-2 );
393 Vec_IntClear( vCex );
397 int iVar = Abc_Lit2Var(iLit);
398 Vec_IntPush( vCex, Abc_Var2Lit(iVar, !Cbs3_VarValue(
p, iVar)) );
415 return p->iHead ==
p->iTail;
419 return p->iTail -
p->iHead;
433static inline void Cbs3_QuePush(
Cbs3_Que_t *
p,
int iObj )
435 if (
p->iTail ==
p->nSize )
440 p->pData[
p->iTail++] = iObj;
442static inline void Cbs3_QueGrow(
Cbs3_Que_t *
p,
int Plus )
444 if (
p->iTail + Plus >
p->nSize )
449 assert(
p->iTail + Plus <= p->nSize );
463static inline int Cbs3_QueHasNode(
Cbs3_Que_t *
p,
int iObj )
483static inline void Cbs3_QueStore(
Cbs3_Que_t *
p,
int * piHeadOld,
int * piTailOld )
486 *piHeadOld =
p->iHead;
487 *piTailOld =
p->iTail;
488 for ( i = *piHeadOld; i < *piTailOld; i++ )
489 Cbs3_QuePush(
p,
p->pData[i] );
490 p->iHead = *piTailOld;
504static inline void Cbs3_QueRestore(
Cbs3_Que_t *
p,
int iHeadOld,
int iTailOld )
523 int i, iObj, iObjMax = 0;
527 Vec_IntEntry(&
p->vActs, iObjMax) < Vec_IntEntry(&
p->vActs, iObj) ||
528 (Vec_IntEntry(&
p->vActs, iObjMax) == Vec_IntEntry(&
p->vActs, iObj) && Vec_IntEntry(&
p->vMap, iObjMax) < Vec_IntEntry(&
p->vMap, iObj)) )
533 if ( iObjMax == 0 || Vec_IntEntry(&
p->vMap, iObjMax) < Vec_IntEntry(&
p->vMap, iObj) )
551static inline void Cbs3_ManCancelUntil(
Cbs3_Man_t *
p,
int iBound )
554 assert( iBound <= p->pProp.iTail );
555 p->pProp.iHead = iBound;
557 Cbs3_VarUnassign(
p, Abc_Lit2Var(iLit) );
558 p->pProp.iTail = iBound;
572static inline void Cbs3_ManAssign(
Cbs3_Man_t *
p,
int iLit,
int Level,
int iRes0,
int iRes1 )
574 int iObj = Abc_Lit2Var(iLit);
575 assert( Cbs3_VarUnused(
p, iObj) );
576 assert( !Cbs3_VarIsAssigned(
p, iObj) );
577 Cbs3_VarSetValue(
p, iObj, !Abc_LitIsCompl(iLit) );
578 Cbs3_QuePush( &
p->pProp, iLit );
579 Vec_IntWriteEntry( &
p->vLevReason, 3*iObj, Level );
580 Vec_IntWriteEntry( &
p->vLevReason, 3*iObj+1, iRes0 );
581 Vec_IntWriteEntry( &
p->vLevReason, 3*iObj+2, iRes1 );
598static inline void Cbs3_ManPrintClause(
Cbs3_Man_t *
p,
int Level,
int hClause )
601 assert( Cbs3_QueIsEmpty( &
p->pClauses ) );
602 printf(
"Level %2d : ", Level );
604 printf(
"%c%d ", Abc_LitIsCompl(iLit) ?
'-':
'+', Abc_Lit2Var(iLit) );
608static inline void Cbs3_ManPrintCube(
Cbs3_Man_t *
p,
int Level,
int hClause )
611 assert( Cbs3_QueIsEmpty( &
p->pClauses ) );
612 printf(
"Level %2d : ", Level );
614 printf(
"%c%d ", Cbs3_VarValue(
p, iObj)?
'+':
'-', iObj );
629static inline void Cbs3_ManCleanWatch(
Cbs3_Man_t *
p )
633 Vec_IntWriteEntry( &
p->vWatches, iLit, 0 );
634 Vec_IntClear( &
p->vWatchUpds );
638static inline void Cbs3_ManWatchClause(
Cbs3_Man_t *
p,
int hClause,
int Lit )
640 int * pLits = Cbs3_ClauseLits(
p, hClause );
641 int * pPlace = Vec_IntEntryP( &
p->vWatches, Abc_LitNot(Lit) );
643 Vec_IntPush( &
p->vWatchUpds, Abc_LitNot(Lit) );
654 assert( Lit == pLits[0] || Lit == pLits[1] );
655 Cbs3_ClauseSetNext(
p, hClause, Lit == pLits[1], *pPlace );
658static inline int Cbs3_QueFinish(
Cbs3_Man_t *
p,
int Level )
661 int i, iObj, hClauseC, hClause = pQue->
iHead, Size = pQue->
iTail - pQue->
iHead - 1;
663 Cbs3_ClauseSetSize(
p, pQue->
iHead, Size );
669 pQue->
iHead = hClause;
674 else if ( i == hClause )
675 Cbs3_QuePush( pQue, iObj );
677 Cbs3_QuePush( pQue, Abc_Var2Lit(iObj, Cbs3_VarValue(
p, iObj)) );
679 Cbs3_QuePush( pQue, 0 );
680 Cbs3_QuePush( pQue, 0 );
682 Cbs3_ManWatchClause(
p, hClauseC, Cbs3_ClauseLit(
p, hClauseC, 0) );
683 Cbs3_ManWatchClause(
p, hClauseC, Cbs3_ClauseLit(
p, hClauseC, 1) );
700static inline int Cbs3_ManDeriveReason(
Cbs3_Man_t *
p,
int Level )
703 int i, k, iObj, iLitLevel, * pReason;
710 Vec_IntClear(
p->vTemp );
711 for ( i = k = pQue->
iHead + 2; i < pQue->iTail; i++ )
713 iObj = pQue->
pData[i];
714 if ( Cbs3_VarMark0(
p, iObj) )
720 Cbs3_VarSetMark0(
p, iObj, 1);
721 Cbs3_ActBumpVar(
p, iObj);
722 Vec_IntPush(
p->vTemp, iObj );
724 iLitLevel = Cbs3_VarDecLevel(
p, iObj );
725 if ( iLitLevel < Level )
727 pQue->
pData[k++] = iObj;
730 assert( iLitLevel == Level );
731 pReason = Cbs3_VarReasonP(
p, iObj );
732 if ( pReason[0] == 0 && pReason[1] == 0 )
737 else if ( pReason[0] != 0 )
739 Cbs3_QuePush( pQue, pReason[0] );
741 Cbs3_QuePush( pQue, pReason[1] );
745 int i, * pLits, nLits = Cbs3_ClauseSize(
p, pReason[1] );
747 Cbs3_QueGrow( pQue, nLits );
748 pLits = Cbs3_ClauseLits(
p, pReason[1] );
749 assert( iObj == Abc_Lit2Var(pLits[0]) );
750 for ( i = 1; i < nLits; i++ )
751 Cbs3_QuePush( pQue, Abc_Lit2Var(pLits[i]) );
759 Cbs3_VarSetMark0(
p, iObj, 0);
760 return Cbs3_QueFinish(
p, Level );
762static inline int Cbs3_ManAnalyze(
Cbs3_Man_t *
p,
int Level,
int iVar,
int iFan0,
int iFan1 )
765 assert( Cbs3_VarIsAssigned(
p, iVar) );
766 assert( Cbs3_QueIsEmpty( pQue ) );
767 Cbs3_QuePush( pQue, 0 );
768 Cbs3_QuePush( pQue, 0 );
771 assert( Cbs3_VarIsAssigned(
p, iFan0) );
772 assert( iFan1 == 0 || Cbs3_VarIsAssigned(
p, iFan1) );
773 Cbs3_QuePush( pQue, iVar );
774 Cbs3_QuePush( pQue, iFan0 );
776 Cbs3_QuePush( pQue, iFan1 );
780 int i, * pLits, nLits = Cbs3_ClauseSize(
p, iFan1 );
782 Cbs3_QueGrow( pQue, nLits );
783 pLits = Cbs3_ClauseLits(
p, iFan1 );
784 assert( iVar == Abc_Lit2Var(pLits[0]) );
785 assert( Cbs3_VarValue(
p, iVar) == Abc_LitIsCompl(pLits[0]) );
786 for ( i = 0; i < nLits; i++ )
787 Cbs3_QuePush( pQue, Abc_Lit2Var(pLits[i]) );
789 return Cbs3_ManDeriveReason(
p, Level );
804static inline int Cbs3_ManPropagateClauses(
Cbs3_Man_t *
p,
int Level,
int Lit )
806 int i, Value, Cur, LitF = Abc_LitNot(Lit);
807 int * pPrev = Vec_IntEntryP( &
p->vWatches, Lit );
809 for ( Cur = *pPrev; Cur; Cur = *pPrev )
811 int nLits = Cbs3_ClauseSize(
p, Cur );
812 int * pLits = Cbs3_ClauseLits(
p, Cur );
817 if ( pLits[0] == LitF )
826 ABC_SWAP(
int, pLits[nLits], pLits[nLits+1] );
829 assert( pLits[1] == LitF );
833 if ( Cbs3_VarValue(
p, Abc_Lit2Var(pLits[0])) == !Abc_LitIsCompl(pLits[0]) )
836 pPrev = Cbs3_ClauseNext1p(
p, Cur);
841 for ( i = 2; i < nLits; i++ )
845 if ( Cbs3_VarValue(
p, Abc_Lit2Var(pLits[i])) == Abc_LitIsCompl(pLits[i]) )
854 *pPrev = *Cbs3_ClauseNext1p(
p, Cur);
857 Cbs3_ManWatchClause(
p, Cur, Cbs3_ClauseLit(
p, Cur, 1) );
871 Value = Cbs3_VarValue(
p, Abc_Lit2Var(pLits[0]));
874 Cbs3_ManAssign(
p, pLits[0], Level, 0, Cur );
875 pPrev = Cbs3_ClauseNext1p(
p, Cur);
881 if ( Value == Abc_LitIsCompl(pLits[0]) )
884 return Cbs3_ManAnalyze(
p, Level, Abc_Lit2Var(pLits[0]), 0, Cur );
902static inline int Cbs3_ManResolve(
Cbs3_Man_t *
p,
int Level,
int hClause0,
int hClause1 )
905 int i, iObj, LevelMax = -1, LevelCur;
912 assert( Cbs3_QueIsEmpty( pQue ) );
913 Cbs3_QuePush( pQue, 0 );
914 Cbs3_QuePush( pQue, 0 );
918 if ( Cbs3_VarMark0(
p, iObj) )
924 Cbs3_VarSetMark0(
p, iObj, 1);
925 Cbs3_ActBumpVar(
p, iObj);
926 Cbs3_QuePush( pQue, iObj );
927 LevelCur = Cbs3_VarDecLevel(
p, iObj );
928 if ( LevelMax < LevelCur )
934 if ( Cbs3_VarMark0(
p, iObj) )
940 Cbs3_VarSetMark0(
p, iObj, 1);
941 Cbs3_ActBumpVar(
p, iObj);
942 Cbs3_QuePush( pQue, iObj );
943 LevelCur = Cbs3_VarDecLevel(
p, iObj );
944 if ( LevelMax < LevelCur )
947 for ( i = pQue->
iHead + 2; i < pQue->iTail; i++ )
948 Cbs3_VarSetMark0(
p, pQue->
pData[i], 0);
949 return Cbs3_ManDeriveReason(
p, LevelMax );
966 int iVar, iLit, i, k =
p->pJust.iTail;
967 Cbs3_QueGrow( &
p->pJust, Cbs3_QueSize(&
p->pJust) + Cbs3_QueSize(&
p->pProp) );
969 if ( Cbs3_VarIsJust(
p, iVar) )
970 p->pJust.pData[k++] = iVar;
972 if ( Cbs3_VarIsJust(
p, Abc_Lit2Var(iLit)) )
973 p->pJust.pData[k++] = Abc_Lit2Var(iLit);
974 p->pJust.iHead =
p->pJust.iTail;
980 int i, k, iLit, hClause, nLits, * pLits;
984 if ( (hClause = Cbs3_ManPropagateClauses(
p, Level, iLit)) )
987 nLits = Vec_IntSize(Vec_WecEntry(&
p->vImps, iLit));
988 pLits = Vec_IntArray(Vec_WecEntry(&
p->vImps, iLit));
989 for ( k = 0; k < nLits; k += 2 )
991 int Value0 = Cbs3_VarValue(
p, Abc_Lit2Var(pLits[k]));
992 int Value1 = pLits[k+1] ? Cbs3_VarValue(
p, Abc_Lit2Var(pLits[k+1])) : -1;
993 if ( Value1 == -1 || Value1 == Abc_LitIsCompl(pLits[k+1]) )
996 Cbs3_ManAssign(
p, pLits[k], Level, Abc_Lit2Var(iLit), Abc_Lit2Var(pLits[k+1]) );
997 else if ( Value0 == Abc_LitIsCompl(pLits[k]) )
998 return Cbs3_ManAnalyze(
p, Level, Abc_Lit2Var(iLit), Abc_Lit2Var(pLits[k]), Abc_Lit2Var(pLits[k+1]) );
1000 if ( Value1 != -1 && Value0 == Abc_LitIsCompl(pLits[k]) )
1003 Cbs3_ManAssign(
p, pLits[k+1], Level, Abc_Lit2Var(iLit), Abc_Lit2Var(pLits[k]) );
1004 else if ( Value1 == Abc_LitIsCompl(pLits[k+1]) )
1005 return Cbs3_ManAnalyze(
p, Level, Abc_Lit2Var(iLit), Abc_Lit2Var(pLits[k]), Abc_Lit2Var(pLits[k+1]) );
1011 p->pProp.iHead =
p->pProp.iTail;
1029 int iPropHead, iJustHead, iJustTail;
1030 int hClause, hLearn0, hLearn1, iVar, iDecLit;
1033 assert( !Cbs3_QueIsEmpty(&
p->pProp) );
1038 assert( Cbs3_QueIsEmpty(&
p->pProp) );
1039 if ( Cbs3_QueIsEmpty(&
p->pJust) )
1042 p->Pars.nJustThis = Abc_MaxInt(
p->Pars.nJustThis,
p->pJust.iTail -
p->pJust.iHead );
1043 if ( Cbs3_ManCheckLimits(
p ) )
1046 iPropHead =
p->pProp.iHead;
1047 iJustHead =
p->pJust.iHead;
1048 iJustTail =
p->pJust.iTail;
1051 iVar = Cbs3_ManDecide(
p );
1052 assert( !Cbs3_VarIsPi(
p, iVar) );
1053 assert( Cbs3_VarIsJust(
p, iVar) );
1055 nRef0 = Vec_IntEntry(&
p->vRef, Abc_Lit2Var(Cbs3_VarLit0(
p, iVar)));
1056 nRef1 = Vec_IntEntry(&
p->vRef, Abc_Lit2Var(Cbs3_VarLit1(
p, iVar)));
1058 if ( nRef0 >= nRef1 )
1059 iDecLit = Abc_LitNot(Cbs3_VarLit0(
p, iVar));
1061 iDecLit = Abc_LitNot(Cbs3_VarLit1(
p, iVar));
1063 Cbs3_ManAssign(
p, iDecLit, Level+1, 0, 0 );
1066 if ( pQue->
pData[hLearn0+1] != Abc_Lit2Var(iDecLit) )
1068 Cbs3_ManCancelUntil(
p, iPropHead );
1069 Cbs3_QueRestore( &
p->pJust, iJustHead, iJustTail );
1071 Cbs3_ManAssign(
p, Abc_LitNot(iDecLit), Level+1, 0, 0 );
1074 if ( pQue->
pData[hLearn1+1] != Abc_Lit2Var(iDecLit) )
1076 hClause = Cbs3_ManResolve(
p, Level, hLearn0, hLearn1 );
1092static inline int Cbs3_ManSolveInt(
Cbs3_Man_t *
p,
int iLit )
1095 assert( !
p->pProp.iHead && !
p->pProp.iTail );
1096 assert( !
p->pJust.iHead && !
p->pJust.iTail );
1097 p->Pars.nBTThis =
p->Pars.nJustThis = 0;
1098 Cbs3_ManAssign(
p, iLit, 0, 0, 0 );
1100 Cbs3_ManSaveModel(
p,
p->vModel );
1103 Cbs3_ManCancelUntil(
p, 0 );
1104 p->pJust.iHead =
p->pJust.iTail = 0;
1105 p->Pars.nBTTotal +=
p->Pars.nBTThis;
1106 p->Pars.nJustTotal = Abc_MaxInt(
p->Pars.nJustTotal,
p->Pars.nJustThis );
1107 if ( Cbs3_ManCheckLimits(
p ) )
1113 int i, RetValue = -1;
1114 assert(
p->pClauses.iHead == 1 &&
p->pClauses.iTail == 1 );
1115 for ( i = 0; i < nRestarts; i++ )
1116 if ( (RetValue = Cbs3_ManSolveInt(
p, iLit)) != -1 )
1118 Cbs3_ManCleanWatch(
p );
1119 p->pClauses.iHead =
p->pClauses.iTail = 1;
1136 printf(
"CO = %8d ", Gia_ManCoNum(
p->pAig) );
1137 printf(
"AND = %8d ", Gia_ManAndNum(
p->pAig) );
1138 printf(
"Conf = %6d ",
p->Pars.nBTLimit );
1139 printf(
"Restart = %2d ",
p->Pars.nRestLimit );
1140 printf(
"JustMax = %5d ",
p->Pars.nJustLimit );
1142 printf(
"Unsat calls %6d (%6.2f %%) Ave conf = %8.1f ",
1143 p->nSatUnsat,
p->nSatTotal? 100.0*
p->nSatUnsat/
p->nSatTotal :0.0,
p->nSatUnsat? 1.0*
p->nConfUnsat/
p->nSatUnsat :0.0 );
1144 ABC_PRTP(
"Time",
p->timeSatUnsat,
p->timeTotal );
1145 printf(
"Sat calls %6d (%6.2f %%) Ave conf = %8.1f ",
1146 p->nSatSat,
p->nSatTotal? 100.0*
p->nSatSat/
p->nSatTotal :0.0,
p->nSatSat? 1.0*
p->nConfSat/
p->nSatSat : 0.0 );
1147 ABC_PRTP(
"Time",
p->timeSatSat,
p->timeTotal );
1148 printf(
"Undef calls %6d (%6.2f %%) Ave conf = %8.1f ",
1149 p->nSatUndec,
p->nSatTotal? 100.0*
p->nSatUndec/
p->nSatTotal :0.0,
p->nSatUndec? 1.0*
p->nConfUndec/
p->nSatUndec : 0.0 );
1150 ABC_PRTP(
"Time",
p->timeSatUndec,
p->timeTotal );
1151 ABC_PRT(
"Total time",
p->timeTotal );
1166static inline int Cbs3_ManAddVar(
Cbs3_Man_t *
p,
int iGiaObj )
1168 assert( Vec_IntSize(&
p->vMap) ==
p->nVars );
1169 Vec_IntPush( &
p->vMap, iGiaObj );
1170 Vec_IntPush( &
p->vRef, Gia_ObjRefNumId(
p->pAig, iGiaObj) );
1171 Vec_IntPushTwo( &
p->vFans, 0, 0 );
1172 Vec_WecPushLevel(&
p->vImps);
1173 Vec_WecPushLevel(&
p->vImps);
1174 return Abc_Var2Lit(
p->nVars++, 0 );
1176static inline void Cbs3_ManAddConstr(
Cbs3_Man_t *
p,
int x,
int x0,
int x1 )
1178 Vec_WecPushTwo( &
p->vImps, x , x0, 0 );
1179 Vec_WecPushTwo( &
p->vImps, x , x1, 0 );
1180 Vec_WecPushTwo( &
p->vImps, 1^x0, 1^x , 0 );
1181 Vec_WecPushTwo( &
p->vImps, 1^x1, 1^x , 0 );
1182 Vec_WecPushTwo( &
p->vImps, 1^x , 1^x0, 1^x1 );
1183 Vec_WecPushTwo( &
p->vImps, x0, x , 1^x1 );
1184 Vec_WecPushTwo( &
p->vImps, x1, x , 1^x0 );
1186static inline void Cbs3_ManAddAnd(
Cbs3_Man_t *
p,
int x,
int x0,
int x1 )
1188 assert( x > 0 && x0 > 0 && x1 > 0 );
1189 Vec_IntWriteEntry( &
p->vFans, x, x0 );
1190 Vec_IntWriteEntry( &
p->vFans, x+1, x1 );
1191 Cbs3_ManAddConstr(
p, x, x0, x1 );
1193static inline int Cbs3_ManToSolver1_rec(
Cbs3_Man_t * pSol,
Gia_Man_t *
p,
int iObj,
int Depth )
1195 Gia_Obj_t * pObj = Gia_ManObj(
p, iObj);
int Lit0, Lit1;
1196 if ( Gia_ObjUpdateTravIdCurrentId(
p, iObj) )
1198 pObj->
Value = Cbs3_ManAddVar( pSol, iObj );
1199 if ( Gia_ObjIsCi(pObj) || Depth == 0 )
1201 assert( Gia_ObjIsAnd(pObj) );
1202 Lit0 = Cbs3_ManToSolver1_rec( pSol,
p, Gia_ObjFaninId0(pObj, iObj), Depth - Gia_ObjFaninC0(pObj) );
1203 Lit1 = Cbs3_ManToSolver1_rec( pSol,
p, Gia_ObjFaninId1(pObj, iObj), Depth - Gia_ObjFaninC1(pObj) );
1204 Cbs3_ManAddAnd( pSol, pObj->
Value, Lit0 ^ Gia_ObjFaninC0(pObj), Lit1 ^ Gia_ObjFaninC1(pObj) );
1210 assert( Gia_ObjIsCo(pRoot) );
1211 Cbs3_ManReset( pSol );
1213 Cbs3_ManToSolver1_rec( pSol,
p, Gia_ObjFaninId0p(
p, pRoot), Depth );
1214 Cbs3_ManGrow( pSol );
1215 Cbs3_ActReset( pSol );
1217 return Cbs3_ManSolve( pSol, Gia_ObjFanin0Copy(pRoot), nRestarts );
1231static inline void Cbs3_ManPrepare(
Cbs3_Man_t *
p )
1234 Vec_WecInit( &
p->vImps, Abc_Var2Lit(
p->nVars, 0) );
1236 if ( x0 ) Cbs3_ManAddConstr(
p, x, x0, x1 );
1238static
inline int Cbs3_ManAddNode(
Cbs3_Man_t *
p,
int iGiaObj,
int iLit0,
int iLit1 )
1240 assert( Vec_IntSize(&
p->vMap) ==
p->nVars );
1241 Vec_IntPush( &
p->vMap, iGiaObj );
1242 Vec_IntPush( &
p->vRef, Gia_ObjRefNumId(
p->pAig, iGiaObj) );
1243 Vec_IntPushTwo( &
p->vFans, iLit0, iLit1 );
1244 return Abc_Var2Lit(
p->nVars++, 0 );
1246static inline int Cbs3_ManToSolver2_rec(
Cbs3_Man_t * pSol,
Gia_Man_t *
p,
int iObj,
int Depth )
1248 Gia_Obj_t * pObj = Gia_ManObj(
p, iObj);
int Lit0, Lit1;
1249 if ( Gia_ObjUpdateTravIdCurrentId(
p, iObj) )
1251 if ( Gia_ObjIsCi(pObj) || Depth == 0 )
1252 return pObj->
Value = Cbs3_ManAddNode(pSol, iObj, 0, 0);
1253 assert( Gia_ObjIsAnd(pObj) );
1254 Lit0 = Cbs3_ManToSolver2_rec( pSol,
p, Gia_ObjFaninId0(pObj, iObj), Depth - Gia_ObjFaninC0(pObj) );
1255 Lit1 = Cbs3_ManToSolver2_rec( pSol,
p, Gia_ObjFaninId1(pObj, iObj), Depth - Gia_ObjFaninC1(pObj) );
1256 return pObj->
Value = Cbs3_ManAddNode(pSol, iObj, Lit0 ^ Gia_ObjFaninC0(pObj), Lit1 ^ Gia_ObjFaninC1(pObj));
1261 assert( Gia_ObjIsCo(pRoot) );
1262 Cbs3_ManReset( pSol );
1264 Cbs3_ManToSolver2_rec( pSol,
p, Gia_ObjFaninId0p(
p, pRoot), Depth );
1265 Cbs3_ManGrow( pSol );
1266 Cbs3_ManPrepare( pSol );
1267 Cbs3_ActReset( pSol );
1269 return Cbs3_ManSolve( pSol, Gia_ObjFanin0Copy(pRoot), nRestarts );
1288 Vec_Int_t * vCex, * vVisit, * vCexStore;
1292 abctime clk, clkTotal = Abc_Clock();
1298 p->Pars.nBTLimit = nConfs;
1299 p->Pars.nRestLimit = nRestarts;
1301 vStatus = Vec_StrAlloc( Gia_ManPoNum(pAig) );
1302 vCexStore = Vec_IntAlloc( 10000 );
1303 vVisit = Vec_IntAlloc( 100 );
1308 if ( Gia_ObjIsConst0(Gia_ObjFanin0(pRoot)) )
1310 Vec_IntClear( vCex );
1311 Vec_StrPush( vStatus, (
char)(!Gia_ObjFaninC0(pRoot)) );
1312 if ( Gia_ObjFaninC0(pRoot) )
1317 status = Cbs3_ManToSolver2(
p, pAig, pRoot,
p->Pars.nRestLimit, 10000 );
1318 Vec_StrPush( vStatus, (
char)status );
1322 p->nConfUndec +=
p->Pars.nBTThis;
1324 p->timeSatUndec += Abc_Clock() - clk;
1330 p->nConfUnsat +=
p->Pars.nBTThis;
1331 p->timeSatUnsat += Abc_Clock() - clk;
1335 p->nConfSat +=
p->Pars.nBTThis;
1338 p->timeSatSat += Abc_Clock() - clk;
1340 Vec_IntFree( vVisit );
1341 p->nSatTotal = Gia_ManPoNum(pAig);
1342 p->timeTotal = Abc_Clock() - clkTotal;
1347 printf(
"Prop1 = %d. Prop2 = %d. Prop3 = %d. ClaConf = %d. FailJ = %d. FailC = %d. ",
p->nPropCalls[0],
p->nPropCalls[1],
p->nPropCalls[2],
p->nClauseConf,
p->nFails[0],
p->nFails[1] );
1354 *pvStatus = vStatus;
#define ABC_SWAP(Type, a, b)
#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)
struct Cbs3_Que_t_ Cbs3_Que_t
#define Cbs3_ClauseForEachEntry1(p, hClause, iObj, i)
Vec_Int_t * Cbs3_ManSolveMiterNc(Gia_Man_t *pAig, int nConfs, int nRestarts, Vec_Str_t **pvStatus, int fVerbose)
#define Cbs3_ClauseForEachEntry(p, hClause, iObj, i)
void Cbs3_ManStop(Cbs3_Man_t *p)
typedefABC_NAMESPACE_IMPL_START struct Cbs3_Par_t_ Cbs3_Par_t
DECLARATIONS ///.
void Cbs3_ManUpdateJFrontier(Cbs3_Man_t *p)
#define Cbs3_QueForEachEntry(Que, iObj, i)
Vec_Int_t * Cbs3_ReadModel(Cbs3_Man_t *p)
void Cbs3_ManSatPrintStats(Cbs3_Man_t *p)
Cbs3_Man_t * Cbs3_ManAlloc(Gia_Man_t *pGia)
int Cbs3_ManSolve(Cbs3_Man_t *p, int iLit, int nRestarts)
void Cbs3_SetDefaultParams(Cbs3_Par_t *pPars)
FUNCTION DEFINITIONS ///.
int Cbs3_ManPropagateNew(Cbs3_Man_t *p, int Level)
int Cbs3_ManSolve2_rec(Cbs3_Man_t *p, int Level)
void Cbs3_ManSetConflictNum(Cbs3_Man_t *p, int Num)
int Cbs3_ManMemory(Cbs3_Man_t *p)
struct Cbs3_Man_t_ Cbs3_Man_t
struct Gia_Obj_t_ Gia_Obj_t
struct Gia_Man_t_ Gia_Man_t
void Gia_ManCreateRefs(Gia_Man_t *p)
void Gia_ManIncrementTravId(Gia_Man_t *p)
#define Gia_ManForEachCo(p, pObj, i)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryDoubleStart(vVec, Entry1, Entry2, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.