-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerminate_Complement.cpp
104 lines (83 loc) · 2.48 KB
/
Terminate_Complement.cpp
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
94
95
96
97
98
99
100
101
102
103
104
using std::cout;
using std::cin;
using std::endl;
using std::vector;
#define Positive 1
#define Negative 2
#define DC 3
#define Zero 0
#define Vec_2D vector<vector<int>>
Vec_2D Terminate_Complement(Vec_2D Pol_Term_i, int Size, int No){
Vec_2D Pol_Term_Comp;
int cube_Zero = 0;//For a cube that has a 00 in it
int cube_One = 0;//Checks if there are all 11 or all don't care cubes
//TERMINATION CONDITION - 1(If the whole Cubelist F doesn't exist)
for(int i = 0; i < No; i++){
for (int j = 0; j < Size; j++){
if(Pol_Term_i[i][j] == Zero){
j += Size;
cube_Zero++;
}
}
}
if(cube_Zero == No){
vector<int> Variables;
for (int i = 0; i<Size; i++){
Variables.push_back(DC);
}
Pol_Term_Comp.push_back(Variables);
}
//TERMINATION CONDITION - 2(If F has a [11 11 11 11] or All Don't Care cube)
for(int i = 0; i < No; i++){
cube_One = 0;
for (int j = 0; j < Size; j++){
if(Pol_Term_i[i][j] == DC){
cube_One++;
}
}
}
if(cube_One == Size){
vector<int> Variables;
for (int i = 0; i<Size; i++){
Variables.push_back(Zero);
}
Pol_Term_Comp.push_back(Variables);
}
//TERMINATION CONDITION - 3(If F has only one cube, can complement using De Morgan's Laws)
if(No == 1){
for(int i = 0; i < No; i++){
cube_One = 0;
for (int j = 0; j < Size; j++){
if(Pol_Term_i[i][j] == Positive){
vector<int> Variables;
for (int k = 0; k<Size; k++){
if(k == j)
{
Variables.push_back(Negative);
}
else
{
Variables.push_back(DC);
}
}
Pol_Term_Comp.push_back(Variables);
}
if(Pol_Term_i[i][j] == Negative){
vector<int> Variables;
for (int k = 0; k<Size; k++){
if(k == j)
{
Variables.push_back(Positive);
}
else
{
Variables.push_back(DC);
}
}
Pol_Term_Comp.push_back(Variables);
}
}
}
}
return Pol_Term_Comp;
}