00001 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <assert.h>
00025 #include <time.h>
00026 #include "satStore.h"
00027 
00031 
00032 
00033 static const lit    LIT_UNDEF = 0xffffffff;
00034 
00035 
00036 struct Int_Man_t_
00037 {
00038     
00039     Sto_Man_t *     pCnf;         
00040     
00041     int             fVerbose;     
00042     int             fProofVerif;  
00043     int             fProofWrite;  
00044     int             nVarsAlloc;   
00045     int             nClosAlloc;   
00046     
00047     int             nRootSize;    
00048     int             nTrailSize;   
00049     lit *           pTrail;       
00050     lit *           pAssigns;     
00051     char *          pSeens;       
00052     Sto_Cls_t **    pReasons;     
00053     Sto_Cls_t **    pWatches;     
00054     
00055     int             nVarsAB;      
00056     char *          pVarTypes;    
00057     unsigned *      pInters;      
00058     int             nIntersAlloc; 
00059     int             nWords;       
00060     
00061     int             Counter;      
00062     int *           pProofNums;   
00063     FILE *          pFile;        
00064     
00065     lit *           pResLits;     
00066     int             nResLits;     
00067     int             nResLitsAlloc;
00068     
00069     int             timeBcp;      
00070     int             timeTrace;    
00071     int             timeTotal;    
00072 };
00073 
00074 
00075 static inline unsigned * Int_ManTruthRead( Int_Man_t * p, Sto_Cls_t * pCls )          { return p->pInters + pCls->Id * p->nWords;                 }
00076 static inline void       Int_ManTruthClear( unsigned * p, int nWords )                { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i]  =  0;    }
00077 static inline void       Int_ManTruthFill( unsigned * p, int nWords )                 { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i]  = ~0;    }
00078 static inline void       Int_ManTruthCopy( unsigned * p, unsigned * q, int nWords )   { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i]  =  q[i]; }
00079 static inline void       Int_ManTruthAnd( unsigned * p, unsigned * q, int nWords )    { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i] &=  q[i]; }
00080 static inline void       Int_ManTruthOr( unsigned * p, unsigned * q, int nWords )     { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i] |=  q[i]; }
00081 static inline void       Int_ManTruthOrNot( unsigned * p, unsigned * q, int nWords )  { int i; for ( i = nWords - 1; i >= 0; i-- ) p[i] |= ~q[i]; }
00082 
00083 
00084 static inline int        Int_ManProofGet( Int_Man_t * p, Sto_Cls_t * pCls )           { return p->pProofNums[pCls->Id];  }
00085 static inline void       Int_ManProofSet( Int_Man_t * p, Sto_Cls_t * pCls, int n )    { p->pProofNums[pCls->Id] = n;     }
00086 
00090 
00102 Int_Man_t * Int_ManAlloc( int nVarsAlloc )
00103 {
00104     Int_Man_t * p;
00105     
00106     p = (Int_Man_t *)malloc( sizeof(Int_Man_t) );
00107     memset( p, 0, sizeof(Int_Man_t) );
00108     
00109     p->nResLitsAlloc = (1<<16);
00110     p->pResLits = malloc( sizeof(lit) * p->nResLitsAlloc );
00111     
00112     p->fProofWrite = 0;
00113     p->fProofVerif = 1;
00114     return p;    
00115 }
00116 
00128 int Int_ManGlobalVars( Int_Man_t * p )
00129 {
00130     Sto_Cls_t * pClause;
00131     int Var, nVarsAB, v;
00132 
00133     
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     
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 ) 
00152             {
00153                 
00154                 nVarsAB++;
00155                 p->pVarTypes[Var] = -1;
00156             }
00157         }
00158     }
00159 
00160     
00161     nVarsAB = 0;
00162     for ( v = 0; v < p->pCnf->nVars; v++ )
00163         if ( p->pVarTypes[v] == -1 )
00164             p->pVarTypes[v] -= nVarsAB++;
00165 
00166     return nVarsAB;
00167 }
00168 
00180 void Int_ManResize( Int_Man_t * p )
00181 {
00182     
00183     if ( p->nVarsAlloc < p->pCnf->nVars )
00184     {
00185         
00186         if ( p->nVarsAlloc == 0 )
00187             p->nVarsAlloc = 1;
00188         while ( p->nVarsAlloc < p->pCnf->nVars ) 
00189             p->nVarsAlloc *= 2;
00190         
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     
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     
00207     p->nVarsAB = Int_ManGlobalVars( p );
00208     
00209     p->nWords = (p->nVarsAB <= 5 ? 1 : (1 << (p->nVarsAB - 5)));
00210 
00211     
00212     if ( p->nClosAlloc < p->pCnf->nClauses )
00213     {
00214         
00215         if ( p->nClosAlloc == 0 )
00216             p->nClosAlloc = 1;
00217         while ( p->nClosAlloc < p->pCnf->nClauses ) 
00218             p->nClosAlloc *= 2;
00219         
00220         p->pProofNums = (int *) realloc( p->pProofNums,  sizeof(int) * p->nClosAlloc );
00221     }
00222     memset( p->pProofNums, 0, sizeof(int) * p->pCnf->nClauses );
00223 
00224     
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 
00231 }
00232 
00244 void Int_ManFree( Int_Man_t * p )
00245 {
00246 
00247 
00248 
00249 
00250 
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 }
00263 
00264 
00265 
00266 
00278 void Int_ManPrintClause( Int_Man_t * p, Sto_Cls_t * pClause )
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 }
00286 
00298 void Int_ManPrintResolvent( lit * pResLits, int nResLits )
00299 {
00300     int i;
00301     printf( "Resolvent: {" );
00302     for ( i = 0; i < nResLits; i++ )
00303         printf( " %d", pResLits[i] );
00304     printf( " }\n" );
00305 }
00306 
00318 void Extra_PrintBinary__( FILE * pFile, unsigned Sign[], int nBits )
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 }
00330 
00342 void Int_ManPrintInterOne( Int_Man_t * p, Sto_Cls_t * pClause )
00343 {
00344     printf( "Clause %2d :  ", pClause->Id );
00345     Extra_PrintBinary__( stdout, Int_ManTruthRead(p, pClause), (1 << p->nVarsAB) );
00346     printf( "\n" );
00347 }
00348 
00349 
00350 
00362 static inline void Int_ManWatchClause( Int_Man_t * p, Sto_Cls_t * pClause, lit Lit )
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 }
00374 
00375 
00387 static inline int Int_ManEnqueue( Int_Man_t * p, lit Lit, Sto_Cls_t * pReason )
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 
00396     return 1;
00397 }
00398 
00410 static inline void Int_ManCancelUntil( Int_Man_t * p, int Level )
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 
00421     }
00422     p->nTrailSize = Level;
00423 }
00424 
00436 static inline Sto_Cls_t * Int_ManPropagateOne( Int_Man_t * p, lit Lit )
00437 {
00438     Sto_Cls_t ** ppPrev, * pCur, * pTemp;
00439     lit LitF = lit_neg(Lit);
00440     int i;
00441     
00442     ppPrev = p->pWatches + Lit;
00443     for ( pCur = p->pWatches[Lit]; pCur; pCur = *ppPrev )
00444     {
00445         
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         
00457         if ( pCur->pLits[0] == p->pAssigns[lit_var(pCur->pLits[0])] )
00458         {
00459             ppPrev = &pCur->pNext1;
00460             continue;
00461         }
00462 
00463         
00464         for ( i = 2; i < (int)pCur->nLits; i++ )
00465         {
00466             
00467             if ( lit_neg(pCur->pLits[i]) == p->pAssigns[lit_var(pCur->pLits[i])] )
00468                 continue;
00469             
00470             pCur->pLits[1] = pCur->pLits[i];
00471             pCur->pLits[i] = LitF;
00472             
00473             *ppPrev = pCur->pNext1;
00474             
00475             Int_ManWatchClause( p, pCur, pCur->pLits[1] );
00476             break;
00477         }
00478         if ( i < (int)pCur->nLits ) 
00479             continue;
00480 
00481         
00482         if ( Int_ManEnqueue(p, pCur->pLits[0], pCur) )
00483         {
00484             ppPrev = &pCur->pNext1;
00485             continue;
00486         }
00487 
00488         
00489         return pCur;
00490     }
00491     return NULL;
00492 }
00493 
00505 Sto_Cls_t * Int_ManPropagate( Int_Man_t * p, int Start )
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 }
00522 
00523 
00535 void Int_ManProofWriteOne( Int_Man_t * p, Sto_Cls_t * pClause )
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 }
00548 
00560 int Int_ManProofTraceOne( Int_Man_t * p, Sto_Cls_t * pConflict, Sto_Cls_t * pFinal )
00561 {
00562     Sto_Cls_t * pReason;
00563     int i, v, Var, PrevId;
00564     int fPrint = 0;
00565     int clk = clock();
00566 
00567     
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     
00576     for ( v = 0; v < (int)pConflict->nLits; v++ )
00577         p->pSeens[lit_var(pConflict->pLits[v])] = 1;
00578 
00579     
00580 
00581 
00582 
00583     if ( p->pCnf->nClausesA )
00584         Int_ManTruthCopy( Int_ManTruthRead(p, pFinal), Int_ManTruthRead(p, pConflict), p->nWords );
00585 
00586     
00587     PrevId = Int_ManProofGet(p, pConflict);
00588     for ( i = p->nTrailSize - 1; i >= 0; i-- )
00589     {
00590         
00591         Var = lit_var(p->pTrail[i]);
00592         if ( !p->pSeens[Var] )
00593             continue;
00594         p->pSeens[Var] = 0;
00595 
00596         
00597         pReason = p->pReasons[Var];
00598         if ( pReason == NULL )
00599             continue;
00600         assert( p->pTrail[i] == pReason->pLits[0] );
00601 
00602         
00603         for ( v = 1; v < (int)pReason->nLits; v++ )
00604             p->pSeens[lit_var(pReason->pLits[v])] = 1;
00605 
00606 
00607         
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 ) 
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         
00623         if ( p->fProofVerif )
00624         {
00625             int v1, v2; 
00626             if ( fPrint )
00627                 Int_ManPrintResolvent( p->pResLits, p->nResLits );
00628             
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             
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             
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                 
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                 
00656                 if ( p->pResLits[v1] == pReason->pLits[v2] )
00657                     continue;
00658                 
00659                 printf( "Recording clause %d: Trying to resolve the clause with more than one opposite literal.\n", pFinal->Id );
00660             }
00661         }
00662 
00663 
00664     }
00665 
00666     
00667 
00668 
00669     
00670 
00671 
00672 
00673     
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     
00699     if ( p->pCnf->nClausesA )
00700     {
00701 
00702     }
00703     Int_ManProofSet( p, pFinal, p->Counter );
00704     return p->Counter;
00705 }
00706 
00718 int Int_ManProofRecordOne( Int_Man_t * p, Sto_Cls_t * pClause )
00719 {
00720     Sto_Cls_t * pConflict;
00721     int i;
00722 
00723     
00724     assert( pClause->nLits > 0 );
00725     if ( pClause->nLits == 0 )
00726         printf( "Error: Empty clause is attempted.\n" );
00727 
00728     
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 ); 
00735             return 0;
00736         }
00737 
00738     
00739     pConflict = Int_ManPropagate( p, p->nRootSize );
00740     if ( pConflict == NULL )
00741     {
00742         assert( 0 ); 
00743         return 0;
00744     }
00745 
00746     
00747     Int_ManProofTraceOne( p, pConflict, pClause );
00748 
00749     
00750     Int_ManCancelUntil( p, p->nRootSize );
00751 
00752     
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     
00762     if ( !Int_ManEnqueue( p, pClause->pLits[0], pClause ) )
00763     {
00764         assert( 0 ); 
00765         return 0;
00766     }
00767 
00768     
00769     pConflict = Int_ManPropagate( p, p->nRootSize );
00770     if ( pConflict )
00771     {
00772         
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     
00780     p->nRootSize = p->nTrailSize;
00781     return 1;
00782 }
00783 
00795 int Int_ManProcessRoots( Int_Man_t * p )
00796 {
00797     Sto_Cls_t * pClause;
00798     int Counter;
00799 
00800     
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     
00811     assert( p->pCnf->pTail->nLits == 0 );
00812 
00813     
00814     p->nTrailSize = 0;
00815     Sto_ManForEachClauseRoot( p->pCnf, pClause )
00816     {
00817         
00818         if ( pClause->nLits > 1 )
00819         {
00820             Int_ManWatchClause( p, pClause, pClause->pLits[0] );
00821             Int_ManWatchClause( p, pClause, pClause->pLits[1] );
00822         }
00823         
00824         if ( pClause->nLits != 1 )
00825             continue;
00826         
00827         assert( lit_check(pClause->pLits[0], p->pCnf->nVars) );
00828         if ( !Int_ManEnqueue( p, pClause->pLits[0], pClause ) )
00829         {
00830             
00831             printf( "Error in Int_ManProcessRoots(): Detected a root-level conflict too early!\n" );
00832             assert( 0 );
00833             return 0;
00834         }
00835     }
00836 
00837     
00838     pClause = Int_ManPropagate( p, 0 );
00839     if ( pClause )
00840     {
00841         
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     
00849     p->nRootSize = p->nTrailSize;
00850     return 1;
00851 }
00852 
00864 void Int_ManPrepareInter( Int_Man_t * p )
00865 {
00866     
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     
00882     Sto_ManForEachClauseRoot( p->pCnf, pClause )
00883     {
00884         if ( !pClause->fA ) 
00885         {
00886             Int_ManTruthFill( Int_ManTruthRead(p, pClause), p->nWords );
00887 
00888             continue;
00889         }
00890         
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 ) 
00896             {
00897                 VarAB = -p->pVarTypes[Var]-1;
00898                 assert( VarAB >= 0 && VarAB < p->nVarsAB );
00899                 if ( lit_sign(pClause->pLits[v]) ) 
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 
00906     }
00907 }
00908 
00921 int Int_ManInterpolate( Int_Man_t * p, Sto_Man_t * pCnf, int fVerbose, unsigned ** ppResult )
00922 {
00923     Sto_Cls_t * pClause;
00924     int RetValue = 1;
00925     int clkTotal = clock();
00926 
00927     
00928     assert( pCnf->nVars > 0 && pCnf->nClauses > 0 );
00929     p->pCnf = pCnf;
00930     p->fVerbose = fVerbose;
00931     *ppResult = NULL;
00932 
00933     
00934     Int_ManResize( p );
00935 
00936     
00937     Int_ManPrepareInter( p );
00938 
00939     
00940     
00941     if ( p->fProofWrite )
00942     {
00943         p->pFile = fopen( "proof.cnf_", "w" );
00944         p->Counter = 0;
00945     }
00946 
00947     
00948     Sto_ManForEachClauseRoot( p->pCnf, pClause )
00949         Int_ManProofWriteOne( p, pClause );
00950 
00951     
00952     if ( Int_ManProcessRoots( p ) )
00953     {
00954         
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     
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 }
00986 
00990 
00991