Reading in boolean function from a txt

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):
ABcD+ABCD+aBcD+aBCD.
A 0.2
B 0.4
C 0.6
D 0.8


Here's my code so far:
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
#include <bits/stdc++.h> 
#include <iostream>
#include <fstream>
#include <string>
#include <sstream> 

using namespace 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!
Last edited on
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.
Topic archived. No new replies allowed.