abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
intM114p.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [intM114p.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Interpolation engine.]
8 
9  Synopsis [Intepolation using interfaced to MiniSat-1.14p.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 24, 2008.]
16 
17  Revision [$Id: intM114p.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "intInt.h"
22 #include "sat/psat/m114p.h"
23 
24 #ifdef ABC_USE_LIBRARIES
25 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 /**Function*************************************************************
37 
38  Synopsis [Returns the SAT solver for one interpolation run.]
39 
40  Description [pInter is the previous interpolant. pAig is one time frame.
41  pFrames is the unrolled time frames.]
42 
43  SideEffects []
44 
45  SeeAlso []
46 
47 ***********************************************************************/
48 M114p_Solver_t Inter_ManDeriveSatSolverM114p(
49  Aig_Man_t * pInter, Cnf_Dat_t * pCnfInter,
50  Aig_Man_t * pAig, Cnf_Dat_t * pCnfAig,
51  Aig_Man_t * pFrames, Cnf_Dat_t * pCnfFrames,
52  Vec_Int_t ** pvMapRoots, Vec_Int_t ** pvMapVars )
53 {
55  Aig_Obj_t * pObj, * pObj2;
56  int i, Lits[2];
57 
58  // sanity checks
59  assert( Aig_ManRegNum(pInter) == 0 );
60  assert( Aig_ManRegNum(pAig) > 0 );
61  assert( Aig_ManRegNum(pFrames) == 0 );
62  assert( Aig_ManCoNum(pInter) == 1 );
63  assert( Aig_ManCoNum(pFrames) == 1 );
64  assert( Aig_ManCiNum(pInter) == Aig_ManRegNum(pAig) );
65 // assert( (Aig_ManCiNum(pFrames) - Aig_ManRegNum(pAig)) % Saig_ManPiNum(pAig) == 0 );
66 
67  // prepare CNFs
68  Cnf_DataLift( pCnfAig, pCnfFrames->nVars );
69  Cnf_DataLift( pCnfInter, pCnfFrames->nVars + pCnfAig->nVars );
70 
71  *pvMapRoots = Vec_IntAlloc( 10000 );
72  *pvMapVars = Vec_IntAlloc( 0 );
73  Vec_IntFill( *pvMapVars, pCnfInter->nVars + pCnfAig->nVars + pCnfFrames->nVars, -1 );
74  for ( i = 0; i < pCnfFrames->nVars; i++ )
75  Vec_IntWriteEntry( *pvMapVars, i, -2 );
76 
77  // start the solver
78  pSat = M114p_SolverNew( 1 );
79  M114p_SolverSetVarNum( pSat, pCnfInter->nVars + pCnfAig->nVars + pCnfFrames->nVars );
80 
81  // add clauses of A
82  // interpolant
83  for ( i = 0; i < pCnfInter->nClauses; i++ )
84  {
85  Vec_IntPush( *pvMapRoots, 0 );
86  if ( !M114p_SolverAddClause( pSat, pCnfInter->pClauses[i], pCnfInter->pClauses[i+1] ) )
87  assert( 0 );
88  }
89  // connector clauses
90  Aig_ManForEachCi( pInter, pObj, i )
91  {
92  pObj2 = Saig_ManLo( pAig, i );
93  Lits[0] = toLitCond( pCnfInter->pVarNums[pObj->Id], 0 );
94  Lits[1] = toLitCond( pCnfAig->pVarNums[pObj2->Id], 1 );
95  Vec_IntPush( *pvMapRoots, 0 );
96  if ( !M114p_SolverAddClause( pSat, Lits, Lits+2 ) )
97  assert( 0 );
98  Lits[0] = toLitCond( pCnfInter->pVarNums[pObj->Id], 1 );
99  Lits[1] = toLitCond( pCnfAig->pVarNums[pObj2->Id], 0 );
100  Vec_IntPush( *pvMapRoots, 0 );
101  if ( !M114p_SolverAddClause( pSat, Lits, Lits+2 ) )
102  assert( 0 );
103  }
104  // one timeframe
105  for ( i = 0; i < pCnfAig->nClauses; i++ )
106  {
107  Vec_IntPush( *pvMapRoots, 0 );
108  if ( !M114p_SolverAddClause( pSat, pCnfAig->pClauses[i], pCnfAig->pClauses[i+1] ) )
109  assert( 0 );
110  }
111  // connector clauses
112  Aig_ManForEachCi( pFrames, pObj, i )
113  {
114  if ( i == Aig_ManRegNum(pAig) )
115  break;
116 // Vec_IntPush( vVarsAB, pCnfFrames->pVarNums[pObj->Id] );
117  Vec_IntWriteEntry( *pvMapVars, pCnfFrames->pVarNums[pObj->Id], i );
118 
119  pObj2 = Saig_ManLi( pAig, i );
120  Lits[0] = toLitCond( pCnfFrames->pVarNums[pObj->Id], 0 );
121  Lits[1] = toLitCond( pCnfAig->pVarNums[pObj2->Id], 1 );
122  Vec_IntPush( *pvMapRoots, 0 );
123  if ( !M114p_SolverAddClause( pSat, Lits, Lits+2 ) )
124  assert( 0 );
125  Lits[0] = toLitCond( pCnfFrames->pVarNums[pObj->Id], 1 );
126  Lits[1] = toLitCond( pCnfAig->pVarNums[pObj2->Id], 0 );
127  Vec_IntPush( *pvMapRoots, 0 );
128  if ( !M114p_SolverAddClause( pSat, Lits, Lits+2 ) )
129  assert( 0 );
130  }
131  // add clauses of B
132  for ( i = 0; i < pCnfFrames->nClauses; i++ )
133  {
134  Vec_IntPush( *pvMapRoots, 1 );
135  if ( !M114p_SolverAddClause( pSat, pCnfFrames->pClauses[i], pCnfFrames->pClauses[i+1] ) )
136  {
137 // assert( 0 );
138  break;
139  }
140  }
141  // return clauses to the original state
142  Cnf_DataLift( pCnfAig, -pCnfFrames->nVars );
143  Cnf_DataLift( pCnfInter, -pCnfFrames->nVars -pCnfAig->nVars );
144  return pSat;
145 }
146 
147 
148 /**Function*************************************************************
149 
150  Synopsis [Performs one resolution step.]
151 
152  Description []
153 
154  SideEffects []
155 
156  SeeAlso []
157 
158 ***********************************************************************/
159 int Inter_ManResolveM114p( Vec_Int_t * vResolvent, int * pLits, int nLits, int iVar )
160 {
161  int i, k, iLit = -1, fFound = 0;
162  // find the variable in the clause
163  for ( i = 0; i < vResolvent->nSize; i++ )
164  if ( lit_var(vResolvent->pArray[i]) == iVar )
165  {
166  iLit = vResolvent->pArray[i];
167  vResolvent->pArray[i] = vResolvent->pArray[--vResolvent->nSize];
168  break;
169  }
170  assert( iLit != -1 );
171  // add other variables
172  for ( i = 0; i < nLits; i++ )
173  {
174  if ( lit_var(pLits[i]) == iVar )
175  {
176  assert( iLit == lit_neg(pLits[i]) );
177  fFound = 1;
178  continue;
179  }
180  // check if this literal appears
181  for ( k = 0; k < vResolvent->nSize; k++ )
182  if ( vResolvent->pArray[k] == pLits[i] )
183  break;
184  if ( k < vResolvent->nSize )
185  continue;
186  // add this literal
187  Vec_IntPush( vResolvent, pLits[i] );
188  }
189  assert( fFound );
190  return 1;
191 }
192 
193 /**Function*************************************************************
194 
195  Synopsis [Computes interpolant using MiniSat-1.14p.]
196 
197  Description [Assumes that the solver returned UNSAT and proof
198  logging was enabled. Array vMapRoots maps number of each root clause
199  into 0 (clause of A) or 1 (clause of B). Array vMapVars maps each SAT
200  solver variable into -1 (var of A), -2 (var of B), and <num> (var of C),
201  where <num> is the var's 0-based number in the ordering of C variables.]
202 
203  SideEffects []
204 
205  SeeAlso []
206 
207 ***********************************************************************/
208 Aig_Man_t * Inter_ManInterpolateM114pPudlak( M114p_Solver_t s, Vec_Int_t * vMapRoots, Vec_Int_t * vMapVars )
209 {
210  Aig_Man_t * p;
211  Aig_Obj_t * pInter, * pInter2, * pVar;
212  Vec_Ptr_t * vInters;
213  Vec_Int_t * vLiterals, * vClauses, * vResolvent;
214  int * pLitsNext, nLitsNext, nOffset, iLit;
215  int * pLits, * pClauses, * pVars;
216  int nLits, nVars, i, k, v, iVar;
218  vInters = Vec_PtrAlloc( 1000 );
219 
220  vLiterals = Vec_IntAlloc( 10000 );
221  vClauses = Vec_IntAlloc( 1000 );
222  vResolvent = Vec_IntAlloc( 100 );
223 
224  // create elementary variables
225  p = Aig_ManStart( 10000 );
226  Vec_IntForEachEntry( vMapVars, iVar, i )
227  if ( iVar >= 0 )
228  Aig_IthVar(p, iVar);
229  // process root clauses
230  M114p_SolverForEachRoot( s, &pLits, nLits, i )
231  {
232  if ( Vec_IntEntry(vMapRoots, i) == 1 ) // clause of B
233  pInter = Aig_ManConst1(p);
234  else // clause of A
235  pInter = Aig_ManConst0(p);
236  Vec_PtrPush( vInters, pInter );
237 
238  // save the root clause
239  Vec_IntPush( vClauses, Vec_IntSize(vLiterals) );
240  Vec_IntPush( vLiterals, nLits );
241  for ( v = 0; v < nLits; v++ )
242  Vec_IntPush( vLiterals, pLits[v] );
243  }
244  assert( Vec_PtrSize(vInters) == Vec_IntSize(vMapRoots) );
245 
246  // process learned clauses
247  M114p_SolverForEachChain( s, &pClauses, &pVars, nVars, i )
248  {
249  pInter = Vec_PtrEntry( vInters, pClauses[0] );
250 
251  // initialize the resolvent
252  nOffset = Vec_IntEntry( vClauses, pClauses[0] );
253  nLitsNext = Vec_IntEntry( vLiterals, nOffset );
254  pLitsNext = Vec_IntArray(vLiterals) + nOffset + 1;
255  Vec_IntClear( vResolvent );
256  for ( v = 0; v < nLitsNext; v++ )
257  Vec_IntPush( vResolvent, pLitsNext[v] );
258 
259  for ( k = 0; k < nVars; k++ )
260  {
261  iVar = Vec_IntEntry( vMapVars, pVars[k] );
262  pInter2 = Vec_PtrEntry( vInters, pClauses[k+1] );
263 
264  // resolve it with the next clause
265  nOffset = Vec_IntEntry( vClauses, pClauses[k+1] );
266  nLitsNext = Vec_IntEntry( vLiterals, nOffset );
267  pLitsNext = Vec_IntArray(vLiterals) + nOffset + 1;
268  Inter_ManResolveM114p( vResolvent, pLitsNext, nLitsNext, pVars[k] );
269 
270  if ( iVar == -1 ) // var of A
271  pInter = Aig_Or( p, pInter, pInter2 );
272  else if ( iVar == -2 ) // var of B
273  pInter = Aig_And( p, pInter, pInter2 );
274  else // var of C
275  {
276  // check polarity of the pivot variable in the clause
277  for ( v = 0; v < nLitsNext; v++ )
278  if ( lit_var(pLitsNext[v]) == pVars[k] )
279  break;
280  assert( v < nLitsNext );
281  pVar = Aig_NotCond( Aig_IthVar(p, iVar), lit_sign(pLitsNext[v]) );
282  pInter = Aig_Mux( p, pVar, pInter, pInter2 );
283  }
284  }
285  Vec_PtrPush( vInters, pInter );
286 
287  // store the resulting clause
288  Vec_IntPush( vClauses, Vec_IntSize(vLiterals) );
289  Vec_IntPush( vLiterals, Vec_IntSize(vResolvent) );
290  Vec_IntForEachEntry( vResolvent, iLit, v )
291  Vec_IntPush( vLiterals, iLit );
292  }
294  assert( Vec_IntSize(vResolvent) == 0 ); // the empty clause
295  Vec_PtrFree( vInters );
296  Vec_IntFree( vLiterals );
297  Vec_IntFree( vClauses );
298  Vec_IntFree( vResolvent );
299  Aig_ObjCreateCo( p, pInter );
300  Aig_ManCleanup( p );
301  return p;
302 }
303 
304 
305 /**Function*************************************************************
306 
307  Synopsis [Computes interpolant using MiniSat-1.14p.]
308 
309  Description [Assumes that the solver returned UNSAT and proof
310  logging was enabled. Array vMapRoots maps number of each root clause
311  into 0 (clause of A) or 1 (clause of B). Array vMapVars maps each SAT
312  solver variable into -1 (var of A), -2 (var of B), and <num> (var of C),
313  where <num> is the var's 0-based number in the ordering of C variables.]
314 
315  SideEffects []
316 
317  SeeAlso []
318 
319 ***********************************************************************/
320 Aig_Man_t * Inter_ManpInterpolateM114( M114p_Solver_t s, Vec_Int_t * vMapRoots, Vec_Int_t * vMapVars )
321 {
322  Aig_Man_t * p;
323  Aig_Obj_t * pInter, * pInter2, * pVar;
324  Vec_Ptr_t * vInters;
325  int * pLits, * pClauses, * pVars;
326  int nLits, nVars, i, k, iVar;
327  int nClauses;
328 
329  nClauses = M114p_SolverProofClauseNum(s);
330 
332 
333  vInters = Vec_PtrAlloc( 1000 );
334  // process root clauses
335  p = Aig_ManStart( 10000 );
336  M114p_SolverForEachRoot( s, &pLits, nLits, i )
337  {
338  if ( Vec_IntEntry(vMapRoots, i) == 1 ) // clause of B
339  pInter = Aig_ManConst1(p);
340  else // clause of A
341  {
342  pInter = Aig_ManConst0(p);
343  for ( k = 0; k < nLits; k++ )
344  {
345  iVar = Vec_IntEntry( vMapVars, lit_var(pLits[k]) );
346  if ( iVar < 0 ) // var of A or B
347  continue;
348  // this is a variable of C
349  pVar = Aig_NotCond( Aig_IthVar(p, iVar), lit_sign(pLits[k]) );
350  pInter = Aig_Or( p, pInter, pVar );
351  }
352  }
353  Vec_PtrPush( vInters, pInter );
354  }
355 // assert( Vec_PtrSize(vInters) == Vec_IntSize(vMapRoots) );
356 
357  // process learned clauses
358  M114p_SolverForEachChain( s, &pClauses, &pVars, nVars, i )
359  {
360  pInter = Vec_PtrEntry( vInters, pClauses[0] );
361  for ( k = 0; k < nVars; k++ )
362  {
363  iVar = Vec_IntEntry( vMapVars, pVars[k] );
364  pInter2 = Vec_PtrEntry( vInters, pClauses[k+1] );
365  if ( iVar == -1 ) // var of A
366  pInter = Aig_Or( p, pInter, pInter2 );
367  else // var of B or C
368  pInter = Aig_And( p, pInter, pInter2 );
369  }
370  Vec_PtrPush( vInters, pInter );
371  }
372 
374  Vec_PtrFree( vInters );
375  Aig_ObjCreateCo( p, pInter );
376  Aig_ManCleanup( p );
377  assert( Aig_ManCheck(p) );
378  return p;
379 }
380 
381 
382 /**Function*************************************************************
383 
384  Synopsis [Performs one SAT run with interpolation.]
385 
386  Description [Returns 1 if proven. 0 if failed. -1 if undecided.]
387 
388  SideEffects []
389 
390  SeeAlso []
391 
392 ***********************************************************************/
393 int Inter_ManPerformOneStepM114p( Inter_Man_t * p, int fUsePudlak, int fUseOther )
394 {
396  Vec_Int_t * vMapRoots, * vMapVars;
397  clock_t clk;
398  int status, RetValue;
399  assert( p->pInterNew == NULL );
400  // derive the SAT solver
401  pSat = Inter_ManDeriveSatSolverM114p( p->pInter, p->pCnfInter,
402  p->pAigTrans, p->pCnfAig, p->pFrames, p->pCnfFrames,
403  &vMapRoots, &vMapVars );
404  // solve the problem
405 clk = clock();
406  status = M114p_SolverSolve( pSat, NULL, NULL, 0 );
407  p->nConfCur = M114p_SolverGetConflictNum( pSat );
408 p->timeSat += clock() - clk;
409  if ( status == 0 )
410  {
411  RetValue = 1;
412 // Inter_ManpInterpolateM114Report( pSat, vMapRoots, vMapVars );
413 
414 clk = clock();
415  if ( fUsePudlak )
416  p->pInterNew = Inter_ManInterpolateM114pPudlak( pSat, vMapRoots, vMapVars );
417  else
418  p->pInterNew = Inter_ManpInterpolateM114( pSat, vMapRoots, vMapVars );
419 p->timeInt += clock() - clk;
420  }
421  else if ( status == 1 )
422  {
423  RetValue = 0;
424  }
425  else
426  {
427  RetValue = -1;
428  }
429  M114p_SolverDelete( pSat );
430  Vec_IntFree( vMapRoots );
431  Vec_IntFree( vMapVars );
432  return RetValue;
433 }
434 
435 ////////////////////////////////////////////////////////////////////////
436 /// END OF FILE ///
437 ////////////////////////////////////////////////////////////////////////
438 
440 
441 #endif
442 
443 
Aig_Obj_t * Aig_ObjCreateCo(Aig_Man_t *p, Aig_Obj_t *pDriver)
Definition: aigObj.c:66
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
ABC_DLL int Aig_ManCheck(Aig_Man_t *p)
FUNCTION DECLARATIONS ///.
Definition: aigCheck.c:45
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Llb_Mgr_t * p
Definition: llb3Image.c:950
ABC_NAMESPACE_HEADER_START typedef int M114p_Solver_t
Definition: m114p_types.h:9
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
int nClauses
Definition: cnf.h:61
#define M114p_SolverForEachRoot(s, ppLits, nLits, i)
Definition: m114p.h:34
static int lit_var(lit l)
Definition: satVec.h:145
static Aig_Obj_t * Saig_ManLo(Aig_Man_t *p, int i)
Definition: saig.h:79
int nVars
Definition: cnf.h:59
Aig_Man_t * Aig_ManStart(int nNodesMax)
DECLARATIONS ///.
Definition: aigMan.c:47
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
int * pVarNums
Definition: cnf.h:63
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static Aig_Obj_t * Aig_ManConst0(Aig_Man_t *p)
Definition: aig.h:263
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Definition: cnf.h:56
typedefABC_NAMESPACE_HEADER_START struct Inter_Man_t_ Inter_Man_t
INCLUDES ///.
Definition: intInt.h:49
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition: aigOper.c:104
void M114p_SolverSetVarNum(M114p_Solver_t s, int nVars)
void M114p_SolverDelete(M114p_Solver_t s)
static lit lit_neg(lit l)
Definition: satVec.h:144
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
int M114p_SolverAddClause(M114p_Solver_t s, lit *begin, lit *end)
int ** pClauses
Definition: cnf.h:62
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Aig_Obj_t * Aig_IthVar(Aig_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Definition: aigOper.c:63
static lit toLitCond(int v, int c)
Definition: satVec.h:143
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static int Aig_ManCiNum(Aig_Man_t *p)
Definition: aig.h:251
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Definition: bblif.c:356
if(last==0)
Definition: sparse_int.h:34
Aig_Obj_t * Aig_Or(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition: aigOper.c:259
static Aig_Obj_t * Saig_ManLi(Aig_Man_t *p, int i)
Definition: saig.h:80
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
Aig_Man_t * pFrames
Definition: intCheck.c:35
void Cnf_DataLift(Cnf_Dat_t *p, int nVarsPlus)
Definition: cnfMan.c:205
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static int Aig_ManRegNum(Aig_Man_t *p)
Definition: aig.h:260
int M114p_SolverGetConflictNum(M114p_Solver_t s)
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
Aig_Obj_t * Aig_Mux(Aig_Man_t *p, Aig_Obj_t *pC, Aig_Obj_t *p1, Aig_Obj_t *p0)
Definition: aigOper.c:317
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
static int lit_sign(lit l)
Definition: satVec.h:146
#define M114p_SolverForEachChain(s, ppClauses, ppVars, nVars, i)
Definition: m114p.h:39
ABC_NAMESPACE_HEADER_START M114p_Solver_t M114p_SolverNew(int fRecordProof)
int M114p_SolverSolve(M114p_Solver_t s, lit *begin, lit *end, int nConfLimit)
#define assert(ex)
Definition: util_old.h:213
static Aig_Obj_t * Aig_NotCond(Aig_Obj_t *p, int c)
Definition: aig.h:248
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
int M114p_SolverProofIsReady(M114p_Solver_t s)
int Id
Definition: aig.h:85
int Aig_ManCleanup(Aig_Man_t *p)
Definition: aigMan.c:265
sat_solver * pSat
Definition: intCheck.c:37
int M114p_SolverProofClauseNum(M114p_Solver_t s)
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223