satProof2.h 9.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
/**CFile****************************************************************

  FileName    [satProof2.h]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [SAT solver.]

  Synopsis    [Proof logging.]

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

  Date        [Ver. 1.0. Started - January 1, 2004.]

  Revision    [$Id: satProof2.h,v 1.0 2004/01/01 1:00:00 alanmi Exp $]

***********************************************************************/
 
#ifndef ABC__sat__bsat__satProof2_h
#define ABC__sat__bsat__satProof2_h

////////////////////////////////////////////////////////////////////////
///                          INCLUDES                                ///
////////////////////////////////////////////////////////////////////////

#include "misc/vec/vec.h"

ABC_NAMESPACE_HEADER_START

////////////////////////////////////////////////////////////////////////
///                         PARAMETERS                               ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                    STRUCTURE DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

typedef struct Prf_Man_t_ Prf_Man_t;
struct Prf_Man_t_ 
{
    int             iFirst;    // first learned clause with proof
    int             iFirst2;   // first learned clause with proof
    int             nWords;    // the number of proof words
    word *          pInfo;     // pointer to the current proof
    Vec_Wrd_t *     vInfo;     // proof information
    Vec_Int_t *     vSaved;    // IDs of saved clauses
    Vec_Int_t *     vId2Pr;    // mapping proof IDs of problem clauses into bitshifts (user's array)
};

////////////////////////////////////////////////////////////////////////
///                       GLOBAL VARIABLES                           ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                       MACRO DEFINITIONS                          ///
////////////////////////////////////////////////////////////////////////

static inline int    Prf_BitWordNum( int nWidth )                { return (nWidth >> 6) + ((nWidth & 63) > 0);                           }
static inline int    Prf_ManSize( Prf_Man_t * p )                { return Vec_WrdSize( p->vInfo ) / p->nWords;                           }
static inline void   Prf_ManClearNewInfo( Prf_Man_t * p )        { int w; for ( w = 0; w < p->nWords; w++ ) Vec_WrdPush( p->vInfo, 0 );  }
static inline word * Prf_ManClauseInfo( Prf_Man_t * p, int Id )  { return Vec_WrdEntryP( p->vInfo, Id * p->nWords );                     }

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DECLARATIONS                        ///
////////////////////////////////////////////////////////////////////////


/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline Prf_Man_t * Prf_ManAlloc()
{
    Prf_Man_t * p;
    p = ABC_CALLOC( Prf_Man_t, 1 );
    p->iFirst  = -1;
    p->iFirst2 = -1;
    p->vInfo   = Vec_WrdAlloc( 1000 );
    p->vSaved  = Vec_IntAlloc( 1000 );
    return p;
}
static inline void Prf_ManStop( Prf_Man_t * p )
{
    if ( p == NULL )
        return;
    Vec_IntFree( p->vSaved );
    Vec_WrdFree( p->vInfo );
    ABC_FREE( p );
}
static inline void Prf_ManStopP( Prf_Man_t ** p )
{
    Prf_ManStop( *p );
    *p = NULL;
}
static inline double Prf_ManMemory( Prf_Man_t * p )
{
    return Vec_WrdMemory(p->vInfo) + Vec_IntMemory(p->vSaved) + sizeof(Prf_Man_t);
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void Prf_ManRestart( Prf_Man_t * p, Vec_Int_t * vId2Pr, int iFirst, int nWidth )
{
    assert( p->iFirst == -1 );
    p->iFirst = iFirst;
    p->nWords = Prf_BitWordNum( nWidth );
    p->vId2Pr = vId2Pr;
    p->pInfo  = NULL;
    Vec_WrdClear( p->vInfo );
}
static inline void Prf_ManGrow( Prf_Man_t * p, int nWidth )
{
    Vec_Wrd_t * vInfoNew;
    int i, w, nSize, nWordsNew;
    assert( p->iFirst >= 0 );
    assert( p->pInfo == NULL );
    if ( nWidth < 64 * p->nWords )
        return;
    // get word count after resizing
    nWordsNew = Abc_MaxInt( Prf_BitWordNum(nWidth), 2 * p->nWords );
    // remap the entries
    nSize = Prf_ManSize( p );
    vInfoNew = Vec_WrdAlloc( (nSize + 1000) * nWordsNew );
    for ( i = 0; i < nSize; i++ )
    {
        p->pInfo = Prf_ManClauseInfo( p, i );
        for ( w = 0; w < p->nWords; w++ )
            Vec_WrdPush( vInfoNew, p->pInfo[w] );
        for ( ; w < nWordsNew; w++ )
            Vec_WrdPush( vInfoNew, 0 );
    }
    Vec_WrdFree( p->vInfo );
    p->vInfo = vInfoNew;
    p->nWords = nWordsNew;
    p->pInfo = NULL;

}
static inline void Prf_ManShrink( Prf_Man_t * p, int iClause )
{
    assert( p->iFirst >= 0 );
    assert( iClause - p->iFirst >= 0 );
    assert( iClause - p->iFirst < Prf_ManSize(p) ); 
    Vec_WrdShrink( p->vInfo, (iClause - p->iFirst) * p->nWords );
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void Prf_ManAddSaved( Prf_Man_t * p, int i, int iNew )
{
    assert( p->iFirst >= 0 );
    if ( i < p->iFirst )
        return;
    if ( Vec_IntSize(p->vSaved) == 0 )
    {
        assert( p->iFirst2 == -1 );
        p->iFirst2 = iNew;
    }
    Vec_IntPush( p->vSaved, i );
}
static inline void Prf_ManCompact( Prf_Man_t * p, int iNew )
{
    int i, w, k = 0, Entry, nSize;
    assert( p->iFirst >= 0 );
    assert( p->pInfo == NULL );
    nSize = Prf_ManSize( p );
    Vec_IntForEachEntry( p->vSaved, Entry, i )
    {
        assert( Entry - p->iFirst >= 0 && Entry - p->iFirst < nSize );
        p->pInfo = Prf_ManClauseInfo( p, Entry - p->iFirst );
        for ( w = 0; w < p->nWords; w++ )
            Vec_WrdWriteEntry( p->vInfo, k++, p->pInfo[w] );
    }
    Vec_WrdShrink( p->vInfo, k );
    Vec_IntClear( p->vSaved );
    p->pInfo = NULL;
    // update first
    if ( p->iFirst2 == -1 )
        p->iFirst = iNew;
    else
        p->iFirst = p->iFirst2;
    p->iFirst2 = -1;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void Prf_ManChainResolve( Prf_Man_t * p, clause * c )
{
    assert( p->iFirst >= 0 );
    assert( p->pInfo != NULL );
    // add to proof info
    if ( c->lrn ) // learned clause
    {
        if ( clause_id(c) >= p->iFirst )
        {
            word * pProofStart;
            int w;
            assert( clause_id(c) - p->iFirst >= 0 );
            assert( clause_id(c) - p->iFirst < Prf_ManSize(p) ); 
            pProofStart = Prf_ManClauseInfo( p, clause_id(c) - p->iFirst );
            for ( w = 0; w < p->nWords; w++ )
                p->pInfo[w] |= pProofStart[w];
        }
    }
    else // problem clause
    {  
242
        if ( clause_id(c) >= 0 ) // has proof ID
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
        {
            int Entry;
            if ( p->vId2Pr == NULL )
                Entry = clause_id(c);
            else
                Entry = Vec_IntEntry( p->vId2Pr, clause_id(c) );
            if ( Entry >= 0 )
            {
                assert( Entry < 64 * p->nWords );
                Abc_InfoSetBit( (unsigned *)p->pInfo, Entry );
            }
        }
    }
}
static inline void Prf_ManChainStart( Prf_Man_t * p, clause * c )
{
    assert( p->iFirst >= 0 );
    // prepare info for new clause
    Prf_ManClearNewInfo( p );
    // get pointer to the proof
    assert( p->pInfo == NULL );
    p->pInfo = Prf_ManClauseInfo( p, Prf_ManSize(p)-1 );
    // add to proof info
    Prf_ManChainResolve( p, c );
}
static inline int Prf_ManChainStop( Prf_Man_t * p )
{
    assert( p->pInfo != NULL );
    p->pInfo = NULL;
    return 0;
}


/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline Vec_Int_t * Prf_ManUnsatCore( Prf_Man_t * p )
{
    Vec_Int_t * vCore;
    int i, Entry;
    assert( p->iFirst >= 0 );
    assert( p->pInfo == NULL );
Alan Mishchenko committed
293
    assert( Prf_ManSize(p) > 0 );
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
    vCore = Vec_IntAlloc( 64 * p->nWords );
    p->pInfo = Prf_ManClauseInfo( p, Prf_ManSize(p)-1 );
    if ( p->vId2Pr == NULL )
    {
        for ( i = 0; i < 64 * p->nWords; i++ )
            if ( Abc_InfoHasBit( (unsigned *)p->pInfo, i ) )
                Vec_IntPush( vCore, i );
    }
    else
    {
        Vec_IntForEachEntry( p->vId2Pr, Entry, i )
        {
            if ( Entry < 0 )
                continue;
            assert( Entry < 64 * p->nWords );
            if ( Abc_InfoHasBit( (unsigned *)p->pInfo, Entry ) )
                Vec_IntPush( vCore, i );
        }
    }
    p->pInfo = NULL;
    Vec_IntSort( vCore, 1 );
    return vCore;
}



ABC_NAMESPACE_HEADER_END

#endif

////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////