abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bmcLoad.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [bmcLoad.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [SAT-based bounded model checking.]
8 
9  Synopsis [Experiments with CNF loading.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: bmcLoad.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "bmc.h"
22 #include "sat/bsat/satStore.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 typedef struct Bmc_Load_t_ Bmc_Load_t;
33 {
34  Bmc_AndPar_t * pPars; // parameters
35  Gia_Man_t * pGia; // unrolled AIG
36  sat_solver * pSat; // SAT solvers
37  Vec_Int_t * vSat2Id; // maps SAT var into its node
38 // Vec_Int_t * vCut; // cut in terms of GIA IDs
39 // Vec_Int_t * vCnf; // CNF for the cut
42 };
43 
44 ////////////////////////////////////////////////////////////////////////
45 /// FUNCTION DEFINITIONS ///
46 ////////////////////////////////////////////////////////////////////////
47 
48 
49 /**Function*************************************************************
50 
51  Synopsis [Load CNF for the cone.]
52 
53  Description []
54 
55  SideEffects []
56 
57  SeeAlso []
58 
59 ***********************************************************************/
60 int Bmc_LoadGetSatVar( Bmc_Load_t * p, int Id )
61 {
62  Gia_Obj_t * pObj = Gia_ManObj( p->pGia, Id );
63  if ( pObj->Value == 0 )
64  {
65  pObj->Value = Vec_IntSize( p->vSat2Id );
66  Vec_IntPush( p->vSat2Id, Id );
67  sat_solver_setnvars( p->pSat, Vec_IntSize(p->vSat2Id) );
68  }
69  return pObj->Value;
70 }
71 int Bmc_LoadAddCnf( void * pMan, int iLit )
72 {
73  Bmc_Load_t * p = (Bmc_Load_t *)pMan;
74  int Lits[3], iVar = Abc_Lit2Var(iLit);
75  Gia_Obj_t * pObj = Gia_ManObj( p->pGia, Vec_IntEntry(p->vSat2Id, iVar) );
76  p->nCallBacks1++;
77  if ( Gia_ObjIsCi(pObj) || Gia_ObjIsConst0(pObj) )
78  return 0;
79  assert( Gia_ObjIsAnd(pObj) );
80  if ( (Abc_LitIsCompl(iLit) ? pObj->fMark1 : pObj->fMark0) )
81  return 0;
82  Lits[0] = Abc_LitNot(iLit);
83  if ( Abc_LitIsCompl(iLit) )
84  {
85  Lits[1] = Abc_Var2Lit( Bmc_LoadGetSatVar(p, Gia_ObjFaninId0p(p->pGia, pObj)), !Gia_ObjFaninC0(pObj) );
86  Lits[2] = Abc_Var2Lit( Bmc_LoadGetSatVar(p, Gia_ObjFaninId1p(p->pGia, pObj)), !Gia_ObjFaninC1(pObj) );
87  sat_solver_clause_new( p->pSat, Lits, Lits + 3, 0 );
88  pObj->fMark1 = 1;
89  }
90  else
91  {
92  Lits[1] = Abc_Var2Lit( Bmc_LoadGetSatVar(p, Gia_ObjFaninId0p(p->pGia, pObj)), Gia_ObjFaninC0(pObj) );
93  sat_solver_clause_new( p->pSat, Lits, Lits + 2, 0 );
94  Lits[1] = Abc_Var2Lit( Bmc_LoadGetSatVar(p, Gia_ObjFaninId1p(p->pGia, pObj)), Gia_ObjFaninC1(pObj) );
95  sat_solver_clause_new( p->pSat, Lits, Lits + 2, 0 );
96  pObj->fMark0 = 1;
97  }
98  p->nCallBacks2++;
99  return 1;
100 }
102 {
103  int iVar = Bmc_LoadGetSatVar( p, Id );
104  Gia_Obj_t * pObj = Gia_ManObj( p->pGia, Id );
105  if ( Gia_ObjIsAnd(pObj) && !(pObj->fMark0 && pObj->fMark1) )
106  {
107  Bmc_LoadAddCnf( p, Abc_Var2Lit(iVar, 0) );
108  Bmc_LoadAddCnf( p, Abc_Var2Lit(iVar, 1) );
109  Bmc_LoadAddCnf_rec( p, Gia_ObjFaninId0(pObj, Id) );
110  Bmc_LoadAddCnf_rec( p, Gia_ObjFaninId1(pObj, Id) );
111  }
112  return iVar;
113 }
114 
115 /**Function*************************************************************
116 
117  Synopsis []
118 
119  Description []
120 
121  SideEffects []
122 
123  SeeAlso []
124 
125 ***********************************************************************/
127 {
128  Bmc_Load_t * p;
129  int Lit;
130  Gia_ManSetPhase( pGia );
131  Gia_ManCleanValue( pGia );
132  Gia_ManCreateRefs( pGia );
133  p = ABC_CALLOC( Bmc_Load_t, 1 );
134  p->pGia = pGia;
135  p->pSat = sat_solver_new();
136  p->vSat2Id = Vec_IntAlloc( 1000 );
137  Vec_IntPush( p->vSat2Id, 0 );
138  // create constant node
139  Lit = Abc_Var2Lit( Bmc_LoadGetSatVar(p, 0), 1 );
140  sat_solver_addclause( p->pSat, &Lit, &Lit + 1 );
141  return p;
142 }
144 {
145  Vec_IntFree( p->vSat2Id );
146  sat_solver_delete( p->pSat );
147  ABC_FREE( p );
148 }
149 
150 /**Function*************************************************************
151 
152  Synopsis []
153 
154  Description []
155 
156  SideEffects []
157 
158  SeeAlso []
159 
160 ***********************************************************************/
161 void Bmc_LoadTest( Gia_Man_t * pGia, int fLoadCnf, int fVerbose )
162 {
163  int nConfLimit = 0;
164  Bmc_Load_t * p;
165  Gia_Obj_t * pObj;
166  int i, status, Lit;
167  abctime clk = Abc_Clock();
168  // create the loading manager
169  p = Bmc_LoadStart( pGia );
170  // add callback for CNF loading
171  if ( fLoadCnf )
172  {
173  p->pSat->pCnfMan = p;
174  p->pSat->pCnfFunc = Bmc_LoadAddCnf;
175  }
176  // solve SAT problem for each PO
177  Gia_ManForEachPo( pGia, pObj, i )
178  {
179  if ( fLoadCnf )
180  Lit = Abc_Var2Lit( Bmc_LoadGetSatVar(p, Gia_ObjFaninId0p(pGia, pObj)), Gia_ObjFaninC0(pObj) );
181  else
182  Lit = Abc_Var2Lit( Bmc_LoadAddCnf_rec(p, Gia_ObjFaninId0p(pGia, pObj)), Gia_ObjFaninC0(pObj) );
183  if ( fVerbose )
184  {
185  printf( "Frame%4d : ", i );
186  printf( "Vars = %6d ", Vec_IntSize(p->vSat2Id) );
187  printf( "Clas = %6d ", sat_solver_nclauses(p->pSat) );
188  }
189  status = sat_solver_solve( p->pSat, &Lit, &Lit + 1, (ABC_INT64_T)nConfLimit, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
190  if ( fVerbose )
191  {
192  printf( "Conf = %6d ", sat_solver_nconflicts(p->pSat) );
193  if ( status == l_False )
194  printf( "UNSAT " );
195  else if ( status == l_True )
196  printf( "SAT " );
197  else // if ( status == l_Undec )
198  printf( "UNDEC " );
199  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
200  }
201  }
202  printf( "Callbacks = %d. Loadings = %d.\n", p->nCallBacks1, p->nCallBacks2 );
203  Bmc_LoadStop( p );
204 }
205 
206 ////////////////////////////////////////////////////////////////////////
207 /// END OF FILE ///
208 ////////////////////////////////////////////////////////////////////////
209 
210 
212 
void Gia_ManCreateRefs(Gia_Man_t *p)
Definition: giaUtil.c:715
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
void Bmc_LoadStop(Bmc_Load_t *p)
Definition: bmcLoad.c:143
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
int sat_solver_clause_new(sat_solver *s, lit *begin, lit *end, int learnt)
Definition: satSolver.c:402
int sat_solver_solve(sat_solver *s, lit *begin, lit *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
Definition: satSolver.c:1700
typedefABC_NAMESPACE_IMPL_START struct Bmc_Load_t_ Bmc_Load_t
DECLARATIONS ///.
Definition: bmcLoad.c:31
Bmc_Load_t * Bmc_LoadStart(Gia_Man_t *pGia)
Definition: bmcLoad.c:126
void sat_solver_delete(sat_solver *s)
Definition: satSolver.c:1141
void Gia_ManCleanValue(Gia_Man_t *p)
Definition: giaUtil.c:310
static int Gia_ObjIsConst0(Gia_Obj_t *pObj)
Definition: gia.h:430
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
int nCallBacks2
Definition: bmcLoad.c:41
int sat_solver_nconflicts(sat_solver *s)
Definition: satSolver.c:1908
static int Gia_ObjFaninId1p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:464
#define l_True
Definition: SolverTypes.h:84
sat_solver * pSat
Definition: bmcLoad.c:36
int Bmc_LoadGetSatVar(Bmc_Load_t *p, int Id)
FUNCTION DEFINITIONS ///.
Definition: bmcLoad.c:60
Bmc_AndPar_t * pPars
Definition: bmcLoad.c:34
unsigned fMark1
Definition: gia.h:84
static abctime Abc_Clock()
Definition: abc_global.h:279
static Gia_Obj_t * Gia_ManObj(Gia_Man_t *p, int v)
Definition: gia.h:402
Definition: gia.h:75
int nCallBacks1
Definition: bmcLoad.c:40
int Bmc_LoadAddCnf(void *pMan, int iLit)
Definition: bmcLoad.c:71
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
void Bmc_LoadTest(Gia_Man_t *pGia, int fLoadCnf, int fVerbose)
Definition: bmcLoad.c:161
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
void sat_solver_setnvars(sat_solver *s, int n)
Definition: satSolver.c:1072
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
int sat_solver_nclauses(sat_solver *s)
Definition: satSolver.c:1902
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Abc_LitNot(int Lit)
Definition: abc_global.h:266
sat_solver * sat_solver_new(void)
Definition: satSolver.c:1001
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
unsigned fMark0
Definition: gia.h:79
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: gia.h:95
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
#define l_False
Definition: SolverTypes.h:85
static int Gia_ObjFaninId0p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:463
Vec_Int_t * vSat2Id
Definition: bmcLoad.c:37
int Bmc_LoadAddCnf_rec(Bmc_Load_t *p, int Id)
Definition: bmcLoad.c:101
#define assert(ex)
Definition: util_old.h:213
void Gia_ManSetPhase(Gia_Man_t *p)
Definition: giaUtil.c:379
unsigned Value
Definition: gia.h:87
Gia_Man_t * pGia
Definition: bmcLoad.c:35
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
ABC_INT64_T abctime
Definition: abc_global.h:278
static int Gia_ObjIsCi(Gia_Obj_t *pObj)
Definition: gia.h:420
#define Gia_ManForEachPo(p, pObj, i)
Definition: gia.h:1036
static int Gia_ObjFaninId1(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:461
static int Gia_ObjFaninId0(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:460