abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fxuUpdate.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [fxuUpdate.c]
4 
5  PackageName [MVSIS 2.0: Multi-valued logic synthesis system.]
6 
7  Synopsis [Updating the sparse matrix when divisors are accepted.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 1.0. Started - February 1, 2003.]
14 
15  Revision [$Id: fxuUpdate.c,v 1.0 2003/02/01 00:00:00 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "fxuInt.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 static void Fxu_UpdateDoublePairs( Fxu_Matrix * p, Fxu_Double * pDouble, Fxu_Var * pVar );
29 static void Fxu_UpdateMatrixDoubleCreateCubes( Fxu_Matrix * p, Fxu_Cube * pCube1, Fxu_Cube * pCube2, Fxu_Double * pDiv );
30 static void Fxu_UpdateMatrixDoubleClean( Fxu_Matrix * p, Fxu_Cube * pCubeUse, Fxu_Cube * pCubeRem );
31 static void Fxu_UpdateMatrixSingleClean( Fxu_Matrix * p, Fxu_Var * pVar1, Fxu_Var * pVar2, Fxu_Var * pVarNew );
32 
33 static void Fxu_UpdateCreateNewVars( Fxu_Matrix * p, Fxu_Var ** ppVarC, Fxu_Var ** ppVarD, int nCubes );
34 static int Fxu_UpdatePairCompare( Fxu_Pair ** ppP1, Fxu_Pair ** ppP2 );
35 static void Fxu_UpdatePairsSort( Fxu_Matrix * p, Fxu_Double * pDouble );
36 
37 static void Fxu_UpdateCleanOldDoubles( Fxu_Matrix * p, Fxu_Double * pDiv, Fxu_Cube * pCube );
38 static void Fxu_UpdateAddNewDoubles( Fxu_Matrix * p, Fxu_Cube * pCube );
39 static void Fxu_UpdateCleanOldSingles( Fxu_Matrix * p );
40 static void Fxu_UpdateAddNewSingles( Fxu_Matrix * p, Fxu_Var * pVar );
41 
42 ////////////////////////////////////////////////////////////////////////
43 /// FUNCTION DEFINITIONS ///
44 ////////////////////////////////////////////////////////////////////////
45 
46 /**Function*************************************************************
47 
48  Synopsis [Updates the matrix after selecting two divisors.]
49 
50  Description []
51 
52  SideEffects []
53 
54  SeeAlso []
55 
56 ***********************************************************************/
57 void Fxu_Update( Fxu_Matrix * p, Fxu_Single * pSingle, Fxu_Double * pDouble )
58 {
59  Fxu_Cube * pCube, * pCubeNew;
60  Fxu_Var * pVarC, * pVarD;
61  Fxu_Var * pVar1, * pVar2;
62 
63  // consider trivial cases
64  if ( pSingle == NULL )
65  {
66  assert( pDouble->Weight == Fxu_HeapDoubleReadMaxWeight( p->pHeapDouble ) );
67  Fxu_UpdateDouble( p );
68  return;
69  }
70  if ( pDouble == NULL )
71  {
72  assert( pSingle->Weight == Fxu_HeapSingleReadMaxWeight( p->pHeapSingle ) );
73  Fxu_UpdateSingle( p );
74  return;
75  }
76 
77  // get the variables of the single
78  pVar1 = pSingle->pVar1;
79  pVar2 = pSingle->pVar2;
80 
81  // remove the best double from the heap
82  Fxu_HeapDoubleDelete( p->pHeapDouble, pDouble );
83  // remove the best divisor from the table
84  Fxu_ListTableDelDivisor( p, pDouble );
85 
86  // create two new columns (vars)
87  Fxu_UpdateCreateNewVars( p, &pVarC, &pVarD, 1 );
88  // create one new row (cube)
89  pCubeNew = Fxu_MatrixAddCube( p, pVarD, 0 );
90  pCubeNew->pFirst = pCubeNew;
91  // set the first cube of the positive var
92  pVarD->pFirst = pCubeNew;
93 
94  // start collecting the affected vars and cubes
97  // add the vars
98  Fxu_MatrixRingVarsAdd( p, pVar1 );
99  Fxu_MatrixRingVarsAdd( p, pVar2 );
100  // remove the literals and collect the affected cubes
101  // remove the divisors associated with this cube
102  // add to the affected cube the literal corresponding to the new column
103  Fxu_UpdateMatrixSingleClean( p, pVar1, pVar2, pVarD );
104  // replace each two cubes of the pair by one new cube
105  // the new cube contains the base and the new literal
106  Fxu_UpdateDoublePairs( p, pDouble, pVarC );
107  // stop collecting the affected vars and cubes
110 
111  // add the literals to the new cube
112  assert( pVar1->iVar < pVar2->iVar );
113  assert( Fxu_SingleCountCoincidence( p, pVar1, pVar2 ) == 0 );
114  Fxu_MatrixAddLiteral( p, pCubeNew, pVar1 );
115  Fxu_MatrixAddLiteral( p, pCubeNew, pVar2 );
116 
117  // create new doubles; we cannot add them in the same loop
118  // because we first have to create *all* new cubes for each node
119  Fxu_MatrixForEachCubeInRing( p, pCube )
120  Fxu_UpdateAddNewDoubles( p, pCube );
121  // update the singles after removing some literals
123 
124  // undo the temporary rings with cubes and vars
127  // we should undo the rings before creating new singles
128 
129  // create new singles
130  Fxu_UpdateAddNewSingles( p, pVarC );
131  Fxu_UpdateAddNewSingles( p, pVarD );
132 
133  // recycle the divisor
134  MEM_FREE_FXU( p, Fxu_Double, 1, pDouble );
135  p->nDivs3++;
136 }
137 
138 /**Function*************************************************************
139 
140  Synopsis [Updates after accepting single cube divisor.]
141 
142  Description []
143 
144  SideEffects []
145 
146  SeeAlso []
147 
148 ***********************************************************************/
150 {
151  Fxu_Single * pSingle;
152  Fxu_Cube * pCube, * pCubeNew;
153  Fxu_Var * pVarC, * pVarD;
154  Fxu_Var * pVar1, * pVar2;
155 
156  // read the best divisor from the heap
157  pSingle = Fxu_HeapSingleReadMax( p->pHeapSingle );
158  // get the variables of this single-cube divisor
159  pVar1 = pSingle->pVar1;
160  pVar2 = pSingle->pVar2;
161 
162  // create two new columns (vars)
163  Fxu_UpdateCreateNewVars( p, &pVarC, &pVarD, 1 );
164  // create one new row (cube)
165  pCubeNew = Fxu_MatrixAddCube( p, pVarD, 0 );
166  pCubeNew->pFirst = pCubeNew;
167  // set the first cube
168  pVarD->pFirst = pCubeNew;
169 
170  // start collecting the affected vars and cubes
173  // add the vars
174  Fxu_MatrixRingVarsAdd( p, pVar1 );
175  Fxu_MatrixRingVarsAdd( p, pVar2 );
176  // remove the literals and collect the affected cubes
177  // remove the divisors associated with this cube
178  // add to the affected cube the literal corresponding to the new column
179  Fxu_UpdateMatrixSingleClean( p, pVar1, pVar2, pVarD );
180  // stop collecting the affected vars and cubes
183 
184  // add the literals to the new cube
185  assert( pVar1->iVar < pVar2->iVar );
186  assert( Fxu_SingleCountCoincidence( p, pVar1, pVar2 ) == 0 );
187  Fxu_MatrixAddLiteral( p, pCubeNew, pVar1 );
188  Fxu_MatrixAddLiteral( p, pCubeNew, pVar2 );
189 
190  // create new doubles; we cannot add them in the same loop
191  // because we first have to create *all* new cubes for each node
192  Fxu_MatrixForEachCubeInRing( p, pCube )
193  Fxu_UpdateAddNewDoubles( p, pCube );
194  // update the singles after removing some literals
196  // we should undo the rings before creating new singles
197 
198  // unmark the cubes
201 
202  // create new singles
203  Fxu_UpdateAddNewSingles( p, pVarC );
204  Fxu_UpdateAddNewSingles( p, pVarD );
205  p->nDivs1++;
206 }
207 
208 /**Function*************************************************************
209 
210  Synopsis [Updates the matrix after accepting a double cube divisor.]
211 
212  Description []
213 
214  SideEffects []
215 
216  SeeAlso []
217 
218 ***********************************************************************/
220 {
221  Fxu_Double * pDiv;
222  Fxu_Cube * pCube, * pCubeNew1, * pCubeNew2;
223  Fxu_Var * pVarC, * pVarD;
224 
225  // remove the best divisor from the heap
226  pDiv = Fxu_HeapDoubleGetMax( p->pHeapDouble );
227  // remove the best divisor from the table
228  Fxu_ListTableDelDivisor( p, pDiv );
229 
230  // create two new columns (vars)
231  Fxu_UpdateCreateNewVars( p, &pVarC, &pVarD, 2 );
232  // create two new rows (cubes)
233  pCubeNew1 = Fxu_MatrixAddCube( p, pVarD, 0 );
234  pCubeNew1->pFirst = pCubeNew1;
235  pCubeNew2 = Fxu_MatrixAddCube( p, pVarD, 1 );
236  pCubeNew2->pFirst = pCubeNew1;
237  // set the first cube
238  pVarD->pFirst = pCubeNew1;
239 
240  // add the literals to the new cubes
241  Fxu_UpdateMatrixDoubleCreateCubes( p, pCubeNew1, pCubeNew2, pDiv );
242 
243  // start collecting the affected cubes and vars
246  // replace each two cubes of the pair by one new cube
247  // the new cube contains the base and the new literal
248  Fxu_UpdateDoublePairs( p, pDiv, pVarD );
249  // stop collecting the affected cubes and vars
252 
253  // create new doubles; we cannot add them in the same loop
254  // because we first have to create *all* new cubes for each node
255  Fxu_MatrixForEachCubeInRing( p, pCube )
256  Fxu_UpdateAddNewDoubles( p, pCube );
257  // update the singles after removing some literals
259 
260  // undo the temporary rings with cubes and vars
263  // we should undo the rings before creating new singles
264 
265  // create new singles
266  Fxu_UpdateAddNewSingles( p, pVarC );
267  Fxu_UpdateAddNewSingles( p, pVarD );
268 
269  // recycle the divisor
270  MEM_FREE_FXU( p, Fxu_Double, 1, pDiv );
271  p->nDivs2++;
272 }
273 
274 /**Function*************************************************************
275 
276  Synopsis [Update the pairs.]
277 
278  Description []
279 
280  SideEffects []
281 
282  SeeAlso []
283 
284 ***********************************************************************/
286 {
287  Fxu_Pair * pPair;
288  Fxu_Cube * pCubeUse, * pCubeRem;
289  int i;
290 
291  // collect and sort the pairs
292  Fxu_UpdatePairsSort( p, pDouble );
293 // for ( i = 0; i < p->nPairsTemp; i++ )
294  for ( i = 0; i < p->vPairs->nSize; i++ )
295  {
296  // get the pair
297 // pPair = p->pPairsTemp[i];
298  pPair = (Fxu_Pair *)p->vPairs->pArray[i];
299  // out of the two cubes, select the one which comes earlier
300  pCubeUse = Fxu_PairMinCube( pPair );
301  pCubeRem = Fxu_PairMaxCube( pPair );
302  // collect the affected cube
303  assert( pCubeUse->pOrder == NULL );
304  Fxu_MatrixRingCubesAdd( p, pCubeUse );
305 
306  // remove some literals from pCubeUse and all literals from pCubeRem
307  Fxu_UpdateMatrixDoubleClean( p, pCubeUse, pCubeRem );
308  // add a literal that depends on the new variable
309  Fxu_MatrixAddLiteral( p, pCubeUse, pVar );
310  // check the literal count
311  assert( pCubeUse->lLits.nItems == pPair->nBase + 1 );
312  assert( pCubeRem->lLits.nItems == 0 );
313 
314  // update the divisors by removing useless pairs
315  Fxu_UpdateCleanOldDoubles( p, pDouble, pCubeUse );
316  Fxu_UpdateCleanOldDoubles( p, pDouble, pCubeRem );
317  // remove the pair
318  MEM_FREE_FXU( p, Fxu_Pair, 1, pPair );
319  }
320  p->vPairs->nSize = 0;
321 }
322 
323 /**Function*************************************************************
324 
325  Synopsis [Add two cubes corresponding to the given double-cube divisor.]
326 
327  Description []
328 
329  SideEffects []
330 
331  SeeAlso []
332 
333 ***********************************************************************/
335 {
336  Fxu_Lit * pLit1, * pLit2;
337  Fxu_Pair * pPair;
338  int nBase, nLits1, nLits2;
339 
340  // fill in the SOP and copy the fanins
341  nBase = nLits1 = nLits2 = 0;
342  pPair = pDiv->lPairs.pHead;
343  pLit1 = pPair->pCube1->lLits.pHead;
344  pLit2 = pPair->pCube2->lLits.pHead;
345  while ( 1 )
346  {
347  if ( pLit1 && pLit2 )
348  {
349  if ( pLit1->iVar == pLit2->iVar )
350  { // skip the cube free part
351  pLit1 = pLit1->pHNext;
352  pLit2 = pLit2->pHNext;
353  nBase++;
354  }
355  else if ( pLit1->iVar < pLit2->iVar )
356  { // add literal to the first cube
357  Fxu_MatrixAddLiteral( p, pCube1, pLit1->pVar );
358  // move to the next literal in this cube
359  pLit1 = pLit1->pHNext;
360  nLits1++;
361  }
362  else
363  { // add literal to the second cube
364  Fxu_MatrixAddLiteral( p, pCube2, pLit2->pVar );
365  // move to the next literal in this cube
366  pLit2 = pLit2->pHNext;
367  nLits2++;
368  }
369  }
370  else if ( pLit1 && !pLit2 )
371  { // add literal to the first cube
372  Fxu_MatrixAddLiteral( p, pCube1, pLit1->pVar );
373  // move to the next literal in this cube
374  pLit1 = pLit1->pHNext;
375  nLits1++;
376  }
377  else if ( !pLit1 && pLit2 )
378  { // add literal to the second cube
379  Fxu_MatrixAddLiteral( p, pCube2, pLit2->pVar );
380  // move to the next literal in this cube
381  pLit2 = pLit2->pHNext;
382  nLits2++;
383  }
384  else
385  break;
386  }
387  assert( pPair->nLits1 == nLits1 );
388  assert( pPair->nLits2 == nLits2 );
389  assert( pPair->nBase == nBase );
390 }
391 
392 
393 /**Function*************************************************************
394 
395  Synopsis [Create the node equal to double-cube divisor.]
396 
397  Description []
398 
399  SideEffects []
400 
401  SeeAlso []
402 
403 ***********************************************************************/
404 void Fxu_UpdateMatrixDoubleClean( Fxu_Matrix * p, Fxu_Cube * pCubeUse, Fxu_Cube * pCubeRem )
405 {
406  Fxu_Lit * pLit1, * bLit1Next;
407  Fxu_Lit * pLit2, * bLit2Next;
408 
409  // initialize the starting literals
410  pLit1 = pCubeUse->lLits.pHead;
411  pLit2 = pCubeRem->lLits.pHead;
412  bLit1Next = pLit1? pLit1->pHNext: NULL;
413  bLit2Next = pLit2? pLit2->pHNext: NULL;
414  // go through the pair and remove the literals in the base
415  // from the first cube and all literals from the second cube
416  while ( 1 )
417  {
418  if ( pLit1 && pLit2 )
419  {
420  if ( pLit1->iVar == pLit2->iVar )
421  { // this literal is present in both cubes - it belongs to the base
422  // mark the affected var
423  if ( pLit1->pVar->pOrder == NULL )
424  Fxu_MatrixRingVarsAdd( p, pLit1->pVar );
425  // leave the base in pCubeUse; delete it from pCubeRem
426  Fxu_MatrixDelLiteral( p, pLit2 );
427  // step to the next literals
428  pLit1 = bLit1Next;
429  pLit2 = bLit2Next;
430  bLit1Next = pLit1? pLit1->pHNext: NULL;
431  bLit2Next = pLit2? pLit2->pHNext: NULL;
432  }
433  else if ( pLit1->iVar < pLit2->iVar )
434  { // this literal is present in pCubeUse - remove it
435  // mark the affected var
436  if ( pLit1->pVar->pOrder == NULL )
437  Fxu_MatrixRingVarsAdd( p, pLit1->pVar );
438  // delete this literal
439  Fxu_MatrixDelLiteral( p, pLit1 );
440  // step to the next literals
441  pLit1 = bLit1Next;
442  bLit1Next = pLit1? pLit1->pHNext: NULL;
443  }
444  else
445  { // this literal is present in pCubeRem - remove it
446  // mark the affected var
447  if ( pLit2->pVar->pOrder == NULL )
448  Fxu_MatrixRingVarsAdd( p, pLit2->pVar );
449  // delete this literal
450  Fxu_MatrixDelLiteral( p, pLit2 );
451  // step to the next literals
452  pLit2 = bLit2Next;
453  bLit2Next = pLit2? pLit2->pHNext: NULL;
454  }
455  }
456  else if ( pLit1 && !pLit2 )
457  { // this literal is present in pCubeUse - leave it
458  // mark the affected var
459  if ( pLit1->pVar->pOrder == NULL )
460  Fxu_MatrixRingVarsAdd( p, pLit1->pVar );
461  // delete this literal
462  Fxu_MatrixDelLiteral( p, pLit1 );
463  // step to the next literals
464  pLit1 = bLit1Next;
465  bLit1Next = pLit1? pLit1->pHNext: NULL;
466  }
467  else if ( !pLit1 && pLit2 )
468  { // this literal is present in pCubeRem - remove it
469  // mark the affected var
470  if ( pLit2->pVar->pOrder == NULL )
471  Fxu_MatrixRingVarsAdd( p, pLit2->pVar );
472  // delete this literal
473  Fxu_MatrixDelLiteral( p, pLit2 );
474  // step to the next literals
475  pLit2 = bLit2Next;
476  bLit2Next = pLit2? pLit2->pHNext: NULL;
477  }
478  else
479  break;
480  }
481 }
482 
483 /**Function*************************************************************
484 
485  Synopsis [Updates the matrix after selecting a single cube divisor.]
486 
487  Description []
488 
489  SideEffects []
490 
491  SeeAlso []
492 
493 ***********************************************************************/
494 void Fxu_UpdateMatrixSingleClean( Fxu_Matrix * p, Fxu_Var * pVar1, Fxu_Var * pVar2, Fxu_Var * pVarNew )
495 {
496  Fxu_Lit * pLit1, * bLit1Next;
497  Fxu_Lit * pLit2, * bLit2Next;
498 
499  // initialize the starting literals
500  pLit1 = pVar1->lLits.pHead;
501  pLit2 = pVar2->lLits.pHead;
502  bLit1Next = pLit1? pLit1->pVNext: NULL;
503  bLit2Next = pLit2? pLit2->pVNext: NULL;
504  while ( 1 )
505  {
506  if ( pLit1 && pLit2 )
507  {
508  if ( pLit1->pCube->pVar->iVar == pLit2->pCube->pVar->iVar )
509  { // these literals coincide
510  if ( pLit1->iCube == pLit2->iCube )
511  { // these literals coincide
512 
513  // collect the affected cube
514  assert( pLit1->pCube->pOrder == NULL );
515  Fxu_MatrixRingCubesAdd( p, pLit1->pCube );
516 
517  // add the literal to this cube corresponding to the new column
518  Fxu_MatrixAddLiteral( p, pLit1->pCube, pVarNew );
519  // clean the old cubes
520  Fxu_UpdateCleanOldDoubles( p, NULL, pLit1->pCube );
521 
522  // remove the literals
523  Fxu_MatrixDelLiteral( p, pLit1 );
524  Fxu_MatrixDelLiteral( p, pLit2 );
525 
526  // go to the next literals
527  pLit1 = bLit1Next;
528  pLit2 = bLit2Next;
529  bLit1Next = pLit1? pLit1->pVNext: NULL;
530  bLit2Next = pLit2? pLit2->pVNext: NULL;
531  }
532  else if ( pLit1->iCube < pLit2->iCube )
533  {
534  pLit1 = bLit1Next;
535  bLit1Next = pLit1? pLit1->pVNext: NULL;
536  }
537  else
538  {
539  pLit2 = bLit2Next;
540  bLit2Next = pLit2? pLit2->pVNext: NULL;
541  }
542  }
543  else if ( pLit1->pCube->pVar->iVar < pLit2->pCube->pVar->iVar )
544  {
545  pLit1 = bLit1Next;
546  bLit1Next = pLit1? pLit1->pVNext: NULL;
547  }
548  else
549  {
550  pLit2 = bLit2Next;
551  bLit2Next = pLit2? pLit2->pVNext: NULL;
552  }
553  }
554  else if ( pLit1 && !pLit2 )
555  {
556  pLit1 = bLit1Next;
557  bLit1Next = pLit1? pLit1->pVNext: NULL;
558  }
559  else if ( !pLit1 && pLit2 )
560  {
561  pLit2 = bLit2Next;
562  bLit2Next = pLit2? pLit2->pVNext: NULL;
563  }
564  else
565  break;
566  }
567 }
568 
569 /**Function*************************************************************
570 
571  Synopsis [Sort the pairs.]
572 
573  Description []
574 
575  SideEffects []
576 
577  SeeAlso []
578 
579 ***********************************************************************/
581 {
582  Fxu_Pair * pPair;
583  // order the pairs by the first cube to ensure that new literals are added
584  // to the matrix from top to bottom - collect pairs into the array
585  p->vPairs->nSize = 0;
586  Fxu_DoubleForEachPair( pDouble, pPair )
587  Vec_PtrPush( p->vPairs, pPair );
588  if ( p->vPairs->nSize < 2 )
589  return;
590  // sort
591  qsort( (void *)p->vPairs->pArray, p->vPairs->nSize, sizeof(Fxu_Pair *),
592  (int (*)(const void *, const void *)) Fxu_UpdatePairCompare );
593  assert( Fxu_UpdatePairCompare( (Fxu_Pair**)p->vPairs->pArray, (Fxu_Pair**)p->vPairs->pArray + p->vPairs->nSize - 1 ) < 0 );
594 }
595 
596 /**Function*************************************************************
597 
598  Synopsis [Compares the vars by their number.]
599 
600  Description []
601 
602  SideEffects []
603 
604  SeeAlso []
605 
606 ***********************************************************************/
607 int Fxu_UpdatePairCompare( Fxu_Pair ** ppP1, Fxu_Pair ** ppP2 )
608 {
609  Fxu_Cube * pC1 = (*ppP1)->pCube1;
610  Fxu_Cube * pC2 = (*ppP2)->pCube1;
611  int iP1CubeMin, iP2CubeMin;
612  if ( pC1->pVar->iVar < pC2->pVar->iVar )
613  return -1;
614  if ( pC1->pVar->iVar > pC2->pVar->iVar )
615  return 1;
616  iP1CubeMin = Fxu_PairMinCubeInt( *ppP1 );
617  iP2CubeMin = Fxu_PairMinCubeInt( *ppP2 );
618  if ( iP1CubeMin < iP2CubeMin )
619  return -1;
620  if ( iP1CubeMin > iP2CubeMin )
621  return 1;
622  assert( 0 );
623  return 0;
624 }
625 
626 
627 /**Function*************************************************************
628 
629  Synopsis [Create new variables.]
630 
631  Description []
632 
633  SideEffects []
634 
635  SeeAlso []
636 
637 ***********************************************************************/
638 void Fxu_UpdateCreateNewVars( Fxu_Matrix * p, Fxu_Var ** ppVarC, Fxu_Var ** ppVarD, int nCubes )
639 {
640  Fxu_Var * pVarC, * pVarD;
641 
642  // add a new column for the complement
643  pVarC = Fxu_MatrixAddVar( p );
644  pVarC->nCubes = 0;
645  // add a new column for the divisor
646  pVarD = Fxu_MatrixAddVar( p );
647  pVarD->nCubes = nCubes;
648 
649  // mark this entry in the Value2Node array
650 // assert( p->pValue2Node[pVarC->iVar] > 0 );
651 // p->pValue2Node[pVarD->iVar ] = p->pValue2Node[pVarC->iVar];
652 // p->pValue2Node[pVarD->iVar+1] = p->pValue2Node[pVarC->iVar]+1;
653 
654  *ppVarC = pVarC;
655  *ppVarD = pVarD;
656 }
657 
658 
659 /**Function*************************************************************
660 
661  Synopsis []
662 
663  Description []
664 
665  SideEffects []
666 
667  SeeAlso []
668 
669 ***********************************************************************/
671 {
672  Fxu_Double * pDivCur;
673  Fxu_Pair * pPair;
674  int i;
675 
676  // if the cube is a recently introduced one
677  // it does not have pairs allocated
678  // in this case, there is nothing to update
679  if ( pCube->pVar->ppPairs == NULL )
680  return;
681 
682  // go through all the pairs of this cube
683  Fxu_CubeForEachPair( pCube, pPair, i )
684  {
685  // get the divisor of this pair
686  pDivCur = pPair->pDiv;
687  // skip the current divisor
688  if ( pDivCur == pDiv )
689  continue;
690  // remove this pair
691  Fxu_ListDoubleDelPair( pDivCur, pPair );
692  // the divisor may have become useless by now
693  if ( pDivCur->lPairs.nItems == 0 )
694  {
695  assert( pDivCur->Weight == pPair->nBase - 1 );
696  Fxu_HeapDoubleDelete( p->pHeapDouble, pDivCur );
697  Fxu_MatrixDelDivisor( p, pDivCur );
698  }
699  else
700  {
701  // update the divisor's weight
702  pDivCur->Weight -= pPair->nLits1 + pPair->nLits2 - 1 + pPair->nBase;
703  Fxu_HeapDoubleUpdate( p->pHeapDouble, pDivCur );
704  }
705  MEM_FREE_FXU( p, Fxu_Pair, 1, pPair );
706  }
707  // finally erase all the pair info associated with this cube
708  Fxu_PairClearStorage( pCube );
709 }
710 
711 /**Function*************************************************************
712 
713  Synopsis [Adds the new divisors that depend on the cube.]
714 
715  Description [Go through all the non-empty cubes of this cover
716  (except the given cube) and, for each of them, add the new divisor
717  with the given cube.]
718 
719  SideEffects []
720 
721  SeeAlso []
722 
723 ***********************************************************************/
725 {
726  Fxu_Cube * pTemp;
727  assert( pCube->pOrder );
728 
729  // if the cube is a recently introduced one
730  // it does not have pairs allocated
731  // in this case, there is nothing to update
732  if ( pCube->pVar->ppPairs == NULL )
733  return;
734 
735  for ( pTemp = pCube->pFirst; pTemp->pVar == pCube->pVar; pTemp = pTemp->pNext )
736  {
737  // do not add pairs with the empty cubes
738  if ( pTemp->lLits.nItems == 0 )
739  continue;
740  // to prevent adding duplicated pairs of the new cubes
741  // do not add the pair, if the current cube is marked
742  if ( pTemp->pOrder && pTemp->iCube >= pCube->iCube )
743  continue;
744  Fxu_MatrixAddDivisor( p, pTemp, pCube );
745  }
746 }
747 
748 /**Function*************************************************************
749 
750  Synopsis [Removes old single cube divisors.]
751 
752  Description []
753 
754  SideEffects []
755 
756  SeeAlso []
757 
758 ***********************************************************************/
760 {
761  Fxu_Single * pSingle, * pSingle2;
762  int WeightNew;
763  int Counter = 0;
764 
765  Fxu_MatrixForEachSingleSafe( p, pSingle, pSingle2 )
766  {
767  // if at least one of the variables is marked, recalculate
768  if ( pSingle->pVar1->pOrder || pSingle->pVar2->pOrder )
769  {
770  Counter++;
771  // get the new weight
772  WeightNew = -2 + Fxu_SingleCountCoincidence( p, pSingle->pVar1, pSingle->pVar2 );
773  if ( WeightNew >= 0 )
774  {
775  pSingle->Weight = WeightNew;
776  Fxu_HeapSingleUpdate( p->pHeapSingle, pSingle );
777  }
778  else
779  {
780  Fxu_HeapSingleDelete( p->pHeapSingle, pSingle );
781  Fxu_ListMatrixDelSingle( p, pSingle );
782  MEM_FREE_FXU( p, Fxu_Single, 1, pSingle );
783  }
784  }
785  }
786 // printf( "Called procedure %d times.\n", Counter );
787 }
788 
789 /**Function*************************************************************
790 
791  Synopsis [Updates the single cube divisors.]
792 
793  Description []
794 
795  SideEffects []
796 
797  SeeAlso []
798 
799 ***********************************************************************/
801 {
802  Fxu_MatrixComputeSinglesOne( p, pVar );
803 }
804 
805 ////////////////////////////////////////////////////////////////////////
806 /// END OF FILE ///
807 ////////////////////////////////////////////////////////////////////////
808 
809 
811 
int nCubes
Definition: fxuInt.h:216
Definition: fxuInt.h:213
void Fxu_UpdateSingle(Fxu_Matrix *p)
Definition: fxuUpdate.c:149
#define Fxu_MatrixForEachSingleSafe(Matrix, Single, Single2)
Definition: fxuInt.h:316
Fxu_ListLit lLits
Definition: fxuInt.h:219
int iCube
Definition: fxuInt.h:203
static void Fxu_UpdateCleanOldSingles(Fxu_Matrix *p)
Definition: fxuUpdate.c:759
static void Fxu_UpdateAddNewSingles(Fxu_Matrix *p, Fxu_Var *pVar)
Definition: fxuUpdate.c:800
static void Fxu_UpdateCreateNewVars(Fxu_Matrix *p, Fxu_Var **ppVarC, Fxu_Var **ppVarD, int nCubes)
Definition: fxuUpdate.c:638
void Fxu_ListTableDelDivisor(Fxu_Matrix *p, Fxu_Double *pDiv)
Definition: fxuList.c:254
void Fxu_PairClearStorage(Fxu_Cube *pCube)
Definition: fxuPair.c:476
Fxu_Pair * pHead
Definition: fxuInt.h:117
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int iVar
Definition: fxuInt.h:215
void Fxu_MatrixAddDivisor(Fxu_Matrix *p, Fxu_Cube *pCube1, Fxu_Cube *pCube2)
Definition: fxuMatrix.c:301
void Fxu_HeapDoubleDelete(Fxu_HeapDouble *p, Fxu_Double *pDiv)
Definition: fxuHeapD.c:250
Fxu_Lit * pHead
Definition: fxuInt.h:109
Fxu_ListPair lPairs
Definition: fxuInt.h:260
int iCube
Definition: fxuInt.h:229
static int Fxu_UpdatePairCompare(Fxu_Pair **ppP1, Fxu_Pair **ppP2)
Definition: fxuUpdate.c:607
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
Fxu_Lit * pHNext
Definition: fxuInt.h:233
#define Fxu_PairMaxCube(pPair)
Definition: fxuInt.h:288
Fxu_Double * Fxu_HeapDoubleGetMax(Fxu_HeapDouble *p)
Definition: fxuHeapD.c:291
#define Fxu_MatrixRingCubesAdd(Matrix, Cube)
Definition: fxuInt.h:394
Fxu_Var * pVar2
Definition: fxuInt.h:273
Fxu_Lit * pVNext
Definition: fxuInt.h:235
void Fxu_UpdateDouble(Fxu_Matrix *p)
Definition: fxuUpdate.c:219
static void Fxu_UpdateMatrixSingleClean(Fxu_Matrix *p, Fxu_Var *pVar1, Fxu_Var *pVar2, Fxu_Var *pVarNew)
Definition: fxuUpdate.c:494
Fxu_Cube * pCube1
Definition: fxuInt.h:245
static void Fxu_UpdateMatrixDoubleClean(Fxu_Matrix *p, Fxu_Cube *pCubeUse, Fxu_Cube *pCubeRem)
Definition: fxuUpdate.c:404
int Fxu_HeapDoubleReadMaxWeight(Fxu_HeapDouble *p)
Definition: fxuHeapD.c:319
Fxu_Double * pDiv
Definition: fxuInt.h:244
void Fxu_MatrixAddLiteral(Fxu_Matrix *p, Fxu_Cube *pCube, Fxu_Var *pVar)
Definition: fxuMatrix.c:205
#define Fxu_DoubleForEachPair(Div, Pair)
Definition: fxuInt.h:357
static void Fxu_UpdateMatrixDoubleCreateCubes(Fxu_Matrix *p, Fxu_Cube *pCube1, Fxu_Cube *pCube2, Fxu_Double *pDiv)
Definition: fxuUpdate.c:334
void Fxu_MatrixDelLiteral(Fxu_Matrix *p, Fxu_Lit *pLit)
Definition: fxuMatrix.c:252
#define Fxu_MatrixRingVarsStart(Matrix)
Definition: fxuInt.h:386
#define Fxu_MatrixRingCubesStop(Matrix)
Definition: fxuInt.h:388
static void Fxu_UpdateCleanOldDoubles(Fxu_Matrix *p, Fxu_Double *pDiv, Fxu_Cube *pCube)
Definition: fxuUpdate.c:670
#define Fxu_MatrixRingCubesStart(Matrix)
Definition: fxuInt.h:385
void Fxu_HeapDoubleUpdate(Fxu_HeapDouble *p, Fxu_Double *pDiv)
Definition: fxuHeapD.c:223
Fxu_ListLit lLits
Definition: fxuInt.h:206
Fxu_Var * pVar
Definition: fxuInt.h:205
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
int nBase
Definition: fxuInt.h:243
Fxu_Cube * Fxu_MatrixAddCube(Fxu_Matrix *p, Fxu_Var *pVar, int iCube)
Definition: fxuMatrix.c:183
Fxu_Cube * pFirst
Definition: fxuInt.h:217
Fxu_Cube * pCube
Definition: fxuInt.h:230
void Fxu_MatrixDelDivisor(Fxu_Matrix *p, Fxu_Double *pDiv)
Definition: fxuMatrix.c:233
void Fxu_MatrixRingVarsUnmark(Fxu_Matrix *p)
Definition: fxu.c:206
static int Counter
#define Fxu_MatrixRingVarsAdd(Matrix, Var)
Definition: fxuInt.h:395
void Fxu_MatrixComputeSinglesOne(Fxu_Matrix *p, Fxu_Var *pVar)
Definition: fxuSingle.c:184
#define Fxu_MatrixForEachCubeInRing(Matrix, Cube)
Definition: fxuInt.h:397
Fxu_Cube * pFirst
Definition: fxuInt.h:204
int nLits2
Definition: fxuInt.h:242
#define MEM_FREE_FXU(Manager, Type, Size, Pointer)
Definition: fxuInt.h:431
Fxu_Cube * pNext
Definition: fxuInt.h:208
int iVar
Definition: fxuInt.h:228
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Fxu_Cube * pCube2
Definition: fxuInt.h:246
int Fxu_SingleCountCoincidence(Fxu_Matrix *p, Fxu_Var *pVar1, Fxu_Var *pVar2)
Definition: fxuSingle.c:241
void Fxu_ListMatrixDelSingle(Fxu_Matrix *p, Fxu_Single *pSingle)
Definition: fxuList.c:194
static ABC_NAMESPACE_IMPL_START void Fxu_UpdateDoublePairs(Fxu_Matrix *p, Fxu_Double *pDouble, Fxu_Var *pVar)
DECLARATIONS ///.
Definition: fxuUpdate.c:285
Fxu_Var * pVar1
Definition: fxuInt.h:272
void Fxu_HeapSingleUpdate(Fxu_HeapSingle *p, Fxu_Single *pSingle)
Definition: fxuHeapS.c:226
int Weight
Definition: fxuInt.h:258
Fxu_Single * Fxu_HeapSingleReadMax(Fxu_HeapSingle *p)
Definition: fxuHeapS.c:275
Fxu_Pair *** ppPairs
Definition: fxuInt.h:218
int Weight
Definition: fxuInt.h:271
Fxu_Var * pVar
Definition: fxuInt.h:231
int Fxu_HeapSingleReadMaxWeight(Fxu_HeapSingle *p)
Definition: fxuHeapS.c:321
Fxu_Var * pOrder
Definition: fxuInt.h:222
static void Fxu_UpdateAddNewDoubles(Fxu_Matrix *p, Fxu_Cube *pCube)
Definition: fxuUpdate.c:724
int nItems
Definition: fxuInt.h:111
#define Fxu_MatrixRingVarsStop(Matrix)
Definition: fxuInt.h:389
int nItems
Definition: fxuInt.h:119
#define Fxu_PairMinCube(pPair)
Definition: fxuInt.h:287
#define assert(ex)
Definition: util_old.h:213
Fxu_Cube * pOrder
Definition: fxuInt.h:209
int nLits1
Definition: fxuInt.h:241
typedefABC_NAMESPACE_HEADER_START struct FxuMatrix Fxu_Matrix
INCLUDES ///.
Definition: fxuInt.h:63
void Fxu_HeapSingleDelete(Fxu_HeapSingle *p, Fxu_Single *pSingle)
Definition: fxuHeapS.c:251
Definition: fxuInt.h:226
void Fxu_Update(Fxu_Matrix *p, Fxu_Single *pSingle, Fxu_Double *pDouble)
FUNCTION DEFINITIONS ///.
Definition: fxuUpdate.c:57
Fxu_Var * Fxu_MatrixAddVar(Fxu_Matrix *p)
Definition: fxuMatrix.c:161
#define Fxu_CubeForEachPair(pCube, pPair, i)
Definition: fxuInt.h:368
static void Fxu_UpdatePairsSort(Fxu_Matrix *p, Fxu_Double *pDouble)
Definition: fxuUpdate.c:580
void Fxu_ListDoubleDelPair(Fxu_Double *pDiv, Fxu_Pair *pPair)
Definition: fxuList.c:489
#define Fxu_PairMinCubeInt(pPair)
Definition: fxuInt.h:289
void Fxu_MatrixRingCubesUnmark(Fxu_Matrix *p)
Definition: fxu.c:185