libFAUDES

Sections

Index

mtc_generator.h

Go to the documentation of this file.
00001 /** @file mtc_generator.h
00002 
00003 Methods for handling multitasking generators
00004 
00005 */
00006 
00007 /* FAU Discrete Event Systems Library (libfaudes)
00008 
00009    Copyright (C) 2008  Matthias Singer
00010    Exclusive copyright is granted to Klaus Schmidt
00011 
00012    This library is free software; you can redistribute it and/or
00013    modify it under the terms of the GNU Lesser General Public
00014    License as published by the Free Software Foundation; either
00015    version 2.1 of the License, or (at your option) any later version.
00016 
00017    This library is distributed in the hope that it will be useful,
00018    but WITHOUT ANY WARRANTY; without even the implied warranty of
00019    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020    Lesser General Public License for more details.
00021 
00022    You should have received a copy of the GNU Lesser General Public
00023    License along with this library; if not, write to the Free Software
00024    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00025 
00026 
00027 #ifndef FAUDES_MTCGENERATOR_H
00028 #define FAUDES_MTCGENERATOR_H
00029 
00030 #include "corefaudes.h"
00031 #include "mtc_attributes.h"
00032 #include <map>
00033 
00034 namespace faudes {
00035 
00036 
00037 /**
00038  * Allows to create colored marking generators (CMGs) as the common
00039  * five tupel consisting  of alphabet, stateset, transition relation,
00040  * initial states, marked states, and attributes for state and event
00041  * properties. Thus, it is possible to set a control status for
00042  * events and to add or delete colored markings to single states.
00043  * Doing so, multitasking generators can be computed and their
00044  * behaviour be analysed.Methods for examining the color status are
00045  * included as well as those for making a CMG accessible or strongly
00046  * coaccessible.  Furthermore, input and output methods for
00047  * mtcGenerators are included.
00048  *
00049  * @ingroup MultitaskingPlugin
00050  */
00051 
00052 template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
00053   class TmtcGenerator : public TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr> {
00054 
00055  public:
00056 
00057     /** @name Constructor, Destructor and Copy-Methods */
00058     /** @{ doxygen group */
00059 
00060     /**
00061      * Creates an emtpy mtcGenerator
00062      */
00063     TmtcGenerator(void);
00064   
00065     /**
00066      * Creates an mtcgenerator from another mtcgenerator - copy constructor:
00067      *
00068      * If the other mtcGenerator uses a local color symbol table, the new
00069      * generator also creates a local symbol table. This new one is empty! If
00070      * you use a local symbol table, you should implement a copy mechanism
00071      * for the entries of the original generator's symbol table.
00072      *
00073      * @param rOtherGen
00074      *   Other mtcgenerator to copy
00075      */
00076     TmtcGenerator(const TmtcGenerator& rOtherGen);
00077   
00078     /**
00079      * Creates an mtcgenerator from another generator - copy constructor 
00080      *
00081      * @param rOtherGen
00082      *   Other generator to copy
00083      */
00084     TmtcGenerator(const vGenerator& rOtherGen);
00085   
00086     /**
00087      * Constructs an mtcGenerator from file
00088      *
00089      * Define FAUDES_CHECKED for consistency checks
00090      *
00091      * @param rFileName
00092      *   Filename
00093      *
00094      * @exception Exception
00095      *   - Opening/reading failed (ids 1, 50, 51)
00096      */
00097     TmtcGenerator(const std::string& rFileName);
00098 
00099     /**
00100      * Destructor for mtcGenerator
00101      *
00102      */
00103     ~TmtcGenerator(void) { FD_DG("TmtcGenerator(" << this << ")::~TmtcGenerator()");};
00104 
00105     /**
00106      * Construct on heap. 
00107      *
00108      * @return 
00109      *   New vGenerator 
00110      */
00111     virtual TmtcGenerator* New(void) const;
00112 
00113     /**
00114      * Construct copy on heap. 
00115      *
00116      * @return 
00117      *   New vGenerator 
00118      */
00119     virtual TmtcGenerator* Copy(void) const;
00120 
00121 
00122     /**
00123      * Copy from other mtcgenerator
00124      *
00125      * @param rSrc
00126      *   mtcGenerator to copy from
00127      */
00128     virtual TmtcGenerator& Assign(const TmtcGenerator& rSrc);
00129 
00130     /**
00131      * Copy from other generator
00132      *
00133      * @param rSrc
00134      *   Generator which will become the copy
00135      */
00136     virtual TmtcGenerator& Assign(const vGenerator& rSrc);
00137 
00138     /** @} doxygen group */
00139 
00140     /** @name Color Symbol Table */
00141     /** @{ doxygen group */
00142 
00143     /**
00144      * Get Pointer to global ColorSymbolTable. This is
00145      * a static member of ColorSet and used as default
00146      * for all derived classes and instantiated objects.
00147      *
00148      * @return
00149      *   Pointer to global ColorSymbolTable
00150      */
00151     SymbolTable* GlobalColorSymbolTablep(void) const;
00152 
00153     /**
00154      * Get Pointer to ColorSymbolTable currently used
00155      * by this mtcGenerator.
00156      *
00157      * @return
00158      *   Pointer to ColorSymbolTable
00159      */
00160     SymbolTable* ColorSymbolTablep(void) const;
00161 
00162     /**
00163      * Set ColorSymbolTable to be used by this mtcGenerator.
00164      * Note: the managemnt of local color symbol tables needs
00165      * a re-design. Dont use thus feature.
00166      *
00167      * @param pSymTab
00168      *   Pointer to SymbolTable
00169      */
00170     void ColorSymbolTable(SymbolTable* pSymTab);
00171 
00172     /**
00173      * Set ColorSymbolTable as given by rOtherGen.
00174      *
00175      * @param rOtherGen
00176      *   Other generator 
00177      */
00178     void ColorSymbolTable(const TmtcGenerator& rOtherGen);
00179 
00180     /** @} doxygen group */
00181 
00182     /** @name Editing Colored States */
00183     /** @{ doxygen group */
00184 
00185     /**
00186      * Create a new named state and set the color rColorName
00187      *
00188      * Define FAUDES_CHECKED for consistency checks
00189      *
00190      * @param  rStateName
00191      *   Name of the state to add
00192      *
00193      * @param rColorName
00194      *   Name of the state color
00195      *
00196      * @return
00197      *   Index of new unique state
00198      *
00199      * @exception Exception
00200      *   - Name already exists (id 104)
00201      *   - Index not member of set (id 200)
00202      */
00203     Idx InsColoredState(const std::string& rStateName, const std::string& rColorName);
00204 
00205     /**
00206      * Create a new named state and set the color colorIndex
00207      *
00208      * Define FAUDES_CHECKED for consistency checks
00209      *
00210      * @param  rStateName
00211      *   Name of the state to add
00212      *
00213      * @param colorIndex
00214      *   Index of the state color, must already exist in symbol table
00215      *
00216      * @return
00217      *   Index of new unique state
00218      *
00219      * @exception Exception
00220      *   - Color index not known to symbol table (id 200)
00221      */
00222     Idx InsColoredState(const std::string& rStateName, Idx colorIndex);
00223 
00224     /**
00225      * Create a new named state and set the colors from rColors
00226      *
00227      * @param  rStateName
00228      *   Name of the state to add
00229      *
00230      * @param rColors
00231      *   Color set
00232      *
00233      * @return
00234      *   Index of new unique state
00235      */
00236     Idx InsColoredState(const std::string& rStateName, const ColorSet& rColors);
00237 
00238     /**
00239      * Create a new unnamed state and set the colors from rColors
00240      *
00241      * @param rColors
00242      *   Color set
00243      *
00244      * @return
00245      *   Index of new unique state
00246      */
00247     Idx InsColoredState(const ColorSet& rColors);
00248 
00249     /**
00250      * Insert a color by name into an existing state 
00251      *
00252      * Define FAUDES_CHECKED for consistency checks
00253      *
00254      * @param stateIndex
00255      *   Index of state to be set as colored state
00256      *
00257      * @param rColorName
00258      *   Name of state color to be added
00259      *
00260      * @return Index of inserted color
00261      *
00262      * @exception Exception
00263      *   - Index not member of set (id 200)
00264      *   - Name already exists / invalid name (id 104)
00265      */
00266     Idx InsColor(Idx stateIndex, const std::string& rColorName);
00267 
00268     /**
00269      * Insert a color by index into an existing state 
00270      *
00271      * Define FAUDES_CHECKED for consistency checks
00272      *
00273      * @param stateIndex
00274      *   Index of state to be set as colored state
00275      *
00276      * @param colorIndex
00277      *   Index of color to be added to state, must already exist in symbol table
00278      *
00279      * @exception Exception
00280      *   - State index not member of set (id 200)
00281      *   - Color index not known to symbol table (id 200)
00282      */
00283     void InsColor(Idx stateIndex, Idx colorIndex);
00284 
00285     /**
00286      * Insert multiple colors from a color set into an existing state 
00287      *
00288      * Define FAUDES_CHECKED for consistency checks
00289      *
00290      * @param stateIndex
00291      *   Index of state to be set as colored state
00292      *
00293      * @param rColors
00294      *   Reference to color set with colors to set for state, colors must already exist in symbol table
00295      *
00296      * @exception Exception
00297      *   - State index not member of set (id 200)
00298      *   - Symbol table mismach (id 200)
00299      *   - Symbol table mismatch (id 88)
00300      */
00301     void InsColors(Idx stateIndex, const ColorSet& rColors);
00302 
00303     /**
00304      * Remove color by name from an existing state specified by index
00305      *
00306      * Define FAUDES_CHECKED for consistency checks.
00307      *
00308      * @param stateIndex
00309      *   State index
00310      *
00311      * @param rColorName
00312      *   Name of the state color
00313      *
00314      * @exception Exception
00315      *   - Index not member of set (id 200)
00316      *   - Name not found in NameSet (id 202)
00317      */
00318     void DelColor(Idx stateIndex, const std::string& rColorName);
00319   
00320     /**
00321      * Remove color by index form an existing state specified by index
00322      *
00323      * Define FAUDES_CHECKED for consistency checks.
00324      *
00325      * @param stateIndex
00326      *   State index
00327      *
00328      * @param colorIndex
00329      *   Index of the state color
00330      *
00331      * @exception Exception
00332      *   - Index not member of set (id 200)
00333      *   - Color index not found in generator (id 205)
00334      */
00335     void DelColor(Idx stateIndex, Idx colorIndex);
00336 
00337     /**
00338      * Remove color by name from all states
00339      *
00340      * @param rColorName
00341      *   Name of state color
00342      */
00343     void DelColor(const std::string& rColorName);
00344 
00345     /**
00346      * Remove color by index from all states
00347      *
00348      * @param colorIndex
00349      *   Index of state color
00350      */
00351     void DelColor(Idx colorIndex);
00352 
00353     /**
00354      * Remove all colors from a particular state. If symbol table
00355      * is local, unused colors are deleted from it, global symbol
00356      * table stays untouched.
00357      *
00358      * Define FAUDES_CHECKED for consistency checks
00359      *
00360      * @param stateIndex
00361      *   State where colors should be removed
00362      *
00363      * @exception Exception
00364      *   - Index not member of set (id 200)
00365      */
00366     void ClrColors(Idx stateIndex);
00367 
00368     /**
00369      * Clear all the generator's state attributes. The current implementation
00370      * also clears the color symbol table if it is local. This behaviour may
00371      * change in future.
00372      */
00373     void ClearStateAttributes();
00374 
00375     /** @} doxygen group */
00376 
00377     /** @name Analyse Colored States and State Colors */
00378     /** @{ doxygen group */
00379 
00380     /**
00381      * Insert all colors used in the generator to a given ColorSet.
00382      *
00383      * @param rColors
00384      *   Color set in which all colors of the generator will be inserted
00385      *
00386      * @exception Exception
00387      *   - Symbol table mismatch (id 88)
00388      */
00389     void Colors(ColorSet& rColors) const;
00390 
00391     /**
00392      * Returns a color set containing all the generator's colors.
00393      *
00394      * @return
00395      *   Color set with generators colors
00396      */
00397     ColorSet Colors(void) const;
00398 
00399     /**
00400      * Return a color set which contains all colors of one state.
00401      *
00402      * @return
00403      *   Color set with state's colors
00404      *
00405      * @exception Exception
00406      *   - Index not member of set (id 200)
00407      */
00408     const ColorSet& Colors(Idx stateIndex) const;
00409 
00410     /**
00411      * Returns a state set containing all states that are colored with the color given by index.
00412      *
00413      * @param colorIndex
00414      *    Color whose corresponding states shall be returned
00415      *
00416      * @return
00417      *    State set containing appropriate states
00418      */
00419     StateSet ColoredStates(Idx colorIndex) const;
00420   
00421     /**
00422      * Returns a state set containing all states that are colored with the color given by name.
00423      *
00424      * @param rColorName
00425      *    Color whose corresponding states shall be returned
00426      *
00427      * @return
00428      *    State set containing appropriate states
00429      */
00430     StateSet ColoredStates(const std::string& rColorName) const;
00431   
00432     /**
00433      * Returns a state set containing all colored states of the mtcGenerator.
00434      *
00435      * @return
00436      *    State set containing colored states
00437      */
00438     StateSet ColoredStates() const;
00439   
00440     /**
00441      * Returns a state set containing all states that are not colored.
00442      *
00443      * @return
00444      *    State set containing uncolored states
00445      */
00446     StateSet UncoloredStates() const;
00447   
00448     /**
00449      * Check if color exists in generator.
00450      *
00451      * @param colorIndex
00452      *   Index which will be examined regarding existence in the generator
00453      *
00454      * @return
00455      *   true if color exists
00456      */
00457     bool ExistsColor(Idx colorIndex) const;
00458   
00459     /**
00460      * Check if color exists in generator.
00461      *
00462      * Define FAUDES_CHECKED for consistency checks
00463      *
00464      * @param rColorName
00465      *   Color name which will be examined regarding existence in the generator
00466      *
00467      * @return
00468      *   true if color exists
00469      *
00470      * @exception Exception
00471      *   - Color name not found in symbol table (id 202)
00472      */
00473     bool ExistsColor(const std::string& rColorName) const;
00474   
00475     /**
00476      * Check if color exists in a given state of the mtcGenerator.
00477      *
00478      * Define FAUDES_CHECKED for consistency checks
00479      *
00480      * @param stateIndex
00481      *   Index which determines the generator's state
00482      *
00483      * @param colorIndex
00484      *   Color index to look for in given state
00485      *
00486      * @return
00487      *   true if color exists in state
00488      *
00489      * @exception Exception
00490      *   - Index not member of set (id 200)
00491      */
00492     bool ExistsColor(Idx stateIndex, Idx colorIndex) const;
00493   
00494     /**
00495      * Check if there is at least one colored state in the mtcGenerator.
00496      *
00497      * @return
00498      *    True if there is at least one colored state
00499      */
00500     bool IsColored(void) const;
00501   
00502     /**
00503      * Check if the given state is colored or not.
00504      *
00505      * Define FAUDES_CHECKED for consistency checks
00506      *
00507      * @param stateIndex
00508      *    State to examine
00509      *
00510      * @return
00511      *    True if given state is colored
00512      *
00513      * @exception Exception
00514      *    - State index not member of set (id 200)
00515      */
00516     bool IsColored(Idx stateIndex) const;
00517   
00518     /** @} doxygen group */
00519 
00520     /** @name Symbol Table */
00521     /** @{ doxygen group */
00522 
00523     /**
00524      * Finally deletes a color name and its index from the currently used symbol table.
00525      *
00526      * @param colorIndex
00527      *   Index of color to delete from symbol table
00528      */
00529     void DelColorName(Idx colorIndex);
00530   
00531     /**
00532      * Delete the given color from the symbol table if it is not used anymore in the generator by calling DelColorName.
00533      *
00534      * @param colorIndex
00535      *   Color which will be deleted from symbol table if not used anymore
00536      */
00537     void CheckSymbolTable(Idx colorIndex);
00538   
00539     /**
00540      * Delete all colors from the given color set from the color symbol table by calling DelColorName if they are not used anymore. rColors must use the same symbol table as the mtcGenerator!
00541      *
00542      * @param rColors
00543      *   Color set with all colors that will be deleted from symbol table if not used anymore
00544      *
00545      * @exception Exception
00546      *   - Symbol table mismatch (id 88)
00547      */
00548     void CheckSymbolTable(ColorSet& rColors);
00549   
00550     /**
00551      * Look up the color name for a given color index.
00552      *
00553      * @param colorIndex
00554      *
00555      * @return 
00556      *   Color name
00557      */
00558     std::string ColorName(Idx colorIndex) const;
00559   
00560     /**
00561      * Look up the color index for a given color name.
00562      *
00563      * @param rColorName
00564      *
00565      * @return 
00566      *   Color index
00567      */
00568     Idx ColorIndex(const std::string& rColorName) const;
00569   
00570     /** @} doxygen group */
00571 
00572     /** @name Output Methods */
00573     /** @{ doxygen group */
00574 
00575     /**
00576      * Writes generator to dot input format.
00577 
00578      * The dot file format is specified by the graphiz package; see http://www.graphviz.org. The package includes the dot command 
00579      * line tool to generate a graphical representation of the generators graph. See also vGenerator::GraphWrite(). 
00580      * This functions sets the re-indexing to minimal indices.
00581      *
00582      * @param rFileName
00583      *    Name of file to save result
00584      */
00585     virtual void DotWrite(const std::string& rFileName) const;
00586   
00587     /**
00588      * Return pretty printable color name for index. Primary meant for debugging messages.
00589      *
00590      * @param index
00591      *
00592      * @return std::string
00593      *   Color name
00594      */
00595     std::string CStr(Idx index) const;
00596 
00597     /** @} doxygen group */
00598 
00599     /** @name Reachability */
00600     /** @{ doxygen group */
00601 
00602     /**
00603      * Generate a state set with all strongly coaccessible states.
00604      *
00605      * @return StateSet
00606      *    Coaccessible states
00607      */
00608     StateSet StronglyCoaccessibleSet(void) const;
00609 
00610     /**
00611      * Make generator strongly coaccessible. Forbidden states are deleted.
00612      *
00613      * @return
00614      *    True if generator is strongly coaccessible
00615      *
00616      * <h4>Example: Computation of the strongly coaccessible form of an mtcGenerator </h4>
00617      * <table border=0> <tr> <td> 
00618      *   <table width=100%>
00619      *     <tr> <td> <center> Original mtcGenerator gen</center> </td> </tr>
00620      *     <tr> <td> @image html tmp_mtc_functions_1b_acc.png </td> </tr>
00621      *     <tr> <td> <center> From state 3 states with other colored markings cannot be reached. So, this generator is weakly coaccessible w.r.t. its color set, but not strongly coaccessible w.r.t. it. </center> </td> </tr>
00622      *   </table>
00623      *   </td> </tr>
00624      *   <tr> <td>
00625      *   <table width=100%>
00626      *     <tr> <td> <center> Result of gen.StronglyCoaccessible(); </center> </td> </tr>
00627      *     <tr> <td> @image html tmp_mtc_functions_1d_str_trim.png </td> </tr>
00628      *     <tr> <td> <center> Resulting mtcGenerator is strongly coaccessible w.r.t its new color set where the color of the primary state 3 is missing </center> </td> </tr>
00629      *   </table>
00630      *   </td> </tr>
00631      * </table>
00632      */
00633     bool StronglyCoaccessible(void);
00634 
00635     /**
00636      * Check if mtcGenerator is strongly coaccessible.
00637      *
00638      * @return
00639      *    True if generator is strongly coaccessible
00640      */
00641     bool IsStronglyCoaccessible(void) const;
00642 
00643     /**
00644      * Generate a state set with all the strongly trim generator's states.
00645      *
00646      * @return StateSet
00647      *    All states for which generator is strongly trim
00648      */
00649     StateSet StronglyTrimSet(void) const;
00650 
00651     /**
00652      * Make generator strongly trim. Therefore, the forbidden states are deleted.
00653      *
00654      * @return
00655      *    True if generator is strongly trim
00656      *
00657      * <h4>Example: Computation of the strongly trim form of an mtcGenerator</h4>
00658      * <table border=0> <tr> <td>
00659      *   <table width=100%>
00660      *     <tr> <td> <center> Original mtcGenerator gen</center> </td> </tr>
00661      *     <tr> <td> @image html tmp_mtc_functions_1a_not_trim.png </td> </tr>
00662      *     <tr> <td> <center> State 5 is not accessible and from state 3 other states with other colored markings cannot be reached. So, this generator is not accessible and weakly coaccessible w.r.t. its color set. </center> </td> </tr>
00663      *   </table>
00664      *   </td> </tr>
00665      *   <tr> <td>
00666      *   <table width=100%>
00667      *     <tr> <td> <center> Result of gen.StronglyTrim(); </center> </td> </tr>
00668      *     <tr> <td> @image html tmp_mtc_functions_1d_str_trim.png </td> </tr>
00669      *     <tr> <td> <center> Resulting mtcGenerator is strongly trim, which means accessible and strongly coaccessible w.r.t its color set </center> </td> </tr>
00670      *   </table>
00671      *   </td> </tr>
00672      * </table>
00673      */
00674     bool StronglyTrim(void);
00675 
00676     /**
00677      * Check if the mtcGenerator is strongly trim.
00678      *
00679      * @return
00680      *    True if generator is strongly trim
00681      */
00682     bool IsStronglyTrim(void) const; 
00683 
00684     /** @} doxygen group */
00685 
00686     
00687     /** @name Further Methods */
00688     /** @{ doxygen group */
00689 
00690     /**
00691      * Insert a new local color symbol table. mpColorSymbolTable is reset.
00692      * The color symbol table pointer in every state attribute's mColors is
00693      * also reset to the new symbol table. If there already exist color entries
00694      * in the current symbol table, they are copied to the new local one.
00695      *
00696      * Define FAUDES_CHECKED for consistency checks
00697      *
00698      * @exception Exception
00699      *   - Could not insert index and symbol to symbol table (id 44)
00700      */
00701     void NewColorSymbolTable();
00702 
00703     /**
00704      * Return a color map with state indices and their corresponding colors. 
00705      * Only states with asociated colors are part of this list.
00706      *
00707      * @return color map
00708      *    Standard library map where states and corresponding colors are saved
00709      */
00710     std::map<Idx,ColorSet> StateColorMap(void) const;
00711 
00712     /** @} doxygen group */
00713 
00714  protected:
00715     /**
00716      * Pointer to currently used symbol table
00717      */
00718     SymbolTable *mpColorSymbolTable;
00719 
00720   /**
00721    * Token output, see Type::SWrite for public wrappers.
00722    * The method assumes that the type parameter is a faudes type and uses
00723    * the provide write method per entry. Reimplement this function in derived 
00724    * classes for non-faudes type vectors.
00725    *
00726    * @param rTw
00727    *   Reference to TokenWriter
00728    *
00729    * @exception Exception 
00730    *   - IO errors (id 2)
00731    */
00732   virtual void DoSWrite(TokenWriter& rTw) const;
00733 
00734 
00735 }; // end class TmtcGeneraator
00736 
00737 
00738 
00739 // convenience typedef for std mtcGenerator
00740 typedef TmtcGenerator<AttributeVoid,AttributeColoredState,AttributeCFlags,AttributeVoid> mtcGenerator;
00741 
00742 // convenient scope macors
00743 #define THIS TmtcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
00744 #define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
00745 #define TEMP template<class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
00746 
00747 
00748 /** 
00749  * RTI wrapper function. See also mtcGenerator::IsStronglyCoaccessible().
00750  * \ingroup GeneratorFunctions
00751  */
00752 void IsStronglyCoaccessible(const mtcGenerator& rGen, bool& rRes);
00753 
00754 /** 
00755  * RTI wrapper function. See also mtcGenerator::IsStronglyTrim().
00756  * \ingroup GeneratorFunctions
00757  */
00758 void IsStronglyTrim(const mtcGenerator& rGen, bool& rRes);
00759 
00760 /** 
00761  * RTI wrapper function. See also mtcGenerator::Coaccessible().
00762  * \ingroup GeneratorFunctions 
00763  */
00764 void StronglyCoaccessible(mtcGenerator& rGen);
00765 
00766 /** 
00767  * RTI wrapper function. See also mtcGenerator::Coaccessible().
00768  * \ingroup GeneratorFunctions
00769  */
00770 void StronglyCoaccessible(const mtcGenerator& rGen, mtcGenerator& rRes);
00771 
00772 /** 
00773  * RTI wrapper function. See also mtcGenerator::Trim().
00774  * \ingroup GeneratorFunctions
00775  */
00776 void StronglyTrim(mtcGenerator& rGen);
00777 
00778 /** 
00779  * RTI wrapper function. See also mtcGenerator::Trim().
00780  * \ingroup GeneratorFunctions
00781  */
00782 void StronglyTrim(const mtcGenerator& rGen, mtcGenerator& rRes);
00783 
00784 
00785 
00786 // TmtcGenerator(void)
00787 TEMP THIS::TmtcGenerator(void) : BASE() {
00788   FD_DG("mtcGenerator(" << this << ")::mtcGenerator()");
00789   mpColorSymbolTable = GlobalColorSymbolTablep();
00790 }
00791 
00792 // TmtcGenerator(rOtherGen)
00793 TEMP THIS::TmtcGenerator(const TmtcGenerator& rOtherGen) : BASE() {
00794   FD_DG("mtcGenerator(" << this << ")::mtcGenerator(rOtherGen)");
00795   if (rOtherGen.ColorSymbolTablep() != ColorSet::StaticSymbolTablep()) 
00796     NewColorSymbolTable();
00797   else ColorSymbolTable(GlobalColorSymbolTablep());
00798   Assign(rOtherGen);
00799 }
00800 
00801 // TmtcGenerator(rOtherGen)
00802 TEMP THIS::TmtcGenerator(const vGenerator& rOtherGen) : BASE() {
00803   FD_DG("mtcGenerator(" << this << ")::mtcGenerator(rOtherGen)");
00804   ColorSymbolTable(GlobalColorSymbolTablep());
00805   Assign(rOtherGen);
00806 }
00807 
00808 // TmtcGenerator(rFilename)
00809  TEMP THIS::TmtcGenerator(const std::string& rFileName) : BASE() {
00810   FD_DG("mtcGenerator(" << this << ")::mtcGenerator(" << rFileName << ")");
00811   ColorSymbolTable(GlobalColorSymbolTablep());
00812   BASE::Read(rFileName);
00813 }
00814 
00815 // New/Copy
00816 TEMP THIS* THIS::New(void) const {
00817   // allocate
00818   THIS* res = new THIS;
00819   // fix base data
00820   res->EventSymbolTablep(BASE::mpEventSymbolTable);
00821   res->mStateNamesEnabled=BASE::mStateNamesEnabled;
00822   // fix my data
00823   res->ColorSymbolTable(GlobalColorSymbolTablep());
00824   // done
00825   return res;
00826 }
00827 
00828 // Copy
00829 TEMP THIS* THIS::Copy(void) const {
00830   // allocate
00831   THIS* res = new THIS(*this);
00832   // done
00833   return res;
00834 }
00835 
00836 
00837 
00838 
00839 // Assign(gen)
00840 TEMP THIS& THIS::Assign(const TmtcGenerator& rSrc) {
00841   FD_DG("mtcGenerator(" << this << ")::Assign(gen&)");
00842   // call base method
00843   BASE::Assign(rSrc);
00844   // my members
00845   ColorSymbolTable(rSrc.ColorSymbolTablep());
00846   // fix non std symboltable (broken)
00847   /*
00848     if (rSrc.ColorSymbolTablep() != ColorSet::StaticSymbolTablep()) {
00849     NewColorSymbolTable();
00850 
00851     ColorSet mycolors(mpColorSymbolTable);
00852     Colors(mycolors);
00853     ColorSet::Iterator cit;
00854     ColorSet::Iterator cit_end = mycolors.End();
00855 
00856     for (cit = mycolors.Begin(); cit != cit_end; cit++) {
00857     ColorSymbolTablep()->SetEntry(*cit, ColorName(*cit));
00858     }
00859     }
00860   */
00861   // done
00862   return *this;
00863 }
00864 
00865 // Assign(gen)
00866 TEMP THIS& THIS::Assign(const vGenerator& rSrc) {
00867   FD_DG("mtcGenerator(" << this << ")::Assign(vgen&)");
00868   // call base method
00869   BASE::Assign(rSrc);
00870   // done
00871   return *this;
00872 }
00873 
00874 // GlobalColorSymbolTablep()
00875 TEMP SymbolTable* THIS::GlobalColorSymbolTablep(void) const {
00876   return ColorSet::StaticSymbolTablep();
00877 }
00878 
00879 // ColorSymbolTablep()
00880 TEMP SymbolTable* THIS::ColorSymbolTablep(void) const {
00881   return mpColorSymbolTable;
00882 }
00883 
00884 // ColorSymbolTable(SymbolTable*)
00885 TEMP void THIS::ColorSymbolTable(SymbolTable* pSymTab) {
00886   mpColorSymbolTable=pSymTab;
00887 }
00888 
00889 // ColorSymbolTable(rOtherGen)
00890 TEMP void THIS::ColorSymbolTable(const TmtcGenerator& rOtherGen) {
00891   ColorSymbolTable(rOtherGen.ColorSymbolTablep());
00892 }
00893 
00894 // InsColoredState(rStateName, rColorName)
00895 TEMP Idx THIS::InsColoredState(const std::string& rStateName, const std::string& rColorName) {
00896   FD_DG("mtcGenerator(" << this << ")::InsColoredState(rStateName, colorName)");
00897   StateAttr *attr;
00898   Idx index;
00899 #ifdef FAUDES_CHECKED
00900   try {
00901     index = BASE::InsState(rStateName);
00902   }
00903   catch (faudes::Exception& exception){
00904     std::stringstream errstr;
00905     errstr << "Name \"" << rStateName << "\" already exists" << std::endl;
00906     throw Exception("mtcGenerator::InsColoredState(rStateName, rColorName)", errstr.str(), 104);
00907   }
00908   try {
00909     attr = BASE::StateAttributep(index);
00910   }
00911   catch (faudes::Exception& exception){
00912     std::stringstream errstr;
00913     errstr << "Index " << index << " not member of set" << std::endl;
00914     throw Exception("mtcGenerator::InsColoredState(stateIndex, colorIndex)", errstr.str(), 200);
00915   }
00916   try {
00917     attr->Colors().Insert(rColorName);
00918   }
00919   catch (faudes::Exception& exception){
00920     std::stringstream errstr;
00921     errstr << "Name already exists / invalid name: " << rColorName << std::endl;
00922     throw Exception("mtcGenerator::InsColoredState(stateIndex, rColorName)", errstr.str(), 104);
00923   }
00924 #else
00925   index = BASE::InsState(rStateName);
00926   attr = Attributep(index);
00927   attr->Colors().Insert(rColorName);
00928 #endif
00929   return index;
00930 }
00931 
00932 // InsColoredState(rStateName, colorIndex)
00933 TEMP Idx THIS::InsColoredState(const std::string& rStateName, const Idx colorIndex) {
00934   Idx index = BASE::InsState(rStateName);
00935   StateAttr *attr = BASE::StateAttributep(index);
00936 #ifdef FAUDES_CHECKED
00937   try {
00938     attr->Colors().Insert(colorIndex);
00939   }
00940   catch (faudes::Exception& exception){
00941     std::stringstream errstr;
00942     errstr << "Color index " << colorIndex << " not known to symbol table" << std::endl;
00943     throw Exception("mtcGenerator::InsColoredState(rStateName, colorIndex)", errstr.str(), 200);
00944   }
00945 #else
00946   attr->Colors().Insert(colorIndex);
00947 #endif
00948   return index;
00949 }
00950 
00951 // InsColoredState(rStateName, rColors)
00952 TEMP Idx THIS::InsColoredState(const std::string& rStateName, const ColorSet& rColors) {
00953   Idx index = BASE::InsState(rStateName);
00954   InsColors(index, rColors);
00955   return index;
00956 }
00957 
00958 // InsColoredState(rColors)
00959 TEMP Idx THIS::InsColoredState(const ColorSet& rColors) {
00960   Idx index = BASE::InsState();
00961   InsColors(index, rColors);
00962   return index;
00963 }
00964 
00965 // InsColor(stateIndex, rColorName)
00966 TEMP Idx THIS::InsColor(Idx stateIndex, const std::string& rColorName) {
00967   StateAttr *attr;
00968   Idx index;
00969 #ifdef FAUDES_CHECKED
00970   try {
00971     attr = BASE::StateAttributep(stateIndex);
00972   }
00973   catch (faudes::Exception& exception){
00974     std::stringstream errstr;
00975     errstr << "State index " << stateIndex << " not member of set" << std::endl;
00976     throw Exception("mtcGenerator::InsColor(stateIndex, colorIndex)", errstr.str(), 200);
00977   }
00978   try {
00979     index = attr->Colors().Insert(rColorName);
00980   }
00981   catch (faudes::Exception& exception){
00982     std::stringstream errstr;
00983     errstr << "Name already exists / invalid name: " << rColorName << std::endl;
00984     throw Exception("mtcGenerator::InsColor(stateIndex, rColorName)", errstr.str(), 104);
00985   }
00986 #else
00987   attr = Attributep(stateIndex);
00988   index = attr->Colors().Insert(rColorName);
00989 #endif
00990   return index;
00991 }
00992 
00993 // InsColor(stateIndex, colorIndex)
00994 TEMP void THIS::InsColor(Idx stateIndex, Idx colorIndex) {
00995   StateAttr *attr;
00996 #ifdef FAUDES_CHECKED
00997   try {
00998     attr = BASE::StateAttributep(stateIndex);
00999   }
01000   catch (faudes::Exception& exception){
01001     std::stringstream errstr;
01002     errstr << "State index " << stateIndex << " not member of set" << std::endl;
01003     throw Exception("mtcGenerator::InsColor(stateIndex, colorIndex)", errstr.str(), 200);
01004   }
01005   try {
01006     attr->Colors().Insert(colorIndex);
01007   }
01008   catch (faudes::Exception& exception){
01009     std::stringstream errstr;
01010     errstr << "Color index " << colorIndex << " not known to symbol table" << std::endl;
01011     throw Exception("mtcGenerator::InsColor(stateIndex, colorIndex)", errstr.str(), 200);
01012   }
01013 #else
01014   attr = Attributep(stateIndex);
01015   attr->Colors().Insert(colorIndex);
01016 #endif
01017 }
01018 
01019 // InsColors(stateIndex, rColors)
01020 TEMP void THIS::InsColors(Idx stateIndex, const ColorSet& rColors) {
01021 #ifdef FAUDES_CHECKED
01022   if(rColors.SymbolTablep() != mpColorSymbolTable) {
01023     std::stringstream errstr;
01024     errstr << "Symbol table mismatch" << std::endl;
01025     throw Exception("mtcGenerator::InsColors(stateIndex, rColors)", errstr.str(), 88);
01026   }
01027 #endif
01028   StateAttr *attr;
01029 #ifdef FAUDES_CHECKED
01030   try {
01031     attr = BASE::StateAttributep(stateIndex);
01032   }
01033   catch (faudes::Exception& exception){
01034     std::stringstream errstr;
01035     errstr << "State index " << stateIndex << " not member of set" << std::endl;
01036     throw Exception("mtcGenerator::InsColors(stateIndex, rColors)", errstr.str(), 200);
01037   }
01038   try {
01039     attr->Colors().InsertSet(rColors);
01040   }
01041   catch (faudes::Exception& exception){
01042     std::stringstream errstr;
01043     errstr << "Symbol table mismach" << std::endl;
01044     throw Exception("mtcGenerator::InsColors(stateIndex, rColors)", errstr.str(), 200);
01045   }
01046 #else
01047   attr = Attributep(stateIndex);
01048   attr->Colors().InsertSet(rColors);
01049 #endif
01050 }
01051 
01052 // DelColor(stateIndex, rColorName)
01053 TEMP void THIS::DelColor(Idx stateIndex, const std::string& rColorName) {
01054   StateAttr *attr;
01055   Idx index;
01056 #ifdef FAUDES_CHECKED
01057   try {
01058     attr = BASE::StateAttributep(stateIndex);
01059   }
01060   catch (faudes::Exception& exception){
01061     std::stringstream errstr;
01062     errstr << "State index " << stateIndex << " not member of set" << std::endl;
01063     throw Exception("mtcGenerator::DelColor(stateIndex, rColorName)", errstr.str(), 200);
01064   }
01065   index = ColorIndex(rColorName);
01066   try {
01067     attr->Colors().Erase(index);
01068   }
01069   catch (faudes::Exception& exception){
01070     std::stringstream errstr;
01071     errstr << "Color name \"" << rColorName << "\" not found in NameSet" << std::endl;
01072     throw Exception("mtcGenerator::DelColor(stateIndex, rColorName)", errstr.str(), 202);
01073   }
01074 #else
01075   attr = Attributep(stateIndex);
01076   index = ColorIndex(rColorName);
01077   attr->Colors().Erase(index);
01078 #endif
01079   CheckSymbolTable(index);
01080 }
01081 
01082 // DelColor(stateIndex, colorIndex)
01083 TEMP void THIS::DelColor(Idx stateIndex, Idx colorIndex) {
01084   StateAttr *attr;
01085   bool res;
01086 #ifdef FAUDES_CHECKED
01087   try {
01088     attr = BASE::StateAttributep(stateIndex);
01089   }
01090   catch (faudes::Exception& exception){
01091     std::stringstream errstr;
01092     errstr << "State index " << stateIndex << " not member of set" << std::endl;
01093     throw Exception("mtcGenerator::DelColor(stateIndex, colorIndex)", errstr.str(), 200);
01094   }
01095 #else
01096   attr = BASE::StateAttributep(stateIndex);
01097 #endif
01098   res = attr->Colors().Erase(colorIndex);
01099   if (!res) {
01100     std::stringstream errstr;
01101     errstr << "Color index " << colorIndex << " not found in generator" << std::endl;
01102     throw Exception("mtcGenerator::DelColor(stateIndex, colorIndex)", errstr.str(), 205);
01103   }
01104   CheckSymbolTable(colorIndex);
01105 }
01106 
01107 // DelColor(rColorName)
01108 TEMP void THIS::DelColor(const std::string& rColorName) {
01109   StateSet::Iterator lit;
01110   StateAttr *attr;
01111 
01112   Idx index = ColorIndex(rColorName);
01113 
01114   for (lit = BASE::pStates->Begin(); lit != BASE::pStates->End(); lit++) {
01115     attr = BASE::StateAttributep(*lit);
01116     attr->Colors().Erase(index);
01117   }
01118   CheckSymbolTable(index);
01119 }
01120 
01121 // DelColor(colorIndex)
01122 TEMP void THIS::DelColor(Idx colorIndex) {
01123   StateSet::Iterator lit;
01124   StateAttr *attr;
01125   for (lit = BASE::pStates->Begin(); lit != BASE::pStates->End(); lit++) {
01126     attr = BASE::StateAttributep(*lit);
01127     attr->Colors().Erase(colorIndex);
01128   }
01129   CheckSymbolTable(colorIndex);
01130 }
01131 
01132 // ClrColors(stateIndex)
01133 TEMP void THIS::ClrColors(Idx stateIndex) {
01134   StateAttr *attr;
01135   ColorSet::Iterator cit;
01136   ColorSet delColors(mpColorSymbolTable);
01137 #ifdef FAUDES_CHECKED
01138   try {
01139     attr = BASE::StateAttributep(stateIndex);
01140   }
01141   catch (faudes::Exception& exception){
01142     std::stringstream errstr;
01143     errstr << "State index " << stateIndex << " not member of set" << std::endl;
01144     throw Exception("mtcGenerator::ClrColors(stateIndex)", errstr.str(), 200);
01145   }
01146 #else
01147   attr = BASE::StateAttributep(stateIndex);
01148 #endif
01149   delColors.InsertSet(attr->Colors());
01150   attr->Colors().Clear();
01151   CheckSymbolTable(delColors);
01152 }
01153 
01154 // DelColorName(colorIndex)
01155 TEMP void THIS::DelColorName(Idx colorIndex) {
01156   ColorSymbolTablep()->ClrEntry(colorIndex);
01157 }
01158 
01159 // Colors(rColors)
01160 TEMP void THIS::Colors(ColorSet& rColors) const {
01161 #ifdef FAUDES_CHECKED
01162   if(rColors.SymbolTablep() != mpColorSymbolTable) {
01163     std::stringstream errstr;
01164     errstr << "Symbol table mismatch" << std::endl;
01165     throw Exception("mtcGenerator::Colors", errstr.str(), 88);
01166   }
01167 #endif
01168   StateSet::Iterator lit;
01169   for (lit = BASE::pStates->Begin(); lit != BASE::pStates->End(); lit++) {
01170     const StateAttr& attr = BASE::pStates->Attribute(*lit);
01171     rColors.InsertSet(attr.Colors());
01172   }
01173 }
01174 
01175 // Colors()
01176 TEMP ColorSet THIS::Colors(void) const {
01177   StateSet::Iterator lit;
01178   ColorSet colors(mpColorSymbolTable);
01179   for (lit = BASE::pStates->Begin(); lit != BASE::pStates->End(); lit++) {
01180     const StateAttr& attr = BASE::pStates->Attribute(*lit);
01181     colors.InsertSet(attr.Colors());
01182   }
01183   return colors;
01184 }
01185 
01186 // Colors(stateIndex)
01187 TEMP const ColorSet& THIS::Colors(Idx stateIndex) const {
01188   const StateAttr* attrp;
01189 #ifdef FAUDES_CHECKED
01190   try {
01191     attrp = &BASE::pStates->Attribute(stateIndex);
01192   }
01193   catch (faudes::Exception& exception){
01194     std::stringstream errstr;
01195     errstr << "State index " << stateIndex << " not member of set" << std::endl;
01196     throw Exception("mtcGenerator::Colors(stateIndex)", errstr.str(), 200);
01197   }
01198 #else
01199   attrp = &BASE::pStates->Attribute(stateIndex);
01200 #endif
01201   return attrp->Colors();
01202 }
01203 
01204 // CheckSymbolTable(colorIndex)
01205 TEMP void THIS::CheckSymbolTable(Idx colorIndex) {
01206   if (ColorSymbolTablep() != ColorSet::StaticSymbolTablep()) {
01207     ColorSet colors(mpColorSymbolTable);
01208     Colors(colors);
01209     if (!colors.Exists(colorIndex))
01210       DelColorName(colorIndex);
01211   }
01212 }
01213 
01214 // CheckSymbolTable(rColors)
01215 TEMP void THIS::CheckSymbolTable(ColorSet& rColors) {
01216 #ifdef FAUDES_CHECKED
01217   if(rColors.SymbolTablep() != mpColorSymbolTable) {
01218     std::stringstream errstr;
01219     errstr << "Symbol table mismatch" << std::endl;
01220     throw Exception("mtcGenerator::CheckSymbolTable", errstr.str(), 88);
01221   }
01222 #endif
01223   if (ColorSymbolTablep() != ColorSet::StaticSymbolTablep()) {
01224     ColorSet colors(mpColorSymbolTable);
01225     // all generator's colors are inserted
01226     Colors(colors);
01227     ColorSet::Iterator cit;
01228     for(cit = rColors.Begin(); cit != rColors.End(); cit++) {
01229       // are colors from rColors still in use?
01230       if(!colors.Exists(*cit)) DelColorName(*cit);
01231     }
01232   }
01233 }
01234 
01235 // ExistsColor(colorIndex)
01236 TEMP bool THIS::ExistsColor(Idx colorIndex) const {
01237   StateSet::Iterator lit;
01238   for (lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
01239     if (ExistsColor(*lit, colorIndex)) return true;
01240   }
01241   return false;
01242 }
01243 
01244 // ExistsColor(colorName)
01245 TEMP bool THIS::ExistsColor(const std::string& rColorName) const {
01246   Idx colorIndex = ColorIndex(rColorName);
01247 #ifdef FAUDES_CHECKED
01248   if (colorIndex == 0) {
01249     std::stringstream errstr;
01250     errstr << "Color name \"" << rColorName << "\" not found in symbol table  " << std::endl;
01251     throw Exception("mtcGenerator::ExistsColor(rColorName)", errstr.str(), 202);
01252   }
01253 #endif
01254   return ExistsColor(colorIndex);
01255 }
01256 
01257 // ColorName(index)
01258 TEMP std::string THIS::ColorName(Idx colorIndex) const {
01259   return ColorSymbolTablep()->Symbol(colorIndex);
01260 }
01261 
01262 // ColorIndex(rColorName)
01263 TEMP Idx THIS::ColorIndex(const std::string& rColorName) const {
01264   return ColorSymbolTablep()->Index(rColorName);
01265 }
01266 
01267 // CStr(index)
01268 TEMP std::string THIS::CStr(Idx index) const {
01269   return ColorName(index);
01270 }
01271 
01272 // ExistsColor(stateIndex, colorIndex)
01273 TEMP bool THIS::ExistsColor(Idx stateIndex, Idx colorIndex) const {
01274 #ifdef FAUDES_CHECKED
01275   try {
01276     return BASE::pStates->Attribute(stateIndex).Colors().Exists(colorIndex);
01277   }
01278   catch (faudes::Exception& exception){
01279     std::stringstream errstr;
01280     errstr << "State index " << stateIndex << " not member of set" << std::endl;
01281     throw Exception("mtcGenerator::ExistsColor(stateIndex, colorIndex)", errstr.str(), 200);
01282   }
01283 #else
01284   return BASE::pStates->Attribute(stateIndex).Colors().Exists(colorIndex);
01285 #endif
01286 }
01287 
01288 // StateColors(stateIndex, rColors)
01289 /*
01290 TEMP void THIS::StateColors(Idx stateIndex, ColorSet& rColors) const {
01291 #ifdef FAUDES_CHECKED
01292   if(rColors.SymbolTablep() != mpColorSymbolTable) {
01293     std::stringstream errstr;
01294     errstr << "Symbol table mismatch" << std::endl;
01295     throw Exception("mtcGenerator::CheckSymbolTable", errstr.str(), 88);
01296   }
01297 #endif
01298   rColors.Clear();
01299 #ifdef FAUDES_CHECKED
01300   try {
01301     StateAttr attr = BASE::pStates->Attribute(stateIndex);
01302     rColors.InsertSet(attr.Colors());
01303   }
01304   catch (faudes::Exception& exception){
01305     std::stringstream errstr;
01306     errstr << "State index " << stateIndex << " not member of set" << std::endl;
01307     throw Exception("mtcGenerator::StateColors(stateIndex, rColors)", errstr.str(), 200);
01308   }
01309 #else
01310   StateAttr attr = BASE::pStates->Attribute(stateIndex);
01311   rColors.InsertSet(attr.Colors());
01312 #endif
01313 }
01314 */
01315 
01316 // StateColors(stateIndex)
01317 /*
01318 TEMP ColorSet THIS::StateColors(Idx stateIndex) const {
01319   ColorSet colors(mpColorSymbolTable);
01320 #ifdef FAUDES_CHECKED
01321   try {
01322     StateAttr attr = BASE::pStates->Attribute(stateIndex);
01323     colors.InsertSet(attr.Colors());
01324   }
01325   catch (faudes::Exception& exception){
01326     std::stringstream errstr;
01327     errstr << "State index " << stateIndex << " not member of set" << std::endl;
01328     throw Exception("mtcGenerator::StateColors(stateIndex, rColors)", errstr.str(), 200);
01329   }
01330 #else
01331   StateAttr attr = BASE::pStates->Attribute(stateIndex);
01332   colors.InsertSet(attr.Colors());
01333 #endif
01334   return colors;
01335 }
01336 
01337 */
01338 
01339 // DotWrite(rFileName)
01340 TEMP void THIS::DotWrite(const std::string& rFileName) const {
01341   FD_DG("TmtcGenerator(" << this << ")::DotWrite(" << rFileName << ")");
01342   TaIndexSet<StateAttr> coloredStates;
01343   StateSet::Iterator it;
01344   BASE::SetMinStateIndexMap();
01345   typename TransSet::Iterator tit;
01346   try {
01347     std::ofstream stream;
01348     stream.exceptions(std::ios::badbit|std::ios::failbit);
01349     stream.open(rFileName.c_str());
01350     stream << "// dot output generated by libFAUDES TmtcGenerator" << std::endl;
01351     stream << "digraph \"" << BASE::Name() << "\" {" << std::endl;
01352     stream << "  rankdir=LR" << std::endl;
01353     stream << "  node [shape=circle];" << std::endl;
01354     stream << std::endl;
01355     stream << "  // initial states" << std::endl;
01356     int i = 1;
01357     for (it = BASE::InitStatesBegin(); it != BASE::InitStatesEnd(); ++it) {
01358       std::string xname= BASE::StateName(*it);
01359       if(xname=="") xname=ToStringInteger(static_cast<long int>(BASE::MinStateIndex(*it)));
01360       stream << "  dot_dummyinit_" << i << " [shape=none, label=\"\" ];" << std::endl;
01361       stream << "  dot_dummyinit_" << i << " -> \"" << xname << "\";" << std::endl; 
01362       i++;
01363     }
01364     stream << std::endl;
01365 
01366     // uncolored states - output
01367     stream << "  // uncolored states" << std::endl;
01368     for (it = BASE::pStates->Begin(); it != BASE::pStates->End(); ++it) {
01369       // does the state have a colored attribute?
01370       const StateAttr& attr = BASE::StateAttribute(*it);
01371       // handling colored states - copy to coloredStates
01372       if (!attr.IsDefault()) {
01373         coloredStates.Insert(*it, attr);
01374       }
01375       else {
01376         std::string xname=BASE::StateName(*it);
01377         if(xname=="") xname=ToStringInteger(BASE::MinStateIndex(*it));
01378         stream << "  \"" << xname << "\";" << std::endl;
01379       }
01380     }
01381 
01382     // colored states - output
01383     std::vector<std::string> ColorVector;
01384     ColorVector.push_back("blue");
01385     ColorVector.push_back("red");
01386     ColorVector.push_back("magenta");
01387     ColorVector.push_back("green");
01388     ColorVector.push_back("darkorange");
01389     ColorVector.push_back("cyan");
01390     ColorVector.push_back("navy");
01391     ColorVector.push_back("brown");
01392     ColorVector.push_back("green4");
01393     ColorVector.push_back("yellow");
01394     ColorVector.push_back("darkviolet");
01395     ColorVector.push_back("firebrick");
01396     ColorVector.push_back("greenyellow");
01397     ColorVector.push_back("peru");
01398     ColorVector.push_back("skyblue");
01399     ColorVector.push_back("darkgreen");
01400     ColorVector.push_back("violetred");
01401     ColorVector.push_back("lightsalmon");
01402     ColorVector.push_back("seagreen");
01403     ColorVector.push_back("saddlebrown");
01404     ColorVector.push_back("slateblue");
01405     ColorVector.push_back("thistle");
01406     ColorVector.push_back("turquoise4");
01407     ColorVector.push_back("gold2");
01408     ColorVector.push_back("sandybrown");
01409     ColorVector.push_back("aquamarine3");
01410     ColorVector.push_back("darkolivegreen");
01411     ColorVector.push_back("yellow4");
01412 
01413     stream << std::endl;
01414     stream << "  // colored states" << std::endl;
01415     int clustNr = 0;
01416     for (it = coloredStates.Begin(); it != coloredStates.End(); it++) {
01417       int count = 0;
01418       std::string xname=BASE::StateName(*it);
01419       if(xname=="") xname=ToStringInteger(static_cast<long int>(BASE::MinStateIndex(*it)));
01420       const StateAttr& attr = coloredStates.Attribute(*it);
01421       if (attr.Colors().Size() > 1) {
01422         for(ColorSet::Iterator cit = attr.ColorsBegin(); cit != attr.ColorsEnd(); cit++) {
01423           stream << "  subgraph cluster_" << clustNr++ << " {color=" << ColorVector.at(*cit-1) << ";" << std::endl;
01424           count++;
01425         }
01426         stream << "    \"" << xname << "\" " << std::endl << "  ";
01427         for (int i=0; i<count; i++) {
01428           stream << "}";
01429         }
01430         stream << std::endl;
01431       }
01432       else if (attr.Colors().Size() == 1) {
01433         ColorSet::Iterator cit;
01434         if ((cit = attr.ColorsBegin()) != attr.ColorsEnd())
01435           stream << "  \"" << xname << "\" " << "[color=" << ColorVector.at(*cit-1) << "]" << std::endl;
01436       }
01437     }
01438     stream << std::endl;
01439 
01440     // marked states
01441     stream << "  // marked states" << std::endl;
01442     for (it = BASE::MarkedStatesBegin(); it != BASE::MarkedStatesEnd(); ++it) {
01443       std::string xname= BASE::StateName(*it);
01444       if(xname=="") xname=ToStringInteger(static_cast<long int>(BASE::MinStateIndex(*it)));
01445       stream << "  \"" << xname << "\";" << std::endl; 
01446       i++;
01447     }
01448 
01449     // transitions
01450     stream << std::endl;
01451     stream << "  // transition relation" << std::endl;
01452     for (tit = BASE::TransRelBegin(); tit != BASE::TransRelEnd(); ++tit) {
01453       std::string x1name= BASE::StateName(tit->X1);
01454       if(x1name=="") x1name=ToStringInteger(BASE::MinStateIndex(tit->X1));
01455       std::string x2name= BASE::StateName(tit->X2);
01456       if(x2name=="") x2name=ToStringInteger(BASE::MinStateIndex(tit->X2));
01457       stream << "  \"" << x1name  << "\" -> \"" << x2name << "\" [label=\"" << BASE::EventName(tit->Ev) << "\"];" << std::endl;
01458     }
01459     stream << "};" << std::endl;
01460     stream.close();
01461   }
01462   catch (std::ios::failure&) {    
01463     throw Exception("TaGenerator::DotWrite", 
01464         "Exception opening/writing dotfile \""+rFileName+"\"", 3);
01465   }
01466   BASE::ClearMinStateIndexMap();
01467 }
01468 
01469 // StateColorMap()
01470 TEMP std::map<Idx,ColorSet> THIS::StateColorMap(void) const {
01471   StateSet::Iterator lit;
01472   std::map<Idx,ColorSet> map;
01473   StateSet cstates = ColoredStates();
01474   for (lit = cstates.Begin(); lit != cstates.End(); lit++) {
01475     map.insert(std::make_pair(*lit, Colors(*lit)));
01476     FD_DF("make_pair(" << ToStringInteger(*lit) << ", " << StateColors(*lit).ToString() << ")");
01477   }
01478   return map;
01479 }
01480 
01481 // ColoredStates(ColorIndex)
01482 TEMP StateSet THIS::ColoredStates(Idx colorIndex) const {
01483   StateSet::Iterator lit;
01484   StateSet coloredStates;
01485   for (lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
01486     if(ExistsColor(*lit, colorIndex)) coloredStates.Insert(*lit);
01487   }
01488   return coloredStates;
01489 }
01490 
01491 // ColoredStates(ColorName)
01492 TEMP StateSet THIS::ColoredStates(const std::string& rColorName) const{
01493   Idx colorIndex = ColorIndex(rColorName);
01494   return ColoredStates(colorIndex);
01495 }
01496 
01497 // ColoredStates()
01498 TEMP StateSet THIS::ColoredStates() const {
01499   StateSet::Iterator lit;
01500   StateSet coloredStates;
01501   for(lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
01502     if(IsColored(*lit)) coloredStates.Insert(*lit);
01503   }
01504   return coloredStates;
01505 }
01506 
01507 // UncoloredStates()
01508 TEMP StateSet THIS::UncoloredStates() const {
01509   StateSet::Iterator lit;
01510   StateSet uncoloredStates;
01511   for (lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
01512     if (!IsColored(*lit)) uncoloredStates.Insert(*lit);
01513   }
01514   return uncoloredStates;
01515 }
01516 
01517 // IsColored()
01518 TEMP bool THIS::IsColored(void) const {
01519   StateSet::Iterator lit;
01520   for(lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
01521     if(IsColored(*lit)) return true;
01522   }
01523   return false;
01524 }
01525 
01526 // IsColored(stateIndex)
01527 TEMP bool THIS::IsColored(Idx stateIndex) const {
01528 #ifdef FAUDES_CHECKED
01529   try {
01530     return !BASE::pStates->Attribute(stateIndex).Colors().Empty();
01531   }
01532   catch (faudes::Exception& exception){
01533     std::stringstream errstr;
01534     errstr << "State index " << stateIndex << " not member of set" << std::endl;
01535     throw Exception("mtcGenerator::IsColored(stateIndex)", errstr.str(), 200);
01536   }
01537 #else
01538   return !BASE::pStates->Attribute(stateIndex).Colors().Empty();
01539 #endif
01540 }
01541 
01542 TEMP StateSet THIS::StronglyCoaccessibleSet(void) const {
01543   mtcGenerator tmp(*this);
01544   StateSet stronglyCoac, notStronglyCoac;
01545   ColorSet colors;
01546   stronglyCoac = BASE::States();
01547   Colors(colors);
01548 
01549   ColorSet::Iterator cit = colors.Begin();
01550   ColorSet::Iterator cit_end = colors.End();
01551 
01552   for (; cit != cit_end; cit++) {
01553     StateSet tmp1, tmp2;
01554     StateSet states = ColoredStates(*cit);
01555     tmp.InjectMarkedStates(states);
01556     tmp1 = tmp.CoaccessibleSet();
01557     tmp2 = stronglyCoac * tmp1;
01558     stronglyCoac = tmp2;
01559   }
01560   tmp.ClearMarkedStates();
01561   return stronglyCoac;
01562 }
01563 
01564 TEMP bool THIS::StronglyCoaccessible(void) {
01565   StateSet stronglyCoacSet = StronglyCoaccessibleSet();
01566   StateSet notStronglyCoac = BASE::States() - stronglyCoacSet;
01567   BASE::DelStates(notStronglyCoac);
01568   return (StronglyCoaccessibleSet() == BASE::States());
01569 }
01570 
01571 TEMP bool THIS::IsStronglyCoaccessible(void) const {
01572   return (StronglyCoaccessibleSet() == BASE::States());
01573 }
01574 
01575 // StronglyTrimSet()
01576 TEMP StateSet THIS::StronglyTrimSet(void) const {
01577   FD_DF("TmtcGenerator::StronglyTrimSet: trim states: "
01578   << StateSet(BASE::AccessibleSet() * StronglyCoaccessibleSet()).ToString());
01579   return BASE::AccessibleSet() * StronglyCoaccessibleSet();
01580 }
01581 
01582 // StronglyTrim()
01583 TEMP bool THIS::StronglyTrim(void) {
01584   // better: compute sets and do one state delete
01585   bool accessiblebool = BASE::Accessible();
01586   bool coaccessiblebool = StronglyCoaccessible();
01587   FD_DF("TmtcGenerator::StronglyTrim: trim states: " << mpStates->ToString());
01588   if (accessiblebool && coaccessiblebool) {
01589     FD_DF("TmtcGenerator::StronglyTrim: generator is trim");
01590     return true;
01591   }
01592   FD_DF("TmtcGenerator::StronglyTrim: generator is not trim");
01593   return false;
01594 }
01595 
01596 // IsStronglyTrim()
01597 TEMP bool THIS::IsStronglyTrim(void) const {
01598   if (BASE::IsAccessible() && IsStronglyCoaccessible()) {
01599     FD_DF("TmtcGenerator::IsStronglyTrim: generator is strongly trim");
01600     return true;
01601   }
01602   else {
01603     FD_DF("TmtcGenerator::IsStronglyTrim: generator is not strongly trim");
01604     return false;
01605   }
01606 }
01607 
01608 // NewColorSymbolTable()
01609 TEMP void THIS::NewColorSymbolTable() {
01610 
01611   StateSet::Iterator lit;
01612   StateAttr *attr;
01613 
01614   StateSet coloredStates = ColoredStates();
01615   coloredStates.Write();
01616   SymbolTable *tmp;
01617   tmp = new SymbolTable;
01618 
01619   // iterate over all colored states
01620   for (lit = coloredStates.Begin(); lit != coloredStates.End(); lit++) {
01621     // get attributes for current state
01622     attr = BASE::pStates->Attributep(*lit);
01623     ColorSet::Iterator cit, cit_end;
01624     cit_end = attr->ColorsEnd();
01625     // iterate over all colors of the current state
01626     for (cit = attr->ColorsBegin(); cit != cit_end; cit++) {
01627 #ifdef FAUDES_CHECKED
01628       try {
01629         // insert color indices and color names to new color symbol table
01630         tmp->InsEntry(*cit, attr->Colors().SymbolicName(*cit));
01631       }
01632       catch (faudes::Exception& exception){
01633         std::stringstream errstr;
01634         errstr << "Could not insert index \"" << *cit << "\" and symbol \"" << 
01635     attr->Colors().SymbolicName(*cit) << "\" to symbol table" << std::endl;
01636         throw Exception("mtcGenerator::NewColorSymbolTable()", errstr.str(), 44);
01637       }
01638 #else
01639       tmp->InsEntry(*cit, attr->Colors().SymbolicName(*cit));
01640 #endif
01641     }
01642     // reset color symbol table pointers
01643     mpColorSymbolTable = tmp;
01644     attr->ColorSymTab(tmp);
01645   }
01646 }
01647 
01648 // ClearStateAttributes()
01649 TEMP void THIS::ClearStateAttributes() {
01650   if(ColorSet::StaticSymbolTablep() != mpColorSymbolTable) mpColorSymbolTable->Clear();
01651   BASE::ClearStateAttributes();
01652 }
01653 
01654 
01655 // DoSWrite(rTw&)
01656 TEMP void THIS::DoSWrite(TokenWriter& rTw) const {
01657   // set up color statistics
01658   std::set<Idx> colcount;
01659   StateSet::Iterator sit;
01660   for(sit = BASE::StatesBegin(); sit != BASE::StatesEnd(); sit++) {
01661     colcount.insert(Colors(*sit).Size());
01662   }
01663   // convert to string
01664   std::multiset<Idx>::iterator cit;
01665   std::stringstream countstr;
01666   for(cit = colcount.begin(); cit != colcount.end(); cit++) {
01667     countstr << *cit << " ";
01668   }
01669   // write
01670   BASE::DoSWrite(rTw);
01671   rTw.WriteComment(" Colors (all):  " + ToStringInteger(Colors().Size()) );
01672   rTw.WriteComment(" Colors (dist): " + countstr.str());
01673   rTw.WriteComment("");
01674 }
01675 
01676 #undef BASE
01677 #undef THIS
01678 #undef TEMP
01679 
01680 } // namespace faudes
01681 
01682 #endif

libFAUDES 2.14g --- 2009-12-3 --- c++ source docu by doxygen 1.5.6