ITrans.hpp

Go to the documentation of this file.
00001 #ifndef wali_wfa_ITRANS_GUARD
00002 #define wali_wfa_ITRANS_GUARD 1
00003 
00004 /*!
00005  * @author Nicholas Kidd
00006  */
00007 
00008 #include <iostream>
00009 #include "wali/Common.hpp"
00010 #include "wali/Markable.hpp"
00011 #include "wali/Printable.hpp"
00012 #include "wali/SemElem.hpp"
00013 #include "wali/KeyContainer.hpp"
00014 
00015 #include "wali/TaggedWeight.hpp"
00016 #include "wali/util/WeightChanger.hpp"
00017 
00018 namespace wali
00019 {
00020   namespace wpds {
00021     class Config;
00022   }
00023 
00024   namespace wfa
00025   {
00026 
00027     class ITrans;
00028 
00029     /*!
00030      * @struct ITransLT
00031      *
00032      * This can be used to place ITrans* into std::set or any other STL
00033      * container that uses Strict-weak ordering.
00034      */
00035     struct ITransLT {
00036       bool operator()( const ITrans* a, const ITrans* b ) const;
00037     };
00038 
00039     struct ITransEq {
00040       bool operator()( const ITrans* a, const ITrans* b );
00041     };
00042 
00043     /*!
00044      * @class ITrans
00045      *
00046      * ITrans defines the interface that an automaton transition must
00047      * implement.
00048      *
00049      * An automaton transition is basically a 4-tuple of (p,g,q,W), where
00050      * p is a "from state", g is a "stack symbol", q is a "to state", and W is
00051      * a weight, or an instance of a SemElem.
00052      *
00053      * IMarkable is to make a ITrans able to be placed in a Worklist.
00054      *
00055      * @see Printable
00056      * @see Markable
00057      * @see Worklist
00058      * @see WFA 
00059      * @see sem_elem_t
00060      * @see ref_ptr
00061      */
00062 
00063     class ITrans : public Printable, public virtual IMarkable
00064     {
00065       //
00066       // Types
00067       //
00068       public:
00069         enum status_t { MODIFIED,SAME };
00070         static const std::string XMLTag;
00071         static const std::string XMLFromTag;
00072         static const std::string XMLStackTag;
00073         static const std::string XMLToTag;
00074 
00075         //
00076         // Methods
00077         //
00078       public:
00079         /*!
00080          * @return a copy of the transition
00081          */
00082         virtual ITrans* copy() const = 0;
00083         /*!
00084          * @return a copy of the transition with changed states and stack
00085          */
00086         virtual ITrans* copy(Key fromst, Key stk, Key tost) const = 0;
00087 
00088         //
00089         // getters (const)
00090         //
00091         /*! @return const Key of from state */
00092         virtual Key from() const throw() = 0;
00093 
00094         /*! @return const Key of stack symbol */
00095         virtual Key stack() const throw() = 0;
00096 
00097         /*! @return const Key of to state */
00098         virtual Key to() const throw() = 0;
00099 
00100         /*! @return const sem_elem_t of ITrans */
00101         virtual const sem_elem_t weight() const throw()  = 0;
00102 
00103         /*!
00104          * @return const sem_elem_t delta of ITrans
00105          *
00106          * delta is used in computing fixpoints
00107          */
00108         virtual const sem_elem_t getDelta() const throw() = 0;
00109 
00110         //
00111         // getters (non const)
00112         //
00113         /*! @return Key of from state */
00114         virtual Key from() throw() = 0;
00115 
00116         /*! @return Key of stack symbol */
00117         virtual Key stack() throw() = 0;
00118 
00119         /*! @return Key of to state */
00120         virtual Key to() throw() = 0;
00121 
00122         /*! @return sem_elem_t of ITrans */
00123         virtual sem_elem_t weight() throw() = 0;
00124 
00125         /*!
00126          * @return sem_elem_t delta of ITrans
00127          *
00128          * delta is used in computing fixpoints
00129          */
00130         virtual sem_elem_t getDelta() throw() = 0;
00131 
00132         //
00133         // setters
00134         //
00135         /*!
00136          * Set weight and delta of this ITrans
00137          * to be param [w].
00138          *
00139          * @param sem_elem_t for new weight and delta
00140          *
00141          * @return void
00142          */
00143         virtual void setWeight( sem_elem_t w )  = 0;
00144 
00145         /*!
00146          * Set the delta value for the ITrans.
00147          */
00148         virtual void setDelta( const sem_elem_t w ) = 0;
00149 
00150         /*!
00151          * When inserting a transition into an automaton, 
00152          * the WFA will check to see if the transition
00153          * already exists. If so, let told be the existing transition
00154          * and tnew be the transition being inserted. Then
00155          * the WFA invokes:
00156          * <code>   
00157          *           told->combineTrans( tnew )
00158          * </code>
00159          *
00160          * @param ITrans* the new ITrans to be "absorbed"
00161          */
00162         virtual void combineTrans( ITrans* tp )= 0;
00163 
00164 
00165         /*!
00166          * Return const referenct to this transitions KeyPair
00167          *
00168          * The KeyPair holds the from state and stack symbol.
00169          *
00170          * @see KeyPair
00171          * @return const KeyPair reference
00172          */
00173         virtual const KeyPair & keypair() const throw() = 0;
00174 
00175         /*!
00176          * @brief return true if the transition has been modified
00177          *
00178          * A ITrans is considered modified if when its weight changes. This
00179          * includes the initial creation of a ITrans object. This follows
00180          * from the fact that all ITrans can be considered (abstractly)
00181          * created with a weight of ZERO
00182          *
00183          * @return true if this transition has been modified
00184          */
00185         virtual bool modified() const throw() = 0;
00186 
00187         /*!
00188          * @return A null pointer.
00189          */
00190         virtual wpds::Config* getConfig() const = 0;
00191 
00192         /*!
00193          * Set this ITrans's Config to c.
00194          * @return void
00195          */
00196         virtual void setConfig( wpds::Config* c ) = 0;
00197 
00198         /*!
00199          * This is used by (E)WPDS::poststar
00200          * during epsilon-transistion contraction.
00201          * The base case is:
00202          *   this->weight()->extend(se)
00203          */
00204         virtual sem_elem_t poststar_eps_closure( sem_elem_t se ) = 0;
00205 
00206         /*!
00207          * This is used by FunctionalWeight
00208          * The base case is:
00209          *   weight \extend tw.weight
00210          */
00211         virtual TaggedWeight apply_post( TaggedWeight tw) const = 0;
00212 
00213         /*!
00214          * This is used by FunctionalWeight
00215          * The base case is:
00216          *   tw.weight \extend weight
00217          */
00218         virtual TaggedWeight apply_pre( TaggedWeight tw) const = 0;
00219 
00220         /*!
00221          * This is used by WeightChanger
00222          * It applies the changer to all weights stored in the transition
00223          * Base case is that it is applied to t->weight()
00224          */
00225         virtual void applyWeightChanger( util::WeightChanger &wc) = 0;
00226 
00227 
00228         //****************************************************
00229         //****************************************************
00230         // Methods that ITrans actually provides a default
00231         // implementation for.
00232         //
00233 
00234         /*! @return true if param rhs is equal to this */
00235         virtual bool equal( const ITrans & rhs ) const;
00236 
00237         /*! @return true if param rhs is equal to this */
00238         virtual bool equal( const ITrans * rhs ) const;
00239 
00240         /*!
00241          * Print this transition to the ostream. Overrides
00242          * or implements Printable::print
00243          *
00244          * @return std::ostream this was written to
00245          *
00246          * @see Printable
00247          *  
00248          */
00249         virtual std::ostream& print( std::ostream& o ) const;
00250 
00251         /*!
00252          * @brief Print ITrans in XML to ostream o
00253          *
00254          * @return std::ostream the marshalled ITrans was written to.
00255          */
00256         virtual std::ostream& marshall( std::ostream& o ) const;
00257 
00258     };
00259 
00260   } // namespace wfa
00261 
00262 } // namespace wali
00263 
00264 #endif  // wali_wfa_ITRANS_GUARD
00265