abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaCTas2.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [giaCSat2.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Scalable AIG package.]
8 
9  Synopsis [Circuit-based SAT solver.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: giaCSat2.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "gia.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 typedef struct Tas_Par_t_ Tas_Par_t;
31 struct Tas_Par_t_
32 {
33  // conflict limits
34  int nBTLimit; // limit on the number of conflicts
35  // current parameters
36  int nBTThis; // number of conflicts
37  int nBTTotal; // total number of conflicts
38  // decision heuristics
39  int fUseHighest; // use node with the highest ID
40  // other parameters
41  int fVerbose;
42 };
43 
44 typedef struct Tas_Sto_t_ Tas_Sto_t;
45 struct Tas_Sto_t_
46 {
47  int iCur; // currently used
48  int nSize; // allocated size
49  char * pBuffer; // handles of objects stored in the queue
50 };
51 
52 typedef struct Tas_Que_t_ Tas_Que_t;
53 struct Tas_Que_t_
54 {
55  int iHead; // beginning of the queue
56  int iTail; // end of the queue
57  int nSize; // allocated size
58  int * pData; // handles of objects stored in the queue
59 };
60 
61 typedef struct Tas_Var_t_ Tas_Var_t;
62 struct Tas_Var_t_
63 {
64  unsigned fTerm : 1; // terminal node
65  unsigned fVal : 1; // current value
66  unsigned fValOld : 1; // previous value
67  unsigned fAssign : 1; // assigned status
68  unsigned fJQueue : 1; // part of J-frontier
69  unsigned fCompl0 : 1; // complemented attribute
70  unsigned fCompl1 : 1; // complemented attribute
71  unsigned fMark0 : 1; // multi-purpose mark
72  unsigned fMark1 : 1; // multi-purpose mark
73  unsigned fPhase : 1; // polarity
74  unsigned Level : 22; // decision level
75  int Id; // unique ID of this variable
76  int IdAig; // original ID of this variable
77  int Reason0; // reason of this variable
78  int Reason1; // reason of this variable
79  int Diff0; // difference for the first fanin
80  int Diff1; // difference for the second fanin
81  int Watch0; // handle of first watch
82  int Watch1; // handle of second watch
83 };
84 
85 typedef struct Tas_Cls_t_ Tas_Cls_t;
86 struct Tas_Cls_t_
87 {
88  int Watch0; // next clause to watch
89  int Watch1; // next clause to watch
90  int pVars[0]; // variable handles
91 };
92 
93 typedef struct Tas_Man_t_ Tas_Man_t;
94 struct Tas_Man_t_
95 {
96  // user data
97  Gia_Man_t * pAig; // AIG manager
98  Tas_Par_t Pars; // parameters
99  // solver data
100  Tas_Sto_t * pVars; // variables
101  Tas_Sto_t * pClauses; // clauses
102  // state representation
103  Tas_Que_t pProp; // propagation queue
104  Tas_Que_t pJust; // justification queue
105  Vec_Int_t * vModel; // satisfying assignment
106  Vec_Ptr_t * vTemp; // temporary storage
107  // SAT calls statistics
108  int nSatUnsat; // the number of proofs
109  int nSatSat; // the number of failure
110  int nSatUndec; // the number of timeouts
111  int nSatTotal; // the number of calls
112  // conflicts
113  int nConfUnsat; // conflicts in unsat problems
114  int nConfSat; // conflicts in sat problems
115  int nConfUndec; // conflicts in undec problems
116  int nConfTotal; // total conflicts
117  // runtime stats
118  clock_t timeSatUnsat; // unsat
119  clock_t timeSatSat; // sat
120  clock_t timeSatUndec; // undecided
121  clock_t timeTotal; // total runtime
122 };
123 
124 static inline int Tas_VarIsAssigned( Tas_Var_t * pVar ) { return pVar->fAssign; }
125 static inline void Tas_VarAssign( Tas_Var_t * pVar ) { assert(!pVar->fAssign); pVar->fAssign = 1; }
126 static inline void Tas_VarUnassign( Tas_Var_t * pVar ) { assert(pVar->fAssign); pVar->fAssign = 0; pVar->fVal = 0; }
127 static inline int Tas_VarValue( Tas_Var_t * pVar ) { assert(pVar->fAssign); return pVar->fVal; }
128 static inline void Tas_VarSetValue( Tas_Var_t * pVar, int v ) { assert(pVar->fAssign); pVar->fVal = v; }
129 static inline int Tas_VarIsJust( Tas_Var_t * pVar ) { return Gia_ObjIsAnd(pVar) && !Tas_VarIsAssigned(Gia_ObjFanin0(pVar)) && !Tas_VarIsAssigned(Gia_ObjFanin1(pVar)); }
130 static inline int Tas_VarFanin0Value( Tas_Var_t * pVar ) { return !Tas_VarIsAssigned(Gia_ObjFanin0(pVar)) ? 2 : (Tas_VarValue(Gia_ObjFanin0(pVar)) ^ Gia_ObjFaninC0(pVar)); }
131 static inline int Tas_VarFanin1Value( Tas_Var_t * pVar ) { return !Tas_VarIsAssigned(Gia_ObjFanin1(pVar)) ? 2 : (Tas_VarValue(Gia_ObjFanin1(pVar)) ^ Gia_ObjFaninC1(pVar)); }
132 
133 static inline int Tas_VarDecLevel( Tas_Man_t * p, Tas_Var_t * pVar ) { assert( pVar->Value != ~0 ); return Vec_IntEntry(p->vLevReas, 3*pVar->Value); }
134 static inline Tas_Var_t * Tas_VarReason0( Tas_Man_t * p, Tas_Var_t * pVar ) { assert( pVar->Value != ~0 ); return pVar + Vec_IntEntry(p->vLevReas, 3*pVar->Value+1); }
135 static inline Tas_Var_t * Tas_VarReason1( Tas_Man_t * p, Tas_Var_t * pVar ) { assert( pVar->Value != ~0 ); return pVar + Vec_IntEntry(p->vLevReas, 3*pVar->Value+2); }
136 static inline int Tas_ClauseDecLevel( Tas_Man_t * p, int hClause ) { return Tas_VarDecLevel( p, p->pClauses.pData[hClause] ); }
137 
138 static inline Tas_Var_t * Tas_ManVar( Tas_Man_t * p, int h ) { return (Tas_Var_t *)(p->pVars->pBuffer + h); }
139 static inline Tas_Cls_t * Tas_ManClause( Tas_Man_t * p, int h ) { return (Tas_Cls_t *)(p->pClauses->pBuffer + h); }
140 
141 #define Tas_ClaForEachVar( p, pClause, pVar, i ) \
142  for ( pVar = Tas_ManVar(p, pClause->pVars[(i=0)]); pClause->pVars[i]; pVar = (Tas_Var_t *)(((char *)pVar + pClause->pVars[++i])) )
143 
144 #define Tas_QueForEachVar( p, pQue, pVar, i ) \
145  for ( pVar = Tas_ManVar(p, pQue->pVars[(i=pQue->iHead)]); i < pQue->iTail; pVar = Tas_ManVar(p, pQue->pVars[i++]) )
146 
147 
148 ////////////////////////////////////////////////////////////////////////
149 /// FUNCTION DEFINITIONS ///
150 ////////////////////////////////////////////////////////////////////////
151 
152 /**Function*************************************************************
153 
154  Synopsis []
155 
156  Description []
157 
158  SideEffects []
159 
160  SeeAlso []
161 
162 ***********************************************************************/
164 {
165  Tas_Var_t * pVar;
166  if ( p->pVars->iCur + sizeof(Tas_Var_t) > p->pVars->nSize )
167  {
168  p->pVars->nSize *= 2;
169  p->pVars->pData = ABC_REALLOC( char, p->pVars->pData, p->pVars->nSize );
170  }
171  pVar = p->pVars->pData + p->pVars->iCur;
172  p->pVars->iCur += sizeof(Tas_Var_t);
173  memset( pVar, 0, sizeof(Tas_Var_t) );
174  pVar->Id = pVar - ((Tas_Var_t *)p->pVars->pData);
175  return pVar;
176 }
177 
178 /**Function*************************************************************
179 
180  Synopsis []
181 
182  Description []
183 
184  SideEffects []
185 
186  SeeAlso []
187 
188 ***********************************************************************/
190 {
191  Tas_Var_t * pVar;
192  assert( !Gia_ObjIsComplement(pObj) );
193  if ( pObj->Value == 0 )
194  {
195  pVar = Tas_ManCreateVar( p );
196  pVar->
197 
198  }
199  return Tas_ManVar( p, pObj->Value );
200 }
201 
202 ////////////////////////////////////////////////////////////////////////
203 /// END OF FILE ///
204 ////////////////////////////////////////////////////////////////////////
205 
206 
208 
static int Tas_VarIsAssigned(Tas_Var_t *pVar)
Definition: giaCTas2.c:124
char * memset()
unsigned fMark1
Definition: giaCTas2.c:72
unsigned fAssign
Definition: giaCTas2.c:67
int nSize
Definition: giaCTas.c:69
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Tas_Cls_t * Tas_ManClause(Tas_Man_t *p, int h)
Definition: giaCTas2.c:139
int Reason0
Definition: giaCTas2.c:77
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
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
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
struct Tas_Var_t_ Tas_Var_t
Definition: giaCTas2.c:61
static Tas_Var_t * Tas_VarReason1(Tas_Man_t *p, Tas_Var_t *pVar)
Definition: giaCTas2.c:135
Gia_Man_t * pAig
Definition: giaCTas.c:85
int Diff0
Definition: giaCTas2.c:79
Tas_Que_t pProp
Definition: giaCTas.c:86
int * pData
Definition: giaCTas2.c:58
int iHead
Definition: giaCTas.c:76
int Reason1
Definition: giaCTas2.c:78
static void Tas_VarUnassign(Tas_Var_t *pVar)
Definition: giaCTas2.c:126
int nBTThis
Definition: giaCTas.c:40
int nSatTotal
Definition: giaCTas.c:105
clock_t timeTotal
Definition: giaCTas2.c:121
int pVars[0]
Definition: giaCTas2.c:90
Definition: gia.h:75
int fUseHighest
Definition: giaCTas.c:50
unsigned fPhase
Definition: giaCTas2.c:73
int fVerbose
Definition: giaCTas.c:54
unsigned fCompl1
Definition: giaCTas2.c:70
int nBTTotal
Definition: giaCTas.c:43
static Tas_Var_t * Tas_ManVar(Tas_Man_t *p, int h)
Definition: giaCTas2.c:138
unsigned Level
Definition: giaCTas2.c:74
int nConfUnsat
Definition: giaCTas.c:107
Gia_Obj_t ** pData
Definition: giaCTas.c:79
int nConfSat
Definition: giaCTas.c:108
int Diff1
Definition: giaCTas2.c:80
int iCur
Definition: giaCTas.c:68
int IdAig
Definition: giaCTas2.c:76
int Watch1
Definition: giaCTas2.c:82
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
int nSatUnsat
Definition: giaCTas.c:102
Tas_Sto_t * pClauses
Definition: giaCTas2.c:101
static void Tas_VarAssign(Tas_Var_t *pVar)
Definition: giaCTas2.c:125
int * pData
Definition: giaCTas.c:70
int nSize
Definition: giaCTas.c:78
int nConfTotal
Definition: giaCTas2.c:116
Vec_Int_t * vLevReas
Definition: giaCTas.c:90
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 int Tas_ClauseDecLevel(Tas_Man_t *p, int hClause)
Definition: giaCTas2.c:136
static int Tas_VarDecLevel(Tas_Man_t *p, Tas_Var_t *pVar)
Definition: giaCTas2.c:133
static int Tas_VarFanin0Value(Tas_Var_t *pVar)
Definition: giaCTas2.c:130
int nSatSat
Definition: giaCTas.c:103
int Watch0
Definition: giaCTas2.c:81
unsigned fMark0
Definition: giaCTas2.c:71
int Watch0
Definition: giaCTas2.c:88
int Watch1
Definition: giaCTas2.c:89
unsigned fVal
Definition: giaCTas2.c:65
static int Tas_VarFanin1Value(Tas_Var_t *pVar)
Definition: giaCTas2.c:131
typedefABC_NAMESPACE_IMPL_START struct Tas_Par_t_ Tas_Par_t
DECLARATIONS ///.
Definition: giaCTas.c:33
unsigned fCompl0
Definition: giaCTas2.c:69
static int Tas_VarIsJust(Tas_Var_t *pVar)
Definition: giaCTas2.c:129
Tas_Sto_t * pVars
Definition: giaCTas2.c:100
int nBTLimit
Definition: giaCTas.c:37
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static Tas_Var_t * Tas_VarReason0(Tas_Man_t *p, Tas_Var_t *pVar)
Definition: giaCTas2.c:134
char * pBuffer
Definition: giaCTas2.c:49
unsigned fValOld
Definition: giaCTas2.c:66
int Id
Definition: giaCTas2.c:75
Tas_Var_t * Tas_ManObj2Var(Tas_Man_t *p, Gia_Obj_t *pObj)
Definition: giaCTas2.c:189
Definition: gia.h:95
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
Tas_Que_t pClauses
Definition: giaCTas.c:88
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
Tas_Que_t pJust
Definition: giaCTas.c:87
unsigned fTerm
Definition: giaCTas2.c:64
int nConfUndec
Definition: giaCTas.c:109
int iTail
Definition: giaCTas.c:77
#define assert(ex)
Definition: util_old.h:213
unsigned Value
Definition: gia.h:87
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
clock_t timeSatSat
Definition: giaCTas2.c:119
Vec_Ptr_t * vTemp
Definition: giaCTas.c:92
static void Tas_VarSetValue(Tas_Var_t *pVar, int v)
Definition: giaCTas2.c:128
Vec_Int_t * vModel
Definition: giaCTas.c:91
unsigned fJQueue
Definition: giaCTas2.c:68
clock_t timeSatUndec
Definition: giaCTas2.c:120
int nSatUndec
Definition: giaCTas.c:104
Tas_Var_t * Tas_ManCreateVar(Tas_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: giaCTas2.c:163
static int Tas_VarValue(Tas_Var_t *pVar)
Definition: giaCTas2.c:127
Tas_Par_t Pars
Definition: giaCTas.c:84
clock_t timeSatUnsat
Definition: giaCTas2.c:118