abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
satProof2.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [satProof2.h]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [SAT solver.]
8 
9  Synopsis [Proof logging.]
10 
11  Author [Alan Mishchenko <alanmi@eecs.berkeley.edu>]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - January 1, 2004.]
16 
17  Revision [$Id: satProof2.h,v 1.0 2004/01/01 1:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__sat__bsat__satProof2_h
22 #define ABC__sat__bsat__satProof2_h
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// INCLUDES ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 #include "misc/vec/vec.h"
29 
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// PARAMETERS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 ////////////////////////////////////////////////////////////////////////
37 /// STRUCTURE DEFINITIONS ///
38 ////////////////////////////////////////////////////////////////////////
39 
40 typedef struct Prf_Man_t_ Prf_Man_t;
41 struct Prf_Man_t_
42 {
43  int iFirst; // first learned clause with proof
44  int iFirst2; // first learned clause with proof
45  int nWords; // the number of proof words
46  word * pInfo; // pointer to the current proof
47  Vec_Wrd_t * vInfo; // proof information
48  Vec_Int_t * vSaved; // IDs of saved clauses
49  Vec_Int_t * vId2Pr; // mapping proof IDs of problem clauses into bitshifts (user's array)
50 };
51 
52 ////////////////////////////////////////////////////////////////////////
53 /// GLOBAL VARIABLES ///
54 ////////////////////////////////////////////////////////////////////////
55 
56 ////////////////////////////////////////////////////////////////////////
57 /// MACRO DEFINITIONS ///
58 ////////////////////////////////////////////////////////////////////////
59 
60 static inline int Prf_BitWordNum( int nWidth ) { return (nWidth >> 6) + ((nWidth & 63) > 0); }
61 static inline int Prf_ManSize( Prf_Man_t * p ) { return Vec_WrdSize( p->vInfo ) / p->nWords; }
62 static inline void Prf_ManClearNewInfo( Prf_Man_t * p ) { int w; for ( w = 0; w < p->nWords; w++ ) Vec_WrdPush( p->vInfo, 0 ); }
63 static inline word * Prf_ManClauseInfo( Prf_Man_t * p, int Id ) { return Vec_WrdEntryP( p->vInfo, Id * p->nWords ); }
64 
65 ////////////////////////////////////////////////////////////////////////
66 /// FUNCTION DECLARATIONS ///
67 ////////////////////////////////////////////////////////////////////////
68 
69 
70 /**Function*************************************************************
71 
72  Synopsis []
73 
74  Description []
75 
76  SideEffects []
77 
78  SeeAlso []
79 
80 ***********************************************************************/
81 static inline Prf_Man_t * Prf_ManAlloc()
82 {
83  Prf_Man_t * p;
84  p = ABC_CALLOC( Prf_Man_t, 1 );
85  p->iFirst = -1;
86  p->iFirst2 = -1;
87  p->vInfo = Vec_WrdAlloc( 1000 );
88  p->vSaved = Vec_IntAlloc( 1000 );
89  return p;
90 }
91 static inline void Prf_ManStop( Prf_Man_t * p )
92 {
93  if ( p == NULL )
94  return;
95  Vec_IntFree( p->vSaved );
96  Vec_WrdFree( p->vInfo );
97  ABC_FREE( p );
98 }
99 static inline void Prf_ManStopP( Prf_Man_t ** p )
100 {
101  Prf_ManStop( *p );
102  *p = NULL;
103 }
104 static inline double Prf_ManMemory( Prf_Man_t * p )
105 {
106  return Vec_WrdMemory(p->vInfo) + Vec_IntMemory(p->vSaved) + sizeof(Prf_Man_t);
107 }
108 
109 /**Function*************************************************************
110 
111  Synopsis []
112 
113  Description []
114 
115  SideEffects []
116 
117  SeeAlso []
118 
119 ***********************************************************************/
120 static inline void Prf_ManRestart( Prf_Man_t * p, Vec_Int_t * vId2Pr, int iFirst, int nWidth )
121 {
122  assert( p->iFirst == -1 );
123  p->iFirst = iFirst;
124  p->nWords = Prf_BitWordNum( nWidth );
125  p->vId2Pr = vId2Pr;
126  p->pInfo = NULL;
127  Vec_WrdClear( p->vInfo );
128 }
129 static inline void Prf_ManGrow( Prf_Man_t * p, int nWidth )
130 {
131  Vec_Wrd_t * vInfoNew;
132  int i, w, nSize, nWordsNew;
133  assert( p->iFirst >= 0 );
134  assert( p->pInfo == NULL );
135  if ( nWidth < 64 * p->nWords )
136  return;
137  // get word count after resizing
138  nWordsNew = Abc_MaxInt( Prf_BitWordNum(nWidth), 2 * p->nWords );
139  // remap the entries
140  nSize = Prf_ManSize( p );
141  vInfoNew = Vec_WrdAlloc( (nSize + 1000) * nWordsNew );
142  for ( i = 0; i < nSize; i++ )
143  {
144  p->pInfo = Prf_ManClauseInfo( p, i );
145  for ( w = 0; w < p->nWords; w++ )
146  Vec_WrdPush( vInfoNew, p->pInfo[w] );
147  for ( ; w < nWordsNew; w++ )
148  Vec_WrdPush( vInfoNew, 0 );
149  }
150  Vec_WrdFree( p->vInfo );
151  p->vInfo = vInfoNew;
152  p->nWords = nWordsNew;
153  p->pInfo = NULL;
154 
155 }
156 static inline void Prf_ManShrink( Prf_Man_t * p, int iClause )
157 {
158  assert( p->iFirst >= 0 );
159  assert( iClause - p->iFirst >= 0 );
160  assert( iClause - p->iFirst < Prf_ManSize(p) );
161  Vec_WrdShrink( p->vInfo, (iClause - p->iFirst) * p->nWords );
162 }
163 
164 /**Function*************************************************************
165 
166  Synopsis []
167 
168  Description []
169 
170  SideEffects []
171 
172  SeeAlso []
173 
174 ***********************************************************************/
175 static inline void Prf_ManAddSaved( Prf_Man_t * p, int i, int iNew )
176 {
177  assert( p->iFirst >= 0 );
178  if ( i < p->iFirst )
179  return;
180  if ( Vec_IntSize(p->vSaved) == 0 )
181  {
182  assert( p->iFirst2 == -1 );
183  p->iFirst2 = iNew;
184  }
185  Vec_IntPush( p->vSaved, i );
186 }
187 static inline void Prf_ManCompact( Prf_Man_t * p, int iNew )
188 {
189  int i, w, k = 0, Entry, nSize;
190  assert( p->iFirst >= 0 );
191  assert( p->pInfo == NULL );
192  nSize = Prf_ManSize( p );
193  Vec_IntForEachEntry( p->vSaved, Entry, i )
194  {
195  assert( Entry - p->iFirst >= 0 && Entry - p->iFirst < nSize );
196  p->pInfo = Prf_ManClauseInfo( p, Entry - p->iFirst );
197  for ( w = 0; w < p->nWords; w++ )
198  Vec_WrdWriteEntry( p->vInfo, k++, p->pInfo[w] );
199  }
200  Vec_WrdShrink( p->vInfo, k );
201  Vec_IntClear( p->vSaved );
202  p->pInfo = NULL;
203  // update first
204  if ( p->iFirst2 == -1 )
205  p->iFirst = iNew;
206  else
207  p->iFirst = p->iFirst2;
208  p->iFirst2 = -1;
209 }
210 
211 /**Function*************************************************************
212 
213  Synopsis []
214 
215  Description []
216 
217  SideEffects []
218 
219  SeeAlso []
220 
221 ***********************************************************************/
222 static inline void Prf_ManChainResolve( Prf_Man_t * p, clause * c )
223 {
224  assert( p->iFirst >= 0 );
225  assert( p->pInfo != NULL );
226  // add to proof info
227  if ( c->lrn ) // learned clause
228  {
229  if ( clause_id(c) >= p->iFirst )
230  {
231  word * pProofStart;
232  int w;
233  assert( clause_id(c) - p->iFirst >= 0 );
234  assert( clause_id(c) - p->iFirst < Prf_ManSize(p) );
235  pProofStart = Prf_ManClauseInfo( p, clause_id(c) - p->iFirst );
236  for ( w = 0; w < p->nWords; w++ )
237  p->pInfo[w] |= pProofStart[w];
238  }
239  }
240  else // problem clause
241  {
242  if ( clause_id(c) >= 0 ) // has proof ID
243  {
244  int Entry;
245  if ( p->vId2Pr == NULL )
246  Entry = clause_id(c);
247  else
248  Entry = Vec_IntEntry( p->vId2Pr, clause_id(c) );
249  if ( Entry >= 0 )
250  {
251  assert( Entry < 64 * p->nWords );
252  Abc_InfoSetBit( (unsigned *)p->pInfo, Entry );
253  }
254  }
255  }
256 }
257 static inline void Prf_ManChainStart( Prf_Man_t * p, clause * c )
258 {
259  assert( p->iFirst >= 0 );
260  // prepare info for new clause
261  Prf_ManClearNewInfo( p );
262  // get pointer to the proof
263  assert( p->pInfo == NULL );
264  p->pInfo = Prf_ManClauseInfo( p, Prf_ManSize(p)-1 );
265  // add to proof info
266  Prf_ManChainResolve( p, c );
267 }
268 static inline int Prf_ManChainStop( Prf_Man_t * p )
269 {
270  assert( p->pInfo != NULL );
271  p->pInfo = NULL;
272  return 0;
273 }
274 
275 
276 /**Function*************************************************************
277 
278  Synopsis []
279 
280  Description []
281 
282  SideEffects []
283 
284  SeeAlso []
285 
286 ***********************************************************************/
287 static inline Vec_Int_t * Prf_ManUnsatCore( Prf_Man_t * p )
288 {
289  Vec_Int_t * vCore;
290  int i, Entry;
291  assert( p->iFirst >= 0 );
292  assert( p->pInfo == NULL );
293  assert( Prf_ManSize(p) > 0 );
294  vCore = Vec_IntAlloc( 64 * p->nWords );
295  p->pInfo = Prf_ManClauseInfo( p, Prf_ManSize(p)-1 );
296  if ( p->vId2Pr == NULL )
297  {
298  for ( i = 0; i < 64 * p->nWords; i++ )
299  if ( Abc_InfoHasBit( (unsigned *)p->pInfo, i ) )
300  Vec_IntPush( vCore, i );
301  }
302  else
303  {
304  Vec_IntForEachEntry( p->vId2Pr, Entry, i )
305  {
306  if ( Entry < 0 )
307  continue;
308  assert( Entry < 64 * p->nWords );
309  if ( Abc_InfoHasBit( (unsigned *)p->pInfo, Entry ) )
310  Vec_IntPush( vCore, i );
311  }
312  }
313  p->pInfo = NULL;
314  Vec_IntSort( vCore, 1 );
315  return vCore;
316 }
317 
318 
319 
321 
322 #endif
323 
324 ////////////////////////////////////////////////////////////////////////
325 /// END OF FILE ///
326 ////////////////////////////////////////////////////////////////////////
327 
static void Prf_ManClearNewInfo(Prf_Man_t *p)
Definition: satProof2.h:62
static double Vec_IntMemory(Vec_Int_t *p)
Definition: vecInt.h:384
static double Vec_WrdMemory(Vec_Wrd_t *p)
Definition: vecWrd.h:368
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Abc_InfoHasBit(unsigned *p, int i)
Definition: abc_global.h:258
static void Vec_WrdPush(Vec_Wrd_t *p, word Entry)
Definition: vecWrd.h:618
static void Prf_ManChainResolve(Prf_Man_t *p, clause *c)
Definition: satProof2.h:222
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static int Vec_WrdSize(Vec_Wrd_t *p)
Definition: vecWrd.h:336
Vec_Int_t * vId2Pr
Definition: satProof2.h:49
static void Vec_IntSort(Vec_Int_t *p, int fReverse)
Definition: vecInt.h:1293
static int clause_id(clause *c)
Definition: satClause.h:144
int nWords
Definition: abcNpn.c:127
typedefABC_NAMESPACE_HEADER_START struct Prf_Man_t_ Prf_Man_t
INCLUDES ///.
Definition: satProof2.h:40
static void Prf_ManChainStart(Prf_Man_t *p, clause *c)
Definition: satProof2.h:257
word * pInfo
Definition: satProof2.h:46
static void Prf_ManAddSaved(Prf_Man_t *p, int i, int iNew)
Definition: satProof2.h:175
int nWords
Definition: satProof2.h:45
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void Vec_WrdClear(Vec_Wrd_t *p)
Definition: vecWrd.h:602
static Prf_Man_t * Prf_ManAlloc()
FUNCTION DECLARATIONS ///.
Definition: satProof2.h:81
static void Vec_WrdShrink(Vec_Wrd_t *p, int nSizeNew)
Definition: vecWrd.h:585
static void Vec_WrdWriteEntry(Vec_Wrd_t *p, int i, word Entry)
Definition: vecWrd.h:418
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static word * Prf_ManClauseInfo(Prf_Man_t *p, int Id)
Definition: satProof2.h:63
static void Vec_WrdFree(Vec_Wrd_t *p)
Definition: vecWrd.h:260
static void Prf_ManShrink(Prf_Man_t *p, int iClause)
Definition: satProof2.h:156
static void Prf_ManCompact(Prf_Man_t *p, int iNew)
Definition: satProof2.h:187
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
static Vec_Int_t * Prf_ManUnsatCore(Prf_Man_t *p)
Definition: satProof2.h:287
static Vec_Wrd_t * Vec_WrdAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecWrd.h:80
static double Prf_ManMemory(Prf_Man_t *p)
Definition: satProof2.h:104
static int Prf_ManChainStop(Prf_Man_t *p)
Definition: satProof2.h:268
static void Abc_InfoSetBit(unsigned *p, int i)
Definition: abc_global.h:259
static void Prf_ManRestart(Prf_Man_t *p, Vec_Int_t *vId2Pr, int iFirst, int nWidth)
Definition: satProof2.h:120
Vec_Wrd_t * vInfo
Definition: satProof2.h:47
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
static void Prf_ManGrow(Prf_Man_t *p, int nWidth)
Definition: satProof2.h:129
int iFirst
Definition: satProof2.h:43
#define ABC_FREE(obj)
Definition: abc_global.h:232
static void Prf_ManStop(Prf_Man_t *p)
Definition: satProof2.h:91
static int Prf_BitWordNum(int nWidth)
GLOBAL VARIABLES ///.
Definition: satProof2.h:60
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
unsigned lrn
Definition: satClause.h:51
static void Prf_ManStopP(Prf_Man_t **p)
Definition: satProof2.h:99
#define assert(ex)
Definition: util_old.h:213
static int Prf_ManSize(Prf_Man_t *p)
Definition: satProof2.h:61
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition: vecWrd.h:42
int iFirst2
Definition: satProof2.h:44
Vec_Int_t * vSaved
Definition: satProof2.h:48
static word * Vec_WrdEntryP(Vec_Wrd_t *p, int i)
Definition: vecWrd.h:401