abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bmcMulti.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [bmcMulti.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [SAT-based bounded model checking.]
8 
9  Synopsis [Proving multi-output properties.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: bmcMulti.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "bmc.h"
22 #include "proof/ssw/ssw.h"
23 #include "misc/extra/extra.h"
24 #include "aig/gia/giaAig.h"
25 #include "aig/ioa/ioa.h"
26 
28 
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// DECLARATIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 ////////////////////////////////////////////////////////////////////////
35 /// FUNCTION DEFINITIONS ///
36 ////////////////////////////////////////////////////////////////////////
37 
38 /**Function*************************************************************
39 
40  Synopsis [Divides outputs into solved and unsolved.]
41 
42  Description [Return array of unsolved outputs to extract into a new AIG.
43  Updates the resulting CEXes (vCexesOut) and current output map (vOutMap).]
44 
45  SideEffects []
46 
47  SeeAlso []
48 
49 ***********************************************************************/
50 Vec_Int_t * Gia_ManProcessOutputs( Vec_Ptr_t * vCexesIn, Vec_Ptr_t * vCexesOut, Vec_Int_t * vOutMap )
51 {
52  Abc_Cex_t * pCex;
53  Vec_Int_t * vLeftOver;
54  int i, iOut;
55  assert( Vec_PtrSize(vCexesIn) == Vec_IntSize(vOutMap) );
56  vLeftOver = Vec_IntAlloc( Vec_PtrSize(vCexesIn) );
57  Vec_IntForEachEntry( vOutMap, iOut, i )
58  {
59  assert( Vec_PtrEntry(vCexesOut, iOut) == NULL );
60  pCex = (Abc_Cex_t *)Vec_PtrEntry( vCexesIn, i );
61  if ( pCex ) // found a CEX for output iOut
62  {
63  Vec_PtrWriteEntry( vCexesIn, i, NULL );
64  Vec_PtrWriteEntry( vCexesOut, iOut, pCex );
65  }
66  else // still unsolved
67  {
68  Vec_IntWriteEntry( vOutMap, Vec_IntSize(vLeftOver), iOut );
69  Vec_IntPush( vLeftOver, i );
70  }
71  }
72  Vec_IntShrink( vOutMap, Vec_IntSize(vLeftOver) );
73  return vLeftOver;
74 }
75 
76 /**Function*************************************************************
77 
78  Synopsis [Counts the number of constant 0 POs.]
79 
80  Description []
81 
82  SideEffects []
83 
84  SeeAlso []
85 
86 ***********************************************************************/
88 {
89  Gia_Obj_t * pObj;
90  int i, Counter = 0;
91  Gia_ManForEachPo( p, pObj, i )
92  Counter += (Gia_ObjFaninLit0p(p, pObj) == 0);
93  return Counter;
94 }
96 {
97  Aig_Obj_t * pObj;
98  int i, Counter = 0;
99  Saig_ManForEachPo( p, pObj, i )
100  Counter += (Aig_ObjChild0(pObj) == Aig_ManConst0(p));
101  return Counter;
102 }
103 
104 /**Function*************************************************************
105 
106  Synopsis []
107 
108  Description []
109 
110  SideEffects []
111 
112  SeeAlso []
113 
114 ***********************************************************************/
115 void Gia_ManMultiReport( Aig_Man_t * p, char * pStr, int nTotalPo, int nTotalSize, abctime clkStart )
116 {
117  printf( "%3s : ", pStr );
118  printf( "PI =%6d ", Saig_ManPiNum(p) );
119  printf( "PO =%6d ", Saig_ManPoNum(p) );
120  printf( "FF =%7d ", Saig_ManRegNum(p) );
121  printf( "ND =%7d ", Aig_ManNodeNum(p) );
122  printf( "Solved =%7d (%5.1f %%) ", nTotalPo-Saig_ManPoNum(p), 100.0*(nTotalPo-Saig_ManPoNum(p))/Abc_MaxInt(1, nTotalPo) );
123  printf( "Size =%7d (%5.1f %%) ", Aig_ManObjNum(p), 100.0*Aig_ManObjNum(p)/Abc_MaxInt(1, nTotalSize) );
124  Abc_PrintTime( 1, "Time", Abc_Clock() - clkStart );
125 }
126 
127 /**Function*************************************************************
128 
129  Synopsis []
130 
131  Description []
132 
133  SideEffects []
134 
135  SeeAlso []
136 
137 ***********************************************************************/
138 Aig_Man_t * Gia_ManMultiProveSyn( Aig_Man_t * p, int fVerbose, int fVeryVerbose )
139 {
140  Aig_Man_t * pAig;
141  Gia_Man_t * pGia, * pTemp;
142  pGia = Gia_ManFromAig( p );
143  pGia = Gia_ManAigSyn2( pTemp = pGia, 1, 0, 0, 0, 0, 0, 0 );
144  Gia_ManStop( pTemp );
145  pAig = Gia_ManToAig( pGia, 0 );
146  Gia_ManStop( pGia );
147  return pAig;
148 }
149 
150 /**Function*************************************************************
151 
152  Synopsis []
153 
154  Description []
155 
156  SideEffects []
157 
158  SeeAlso []
159 
160 ***********************************************************************/
162 {
163  Ssw_RarPars_t ParsSim, * pParsSim = &ParsSim;
164  Saig_ParBmc_t ParsBmc, * pParsBmc = &ParsBmc;
165  Vec_Int_t * vOutMap, * vLeftOver;
166  Vec_Ptr_t * vCexes;
167  Aig_Man_t * pTemp;
168  abctime clkStart = Abc_Clock();
169  abctime nTimeToStop = pPars->TimeOutGlo ? Abc_Clock() + pPars->TimeOutGlo * CLOCKS_PER_SEC : 0;
170  int nTotalPo = Saig_ManPoNum(p);
171  int nTotalSize = Aig_ManObjNum(p);
172  int TimeOutLoc = pPars->TimeOutLoc;
173  int i, RetValue = -1;
174  if ( pPars->fVerbose )
175  printf( "MultiProve parameters: Global timeout = %d sec. Local timeout = %d sec. Time increase = %d %%.\n",
176  pPars->TimeOutGlo, pPars->TimeOutLoc, pPars->TimeOutInc );
177  if ( pPars->fVerbose )
178  printf( "Gap timout = %d sec. Per-output timeout = %d msec. Use synthesis = %d. Dump final = %d. Verbose = %d.\n",
179  pPars->TimeOutGap, pPars->TimePerOut, pPars->fUseSyn, pPars->fDumpFinal, pPars->fVerbose );
180  // create output map
181  vOutMap = Vec_IntStartNatural( Saig_ManPoNum(p) ); // maps current outputs into their original IDs
182  vCexes = Vec_PtrStart( Saig_ManPoNum(p) ); // maps solved outputs into their CEXes (or markers)
183  for ( i = 0; i < 1000; i++ )
184  {
185  int nSolved = Vec_PtrCountZero(vCexes);
186  // perform SIM3
187  Ssw_RarSetDefaultParams( pParsSim );
188  pParsSim->fSolveAll = 1;
189  pParsSim->fNotVerbose = 1;
190  pParsSim->fSilent = !pPars->fVeryVerbose;
191  pParsSim->TimeOut = TimeOutLoc;
192  pParsSim->nRandSeed = (i * 17) % 500;
193  pParsSim->nWords = 5;
194  RetValue *= Ssw_RarSimulate( p, pParsSim );
195  // sort outputs
196  if ( p->vSeqModelVec )
197  {
198  vLeftOver = Gia_ManProcessOutputs( p->vSeqModelVec, vCexes, vOutMap );
199  if ( Vec_IntSize(vLeftOver) == 0 )
200  break;
201  // remove solved
202  p = Saig_ManDupCones( pTemp = p, Vec_IntArray(vLeftOver), Vec_IntSize(vLeftOver) );
203  Vec_IntFree( vLeftOver );
204  Aig_ManStop( pTemp );
205  }
206  if ( pPars->fVerbose )
207  Gia_ManMultiReport( p, "SIM", nTotalPo, nTotalSize, clkStart );
208 
209  // check timeout
210  if ( nTimeToStop && Abc_Clock() + TimeOutLoc * CLOCKS_PER_SEC > nTimeToStop )
211  {
212  printf( "Global timeout (%d sec) is reached.\n", pPars->TimeOutGlo );
213  break;
214  }
215 
216  // perform BMC
217  Saig_ParBmcSetDefaultParams( pParsBmc );
218  pParsBmc->fSolveAll = 1;
219  pParsBmc->fNotVerbose = 1;
220  pParsBmc->fSilent = !pPars->fVeryVerbose;
221  pParsBmc->nTimeOut = TimeOutLoc;
222  pParsBmc->nTimeOutOne = pPars->TimePerOut;
223  RetValue *= Saig_ManBmcScalable( p, pParsBmc );
224  if ( pPars->fVeryVerbose )
225  Abc_Print( 1, "Some outputs are SAT (%d out of %d) after %d frames.\n",
226  Saig_ManPoNum(p) - Vec_PtrCountZero(p->vSeqModelVec), Saig_ManPoNum(p), pParsBmc->iFrame );
227  // sort outputs
228  if ( p->vSeqModelVec )
229  {
230  vLeftOver = Gia_ManProcessOutputs( p->vSeqModelVec, vCexes, vOutMap );
231  if ( Vec_IntSize(vLeftOver) == 0 )
232  break;
233  // remove solved
234  p = Saig_ManDupCones( pTemp = p, Vec_IntArray(vLeftOver), Vec_IntSize(vLeftOver) );
235  Vec_IntFree( vLeftOver );
236  Aig_ManStop( pTemp );
237  }
238  if ( pPars->fVerbose )
239  Gia_ManMultiReport( p, "BMC", nTotalPo, nTotalSize, clkStart );
240 
241  // check timeout
242  if ( nTimeToStop && Abc_Clock() + TimeOutLoc * CLOCKS_PER_SEC > nTimeToStop )
243  {
244  printf( "Global timeout (%d sec) is reached.\n", pPars->TimeOutGlo );
245  break;
246  }
247 
248  // check gap timeout
249  if ( pPars->TimeOutGap && pPars->TimeOutGap <= TimeOutLoc && nSolved == Vec_PtrCountZero(vCexes) )
250  {
251  printf( "Gap timeout (%d sec) is reached.\n", pPars->TimeOutGap );
252  break;
253  }
254 
255  // synthesize
256  if ( pPars->fUseSyn )
257  {
258  p = Gia_ManMultiProveSyn( pTemp = p, pPars->fVerbose, pPars->fVeryVerbose );
259  Aig_ManStop( pTemp );
260  if ( pPars->fVerbose )
261  Gia_ManMultiReport( p, "SYN", nTotalPo, nTotalSize, clkStart );
262  }
263 
264  // increase timeout
265  TimeOutLoc += TimeOutLoc * pPars->TimeOutInc / 100;
266  }
267  Vec_IntFree( vOutMap );
268  if ( pPars->fVerbose )
269  printf( "The number of POs proved UNSAT by synthesis = %d.\n", Gia_ManCountConst0Pos(p) );
270  if ( pPars->fDumpFinal )
271  {
272  char * pFileName = Extra_FileNameGenericAppend( p->pName, "_out.aig" );
273  Ioa_WriteAiger( p, pFileName, 0, 0 );
274  printf( "Final AIG was dumped into file \"%s\".\n", pFileName );
275  }
276  Aig_ManStop( p );
277  return vCexes;
278 }
280 {
281  Aig_Man_t * pAig;
282  if ( p->vSeqModelVec )
283  Vec_PtrFreeFree( p->vSeqModelVec ), p->vSeqModelVec = NULL;
284  pAig = Gia_ManToAig( p, 0 );
285  p->vSeqModelVec = Gia_ManMultiProveAig( pAig, pPars ); // deletes pAig
287  return Vec_PtrCountZero(p->vSeqModelVec) == Vec_PtrSize(p->vSeqModelVec) ? -1 : 0;
288 }
289 
290 ////////////////////////////////////////////////////////////////////////
291 /// END OF FILE ///
292 ////////////////////////////////////////////////////////////////////////
293 
294 
296 
int fVerbose
Definition: bmc.h:119
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
static Vec_Ptr_t * Vec_PtrStart(int nSize)
Definition: vecPtr.h:106
int fVeryVerbose
Definition: bmc.h:120
void Saig_ParBmcSetDefaultParams(Saig_ParBmc_t *p)
Definition: bmcBmc3.c:1284
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
int TimeOutGap
Definition: bmc.h:115
int Saig_ManBmcScalable(Aig_Man_t *pAig, Saig_ParBmc_t *pPars)
Definition: bmcBmc3.c:1390
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
static int Saig_ManPoNum(Aig_Man_t *p)
Definition: saig.h:74
Aig_Man_t * Gia_ManMultiProveSyn(Aig_Man_t *p, int fVerbose, int fVeryVerbose)
Definition: bmcMulti.c:138
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Aig_Obj_t * Aig_ObjChild0(Aig_Obj_t *pObj)
Definition: aig.h:310
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
void Aig_ManStop(Aig_Man_t *p)
Definition: aigMan.c:187
static int Aig_ManObjNum(Aig_Man_t *p)
Definition: aig.h:258
static int Gia_ObjFaninLit0p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:469
int nTimeOutOne
Definition: bmc.h:55
static void Vec_PtrFreeFree(Vec_Ptr_t *p)
Definition: vecPtr.h:569
ABC_NAMESPACE_IMPL_START Vec_Int_t * Gia_ManProcessOutputs(Vec_Ptr_t *vCexesIn, Vec_Ptr_t *vCexesOut, Vec_Int_t *vOutMap)
DECLARATIONS ///.
Definition: bmcMulti.c:50
int fUseSyn
Definition: bmc.h:117
int fSilent
Definition: ssw.h:104
static Aig_Obj_t * Aig_ManConst0(Aig_Man_t *p)
Definition: aig.h:263
int iFrame
Definition: bmc.h:70
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static Vec_Int_t * Vec_IntStartNatural(int nSize)
Definition: bblif.c:192
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
int Gia_ManMultiProve(Gia_Man_t *p, Bmc_MulPar_t *pPars)
Definition: bmcMulti.c:279
static int Aig_ManNodeNum(Aig_Man_t *p)
Definition: aig.h:256
Definition: gia.h:75
int fNotVerbose
Definition: ssw.h:103
Aig_Man_t * Saig_ManDupCones(Aig_Man_t *pAig, int *pPos, int nPos)
Definition: saigDup.c:543
int nTimeOut
Definition: bmc.h:53
Gia_Man_t * Gia_ManFromAig(Aig_Man_t *p)
INCLUDES ///.
Definition: giaAig.c:73
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
int TimeOutGlo
Definition: bmc.h:112
int Gia_ManCountConst0Pos(Aig_Man_t *p)
Definition: bmcMulti.c:95
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Gia_Man_t * Gia_ManAigSyn2(Gia_Man_t *p, int fOldAlgo, int fCoarsen, int fCutMin, int nRelaxRatio, int fDelayMin, int fVerbose, int fVeryVerbose)
Definition: giaScript.c:69
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
int TimeOut
Definition: ssw.h:98
int fNotVerbose
Definition: bmc.h:67
int Gia_ManCountConst0PosGia(Gia_Man_t *p)
Definition: bmcMulti.c:87
Aig_Man_t * Gia_ManToAig(Gia_Man_t *p, int fChoices)
Definition: giaAig.c:277
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Counter
int TimeOutInc
Definition: bmc.h:114
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
void Ioa_WriteAiger(Aig_Man_t *pMan, char *pFileName, int fWriteSymbols, int fCompact)
Definition: ioaWriteAig.c:446
static int Vec_PtrCountZero(Vec_Ptr_t *p)
Definition: vecPtr.h:343
Vec_Ptr_t * vSeqModelVec
Definition: gia.h:137
static int Saig_ManRegNum(Aig_Man_t *p)
Definition: saig.h:77
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
int nWords
Definition: ssw.h:93
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int fDumpFinal
Definition: bmc.h:118
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
int fSilent
Definition: bmc.h:69
static int Saig_ManPiNum(Aig_Man_t *p)
MACRO DEFINITIONS ///.
Definition: saig.h:73
static void Vec_IntShrink(Vec_Int_t *p, int nSizeNew)
Definition: bblif.c:435
Definition: gia.h:95
void Ssw_RarSetDefaultParams(Ssw_RarPars_t *p)
FUNCTION DEFINITIONS ///.
Definition: sswRarity.c:102
int TimeOutLoc
Definition: bmc.h:113
int fSolveAll
Definition: ssw.h:100
Vec_Ptr_t * Gia_ManMultiProveAig(Aig_Man_t *p, Bmc_MulPar_t *pPars)
Definition: bmcMulti.c:161
int TimePerOut
Definition: bmc.h:116
#define Saig_ManForEachPo(p, pObj, i)
Definition: saig.h:93
#define assert(ex)
Definition: util_old.h:213
char * Extra_FileNameGenericAppend(char *pBase, char *pSuffix)
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
Definition: utilCex.h:39
void Gia_ManMultiReport(Aig_Man_t *p, char *pStr, int nTotalPo, int nTotalSize, abctime clkStart)
Definition: bmcMulti.c:115
int nRandSeed
Definition: ssw.h:97
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
ABC_INT64_T abctime
Definition: abc_global.h:278
#define Gia_ManForEachPo(p, pObj, i)
Definition: gia.h:1036
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
int fSolveAll
Definition: bmc.h:57
int Ssw_RarSimulate(Aig_Man_t *pAig, Ssw_RarPars_t *pPars)
Definition: sswRarity.c:973