abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mfsGia.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [mfsGia.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [The good old minimization with complete don't-cares.]
8 
9  Synopsis [Experimental code based on the new AIG package.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - July 29, 2009.]
16 
17  Revision [$Id: mfsGia.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "mfsInt.h"
22 #include "aig/gia/giaAig.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 static inline int Gia_ObjChild0Copy( Aig_Obj_t * pObj ) { return Gia_LitNotCond( Aig_ObjFanin0(pObj)->iData, Aig_ObjFaninC0(pObj) ); }
32 static inline int Gia_ObjChild1Copy( Aig_Obj_t * pObj ) { return Gia_LitNotCond( Aig_ObjFanin1(pObj)->iData, Aig_ObjFaninC1(pObj) ); }
33 
34 // r i10_if6.blif; ps; mfs -v
35 // r pj1_if6.blif; ps; mfs -v
36 // r x/01_if6.blif; ps; mfs -v
37 
38 ////////////////////////////////////////////////////////////////////////
39 /// FUNCTION DEFINITIONS ///
40 ////////////////////////////////////////////////////////////////////////
41 
42 /**Function*************************************************************
43 
44  Synopsis [Derives the resubstitution miter as an GIA.]
45 
46  Description []
47 
48  SideEffects []
49 
50  SeeAlso []
51 
52 ***********************************************************************/
54 {
55  Gia_Man_t * pNew;//, * pTemp;
56  Aig_Obj_t * pObj;
57  int i, * pOuts0, * pOuts1;
58  Aig_ManSetPioNumbers( p );
59  // create the new manager
60  pNew = Gia_ManStart( Aig_ManObjNum(p) );
61  pNew->pName = Gia_UtilStrsav( p->pName );
62  pNew->pSpec = Gia_UtilStrsav( p->pSpec );
63  Gia_ManHashAlloc( pNew );
64  // create the objects
65  pOuts0 = ABC_ALLOC( int, Aig_ManPoNum(p) );
66  Aig_ManForEachObj( p, pObj, i )
67  {
68  if ( Aig_ObjIsAnd(pObj) )
69  pObj->iData = Gia_ManHashAnd( pNew, Gia_ObjChild0Copy(pObj), Gia_ObjChild1Copy(pObj) );
70  else if ( Aig_ObjIsPi(pObj) )
71  pObj->iData = Gia_ManAppendCi( pNew );
72  else if ( Aig_ObjIsPo(pObj) )
73  pOuts0[ Aig_ObjPioNum(pObj) ] = Gia_ObjChild0Copy(pObj);
74  else if ( Aig_ObjIsConst1(pObj) )
75  pObj->iData = 1;
76  else
77  assert( 0 );
78  }
79  // create the objects
80  pOuts1 = ABC_ALLOC( int, Aig_ManPoNum(p) );
81  Aig_ManForEachObj( p, pObj, i )
82  {
83  if ( Aig_ObjIsAnd(pObj) )
84  pObj->iData = Gia_ManHashAnd( pNew, Gia_ObjChild0Copy(pObj), Gia_ObjChild1Copy(pObj) );
85  else if ( Aig_ObjIsPi(pObj) )
86  pObj->iData = Gia_ManAppendCi( pNew );
87  else if ( Aig_ObjIsPo(pObj) )
88  pOuts1[ Aig_ObjPioNum(pObj) ] = Gia_ObjChild0Copy(pObj);
89  else if ( Aig_ObjIsConst1(pObj) )
90  pObj->iData = 1;
91  else
92  assert( 0 );
93  }
94  // add the outputs
95  Gia_ManAppendCo( pNew, pOuts0[0] );
96  Gia_ManAppendCo( pNew, pOuts1[0] );
97  Gia_ManAppendCo( pNew, pOuts0[1] );
98  Gia_ManAppendCo( pNew, Gia_LitNot(pOuts1[1]) );
99  for ( i = 2; i < Aig_ManPoNum(p); i++ )
100  Gia_ManAppendCo( pNew, Gia_LitNot( Gia_ManHashXor(pNew, pOuts0[i], pOuts1[i]) ) );
101  Gia_ManHashStop( pNew );
102  ABC_FREE( pOuts0 );
103  ABC_FREE( pOuts1 );
104 // pNew = Gia_ManCleanup( pTemp = pNew );
105 // Gia_ManStop( pTemp );
106  return pNew;
107 }
108 
109 /**Function*************************************************************
110 
111  Synopsis []
112 
113  Description []
114 
115  SideEffects []
116 
117  SeeAlso []
118 
119 ***********************************************************************/
121 {
122  int nBTLimit = 500;
123  // prepare AIG
124  assert( p->pGia == NULL );
125  p->pGia = Gia_ManCreateResubMiter( p->pAigWin );
126  // prepare AIG
127  Gia_ManCreateRefs( p->pGia );
128  Gia_ManCleanMark0( p->pGia );
129  Gia_ManCleanMark1( p->pGia );
130  Gia_ManFillValue ( p->pGia ); // maps nodes into trail ids
131  Gia_ManCleanPhase( p->pGia );
132  // prepare solver
133  p->pTas = Tas_ManAlloc( p->pGia, nBTLimit );
134  p->vCex = Tas_ReadModel( p->pTas );
135  p->vGiaLits = Vec_PtrAlloc( 100 );
136 }
137 
138 
139 /**Function*************************************************************
140 
141  Synopsis []
142 
143  Description []
144 
145  SideEffects []
146 
147  SeeAlso []
148 
149 ***********************************************************************/
151 {
152  assert( p->pGia != NULL );
153  Gia_ManStop( p->pGia ); p->pGia = NULL;
154  Tas_ManStop( p->pTas ); p->pTas = NULL;
155  Vec_PtrFree( p->vGiaLits );
156 }
157 
158 /**Function*************************************************************
159 
160  Synopsis []
161 
162  Description []
163 
164  SideEffects []
165 
166  SeeAlso []
167 
168 ***********************************************************************/
170 {
171  Gia_Obj_t * pObj;
172  int i, Entry;
173 // Gia_ManCleanMark1( p );
174  Gia_ManConst0(p)->fMark1 = 0;
175  Gia_ManForEachCi( p, pObj, i )
176  pObj->fMark1 = 0;
177 // pObj->fMark1 = Gia_ManRandom(0);
178  Vec_IntForEachEntry( vCex, Entry, i )
179  {
180  pObj = Gia_ManCi( p, Gia_Lit2Var(Entry) );
181  pObj->fMark1 = !Gia_LitIsCompl(Entry);
182  }
183  Gia_ManForEachAnd( p, pObj, i )
184  pObj->fMark1 = (Gia_ObjFanin0(pObj)->fMark1 ^ Gia_ObjFaninC0(pObj)) &
185  (Gia_ObjFanin1(pObj)->fMark1 ^ Gia_ObjFaninC1(pObj));
186  Gia_ManForEachCo( p, pObj, i )
187  pObj->fMark1 = Gia_ObjFanin0(pObj)->fMark1 ^ Gia_ObjFaninC0(pObj);
188 }
189 
190 
191 
192 
193 /**Function*************************************************************
194 
195  Synopsis []
196 
197  Description []
198 
199  SideEffects []
200 
201  SeeAlso []
202 
203 ***********************************************************************/
204 int Abc_NtkMfsTryResubOnceGia( Mfs_Man_t * p, int * pCands, int nCands )
205 {
206  int fVeryVerbose = 0;
207  int fUseGia = 1;
208  unsigned * pData;
209  int i, iVar, status, iOut;
210  clock_t clk = clock();
211  p->nSatCalls++;
212 // return -1;
213  assert( p->pGia != NULL );
214  assert( p->pTas != NULL );
215  // convert to literals
216  Vec_PtrClear( p->vGiaLits );
217  // create the first four literals
218  Vec_PtrPush( p->vGiaLits, Gia_ObjChild0(Gia_ManPo(p->pGia, 0)) );
219  Vec_PtrPush( p->vGiaLits, Gia_ObjChild0(Gia_ManPo(p->pGia, 1)) );
220  Vec_PtrPush( p->vGiaLits, Gia_ObjChild0(Gia_ManPo(p->pGia, 2)) );
221  Vec_PtrPush( p->vGiaLits, Gia_ObjChild0(Gia_ManPo(p->pGia, 3)) );
222  for ( i = 0; i < nCands; i++ )
223  {
224  // get the output number
225  iOut = Gia_Lit2Var(pCands[i]) - 2 * p->pCnf->nVars;
226  // write the literal
227  Vec_PtrPush( p->vGiaLits, Gia_ObjChild0(Gia_ManPo(p->pGia, 4 + iOut)) );
228  }
229  // perform SAT solving
230  status = Tas_ManSolveArray( p->pTas, p->vGiaLits );
231  if ( status == -1 )
232  {
233  p->nTimeOuts++;
234  if ( fVeryVerbose )
235  printf( "t" );
236 // p->nSatUndec++;
237 // p->nConfUndec += p->Pars.nBTThis;
238 // Cec_ManSatAddToStore( vCexStore, NULL, i ); // timeout
239 // p->timeSatUndec += clock() - clk;
240  }
241  else if ( status == 1 )
242  {
243  if ( fVeryVerbose )
244  printf( "u" );
245 // p->nSatUnsat++;
246 // p->nConfUnsat += p->Pars.nBTThis;
247 // p->timeSatUnsat += clock() - clk;
248  }
249  else
250  {
251  p->nSatCexes++;
252  if ( fVeryVerbose )
253  printf( "s" );
254 // p->nSatSat++;
255 // p->nConfSat += p->Pars.nBTThis;
256 // Gia_SatVerifyPattern( pAig, pRoot, vCex, vVisit );
257 // Cec_ManSatAddToStore( vCexStore, vCex, i );
258 // p->timeSatSat += clock() - clk;
259 
260  // resimulate the counter-example
261  Abc_NtkMfsResimulate( p->pGia, Tas_ReadModel(p->pTas) );
262 
263  if ( fUseGia )
264  {
265 /*
266  int Val0 = Gia_ManPo(p->pGia, 0)->fMark1;
267  int Val1 = Gia_ManPo(p->pGia, 1)->fMark1;
268  int Val2 = Gia_ManPo(p->pGia, 2)->fMark1;
269  int Val3 = Gia_ManPo(p->pGia, 3)->fMark1;
270  assert( Val0 == 1 );
271  assert( Val1 == 1 );
272  assert( Val2 == 1 );
273  assert( Val3 == 1 );
274 */
275  // store the counter-example
276  Vec_IntForEachEntry( p->vProjVarsSat, iVar, i )
277  {
278  pData = (unsigned *)Vec_PtrEntry( p->vDivCexes, i );
279  iOut = iVar - 2 * p->pCnf->nVars;
280 // if ( !Gia_ManPo( p->pGia, 4 + iOut )->fMark1 ) // remove 0s!!!
281  if ( Gia_ManPo( p->pGia, 4 + iOut )->fMark1 ) // remove 0s!!! - rememeber complemented attribute
282  {
283  assert( Aig_InfoHasBit(pData, p->nCexes) );
284  Aig_InfoXorBit( pData, p->nCexes );
285  }
286  }
287  p->nCexes++;
288  }
289 
290  }
291  return status;
292 }
293 
294 
295 ////////////////////////////////////////////////////////////////////////
296 /// END OF FILE ///
297 ////////////////////////////////////////////////////////////////////////
298 
299 
301 
Tas_Man_t * Tas_ManAlloc(Gia_Man_t *pAig, int nBTLimit)
Definition: giaCTas.c:187
int Tas_ManSolveArray(Tas_Man_t *p, Vec_Ptr_t *vObjs)
Definition: giaCTas.c:1423
void Gia_ManCreateRefs(Gia_Man_t *p)
Definition: giaUtil.c:715
void Gia_ManCleanPhase(Gia_Man_t *p)
Definition: giaUtil.c:431
static Gia_Obj_t * Gia_ObjChild0(Gia_Obj_t *pObj)
Definition: gia.h:457
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
void Tas_ManStop(Tas_Man_t *p)
Definition: giaCTas.c:223
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
Vec_Int_t * vProjVarsSat
Definition: mfsInt.h:65
void Abc_NtkMfsConstructGia(Mfs_Man_t *p)
Definition: mfsGia.c:120
static Gia_Obj_t * Gia_ManCi(Gia_Man_t *p, int v)
Definition: gia.h:403
static int Gia_ManAppendCo(Gia_Man_t *p, int iLit0)
Definition: gia.h:703
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:658
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Aig_ManObjNum(Aig_Man_t *p)
Definition: aig.h:258
static Gia_Obj_t * Gia_ManPo(Gia_Man_t *p, int v)
Definition: gia.h:406
static int Gia_ManAppendCi(Gia_Man_t *p)
Definition: gia.h:583
int nVars
Definition: cnf.h:59
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
void Gia_ManCleanMark0(Gia_Man_t *p)
Definition: giaUtil.c:215
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
unsigned fMark1
Definition: gia.h:84
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
Definition: gia.h:75
void Gia_ManCleanMark1(Gia_Man_t *p)
Definition: giaUtil.c:272
Aig_Man_t * pAigWin
Definition: mfsInt.h:87
void Abc_NtkMfsResimulate(Gia_Man_t *p, Vec_Int_t *vCex)
Definition: mfsGia.c:169
static int Gia_ObjChild1Copy(Aig_Obj_t *pObj)
Definition: mfsGia.c:32
#define Gia_ManForEachCi(p, pObj, i)
Definition: gia.h:1016
int Abc_NtkMfsTryResubOnceGia(Mfs_Man_t *p, int *pCands, int nCands)
Definition: mfsGia.c:204
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
char * pName
Definition: gia.h:97
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
char * pSpec
Definition: gia.h:98
static int Aig_ObjIsConst1(Aig_Obj_t *pObj)
Definition: aig.h:274
Gia_Man_t * Gia_ManStart(int nObjsMax)
DECLARATIONS ///.
Definition: giaMan.c:52
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
Definition: aig.h:69
void Gia_ManFillValue(Gia_Man_t *p)
Definition: giaUtil.c:328
Vec_Int_t * Tas_ReadModel(Tas_Man_t *p)
Definition: giaCTas.c:250
int nSatCalls
Definition: mfsInt.h:70
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Vec_Ptr_t * vDivCexes
Definition: mfsInt.h:67
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int iData
Definition: aig.h:88
int nCexes
Definition: mfsInt.h:69
void Abc_NtkMfsDeconstructGia(Mfs_Man_t *p)
Definition: mfsGia.c:150
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
static ABC_NAMESPACE_IMPL_START int Gia_ObjChild0Copy(Aig_Obj_t *pObj)
DECLARATIONS ///.
Definition: mfsGia.c:31
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: gia.h:95
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
static int Aig_ObjFaninC1(Aig_Obj_t *pObj)
Definition: aig.h:307
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
int nSatCexes
Definition: mfsInt.h:71
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition: giaHash.c:99
Cnf_Dat_t * pCnf
Definition: mfsInt.h:88
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:572
Gia_Man_t * Gia_ManCreateResubMiter(Aig_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: mfsGia.c:53
static int Aig_ObjIsAnd(Aig_Obj_t *pObj)
Definition: aig.h:278
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Gia_ManHashStop(Gia_Man_t *p)
Definition: giaHash.c:142
int nTimeOuts
Definition: mfsInt.h:114