abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fraigApi.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [fraigApi.c]
4 
5  PackageName [FRAIG: Functionally reduced AND-INV graphs.]
6 
7  Synopsis [Access APIs for the FRAIG manager and node.]
8 
9  Author [Alan Mishchenko <alanmi@eecs.berkeley.edu>]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 2.0. Started - October 1, 2004]
14 
15  Revision [$Id: fraigApi.c,v 1.2 2005/07/08 01:01:30 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "fraigInt.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// FUNCTION DEFINITIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 /**Function*************************************************************
33 
34  Synopsis [Access functions to read the data members of the manager.]
35 
36  Description []
37 
38  SideEffects []
39 
40  SeeAlso []
41 
42 ***********************************************************************/
43 Fraig_NodeVec_t * Fraig_ManReadVecInputs( Fraig_Man_t * p ) { return p->vInputs; }
44 Fraig_NodeVec_t * Fraig_ManReadVecOutputs( Fraig_Man_t * p ) { return p->vOutputs; }
45 Fraig_NodeVec_t * Fraig_ManReadVecNodes( Fraig_Man_t * p ) { return p->vNodes; }
46 Fraig_Node_t ** Fraig_ManReadInputs ( Fraig_Man_t * p ) { return p->vInputs->pArray; }
47 Fraig_Node_t ** Fraig_ManReadOutputs( Fraig_Man_t * p ) { return p->vOutputs->pArray; }
48 Fraig_Node_t ** Fraig_ManReadNodes( Fraig_Man_t * p ) { return p->vNodes->pArray; }
49 int Fraig_ManReadInputNum ( Fraig_Man_t * p ) { return p->vInputs->nSize; }
50 int Fraig_ManReadOutputNum( Fraig_Man_t * p ) { return p->vOutputs->nSize; }
51 int Fraig_ManReadNodeNum( Fraig_Man_t * p ) { return p->vNodes->nSize; }
52 Fraig_Node_t * Fraig_ManReadConst1 ( Fraig_Man_t * p ) { return p->pConst1; }
53 Fraig_Node_t * Fraig_ManReadIthNode( Fraig_Man_t * p, int i ) { assert ( i < p->vNodes->nSize ); return p->vNodes->pArray[i]; }
54 char ** Fraig_ManReadInputNames( Fraig_Man_t * p ) { return p->ppInputNames; }
55 char ** Fraig_ManReadOutputNames( Fraig_Man_t * p ) { return p->ppOutputNames; }
56 char * Fraig_ManReadVarsInt( Fraig_Man_t * p ) { return (char *)p->vVarsInt; }
57 char * Fraig_ManReadSat( Fraig_Man_t * p ) { return (char *)p->pSat; }
58 int Fraig_ManReadFuncRed( Fraig_Man_t * p ) { return p->fFuncRed; }
59 int Fraig_ManReadFeedBack( Fraig_Man_t * p ) { return p->fFeedBack; }
60 int Fraig_ManReadDoSparse( Fraig_Man_t * p ) { return p->fDoSparse; }
61 int Fraig_ManReadChoicing( Fraig_Man_t * p ) { return p->fChoicing; }
62 int Fraig_ManReadVerbose( Fraig_Man_t * p ) { return p->fVerbose; }
63 int * Fraig_ManReadModel( Fraig_Man_t * p ) { return p->pModel; }
64 // returns the number of patterns used for random simulation (this number is fixed for the FRAIG run)
65 int Fraig_ManReadPatternNumRandom( Fraig_Man_t * p ) { return p->nWordsRand * 32; }
66 // returns the number of dynamic patterns accumulated at runtime (include SAT solver counter-examples and distance-1 patterns derived from them)
67 int Fraig_ManReadPatternNumDynamic( Fraig_Man_t * p ) { return p->iWordStart * 32; }
68 // returns the number of dynamic patterns proved useful to distinquish some FRAIG nodes (this number is more than 0 after the first garbage collection of patterns)
69 int Fraig_ManReadPatternNumDynamicFiltered( Fraig_Man_t * p ) { return p->iPatsPerm; }
70 // returns the number of times FRAIG package timed out
71 int Fraig_ManReadSatFails( Fraig_Man_t * p ) { return p->nSatFailsReal; }
72 // returns the number of conflicts in the SAT solver
73 int Fraig_ManReadConflicts( Fraig_Man_t * p ) { return p->pSat? Msat_SolverReadBackTracks(p->pSat) : 0; }
74 // returns the number of inspections in the SAT solver
75 int Fraig_ManReadInspects( Fraig_Man_t * p ) { return p->pSat? Msat_SolverReadInspects(p->pSat) : 0; }
76 
77 /**Function*************************************************************
78 
79  Synopsis [Access functions to set the data members of the manager.]
80 
81  Description []
82 
83  SideEffects []
84 
85  SeeAlso []
86 
87 ***********************************************************************/
88 void Fraig_ManSetFuncRed( Fraig_Man_t * p, int fFuncRed ) { p->fFuncRed = fFuncRed; }
89 void Fraig_ManSetFeedBack( Fraig_Man_t * p, int fFeedBack ) { p->fFeedBack = fFeedBack; }
90 void Fraig_ManSetDoSparse( Fraig_Man_t * p, int fDoSparse ) { p->fDoSparse = fDoSparse; }
91 void Fraig_ManSetChoicing( Fraig_Man_t * p, int fChoicing ) { p->fChoicing = fChoicing; }
92 void Fraig_ManSetTryProve( Fraig_Man_t * p, int fTryProve ) { p->fTryProve = fTryProve; }
93 void Fraig_ManSetVerbose( Fraig_Man_t * p, int fVerbose ) { p->fVerbose = fVerbose; }
94 void Fraig_ManSetOutputNames( Fraig_Man_t * p, char ** ppNames ) { p->ppOutputNames = ppNames; }
95 void Fraig_ManSetInputNames( Fraig_Man_t * p, char ** ppNames ) { p->ppInputNames = ppNames; }
96 
97 /**Function*************************************************************
98 
99  Synopsis [Access functions to read the data members of the node.]
100 
101  Description []
102 
103  SideEffects []
104 
105  SeeAlso []
106 
107 ***********************************************************************/
110 int Fraig_NodeReadNum( Fraig_Node_t * p ) { return p->Num; }
115 int Fraig_NodeReadNumRefs( Fraig_Node_t * p ) { return p->nRefs; }
117 int Fraig_NodeReadSimInv( Fraig_Node_t * p ) { return p->fInv; }
118 int Fraig_NodeReadNumOnes( Fraig_Node_t * p ) { return p->nOnes; }
119 // returns the pointer to the random simulation patterns (their number is returned by Fraig_ManReadPatternNumRandom)
120 // memory pointed to by this and the following procedure is maintained by the FRAIG package and exists as long as the package runs
121 unsigned * Fraig_NodeReadPatternsRandom( Fraig_Node_t * p ) { return p->puSimR; }
122 // returns the pointer to the dynamic simulation patterns (their number is returned by Fraig_ManReadPatternNumDynamic or Fraig_ManReadPatternNumDynamicFiltered)
123 // if the number of patterns is not evenly divisible by 32, the patterns beyond the given number contain garbage
124 unsigned * Fraig_NodeReadPatternsDynamic( Fraig_Node_t * p ) { return p->puSimD; }
125 
126 /**Function*************************************************************
127 
128  Synopsis [Access functions to set the data members of the node.]
129 
130  Description []
131 
132  SideEffects []
133 
134  SeeAlso []
135 
136 ***********************************************************************/
137 void Fraig_NodeSetData0( Fraig_Node_t * p, Fraig_Node_t * pData ) { p->pData0 = pData; }
138 void Fraig_NodeSetData1( Fraig_Node_t * p, Fraig_Node_t * pData ) { p->pData1 = pData; }
139 
140 /**Function*************************************************************
141 
142  Synopsis [Checks the type of the node.]
143 
144  Description []
145 
146  SideEffects []
147 
148  SeeAlso []
149 
150 ***********************************************************************/
151 int Fraig_NodeIsConst( Fraig_Node_t * p ) { return (Fraig_Regular(p))->Num == 0; }
152 int Fraig_NodeIsVar( Fraig_Node_t * p ) { return (Fraig_Regular(p))->NumPi >= 0; }
153 int Fraig_NodeIsAnd( Fraig_Node_t * p ) { return (Fraig_Regular(p))->NumPi < 0 && (Fraig_Regular(p))->Num > 0; }
155 
156 /**Function*************************************************************
157 
158  Synopsis [Returns a new primary input node.]
159 
160  Description [If the node with this number does not exist,
161  create a new PI node with this number.]
162 
163  SideEffects []
164 
165  SeeAlso []
166 
167 ***********************************************************************/
169 {
170  int k;
171  if ( i < 0 )
172  {
173  printf( "Requesting a PI with a negative number\n" );
174  return NULL;
175  }
176  // create the PIs to fill in the interval
177  if ( i >= p->vInputs->nSize )
178  for ( k = p->vInputs->nSize; k <= i; k++ )
179  Fraig_NodeCreatePi( p );
180  return p->vInputs->pArray[i];
181 }
182 
183 /**Function*************************************************************
184 
185  Synopsis [Creates a new PO node.]
186 
187  Description [This procedure may take a complemented node.]
188 
189  SideEffects []
190 
191  SeeAlso []
192 
193 ***********************************************************************/
195 {
196  // internal node may be a PO two times
197  Fraig_Regular(pNode)->fNodePo = 1;
198  Fraig_NodeVecPush( p->vOutputs, pNode );
199 }
200 
201 /**Function*************************************************************
202 
203  Synopsis [Perfoms the AND operation with functional hashing.]
204 
205  Description []
206 
207  SideEffects []
208 
209  SeeAlso []
210 
211 ***********************************************************************/
213 {
214  return Fraig_NodeAndCanon( p, p1, p2 );
215 }
216 
217 /**Function*************************************************************
218 
219  Synopsis [Perfoms the OR operation with functional hashing.]
220 
221  Description []
222 
223  SideEffects []
224 
225  SeeAlso []
226 
227 ***********************************************************************/
229 {
230  return Fraig_Not( Fraig_NodeAndCanon( p, Fraig_Not(p1), Fraig_Not(p2) ) );
231 }
232 
233 /**Function*************************************************************
234 
235  Synopsis [Perfoms the EXOR operation with functional hashing.]
236 
237  Description []
238 
239  SideEffects []
240 
241  SeeAlso []
242 
243 ***********************************************************************/
245 {
246  return Fraig_NodeMux( p, p1, Fraig_Not(p2), p2 );
247 }
248 
249 /**Function*************************************************************
250 
251  Synopsis [Perfoms the MUX operation with functional hashing.]
252 
253  Description []
254 
255  SideEffects []
256 
257  SeeAlso []
258 
259 ***********************************************************************/
261 {
262  Fraig_Node_t * pAnd1, * pAnd2, * pRes;
263  pAnd1 = Fraig_NodeAndCanon( p, pC, pT ); Fraig_Ref( pAnd1 );
264  pAnd2 = Fraig_NodeAndCanon( p, Fraig_Not(pC), pE ); Fraig_Ref( pAnd2 );
265  pRes = Fraig_NodeOr( p, pAnd1, pAnd2 );
266  Fraig_RecursiveDeref( p, pAnd1 );
267  Fraig_RecursiveDeref( p, pAnd2 );
268  Fraig_Deref( pRes );
269  return pRes;
270 }
271 
272 
273 /**Function*************************************************************
274 
275  Synopsis [Sets the node to be equivalent to the given one.]
276 
277  Description [This procedure is a work-around for the equivalence check.
278  Does not verify the equivalence. Use at the user's risk.]
279 
280  SideEffects []
281 
282  SeeAlso []
283 
284 ***********************************************************************/
285 void Fraig_NodeSetChoice( Fraig_Man_t * pMan, Fraig_Node_t * pNodeOld, Fraig_Node_t * pNodeNew )
286 {
287 // assert( pMan->fChoicing );
288  pNodeNew->pNextE = pNodeOld->pNextE;
289  pNodeOld->pNextE = pNodeNew;
290  pNodeNew->pRepr = pNodeOld;
291 }
292 
293 ////////////////////////////////////////////////////////////////////////
294 /// END OF FILE ///
295 ////////////////////////////////////////////////////////////////////////
296 
297 
299 
int Fraig_NodeIsVar(Fraig_Node_t *p)
Definition: fraigApi.c:152
int Fraig_ManReadPatternNumDynamic(Fraig_Man_t *p)
Definition: fraigApi.c:67
void Fraig_ManSetTryProve(Fraig_Man_t *p, int fTryProve)
Definition: fraigApi.c:92
Fraig_Node_t * Fraig_ManReadConst1(Fraig_Man_t *p)
Definition: fraigApi.c:52
int Msat_SolverReadInspects(Msat_Solver_t *p)
Definition: msatSolverApi.c:59
void Fraig_NodeVecPush(Fraig_NodeVec_t *p, Fraig_Node_t *Entry)
Definition: fraigVec.c:189
int Fraig_ManReadChoicing(Fraig_Man_t *p)
Definition: fraigApi.c:61
int Fraig_ManReadOutputNum(Fraig_Man_t *p)
Definition: fraigApi.c:50
#define Fraig_RecursiveDeref(p, c)
Definition: fraig.h:115
Fraig_NodeVec_t * Fraig_ManReadVecNodes(Fraig_Man_t *p)
Definition: fraigApi.c:45
int Msat_SolverReadBackTracks(Msat_Solver_t *p)
Definition: msatSolverApi.c:58
void Fraig_ManSetChoicing(Fraig_Man_t *p, int fChoicing)
Definition: fraigApi.c:91
typedefABC_NAMESPACE_HEADER_START struct Fraig_ManStruct_t_ Fraig_Man_t
INCLUDES ///.
Definition: fraig.h:40
unsigned * Fraig_NodeReadPatternsRandom(Fraig_Node_t *p)
Definition: fraigApi.c:121
Fraig_Node_t * Fraig_ManReadIthVar(Fraig_Man_t *p, int i)
Definition: fraigApi.c:168
char * Fraig_ManReadSat(Fraig_Man_t *p)
Definition: fraigApi.c:57
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Fraig_Node_t * Fraig_NodeReadData0(Fraig_Node_t *p)
Definition: fraigApi.c:108
char ** Fraig_ManReadInputNames(Fraig_Man_t *p)
Definition: fraigApi.c:54
int Fraig_NodeComparePhase(Fraig_Node_t *p1, Fraig_Node_t *p2)
Definition: fraigApi.c:154
Fraig_Node_t ** Fraig_ManReadInputs(Fraig_Man_t *p)
Definition: fraigApi.c:46
int Fraig_NodeIsConst(Fraig_Node_t *p)
Definition: fraigApi.c:151
Fraig_Node_t * Fraig_ManReadIthNode(Fraig_Man_t *p, int i)
Definition: fraigApi.c:53
int Fraig_ManReadFeedBack(Fraig_Man_t *p)
Definition: fraigApi.c:59
int Fraig_ManReadNodeNum(Fraig_Man_t *p)
Definition: fraigApi.c:51
int Fraig_ManReadInputNum(Fraig_Man_t *p)
Definition: fraigApi.c:49
void Fraig_ManSetDoSparse(Fraig_Man_t *p, int fDoSparse)
Definition: fraigApi.c:90
unsigned * puSimD
Definition: fraigInt.h:248
Fraig_Node_t * p2
Definition: fraigInt.h:233
int Fraig_NodeReadNum(Fraig_Node_t *p)
Definition: fraigApi.c:110
#define Fraig_Ref(p)
Definition: fraig.h:113
Fraig_Node_t * Fraig_NodeReadRepr(Fraig_Node_t *p)
Definition: fraigApi.c:114
Fraig_Node_t * Fraig_NodeCreatePi(Fraig_Man_t *p)
Definition: fraigNode.c:87
#define Fraig_Deref(p)
Definition: fraig.h:114
#define Fraig_Not(p)
Definition: fraig.h:109
void Fraig_ManSetVerbose(Fraig_Man_t *p, int fVerbose)
Definition: fraigApi.c:93
int * Fraig_ManReadModel(Fraig_Man_t *p)
Definition: fraigApi.c:63
unsigned * puSimR
Definition: fraigInt.h:247
int Fraig_NodeReadNumRefs(Fraig_Node_t *p)
Definition: fraigApi.c:115
void Fraig_ManSetInputNames(Fraig_Man_t *p, char **ppNames)
Definition: fraigApi.c:95
Fraig_Node_t * pNextE
Definition: fraigInt.h:241
int Fraig_ManReadSatFails(Fraig_Man_t *p)
Definition: fraigApi.c:71
Fraig_Node_t * Fraig_NodeOr(Fraig_Man_t *p, Fraig_Node_t *p1, Fraig_Node_t *p2)
Definition: fraigApi.c:228
int Fraig_NodeReadNumFanouts(Fraig_Node_t *p)
Definition: fraigApi.c:116
void Fraig_ManSetFeedBack(Fraig_Man_t *p, int fFeedBack)
Definition: fraigApi.c:89
int Fraig_ManReadFuncRed(Fraig_Man_t *p)
Definition: fraigApi.c:58
Fraig_Node_t * pData1
Definition: fraigInt.h:252
unsigned * Fraig_NodeReadPatternsDynamic(Fraig_Node_t *p)
Definition: fraigApi.c:124
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
int Fraig_NodeReadNumOnes(Fraig_Node_t *p)
Definition: fraigApi.c:118
Fraig_Node_t * p1
Definition: fraigInt.h:232
int Fraig_ManReadInspects(Fraig_Man_t *p)
Definition: fraigApi.c:75
void Fraig_ManSetPo(Fraig_Man_t *p, Fraig_Node_t *pNode)
Definition: fraigApi.c:194
void Fraig_ManSetOutputNames(Fraig_Man_t *p, char **ppNames)
Definition: fraigApi.c:94
Fraig_Node_t * Fraig_NodeReadTwo(Fraig_Node_t *p)
Definition: fraigApi.c:112
int Fraig_ManReadDoSparse(Fraig_Man_t *p)
Definition: fraigApi.c:60
void Fraig_NodeSetData1(Fraig_Node_t *p, Fraig_Node_t *pData)
Definition: fraigApi.c:138
int Fraig_ManReadConflicts(Fraig_Man_t *p)
Definition: fraigApi.c:73
Fraig_Node_t * Fraig_NodeReadData1(Fraig_Node_t *p)
Definition: fraigApi.c:109
char ** Fraig_ManReadOutputNames(Fraig_Man_t *p)
Definition: fraigApi.c:55
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int Fraig_NodeReadSimInv(Fraig_Node_t *p)
Definition: fraigApi.c:117
Fraig_Node_t * Fraig_NodeMux(Fraig_Man_t *p, Fraig_Node_t *pC, Fraig_Node_t *pT, Fraig_Node_t *pE)
Definition: fraigApi.c:260
Fraig_Node_t * pRepr
Definition: fraigInt.h:242
char * Fraig_ManReadVarsInt(Fraig_Man_t *p)
Definition: fraigApi.c:56
#define Fraig_Regular(p)
Definition: fraig.h:108
Fraig_Node_t * Fraig_NodeAnd(Fraig_Man_t *p, Fraig_Node_t *p1, Fraig_Node_t *p2)
Definition: fraigApi.c:212
int Fraig_ManReadVerbose(Fraig_Man_t *p)
Definition: fraigApi.c:62
int Fraig_ManReadPatternNumRandom(Fraig_Man_t *p)
Definition: fraigApi.c:65
Fraig_Node_t ** Fraig_ManReadNodes(Fraig_Man_t *p)
Definition: fraigApi.c:48
int Fraig_NodeIsAnd(Fraig_Node_t *p)
Definition: fraigApi.c:153
#define assert(ex)
Definition: util_old.h:213
ABC_NAMESPACE_IMPL_START Fraig_NodeVec_t * Fraig_ManReadVecInputs(Fraig_Man_t *p)
DECLARATIONS ///.
Definition: fraigApi.c:43
Fraig_Node_t * Fraig_NodeReadNextE(Fraig_Node_t *p)
Definition: fraigApi.c:113
int Fraig_ManReadPatternNumDynamicFiltered(Fraig_Man_t *p)
Definition: fraigApi.c:69
unsigned nFanouts
Definition: fraigInt.h:228
Fraig_NodeVec_t * Fraig_ManReadVecOutputs(Fraig_Man_t *p)
Definition: fraigApi.c:44
Fraig_Node_t ** Fraig_ManReadOutputs(Fraig_Man_t *p)
Definition: fraigApi.c:47
Fraig_Node_t * Fraig_NodeReadOne(Fraig_Node_t *p)
Definition: fraigApi.c:111
void Fraig_ManSetFuncRed(Fraig_Man_t *p, int fFuncRed)
Definition: fraigApi.c:88
void Fraig_NodeSetChoice(Fraig_Man_t *pMan, Fraig_Node_t *pNodeOld, Fraig_Node_t *pNodeNew)
Definition: fraigApi.c:285
ABC_NAMESPACE_IMPL_START Fraig_Node_t * Fraig_NodeAndCanon(Fraig_Man_t *pMan, Fraig_Node_t *p1, Fraig_Node_t *p2)
DECLARATIONS ///.
Definition: fraigCanon.c:52
void Fraig_NodeSetData0(Fraig_Node_t *p, Fraig_Node_t *pData)
Definition: fraigApi.c:137
Fraig_Node_t * pData0
Definition: fraigInt.h:251
Fraig_Node_t * Fraig_NodeExor(Fraig_Man_t *p, Fraig_Node_t *p1, Fraig_Node_t *p2)
Definition: fraigApi.c:244