-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMiner.hpp
75 lines (73 loc) · 1.9 KB
/
Miner.hpp
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
#include <stdio.h>
#include <vector>
#include <map>
#include "MTree.hpp"
using namespace std;
class Miner
{
protected:
clock_t miner_begin;
TransactionDB* DB;
int threshold = 1;
vector<Itemset*> result;
public:
bool verbose = false;
Miner(){}
Miner(TransactionDB* _db, int _threshold) : DB(_db), threshold(_threshold) {}
Miner(TransactionDB* _db, float _ratio) : DB(_db), threshold(_ratio * _db->size()) {}
virtual ~Miner()
{
for (vector<Itemset*>::iterator i = result.begin(); i != result.end(); i++)
{
delete *i;
}
}
void print_result()
{
for (vector<Itemset*>::iterator i = result.begin(); i != result.end(); i++)
{
(*i)->print_self();
}
}
void write_result(ofstream & output)
{
for (vector<Itemset*>::iterator i = result.begin(); i != result.end(); i++)
{
(*i)->write_self(output);
}
}
virtual void mine()
{
result.clear();
miner_begin = clock();
}
int result_size()
{
return int(result.size());
}
float elapsed_time()
{
return float(clock() - miner_begin)/CLOCKS_PER_SEC;
}
bool check_threshold(bool frequent) const
{
bool valid = true;
for (vector<Itemset*>::const_iterator i = result.begin(); i != result.end(); i++)
{
if ((frequent && (*i)->support < threshold) || (!frequent && (*i)->support >= threshold))
{
valid = false;
printf("threshold %d | ", threshold);
(*i)->print_self();
}
}
return valid;
}
bool check_basic() const
{
printf("Miner done. result num: %ld\nEnter any key to validate result...\n", result.size());
cin.get();
return DB->validate(result);
}
virtual bool check() const {return false;}
};