37static const lit LIT_UNDEF = 0xffffffff;
113 p->vResLits = Vec_IntAlloc( 1000 );
134 int LargeNum = -100000000;
142 for ( v = 0; v < (int)pClause->
nLits; v++ )
143 p->pVarTypes[lit_var(pClause->
pLits[v])] = 1;
152 for ( v = 0; v < (int)pClause->
nLits; v++ )
155 if (
p->pVarTypes[
Var] == 1 )
159 p->pVarTypes[
Var] = LargeNum;
163 assert( nVarsAB <= Vec_IntSize(
p->vVarsAB) );
168 p->pVarTypes[
Var] = -(1+nVarsAB++);
171 for ( v = 0; v <
p->pCnf->nVars; v++ )
172 assert(
p->pVarTypes[v] != LargeNum );
191 if (
p->nVarsAlloc <
p->pCnf->nVars )
194 if (
p->nVarsAlloc == 0 )
196 while (
p->nVarsAlloc <
p->pCnf->nVars )
208 memset(
p->pAssigns , 0xff,
sizeof(
lit) *
p->pCnf->nVars );
209 memset(
p->pSeens , 0,
sizeof(
char) *
p->pCnf->nVars );
210 memset(
p->pVarTypes, 0,
sizeof(
int) *
p->pCnf->nVars );
218 if (
p->nClosAlloc <
p->pCnf->nClauses )
221 if (
p->nClosAlloc == 0 )
223 while (
p->nClosAlloc <
p->pCnf->nClauses )
228 memset(
p->pProofNums, 0,
sizeof(
int) *
p->pCnf->nClauses );
231 if (
p->nIntersAlloc <
p->pCnf->nClauses )
233 p->nIntersAlloc =
p->pCnf->nClauses;
266 Vec_IntFree(
p->vResLits );
287 printf(
"Clause ID = %d. Proof = %d. {", pClause->
Id, Inta_ManProofGet(
p, pClause) );
288 for ( i = 0; i < (int)pClause->
nLits; i++ )
289 printf(
" %d", pClause->
pLits[i] );
307 printf(
"Resolvent: {" );
309 printf(
" %d", Entry );
326 printf(
"Clause %2d : ", pClause->
Id );
346 assert( lit_check(Lit,
p->pCnf->nVars) );
347 if ( pClause->
pLits[0] == Lit )
348 pClause->
pNext0 =
p->pWatches[lit_neg(Lit)];
352 pClause->
pNext1 =
p->pWatches[lit_neg(Lit)];
354 p->pWatches[lit_neg(Lit)] = pClause;
371 int Var = lit_var(Lit);
372 if (
p->pAssigns[
Var] != LIT_UNDEF )
373 return p->pAssigns[
Var] == Lit;
374 p->pAssigns[
Var] = Lit;
375 p->pReasons[
Var] = pReason;
376 p->pTrail[
p->nTrailSize++] = Lit;
392static inline void Inta_ManCancelUntil(
Inta_Man_t *
p,
int Level )
396 for ( i =
p->nTrailSize - 1; i >= Level; i-- )
399 Var = lit_var( Lit );
400 p->pReasons[
Var] = NULL;
401 p->pAssigns[
Var] = LIT_UNDEF;
404 p->nTrailSize = Level;
421 lit LitF = lit_neg(Lit);
424 ppPrev =
p->pWatches + Lit;
425 for ( pCur =
p->pWatches[Lit]; pCur; pCur = *ppPrev )
428 if ( pCur->
pLits[0] == LitF )
431 pCur->
pLits[1] = LitF;
439 if ( pCur->
pLits[0] ==
p->pAssigns[lit_var(pCur->
pLits[0])] )
446 for ( i = 2; i < (int)pCur->
nLits; i++ )
449 if ( lit_neg(pCur->
pLits[i]) ==
p->pAssigns[lit_var(pCur->
pLits[i])] )
453 pCur->
pLits[i] = LitF;
457 Inta_ManWatchClause(
p, pCur, pCur->
pLits[1] );
460 if ( i < (
int)pCur->
nLits )
464 if ( Inta_ManEnqueue(
p, pCur->
pLits[0], pCur) )
492 for ( i = Start; i <
p->nTrailSize; i++ )
494 pClause = Inta_ManPropagateOne(
p,
p->pTrail[i] );
497p->timeBcp += Abc_Clock() - clk;
501p->timeBcp += Abc_Clock() - clk;
519 Inta_ManProofSet(
p, pClause, ++
p->Counter );
521 if (
p->fProofWrite )
524 fprintf(
p->pFile,
"%d", Inta_ManProofGet(
p, pClause) );
525 for ( v = 0; v < (int)pClause->
nLits; v++ )
526 fprintf(
p->pFile,
" %d", lit_print(pClause->
pLits[v]) );
527 fprintf(
p->pFile,
" 0 0\n" );
545 int i, v,
Var, PrevId;
550 if (
p->fProofVerif )
552 Vec_IntClear(
p->vResLits );
553 for ( i = 0; i < (int)pConflict->
nLits; i++ )
554 Vec_IntPush(
p->vResLits, pConflict->
pLits[i] );
558 for ( v = 0; v < (int)pConflict->
nLits; v++ )
559 p->pSeens[lit_var(pConflict->
pLits[v])] = 1;
565 if (
p->pCnf->nClausesA )
566 Inta_ManAigCopy(
p, Inta_ManAigRead(
p, pFinal), Inta_ManAigRead(
p, pConflict) );
569 PrevId = Inta_ManProofGet(
p, pConflict);
570 for ( i =
p->nTrailSize - 1; i >= 0; i-- )
573 Var = lit_var(
p->pTrail[i]);
574 if ( !
p->pSeens[
Var] )
579 pReason =
p->pReasons[
Var];
580 if ( pReason == NULL )
585 for ( v = 1; v < (int)pReason->
nLits; v++ )
586 p->pSeens[lit_var(pReason->
pLits[v])] = 1;
589 assert( Inta_ManProofGet(
p, pReason) > 0 );
591 if (
p->fProofWrite )
592 fprintf(
p->pFile,
"%d * %d %d 0\n",
p->Counter, PrevId, Inta_ManProofGet(
p, pReason) );
595 if (
p->pCnf->nClausesA )
597 if (
p->pVarTypes[
Var] == 1 )
598 Inta_ManAigOr(
p, Inta_ManAigRead(
p, pFinal), Inta_ManAigRead(
p, pReason) );
600 Inta_ManAigAnd(
p, Inta_ManAigRead(
p, pFinal), Inta_ManAigRead(
p, pReason) );
604 if (
p->fProofVerif )
606 int v1, v2, Entry = -1;
611 if ( lit_var(Entry) ==
Var )
613 if ( v1 == Vec_IntSize(
p->vResLits) )
614 printf(
"Recording clause %d: Cannot find variable %d in the temporary resolvent.\n", pFinal->
Id,
Var );
615 if ( Entry != lit_neg(pReason->
pLits[0]) )
616 printf(
"Recording clause %d: The resolved variable %d is in the wrong polarity.\n", pFinal->
Id,
Var );
619 Vec_IntRemove(
p->vResLits, Entry );
621 for ( v2 = 1; v2 < (int)pReason->
nLits; v2++ )
624 if ( lit_var(Entry) == lit_var(pReason->
pLits[v2]) )
627 if ( v1 == Vec_IntSize(
p->vResLits) )
629 Vec_IntPush(
p->vResLits, pReason->
pLits[v2] );
633 if ( Entry == pReason->
pLits[v2] )
636 printf(
"Recording clause %d: Trying to resolve the clause with more than one opposite literal.\n", pFinal->
Id );
650 if (
p->fProofVerif )
652 int v1, v2, Entry = -1;
657 for ( v2 = 0; v2 < (int)pFinal->
nLits; v2++ )
658 if ( pFinal->
pLits[v2] == Entry )
660 if ( v2 < (
int)pFinal->
nLits )
664 if ( v1 < Vec_IntSize(
p->vResLits) )
666 printf(
"Recording clause %d: The final resolvent is wrong.\n", pFinal->
Id );
675 if ( Vec_IntSize(
p->vResLits) != (
int)pFinal->
nLits )
677 for ( v1 = 0; v1 < (int)pFinal->
nLits; v1++ )
680 if ( pFinal->
pLits[v1] == Entry )
682 if ( v2 < Vec_IntSize(
p->vResLits) )
686 for ( v2 = v1; v2 < (int)pFinal->
nLits; v2++ )
690 assert( Vec_IntSize(
p->vResLits) == (
int)pFinal->
nLits );
693p->timeTrace += Abc_Clock() - clk;
696 if (
p->pCnf->nClausesA )
700 Inta_ManProofSet(
p, pFinal,
p->Counter );
702 assert(
p->pProofNums[pFinal->
Id-1] !=
p->Counter );
726 if ( pClause->
nLits == 0 )
727 printf(
"Error: Empty clause is attempted.\n" );
730 assert(
p->nTrailSize ==
p->nRootSize );
734 for ( i = 0; i < (int)pClause->
nLits; i++ )
735 if (
p->pAssigns[lit_var(pClause->
pLits[i])] == pClause->
pLits[i] )
739 for ( i = 0; i < (int)pClause->
nLits; i++ )
740 if ( !Inta_ManEnqueue(
p, lit_neg(pClause->
pLits[i]), NULL ) )
748 if ( pConflict == NULL )
759 for ( i = 0; i < (int)pConflict->
nLits; i++ )
761 for ( j = 0; j < (int)pClause->
nLits; j++ )
762 if ( pConflict->
pLits[i] == pClause->
pLits[j] )
764 if ( j == (
int)pClause->
nLits )
767 if ( i == (
int)pConflict->
nLits )
770 Inta_ManCancelUntil(
p,
p->nRootSize );
779 Inta_ManCancelUntil(
p,
p->nRootSize );
782 if ( pClause->
nLits > 1 )
784 Inta_ManWatchClause(
p, pClause, pClause->
pLits[0] );
785 Inta_ManWatchClause(
p, pClause, pClause->
pLits[1] );
791 if ( !Inta_ManEnqueue(
p, pClause->
pLits[0], pClause ) )
809 p->nRootSize =
p->nTrailSize;
833 assert( (
int)pClause->
fA == (Counter < (
int)
p->pCnf->nClausesA) );
834 assert( (
int)pClause->
fRoot == (Counter < (
int)
p->pCnf->nRoots) );
837 assert(
p->pCnf->nClauses == Counter );
840 assert(
p->pCnf->pTail->nLits == 0 );
847 if ( pClause->
nLits > 1 )
849 Inta_ManWatchClause(
p, pClause, pClause->
pLits[0] );
850 Inta_ManWatchClause(
p, pClause, pClause->
pLits[1] );
853 if ( pClause->
nLits != 1 )
857 if ( !Inta_ManEnqueue(
p, pClause->
pLits[0], pClause ) )
865 printf(
"Found root level conflict!\n" );
877 printf(
"Found root level conflict!\n" );
882 p->nRootSize =
p->nTrailSize;
907 Inta_ManAigFill(
p, Inta_ManAigRead(
p, pClause) );
912 Inta_ManAigClear(
p, Inta_ManAigRead(
p, pClause) );
913 for ( v = 0; v < (int)pClause->
nLits; v++ )
916 if (
p->pVarTypes[
Var] < 0 )
918 VarAB = -
p->pVarTypes[
Var]-1;
919 assert( VarAB >= 0 && VarAB < Vec_IntSize(
p->vVarsAB) );
920 if ( lit_sign(pClause->
pLits[v]) )
921 Inta_ManAigOrNotVar(
p, Inta_ManAigRead(
p, pClause), VarAB );
923 Inta_ManAigOrVar(
p, Inta_ManAigRead(
p, pClause), VarAB );
950 abctime clkTotal = Abc_Clock();
952 if ( TimeToStop && Abc_Clock() > TimeToStop )
958 p->fVerbose = fVerbose;
971 if (
p->fProofWrite )
973 p->pFile = fopen(
"proof.cnf_",
"w" );
981 if ( TimeToStop && Abc_Clock() > TimeToStop )
995 if ( pClause->
fRoot )
1002 if ( TimeToStop && Abc_Clock() > TimeToStop )
1012 if (
p->fProofWrite )
1022 printf(
"Vars = %d. Roots = %d. Learned = %d. Resol steps = %d. Ave = %.2f. Mem = %.2f MB ",
1023 p->pCnf->nVars,
p->pCnf->nRoots,
p->pCnf->nClauses-
p->pCnf->nRoots,
p->Counter,
1024 1.0*(
p->Counter-
p->pCnf->nRoots)/(
p->pCnf->nClauses-
p->pCnf->nRoots),
1026 Abc_PrintTime( 1,
"Time", Abc_Clock() - clkTotal );
1027p->timeTotal += Abc_Clock() - clkTotal;
1030 pObj = *Inta_ManAigRead(
p,
p->pCnf->pTail );
1058 pMiter = Aig_ManConst1(
p);
1061 if ( fClausesA ^ pClause->
fA )
1064 pSum = Aig_ManConst0(
p);
1065 for ( v = 0; v < (int)pClause->
nLits; v++ )
1076 pSum =
Aig_Or(
p, pSum, pLit );
1078 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
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 ///.
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 ///.
Sto_Cls_t * Inta_ManPropagate(Inta_Man_t *p, int Start)
void Inta_ManPrepareInter(Inta_Man_t *p)
int Inta_ManGlobalVars(Inta_Man_t *p)
void Inta_ManPrintResolvent(Vec_Int_t *vResLits)
void * Inta_ManInterpolate(Inta_Man_t *p, Sto_Man_t *pCnf, abctime TimeToStop, void *vVarsAB, int fVerbose)
Inta_Man_t * Inta_ManAlloc()
FUNCTION DEFINITIONS ///.
Aig_Man_t * Inta_ManDeriveClauses(Inta_Man_t *pMan, Sto_Man_t *pCnf, int fClausesA)
int Inta_ManProofRecordOne(Inta_Man_t *p, Sto_Cls_t *pClause)
void Inta_ManPrintClause(Inta_Man_t *p, Sto_Cls_t *pClause)
int Inta_ManProofTraceOne(Inta_Man_t *p, Sto_Cls_t *pConflict, Sto_Cls_t *pFinal)
void Inta_ManFree(Inta_Man_t *p)
void Inta_ManResize(Inta_Man_t *p)
int Inta_ManProcessRoots(Inta_Man_t *p)
void Inta_ManPrintInterOne(Inta_Man_t *p, Sto_Cls_t *pClause)
void Inta_ManProofWriteOne(Inta_Man_t *p, Sto_Cls_t *pClause)
int Sto_ManMemoryReport(Sto_Man_t *p)
#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)
struct Inta_Man_t_ Inta_Man_t
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.