EPA.hpp

Go to the documentation of this file.
00001 #ifndef wali_EPA_GUARD
00002 #define wali_EPA_GUARD 1
00003 
00004 /*!
00005  * @author Nicholas Kidd
00006  * @author Akash Lal
00007  */
00008 
00009 #include "wali/wfa/WFA.hpp"
00010 #include "wali/wfa/epr/FunctionalWeight.hpp"
00011 #include "wali/wfa/epr/FunctionalWeightMaker.hpp"
00012 #include <map>
00013 #include <list>
00014 
00015 namespace wali 
00016 {
00017   namespace wfa 
00018   {
00019     namespace epr 
00020     {
00021 
00022       /*! 
00023        * @class EPA
00024        * @brief Implements the Error Projection Automaton
00025        */
00026 
00027       class EPA : public WFA {
00028         private:
00029 
00030           // Store the BFS order for states <-- not updated with transition insertions
00031           std::map< Key, unsigned int> bfsOrder;
00032 
00033           typedef std::list< std::pair< sem_elem_t, sem_elem_t > > CacheElem;
00034           std::map< Key, CacheElem > errorProjCache;
00035           std::map< Key, walienum::ETag > stateTagMap;
00036           int nCacheHits;
00037 
00038         public:
00039 
00040           EPA( );
00041 
00042           ~EPA();
00043 
00044           void clear();
00045 
00046           int getCacheHits();
00047 
00048           void buildEPA(WFA &post, WFA &pre);
00049 
00050           // Compute the error projection weight for node with bottleneck weight initWeight
00051           sem_elem_t apply(Key node, sem_elem_t initWeight);
00052 
00053           // Same as above, but increments notfound by 1 if the node was not found in
00054           // the automaton
00055           sem_elem_t apply(Key node, sem_elem_t initWeight, int &notfound);
00056 
00057         private:
00058 
00059           // returns invalid sem_elem_t if (q,w) is not found in the cache
00060           sem_elem_t lookupCache(Key q, sem_elem_t w);
00061 
00062           // Adds ((q,w),res) to the cache
00063           void addToCache(Key q, sem_elem_t w, sem_elem_t res);
00064 
00065           // Maintain a State Key -> ETag map
00066           void setStateTag(State *s, walienum::ETag et);
00067           walienum::ETag getStateTag(State *s);
00068 
00069           // Do a BFS on the automaton and store the BFS number
00070           // in bfsOrder
00071           void orderStatesBFS();
00072 
00073       }; // class EPA
00074 
00075     } // namespace epr
00076 
00077   } // namespace wfa
00078 
00079 } // namespace wali
00080 
00081 #endif  // wali_EPA_GUARD
00082