-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
61 lines (56 loc) · 1.63 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
#include "Apriori.h"
#include "Eclat.h"
#include <iostream>
#include <fstream>
#include <cstring>
#include <bitset>
#include <vector>
#include <ctime>
using namespace std;
using std::bitset;
int main() {
ifstream fin("data.txt");
string str;
bitset<100> data[3500];
int data_index = 0;
while(getline(fin, str)) {
vector<int> nums;
int last_pos = 0;
for(int i = 0; i < str.length(); i ++) {
if(str[i] == ' ') {
string s = str.substr(last_pos, i - last_pos);
int num = 0;
if(s.length() == 1) {
num = s[0] - '0';
}
else {
num = (s[0] - '0') * 10 + (s[1] - '0');
}
nums.push_back(num);
last_pos = i + 1;
}
}
for(int i = 0; i < nums.size(); i ++) {
data[data_index].set(nums[i]);
}
data_index ++;
}
printf("Transaction read done\n");
double min_sup = 0;
scanf("%lf", &min_sup);
clock_t start = clock();
Eclat *my_Eclat = new Eclat(data, data_index, min_sup);
printf("Eclat Algorithm: \n");
my_Eclat -> getResult();
clock_t end = clock();
double time_spend = (double)(end - start)/(double)(CLOCKS_PER_SEC);
printf("time spend: %.4lf\n", time_spend);
start = clock();
Apriori *my_Apriori = new Apriori(data, data_index, min_sup);
printf("Apriori Algorithm: \n");
my_Apriori -> getResult();
end = clock();
time_spend = (double)(end - start)/(double)(CLOCKS_PER_SEC);
printf("time spend: %.4lf\n", time_spend);
return 0;
}