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