37static const lit LIT_UNDEF = 0xffffffff;
103 p->nResLitsAlloc = (1<<16);
108 p->vAntClas = Vec_PtrAlloc( 1000 );
130 if (
p->nVarsAlloc <
p->pCnf->nVars )
133 if (
p->nVarsAlloc == 0 )
135 while (
p->nVarsAlloc <
p->pCnf->nVars )
147 memset(
p->pAssigns , 0xff,
sizeof(
lit) *
p->pCnf->nVars );
148 memset(
p->pSeens , 0,
sizeof(
char) *
p->pCnf->nVars );
154 if (
p->nClosAlloc <
p->pCnf->nClauses )
157 if (
p->nClosAlloc == 0 )
159 while (
p->nClosAlloc <
p->pCnf->nClauses )
164 memset(
p->pProofNums, 0,
sizeof(
int) *
p->pCnf->nClauses );
218 printf(
"Clause ID = %d. Proof = %d. {", pClause->
Id, Intp_ManProofGet(
p, pClause) );
219 for ( i = 0; i < (int)pClause->
nLits; i++ )
220 printf(
" %d", pClause->
pLits[i] );
238 printf(
"Resolvent: {" );
239 for ( i = 0; i < nResLits; i++ )
240 printf(
" %d", pResLits[i] );
257 printf(
"Clause %2d : ", pClause->
Id );
277 assert( lit_check(Lit,
p->pCnf->nVars) );
278 if ( pClause->
pLits[0] == Lit )
279 pClause->
pNext0 =
p->pWatches[lit_neg(Lit)];
283 pClause->
pNext1 =
p->pWatches[lit_neg(Lit)];
285 p->pWatches[lit_neg(Lit)] = pClause;
302 int Var = lit_var(Lit);
303 if (
p->pAssigns[
Var] != LIT_UNDEF )
304 return p->pAssigns[
Var] == Lit;
305 p->pAssigns[
Var] = Lit;
306 p->pReasons[
Var] = pReason;
307 p->pTrail[
p->nTrailSize++] = Lit;
323static inline void Intp_ManCancelUntil(
Intp_Man_t *
p,
int Level )
327 for ( i =
p->nTrailSize - 1; i >= Level; i-- )
330 Var = lit_var( Lit );
331 p->pReasons[
Var] = NULL;
332 p->pAssigns[
Var] = LIT_UNDEF;
335 p->nTrailSize = Level;
352 lit LitF = lit_neg(Lit);
355 ppPrev =
p->pWatches + Lit;
356 for ( pCur =
p->pWatches[Lit]; pCur; pCur = *ppPrev )
359 if ( pCur->
pLits[0] == LitF )
362 pCur->
pLits[1] = LitF;
370 if ( pCur->
pLits[0] ==
p->pAssigns[lit_var(pCur->
pLits[0])] )
377 for ( i = 2; i < (int)pCur->
nLits; i++ )
380 if ( lit_neg(pCur->
pLits[i]) ==
p->pAssigns[lit_var(pCur->
pLits[i])] )
384 pCur->
pLits[i] = LitF;
388 Intp_ManWatchClause(
p, pCur, pCur->
pLits[1] );
391 if ( i < (
int)pCur->
nLits )
395 if ( Intp_ManEnqueue(
p, pCur->
pLits[0], pCur) )
423 for ( i = Start; i <
p->nTrailSize; i++ )
425 pClause = Intp_ManPropagateOne(
p,
p->pTrail[i] );
428p->timeBcp += Abc_Clock() - clk;
432p->timeBcp += Abc_Clock() - clk;
450 Intp_ManProofSet(
p, pClause, ++
p->Counter );
452 if (
p->fProofWrite )
455 fprintf(
p->pFile,
"%d", Intp_ManProofGet(
p, pClause) );
456 for ( v = 0; v < (int)pClause->
nLits; v++ )
457 fprintf(
p->pFile,
" %d", lit_print(pClause->
pLits[v]) );
458 fprintf(
p->pFile,
" 0 0\n" );
476 int i, v,
Var, PrevId;
481 if (
p->fProofVerif )
485 p->nResLits = pConflict->
nLits;
489 for ( v = 0; v < (int)pConflict->
nLits; v++ )
490 p->pSeens[lit_var(pConflict->
pLits[v])] = 1;
501 assert( Vec_PtrSize(
p->vAntClas) == pFinal->
Id -
p->nAntStart );
502 Vec_IntPush( vAnts, pConflict->
Id );
503 Vec_PtrPush(
p->vAntClas, vAnts );
510 PrevId = Intp_ManProofGet(
p, pConflict);
511 for ( i =
p->nTrailSize - 1; i >= 0; i-- )
514 Var = lit_var(
p->pTrail[i]);
515 if ( !
p->pSeens[
Var] )
520 pReason =
p->pReasons[
Var];
521 if ( pReason == NULL )
526 for ( v = 1; v < (int)pReason->
nLits; v++ )
527 p->pSeens[lit_var(pReason->
pLits[v])] = 1;
531 assert( Intp_ManProofGet(
p, pReason) > 0 );
533 if (
p->fProofWrite )
534 fprintf(
p->pFile,
"%d * %d %d 0\n",
p->Counter, PrevId, Intp_ManProofGet(
p, pReason) );
546 if (
p->fProofVerif )
552 for ( v1 = 0; v1 <
p->nResLits; v1++ )
553 if ( lit_var(
p->pResLits[v1]) ==
Var )
555 if ( v1 ==
p->nResLits )
556 printf(
"Recording clause %d: Cannot find variable %d in the temporary resolvent.\n", pFinal->
Id,
Var );
557 if (
p->pResLits[v1] != lit_neg(pReason->
pLits[0]) )
558 printf(
"Recording clause %d: The resolved variable %d is in the wrong polarity.\n", pFinal->
Id,
Var );
562 for ( ; v1 <
p->nResLits; v1++ )
563 p->pResLits[v1] =
p->pResLits[v1+1];
565 for ( v2 = 1; v2 < (int)pReason->
nLits; v2++ )
567 for ( v1 = 0; v1 <
p->nResLits; v1++ )
568 if ( lit_var(
p->pResLits[v1]) == lit_var(pReason->
pLits[v2]) )
571 if ( v1 ==
p->nResLits )
573 if (
p->nResLits ==
p->nResLitsAlloc )
574 printf(
"Recording clause %d: Ran out of space for intermediate resolvent.\n", pFinal->
Id );
575 p->pResLits[
p->nResLits++ ] = pReason->
pLits[v2];
579 if (
p->pResLits[v1] == pReason->
pLits[v2] )
582 printf(
"Recording clause %d: Trying to resolve the clause with more than one opposite literal.\n", pFinal->
Id );
588 Vec_IntPush( (
Vec_Int_t *)Vec_PtrEntryLast(
p->vAntClas), pReason->
Id );
599 if (
p->fProofVerif )
604 for ( v1 = 0; v1 <
p->nResLits; v1++ )
606 for ( v2 = 0; v2 < (int)pFinal->
nLits; v2++ )
607 if ( pFinal->
pLits[v2] ==
p->pResLits[v1] )
609 if ( v2 < (
int)pFinal->
nLits )
613 if ( v1 < p->nResLits )
615 printf(
"Recording clause %d: The final resolvent is wrong.\n", pFinal->
Id );
624 if (
p->nResLits != (
int)pFinal->
nLits )
626 for ( v1 = 0; v1 < (int)pFinal->
nLits; v1++ )
628 for ( v2 = 0; v2 <
p->nResLits; v2++ )
629 if ( pFinal->
pLits[v1] ==
p->pResLits[v2] )
631 if ( v2 < p->nResLits )
635 for ( v2 = v1; v2 < (int)pFinal->
nLits; v2++ )
642p->timeTrace += Abc_Clock() - clk;
649 Intp_ManProofSet(
p, pFinal,
p->Counter );
651 assert(
p->pProofNums[pFinal->
Id-1] !=
p->Counter );
675 if ( pClause->
nLits == 0 )
676 printf(
"Error: Empty clause is attempted.\n" );
679 assert(
p->nTrailSize ==
p->nRootSize );
683 for ( i = 0; i < (int)pClause->
nLits; i++ )
684 if (
p->pAssigns[lit_var(pClause->
pLits[i])] == pClause->
pLits[i] )
687 Vec_PtrPush(
p->vAntClas, Vec_IntAlloc(0) );
692 for ( i = 0; i < (int)pClause->
nLits; i++ )
693 if ( !Intp_ManEnqueue(
p, lit_neg(pClause->
pLits[i]), NULL ) )
701 if ( pConflict == NULL )
712 for ( i = 0; i < (int)pConflict->
nLits; i++ )
714 for ( j = 0; j < (int)pClause->
nLits; j++ )
715 if ( pConflict->
pLits[i] == pClause->
pLits[j] )
717 if ( j == (
int)pClause->
nLits )
720 if ( i == (
int)pConflict->
nLits )
723 Intp_ManCancelUntil(
p,
p->nRootSize );
725 Vec_PtrPush(
p->vAntClas, Vec_IntAlloc(0) );
734 Intp_ManCancelUntil(
p,
p->nRootSize );
737 if ( pClause->
nLits > 1 )
739 Intp_ManWatchClause(
p, pClause, pClause->
pLits[0] );
740 Intp_ManWatchClause(
p, pClause, pClause->
pLits[1] );
746 if ( !Intp_ManEnqueue(
p, pClause->
pLits[0], pClause ) )
757 while ( Vec_PtrSize(
p->vAntClas) <
p->pCnf->pEmpty->Id -
p->nAntStart )
758 Vec_PtrPush(
p->vAntClas, Vec_IntAlloc(0) );
767 p->nRootSize =
p->nTrailSize;
791 assert( (
int)pClause->
fA == (Counter < (
int)
p->pCnf->nClausesA) );
792 assert( (
int)pClause->
fRoot == (Counter < (
int)
p->pCnf->nRoots) );
795 assert(
p->pCnf->nClauses == Counter );
798 assert(
p->pCnf->pTail->nLits == 0 );
805 if ( pClause->
nLits > 1 )
807 Intp_ManWatchClause(
p, pClause, pClause->
pLits[0] );
808 Intp_ManWatchClause(
p, pClause, pClause->
pLits[1] );
811 if ( pClause->
nLits != 1 )
815 if ( !Intp_ManEnqueue(
p, pClause->
pLits[0], pClause ) )
823 printf(
"Found root level conflict!\n" );
835 printf(
"Found root level conflict!\n" );
840 p->nRootSize =
p->nTrailSize;
862 int nConfMax = 1000000;
866 int i, iClause, RetValue;
869 vClauses = Vec_PtrAlloc( 1000 );
872 assert( Vec_PtrSize(vClauses) == pClause->
Id );
873 Vec_PtrPush( vClauses, pClause );
880 pClause = (
Sto_Cls_t *)Vec_PtrEntry( vClauses, iClause );
883 printf(
"The core verification problem is trivially UNSAT.\n" );
887 Vec_PtrFree( vClauses );
889 RetValue =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)nConfMax, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
894 printf(
"Conflict limit is reached. " );
895 else if ( RetValue ==
l_True )
896 printf(
"UNSAT core verification FAILED. " );
898 printf(
"UNSAT core verification succeeded. " );
899 ABC_PRT(
"Time", Abc_Clock() - clk );
904 printf(
"UNSAT core verification FAILED. \n" );
925 if ( Vec_StrEntry( vVisited, iThis ) )
927 Vec_StrWriteEntry( vVisited, iThis, 1 );
929 if ( iThis < nRoots )
932 Vec_IntPush( vCore, iThis );
940 vAnt = (
Vec_Int_t *)Vec_PtrEntry( vAntClas, iThis - nRoots );
946 Vec_IntPush( vCore, iThis );
969 abctime clkTotal = Abc_Clock();
974 p->fVerbose = fVerbose;
981 if (
p->fProofWrite )
983 p->pFile = fopen(
"proof.cnf_",
"w" );
990 Vec_PtrClear(
p->vAntClas );
991 p->nAntStart =
p->pCnf->nRoots;
1002 if ( pClause->
fRoot )
1015 assert(
p->pCnf->pEmpty->Id -
p->nAntStart == Vec_PtrSize(
p->vAntClas) - 1 );
1016 Vec_PtrPush(
p->vAntClas, Vec_IntAlloc(0) );
1019 if (
p->fProofWrite )
1029 printf(
"Vars = %d. Roots = %d. Learned = %d. Resol steps = %d. Ave = %.2f. Mem = %.2f MB\n",
1030 p->pCnf->nVars,
p->pCnf->nRoots,
p->pCnf->nClauses-
p->pCnf->nRoots,
p->Counter,
1031 1.0*(
p->Counter-
p->pCnf->nRoots)/(
p->pCnf->nClauses-
p->pCnf->nRoots),
1033p->timeTotal += Abc_Clock() - clkTotal;
1037 vCore = Vec_IntAlloc( 1000 );
1038 vVisited = Vec_StrStart(
p->pCnf->pEmpty->Id+1 );
1040 Vec_StrFree( vVisited );
1042 printf(
"Root clauses = %d. Learned clauses = %d. UNSAT core size = %d.\n",
1043 p->pCnf->nRoots,
p->pCnf->nClauses-
p->pCnf->nRoots, Vec_IntSize(vCore) );
1065 int v, i, iClause, fCompl, iObj, iFrame;
1067 vClaMap = Vec_PtrAlloc( pCnf->
nClauses );
1069 Vec_PtrPush( vClaMap, pClause );
1071 fprintf( pFile,
"UNSAT contains %d learned clauses:\n", Vec_IntSize(vCore) );
1074 pClause = (
Sto_Cls_t *)Vec_PtrEntry(vClaMap, iClause);
1075 fprintf( pFile,
"%6d : %6d : ", i, iClause - pCnf->
nRoots );
1076 for ( v = 0; v < (int)pClause->
nLits; v++ )
1078 fCompl = Abc_LitIsCompl(pClause->
pLits[v]);
1079 iObj = Vec_IntEntry(vVarMap, 2*Abc_Lit2Var(pClause->
pLits[v]));
1080 iFrame = Vec_IntEntry(vVarMap, 2*Abc_Lit2Var(pClause->
pLits[v])+1);
1081 fprintf( pFile,
"%s%d(%d) ", fCompl ?
"!":
"", iObj, iFrame );
1083 if ( pClause->
nLits == 0 )
1084 fprintf( pFile,
"Empty" );
1085 fprintf( pFile,
"\n" );
1087 Vec_PtrFree( vClaMap );
#define ABC_ALLOC(type, num)
#define ABC_REALLOC(type, obj, 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
#define sat_solver_addclause
void * Intp_ManUnsatCore(Intp_Man_t *p, Sto_Man_t *pCnf, int fLearned, int fVerbose)
void Intp_ManFree(Intp_Man_t *p)
void Intp_ManUnsatCore_rec(Vec_Ptr_t *vAntClas, int iThis, Vec_Int_t *vCore, int nRoots, Vec_Str_t *vVisited, int fLearned)
void Intp_ManUnsatCoreVerify(Sto_Man_t *pCnf, Vec_Int_t *vCore)
void Intp_ManPrintResolvent(lit *pResLits, int nResLits)
void Intp_ManResize(Intp_Man_t *p)
void Intp_ManPrintClause(Intp_Man_t *p, Sto_Cls_t *pClause)
int Intp_ManProofTraceOne(Intp_Man_t *p, Sto_Cls_t *pConflict, Sto_Cls_t *pFinal)
void Intp_ManProofWriteOne(Intp_Man_t *p, Sto_Cls_t *pClause)
void Intp_ManUnsatCorePrintForBmc(FILE *pFile, Sto_Man_t *pCnf, void *vCore0, void *vVarMap0)
Sto_Cls_t * Intp_ManPropagate(Intp_Man_t *p, int Start)
Intp_Man_t * Intp_ManAlloc()
FUNCTION DEFINITIONS ///.
int Intp_ManProofRecordOne(Intp_Man_t *p, Sto_Cls_t *pClause)
int Intp_ManProcessRoots(Intp_Man_t *p)
void Intp_ManPrintInterOne(Intp_Man_t *p, Sto_Cls_t *pClause)
sat_solver * sat_solver_new(void)
void sat_solver_delete(sat_solver *s)
int Sto_ManMemoryReport(Sto_Man_t *p)
struct Intp_Man_t_ Intp_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 ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.