src/sat/fraig/fraigFeed.c File Reference

#include "fraigInt.h"
Include dependency graph for fraigFeed.c:

Go to the source code of this file.

Functions

static int Fraig_FeedBackPrepare (Fraig_Man_t *p, int *pModel, Msat_IntVec_t *vVars)
static int Fraig_FeedBackInsert (Fraig_Man_t *p, int nVarsPi)
static void Fraig_FeedBackVerify (Fraig_Man_t *p, Fraig_Node_t *pOld, Fraig_Node_t *pNew)
static void Fraig_FeedBackCovering (Fraig_Man_t *p, Msat_IntVec_t *vPats)
static Fraig_NodeVec_tFraig_FeedBackCoveringStart (Fraig_Man_t *pMan)
static int Fraig_GetSmallestColumn (int *pHits, int nHits)
static int Fraig_GetHittingPattern (unsigned *pSims, int nWords)
static void Fraig_CancelCoveredColumns (Fraig_NodeVec_t *vColumns, int *pHits, int iPat)
static void Fraig_FeedBackCheckTable (Fraig_Man_t *p)
static void Fraig_FeedBackCheckTableF0 (Fraig_Man_t *p)
static void Fraig_ReallocateSimulationInfo (Fraig_Man_t *p)
void Fraig_FeedBackInit (Fraig_Man_t *p)
void Fraig_FeedBack (Fraig_Man_t *p, int *pModel, Msat_IntVec_t *vVars, Fraig_Node_t *pOld, Fraig_Node_t *pNew)
int Fraig_FeedBackCompress (Fraig_Man_t *p)
int * Fraig_ManAllocCounterExample (Fraig_Man_t *p)
int Fraig_ManSimulateBitNode_rec (Fraig_Man_t *p, Fraig_Node_t *pNode)
int Fraig_ManSimulateBitNode (Fraig_Man_t *p, Fraig_Node_t *pNode, int *pModel)
int * Fraig_ManSaveCounterExample (Fraig_Man_t *p, Fraig_Node_t *pNode)

Function Documentation

void Fraig_CancelCoveredColumns ( Fraig_NodeVec_t vColumns,
int *  pHits,
int  iPat 
) [static]

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

Synopsis [Cancel covered patterns.]

Description []

SideEffects []

SeeAlso []

Definition at line 608 of file fraigFeed.c.

00609 {
00610     unsigned * pSims;
00611     int i;
00612     for ( i = 0; i < vColumns->nSize; i++ )
00613     {
00614         pSims = (unsigned *)vColumns->pArray[i];
00615         if ( Fraig_BitStringHasBit( pSims, iPat ) )
00616             pHits[i] = 0;
00617     }
00618 }

void Fraig_FeedBack ( Fraig_Man_t p,
int *  pModel,
Msat_IntVec_t vVars,
Fraig_Node_t pOld,
Fraig_Node_t pNew 
)

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

Synopsis [Processes the feedback from teh solver.]

Description [Array pModel gives the value of each variable in the SAT solver. Array vVars is the array of integer numbers of variables involves in this conflict.]

SideEffects []

SeeAlso []

Definition at line 77 of file fraigFeed.c.

00078 {
00079     int nVarsPi, nWords;
00080     int i, clk = clock();
00081 
00082     // get the number of PI vars in the feedback (also sets the PI values)
00083     nVarsPi = Fraig_FeedBackPrepare( p, pModel, vVars );
00084 
00085     // set the PI values
00086     nWords = Fraig_FeedBackInsert( p, nVarsPi );
00087     assert( p->iWordStart + nWords <= p->nWordsDyna );
00088 
00089     // resimulates the words from p->iWordStart to iWordStop
00090     for ( i = 1; i < p->vNodes->nSize; i++ )
00091         if ( Fraig_NodeIsAnd(p->vNodes->pArray[i]) )
00092             Fraig_NodeSimulate( p->vNodes->pArray[i], p->iWordStart, p->iWordStart + nWords, 0 );
00093 
00094     if ( p->fDoSparse )
00095         Fraig_TableRehashF0( p, 0 );
00096 
00097     if ( !p->fChoicing )
00098     Fraig_FeedBackVerify( p, pOld, pNew );
00099 
00100     // if there is no room left, compress the patterns
00101     if ( p->iWordStart + nWords == p->nWordsDyna )
00102         p->iWordStart = Fraig_FeedBackCompress( p );
00103     else  // otherwise, update the starting word
00104         p->iWordStart += nWords;
00105 
00106 p->timeFeed += clock() - clk;
00107 }

void Fraig_FeedBackCheckTable ( Fraig_Man_t p  )  [static]

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

Synopsis [Checks the correctness of the functional simulation table.]

Description []

SideEffects []

SeeAlso []

Definition at line 632 of file fraigFeed.c.

00633 {
00634     Fraig_HashTable_t * pT = p->pTableF;
00635     Fraig_Node_t * pEntF, * pEntD;
00636     int i, k, m, nPairs;
00637     int clk = clock();
00638 
00639     nPairs = 0;
00640     for ( i = 0; i < pT->nBins; i++ )
00641     Fraig_TableBinForEachEntryF( pT->pBins[i], pEntF )
00642     {
00643         p->vCones->nSize = 0;
00644         Fraig_TableBinForEachEntryD( pEntF, pEntD )
00645             Fraig_NodeVecPush( p->vCones, pEntD );
00646         if ( p->vCones->nSize == 1 )
00647             continue;
00648         for ( k = 0; k < p->vCones->nSize; k++ )
00649             for ( m = k+1; m < p->vCones->nSize; m++ )
00650             {
00651                 if ( Fraig_CompareSimInfo( p->vCones->pArray[k], p->vCones->pArray[m], p->iWordStart, 0 ) )
00652                     printf( "Nodes %d and %d have the same D simulation info.\n", 
00653                         p->vCones->pArray[k]->Num, p->vCones->pArray[m]->Num );
00654                 nPairs++;
00655             }   
00656     }
00657 //    printf( "\nThe total of %d node pairs have been verified.\n", nPairs );
00658 }

void Fraig_FeedBackCheckTableF0 ( Fraig_Man_t p  )  [static]

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

Synopsis [Checks the correctness of the functional simulation table.]

Description []

SideEffects []

SeeAlso []

Definition at line 671 of file fraigFeed.c.

00672 {
00673     Fraig_HashTable_t * pT = p->pTableF0;
00674     Fraig_Node_t * pEntF;
00675     int i, k, m, nPairs;
00676 
00677     nPairs = 0;
00678     for ( i = 0; i < pT->nBins; i++ )
00679     {
00680         p->vCones->nSize = 0;
00681         Fraig_TableBinForEachEntryF( pT->pBins[i], pEntF )
00682             Fraig_NodeVecPush( p->vCones, pEntF );
00683         if ( p->vCones->nSize == 1 )
00684             continue;
00685         for ( k = 0; k < p->vCones->nSize; k++ )
00686             for ( m = k+1; m < p->vCones->nSize; m++ )
00687             {
00688                 if ( Fraig_CompareSimInfo( p->vCones->pArray[k], p->vCones->pArray[m], p->iWordStart, 0 ) )
00689                     printf( "Nodes %d and %d have the same D simulation info.\n", 
00690                         p->vCones->pArray[k]->Num, p->vCones->pArray[m]->Num );
00691                 nPairs++;
00692             }   
00693     }
00694 //    printf( "\nThe total of %d node pairs have been verified.\n", nPairs );
00695 }

int Fraig_FeedBackCompress ( Fraig_Man_t p  ) 

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

Synopsis [Compress the simulation patterns.]

Description []

SideEffects []

SeeAlso []

Definition at line 274 of file fraigFeed.c.

00275 {
00276     unsigned * pSims;
00277     unsigned uHash;
00278     int i, w, t, nPats, * pPats;
00279     int fPerformChecks = (p->nBTLimit == -1);
00280 
00281     // solve the covering problem
00282     if ( fPerformChecks )
00283     {
00284         Fraig_FeedBackCheckTable( p );
00285         if ( p->fDoSparse ) 
00286             Fraig_FeedBackCheckTableF0( p );
00287     }
00288 
00289     // solve the covering problem
00290     Fraig_FeedBackCovering( p, p->vPatsReal );
00291 
00292 
00293     // get the number of additional patterns
00294     nPats = Msat_IntVecReadSize( p->vPatsReal );
00295     pPats = Msat_IntVecReadArray( p->vPatsReal );
00296     // get the new starting word
00297     p->iWordStart = FRAIG_NUM_WORDS( p->iPatsPerm + nPats );
00298 
00299     // set the simulation info for the PIs
00300     for ( i = 0; i < p->vInputs->nSize; i++ )
00301     {
00302         // get hold of the simulation info for this PI
00303         pSims = p->vInputs->pArray[i]->puSimD;
00304         // clean the storage for the new patterns
00305         for ( w = p->iWordPerm; w < p->iWordStart; w++ )
00306             p->pSimsTemp[w] = 0;
00307         // set the patterns
00308         for ( t = 0; t < nPats; t++ )
00309             if ( Fraig_BitStringHasBit( pSims, pPats[t] ) )
00310             {
00311                 // check if this pattern falls into temporary storage
00312                 if ( p->iPatsPerm + t < p->iWordPerm * 32 )
00313                     Fraig_BitStringSetBit( pSims, p->iPatsPerm + t );
00314                 else
00315                     Fraig_BitStringSetBit( p->pSimsTemp, p->iPatsPerm + t );
00316             }
00317         // copy the pattern 
00318         for ( w = p->iWordPerm; w < p->iWordStart; w++ )
00319             pSims[w] = p->pSimsTemp[w];
00320         // recompute the hashing info
00321         uHash = 0;
00322         for ( w = 0; w < p->iWordStart; w++ )
00323             uHash ^= pSims[w] * s_FraigPrimes[w];
00324         p->vInputs->pArray[i]->uHashD = uHash;
00325     }
00326 
00327     // update info about the permanently stored patterns
00328     p->iWordPerm = p->iWordStart;
00329     p->iPatsPerm += nPats;
00330     assert( p->iWordPerm == FRAIG_NUM_WORDS( p->iPatsPerm ) );
00331 
00332     // resimulate and recompute the hash values
00333     for ( i = 1; i < p->vNodes->nSize; i++ )
00334         if ( Fraig_NodeIsAnd(p->vNodes->pArray[i]) )
00335         {
00336             p->vNodes->pArray[i]->uHashD = 0;
00337             Fraig_NodeSimulate( p->vNodes->pArray[i], 0, p->iWordPerm, 0 );
00338         }
00339 
00340     // double-check that the nodes are still distinguished
00341     if ( fPerformChecks )
00342         Fraig_FeedBackCheckTable( p );
00343 
00344     // rehash the values in the F0 table
00345     if ( p->fDoSparse ) 
00346     {
00347         Fraig_TableRehashF0( p, 0 );
00348         if ( fPerformChecks )
00349             Fraig_FeedBackCheckTableF0( p );
00350     }
00351 
00352     // check if we need to resize the simulation info
00353     // if less than FRAIG_WORDS_STORE words are left, reallocate simulation info
00354     if ( p->iWordPerm + FRAIG_WORDS_STORE > p->nWordsDyna )
00355         Fraig_ReallocateSimulationInfo( p );
00356 
00357     // set the real patterns
00358     Msat_IntVecClear( p->vPatsReal );
00359     memset( p->pSimsReal, 0, sizeof(unsigned)*p->nWordsDyna );
00360     for ( w = 0; w < p->iWordPerm; w++ )
00361         p->pSimsReal[w] = FRAIG_FULL;
00362     if ( p->iPatsPerm % 32 > 0 )
00363         p->pSimsReal[p->iWordPerm-1] = FRAIG_MASK( p->iPatsPerm % 32 );
00364 //    printf( "The number of permanent words = %d.\n", p->iWordPerm );
00365     return p->iWordStart;
00366 }

void Fraig_FeedBackCovering ( Fraig_Man_t p,
Msat_IntVec_t vPats 
) [static]

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

Synopsis [Checks the correctness of the functional simulation table.]

Description []

SideEffects []

SeeAlso []

Definition at line 382 of file fraigFeed.c.

00383 {
00384     Fraig_NodeVec_t * vColumns;
00385     unsigned * pSims;
00386     int * pHits, iPat, iCol, i;
00387     int nOnesTotal, nSolStarting;
00388     int fVeryVerbose = 0;
00389 
00390     // collect the pairs to be distinguished
00391     vColumns = Fraig_FeedBackCoveringStart( p );
00392     // collect the number of 1s in each simulation vector
00393     nOnesTotal = 0;
00394     pHits = ALLOC( int, vColumns->nSize );
00395     for ( i = 0; i < vColumns->nSize; i++ )
00396     {
00397         pSims = (unsigned *)vColumns->pArray[i];
00398         pHits[i] = Fraig_BitStringCountOnes( pSims, p->iWordStart );
00399         nOnesTotal += pHits[i];
00400 //        assert( pHits[i] > 0 );
00401     }
00402  
00403     // go through the patterns
00404     nSolStarting = Msat_IntVecReadSize(vPats);
00405     while ( (iCol = Fraig_GetSmallestColumn( pHits, vColumns->nSize )) != -1 )
00406     {
00407         // find the pattern, which hits this column
00408         iPat = Fraig_GetHittingPattern( (unsigned *)vColumns->pArray[iCol], p->iWordStart );
00409         // cancel the columns covered by this pattern
00410         Fraig_CancelCoveredColumns( vColumns, pHits, iPat );
00411         // save the pattern
00412         Msat_IntVecPush( vPats, iPat );
00413     }
00414 
00415     // free the set of columns
00416     for ( i = 0; i < vColumns->nSize; i++ )
00417         Fraig_MemFixedEntryRecycle( p->mmSims, (char *)vColumns->pArray[i] );
00418 
00419     // print stats related to the covering problem
00420     if ( p->fVerbose && fVeryVerbose )
00421     {
00422         printf( "%3d\\%3d\\%3d   ",     p->nWordsRand, p->nWordsDyna, p->iWordPerm );
00423         printf( "Col (pairs) = %5d.  ", vColumns->nSize );
00424         printf( "Row (pats) = %5d.  ",  p->iWordStart * 32 );
00425         printf( "Dns = %6.2f %%.  ",    vColumns->nSize==0? 0.0 : 100.0 * nOnesTotal / vColumns->nSize / p->iWordStart / 32 );
00426         printf( "Sol = %3d (%3d).  ",   Msat_IntVecReadSize(vPats), nSolStarting );
00427         printf( "\n" );
00428     }
00429     Fraig_NodeVecFree( vColumns );
00430     free( pHits );
00431 }

Fraig_NodeVec_t * Fraig_FeedBackCoveringStart ( Fraig_Man_t p  )  [static]

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

Synopsis [Checks the correctness of the functional simulation table.]

Description []

SideEffects []

SeeAlso []

Definition at line 445 of file fraigFeed.c.

00446 {
00447     Fraig_NodeVec_t * vColumns;
00448     Fraig_HashTable_t * pT = p->pTableF;
00449     Fraig_Node_t * pEntF, * pEntD;
00450     unsigned * pSims;
00451     unsigned * pUnsigned1, * pUnsigned2;
00452     int i, k, m, w;//, nOnes;
00453 
00454     // start the set of columns
00455     vColumns = Fraig_NodeVecAlloc( 100 );
00456 
00457     // go through the pairs of nodes to be distinguished
00458     for ( i = 0; i < pT->nBins; i++ )
00459     Fraig_TableBinForEachEntryF( pT->pBins[i], pEntF )
00460     {
00461         p->vCones->nSize = 0;
00462         Fraig_TableBinForEachEntryD( pEntF, pEntD )
00463             Fraig_NodeVecPush( p->vCones, pEntD );
00464         if ( p->vCones->nSize == 1 )
00465             continue;
00467         if ( p->vCones->nSize > 20 ) 
00468             continue;
00470 
00471         for ( k = 0; k < p->vCones->nSize; k++ )
00472             for ( m = k+1; m < p->vCones->nSize; m++ )
00473             {
00474                 if ( !Fraig_CompareSimInfoUnderMask( p->vCones->pArray[k], p->vCones->pArray[m], p->iWordStart, 0, p->pSimsReal ) )
00475                     continue;
00476 
00477                 // primary simulation patterns (counter-examples) cannot distinguish this pair
00478                 // get memory to store the feasible simulation patterns
00479                 pSims = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
00480                 // find the pattern that distinguish this column, exept the primary ones
00481                 pUnsigned1 = p->vCones->pArray[k]->puSimD;
00482                 pUnsigned2 = p->vCones->pArray[m]->puSimD;
00483                 for ( w = 0; w < p->iWordStart; w++ )
00484                     pSims[w] = (pUnsigned1[w] ^ pUnsigned2[w]) & ~p->pSimsReal[w];
00485                 // store the pattern
00486                 Fraig_NodeVecPush( vColumns, (Fraig_Node_t *)pSims );
00487 //                nOnes = Fraig_BitStringCountOnes(pSims, p->iWordStart);
00488 //                assert( nOnes > 0 );
00489             }      
00490     }
00491 
00492     // if the flag is not set, do not consider sparse nodes in p->pTableF0
00493     if ( !p->fDoSparse )
00494         return vColumns;
00495 
00496     // recalculate their hash values based on p->pSimsReal
00497     pT = p->pTableF0;
00498     for ( i = 0; i < pT->nBins; i++ )
00499     Fraig_TableBinForEachEntryF( pT->pBins[i], pEntF )
00500     {
00501         pSims = pEntF->puSimD;
00502         pEntF->uHashD = 0;
00503         for ( w = 0; w < p->iWordStart; w++ )
00504             pEntF->uHashD ^= (pSims[w] & p->pSimsReal[w]) * s_FraigPrimes[w];
00505     }
00506 
00507     // rehash the table using these values
00508     Fraig_TableRehashF0( p, 1 );
00509 
00510     // collect the classes of equivalent node pairs
00511     for ( i = 0; i < pT->nBins; i++ )
00512     Fraig_TableBinForEachEntryF( pT->pBins[i], pEntF )
00513     {
00514         p->vCones->nSize = 0;
00515         Fraig_TableBinForEachEntryD( pEntF, pEntD )
00516             Fraig_NodeVecPush( p->vCones, pEntD );
00517         if ( p->vCones->nSize == 1 )
00518             continue;
00519 
00520         // primary simulation patterns (counter-examples) cannot distinguish all these pairs
00521         for ( k = 0; k < p->vCones->nSize; k++ )
00522             for ( m = k+1; m < p->vCones->nSize; m++ )
00523             {
00524                 // get memory to store the feasible simulation patterns
00525                 pSims = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
00526                 // find the patterns that are not distinquished
00527                 pUnsigned1 = p->vCones->pArray[k]->puSimD;
00528                 pUnsigned2 = p->vCones->pArray[m]->puSimD;
00529                 for ( w = 0; w < p->iWordStart; w++ )
00530                     pSims[w] = (pUnsigned1[w] ^ pUnsigned2[w]) & ~p->pSimsReal[w];
00531                 // store the pattern
00532                 Fraig_NodeVecPush( vColumns, (Fraig_Node_t *)pSims );
00533 //                nOnes = Fraig_BitStringCountOnes(pSims, p->iWordStart);
00534 //                assert( nOnes > 0 );
00535             }      
00536     }
00537     return vColumns;
00538 }

void Fraig_FeedBackInit ( Fraig_Man_t p  ) 

FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Initializes the feedback information.]

Description []

SideEffects []

SeeAlso []

Definition at line 54 of file fraigFeed.c.

00055 {
00056     p->vCones    = Fraig_NodeVecAlloc( 500 );
00057     p->vPatsReal = Msat_IntVecAlloc( 1000 ); 
00058     p->pSimsReal = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
00059     memset( p->pSimsReal, 0, sizeof(unsigned) * p->nWordsDyna );
00060     p->pSimsTemp = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
00061     p->pSimsDiff = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
00062 }

int Fraig_FeedBackInsert ( Fraig_Man_t p,
int  nVarsPi 
) [static]

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

Synopsis [Inserts the new simulation patterns.]

Description []

SideEffects []

SeeAlso []

Definition at line 163 of file fraigFeed.c.

00164 {
00165     Fraig_Node_t * pNode;
00166     int nWords, iPatFlip, nPatFlipLimit, i, w;
00167     int fUseNoPats = 0;
00168     int fUse2Pats = 0;
00169 
00170     // get the number of words 
00171     if ( fUse2Pats )
00172         nWords = FRAIG_NUM_WORDS( 2 * nVarsPi + 1 );
00173     else if ( fUseNoPats )
00174         nWords = 1;
00175     else
00176         nWords = FRAIG_NUM_WORDS( nVarsPi + 1 );
00177     // update the number of words if they do not fit into the simulation info
00178     if ( nWords > p->nWordsDyna - p->iWordStart )
00179         nWords = p->nWordsDyna - p->iWordStart; 
00180     // determine the bound on the flipping bit
00181     nPatFlipLimit = nWords * 32 - 2;
00182 
00183     // mark the real pattern
00184     Msat_IntVecPush( p->vPatsReal, p->iWordStart * 32 ); 
00185     // record the real pattern
00186     Fraig_BitStringSetBit( p->pSimsReal, p->iWordStart * 32 );
00187 
00188     // set the values at the PIs
00189     iPatFlip = 1;
00190     for ( i = 0; i < p->vInputs->nSize; i++ )
00191     {
00192         pNode = p->vInputs->pArray[i];
00193         for ( w = p->iWordStart; w < p->iWordStart + nWords; w++ )
00194             if ( !pNode->fFeedUse )
00195                 pNode->puSimD[w] = FRAIG_RANDOM_UNSIGNED;
00196             else if ( pNode->fFeedVal )
00197                 pNode->puSimD[w] = FRAIG_FULL;
00198             else // if ( !pNode->fFeedVal )
00199                 pNode->puSimD[w] = 0;
00200 
00201         if ( fUse2Pats )
00202         {
00203             // flip two patterns
00204             if ( pNode->fFeedUse && 2 * iPatFlip < nPatFlipLimit )
00205             {
00206                 Fraig_BitStringXorBit( pNode->puSimD + p->iWordStart, 2 * iPatFlip - 1 );
00207                 Fraig_BitStringXorBit( pNode->puSimD + p->iWordStart, 2 * iPatFlip     );
00208                 Fraig_BitStringXorBit( pNode->puSimD + p->iWordStart, 2 * iPatFlip + 1 );
00209                 iPatFlip++;
00210             }
00211         }
00212         else if ( fUseNoPats )
00213         {
00214         }
00215         else
00216         {
00217             // flip the diagonal
00218             if ( pNode->fFeedUse && iPatFlip < nPatFlipLimit )
00219             {
00220                 Fraig_BitStringXorBit( pNode->puSimD + p->iWordStart, iPatFlip );
00221                 iPatFlip++;
00222     //            Extra_PrintBinary( stdout, &pNode->puSimD, 45 ); printf( "\n" );
00223             }
00224         }
00225         // clean the use mask
00226         pNode->fFeedUse = 0;
00227 
00228         // add the info to the D hash value of the PIs
00229         for ( w = p->iWordStart; w < p->iWordStart + nWords; w++ )
00230             pNode->uHashD ^= pNode->puSimD[w] * s_FraigPrimes[w];
00231 
00232     }
00233     return nWords;
00234 }

int Fraig_FeedBackPrepare ( Fraig_Man_t p,
int *  pModel,
Msat_IntVec_t vVars 
) [static]

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

FileName [fraigFeed.c]

PackageName [FRAIG: Functionally reduced AND-INV graphs.]

Synopsis [Procedures to support the solver feedback.]

Author [Alan Mishchenko <alanmi@eecs.berkeley.edu>]

Affiliation [UC Berkeley]

Date [Ver. 2.0. Started - October 1, 2004]

Revision [

Id
fraigFeed.c,v 1.8 2005/07/08 01:01:31 alanmi Exp

] DECLARATIONS ///

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

Synopsis [Get the number and values of the PI variables.]

Description [Returns the number of PI variables involved in this feedback. Fills in the internal presence and value data for the primary inputs.]

SideEffects []

SeeAlso []

Definition at line 121 of file fraigFeed.c.

00122 {
00123     Fraig_Node_t * pNode;
00124     int i, nVars, nVarsPis, * pVars;
00125 
00126     // clean the presence flag for all PIs
00127     for ( i = 0; i < p->vInputs->nSize; i++ )
00128     {
00129         pNode = p->vInputs->pArray[i];
00130         pNode->fFeedUse = 0;
00131     }
00132 
00133     // get the variables involved in the feedback
00134     nVars = Msat_IntVecReadSize(vVars);
00135     pVars = Msat_IntVecReadArray(vVars);
00136 
00137     // set the values for the present variables
00138     nVarsPis = 0;
00139     for ( i = 0; i < nVars; i++ )
00140     {
00141         pNode = p->vNodes->pArray[ pVars[i] ];
00142         if ( !Fraig_NodeIsVar(pNode) )
00143             continue;
00144         // set its value
00145         pNode->fFeedUse = 1;
00146         pNode->fFeedVal = !MSAT_LITSIGN(pModel[pVars[i]]);
00147         nVarsPis++;
00148     }
00149     return nVarsPis;
00150 }

void Fraig_FeedBackVerify ( Fraig_Man_t p,
Fraig_Node_t pOld,
Fraig_Node_t pNew 
) [static]

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

Synopsis [Checks that the SAT solver pattern indeed distinquishes the nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 248 of file fraigFeed.c.

00249 {
00250     int fValue1, fValue2, iPat;
00251     iPat   = Msat_IntVecReadEntry( p->vPatsReal, Msat_IntVecReadSize(p->vPatsReal)-1 );
00252     fValue1 = (Fraig_BitStringHasBit( pOld->puSimD, iPat ));
00253     fValue2 = (Fraig_BitStringHasBit( pNew->puSimD, iPat ));
00254 /*
00255 Fraig_PrintNode( p, pOld );
00256 printf( "\n" );
00257 Fraig_PrintNode( p, pNew );
00258 printf( "\n" );
00259 */
00260 //    assert( fValue1 != fValue2 );
00261 }

int Fraig_GetHittingPattern ( unsigned *  pSims,
int  nWords 
) [static]

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

Synopsis [Select the pattern, which hits this column.]

Description []

SideEffects []

SeeAlso []

Definition at line 583 of file fraigFeed.c.

00584 {
00585     int i, b;
00586     for ( i = 0; i < nWords; i++ )
00587     {
00588         if ( pSims[i] == 0 )
00589             continue;
00590         for ( b = 0; b < 32; b++ )
00591             if ( pSims[i] & (1 << b) )
00592                 return i * 32 + b;
00593     }
00594     return -1;
00595 }

int Fraig_GetSmallestColumn ( int *  pHits,
int  nHits 
) [static]

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

Synopsis [Selects the column, which has the smallest number of hits.]

Description []

SideEffects []

SeeAlso []

Definition at line 551 of file fraigFeed.c.

00552 {
00553     int i, iColMin = -1, nHitsMin = 1000000;
00554     for ( i = 0; i < nHits; i++ )
00555     {
00556         // skip covered columns
00557         if ( pHits[i] == 0 )
00558             continue;
00559         // take the column if it can only be covered by one pattern
00560         if ( pHits[i] == 1 )
00561             return i;
00562         // find the column, which requires the smallest number of patterns
00563         if ( nHitsMin > pHits[i] )
00564         {
00565             nHitsMin = pHits[i];
00566             iColMin = i;
00567         }
00568     }
00569     return iColMin;
00570 }

int* Fraig_ManAllocCounterExample ( Fraig_Man_t p  ) 

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

Synopsis [Generated trivial counter example.]

Description []

SideEffects []

SeeAlso []

Definition at line 784 of file fraigFeed.c.

00785 {
00786     int * pModel;
00787     pModel = ALLOC( int, p->vInputs->nSize );
00788     memset( pModel, 0, sizeof(int) * p->vInputs->nSize );
00789     return pModel;
00790 }

int* Fraig_ManSaveCounterExample ( Fraig_Man_t p,
Fraig_Node_t pNode 
)

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

Synopsis [Saves the counter example.]

Description []

SideEffects []

SeeAlso []

Definition at line 857 of file fraigFeed.c.

00858 {
00859     int * pModel;
00860     int iPattern;
00861     int i, fCompl;
00862 
00863     // the node can be complemented
00864     fCompl = Fraig_IsComplement(pNode);
00865     // because we compare with constant 0, p->pConst1 should also be complemented
00866     fCompl = !fCompl;
00867 
00868     // derive the model
00869     pModel = Fraig_ManAllocCounterExample( p );
00870     iPattern = Fraig_FindFirstDiff( p->pConst1, Fraig_Regular(pNode), fCompl, p->nWordsRand, 1 );
00871     if ( iPattern >= 0 )
00872     {
00873         for ( i = 0; i < p->vInputs->nSize; i++ )
00874             if ( Fraig_BitStringHasBit( p->vInputs->pArray[i]->puSimR, iPattern ) )
00875                 pModel[i] = 1;
00876 /*
00877 printf( "SAT solver's pattern:\n" );
00878 for ( i = 0; i < p->vInputs->nSize; i++ )
00879     printf( "%d", pModel[i] );
00880 printf( "\n" );
00881 */
00882         assert( Fraig_ManSimulateBitNode( p, pNode, pModel ) );
00883         return pModel;
00884     }
00885     iPattern = Fraig_FindFirstDiff( p->pConst1, Fraig_Regular(pNode), fCompl, p->iWordStart, 0 );
00886     if ( iPattern >= 0 )
00887     {
00888         for ( i = 0; i < p->vInputs->nSize; i++ )
00889             if ( Fraig_BitStringHasBit( p->vInputs->pArray[i]->puSimD, iPattern ) )
00890                 pModel[i] = 1;
00891 /*
00892 printf( "SAT solver's pattern:\n" );
00893 for ( i = 0; i < p->vInputs->nSize; i++ )
00894     printf( "%d", pModel[i] );
00895 printf( "\n" );
00896 */
00897         assert( Fraig_ManSimulateBitNode( p, pNode, pModel ) );
00898         return pModel;
00899     }
00900     FREE( pModel );
00901     return NULL;
00902 }

int Fraig_ManSimulateBitNode ( Fraig_Man_t p,
Fraig_Node_t pNode,
int *  pModel 
)

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

Synopsis [Simulates one bit.]

Description []

SideEffects []

SeeAlso []

Definition at line 829 of file fraigFeed.c.

00830 {
00831     int fCompl, RetValue, i;
00832     // set the PI values
00833     Fraig_ManIncrementTravId( p );
00834     for ( i = 0; i < p->vInputs->nSize; i++ )
00835     {
00836         Fraig_NodeSetTravIdCurrent( p, p->vInputs->pArray[i] );
00837         p->vInputs->pArray[i]->fMark3 = pModel[i];
00838     }
00839     // perform the traversal
00840     fCompl = Fraig_IsComplement(pNode);
00841     RetValue = Fraig_ManSimulateBitNode_rec( p, Fraig_Regular(pNode) );
00842     return fCompl ^ RetValue;
00843 }

int Fraig_ManSimulateBitNode_rec ( Fraig_Man_t p,
Fraig_Node_t pNode 
)

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

Synopsis [Saves the counter example.]

Description []

SideEffects []

SeeAlso []

Definition at line 804 of file fraigFeed.c.

00805 {
00806     int Value0, Value1;
00807     if ( Fraig_NodeIsTravIdCurrent( p, pNode ) )
00808         return pNode->fMark3;
00809     Fraig_NodeSetTravIdCurrent( p, pNode );
00810     Value0 = Fraig_ManSimulateBitNode_rec( p, Fraig_Regular(pNode->p1) );
00811     Value1 = Fraig_ManSimulateBitNode_rec( p, Fraig_Regular(pNode->p2) );
00812     Value0 ^= Fraig_IsComplement(pNode->p1);
00813     Value1 ^= Fraig_IsComplement(pNode->p2);
00814     pNode->fMark3 = Value0 & Value1;
00815     return pNode->fMark3;
00816 }

void Fraig_ReallocateSimulationInfo ( Fraig_Man_t p  )  [static]

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

Synopsis [Doubles the size of simulation info.]

Description []

SideEffects []

SeeAlso []

Definition at line 708 of file fraigFeed.c.

00709 {
00710     Fraig_MemFixed_t * mmSimsNew;        // new memory manager for simulation info
00711     Fraig_Node_t * pNode;
00712     unsigned * pSimsNew;
00713     unsigned uSignOld;
00714     int i;
00715 
00716     // allocate a new memory manager
00717     p->nWordsDyna *= 2;
00718     mmSimsNew = Fraig_MemFixedStart( sizeof(unsigned) * (p->nWordsRand + p->nWordsDyna) );
00719 
00720     // set the new data for the constant node
00721     pNode = p->pConst1;
00722     pNode->puSimR = (unsigned *)Fraig_MemFixedEntryFetch( mmSimsNew );
00723     pNode->puSimD = pNode->puSimR + p->nWordsRand;
00724     memset( pNode->puSimR, 0, sizeof(unsigned) * p->nWordsRand );
00725     memset( pNode->puSimD, 0, sizeof(unsigned) * p->nWordsDyna );
00726 
00727     // copy the simulation info of the PIs
00728     for ( i = 0; i < p->vInputs->nSize; i++ )
00729     {
00730         pNode = p->vInputs->pArray[i];
00731         // copy the simulation info
00732         pSimsNew = (unsigned *)Fraig_MemFixedEntryFetch( mmSimsNew );
00733         memmove( pSimsNew, pNode->puSimR, sizeof(unsigned) * (p->nWordsRand + p->iWordStart) );
00734         // attach the new info
00735         pNode->puSimR = pSimsNew;
00736         pNode->puSimD = pNode->puSimR + p->nWordsRand;
00737         // signatures remain without changes
00738     }
00739 
00740     // replace the manager to free up some memory
00741     Fraig_MemFixedStop( p->mmSims, 0 );
00742     p->mmSims = mmSimsNew;
00743 
00744     // resimulate the internal nodes (this should lead to the same signatures)
00745     for ( i = 1; i < p->vNodes->nSize; i++ )
00746     {
00747         pNode = p->vNodes->pArray[i];
00748         if ( !Fraig_NodeIsAnd(pNode) )
00749             continue;
00750         // allocate memory for the simulation info
00751         pNode->puSimR = (unsigned *)Fraig_MemFixedEntryFetch( mmSimsNew );
00752         pNode->puSimD = pNode->puSimR + p->nWordsRand;
00753         // derive random simulation info
00754         uSignOld = pNode->uHashR;
00755         pNode->uHashR = 0;
00756         Fraig_NodeSimulate( pNode, 0, p->nWordsRand, 1 );
00757         assert( uSignOld == pNode->uHashR );
00758         // derive dynamic simulation info
00759         uSignOld = pNode->uHashD;
00760         pNode->uHashD = 0;
00761         Fraig_NodeSimulate( pNode, 0, p->iWordStart, 0 );
00762         assert( uSignOld == pNode->uHashD );
00763     }
00764 
00765     // realloc temporary storage
00766     p->pSimsReal = (unsigned *)Fraig_MemFixedEntryFetch( mmSimsNew );
00767     memset( p->pSimsReal, 0, sizeof(unsigned) * p->nWordsDyna );
00768     p->pSimsTemp = (unsigned *)Fraig_MemFixedEntryFetch( mmSimsNew );
00769     p->pSimsDiff = (unsigned *)Fraig_MemFixedEntryFetch( mmSimsNew );
00770 }


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