@@ -4,12 +4,13 @@ bool BDD_node::operator==(const BDD_node &rhs) const
4
4
{
5
5
return this ->var == rhs.var && this ->low == rhs.low && this ->high == rhs.high ;
6
6
}
7
- ROBDD::ROBDD ()
7
+ ROBDD::ROBDD (bool order_by_ascii )
8
8
{
9
9
this ->zero = new BDD_node ({0 , nullptr , nullptr });
10
10
this ->one = new BDD_node ({1 , nullptr , nullptr });
11
11
this ->node_table [*(this ->zero )] = this ->zero ;
12
12
this ->node_table [*(this ->one )] = this ->one ;
13
+ this ->order_by_ascii = order_by_ascii;
13
14
}
14
15
15
16
BDD_node *ROBDD::get_one () const
@@ -29,7 +30,11 @@ unsigned int ROBDD::get_ID(std::string var)
29
30
{
30
31
// new var
31
32
if (this ->var_to_ID .find (var) == this ->var_to_ID .end ())
32
- this ->var_to_ID [var] = avail_ID++;
33
+ {
34
+ this ->var_to_ID [var] = avail_ID;
35
+ this ->ID_to_var [avail_ID] = var;
36
+ avail_ID++;
37
+ }
33
38
return this ->var_to_ID [var];
34
39
}
35
40
@@ -94,6 +99,10 @@ BDD_node *ROBDD::apply(binary_op op, BDD_node *left, BDD_node *right)
94
99
95
100
BDD_node *ROBDD::_apply (binary_op op, BDD_node *left, BDD_node *right)
96
101
{
102
+ auto less = [&](BDD_node *lhs, BDD_node *rhs)
103
+ {
104
+ return this ->order_by_ascii ? this ->ID_to_var [lhs->var ] < this ->ID_to_var [rhs->var ] : lhs->var < rhs->var ;
105
+ };
97
106
auto found = this ->apply_table [op].find (std::pair<BDD_node *, BDD_node *>(left, right));
98
107
BDD_node *res;
99
108
if (found != this ->apply_table [op].end ())
@@ -106,13 +115,13 @@ BDD_node *ROBDD::_apply(binary_op op, BDD_node *left, BDD_node *right)
106
115
auto r = this ->_apply (op, left->high , right->high );
107
116
res = this ->make_node (left->var , l, r);
108
117
}
109
- else if ((left-> var < right-> var and left->var > 1 ) or right->var <= 1 ) // unfold left BDD tree
118
+ else if ((less ( left, right) and left->var > 1 ) or right->var <= 1 ) // unfold left BDD tree
110
119
{
111
120
auto l = this ->_apply (op, left->low , right);
112
121
auto r = this ->_apply (op, left->high , right);
113
122
res = this ->make_node (left->var , l, r);
114
123
}
115
- else if ((left-> var > right-> var and right-> var > 1 ) or left-> var <= 1 ) // unfold right BDD tree
124
+ else // unfold right BDD tree
116
125
{
117
126
auto l = this ->_apply (op, left, right->low );
118
127
auto r = this ->_apply (op, left, right->high );
@@ -165,8 +174,6 @@ void ROBDD::output(std::ofstream &out)
165
174
this ->printed [this ->zero ] = 0 ;
166
175
this ->printed [this ->one ] = 1 ;
167
176
this ->uuid = 2 ;
168
- for (auto it : this ->var_to_ID )
169
- this ->ID_to_var [it.second ] = it.first ;
170
177
out << " digraph ROBDD {\n "
171
178
<< " fontname=\" Helvetica,Arial,sans-serif\"\n "
172
179
<< " node [fontname=\" Helvetica,Arial,sans-serif\" ]\n "
0 commit comments