Hi, I'm working on a project that converts a Boolean function into a Binary-Decision-Diagram(BDD) using the CUDD package.
Here's a simple example showing how the functions works:
1 2 3 4 5 6 7 8 9 10 11
// Top=a(b+c+de)
int main()
{
Cudd mgr(0, 0);
BDD a = mgr.bddVar();
BDD b = mgr.bddVar();
BDD c = mgr.bddVar();
BDD d = mgr.bddVar();
BDD e = mgr.bddVar();
BDD top = a*(b + c + d*e);
}
And my question is how should I construct the BDD using these functions after reading a Boolean function from a .txt file as below(upper-case stands for the variable's complement):
#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
usingnamespace std;
struct variable
{
// The index of the variable
int index;
// The name of the variable
char name;
// Probability of the variable and its complement
float prob, prob_not;
};
int main()
{
ifstream infile;
ofstream outfile;
stringstream ss;
string line;
string boolfunction;
char var_name;
float var_prob;
int count = 0;
// Construct a vector(list) which every element is a variable
// which stores its name and probabilities
vector<variable> var_list;
// Open boolean function and variables prob. file
//infile.open(argv[1], ios::in);
infile.open("testcase/input1.txt", ios::in);
if(!infile.is_open())
{
cout << "Failed to open file!" << endl;
exit(1);
}
infile >> boolfunction;
while(getline(infile, line))
{
ss << line;
while(ss >> var_name >> var_prob)
{
variable var;
if(isupper(var_name))
{
var.index = count-1;
var.name = tolower(var_name);
var.prob = 1 - var_prob;
var.prob_not = var_prob;
var_list.push_back(var);
}
else
{
var.name = var_name;
var.prob = var_prob;
var.prob_not = 1 - var_prob;
var_list.push_back(var);
}
}
ss.str("");
ss.clear();
count++;
}
cout << "The boolean function is : " << boolfunction << endl;
cout << "There are " << var_list.size() << " variables in total " << endl;
for(int i=0; i < var_list.size(); i++)
{
cout << "Variable " << var_list[i].name << " : " << endl;
cout << "Its index is " << var_list[i].index << endl;
cout << "Its probability is " << var_list[i].prob << endl;
cout << "Its probability of its complement is " << var_list[i].prob_not << endl;
cout << endl;
}
return 0;
}
After getting my variable vector list, how should I deal with the read in Boolean function and construct a BDD using the above CUDD functions like a while or for loop w/o specifying 5 lines of mgr.bddVar();
Thx in advance!
This is the third time I've seen this post. Different title, but same code and everything.
Don't double-post; it won't help you get better answers. If the previous answers didn't work for you, post back on that thread, and we will try to help.