Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

trie/trie_manipulators/sequence/SimplePruner.hpp

Go to the documentation of this file.
00001 #ifndef SimplePruner_HPP
00002 #define SimplePruner_HPP
00003 
00004 #include "common.hpp"
00005 #include "common/Edge.hpp"
00006 #include "apriori/bodon/trie/trie_manipulators/ManipulatorBase.hpp"
00007 #include <vector>
00008 //#include <cstdio>
00009 //#include <iterator>   //for test
00010 
00011 
00012 
00013 
00014 namespace Bodon
00015 {
00016 namespace sequence
00017 {
00018    template <class DF_D, class TRIE>
00019    class SimplePruner : public ManipulatorBase<DF_D, TRIE>
00020    {
00021       protected:
00022          std::vector<Edge> extenders;
00023 
00024       public:
00025          SimplePruner( TRIE& main_trie, DF_D& df_decoder ) : 
00026             ManipulatorBase<DF_D, TRIE>(main_trie, df_decoder){}
00027 
00028 
00029       protected:
00031          int isAllSubsetFrequent( std::vector<item_t>& maybe_candidate, 
00032                                   const item_t new_item ) const;
00033 
00034 
00035          void generateCandidateAtParent( 
00036             TRIE* trie, std::vector<item_t>& maybe_candidate );
00037    };
00038 
00039 
00040    template <class DF_D, class TRIE> inline int 
00041    SimplePruner<DF_D, TRIE>::isAllSubsetFrequent( 
00042       std::vector<item_t>& generator, const item_t new_item ) const
00043    {
00044       assert(generator.size() > 1);
00045       std::vector<item_t>::iterator item_it = generator.end()-2;
00046       register item_t deleted_item = *item_it, temp_item;
00047       const TRIE* temp_trie;
00048 
00049       generator.erase( item_it );
00050       temp_trie = main_trie.isIncluded( generator, generator.begin() );
00051       if( temp_trie)
00052       { 
00053          if( !temp_trie->edgelist.find(new_item) )
00054          {
00055             generator.insert( item_it, deleted_item );
00056             return 0;
00057          }
00058       }
00059       else
00060       {
00061          generator.insert( item_it, deleted_item );
00062          return 0;
00063       }
00064       while(item_it != generator.begin())
00065       {
00066          --item_it;
00067          temp_item = *item_it;
00068          *item_it = deleted_item;
00069          deleted_item = temp_item;
00070          temp_trie = main_trie.isIncluded( generator, generator.begin() );      
00071          if( temp_trie)
00072          { 
00073             if( !temp_trie->edgelist.find(new_item) )
00074             {
00075                generator.insert( item_it, deleted_item );
00076                return 0;
00077             }
00078          }
00079          else
00080          {
00081             generator.insert( item_it, deleted_item );
00082             return 0;
00083          }
00084       }
00085       generator.insert( item_it, deleted_item );
00086       return 1;
00087    }
00088 
00089 
00090    template <class DF_D, class TRIE> inline void 
00091    SimplePruner<DF_D, TRIE>::
00092    generateCandidateAtParent(TRIE* trie, std::vector<item_t>& maybe_candidate)
00093    {
00094       typename TRIE::iterator itEdge( trie->edgelist.begin() ), itEdge2;
00095       TRIE* toExtend;
00096       while( itEdge != trie->edgelist.end() )
00097       {
00098          toExtend = static_cast<TRIE*>((*itEdge).second);
00099          df_decoder.pushItemWithWrite( (*itEdge).first, toExtend->getCounter() );
00100          df_decoder.popItem();
00101          maybe_candidate.push_back((*itEdge).first);
00102          extenders.clear();
00103          for( itEdge2 = trie->edgelist.begin(); itEdge2 != trie->edgelist.end(); ++itEdge2 )
00104          {
00105             if( isAllSubsetFrequent( maybe_candidate, (*itEdge2).first ) == 1 )
00106                extenders.push_back(Edge((*itEdge2).first, new TRIE(0)));
00107          }
00108          maybe_candidate.pop_back();
00109          toExtend->edgelist.insert(extenders);
00110          ++itEdge;
00111       }
00112    }
00113 }
00114 }
00115 #endif

Generated on Sun Sep 17 17:50:40 2006 for FIM environment by  doxygen 1.4.4