-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
118 lines (105 loc) · 2.22 KB
/
main.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// main.cpp
#include "Quine_McCluskey.h"
#include "Petrick_Method.h"
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <set>
using namespace std;
void Init(ifstream &,Quine_McCluskey &);
void Output(ofstream &,Quine_McCluskey &,Petrick_Method &);
int main(int argc, char *argv[])
{
if( argc!=3 ) {
cerr<<"Wrong number of arguments. Please execute as follow : \n"
<<"./hw1.o <input_file name> <output_file name>"<< endl;
exit(-1);
}
ifstream fin( argv[1] );
ofstream fout( argv[2] );
cout<<"\n***** Quine-McCluskey Algorithm *****"<< endl;
Quine_McCluskey QM;
Init( fin , QM );
QM.Solve();
QM.Print_Prime_Impli();
cout<<"\n***** Petrick's Method *****"<< endl;
Petrick_Method PM( QM.Get_Prime_Impli() , QM.Get_On_Set() );
PM.Solve();
PM.Print_POS();
// PM.Print_SOP();
cout<<"\n***** All possible fewest-terms results *****"<< endl;
PM.Print_FewestTerm_P();
cout<<"\n***** Final Answer *****"<< endl;
Output( fout , QM , PM );
fin.close();
fout.close();
return 0;
}
/* input format example
* .i 4 ( the function f has 4 input variables: A,B,C,D )
* .m ( on set )
* 4 5 6 8 9 10 13
* .d ( don't care set )
* 0 7 15
*/
void Init(ifstream &fin, Quine_McCluskey &QM) {
// input from a file
char c;
while( fin>> c ) {
if( c=='.' )
continue;
if( c=='i' ) {
int n;
fin>> n ;
QM.Set_Num_Var(n);
}
else if( c=='m' ) {
string s;
stringstream ss;
getline( fin , s );
getline( fin , s );
ss<< s ;
int n;
while( ss>> n )
QM.Add_On_Set(n);
}
else if( c=='d' ) {
string s;
stringstream ss;
getline( fin , s );
getline( fin , s );
ss<< s ;
int n;
while( ss>> n )
QM.Add_DC_Set(n);
}
else {
cerr<<"Wrong input format."<< endl;
exit(-1);
}
}
}
/* output format example
* .pi 7 ( there are 7 prime implicants )
* 0-00
* -000
* 100-
* 10-0
* 01--
* 1-01
* -1-1
* .mc 3 ( 3 prime implicants in minimum covering )
* 10-0
* 1-01
* 01--
* cost=8
*/
void Output(ofstream &fout, Quine_McCluskey &QM, Petrick_Method &PM) {
QM.HW1_Print_Prime_Impli();
QM.HW1_Print_Prime_Impli(fout);
PM.HW1_Print_Minimum_Cover();
PM.HW1_Print_Minimum_Cover(fout);
cout<< endl;
}