-
Notifications
You must be signed in to change notification settings - Fork 0
/
bryantPrint.c
64 lines (55 loc) · 1.53 KB
/
bryantPrint.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
#include <stdio.h>
#include <stdlib.h>
#include "bryantPrint.h"
#include "bryant.h"
#include "var.h"
int print_bryant(FILE *stream, node *f, bitset *trues, bitset *falses,
int terms);
/* Print out an ROBDD in some readable format. We display it in disjunctive
* form.
*/
void printOut(FILE *stream, node *f)
{
bitset trues, falses;
if (f == one) {
fprintf(stream, "TRUE");
} else if (f == zero) {
fprintf(stream, "FALSE");
} else {
BITSET_CLEAR(trues);
BITSET_CLEAR(falses);
(void)print_bryant(stream, f, &trues, &falses, 0);
}
}
int print_bryant(FILE *stream, node *f,
bitset *trues, bitset *falses, int terms)
{
if (f == one) {
bitset all;
int var;
int word;
bitmask mask;
char sep = '(';
if (terms>0) fprintf(stream, " ");
BITSET_UNION(all, *trues, *falses);
FOREACH_ELEMENT(all, var, word, mask) {
if (BITSET_MEMBER(*trues, word, mask)) {
fprintf(stream, "%c%d", sep, var-VAR_SHIFT);
} else {
fprintf(stream, "%c~%d", sep, var-VAR_SHIFT);
}
sep = ' ';
}
fprintf(stream, ")");
++terms;
} else if (f != zero) {
BITSET_ADD_ELEMENT(*trues, f->value);
terms += print_bryant(stream, f->tr, trues, falses, terms);
BITSET_TOGGLE_ELEMENT(*trues, f->value);
BITSET_ADD_ELEMENT(*falses, f->value);
terms += print_bryant(stream, f->fa, trues, falses, terms);
BITSET_TOGGLE_ELEMENT(*falses, f->value);
}
/* don't do anything for zero terminal */
return terms;
}