111 #define Pr_ManForEachClause( p, pCls ) for( pCls = p->pHead; pCls; pCls = pCls->pNext )
112 #define Pr_ManForEachClauseRoot( p, pCls ) for( pCls = p->pHead; pCls != p->pLearnt; pCls = pCls->pNext )
113 #define Pr_ManForEachClauseLearnt( p, pCls ) for( pCls = p->pLearnt; pCls; pCls = pCls->pNext )
152 p->nChunkSize = (1<<16);
154 p->nResLitsAlloc = (1<<16);
176 if ( p->nVarsAlloc < nVarsNew )
178 int nVarsAllocOld = p->nVarsAlloc;
180 if ( p->nVarsAlloc == 0 )
182 while ( p->nVarsAlloc < nVarsNew )
187 p->pSeens =
ABC_REALLOC(
char, p->pSeens, p->nVarsAlloc );
188 p->pVarTypes =
ABC_REALLOC(
char, p->pVarTypes, p->nVarsAlloc );
192 memset( p->pAssigns + nVarsAllocOld, 0xff,
sizeof(
lit) * (p->nVarsAlloc - nVarsAllocOld) );
193 memset( p->pSeens + nVarsAllocOld, 0,
sizeof(
char) * (p->nVarsAlloc - nVarsAllocOld) );
194 memset( p->pVarTypes + nVarsAllocOld, 0,
sizeof(
char) * (p->nVarsAlloc - nVarsAllocOld) );
195 memset( p->pReasons + nVarsAllocOld, 0,
sizeof(
Pr_Cls_t *) * (p->nVarsAlloc - nVarsAllocOld) );
196 memset( p->pWatches + nVarsAllocOld, 0,
sizeof(
Pr_Cls_t *) * (p->nVarsAlloc - nVarsAllocOld)*2 );
199 if ( p->nVars < nVarsNew )
216 printf(
"Runtime stats:\n" );
217 ABC_PRT(
"Reading ", p->timeRead );
219 ABC_PRT(
"Trace ", p->timeTrace );
220 ABC_PRT(
"TOTAL ", p->timeTotal );
247 if ( pClause->
pLits[0] == Lit )
254 p->pWatches[
lit_neg(Lit)] = pClause;
279 for ( i = pBeg + 1; i < pEnd; i++ )
283 for ( j = i; j > pBeg && *(j-1) > Lit; j-- )
288 for ( i = pBeg + 1; i < pEnd; i++ )
295 nSize =
sizeof(
Pr_Cls_t) +
sizeof(
lit) * (pEnd - pBeg);
300 assert( !fClauseA || fRoot );
302 p->nClausesA += fClauseA;
303 pClause->
Id = p->nClauses++;
304 pClause->
fA = fClauseA;
305 pClause->
fRoot = fRoot;
306 pClause->
nLits = pEnd - pBeg;
310 if ( p->pHead == NULL )
312 if ( p->pTail == NULL )
316 p->pTail->
pNext = pClause;
321 if ( p->pLearnt == NULL && !pClause->
fRoot )
322 p->pLearnt = pClause;
325 if ( pClause->
nLits == 0 )
328 printf(
"More than one empty clause!\n" );
348 if ( p->pChunkLast == NULL || nBytes > p->nChunkSize - p->nChunkUsed )
350 pMem = (
char *)
ABC_ALLOC(
char, p->nChunkSize );
351 *(
char **)pMem = p->pChunkLast;
352 p->pChunkLast = pMem;
353 p->nChunkUsed =
sizeof(
char *);
355 pMem = p->pChunkLast + p->nChunkUsed;
356 p->nChunkUsed += nBytes;
373 char * pMem, * pNext;
374 if ( p->pChunkLast == NULL )
376 for ( pMem = p->pChunkLast; pNext = *(
char **)pMem; pMem = pNext )
395 char * pMem, * pNext;
396 if ( p->pChunkLast == NULL )
398 Total = p->nChunkUsed;
399 for ( pMem = p->pChunkLast; pNext = *(
char **)pMem; pMem = pNext )
400 Total += p->nChunkSize;
420 Remainder = (nBits%(
sizeof(unsigned)*8));
421 nWords = (nBits/(
sizeof(unsigned)*8)) + (Remainder>0);
423 for ( w = nWords-1; w >= 0; w-- )
424 for ( i = ((w == nWords-1 && Remainder)? Remainder-1: 31); i >= 0; i-- )
425 fprintf( pFile,
"%c",
'0' + (
int)((Sign[w] & (1<<i)) > 0) );
441 printf(
"Clause %2d : ", pClause->
Id );
463 return p->pAssigns[
Var] == Lit;
464 p->pAssigns[
Var] = Lit;
465 p->pReasons[
Var] = pReason;
466 p->pTrail[p->nTrailSize++] = Lit;
486 for ( i = p->nTrailSize - 1; i >= Level; i-- )
490 p->pReasons[
Var] = NULL;
494 p->nTrailSize = Level;
510 Pr_Cls_t ** ppPrev, * pCur, * pTemp;
514 ppPrev = p->pWatches + Lit;
515 for ( pCur = p->pWatches[Lit]; pCur; pCur = *ppPrev )
518 if ( pCur->
pLits[0] == LitF )
521 pCur->
pLits[1] = LitF;
536 for ( i = 2; i < (int)pCur->
nLits; i++ )
543 pCur->
pLits[i] = LitF;
550 if ( i < (
int)pCur->
nLits )
582 for ( i = Start; i < p->nTrailSize; i++ )
610 printf(
"Clause ID = %d. Proof = %d. {", pClause->
Id, (
int)pClause->
pProof );
611 for ( i = 0; i < (int)pClause->
nLits; i++ )
612 printf(
" %d", pClause->
pLits[i] );
630 printf(
"Resolvent: {" );
631 for ( i = 0; i < nResLits; i++ )
632 printf(
" %d", pResLits[i] );
649 pClause->
pProof = (
void *)++p->Counter;
651 if ( p->fProofWrite )
654 fprintf( (FILE *)p->pManProof,
"%d", (
int)pClause->
pProof );
655 for ( v = 0; v < (int)pClause->
nLits; v++ )
656 fprintf( (FILE *)p->pManProof,
" %d",
lit_print(pClause->
pLits[v]) );
657 fprintf( (FILE *)p->pManProof,
" 0 0\n" );
675 int i, v,
Var, PrevId;
680 if ( p->fProofVerif )
682 assert( (
int)pConflict->
nLits <= p->nResLitsAlloc );
684 p->nResLits = pConflict->
nLits;
688 for ( v = 0; v < (int)pConflict->
nLits; v++ )
699 PrevId = (int)pConflict->
pProof;
700 for ( i = p->nTrailSize - 1; i >= 0; i-- )
704 if ( !p->pSeens[Var] )
709 pReason = p->pReasons[
Var];
710 if ( pReason == NULL )
715 for ( v = 1; v < (int)pReason->
nLits; v++ )
722 if ( p->fProofWrite )
723 fprintf( (FILE *)p->pManProof,
"%d * %d %d 0\n", p->Counter, PrevId, (
int)pReason->
pProof );
728 if ( p->pVarTypes[Var] == 1 )
735 if ( p->fProofVerif )
741 for ( v1 = 0; v1 < p->nResLits; v1++ )
742 if (
lit_var(p->pResLits[v1]) == Var )
744 if ( v1 == p->nResLits )
745 printf(
"Recording clause %d: Cannot find variable %d in the temporary resolvent.\n", pFinal->
Id, Var );
747 printf(
"Recording clause %d: The resolved variable %d is in the wrong polarity.\n", pFinal->
Id, Var );
751 for ( ; v1 < p->nResLits; v1++ )
752 p->pResLits[v1] = p->pResLits[v1+1];
754 for ( v2 = 1; v2 < (int)pReason->
nLits; v2++ )
756 for ( v1 = 0; v1 < p->nResLits; v1++ )
760 if ( v1 == p->nResLits )
762 if ( p->nResLits == p->nResLitsAlloc )
763 printf(
"Recording clause %d: Ran out of space for intermediate resolvent.\n, pFinal->Id" );
764 p->pResLits[ p->nResLits++ ] = pReason->
pLits[v2];
768 if ( p->pResLits[v1] == pReason->
pLits[v2] )
771 printf(
"Recording clause %d: Trying to resolve the clause with more than one opposite literal.\n", pFinal->
Id );
786 if ( p->fProofVerif )
791 for ( v1 = 0; v1 < p->nResLits; v1++ )
793 for ( v2 = 0; v2 < (int)pFinal->
nLits; v2++ )
794 if ( pFinal->
pLits[v2] == p->pResLits[v1] )
796 if ( v2 < (
int)pFinal->
nLits )
800 if ( v1 < p->nResLits )
802 printf(
"Recording clause %d: The final resolvent is wrong.\n", pFinal->
Id );
836 if ( pClause->
nLits == 0 )
837 printf(
"Error: Empty clause is attempted.\n" );
841 assert( p->nTrailSize == p->nRootSize );
842 for ( i = 0; i < (int)pClause->
nLits; i++ )
851 if ( pConflict == NULL )
864 if ( pClause->
nLits > 1 )
885 printf(
"Found last conflict after adding unit clause number %d!\n", pClause->
Id );
890 p->nRootSize = p->nTrailSize;
914 assert( (
int)pClause->
fA == (Counter < (
int)p->nClausesA) );
915 assert( (
int)pClause->
fRoot == (Counter < (
int)p->nRoots) );
918 assert( p->nClauses == Counter );
921 assert( p->pTail->nLits == 0 );
928 if ( pClause->
nLits > 1 )
934 if ( pClause->
nLits != 1 )
941 printf(
"Pr_ManProcessRoots(): Detected a root-level conflict\n" );
952 printf(
"Pr_ManProcessRoots(): Detected a root-level conflict\n" );
958 p->nRootSize = p->nTrailSize;
975 unsigned uTruths[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 };
984 for ( v = 0; v < (int)pClause->
nLits; v++ )
994 for ( v = 0; v < (int)pClause->
nLits; v++ )
997 if ( p->pVarTypes[Var] == 1 )
1001 p->pVarTypes[
Var] = -1;
1008 for ( v = 0; v < p->nVars; v++ )
1009 if ( p->pVarTypes[v] == -1 )
1010 p->pVarTypes[v] -= p->nVarsAB++;
1011 printf(
"There are %d global variables.\n", p->nVarsAB );
1024 for ( v = 0; v < (int)pClause->
nLits; v++ )
1027 if ( p->pVarTypes[Var] < 0 )
1030 pClause->
uTruth |= ~uTruths[ -p->pVarTypes[
Var]-1 ];
1032 pClause->
uTruth |= uTruths[ -p->pVarTypes[
Var]-1 ];
1064 if ( p->fProofWrite )
1065 p->pManProof = fopen(
"proof.cnf_",
"w" );
1084 printf(
"Interpolant: " );
1089 if ( p->fProofWrite )
1091 fclose( (FILE *)p->pManProof );
1092 p->pManProof = NULL;
1111 char * pCur, * pBuffer = NULL;
1112 int * pArray = NULL;
1114 int RetValue,
Counter, nNumbers, Temp;
1115 int nClauses, nClausesA, nRoots, nVars;
1118 pFile = fopen( pFileName,
"r" );
1119 if ( pFile == NULL )
1121 printf(
"Count not open input file \"%s\".\n", pFileName );
1126 pBuffer = (
char *)
ABC_ALLOC(
char, (1<<16) );
1127 for ( Counter = 0; fgets( pBuffer, (1<<16), pFile ); )
1129 if ( pBuffer[0] ==
'c' )
1131 if ( pBuffer[0] ==
'p' )
1135 RetValue = sscanf( pBuffer + 1,
"%d %d %d %d", &nVars, &nClauses, &nRoots, &nClausesA );
1136 if ( RetValue != 3 && RetValue != 4 )
1138 printf(
"Wrong input file format.\n" );
1141 pArray = (
int *)
ABC_ALLOC(
char,
sizeof(
int) * (nVars + 10) );
1145 for ( pCur = pBuffer; *pCur; pCur++ )
1146 if ( !(*pCur ==
' ' || *pCur ==
'\t' || *pCur ==
'\r' || *pCur ==
'\n') )
1156 for ( ; *pCur && *pCur ==
' '; pCur++ );
1159 sscanf( pCur,
"%d", &Temp );
1162 pArray[ nNumbers++ ] =
lit_read( Temp );
1164 for ( ; *pCur && *pCur !=
' '; pCur++ );
1167 if ( !
Pr_ManAddClause( p, (
unsigned *)pArray, (
unsigned *)pArray + nNumbers, Counter < nRoots, Counter < nClausesA ) )
1169 printf(
"Bad clause number %d.\n", Counter );
1176 if ( Counter != nClauses )
1177 printf(
"Expected %d clauses but read %d.\n", nClauses, Counter );
1181 if ( pBuffer )
ABC_FREE( pBuffer );
1247 printf(
"Vars = %d. Roots = %d. Learned = %d. Resol steps = %d. Ave = %.2f. Mem = %.2f MB\n",
1248 p->nVars, p->nRoots, p->nClauses-p->nRoots, p->Counter,
1249 1.0*(p->Counter-p->nRoots)/(p->nClauses-p->nRoots),
void Pr_ManPrintResolvent(lit *pResLits, int nResLits)
int Pr_ManProcessRoots(Pr_Man_t *p)
#define Pr_ManForEachClauseLearnt(p, pCls)
static Pr_Cls_t * Pr_ManPropagateOne(Pr_Man_t *p, lit Lit)
void Pr_ManFree(Pr_Man_t *p)
static int lit_check(lit l, int n)
static int lit_var(lit l)
#define ABC_REALLOC(type, obj, num)
#define Pr_ManForEachClauseRoot(p, pCls)
int Pr_ManProofTraceOne(Pr_Man_t *p, Pr_Cls_t *pConflict, Pr_Cls_t *pFinal)
static void Pr_ManResize(Pr_Man_t *p, int nVarsNew)
static int Pr_ManEnqueue(Pr_Man_t *p, lit Lit, Pr_Cls_t *pReason)
static lit lit_neg(lit l)
static void Pr_ManWatchClause(Pr_Man_t *p, Pr_Cls_t *pClause, lit Lit)
int Pr_ManProofWrite(Pr_Man_t *p)
Pr_Cls_t * Pr_ManPropagate(Pr_Man_t *p, int Start)
#define ABC_ALLOC(type, num)
void Pr_ManPrintClause(Pr_Cls_t *pClause)
int Pr_ManMemoryReport(Pr_Man_t *p)
static abctime Abc_Clock()
void Extra_PrintBinary_(FILE *pFile, unsigned Sign[], int nBits)
for(p=first;p->value< newval;p=p->next)
int Pr_ManProofRecordOne(Pr_Man_t *p, Pr_Cls_t *pClause)
int Pr_ManProofTest(char *pFileName)
#define Pr_ManForEachClause(p, pCls)
static void Pr_ManCancelUntil(Pr_Man_t *p, int Level)
void Pr_ManProofWriteOne(Pr_Man_t *p, Pr_Cls_t *pClause)
void Pr_ManPrintInterOne(Pr_Man_t *p, Pr_Cls_t *pClause)
void Pr_ManPrepareInter(Pr_Man_t *p)
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_HEADER_START struct Pr_Man_t_ Pr_Man_t
INCLUDES ///.
Pr_Man_t * Pr_ManAlloc(int nVarsAlloc)
FUNCTION DEFINITIONS ///.
static void Pr_ManMemoryStop(Pr_Man_t *p)
#define ABC_NAMESPACE_IMPL_START
int Pr_ManAddClause(Pr_Man_t *p, lit *pBeg, lit *pEnd, int fRoot, int fClauseA)
static lit lit_read(int s)
static int lit_sign(lit l)
static int lit_print(lit l)
Pr_Man_t * Pr_ManProofRead(char *pFileName)
static const lit LIT_UNDEF
struct Pr_Cls_t_ Pr_Cls_t
static char * Pr_ManMemoryFetch(Pr_Man_t *p, int nBytes)
static lit toLitCond(int v, int c)
ABC_NAMESPACE_IMPL_START typedef unsigned lit
DECLARATIONS ///.