Go to the source code of this file.
Data Structures | |
struct | Sto_Cls_t_ |
struct | Sto_Man_t_ |
Defines | |
#define | STO_MAX(a, b) ((a) > (b) ? (a) : (b)) |
#define | Sto_ManForEachClause(p, pCls) for( pCls = p->pHead; pCls; pCls = pCls->pNext ) |
#define | Sto_ManForEachClauseRoot(p, pCls) for( pCls = p->pHead; pCls && pCls->fRoot; pCls = pCls->pNext ) |
Typedefs | |
typedef unsigned | lit |
typedef struct Sto_Cls_t_ | Sto_Cls_t |
typedef struct Sto_Man_t_ | Sto_Man_t |
typedef struct Int_Man_t_ | Int_Man_t |
Functions | |
static lit | toLit (int v) |
static lit | toLitCond (int v, int c) |
static lit | lit_neg (lit l) |
static int | lit_var (lit l) |
static int | lit_sign (lit l) |
static int | lit_print (lit l) |
static lit | lit_read (int s) |
static int | lit_check (lit l, int n) |
Sto_Man_t * | Sto_ManAlloc () |
void | Sto_ManFree (Sto_Man_t *p) |
int | Sto_ManAddClause (Sto_Man_t *p, lit *pBeg, lit *pEnd) |
int | Sto_ManMemoryReport (Sto_Man_t *p) |
void | Sto_ManMarkRoots (Sto_Man_t *p) |
void | Sto_ManMarkClausesA (Sto_Man_t *p) |
void | Sto_ManDumpClauses (Sto_Man_t *p, char *pFileName) |
Sto_Man_t * | Sto_ManLoadClauses (char *pFileName) |
Int_Man_t * | Int_ManAlloc (int nVarsAlloc) |
void | Int_ManFree (Int_Man_t *p) |
int | Int_ManInterpolate (Int_Man_t *p, Sto_Man_t *pCnf, int fVerbose, unsigned **ppResult) |
#define Sto_ManForEachClause | ( | p, | |||
pCls | ) | for( pCls = p->pHead; pCls; pCls = pCls->pNext ) |
Definition at line 101 of file satStore.h.
#define Sto_ManForEachClauseRoot | ( | p, | |||
pCls | ) | for( pCls = p->pHead; pCls && pCls->fRoot; pCls = pCls->pNext ) |
Definition at line 102 of file satStore.h.
#define STO_MAX | ( | a, | |||
b | ) | ((a) > (b) ? (a) : (b)) |
CFile****************************************************************
FileName [pr.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Proof recording.]
Synopsis [External declarations.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [
]
Definition at line 43 of file satStore.h.
typedef struct Int_Man_t_ Int_Man_t |
Definition at line 123 of file satStore.h.
typedef unsigned lit |
INCLUDES /// PARAMETERS /// BASIC TYPES ///
Definition at line 57 of file satStore.h.
typedef struct Sto_Cls_t_ Sto_Cls_t |
Definition at line 59 of file satStore.h.
typedef struct Sto_Man_t_ Sto_Man_t |
Definition at line 73 of file satStore.h.
Int_Man_t* Int_ManAlloc | ( | int | nVarsAlloc | ) |
FUNCTION DEFINITIONS ///Function*************************************************************
Synopsis [Allocate proof manager.]
Description []
SideEffects []
SeeAlso []
Definition at line 102 of file satInter.c.
00103 { 00104 Int_Man_t * p; 00105 // allocate the manager 00106 p = (Int_Man_t *)malloc( sizeof(Int_Man_t) ); 00107 memset( p, 0, sizeof(Int_Man_t) ); 00108 // verification 00109 p->nResLitsAlloc = (1<<16); 00110 p->pResLits = malloc( sizeof(lit) * p->nResLitsAlloc ); 00111 // parameters 00112 p->fProofWrite = 0; 00113 p->fProofVerif = 1; 00114 return p; 00115 }
void Int_ManFree | ( | Int_Man_t * | p | ) |
Function*************************************************************
Synopsis [Deallocate proof manager.]
Description []
SideEffects []
SeeAlso []
Definition at line 244 of file satInter.c.
00245 { 00246 /* 00247 printf( "Runtime stats:\n" ); 00248 PRT( "BCP ", p->timeBcp ); 00249 PRT( "Trace ", p->timeTrace ); 00250 PRT( "TOTAL ", p->timeTotal ); 00251 */ 00252 free( p->pInters ); 00253 free( p->pProofNums ); 00254 free( p->pTrail ); 00255 free( p->pAssigns ); 00256 free( p->pSeens ); 00257 free( p->pVarTypes ); 00258 free( p->pReasons ); 00259 free( p->pWatches ); 00260 free( p->pResLits ); 00261 free( p ); 00262 }
Function*************************************************************
Synopsis [Computes interpolant for the given CNF.]
Description [Returns the number of common variable found and interpolant. Returns 0, if something did not work.]
SideEffects []
SeeAlso []
Definition at line 921 of file satInter.c.
00922 { 00923 Sto_Cls_t * pClause; 00924 int RetValue = 1; 00925 int clkTotal = clock(); 00926 00927 // check that the CNF makes sense 00928 assert( pCnf->nVars > 0 && pCnf->nClauses > 0 ); 00929 p->pCnf = pCnf; 00930 p->fVerbose = fVerbose; 00931 *ppResult = NULL; 00932 00933 // adjust the manager 00934 Int_ManResize( p ); 00935 00936 // prepare the interpolant computation 00937 Int_ManPrepareInter( p ); 00938 00939 // construct proof for each clause 00940 // start the proof 00941 if ( p->fProofWrite ) 00942 { 00943 p->pFile = fopen( "proof.cnf_", "w" ); 00944 p->Counter = 0; 00945 } 00946 00947 // write the root clauses 00948 Sto_ManForEachClauseRoot( p->pCnf, pClause ) 00949 Int_ManProofWriteOne( p, pClause ); 00950 00951 // propagate root level assignments 00952 if ( Int_ManProcessRoots( p ) ) 00953 { 00954 // if there is no conflict, consider learned clauses 00955 Sto_ManForEachClause( p->pCnf, pClause ) 00956 { 00957 if ( pClause->fRoot ) 00958 continue; 00959 if ( !Int_ManProofRecordOne( p, pClause ) ) 00960 { 00961 RetValue = 0; 00962 break; 00963 } 00964 } 00965 } 00966 00967 // stop the proof 00968 if ( p->fProofWrite ) 00969 { 00970 fclose( p->pFile ); 00971 p->pFile = NULL; 00972 } 00973 00974 if ( fVerbose ) 00975 { 00976 printf( "Vars = %d. Roots = %d. Learned = %d. Resol steps = %d. Ave = %.2f. Mem = %.2f Mb\n", 00977 p->pCnf->nVars, p->pCnf->nRoots, p->pCnf->nClauses-p->pCnf->nRoots, p->Counter, 00978 1.0*(p->Counter-p->pCnf->nRoots)/(p->pCnf->nClauses-p->pCnf->nRoots), 00979 1.0*Sto_ManMemoryReport(p->pCnf)/(1<<20) ); 00980 p->timeTotal += clock() - clkTotal; 00981 } 00982 00983 *ppResult = Int_ManTruthRead( p, p->pCnf->pTail ); 00984 return p->nVarsAB; 00985 }
static int lit_check | ( | lit | l, | |
int | n | |||
) | [inline, static] |
Definition at line 98 of file satStore.h.
00098 { return l >= 0 && lit_var(l) < n; }
Definition at line 93 of file satStore.h.
static int lit_print | ( | lit | l | ) | [inline, static] |
Definition at line 96 of file satStore.h.
static lit lit_read | ( | int | s | ) | [inline, static] |
Definition at line 97 of file satStore.h.
static int lit_sign | ( | lit | l | ) | [inline, static] |
Definition at line 95 of file satStore.h.
static int lit_var | ( | lit | l | ) | [inline, static] |
Definition at line 94 of file satStore.h.
Function*************************************************************
Synopsis [Adds one clause to the manager.]
Description []
SideEffects []
SeeAlso []
Definition at line 157 of file satStore.c.
00158 { 00159 Sto_Cls_t * pClause; 00160 lit Lit, * i, * j; 00161 int nSize; 00162 00163 // process the literals 00164 if ( pBeg < pEnd ) 00165 { 00166 // insertion sort 00167 for ( i = pBeg + 1; i < pEnd; i++ ) 00168 { 00169 Lit = *i; 00170 for ( j = i; j > pBeg && *(j-1) > Lit; j-- ) 00171 *j = *(j-1); 00172 *j = Lit; 00173 } 00174 // make sure there is no duplicated variables 00175 for ( i = pBeg + 1; i < pEnd; i++ ) 00176 if ( lit_var(*(i-1)) == lit_var(*i) ) 00177 { 00178 printf( "The clause contains two literals of the same variable: %d and %d.\n", *(i-1), *i ); 00179 return 0; 00180 } 00181 // check the largest var size 00182 p->nVars = STO_MAX( p->nVars, lit_var(*(pEnd-1)) + 1 ); 00183 } 00184 00185 // get memory for the clause 00186 nSize = sizeof(Sto_Cls_t) + sizeof(lit) * (pEnd - pBeg); 00187 pClause = (Sto_Cls_t *)Sto_ManMemoryFetch( p, nSize ); 00188 memset( pClause, 0, sizeof(Sto_Cls_t) ); 00189 00190 // assign the clause 00191 pClause->Id = p->nClauses++; 00192 pClause->nLits = pEnd - pBeg; 00193 memcpy( pClause->pLits, pBeg, sizeof(lit) * (pEnd - pBeg) ); 00194 00195 // add the clause to the list 00196 if ( p->pHead == NULL ) 00197 p->pHead = pClause; 00198 if ( p->pTail == NULL ) 00199 p->pTail = pClause; 00200 else 00201 { 00202 p->pTail->pNext = pClause; 00203 p->pTail = pClause; 00204 } 00205 00206 // add the empty clause 00207 if ( pClause->nLits == 0 ) 00208 { 00209 if ( p->pEmpty ) 00210 { 00211 printf( "More than one empty clause!\n" ); 00212 return 0; 00213 } 00214 p->pEmpty = pClause; 00215 } 00216 return 1; 00217 }
Sto_Man_t* Sto_ManAlloc | ( | ) |
MACRO DEFINITIONS /// FUNCTION DECLARATIONS ///
Function*************************************************************
Synopsis [Allocate proof manager.]
Description []
SideEffects []
SeeAlso []
Definition at line 118 of file satStore.c.
void Sto_ManDumpClauses | ( | Sto_Man_t * | p, | |
char * | pFileName | |||
) |
Function*************************************************************
Synopsis [Writes the stored clauses into a file.]
Description []
SideEffects []
SeeAlso []
Definition at line 275 of file satStore.c.
00276 { 00277 FILE * pFile; 00278 Sto_Cls_t * pClause; 00279 int i; 00280 // start the file 00281 pFile = fopen( pFileName, "w" ); 00282 if ( pFile == NULL ) 00283 { 00284 printf( "Error: Cannot open output file (%s).\n", pFileName ); 00285 return; 00286 } 00287 // write the data 00288 fprintf( pFile, "p %d %d %d %d\n", p->nVars, p->nClauses, p->nRoots, p->nClausesA ); 00289 Sto_ManForEachClause( p, pClause ) 00290 { 00291 for ( i = 0; i < (int)pClause->nLits; i++ ) 00292 fprintf( pFile, " %d", lit_print(pClause->pLits[i]) ); 00293 fprintf( pFile, "\n" ); 00294 } 00295 fprintf( pFile, " 0\n" ); 00296 fclose( pFile ); 00297 }
void Sto_ManFree | ( | Sto_Man_t * | p | ) |
Function*************************************************************
Synopsis [Deallocate proof manager.]
Description []
SideEffects []
SeeAlso []
Definition at line 140 of file satStore.c.
00141 { 00142 Sto_ManMemoryStop( p ); 00143 free( p ); 00144 }
Sto_Man_t* Sto_ManLoadClauses | ( | char * | pFileName | ) |
Function*************************************************************
Synopsis [Reads CNF from file.]
Description []
SideEffects []
SeeAlso []
Definition at line 354 of file satStore.c.
00355 { 00356 FILE * pFile; 00357 Sto_Man_t * p; 00358 Sto_Cls_t * pClause; 00359 char pBuffer[1024]; 00360 int nLits, nLitsAlloc, Counter, Number; 00361 lit * pLits; 00362 00363 // start the file 00364 pFile = fopen( pFileName, "r" ); 00365 if ( pFile == NULL ) 00366 { 00367 printf( "Error: Cannot open input file (%s).\n", pFileName ); 00368 return NULL; 00369 } 00370 00371 // create the manager 00372 p = Sto_ManAlloc(); 00373 00374 // alloc the array of literals 00375 nLitsAlloc = 1024; 00376 pLits = (lit *)malloc( sizeof(lit) * nLitsAlloc ); 00377 00378 // read file header 00379 p->nVars = p->nClauses = p->nRoots = p->nClausesA = 0; 00380 while ( fgets( pBuffer, 1024, pFile ) ) 00381 { 00382 if ( pBuffer[0] == 'c' ) 00383 continue; 00384 if ( pBuffer[0] == 'p' ) 00385 { 00386 sscanf( pBuffer + 1, "%d %d %d %d", p->nVars, p->nClauses, p->nRoots, p->nClausesA ); 00387 break; 00388 } 00389 printf( "Warning: Skipping line: \"%s\"\n", pBuffer ); 00390 } 00391 00392 // read the clauses 00393 nLits = 0; 00394 while ( Sto_ManLoadNumber(pFile, &Number) ) 00395 { 00396 if ( Number == 0 ) 00397 { 00398 int RetValue; 00399 RetValue = Sto_ManAddClause( p, pLits, pLits + nLits ); 00400 assert( RetValue ); 00401 nLits = 0; 00402 continue; 00403 } 00404 if ( nLits == nLitsAlloc ) 00405 { 00406 nLitsAlloc *= 2; 00407 pLits = (lit *)realloc( pLits, sizeof(lit) * nLitsAlloc ); 00408 } 00409 pLits[ nLits++ ] = lit_read(Number); 00410 } 00411 if ( nLits > 0 ) 00412 printf( "Error: The last clause was not saved.\n" ); 00413 00414 // count clauses 00415 Counter = 0; 00416 Sto_ManForEachClause( p, pClause ) 00417 Counter++; 00418 00419 // check the number of clauses 00420 if ( p->nClauses != Counter ) 00421 { 00422 printf( "Error: The actual number of clauses (%d) is different than declared (%d).\n", Counter, p->nClauses ); 00423 Sto_ManFree( p ); 00424 return NULL; 00425 } 00426 00427 free( pLits ); 00428 fclose( pFile ); 00429 return p; 00430 }
void Sto_ManMarkClausesA | ( | Sto_Man_t * | p | ) |
Function*************************************************************
Synopsis [Mark all clauses added so far as clause of A.]
Description []
SideEffects []
SeeAlso []
Definition at line 252 of file satStore.c.
00253 { 00254 Sto_Cls_t * pClause; 00255 p->nClausesA = 0; 00256 Sto_ManForEachClause( p, pClause ) 00257 { 00258 pClause->fA = 1; 00259 p->nClausesA++; 00260 } 00261 }
void Sto_ManMarkRoots | ( | Sto_Man_t * | p | ) |
Function*************************************************************
Synopsis [Mark all clauses added so far as root clauses.]
Description []
SideEffects []
SeeAlso []
Definition at line 230 of file satStore.c.
00231 { 00232 Sto_Cls_t * pClause; 00233 p->nRoots = 0; 00234 Sto_ManForEachClause( p, pClause ) 00235 { 00236 pClause->fRoot = 1; 00237 p->nRoots++; 00238 } 00239 }
int Sto_ManMemoryReport | ( | Sto_Man_t * | p | ) |
Function*************************************************************
Synopsis [Reports memory usage in bytes.]
Description []
SideEffects []
SeeAlso []
Definition at line 94 of file satStore.c.
00095 { 00096 int Total; 00097 char * pMem, * pNext; 00098 if ( p->pChunkLast == NULL ) 00099 return 0; 00100 Total = p->nChunkUsed; 00101 for ( pMem = p->pChunkLast; pNext = *(char **)pMem; pMem = pNext ) 00102 Total += p->nChunkSize; 00103 return Total; 00104 }
static lit toLit | ( | int | v | ) | [inline, static] |
Definition at line 91 of file satStore.h.
static lit toLitCond | ( | int | v, | |
int | c | |||
) | [inline, static] |
Definition at line 92 of file satStore.h.