00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef APRIORI_H
00010 #define APRIORI_H
00011
00012 #include "Trie.hpp"
00013 #include "Trie_hash.hpp"
00014 #include <map>
00015
00016
00021
00022 struct itemsetLess: public binary_function<const vector<itemtype>& , const vector<itemtype>&, bool>
00023 {
00024 bool operator()( const vector<itemtype>& basket_1, const vector<itemtype>& basket_2 ) const
00025 {
00026 itemtype item_index_1 = 0,
00027 item_index_2 = 0;
00028 while( item_index_1<basket_1.size() && item_index_2 < basket_2.size() )
00029 if( basket_1[item_index_1] < basket_2[item_index_2] ) return true;
00030 else if( basket_1[item_index_1] > basket_2[item_index_2] ) return false;
00031 else
00032 {
00033 item_index_1++;
00034 item_index_2++;
00035 }
00036 if( item_index_1 == basket_1.size() && item_index_2 < basket_2.size() ) return true;
00037 else return false;
00038 }
00039 };
00040
00090 class Apriori {
00091 public:
00092 Apriori( const bool& store_input, const int& trie_type=1, const int& child_threshold = 5 );
00093
00095 void APRIORI_alg( ofstream& outcomefile, const char* basket_filename, const double& min_supp, const double& min_conf );
00096
00097 private:
00098
00100 void read_in_a_line( FILE* filepoint );
00102 void support( FILE* filepoint, const itemtype& candidate_size );
00103
00104 Trie* trie;
00105 vector<itemtype> basket;
00106 unsigned long basket_number;
00107 map<vector<itemtype>, unsigned long, itemsetLess> reduced_baskets;
00108 bool store_input;
00109 };
00110
00111 #endif