Reading in boolean function from a txt

Hi, I'm working on a project which needs to calculate the signal probability of a boolean function in the sum-of-product form.
In addition, the boolean function need to be implemented in Binary-Decision-Diagram. In this project, I'm using the CUDD package.
Below is the input data txt file.
ABcD+ABCD+aBcD+aBCD.
A 0.2
B 0.4
C 0.6
D 0.8

The lowercase character represents a plain variable, whereas its uppercase is for its complement. And the number is the probability.

And here is 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
#include <bits/stdc++.h> 
#include <iostream>
#include <fstream>
#include <string>
#include <sstream> 

using namespace std; 

struct variable
{
	// 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;
	
	
	// 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("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.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();
	}
	
	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 probability is " << var_list[i].prob << endl;
		cout << "Its probability of its complement is " << var_list[i].prob_not << endl;
		cout << endl;
	}

	
	
	
return 0;
}


I'm still studying the CUDD package and each function in it.
I'm wondering how to deal with the boolean function string read in to make it correspond to the function in CUDD package.
Thanks in advance!!
Last edited on
What was wrong with the answers @againtry gave you in your other (identical) thread?
http://www.cplusplus.com/forum/beginner/278111/#msg1200533
Last edited on
Topic archived. No new replies allowed.