src/sat/bsat/satInter.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include "satStore.h"
Include dependency graph for satInter.c:

Go to the source code of this file.

Data Structures

struct  Int_Man_t_

Functions

static unsigned * Int_ManTruthRead (Int_Man_t *p, Sto_Cls_t *pCls)
static void Int_ManTruthClear (unsigned *p, int nWords)
static void Int_ManTruthFill (unsigned *p, int nWords)
static void Int_ManTruthCopy (unsigned *p, unsigned *q, int nWords)
static void Int_ManTruthAnd (unsigned *p, unsigned *q, int nWords)
static void Int_ManTruthOr (unsigned *p, unsigned *q, int nWords)
static void Int_ManTruthOrNot (unsigned *p, unsigned *q, int nWords)
static int Int_ManProofGet (Int_Man_t *p, Sto_Cls_t *pCls)
static void Int_ManProofSet (Int_Man_t *p, Sto_Cls_t *pCls, int n)
Int_Man_tInt_ManAlloc (int nVarsAlloc)
int Int_ManGlobalVars (Int_Man_t *p)
void Int_ManResize (Int_Man_t *p)
void Int_ManFree (Int_Man_t *p)
void Int_ManPrintClause (Int_Man_t *p, Sto_Cls_t *pClause)
void Int_ManPrintResolvent (lit *pResLits, int nResLits)
void Extra_PrintBinary__ (FILE *pFile, unsigned Sign[], int nBits)
void Int_ManPrintInterOne (Int_Man_t *p, Sto_Cls_t *pClause)
static void Int_ManWatchClause (Int_Man_t *p, Sto_Cls_t *pClause, lit Lit)
static int Int_ManEnqueue (Int_Man_t *p, lit Lit, Sto_Cls_t *pReason)
static void Int_ManCancelUntil (Int_Man_t *p, int Level)
static Sto_Cls_tInt_ManPropagateOne (Int_Man_t *p, lit Lit)
Sto_Cls_tInt_ManPropagate (Int_Man_t *p, int Start)
void Int_ManProofWriteOne (Int_Man_t *p, Sto_Cls_t *pClause)
int Int_ManProofTraceOne (Int_Man_t *p, Sto_Cls_t *pConflict, Sto_Cls_t *pFinal)
int Int_ManProofRecordOne (Int_Man_t *p, Sto_Cls_t *pClause)
int Int_ManProcessRoots (Int_Man_t *p)
void Int_ManPrepareInter (Int_Man_t *p)
int Int_ManInterpolate (Int_Man_t *p, Sto_Man_t *pCnf, int fVerbose, unsigned **ppResult)

Variables

static const lit LIT_UNDEF = 0xffffffff

Function Documentation

void Extra_PrintBinary__ ( FILE *  pFile,
unsigned  Sign[],
int  nBits 
)

Function*************************************************************

Synopsis [Records the proof.]

Description []

SideEffects []

SeeAlso []

Definition at line 318 of file satInter.c.

00319 {
00320     int Remainder, nWords;
00321     int w, i;
00322 
00323     Remainder = (nBits%(sizeof(unsigned)*8));
00324     nWords    = (nBits/(sizeof(unsigned)*8)) + (Remainder>0);
00325 
00326     for ( w = nWords-1; w >= 0; w-- )
00327         for ( i = ((w == nWords-1 && Remainder)? Remainder-1: 31); i >= 0; i-- )
00328             fprintf( pFile, "%c", '0' + (int)((Sign[w] & (1<<i)) > 0) );
00329 }

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 }

static void Int_ManCancelUntil ( Int_Man_t p,
int  Level 
) [inline, static]

Function*************************************************************

Synopsis [Records implication.]

Description []

SideEffects []

SeeAlso []

Definition at line 410 of file satInter.c.

00411 {
00412     lit Lit;
00413     int i, Var;
00414     for ( i = p->nTrailSize - 1; i >= Level; i-- )
00415     {
00416         Lit = p->pTrail[i];
00417         Var = lit_var( Lit );
00418         p->pReasons[Var] = NULL;
00419         p->pAssigns[Var] = LIT_UNDEF;
00420 //printf( "cancelling var %d\n", Var );
00421     }
00422     p->nTrailSize = Level;
00423 }

static int Int_ManEnqueue ( Int_Man_t p,
lit  Lit,
Sto_Cls_t pReason 
) [inline, static]

Function*************************************************************

Synopsis [Records implication.]

Description []

SideEffects []

SeeAlso []

Definition at line 387 of file satInter.c.

00388 {
00389     int Var = lit_var(Lit);
00390     if ( p->pAssigns[Var] != LIT_UNDEF )
00391         return p->pAssigns[Var] == Lit;
00392     p->pAssigns[Var] = Lit;
00393     p->pReasons[Var] = pReason;
00394     p->pTrail[p->nTrailSize++] = Lit;
00395 //printf( "assigning var %d value %d\n", Var, !lit_sign(Lit) );
00396     return 1;
00397 }

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 }

int Int_ManGlobalVars ( Int_Man_t p  ) 

Function*************************************************************

Synopsis [Count common variables in the clauses of A and B.]

Description []

SideEffects []

SeeAlso []

Definition at line 128 of file satInter.c.

00129 {
00130     Sto_Cls_t * pClause;
00131     int Var, nVarsAB, v;
00132 
00133     // mark the variable encountered in the clauses of A
00134     Sto_ManForEachClauseRoot( p->pCnf, pClause )
00135     {
00136         if ( !pClause->fA )
00137             break;
00138         for ( v = 0; v < (int)pClause->nLits; v++ )
00139             p->pVarTypes[lit_var(pClause->pLits[v])] = 1;
00140     }
00141 
00142     // check variables that appear in clauses of B
00143     nVarsAB = 0;
00144     Sto_ManForEachClauseRoot( p->pCnf, pClause )
00145     {
00146         if ( pClause->fA )
00147             continue;
00148         for ( v = 0; v < (int)pClause->nLits; v++ )
00149         {
00150             Var = lit_var(pClause->pLits[v]);
00151             if ( p->pVarTypes[Var] == 1 ) // var of A
00152             {
00153                 // change it into a global variable
00154                 nVarsAB++;
00155                 p->pVarTypes[Var] = -1;
00156             }
00157         }
00158     }
00159 
00160     // order global variables
00161     nVarsAB = 0;
00162     for ( v = 0; v < p->pCnf->nVars; v++ )
00163         if ( p->pVarTypes[v] == -1 )
00164             p->pVarTypes[v] -= nVarsAB++;
00165 //printf( "There are %d global variables.\n", nVarsAB );
00166     return nVarsAB;
00167 }

int Int_ManInterpolate ( Int_Man_t p,
Sto_Man_t pCnf,
int  fVerbose,
unsigned **  ppResult 
)

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 }

void Int_ManPrepareInter ( Int_Man_t p  ) 

Function*************************************************************

Synopsis [Records the proof.]

Description []

SideEffects []

SeeAlso []

Definition at line 864 of file satInter.c.

00865 {
00866     // elementary truth tables
00867     unsigned uTruths[8][8] = {
00868         { 0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA },
00869         { 0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC },
00870         { 0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0 },
00871         { 0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00 },
00872         { 0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000 }, 
00873         { 0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF }, 
00874         { 0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF }, 
00875         { 0x00000000,0x00000000,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF } 
00876     };
00877     Sto_Cls_t * pClause;
00878     int Var, VarAB, v;
00879     assert( p->nVarsAB <= 8 );
00880 
00881     // set interpolants for root clauses
00882     Sto_ManForEachClauseRoot( p->pCnf, pClause )
00883     {
00884         if ( !pClause->fA ) // clause of B
00885         {
00886             Int_ManTruthFill( Int_ManTruthRead(p, pClause), p->nWords );
00887 //            Int_ManPrintInterOne( p, pClause );
00888             continue;
00889         }
00890         // clause of A
00891         Int_ManTruthClear( Int_ManTruthRead(p, pClause), p->nWords );
00892         for ( v = 0; v < (int)pClause->nLits; v++ )
00893         {
00894             Var = lit_var(pClause->pLits[v]);
00895             if ( p->pVarTypes[Var] < 0 ) // global var
00896             {
00897                 VarAB = -p->pVarTypes[Var]-1;
00898                 assert( VarAB >= 0 && VarAB < p->nVarsAB );
00899                 if ( lit_sign(pClause->pLits[v]) ) // negative var
00900                     Int_ManTruthOrNot( Int_ManTruthRead(p, pClause), uTruths[VarAB], p->nWords );
00901                 else
00902                     Int_ManTruthOr( Int_ManTruthRead(p, pClause), uTruths[VarAB], p->nWords );
00903             }
00904         }
00905 //        Int_ManPrintInterOne( p, pClause );
00906     }
00907 }

void Int_ManPrintClause ( Int_Man_t p,
Sto_Cls_t pClause 
)

Function*************************************************************

Synopsis [Prints the clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 278 of file satInter.c.

00279 {
00280     int i;
00281     printf( "Clause ID = %d. Proof = %d. {", pClause->Id, Int_ManProofGet(p, pClause) );
00282     for ( i = 0; i < (int)pClause->nLits; i++ )
00283         printf( " %d", pClause->pLits[i] );
00284     printf( " }\n" );
00285 }

void Int_ManPrintInterOne ( Int_Man_t p,
Sto_Cls_t pClause 
)

Function*************************************************************

Synopsis [Prints the interpolant for one clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 342 of file satInter.c.

00343 {
00344     printf( "Clause %2d :  ", pClause->Id );
00345     Extra_PrintBinary__( stdout, Int_ManTruthRead(p, pClause), (1 << p->nVarsAB) );
00346     printf( "\n" );
00347 }

void Int_ManPrintResolvent ( lit pResLits,
int  nResLits 
)

Function*************************************************************

Synopsis [Prints the resolvent.]

Description []

SideEffects []

SeeAlso []

Definition at line 298 of file satInter.c.

00299 {
00300     int i;
00301     printf( "Resolvent: {" );
00302     for ( i = 0; i < nResLits; i++ )
00303         printf( " %d", pResLits[i] );
00304     printf( " }\n" );
00305 }

int Int_ManProcessRoots ( Int_Man_t p  ) 

Function*************************************************************

Synopsis [Propagate the root clauses.]

Description []

SideEffects []

SeeAlso []

Definition at line 795 of file satInter.c.

00796 {
00797     Sto_Cls_t * pClause;
00798     int Counter;
00799 
00800     // make sure the root clauses are preceeding the learnt clauses
00801     Counter = 0;
00802     Sto_ManForEachClause( p->pCnf, pClause )
00803     {
00804         assert( (int)pClause->fA    == (Counter < (int)p->pCnf->nClausesA) );
00805         assert( (int)pClause->fRoot == (Counter < (int)p->pCnf->nRoots)    );
00806         Counter++;
00807     }
00808     assert( p->pCnf->nClauses == Counter );
00809 
00810     // make sure the last clause if empty
00811     assert( p->pCnf->pTail->nLits == 0 );
00812 
00813     // go through the root unit clauses
00814     p->nTrailSize = 0;
00815     Sto_ManForEachClauseRoot( p->pCnf, pClause )
00816     {
00817         // create watcher lists for the root clauses
00818         if ( pClause->nLits > 1 )
00819         {
00820             Int_ManWatchClause( p, pClause, pClause->pLits[0] );
00821             Int_ManWatchClause( p, pClause, pClause->pLits[1] );
00822         }
00823         // empty clause and large clauses
00824         if ( pClause->nLits != 1 )
00825             continue;
00826         // unit clause
00827         assert( lit_check(pClause->pLits[0], p->pCnf->nVars) );
00828         if ( !Int_ManEnqueue( p, pClause->pLits[0], pClause ) )
00829         {
00830             // detected root level conflict
00831             printf( "Error in Int_ManProcessRoots(): Detected a root-level conflict too early!\n" );
00832             assert( 0 );
00833             return 0;
00834         }
00835     }
00836 
00837     // propagate the root unit clauses
00838     pClause = Int_ManPropagate( p, 0 );
00839     if ( pClause )
00840     {
00841         // detected root level conflict
00842         Int_ManProofTraceOne( p, pClause, p->pCnf->pEmpty );
00843         if ( p->fVerbose )
00844             printf( "Found root level conflict!\n" );
00845         return 0;
00846     }
00847 
00848     // set the root level
00849     p->nRootSize = p->nTrailSize;
00850     return 1;
00851 }

static int Int_ManProofGet ( Int_Man_t p,
Sto_Cls_t pCls 
) [inline, static]

Definition at line 84 of file satInter.c.

00084 { return p->pProofNums[pCls->Id];  }

int Int_ManProofRecordOne ( Int_Man_t p,
Sto_Cls_t pClause 
)

Function*************************************************************

Synopsis [Records the proof for one clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 718 of file satInter.c.

00719 {
00720     Sto_Cls_t * pConflict;
00721     int i;
00722 
00723     // empty clause never ends up there
00724     assert( pClause->nLits > 0 );
00725     if ( pClause->nLits == 0 )
00726         printf( "Error: Empty clause is attempted.\n" );
00727 
00728     // add assumptions to the trail
00729     assert( !pClause->fRoot );
00730     assert( p->nTrailSize == p->nRootSize );
00731     for ( i = 0; i < (int)pClause->nLits; i++ )
00732         if ( !Int_ManEnqueue( p, lit_neg(pClause->pLits[i]), NULL ) )
00733         {
00734             assert( 0 ); // impossible
00735             return 0;
00736         }
00737 
00738     // propagate the assumptions
00739     pConflict = Int_ManPropagate( p, p->nRootSize );
00740     if ( pConflict == NULL )
00741     {
00742         assert( 0 ); // cannot prove
00743         return 0;
00744     }
00745 
00746     // construct the proof
00747     Int_ManProofTraceOne( p, pConflict, pClause );
00748 
00749     // undo to the root level
00750     Int_ManCancelUntil( p, p->nRootSize );
00751 
00752     // add large clauses to the watched lists
00753     if ( pClause->nLits > 1 )
00754     {
00755         Int_ManWatchClause( p, pClause, pClause->pLits[0] );
00756         Int_ManWatchClause( p, pClause, pClause->pLits[1] );
00757         return 1;
00758     }
00759     assert( pClause->nLits == 1 );
00760 
00761     // if the clause proved is unit, add it and propagate
00762     if ( !Int_ManEnqueue( p, pClause->pLits[0], pClause ) )
00763     {
00764         assert( 0 ); // impossible
00765         return 0;
00766     }
00767 
00768     // propagate the assumption
00769     pConflict = Int_ManPropagate( p, p->nRootSize );
00770     if ( pConflict )
00771     {
00772         // construct the proof
00773         Int_ManProofTraceOne( p, pConflict, p->pCnf->pEmpty );
00774         if ( p->fVerbose )
00775             printf( "Found last conflict after adding unit clause number %d!\n", pClause->Id );
00776         return 0;
00777     }
00778 
00779     // update the root level
00780     p->nRootSize = p->nTrailSize;
00781     return 1;
00782 }

static void Int_ManProofSet ( Int_Man_t p,
Sto_Cls_t pCls,
int  n 
) [inline, static]

Definition at line 85 of file satInter.c.

00085 { p->pProofNums[pCls->Id] = n;     }

int Int_ManProofTraceOne ( Int_Man_t p,
Sto_Cls_t pConflict,
Sto_Cls_t pFinal 
)

Function*************************************************************

Synopsis [Traces the proof for one clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 560 of file satInter.c.

00561 {
00562     Sto_Cls_t * pReason;
00563     int i, v, Var, PrevId;
00564     int fPrint = 0;
00565     int clk = clock();
00566 
00567     // collect resolvent literals
00568     if ( p->fProofVerif )
00569     {
00570         assert( (int)pConflict->nLits <= p->nResLitsAlloc );
00571         memcpy( p->pResLits, pConflict->pLits, sizeof(lit) * pConflict->nLits );
00572         p->nResLits = pConflict->nLits;
00573     }
00574 
00575     // mark all the variables in the conflict as seen
00576     for ( v = 0; v < (int)pConflict->nLits; v++ )
00577         p->pSeens[lit_var(pConflict->pLits[v])] = 1;
00578 
00579     // start the anticedents
00580 //    pFinal->pAntis = Vec_PtrAlloc( 32 );
00581 //    Vec_PtrPush( pFinal->pAntis, pConflict );
00582 
00583     if ( p->pCnf->nClausesA )
00584         Int_ManTruthCopy( Int_ManTruthRead(p, pFinal), Int_ManTruthRead(p, pConflict), p->nWords );
00585 
00586     // follow the trail backwards
00587     PrevId = Int_ManProofGet(p, pConflict);
00588     for ( i = p->nTrailSize - 1; i >= 0; i-- )
00589     {
00590         // skip literals that are not involved
00591         Var = lit_var(p->pTrail[i]);
00592         if ( !p->pSeens[Var] )
00593             continue;
00594         p->pSeens[Var] = 0;
00595 
00596         // skip literals of the resulting clause
00597         pReason = p->pReasons[Var];
00598         if ( pReason == NULL )
00599             continue;
00600         assert( p->pTrail[i] == pReason->pLits[0] );
00601 
00602         // add the variables to seen
00603         for ( v = 1; v < (int)pReason->nLits; v++ )
00604             p->pSeens[lit_var(pReason->pLits[v])] = 1;
00605 
00606 
00607         // record the reason clause
00608         assert( Int_ManProofGet(p, pReason) > 0 );
00609         p->Counter++;
00610         if ( p->fProofWrite )
00611             fprintf( p->pFile, "%d * %d %d 0\n", p->Counter, PrevId, Int_ManProofGet(p, pReason) );
00612         PrevId = p->Counter;
00613 
00614         if ( p->pCnf->nClausesA )
00615         {
00616             if ( p->pVarTypes[Var] == 1 ) // var of A
00617                 Int_ManTruthOr( Int_ManTruthRead(p, pFinal), Int_ManTruthRead(p, pReason), p->nWords );
00618             else
00619                 Int_ManTruthAnd( Int_ManTruthRead(p, pFinal), Int_ManTruthRead(p, pReason), p->nWords );
00620         }
00621  
00622         // resolve the temporary resolvent with the reason clause
00623         if ( p->fProofVerif )
00624         {
00625             int v1, v2; 
00626             if ( fPrint )
00627                 Int_ManPrintResolvent( p->pResLits, p->nResLits );
00628             // check that the var is present in the resolvent
00629             for ( v1 = 0; v1 < p->nResLits; v1++ )
00630                 if ( lit_var(p->pResLits[v1]) == Var )
00631                     break;
00632             if ( v1 == p->nResLits )
00633                 printf( "Recording clause %d: Cannot find variable %d in the temporary resolvent.\n", pFinal->Id, Var );
00634             if ( p->pResLits[v1] != lit_neg(pReason->pLits[0]) )
00635                 printf( "Recording clause %d: The resolved variable %d is in the wrong polarity.\n", pFinal->Id, Var );
00636             // remove this variable from the resolvent
00637             assert( lit_var(p->pResLits[v1]) == Var );
00638             p->nResLits--;
00639             for ( ; v1 < p->nResLits; v1++ )
00640                 p->pResLits[v1] = p->pResLits[v1+1];
00641             // add variables of the reason clause
00642             for ( v2 = 1; v2 < (int)pReason->nLits; v2++ )
00643             {
00644                 for ( v1 = 0; v1 < p->nResLits; v1++ )
00645                     if ( lit_var(p->pResLits[v1]) == lit_var(pReason->pLits[v2]) )
00646                         break;
00647                 // if it is a new variable, add it to the resolvent
00648                 if ( v1 == p->nResLits ) 
00649                 {
00650                     if ( p->nResLits == p->nResLitsAlloc )
00651                         printf( "Recording clause %d: Ran out of space for intermediate resolvent.\n, pFinal->Id" );
00652                     p->pResLits[ p->nResLits++ ] = pReason->pLits[v2];
00653                     continue;
00654                 }
00655                 // if the variable is the same, the literal should be the same too
00656                 if ( p->pResLits[v1] == pReason->pLits[v2] )
00657                     continue;
00658                 // the literal is different
00659                 printf( "Recording clause %d: Trying to resolve the clause with more than one opposite literal.\n", pFinal->Id );
00660             }
00661         }
00662 
00663 //        Vec_PtrPush( pFinal->pAntis, pReason );
00664     }
00665 
00666     // unmark all seen variables
00667 //    for ( i = p->nTrailSize - 1; i >= 0; i-- )
00668 //        p->pSeens[lit_var(p->pTrail[i])] = 0;
00669     // check that the literals are unmarked
00670 //    for ( i = p->nTrailSize - 1; i >= 0; i-- )
00671 //        assert( p->pSeens[lit_var(p->pTrail[i])] == 0 );
00672 
00673     // use the resulting clause to check the correctness of resolution
00674     if ( p->fProofVerif )
00675     {
00676         int v1, v2; 
00677         if ( fPrint )
00678             Int_ManPrintResolvent( p->pResLits, p->nResLits );
00679         for ( v1 = 0; v1 < p->nResLits; v1++ )
00680         {
00681             for ( v2 = 0; v2 < (int)pFinal->nLits; v2++ )
00682                 if ( pFinal->pLits[v2] == p->pResLits[v1] )
00683                     break;
00684             if ( v2 < (int)pFinal->nLits )
00685                 continue;
00686             break;
00687         }
00688         if ( v1 < p->nResLits )
00689         {
00690             printf( "Recording clause %d: The final resolvent is wrong.\n", pFinal->Id );
00691             Int_ManPrintClause( p, pConflict );
00692             Int_ManPrintResolvent( p->pResLits, p->nResLits );
00693             Int_ManPrintClause( p, pFinal );
00694         }
00695     }
00696 p->timeTrace += clock() - clk;
00697 
00698     // return the proof pointer 
00699     if ( p->pCnf->nClausesA )
00700     {
00701 //        Int_ManPrintInterOne( p, pFinal );
00702     }
00703     Int_ManProofSet( p, pFinal, p->Counter );
00704     return p->Counter;
00705 }

void Int_ManProofWriteOne ( Int_Man_t p,
Sto_Cls_t pClause 
)

Function*************************************************************

Synopsis [Writes one root clause into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 535 of file satInter.c.

00536 {
00537     Int_ManProofSet( p, pClause, ++p->Counter );
00538 
00539     if ( p->fProofWrite )
00540     {
00541         int v;
00542         fprintf( p->pFile, "%d", Int_ManProofGet(p, pClause) );
00543         for ( v = 0; v < (int)pClause->nLits; v++ )
00544             fprintf( p->pFile, " %d", lit_print(pClause->pLits[v]) );
00545         fprintf( p->pFile, " 0 0\n" );
00546     }
00547 }

Sto_Cls_t* Int_ManPropagate ( Int_Man_t p,
int  Start 
)

Function*************************************************************

Synopsis [Propagate the current assignments.]

Description []

SideEffects []

SeeAlso []

Definition at line 505 of file satInter.c.

00506 {
00507     Sto_Cls_t * pClause;
00508     int i;
00509     int clk = clock();
00510     for ( i = Start; i < p->nTrailSize; i++ )
00511     {
00512         pClause = Int_ManPropagateOne( p, p->pTrail[i] );
00513         if ( pClause )
00514         {
00515 p->timeBcp += clock() - clk;
00516             return pClause;
00517         }
00518     }
00519 p->timeBcp += clock() - clk;
00520     return NULL;
00521 }

static Sto_Cls_t* Int_ManPropagateOne ( Int_Man_t p,
lit  Lit 
) [inline, static]

Function*************************************************************

Synopsis [Propagate one assignment.]

Description []

SideEffects []

SeeAlso []

Definition at line 436 of file satInter.c.

00437 {
00438     Sto_Cls_t ** ppPrev, * pCur, * pTemp;
00439     lit LitF = lit_neg(Lit);
00440     int i;
00441     // iterate through the literals
00442     ppPrev = p->pWatches + Lit;
00443     for ( pCur = p->pWatches[Lit]; pCur; pCur = *ppPrev )
00444     {
00445         // make sure the false literal is in the second literal of the clause
00446         if ( pCur->pLits[0] == LitF )
00447         {
00448             pCur->pLits[0] = pCur->pLits[1];
00449             pCur->pLits[1] = LitF;
00450             pTemp = pCur->pNext0;
00451             pCur->pNext0 = pCur->pNext1;
00452             pCur->pNext1 = pTemp;
00453         }
00454         assert( pCur->pLits[1] == LitF );
00455 
00456         // if the first literal is true, the clause is satisfied
00457         if ( pCur->pLits[0] == p->pAssigns[lit_var(pCur->pLits[0])] )
00458         {
00459             ppPrev = &pCur->pNext1;
00460             continue;
00461         }
00462 
00463         // look for a new literal to watch
00464         for ( i = 2; i < (int)pCur->nLits; i++ )
00465         {
00466             // skip the case when the literal is false
00467             if ( lit_neg(pCur->pLits[i]) == p->pAssigns[lit_var(pCur->pLits[i])] )
00468                 continue;
00469             // the literal is either true or unassigned - watch it
00470             pCur->pLits[1] = pCur->pLits[i];
00471             pCur->pLits[i] = LitF;
00472             // remove this clause from the watch list of Lit
00473             *ppPrev = pCur->pNext1;
00474             // add this clause to the watch list of pCur->pLits[i] (now it is pCur->pLits[1])
00475             Int_ManWatchClause( p, pCur, pCur->pLits[1] );
00476             break;
00477         }
00478         if ( i < (int)pCur->nLits ) // found new watch
00479             continue;
00480 
00481         // clause is unit - enqueue new implication
00482         if ( Int_ManEnqueue(p, pCur->pLits[0], pCur) )
00483         {
00484             ppPrev = &pCur->pNext1;
00485             continue;
00486         }
00487 
00488         // conflict detected - return the conflict clause
00489         return pCur;
00490     }
00491     return NULL;
00492 }

void Int_ManResize ( Int_Man_t p  ) 

Function*************************************************************

Synopsis [Resize proof manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 180 of file satInter.c.

00181 {
00182     // check if resizing is needed
00183     if ( p->nVarsAlloc < p->pCnf->nVars )
00184     {
00185         // find the new size
00186         if ( p->nVarsAlloc == 0 )
00187             p->nVarsAlloc = 1;
00188         while ( p->nVarsAlloc < p->pCnf->nVars ) 
00189             p->nVarsAlloc *= 2;
00190         // resize the arrays
00191         p->pTrail    = (lit *)       realloc( p->pTrail,    sizeof(lit) * p->nVarsAlloc );
00192         p->pAssigns  = (lit *)       realloc( p->pAssigns,  sizeof(lit) * p->nVarsAlloc );
00193         p->pSeens    = (char *)      realloc( p->pSeens,    sizeof(char) * p->nVarsAlloc );
00194         p->pVarTypes = (char *)      realloc( p->pVarTypes, sizeof(char) * p->nVarsAlloc );
00195         p->pReasons  = (Sto_Cls_t **)realloc( p->pReasons,  sizeof(Sto_Cls_t *) * p->nVarsAlloc );
00196         p->pWatches  = (Sto_Cls_t **)realloc( p->pWatches,  sizeof(Sto_Cls_t *) * p->nVarsAlloc*2 );
00197     }
00198 
00199     // clean the free space
00200     memset( p->pAssigns , 0xff, sizeof(lit) * p->pCnf->nVars );
00201     memset( p->pSeens   , 0,    sizeof(char) * p->pCnf->nVars );
00202     memset( p->pVarTypes, 0,    sizeof(char) * p->pCnf->nVars );
00203     memset( p->pReasons , 0,    sizeof(Sto_Cls_t *) * p->pCnf->nVars );
00204     memset( p->pWatches , 0,    sizeof(Sto_Cls_t *) * p->pCnf->nVars*2 );
00205 
00206     // compute the number of common variables
00207     p->nVarsAB = Int_ManGlobalVars( p );
00208     // compute the number of words in the truth table
00209     p->nWords = (p->nVarsAB <= 5 ? 1 : (1 << (p->nVarsAB - 5)));
00210 
00211     // check if resizing of clauses is needed
00212     if ( p->nClosAlloc < p->pCnf->nClauses )
00213     {
00214         // find the new size
00215         if ( p->nClosAlloc == 0 )
00216             p->nClosAlloc = 1;
00217         while ( p->nClosAlloc < p->pCnf->nClauses ) 
00218             p->nClosAlloc *= 2;
00219         // resize the arrays
00220         p->pProofNums = (int *) realloc( p->pProofNums,  sizeof(int) * p->nClosAlloc );
00221     }
00222     memset( p->pProofNums, 0, sizeof(int) * p->pCnf->nClauses );
00223 
00224     // check if resizing of truth tables is needed
00225     if ( p->nIntersAlloc < p->nWords * p->pCnf->nClauses )
00226     {
00227         p->nIntersAlloc = p->nWords * p->pCnf->nClauses;
00228         p->pInters = (unsigned *) realloc( p->pInters, sizeof(unsigned) * p->nIntersAlloc );
00229     }
00230 //    memset( p->pInters, 0, sizeof(unsigned) * p->nWords * p->pCnf->nClauses );
00231 }

static void Int_ManTruthAnd ( unsigned *  p,
unsigned *  q,
int  nWords 
) [inline, static]

Definition at line 79 of file satInter.c.

00079 { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i] &=  q[i]; }

static void Int_ManTruthClear ( unsigned *  p,
int  nWords 
) [inline, static]

Definition at line 76 of file satInter.c.

00076 { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i]  =  0;    }

static void Int_ManTruthCopy ( unsigned *  p,
unsigned *  q,
int  nWords 
) [inline, static]

Definition at line 78 of file satInter.c.

00078 { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i]  =  q[i]; }

static void Int_ManTruthFill ( unsigned *  p,
int  nWords 
) [inline, static]

Definition at line 77 of file satInter.c.

00077 { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i]  = ~0;    }

static void Int_ManTruthOr ( unsigned *  p,
unsigned *  q,
int  nWords 
) [inline, static]

Definition at line 80 of file satInter.c.

00080 { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i] |=  q[i]; }

static void Int_ManTruthOrNot ( unsigned *  p,
unsigned *  q,
int  nWords 
) [inline, static]

Definition at line 81 of file satInter.c.

00081 { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i] |= ~q[i]; }

static unsigned* Int_ManTruthRead ( Int_Man_t p,
Sto_Cls_t pCls 
) [inline, static]

Definition at line 75 of file satInter.c.

00075 { return p->pInters + pCls->Id * p->nWords;                 }

static void Int_ManWatchClause ( Int_Man_t p,
Sto_Cls_t pClause,
lit  Lit 
) [inline, static]

Function*************************************************************

Synopsis [Adds one clause to the watcher list.]

Description []

SideEffects []

SeeAlso []

Definition at line 362 of file satInter.c.

00363 {
00364     assert( lit_check(Lit, p->pCnf->nVars) );
00365     if ( pClause->pLits[0] == Lit )
00366         pClause->pNext0 = p->pWatches[lit_neg(Lit)];  
00367     else
00368     {
00369         assert( pClause->pLits[1] == Lit );
00370         pClause->pNext1 = p->pWatches[lit_neg(Lit)];  
00371     }
00372     p->pWatches[lit_neg(Lit)] = pClause;
00373 }


Variable Documentation

const lit LIT_UNDEF = 0xffffffff [static]

CFile****************************************************************

FileName [satInter.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [SAT sat_solver.]

Synopsis [Interpolation package.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
satInter.c,v 1.4 2005/09/16 22:55:03 casem Exp

] DECLARATIONS ///

Definition at line 33 of file satInter.c.


Generated on Tue Jan 5 12:19:36 2010 for abc70930 by  doxygen 1.6.1