abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
covMinUtil.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [covMinUtil.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Mapping into network of SOPs/ESOPs.]
8 
9  Synopsis [Utilities.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: covMinUtil.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "covInt.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis []
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
45 void Min_CubeCreate( Vec_Str_t * vCover, Min_Cube_t * pCube, char Type )
46 {
47  int i;
48  assert( (int)pCube->nLits == Min_CubeCountLits(pCube) );
49  for ( i = 0; i < (int)pCube->nVars; i++ )
50  if ( Min_CubeHasBit(pCube, i*2) )
51  {
52  if ( Min_CubeHasBit(pCube, i*2+1) )
53 // fprintf( pFile, "-" );
54  Vec_StrPush( vCover, '-' );
55  else
56 // fprintf( pFile, "0" );
57  Vec_StrPush( vCover, '0' );
58  }
59  else
60  {
61  if ( Min_CubeHasBit(pCube, i*2+1) )
62  // fprintf( pFile, "1" );
63  Vec_StrPush( vCover, '1' );
64  else
65 // fprintf( pFile, "?" );
66  Vec_StrPush( vCover, '?' );
67  }
68 // fprintf( pFile, " 1\n" );
69  Vec_StrPush( vCover, ' ' );
70  Vec_StrPush( vCover, Type );
71  Vec_StrPush( vCover, '\n' );
72 }
73 
74 /**Function*************************************************************
75 
76  Synopsis []
77 
78  Description []
79 
80  SideEffects []
81 
82  SeeAlso []
83 
84 ***********************************************************************/
85 void Min_CoverCreate( Vec_Str_t * vCover, Min_Cube_t * pCover, char Type )
86 {
87  Min_Cube_t * pCube;
88  assert( pCover != NULL );
89  Vec_StrClear( vCover );
90  Min_CoverForEachCube( pCover, pCube )
91  Min_CubeCreate( vCover, pCube, Type );
92  Vec_StrPush( vCover, 0 );
93 }
94 
95 /**Function*************************************************************
96 
97  Synopsis []
98 
99  Description []
100 
101  SideEffects []
102 
103  SeeAlso []
104 
105 ***********************************************************************/
106 void Min_CubeWrite( FILE * pFile, Min_Cube_t * pCube )
107 {
108  int i;
109  assert( (int)pCube->nLits == Min_CubeCountLits(pCube) );
110  for ( i = 0; i < (int)pCube->nVars; i++ )
111  if ( Min_CubeHasBit(pCube, i*2) )
112  {
113  if ( Min_CubeHasBit(pCube, i*2+1) )
114  fprintf( pFile, "-" );
115  else
116  fprintf( pFile, "0" );
117  }
118  else
119  {
120  if ( Min_CubeHasBit(pCube, i*2+1) )
121  fprintf( pFile, "1" );
122  else
123  fprintf( pFile, "?" );
124  }
125  fprintf( pFile, " 1\n" );
126 // fprintf( pFile, " %d\n", pCube->nLits );
127 }
128 
129 /**Function*************************************************************
130 
131  Synopsis []
132 
133  Description []
134 
135  SideEffects []
136 
137  SeeAlso []
138 
139 ***********************************************************************/
140 void Min_CoverWrite( FILE * pFile, Min_Cube_t * pCover )
141 {
142  Min_Cube_t * pCube;
143  Min_CoverForEachCube( pCover, pCube )
144  Min_CubeWrite( pFile, pCube );
145  printf( "\n" );
146 }
147 
148 /**Function*************************************************************
149 
150  Synopsis []
151 
152  Description []
153 
154  SideEffects []
155 
156  SeeAlso []
157 
158 ***********************************************************************/
159 void Min_CoverWriteStore( FILE * pFile, Min_Man_t * p )
160 {
161  Min_Cube_t * pCube;
162  int i;
163  for ( i = 0; i <= p->nVars; i++ )
164  {
165  Min_CoverForEachCube( p->ppStore[i], pCube )
166  {
167  printf( "%2d : ", i );
168  if ( pCube == p->pBubble )
169  {
170  printf( "Bubble\n" );
171  continue;
172  }
173  Min_CubeWrite( pFile, pCube );
174  }
175  }
176  printf( "\n" );
177 }
178 
179 /**Function*************************************************************
180 
181  Synopsis []
182 
183  Description []
184 
185  SideEffects []
186 
187  SeeAlso []
188 
189 ***********************************************************************/
190 void Min_CoverWriteFile( Min_Cube_t * pCover, char * pName, int fEsop )
191 {
192  char Buffer[1000];
193  Min_Cube_t * pCube;
194  FILE * pFile;
195  int i;
196  sprintf( Buffer, "%s.%s", pName, fEsop? "esop" : "pla" );
197  for ( i = strlen(Buffer) - 1; i >= 0; i-- )
198  if ( Buffer[i] == '<' || Buffer[i] == '>' )
199  Buffer[i] = '_';
200  pFile = fopen( Buffer, "w" );
201  fprintf( pFile, "# %s cover for output %s generated by ABC on %s\n", fEsop? "ESOP":"SOP", pName, Extra_TimeStamp() );
202  fprintf( pFile, ".i %d\n", pCover? pCover->nVars : 0 );
203  fprintf( pFile, ".o %d\n", 1 );
204  fprintf( pFile, ".p %d\n", Min_CoverCountCubes(pCover) );
205  if ( fEsop ) fprintf( pFile, ".type esop\n" );
206  Min_CoverForEachCube( pCover, pCube )
207  Min_CubeWrite( pFile, pCube );
208  fprintf( pFile, ".e\n" );
209  fclose( pFile );
210 }
211 
212 /**Function*************************************************************
213 
214  Synopsis []
215 
216  Description []
217 
218  SideEffects []
219 
220  SeeAlso []
221 
222 ***********************************************************************/
224 {
225  Min_Cube_t * pCube;
226  int i;
227  for ( i = 0; i <= p->nVars; i++ )
228  Min_CoverForEachCube( p->ppStore[i], pCube )
229  assert( i == (int)pCube->nLits );
230 }
231 
232 
233 /**Function*************************************************************
234 
235  Synopsis []
236 
237  Description []
238 
239  SideEffects []
240 
241  SeeAlso []
242 
243 ***********************************************************************/
244 int Min_CubeCheck( Min_Cube_t * pCube )
245 {
246  int i;
247  for ( i = 0; i < (int)pCube->nVars; i++ )
248  if ( Min_CubeGetVar( pCube, i ) == 0 )
249  return 0;
250  return 1;
251 }
252 
253 /**Function*************************************************************
254 
255  Synopsis [Converts the cover from the sorted structure.]
256 
257  Description []
258 
259  SideEffects []
260 
261  SeeAlso []
262 
263 ***********************************************************************/
264 Min_Cube_t * Min_CoverCollect( Min_Man_t * p, int nSuppSize )
265 {
266  Min_Cube_t * pCov = NULL, ** ppTail = &pCov;
267  Min_Cube_t * pCube, * pCube2;
268  int i;
269  for ( i = 0; i <= nSuppSize; i++ )
270  {
271  Min_CoverForEachCubeSafe( p->ppStore[i], pCube, pCube2 )
272  {
273  assert( i == (int)pCube->nLits );
274  *ppTail = pCube;
275  ppTail = &pCube->pNext;
276  assert( pCube->uData[0] ); // not a bubble
277  }
278  }
279  *ppTail = NULL;
280  return pCov;
281 }
282 
283 /**Function*************************************************************
284 
285  Synopsis [Sorts the cover in the increasing number of literals.]
286 
287  Description []
288 
289  SideEffects []
290 
291  SeeAlso []
292 
293 ***********************************************************************/
295 {
296  Min_Cube_t * pCube, * pCube2;
297  Min_ManClean( p, p->nVars );
298  Min_CoverForEachCubeSafe( pCover, pCube, pCube2 )
299  {
300  pCube->pNext = p->ppStore[pCube->nLits];
301  p->ppStore[pCube->nLits] = pCube;
302  p->nCubes++;
303  }
304 }
305 
306 /**Function*************************************************************
307 
308  Synopsis [Sorts the cover in the increasing number of literals.]
309 
310  Description []
311 
312  SideEffects []
313 
314  SeeAlso []
315 
316 ***********************************************************************/
318 {
319  Min_Cube_t * pCube;
320  int i, Counter;
321  if ( pCover == NULL )
322  return 0;
323  // clean the cube
324  for ( i = 0; i < (int)pCover->nWords; i++ )
325  p->pTemp->uData[i] = ~((unsigned)0);
326  // add the bit data
327  Min_CoverForEachCube( pCover, pCube )
328  for ( i = 0; i < (int)pCover->nWords; i++ )
329  p->pTemp->uData[i] &= pCube->uData[i];
330  // count the vars
331  Counter = 0;
332  for ( i = 0; i < (int)pCover->nVars; i++ )
333  Counter += ( Min_CubeGetVar(p->pTemp, i) != 3 );
334  return Counter;
335 }
336 
337 ////////////////////////////////////////////////////////////////////////
338 /// END OF FILE ///
339 ////////////////////////////////////////////////////////////////////////
340 
341 
343 
void Min_CoverCreate(Vec_Str_t *vCover, Min_Cube_t *pCover, char Type)
Definition: covMinUtil.c:85
unsigned nVars
Definition: covInt.h:57
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Min_CubeCountLits(Min_Cube_t *pCube)
Definition: covInt.h:224
void Min_CoverExpand(Min_Man_t *p, Min_Cube_t *pCover)
Definition: covMinUtil.c:294
Min_Cube_t * pNext
Definition: covInt.h:56
static void Vec_StrClear(Vec_Str_t *p)
Definition: vecStr.h:519
#define Min_CoverForEachCubeSafe(pCover, pCube, pCube2)
Definition: covInt.h:69
int Min_CubeCheck(Min_Cube_t *pCube)
Definition: covMinUtil.c:244
static void Vec_StrPush(Vec_Str_t *p, char Entry)
Definition: vecStr.h:535
ABC_NAMESPACE_IMPL_START void Min_CubeCreate(Vec_Str_t *vCover, Min_Cube_t *pCube, char Type)
DECLARATIONS ///.
Definition: covMinUtil.c:45
void Min_CubeWrite(FILE *pFile, Min_Cube_t *pCube)
Definition: covMinUtil.c:106
void Min_CoverWrite(FILE *pFile, Min_Cube_t *pCover)
Definition: covMinUtil.c:140
static int Min_CubeGetVar(Min_Cube_t *p, int Var)
Definition: covInt.h:86
void Min_CoverWriteFile(Min_Cube_t *pCover, char *pName, int fEsop)
Definition: covMinUtil.c:190
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static int Min_CoverCountCubes(Min_Cube_t *pCover)
Definition: covInt.h:274
unsigned nWords
Definition: covInt.h:58
unsigned nLits
Definition: covInt.h:59
void Min_CoverCheck(Min_Man_t *p)
Definition: covMinUtil.c:223
char * sprintf()
static int Counter
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void Min_CoverWriteStore(FILE *pFile, Min_Man_t *p)
Definition: covMinUtil.c:159
int Min_CoverSuppVarNum(Min_Man_t *p, Min_Cube_t *pCover)
Definition: covMinUtil.c:317
#define Min_CoverForEachCube(pCover, pCube)
Definition: covInt.h:65
char * Extra_TimeStamp()
Min_Cube_t * Min_CoverCollect(Min_Man_t *p, int nSuppSize)
Definition: covMinUtil.c:264
#define assert(ex)
Definition: util_old.h:213
int strlen()
static int Min_CubeHasBit(Min_Cube_t *p, int i)
Definition: covInt.h:83
unsigned uData[1]
Definition: covInt.h:60
void Min_ManClean(Min_Man_t *p, int nSupp)
Definition: covMinMan.c:83
typedefABC_NAMESPACE_HEADER_START struct Min_Man_t_ Min_Man_t
DECLARATIONS ///.
Definition: covInt.h:34