37static const lit LIT_UNDEF = 0xffffffff;
117 p->nResLitsAlloc = (1<<16);
139 int LargeNum = -100000000;
147 for ( v = 0; v < (int)pClause->
nLits; v++ )
148 p->pVarTypes[lit_var(pClause->
pLits[v])] = 1;
157 for ( v = 0; v < (int)pClause->
nLits; v++ )
160 if (
p->pVarTypes[
Var] == 1 )
164 p->pVarTypes[
Var] = LargeNum;
168 assert( nVarsAB <= Vec_IntSize(
p->vVarsAB) );
173 p->pVarTypes[
Var] = -(1+nVarsAB++);
176 for ( v = 0; v <
p->pCnf->nVars; v++ )
177 assert(
p->pVarTypes[v] != LargeNum );
196 if (
p->nVarsAlloc <
p->pCnf->nVars )
199 if (
p->nVarsAlloc == 0 )
201 while (
p->nVarsAlloc <
p->pCnf->nVars )
213 memset(
p->pAssigns , 0xff,
sizeof(
lit) *
p->pCnf->nVars );
214 memset(
p->pSeens , 0,
sizeof(
char) *
p->pCnf->nVars );
215 memset(
p->pVarTypes, 0,
sizeof(
int) *
p->pCnf->nVars );
223 if (
p->nClosAlloc <
p->pCnf->nClauses )
226 if (
p->nClosAlloc == 0 )
228 while (
p->nClosAlloc <
p->pCnf->nClauses )
233 memset(
p->pProofNums, 0,
sizeof(
int) *
p->pCnf->nClauses );
236 if (
p->nIntersAlloc <
p->pCnf->nClauses )
238 p->nIntersAlloc =
p->pCnf->nClauses;
292 printf(
"Clause ID = %d. Proof = %d. {", pClause->
Id, Intb_ManProofGet(
p, pClause) );
293 for ( i = 0; i < (int)pClause->
nLits; i++ )
294 printf(
" %d", pClause->
pLits[i] );
312 printf(
"Resolvent: {" );
313 for ( i = 0; i < nResLits; i++ )
314 printf(
" %d", pResLits[i] );
331 printf(
"Clause %2d : ", pClause->
Id );
351 assert( lit_check(Lit,
p->pCnf->nVars) );
352 if ( pClause->
pLits[0] == Lit )
353 pClause->
pNext0 =
p->pWatches[lit_neg(Lit)];
357 pClause->
pNext1 =
p->pWatches[lit_neg(Lit)];
359 p->pWatches[lit_neg(Lit)] = pClause;
376 int Var = lit_var(Lit);
377 if (
p->pAssigns[
Var] != LIT_UNDEF )
378 return p->pAssigns[
Var] == Lit;
379 p->pAssigns[
Var] = Lit;
380 p->pReasons[
Var] = pReason;
381 p->pTrail[
p->nTrailSize++] = Lit;
397static inline void Intb_ManCancelUntil(
Intb_Man_t *
p,
int Level )
401 for ( i =
p->nTrailSize - 1; i >= Level; i-- )
404 Var = lit_var( Lit );
405 p->pReasons[
Var] = NULL;
406 p->pAssigns[
Var] = LIT_UNDEF;
409 p->nTrailSize = Level;
426 lit LitF = lit_neg(Lit);
429 ppPrev =
p->pWatches + Lit;
430 for ( pCur =
p->pWatches[Lit]; pCur; pCur = *ppPrev )
433 if ( pCur->
pLits[0] == LitF )
436 pCur->
pLits[1] = LitF;
444 if ( pCur->
pLits[0] ==
p->pAssigns[lit_var(pCur->
pLits[0])] )
451 for ( i = 2; i < (int)pCur->
nLits; i++ )
454 if ( lit_neg(pCur->
pLits[i]) ==
p->pAssigns[lit_var(pCur->
pLits[i])] )
458 pCur->
pLits[i] = LitF;
462 Intb_ManWatchClause(
p, pCur, pCur->
pLits[1] );
465 if ( i < (
int)pCur->
nLits )
469 if ( Intb_ManEnqueue(
p, pCur->
pLits[0], pCur) )
497 for ( i = Start; i <
p->nTrailSize; i++ )
499 pClause = Intb_ManPropagateOne(
p,
p->pTrail[i] );
502p->timeBcp += Abc_Clock() - clk;
506p->timeBcp += Abc_Clock() - clk;
524 Intb_ManProofSet(
p, pClause, ++
p->Counter );
526 if (
p->fProofWrite )
529 fprintf(
p->pFile,
"%d", Intb_ManProofGet(
p, pClause) );
530 for ( v = 0; v < (int)pClause->
nLits; v++ )
531 fprintf(
p->pFile,
" %d", lit_print(pClause->
pLits[v]) );
532 fprintf(
p->pFile,
" 0 0\n" );
550 if (
p->pVarTypes[
Var] >= 0 )
552 VarAB = -
p->pVarTypes[
Var]-1;
553 assert( VarAB >= 0 && VarAB < Vec_IntSize(
p->vVarsAB) );
571 int i, v,
Var, PrevId;
576 if (
p->fProofVerif )
580 p->nResLits = pConflict->
nLits;
584 for ( v = 0; v < (int)pConflict->
nLits; v++ )
585 p->pSeens[lit_var(pConflict->
pLits[v])] = 1;
591 if (
p->pCnf->nClausesA )
592 Intb_ManAigCopy(
p, Intb_ManAigRead(
p, pFinal), Intb_ManAigRead(
p, pConflict) );
595 PrevId = Intb_ManProofGet(
p, pConflict);
596 for ( i =
p->nTrailSize - 1; i >= 0; i-- )
599 Var = lit_var(
p->pTrail[i]);
600 if ( !
p->pSeens[
Var] )
605 pReason =
p->pReasons[
Var];
606 if ( pReason == NULL )
611 for ( v = 1; v < (int)pReason->
nLits; v++ )
612 p->pSeens[lit_var(pReason->
pLits[v])] = 1;
615 assert( Intb_ManProofGet(
p, pReason) > 0 );
617 if (
p->fProofWrite )
618 fprintf(
p->pFile,
"%d * %d %d 0\n",
p->Counter, PrevId, Intb_ManProofGet(
p, pReason) );
621 if (
p->pCnf->nClausesA )
623 if (
p->pVarTypes[
Var] == 1 )
624 Intb_ManAigOr(
p, Intb_ManAigRead(
p, pFinal), Intb_ManAigRead(
p, pReason) );
625 else if (
p->pVarTypes[
Var] == 0 )
626 Intb_ManAigAnd(
p, Intb_ManAigRead(
p, pFinal), Intb_ManAigRead(
p, pReason) );
631 for ( v = 0; v < (int)pReason->
nLits; v++ )
632 if ( lit_var(pReason->
pLits[v]) ==
Var )
635 if ( lit_sign(pReason->
pLits[v]) )
636 Intb_ManAigMux0(
p, Intb_ManAigRead(
p, pFinal), Intb_ManAigRead(
p, pReason), VarAB );
638 Intb_ManAigMux1(
p, Intb_ManAigRead(
p, pFinal), Intb_ManAigRead(
p, pReason), VarAB );
643 if (
p->fProofVerif )
649 for ( v1 = 0; v1 <
p->nResLits; v1++ )
650 if ( lit_var(
p->pResLits[v1]) ==
Var )
652 if ( v1 ==
p->nResLits )
653 printf(
"Recording clause %d: Cannot find variable %d in the temporary resolvent.\n", pFinal->
Id,
Var );
654 if (
p->pResLits[v1] != lit_neg(pReason->
pLits[0]) )
655 printf(
"Recording clause %d: The resolved variable %d is in the wrong polarity.\n", pFinal->
Id,
Var );
659 for ( ; v1 <
p->nResLits; v1++ )
660 p->pResLits[v1] =
p->pResLits[v1+1];
662 for ( v2 = 1; v2 < (int)pReason->
nLits; v2++ )
664 for ( v1 = 0; v1 <
p->nResLits; v1++ )
665 if ( lit_var(
p->pResLits[v1]) == lit_var(pReason->
pLits[v2]) )
668 if ( v1 ==
p->nResLits )
670 if (
p->nResLits ==
p->nResLitsAlloc )
671 printf(
"Recording clause %d: Ran out of space for intermediate resolvent.\n", pFinal->
Id );
672 p->pResLits[
p->nResLits++ ] = pReason->
pLits[v2];
676 if (
p->pResLits[v1] == pReason->
pLits[v2] )
679 printf(
"Recording clause %d: Trying to resolve the clause with more than one opposite literal.\n", pFinal->
Id );
693 if (
p->fProofVerif )
698 for ( v1 = 0; v1 <
p->nResLits; v1++ )
700 for ( v2 = 0; v2 < (int)pFinal->
nLits; v2++ )
701 if ( pFinal->
pLits[v2] ==
p->pResLits[v1] )
703 if ( v2 < (
int)pFinal->
nLits )
707 if ( v1 < p->nResLits )
709 printf(
"Recording clause %d: The final resolvent is wrong.\n", pFinal->
Id );
718 if (
p->nResLits != (
int)pFinal->
nLits )
720 for ( v1 = 0; v1 < (int)pFinal->
nLits; v1++ )
722 for ( v2 = 0; v2 <
p->nResLits; v2++ )
723 if ( pFinal->
pLits[v1] ==
p->pResLits[v2] )
725 if ( v2 < p->nResLits )
729 for ( v2 = v1; v2 < (int)pFinal->
nLits; v2++ )
736p->timeTrace += Abc_Clock() - clk;
739 if (
p->pCnf->nClausesA )
743 Intb_ManProofSet(
p, pFinal,
p->Counter );
745 assert(
p->pProofNums[pFinal->
Id-1] !=
p->Counter );
769 if ( pClause->
nLits == 0 )
770 printf(
"Error: Empty clause is attempted.\n" );
773 assert(
p->nTrailSize ==
p->nRootSize );
777 for ( i = 0; i < (int)pClause->
nLits; i++ )
778 if (
p->pAssigns[lit_var(pClause->
pLits[i])] == pClause->
pLits[i] )
782 for ( i = 0; i < (int)pClause->
nLits; i++ )
783 if ( !Intb_ManEnqueue(
p, lit_neg(pClause->
pLits[i]), NULL ) )
791 if ( pConflict == NULL )
802 for ( i = 0; i < (int)pConflict->
nLits; i++ )
804 for ( j = 0; j < (int)pClause->
nLits; j++ )
805 if ( pConflict->
pLits[i] == pClause->
pLits[j] )
807 if ( j == (
int)pClause->
nLits )
810 if ( i == (
int)pConflict->
nLits )
813 Intb_ManCancelUntil(
p,
p->nRootSize );
822 Intb_ManCancelUntil(
p,
p->nRootSize );
825 if ( pClause->
nLits > 1 )
827 Intb_ManWatchClause(
p, pClause, pClause->
pLits[0] );
828 Intb_ManWatchClause(
p, pClause, pClause->
pLits[1] );
834 if ( !Intb_ManEnqueue(
p, pClause->
pLits[0], pClause ) )
852 p->nRootSize =
p->nTrailSize;
876 assert( (
int)pClause->
fA == (Counter < (
int)
p->pCnf->nClausesA) );
877 assert( (
int)pClause->
fRoot == (Counter < (
int)
p->pCnf->nRoots) );
880 assert(
p->pCnf->nClauses == Counter );
883 assert(
p->pCnf->pTail->nLits == 0 );
890 if ( pClause->
nLits > 1 )
892 Intb_ManWatchClause(
p, pClause, pClause->
pLits[0] );
893 Intb_ManWatchClause(
p, pClause, pClause->
pLits[1] );
896 if ( pClause->
nLits != 1 )
900 if ( !Intb_ManEnqueue(
p, pClause->
pLits[0], pClause ) )
908 printf(
"Found root level conflict!\n" );
920 printf(
"Found root level conflict!\n" );
925 p->nRootSize =
p->nTrailSize;
950 Intb_ManAigFill(
p, Intb_ManAigRead(
p, pClause) );
955 Intb_ManAigClear(
p, Intb_ManAigRead(
p, pClause) );
956 for ( v = 0; v < (int)pClause->
nLits; v++ )
959 if (
p->pVarTypes[
Var] < 0 )
961 VarAB = -
p->pVarTypes[
Var]-1;
962 assert( VarAB >= 0 && VarAB < Vec_IntSize(
p->vVarsAB) );
963 if ( lit_sign(pClause->
pLits[v]) )
964 Intb_ManAigOrNotVar(
p, Intb_ManAigRead(
p, pClause), VarAB );
966 Intb_ManAigOrVar(
p, Intb_ManAigRead(
p, pClause), VarAB );
993 abctime clkTotal = Abc_Clock();
998 p->fVerbose = fVerbose;
1011 if (
p->fProofWrite )
1013 p->pFile = fopen(
"proof.cnf_",
"w" );
1027 if ( pClause->
fRoot )
1038 if (
p->fProofWrite )
1048 printf(
"Vars = %d. Roots = %d. Learned = %d. Resol steps = %d. Ave = %.2f. Mem = %.2f MB\n",
1049 p->pCnf->nVars,
p->pCnf->nRoots,
p->pCnf->nClauses-
p->pCnf->nRoots,
p->Counter,
1050 1.0*(
p->Counter-
p->pCnf->nRoots)/(
p->pCnf->nClauses-
p->pCnf->nRoots),
1052p->timeTotal += Abc_Clock() - clkTotal;
1055 pObj = *Intb_ManAigRead(
p,
p->pCnf->pTail );
1083 pMiter = Aig_ManConst1(
p);
1086 if ( fClausesA ^ pClause->
fA )
1089 pSum = Aig_ManConst0(
p);
1090 for ( v = 0; v < (int)pClause->
nLits; v++ )
1101 pSum =
Aig_Or(
p, pSum, pLit );
1103 pMiter =
Aig_And(
p, pMiter, pSum );
#define ABC_ALLOC(type, num)
#define ABC_REALLOC(type, obj, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
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)
Aig_Obj_t * Aig_Mux(Aig_Man_t *p, Aig_Obj_t *pC, Aig_Obj_t *p1, Aig_Obj_t *p0)
struct Aig_Obj_t_ Aig_Obj_t
Aig_Man_t * Aig_ManStart(int nNodesMax)
DECLARATIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
int Aig_ManCleanup(Aig_Man_t *p)
Aig_Obj_t * Aig_IthVar(Aig_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Aig_Obj_t * Aig_Or(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
void Intb_ManPrintInterOne(Intb_Man_t *p, Sto_Cls_t *pClause)
void Intb_ManFree(Intb_Man_t *p)
void Intb_ManProofWriteOne(Intb_Man_t *p, Sto_Cls_t *pClause)
int Intb_ManProcessRoots(Intb_Man_t *p)
Intb_Man_t * Intb_ManAlloc()
FUNCTION DEFINITIONS ///.
Aig_Man_t * Intb_ManDeriveClauses(Intb_Man_t *pMan, Sto_Man_t *pCnf, int fClausesA)
int Intb_ManProofTraceOne(Intb_Man_t *p, Sto_Cls_t *pConflict, Sto_Cls_t *pFinal)
void Intb_ManResize(Intb_Man_t *p)
int Intb_ManProofRecordOne(Intb_Man_t *p, Sto_Cls_t *pClause)
int Intb_ManGlobalVars(Intb_Man_t *p)
void Intb_ManPrintClause(Intb_Man_t *p, Sto_Cls_t *pClause)
int Intb_ManGetGlobalVar(Intb_Man_t *p, int Var)
void Intb_ManPrepareInter(Intb_Man_t *p)
void Intb_ManPrintResolvent(lit *pResLits, int nResLits)
void * Intb_ManInterpolate(Intb_Man_t *p, Sto_Man_t *pCnf, void *vVarsAB, int fVerbose)
Sto_Cls_t * Intb_ManPropagate(Intb_Man_t *p, int Start)
int Sto_ManMemoryReport(Sto_Man_t *p)
struct Intb_Man_t_ Intb_Man_t
#define Sto_ManForEachClause(p, pCls)
struct Sto_Man_t_ Sto_Man_t
struct Sto_Cls_t_ Sto_Cls_t
BASIC TYPES ///.
#define Sto_ManForEachClauseRoot(p, pCls)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.