forked from hlsyounes/ymer
/
cuddUtil.c
3774 lines (3076 loc) · 99.6 KB
/
cuddUtil.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**CFile***********************************************************************
FileName [cuddUtil.c]
PackageName [cudd]
Synopsis [Utility functions.]
Description [External procedures included in this module:
<ul>
<li> Cudd_PrintMinterm()
<li> Cudd_bddPrintCover()
<li> Cudd_PrintDebug()
<li> Cudd_DagSize()
<li> Cudd_EstimateCofactor()
<li> Cudd_EstimateCofactorSimple()
<li> Cudd_SharingSize()
<li> Cudd_CountMinterm()
<li> Cudd_CountPath()
<li> Cudd_CountPathsToNonZero()
<li> Cudd_Support()
<li> Cudd_SupportIndex()
<li> Cudd_SupportSize()
<li> Cudd_VectorSupport()
<li> Cudd_VectorSupportIndex()
<li> Cudd_VectorSupportSize()
<li> Cudd_ClassifySupport()
<li> Cudd_CountLeaves()
<li> Cudd_bddPickOneCube()
<li> Cudd_bddPickOneMinterm()
<li> Cudd_bddPickArbitraryMinterms()
<li> Cudd_SubsetWithMaskVars()
<li> Cudd_FirstCube()
<li> Cudd_NextCube()
<li> Cudd_bddComputeCube()
<li> Cudd_addComputeCube()
<li> Cudd_FirstNode()
<li> Cudd_NextNode()
<li> Cudd_GenFree()
<li> Cudd_IsGenEmpty()
<li> Cudd_IndicesToCube()
<li> Cudd_PrintVersion()
<li> Cudd_AverageDistance()
<li> Cudd_Random()
<li> Cudd_Srandom()
<li> Cudd_Density()
</ul>
Internal procedures included in this module:
<ul>
<li> cuddP()
<li> cuddStCountfree()
<li> cuddCollectNodes()
<li> cuddNodeArray()
</ul>
Static procedures included in this module:
<ul>
<li> dp2()
<li> ddPrintMintermAux()
<li> ddDagInt()
<li> ddCountMintermAux()
<li> ddCountPathAux()
<li> ddSupportStep()
<li> ddClearFlag()
<li> ddLeavesInt()
<li> ddPickArbitraryMinterms()
<li> ddPickRepresentativeCube()
</ul>]
Author [Fabio Somenzi]
Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
Neither the name of the University of Colorado nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.]
******************************************************************************/
#include "util.h"
#include "cuddInt.h"
/*---------------------------------------------------------------------------*/
/* Constant declarations */
/*---------------------------------------------------------------------------*/
/* Random generator constants. */
#define MODULUS1 2147483563
#define LEQA1 40014
#define LEQQ1 53668
#define LEQR1 12211
#define MODULUS2 2147483399
#define LEQA2 40692
#define LEQQ2 52774
#define LEQR2 3791
#define STAB_SIZE 64
#define STAB_DIV (1 + (MODULUS1 - 1) / STAB_SIZE)
/*---------------------------------------------------------------------------*/
/* Stucture declarations */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Type declarations */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Variable declarations */
/*---------------------------------------------------------------------------*/
#ifndef lint
static char rcsid[] DD_UNUSED = "$Id: cuddUtil.c,v 1.81 2009/03/08 02:49:02 fabio Exp $";
#endif
static DdNode *background, *zero;
static long cuddRand = 0;
static long cuddRand2;
static long shuffleSelect;
static long shuffleTable[STAB_SIZE];
/*---------------------------------------------------------------------------*/
/* Macro declarations */
/*---------------------------------------------------------------------------*/
#define bang(f) ((Cudd_IsComplement(f)) ? '!' : ' ')
#ifdef __cplusplus
extern "C" {
#endif
/**AutomaticStart*************************************************************/
/*---------------------------------------------------------------------------*/
/* Static function prototypes */
/*---------------------------------------------------------------------------*/
static int dp2 (DdManager *dd, DdNode *f, st_table *t);
static void ddPrintMintermAux (DdManager *dd, DdNode *node, int *list);
static int ddDagInt (DdNode *n);
static int cuddNodeArrayRecur (DdNode *f, DdNodePtr *table, int index);
static int cuddEstimateCofactor (DdManager *dd, st_table *table, DdNode * node, int i, int phase, DdNode ** ptr);
static DdNode * cuddUniqueLookup (DdManager * unique, int index, DdNode * T, DdNode * E);
static int cuddEstimateCofactorSimple (DdNode * node, int i);
static double ddCountMintermAux (DdNode *node, double max, DdHashTable *table);
static double ddCountPathAux (DdNode *node, st_table *table);
static double ddCountPathsToNonZero (DdNode * N, st_table * table);
static void ddSupportStep (DdNode *f, int *support);
static void ddClearFlag (DdNode *f);
static int ddLeavesInt (DdNode *n);
static int ddPickArbitraryMinterms (DdManager *dd, DdNode *node, int nvars, int nminterms, char **string);
static int ddPickRepresentativeCube (DdManager *dd, DdNode *node, double *weight, char *string);
/**AutomaticEnd***************************************************************/
#ifdef __cplusplus
}
#endif
/*---------------------------------------------------------------------------*/
/* Definition of exported functions */
/*---------------------------------------------------------------------------*/
/**Function********************************************************************
Synopsis [Prints a disjoint sum of products.]
Description [Prints a disjoint sum of product cover for the function
rooted at node. Each product corresponds to a path from node to a
leaf node different from the logical zero, and different from the
background value. Uses the package default output file. Returns 1
if successful; 0 otherwise.]
SideEffects [None]
SeeAlso [Cudd_PrintDebug Cudd_bddPrintCover]
******************************************************************************/
int
Cudd_PrintMinterm(
DdManager * manager,
DdNode * node)
{
int i, *list;
background = manager->background;
zero = Cudd_Not(manager->one);
list = ALLOC(int,manager->size);
if (list == NULL) {
manager->errorCode = CUDD_MEMORY_OUT;
return(0);
}
for (i = 0; i < manager->size; i++) list[i] = 2;
ddPrintMintermAux(manager,node,list);
FREE(list);
return(1);
} /* end of Cudd_PrintMinterm */
/**Function********************************************************************
Synopsis [Prints a sum of prime implicants of a BDD.]
Description [Prints a sum of product cover for an incompletely
specified function given by a lower bound and an upper bound. Each
product is a prime implicant obtained by expanding the product
corresponding to a path from node to the constant one. Uses the
package default output file. Returns 1 if successful; 0 otherwise.]
SideEffects [None]
SeeAlso [Cudd_PrintMinterm]
******************************************************************************/
int
Cudd_bddPrintCover(
DdManager *dd,
DdNode *l,
DdNode *u)
{
int *array;
int q, result;
DdNode *lb;
#ifdef DD_DEBUG
DdNode *cover;
#endif
array = ALLOC(int, Cudd_ReadSize(dd));
if (array == NULL) return(0);
lb = l;
cuddRef(lb);
#ifdef DD_DEBUG
cover = Cudd_ReadLogicZero(dd);
cuddRef(cover);
#endif
while (lb != Cudd_ReadLogicZero(dd)) {
DdNode *implicant, *prime, *tmp;
int length;
implicant = Cudd_LargestCube(dd,lb,&length);
if (implicant == NULL) {
Cudd_RecursiveDeref(dd,lb);
FREE(array);
return(0);
}
cuddRef(implicant);
prime = Cudd_bddMakePrime(dd,implicant,u);
if (prime == NULL) {
Cudd_RecursiveDeref(dd,lb);
Cudd_RecursiveDeref(dd,implicant);
FREE(array);
return(0);
}
cuddRef(prime);
Cudd_RecursiveDeref(dd,implicant);
tmp = Cudd_bddAnd(dd,lb,Cudd_Not(prime));
if (tmp == NULL) {
Cudd_RecursiveDeref(dd,lb);
Cudd_RecursiveDeref(dd,prime);
FREE(array);
return(0);
}
cuddRef(tmp);
Cudd_RecursiveDeref(dd,lb);
lb = tmp;
result = Cudd_BddToCubeArray(dd,prime,array);
if (result == 0) {
Cudd_RecursiveDeref(dd,lb);
Cudd_RecursiveDeref(dd,prime);
FREE(array);
return(0);
}
for (q = 0; q < dd->size; q++) {
switch (array[q]) {
case 0:
(void) fprintf(dd->out, "0");
break;
case 1:
(void) fprintf(dd->out, "1");
break;
case 2:
(void) fprintf(dd->out, "-");
break;
default:
(void) fprintf(dd->out, "?");
}
}
(void) fprintf(dd->out, " 1\n");
#ifdef DD_DEBUG
tmp = Cudd_bddOr(dd,prime,cover);
if (tmp == NULL) {
Cudd_RecursiveDeref(dd,cover);
Cudd_RecursiveDeref(dd,lb);
Cudd_RecursiveDeref(dd,prime);
FREE(array);
return(0);
}
cuddRef(tmp);
Cudd_RecursiveDeref(dd,cover);
cover = tmp;
#endif
Cudd_RecursiveDeref(dd,prime);
}
(void) fprintf(dd->out, "\n");
Cudd_RecursiveDeref(dd,lb);
FREE(array);
#ifdef DD_DEBUG
if (!Cudd_bddLeq(dd,cover,u) || !Cudd_bddLeq(dd,l,cover)) {
Cudd_RecursiveDeref(dd,cover);
return(0);
}
Cudd_RecursiveDeref(dd,cover);
#endif
return(1);
} /* end of Cudd_bddPrintCover */
/**Function********************************************************************
Synopsis [Prints to the standard output a DD and its statistics.]
Description [Prints to the standard output a DD and its statistics.
The statistics include the number of nodes, the number of leaves, and
the number of minterms. (The number of minterms is the number of
assignments to the variables that cause the function to be different
from the logical zero (for BDDs) and from the background value (for
ADDs.) The statistics are printed if pr > 0. Specifically:
<ul>
<li> pr = 0 : prints nothing
<li> pr = 1 : prints counts of nodes and minterms
<li> pr = 2 : prints counts + disjoint sum of product
<li> pr = 3 : prints counts + list of nodes
<li> pr > 3 : prints counts + disjoint sum of product + list of nodes
</ul>
For the purpose of counting the number of minterms, the function is
supposed to depend on n variables. Returns 1 if successful; 0 otherwise.]
SideEffects [None]
SeeAlso [Cudd_DagSize Cudd_CountLeaves Cudd_CountMinterm
Cudd_PrintMinterm]
******************************************************************************/
int
Cudd_PrintDebug(
DdManager * dd,
DdNode * f,
int n,
int pr)
{
DdNode *azero, *bzero;
int nodes;
int leaves;
double minterms;
int retval = 1;
if (f == NULL) {
(void) fprintf(dd->out,": is the NULL DD\n");
(void) fflush(dd->out);
return(0);
}
azero = DD_ZERO(dd);
bzero = Cudd_Not(DD_ONE(dd));
if ((f == azero || f == bzero) && pr > 0){
(void) fprintf(dd->out,": is the zero DD\n");
(void) fflush(dd->out);
return(1);
}
if (pr > 0) {
nodes = Cudd_DagSize(f);
if (nodes == CUDD_OUT_OF_MEM) retval = 0;
leaves = Cudd_CountLeaves(f);
if (leaves == CUDD_OUT_OF_MEM) retval = 0;
minterms = Cudd_CountMinterm(dd, f, n);
if (minterms == (double)CUDD_OUT_OF_MEM) retval = 0;
(void) fprintf(dd->out,": %d nodes %d leaves %g minterms\n",
nodes, leaves, minterms);
if (pr > 2) {
if (!cuddP(dd, f)) retval = 0;
}
if (pr == 2 || pr > 3) {
if (!Cudd_PrintMinterm(dd,f)) retval = 0;
(void) fprintf(dd->out,"\n");
}
(void) fflush(dd->out);
}
return(retval);
} /* end of Cudd_PrintDebug */
/**Function********************************************************************
Synopsis [Counts the number of nodes in a DD.]
Description [Counts the number of nodes in a DD. Returns the number
of nodes in the graph rooted at node.]
SideEffects [None]
SeeAlso [Cudd_SharingSize Cudd_PrintDebug]
******************************************************************************/
int
Cudd_DagSize(
DdNode * node)
{
int i;
i = ddDagInt(Cudd_Regular(node));
ddClearFlag(Cudd_Regular(node));
return(i);
} /* end of Cudd_DagSize */
/**Function********************************************************************
Synopsis [Estimates the number of nodes in a cofactor of a DD.]
Description [Estimates the number of nodes in a cofactor of a DD.
Returns an estimate of the number of nodes in a cofactor of
the graph rooted at node with respect to the variable whose index is i.
In case of failure, returns CUDD_OUT_OF_MEM.
This function uses a refinement of the algorithm of Cabodi et al.
(ICCAD96). The refinement allows the procedure to account for part
of the recombination that may occur in the part of the cofactor above
the cofactoring variable. This procedure does no create any new node.
It does keep a small table of results; therefore it may run out of memory.
If this is a concern, one should use Cudd_EstimateCofactorSimple, which
is faster, does not allocate any memory, but is less accurate.]
SideEffects [None]
SeeAlso [Cudd_DagSize Cudd_EstimateCofactorSimple]
******************************************************************************/
int
Cudd_EstimateCofactor(
DdManager *dd /* manager */,
DdNode * f /* function */,
int i /* index of variable */,
int phase /* 1: positive; 0: negative */
)
{
int val;
DdNode *ptr;
st_table *table;
table = st_init_table(st_ptrcmp,st_ptrhash);
if (table == NULL) return(CUDD_OUT_OF_MEM);
val = cuddEstimateCofactor(dd,table,Cudd_Regular(f),i,phase,&ptr);
ddClearFlag(Cudd_Regular(f));
st_free_table(table);
return(val);
} /* end of Cudd_EstimateCofactor */
/**Function********************************************************************
Synopsis [Estimates the number of nodes in a cofactor of a DD.]
Description [Estimates the number of nodes in a cofactor of a DD.
Returns an estimate of the number of nodes in the positive cofactor of
the graph rooted at node with respect to the variable whose index is i.
This procedure implements with minor changes the algorithm of Cabodi et al.
(ICCAD96). It does not allocate any memory, it does not change the
state of the manager, and it is fast. However, it has been observed to
overestimate the size of the cofactor by as much as a factor of 2.]
SideEffects [None]
SeeAlso [Cudd_DagSize]
******************************************************************************/
int
Cudd_EstimateCofactorSimple(
DdNode * node,
int i)
{
int val;
val = cuddEstimateCofactorSimple(Cudd_Regular(node),i);
ddClearFlag(Cudd_Regular(node));
return(val);
} /* end of Cudd_EstimateCofactorSimple */
/**Function********************************************************************
Synopsis [Counts the number of nodes in an array of DDs.]
Description [Counts the number of nodes in an array of DDs. Shared
nodes are counted only once. Returns the total number of nodes.]
SideEffects [None]
SeeAlso [Cudd_DagSize]
******************************************************************************/
int
Cudd_SharingSize(
DdNode ** nodeArray,
int n)
{
int i,j;
i = 0;
for (j = 0; j < n; j++) {
i += ddDagInt(Cudd_Regular(nodeArray[j]));
}
for (j = 0; j < n; j++) {
ddClearFlag(Cudd_Regular(nodeArray[j]));
}
return(i);
} /* end of Cudd_SharingSize */
/**Function********************************************************************
Synopsis [Counts the number of minterms of a DD.]
Description [Counts the number of minterms of a DD. The function is
assumed to depend on nvars variables. The minterm count is
represented as a double, to allow for a larger number of variables.
Returns the number of minterms of the function rooted at node if
successful; (double) CUDD_OUT_OF_MEM otherwise.]
SideEffects [None]
SeeAlso [Cudd_PrintDebug Cudd_CountPath]
******************************************************************************/
double
Cudd_CountMinterm(
DdManager * manager,
DdNode * node,
int nvars)
{
double max;
DdHashTable *table;
double res;
CUDD_VALUE_TYPE epsilon;
background = manager->background;
zero = Cudd_Not(manager->one);
max = pow(2.0,(double)nvars);
table = cuddHashTableInit(manager,1,2);
if (table == NULL) {
return((double)CUDD_OUT_OF_MEM);
}
epsilon = Cudd_ReadEpsilon(manager);
Cudd_SetEpsilon(manager,(CUDD_VALUE_TYPE)0.0);
res = ddCountMintermAux(node,max,table);
cuddHashTableQuit(table);
Cudd_SetEpsilon(manager,epsilon);
return(res);
} /* end of Cudd_CountMinterm */
/**Function********************************************************************
Synopsis [Counts the number of paths of a DD.]
Description [Counts the number of paths of a DD. Paths to all
terminal nodes are counted. The path count is represented as a
double, to allow for a larger number of variables. Returns the
number of paths of the function rooted at node if successful;
(double) CUDD_OUT_OF_MEM otherwise.]
SideEffects [None]
SeeAlso [Cudd_CountMinterm]
******************************************************************************/
double
Cudd_CountPath(
DdNode * node)
{
st_table *table;
double i;
table = st_init_table(st_ptrcmp,st_ptrhash);
if (table == NULL) {
return((double)CUDD_OUT_OF_MEM);
}
i = ddCountPathAux(Cudd_Regular(node),table);
st_foreach(table, cuddStCountfree, NULL);
st_free_table(table);
return(i);
} /* end of Cudd_CountPath */
/**Function********************************************************************
Synopsis [Counts the number of paths to a non-zero terminal of a DD.]
Description [Counts the number of paths to a non-zero terminal of a
DD. The path count is
represented as a double, to allow for a larger number of variables.
Returns the number of paths of the function rooted at node.]
SideEffects [None]
SeeAlso [Cudd_CountMinterm Cudd_CountPath]
******************************************************************************/
double
Cudd_CountPathsToNonZero(
DdNode * node)
{
st_table *table;
double i;
table = st_init_table(st_ptrcmp,st_ptrhash);
if (table == NULL) {
return((double)CUDD_OUT_OF_MEM);
}
i = ddCountPathsToNonZero(node,table);
st_foreach(table, cuddStCountfree, NULL);
st_free_table(table);
return(i);
} /* end of Cudd_CountPathsToNonZero */
/**Function********************************************************************
Synopsis [Finds the variables on which a DD depends.]
Description [Finds the variables on which a DD depends.
Returns a BDD consisting of the product of the variables if
successful; NULL otherwise.]
SideEffects [None]
SeeAlso [Cudd_VectorSupport Cudd_ClassifySupport]
******************************************************************************/
DdNode *
Cudd_Support(
DdManager * dd /* manager */,
DdNode * f /* DD whose support is sought */)
{
int *support;
DdNode *res, *tmp, *var;
int i,j;
int size;
/* Allocate and initialize support array for ddSupportStep. */
size = ddMax(dd->size, dd->sizeZ);
support = ALLOC(int,size);
if (support == NULL) {
dd->errorCode = CUDD_MEMORY_OUT;
return(NULL);
}
for (i = 0; i < size; i++) {
support[i] = 0;
}
/* Compute support and clean up markers. */
ddSupportStep(Cudd_Regular(f),support);
ddClearFlag(Cudd_Regular(f));
/* Transform support from array to cube. */
do {
dd->reordered = 0;
res = DD_ONE(dd);
cuddRef(res);
for (j = size - 1; j >= 0; j--) { /* for each level bottom-up */
i = (j >= dd->size) ? j : dd->invperm[j];
if (support[i] == 1) {
/* The following call to cuddUniqueInter is guaranteed
** not to trigger reordering because the node we look up
** already exists. */
var = cuddUniqueInter(dd,i,dd->one,Cudd_Not(dd->one));
cuddRef(var);
tmp = cuddBddAndRecur(dd,res,var);
if (tmp == NULL) {
Cudd_RecursiveDeref(dd,res);
Cudd_RecursiveDeref(dd,var);
res = NULL;
break;
}
cuddRef(tmp);
Cudd_RecursiveDeref(dd,res);
Cudd_RecursiveDeref(dd,var);
res = tmp;
}
}
} while (dd->reordered == 1);
FREE(support);
if (res != NULL) cuddDeref(res);
return(res);
} /* end of Cudd_Support */
/**Function********************************************************************
Synopsis [Finds the variables on which a DD depends.]
Description [Finds the variables on which a DD depends. Returns an
index array of the variables if successful; NULL otherwise. The
size of the array equals the number of variables in the manager.
Each entry of the array is 1 if the corresponding variable is in the
support of the DD and 0 otherwise.]
SideEffects [None]
SeeAlso [Cudd_Support Cudd_VectorSupport Cudd_ClassifySupport]
******************************************************************************/
int *
Cudd_SupportIndex(
DdManager * dd /* manager */,
DdNode * f /* DD whose support is sought */)
{
int *support;
int i;
int size;
/* Allocate and initialize support array for ddSupportStep. */
size = ddMax(dd->size, dd->sizeZ);
support = ALLOC(int,size);
if (support == NULL) {
dd->errorCode = CUDD_MEMORY_OUT;
return(NULL);
}
for (i = 0; i < size; i++) {
support[i] = 0;
}
/* Compute support and clean up markers. */
ddSupportStep(Cudd_Regular(f),support);
ddClearFlag(Cudd_Regular(f));
return(support);
} /* end of Cudd_SupportIndex */
/**Function********************************************************************
Synopsis [Counts the variables on which a DD depends.]
Description [Counts the variables on which a DD depends.
Returns the number of the variables if successful; CUDD_OUT_OF_MEM
otherwise.]
SideEffects [None]
SeeAlso [Cudd_Support]
******************************************************************************/
int
Cudd_SupportSize(
DdManager * dd /* manager */,
DdNode * f /* DD whose support size is sought */)
{
int *support;
int i;
int size;
int count;
/* Allocate and initialize support array for ddSupportStep. */
size = ddMax(dd->size, dd->sizeZ);
support = ALLOC(int,size);
if (support == NULL) {
dd->errorCode = CUDD_MEMORY_OUT;
return(CUDD_OUT_OF_MEM);
}
for (i = 0; i < size; i++) {
support[i] = 0;
}
/* Compute support and clean up markers. */
ddSupportStep(Cudd_Regular(f),support);
ddClearFlag(Cudd_Regular(f));
/* Count support variables. */
count = 0;
for (i = 0; i < size; i++) {
if (support[i] == 1) count++;
}
FREE(support);
return(count);
} /* end of Cudd_SupportSize */
/**Function********************************************************************
Synopsis [Finds the variables on which a set of DDs depends.]
Description [Finds the variables on which a set of DDs depends.
The set must contain either BDDs and ADDs, or ZDDs.
Returns a BDD consisting of the product of the variables if
successful; NULL otherwise.]
SideEffects [None]
SeeAlso [Cudd_Support Cudd_ClassifySupport]
******************************************************************************/
DdNode *
Cudd_VectorSupport(
DdManager * dd /* manager */,
DdNode ** F /* array of DDs whose support is sought */,
int n /* size of the array */)
{
int *support;
DdNode *res, *tmp, *var;
int i,j;
int size;
/* Allocate and initialize support array for ddSupportStep. */
size = ddMax(dd->size, dd->sizeZ);
support = ALLOC(int,size);
if (support == NULL) {
dd->errorCode = CUDD_MEMORY_OUT;
return(NULL);
}
for (i = 0; i < size; i++) {
support[i] = 0;
}
/* Compute support and clean up markers. */
for (i = 0; i < n; i++) {
ddSupportStep(Cudd_Regular(F[i]),support);
}
for (i = 0; i < n; i++) {
ddClearFlag(Cudd_Regular(F[i]));
}
/* Transform support from array to cube. */
res = DD_ONE(dd);
cuddRef(res);
for (j = size - 1; j >= 0; j--) { /* for each level bottom-up */
i = (j >= dd->size) ? j : dd->invperm[j];
if (support[i] == 1) {
var = cuddUniqueInter(dd,i,dd->one,Cudd_Not(dd->one));
cuddRef(var);
tmp = Cudd_bddAnd(dd,res,var);
if (tmp == NULL) {
Cudd_RecursiveDeref(dd,res);
Cudd_RecursiveDeref(dd,var);
FREE(support);
return(NULL);
}
cuddRef(tmp);
Cudd_RecursiveDeref(dd,res);
Cudd_RecursiveDeref(dd,var);
res = tmp;
}
}
FREE(support);
cuddDeref(res);
return(res);
} /* end of Cudd_VectorSupport */
/**Function********************************************************************
Synopsis [Finds the variables on which a set of DDs depends.]
Description [Finds the variables on which a set of DDs depends.
The set must contain either BDDs and ADDs, or ZDDs.
Returns an index array of the variables if successful; NULL otherwise.]
SideEffects [None]
SeeAlso [Cudd_SupportIndex Cudd_VectorSupport Cudd_ClassifySupport]
******************************************************************************/
int *
Cudd_VectorSupportIndex(
DdManager * dd /* manager */,
DdNode ** F /* array of DDs whose support is sought */,
int n /* size of the array */)
{
int *support;
int i;
int size;
/* Allocate and initialize support array for ddSupportStep. */
size = ddMax(dd->size, dd->sizeZ);
support = ALLOC(int,size);
if (support == NULL) {
dd->errorCode = CUDD_MEMORY_OUT;
return(NULL);
}
for (i = 0; i < size; i++) {
support[i] = 0;
}
/* Compute support and clean up markers. */
for (i = 0; i < n; i++) {
ddSupportStep(Cudd_Regular(F[i]),support);
}
for (i = 0; i < n; i++) {
ddClearFlag(Cudd_Regular(F[i]));
}
return(support);
} /* end of Cudd_VectorSupportIndex */
/**Function********************************************************************
Synopsis [Counts the variables on which a set of DDs depends.]
Description [Counts the variables on which a set of DDs depends.
The set must contain either BDDs and ADDs, or ZDDs.
Returns the number of the variables if successful; CUDD_OUT_OF_MEM
otherwise.]
SideEffects [None]
SeeAlso [Cudd_VectorSupport Cudd_SupportSize]
******************************************************************************/
int
Cudd_VectorSupportSize(
DdManager * dd /* manager */,
DdNode ** F /* array of DDs whose support is sought */,
int n /* size of the array */)
{
int *support;
int i;
int size;
int count;
/* Allocate and initialize support array for ddSupportStep. */
size = ddMax(dd->size, dd->sizeZ);
support = ALLOC(int,size);
if (support == NULL) {
dd->errorCode = CUDD_MEMORY_OUT;
return(CUDD_OUT_OF_MEM);
}
for (i = 0; i < size; i++) {
support[i] = 0;
}
/* Compute support and clean up markers. */
for (i = 0; i < n; i++) {
ddSupportStep(Cudd_Regular(F[i]),support);
}
for (i = 0; i < n; i++) {
ddClearFlag(Cudd_Regular(F[i]));
}
/* Count vriables in support. */
count = 0;
for (i = 0; i < size; i++) {