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

trie/trie_manipulators/sequence/CandidateGeneratorNoprune.hpp

Go to the documentation of this file.
00001 #ifndef CandidateGeneratorNoprune_HPP
00002 #define CandidateGeneratorNoprune_HPP
00003 
00004 #include "common.hpp"
00005 #include "common/Edge.hpp"
00006 #include "common/log.h"
00007 #include "apriori/bodon/trie/trie_manipulators/ManipulatorBase.hpp"
00008 #include <vector>
00009 //#include <cstdio>
00010 //#include <iterator>   //for test
00011 
00012 
00013 
00014 
00015 namespace Bodon
00016 {
00017 namespace sequence
00018 {
00019    template <class DF_D, class TRIE>
00020    class CandidateGeneratorNoprune : public ManipulatorBase<DF_D, TRIE>
00021    {
00022       protected:
00023          std::vector<Edge> extenders;
00024          unsigned int nr_of_new_candidates;
00025          unsigned int nr_of_all_candidates;
00026 
00027       public:
00028          CandidateGeneratorNoprune( TRIE& main_trie, DF_D& df_decoder ) : 
00029             ManipulatorBase<DF_D, TRIE>(main_trie, df_decoder),
00030             nr_of_all_candidates(0){}
00031 
00032 
00038          void generateCandidate(unsigned int candidate_size);
00039          
00040          void afterWorkCandGen();
00041       protected:
00042 
00043          void generateCandidateAtParent( TRIE* trie );
00045          void generateCandidateFindParent( 
00046             TRIE* trie, unsigned int step_to_freq_par);
00047 
00048       public:
00049          // No public members
00050    };
00051 
00052 
00053    template <class DF_D, class TRIE> 
00054    void CandidateGeneratorNoprune<DF_D, TRIE>::
00055    generateCandidate(unsigned int candidate_size)
00056    {
00057       assert(candidate_size > 1);
00058       nr_of_new_candidates = 0;
00059       generateCandidateFindParent( &main_trie,
00060                                    candidate_size -2 );
00061       log_debug(0, "Number of newly generated candidates: %d", nr_of_new_candidates);
00062 #if DEBUG_LEVEL >= LEVEL_DBG
00063       nr_of_all_candidates += nr_of_new_candidates;
00064 #endif
00065    }
00066    template <class DF_D, class TRIE> 
00067    void CandidateGeneratorNoprune<DF_D, TRIE>::
00068    afterWorkCandGen()
00069    {
00070       log_dbg(0, "The total number of generated candidates: %d", nr_of_all_candidates);
00071    }
00072 
00073 
00074    template <class DF_D, class TRIE> inline void 
00075    CandidateGeneratorNoprune<DF_D, TRIE>::
00076    generateCandidateAtParent(TRIE* trie)
00077    {
00078       typename TRIE::iterator itEdge( trie->edgelist.begin() ), itEdge2;
00079       TRIE* toExtend;
00080       while( itEdge != trie->edgelist.end() )
00081       {
00082          toExtend = static_cast<TRIE*>((*itEdge).second);
00083          df_decoder.pushItemWithWrite( (*itEdge).first, 
00084                                        toExtend->getCounter() );
00085          df_decoder.popItem();
00086          extenders.clear();
00087          for( itEdge2 = trie->edgelist.begin(); 
00088               itEdge2 != trie->edgelist.end(); ++itEdge2 )
00089             extenders.push_back(Edge((*itEdge2).first, new TRIE(0)));
00090          if(extenders.empty())
00091          {
00092             delete toExtend;
00093             itEdge = trie->edgelist.erase(itEdge);
00094          }
00095          else 
00096          {
00097             toExtend->edgelist.insert(extenders);
00098             ++itEdge;
00099          }
00100       }
00101    }
00102 
00103 
00104    template <class DF_D, class TRIE> void
00105    CandidateGeneratorNoprune<DF_D, TRIE>::
00106    generateCandidateFindParent( TRIE* trie, 
00107                                 unsigned int step_to_freq_par)
00108    {
00109       typename TRIE::iterator itEdge( trie->edgelist.begin() );
00110       if(step_to_freq_par)
00111       {
00112          --step_to_freq_par;
00113          while( itEdge != trie->edgelist.end() )
00114          {
00115             df_decoder.pushItem( (*itEdge).first );
00116             generateCandidateFindParent( 
00117                static_cast<TRIE*>((*itEdge).second), step_to_freq_par);
00118             if(static_cast<TRIE*>((*itEdge).second)->edgelist.empty())
00119             {
00120                delete static_cast<TRIE*>((*itEdge).second);
00121                itEdge = trie->edgelist.erase(itEdge);
00122             }
00123             else ++itEdge;
00124             df_decoder.popItem();
00125          }
00126       }
00127       else
00128       {
00129          generateCandidateAtParent(trie);
00130 #if DEBUG_LEVEL >= LEVEL_DBG
00131          for( typename TRIE::iterator it( trie->edgelist.begin() );
00132               it != trie->edgelist.end(); ++it)
00133             nr_of_new_candidates += 
00134                static_cast<TRIE*>((*it).second)->edgelist.size();
00135 #endif
00136       }
00137    }
00138 }
00139 }
00140 #endif

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