00001 #ifndef CandidateGeneratorSimplePrune_HPP
00002 #define CandidateGeneratorSimplePrune_HPP
00003
00004 #include "apriori/bodon-vector/vector_typedef.hpp"
00005 #include "common/log.h"
00006
00007
00008
00009
00010
00011
00012 bool lessItemvector( const itemvecCounterPair& elem1,
00013 const itemvecCounterPair& elem2 )
00014 {
00015 return elem1.first < elem2.first;
00016 }
00017
00018 namespace Bodon
00019 {
00020 namespace vector_based
00021 {
00022 template <class D, class DUMMY>
00023 class CandidateGeneratorSimplePrune
00024 {
00025 protected:
00026 cand_vector_t& candidates;
00027 public:
00028 CandidateGeneratorSimplePrune<D, DUMMY>
00029 ( cand_vector_t& candidates, D& decoder, DUMMY& dummy) :
00030 candidates(candidates){}
00031
00032
00038 void generateCandidate(unsigned int candidate_size);
00039
00040 void afterWorkCandGen(){}
00041
00042 bool isThereAnyCandidate()
00043 {
00044 return !candidates.empty();
00045 }
00046 };
00047
00048
00049 template <class D, class DUMMY> inline
00050 void CandidateGeneratorSimplePrune<D, DUMMY>::
00051 generateCandidate(const unsigned int candidate_size)
00052 {
00053 if(!candidates.empty())
00054 {
00055 cand_vector_t::size_type orig_size(candidates.size());
00056 itemvector new_candidate;
00057 cand_vector_t::size_type index=0, index2;
00058 for(;index < orig_size -1; ++index)
00059 {
00060 new_candidate.clear();
00061 new_candidate.insert(new_candidate.end(),
00062 candidates[index].first.begin(),
00063 candidates[index].first.end());
00064 index2 = index +1;
00065 while(index2 < orig_size &&
00066 candidates[index].first.haveSamePrefix(candidates[index2].first))
00067 {
00068 new_candidate.push_back(candidates[index2].first.back());
00069
00070
00071
00072
00073
00074
00075 bool isAllSubsetFrequent = true;
00076 std::vector<item_t>::iterator item_it = new_candidate.end()-1;
00077 register item_t deleted_item = *item_it, temp_item;
00078 new_candidate.erase(item_it);
00079 while (isAllSubsetFrequent && item_it != new_candidate.begin())
00080 {
00081
00082
00083
00084
00085 if (!std::binary_search(
00086 candidates.begin(),
00087 candidates.begin()+orig_size,
00088
00089 itemvecCounterPair(new_candidate, 0)
00090 ,::lessItemvector
00091 )
00092 )
00093
00094
00095
00096
00097 {
00098 isAllSubsetFrequent = false;
00099 }
00100 else
00101 {
00102 --item_it;
00103 temp_item = *item_it;
00104 *item_it = deleted_item;
00105 deleted_item = temp_item;
00106 }
00107 }
00108 new_candidate.insert(item_it, deleted_item);
00109 if (isAllSubsetFrequent)
00110
00111
00112 {
00113 candidates.push_back(
00114 itemvecCounterPair(new_candidate, 0));
00115 }
00116 new_candidate.pop_back();
00117 ++index2;
00118 }
00119 }
00120 candidates.erase(candidates.begin(), candidates.begin()+orig_size);
00121 }
00122 }
00123 }
00124 }
00125 #endif