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 bool IsStronglyCoaccessible(const mtcGenerator& rGen);
00753 
00754 /** 
00755  * RTI wrapper function. See also mtcGenerator::IsStronglyTrim().
00756  * \ingroup GeneratorFunctions
00757  */
00758 bool IsStronglyTrim(const mtcGenerator& rGen);
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 // DotWrite(rFileName)
01289 TEMP void THIS::DotWrite(const std::string& rFileName) const {
01290   FD_DG("TmtcGenerator(" << this << ")::DotWrite(" << rFileName << ")");
01291   TaIndexSet<StateAttr> coloredStates;
01292   StateSet::Iterator it;
01293   BASE::SetMinStateIndexMap();
01294   typename TransSet::Iterator tit;
01295   try {
01296     std::ofstream stream;
01297     stream.exceptions(std::ios::badbit|std::ios::failbit);
01298     stream.open(rFileName.c_str());
01299     stream << "// dot output generated by libFAUDES TmtcGenerator" << std::endl;
01300     stream << "digraph \"" << BASE::Name() << "\" {" << std::endl;
01301     stream << "  rankdir=LR" << std::endl;
01302     stream << "  node [shape=circle];" << std::endl;
01303     stream << std::endl;
01304     stream << "  // initial states" << std::endl;
01305     int i = 1;
01306     for (it = BASE::InitStatesBegin(); it != BASE::InitStatesEnd(); ++it) {
01307       std::string xname= BASE::StateName(*it);
01308       if(xname=="") xname=ToStringInteger(static_cast<long int>(BASE::MinStateIndex(*it)));
01309       stream << "  dot_dummyinit_" << i << " [shape=none, label=\"\" ];" << std::endl;
01310       stream << "  dot_dummyinit_" << i << " -> \"" << xname << "\";" << std::endl; 
01311       i++;
01312     }
01313     stream << std::endl;
01314 
01315     // uncolored states - output
01316     stream << "  // uncolored states" << std::endl;
01317     for (it = BASE::pStates->Begin(); it != BASE::pStates->End(); ++it) {
01318       // does the state have a colored attribute?
01319       const StateAttr& attr = BASE::StateAttribute(*it);
01320       // handling colored states - copy to coloredStates
01321       if (!attr.IsDefault()) {
01322         coloredStates.Insert(*it, attr);
01323       }
01324       else {
01325         std::string xname=BASE::StateName(*it);
01326         if(xname=="") xname=ToStringInteger(BASE::MinStateIndex(*it));
01327         stream << "  \"" << xname << "\";" << std::endl;
01328       }
01329     }
01330 
01331     // colored states - output
01332     std::vector<std::string> ColorVector;
01333     ColorVector.push_back("blue");
01334     ColorVector.push_back("red");
01335     ColorVector.push_back("magenta");
01336     ColorVector.push_back("green");
01337     ColorVector.push_back("darkorange");
01338     ColorVector.push_back("cyan");
01339     ColorVector.push_back("navy");
01340     ColorVector.push_back("brown");
01341     ColorVector.push_back("green4");
01342     ColorVector.push_back("yellow");
01343     ColorVector.push_back("darkviolet");
01344     ColorVector.push_back("firebrick");
01345     ColorVector.push_back("greenyellow");
01346     ColorVector.push_back("peru");
01347     ColorVector.push_back("skyblue");
01348     ColorVector.push_back("darkgreen");
01349     ColorVector.push_back("violetred");
01350     ColorVector.push_back("lightsalmon");
01351     ColorVector.push_back("seagreen");
01352     ColorVector.push_back("saddlebrown");
01353     ColorVector.push_back("slateblue");
01354     ColorVector.push_back("thistle");
01355     ColorVector.push_back("turquoise4");
01356     ColorVector.push_back("gold2");
01357     ColorVector.push_back("sandybrown");
01358     ColorVector.push_back("aquamarine3");
01359     ColorVector.push_back("darkolivegreen");
01360     ColorVector.push_back("yellow4");
01361 
01362     stream << std::endl;
01363     stream << "  // colored states" << std::endl;
01364     int clustNr = 0;
01365     for (it = coloredStates.Begin(); it != coloredStates.End(); it++) {
01366       int count = 0;
01367       std::string xname=BASE::StateName(*it);
01368       if(xname=="") xname=ToStringInteger(static_cast<long int>(BASE::MinStateIndex(*it)));
01369       const StateAttr& attr = coloredStates.Attribute(*it);
01370       if (attr.Colors().Size() > 1) {
01371         for(ColorSet::Iterator cit = attr.ColorsBegin(); cit != attr.ColorsEnd(); cit++) {
01372           stream << "  subgraph cluster_" << clustNr++ << " {color=" << ColorVector.at(*cit-1) << ";" << std::endl;
01373           count++;
01374         }
01375         stream << "    \"" << xname << "\" " << std::endl << "  ";
01376         for (int i=0; i<count; i++) {
01377           stream << "}";
01378         }
01379         stream << std::endl;
01380       }
01381       else if (attr.Colors().Size() == 1) {
01382         ColorSet::Iterator cit;
01383         if ((cit = attr.ColorsBegin()) != attr.ColorsEnd())
01384           stream << "  \"" << xname << "\" " << "[color=" << ColorVector.at(*cit-1) << "]" << std::endl;
01385       }
01386     }
01387     stream << std::endl;
01388 
01389     // marked states
01390     stream << "  // marked states" << std::endl;
01391     for (it = BASE::MarkedStatesBegin(); it != BASE::MarkedStatesEnd(); ++it) {
01392       std::string xname= BASE::StateName(*it);
01393       if(xname=="") xname=ToStringInteger(static_cast<long int>(BASE::MinStateIndex(*it)));
01394       stream << "  \"" << xname << "\";" << std::endl; 
01395       i++;
01396     }
01397 
01398     // transitions
01399     stream << std::endl;
01400     stream << "  // transition relation" << std::endl;
01401     for (tit = BASE::TransRelBegin(); tit != BASE::TransRelEnd(); ++tit) {
01402       std::string x1name= BASE::StateName(tit->X1);
01403       if(x1name=="") x1name=ToStringInteger(BASE::MinStateIndex(tit->X1));
01404       std::string x2name= BASE::StateName(tit->X2);
01405       if(x2name=="") x2name=ToStringInteger(BASE::MinStateIndex(tit->X2));
01406       stream << "  \"" << x1name  << "\" -> \"" << x2name << "\" [label=\"" << BASE::EventName(tit->Ev) << "\"];" << std::endl;
01407     }
01408     stream << "};" << std::endl;
01409     stream.close();
01410   }
01411   catch (std::ios::failure&) {    
01412     throw Exception("TaGenerator::DotWrite", 
01413         "Exception opening/writing dotfile \""+rFileName+"\"", 3);
01414   }
01415   BASE::ClearMinStateIndexMap();
01416 }
01417 
01418 // StateColorMap()
01419 TEMP std::map<Idx,ColorSet> THIS::StateColorMap(void) const {
01420   StateSet::Iterator lit;
01421   std::map<Idx,ColorSet> map;
01422   StateSet cstates = ColoredStates();
01423   for (lit = cstates.Begin(); lit != cstates.End(); lit++) {
01424     map.insert(std::make_pair(*lit, Colors(*lit)));
01425     FD_DF("make_pair(" << ToStringInteger(*lit) << ", " << (THIS::Colors(*lit).ToString()) << ")");
01426   }
01427   return map;
01428 }
01429 
01430 // ColoredStates(ColorIndex)
01431 TEMP StateSet THIS::ColoredStates(Idx colorIndex) const {
01432   StateSet::Iterator lit;
01433   StateSet coloredStates;
01434   for (lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
01435     if(ExistsColor(*lit, colorIndex)) coloredStates.Insert(*lit);
01436   }
01437   return coloredStates;
01438 }
01439 
01440 // ColoredStates(ColorName)
01441 TEMP StateSet THIS::ColoredStates(const std::string& rColorName) const{
01442   Idx colorIndex = ColorIndex(rColorName);
01443   return ColoredStates(colorIndex);
01444 }
01445 
01446 // ColoredStates()
01447 TEMP StateSet THIS::ColoredStates() const {
01448   StateSet::Iterator lit;
01449   StateSet coloredStates;
01450   for(lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
01451     if(IsColored(*lit)) coloredStates.Insert(*lit);
01452   }
01453   return coloredStates;
01454 }
01455 
01456 // UncoloredStates()
01457 TEMP StateSet THIS::UncoloredStates() const {
01458   StateSet::Iterator lit;
01459   StateSet uncoloredStates;
01460   for (lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
01461     if (!IsColored(*lit)) uncoloredStates.Insert(*lit);
01462   }
01463   return uncoloredStates;
01464 }
01465 
01466 // IsColored()
01467 TEMP bool THIS::IsColored(void) const {
01468   StateSet::Iterator lit;
01469   for(lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
01470     if(IsColored(*lit)) return true;
01471   }
01472   return false;
01473 }
01474 
01475 // IsColored(stateIndex)
01476 TEMP bool THIS::IsColored(Idx stateIndex) const {
01477 #ifdef FAUDES_CHECKED
01478   try {
01479     return !BASE::pStates->Attribute(stateIndex).Colors().Empty();
01480   }
01481   catch (faudes::Exception& exception){
01482     std::stringstream errstr;
01483     errstr << "State index " << stateIndex << " not member of set" << std::endl;
01484     throw Exception("mtcGenerator::IsColored(stateIndex)", errstr.str(), 200);
01485   }
01486 #else
01487   return !BASE::pStates->Attribute(stateIndex).Colors().Empty();
01488 #endif
01489 }
01490 
01491 TEMP StateSet THIS::StronglyCoaccessibleSet(void) const {
01492   mtcGenerator tmp(*this);
01493   StateSet stronglyCoac, notStronglyCoac;
01494   ColorSet colors;
01495   stronglyCoac = BASE::States();
01496   Colors(colors);
01497 
01498   ColorSet::Iterator cit = colors.Begin();
01499   ColorSet::Iterator cit_end = colors.End();
01500 
01501   for (; cit != cit_end; cit++) {
01502     StateSet tmp1, tmp2;
01503     StateSet states = ColoredStates(*cit);
01504     tmp.InjectMarkedStates(states);
01505     tmp1 = tmp.CoaccessibleSet();
01506     tmp2 = stronglyCoac * tmp1;
01507     stronglyCoac = tmp2;
01508   }
01509   tmp.ClearMarkedStates();
01510   return stronglyCoac;
01511 }
01512 
01513 TEMP bool THIS::StronglyCoaccessible(void) {
01514   StateSet stronglyCoacSet = StronglyCoaccessibleSet();
01515   StateSet notStronglyCoac = BASE::States() - stronglyCoacSet;
01516   BASE::DelStates(notStronglyCoac);
01517   return (StronglyCoaccessibleSet() == BASE::States());
01518 }
01519 
01520 TEMP bool THIS::IsStronglyCoaccessible(void) const {
01521   return (StronglyCoaccessibleSet() == BASE::States());
01522 }
01523 
01524 // StronglyTrimSet()
01525 TEMP StateSet THIS::StronglyTrimSet(void) const {
01526   FD_DF("TmtcGenerator::StronglyTrimSet: trim states: "
01527   << StateSet(BASE::AccessibleSet() * StronglyCoaccessibleSet()).ToString());
01528   return BASE::AccessibleSet() * StronglyCoaccessibleSet();
01529 }
01530 
01531 // StronglyTrim()
01532 TEMP bool THIS::StronglyTrim(void) {
01533   // better: compute sets and do one state delete
01534   bool accessiblebool = BASE::Accessible();
01535   bool coaccessiblebool = StronglyCoaccessible();
01536   FD_DF("TmtcGenerator::StronglyTrim: trim states: " <<  (THIS::mpStates->ToString()));
01537   if (accessiblebool && coaccessiblebool) {
01538     FD_DF("TmtcGenerator::StronglyTrim: generator is trim");
01539     return true;
01540   }
01541   FD_DF("TmtcGenerator::StronglyTrim: generator is not trim");
01542   return false;
01543 }
01544 
01545 // IsStronglyTrim()
01546 TEMP bool THIS::IsStronglyTrim(void) const {
01547   if (BASE::IsAccessible() && IsStronglyCoaccessible()) {
01548     FD_DF("TmtcGenerator::IsStronglyTrim: generator is strongly trim");
01549     return true;
01550   }
01551   else {
01552     FD_DF("TmtcGenerator::IsStronglyTrim: generator is not strongly trim");
01553     return false;
01554   }
01555 }
01556 
01557 // NewColorSymbolTable()
01558 TEMP void THIS::NewColorSymbolTable() {
01559 
01560   StateSet::Iterator lit;
01561   StateAttr *attr;
01562 
01563   StateSet coloredStates = ColoredStates();
01564   coloredStates.Write();
01565   SymbolTable *tmp;
01566   tmp = new SymbolTable;
01567 
01568   // iterate over all colored states
01569   for (lit = coloredStates.Begin(); lit != coloredStates.End(); lit++) {
01570     // get attributes for current state
01571     attr = BASE::pStates->Attributep(*lit);
01572     ColorSet::Iterator cit, cit_end;
01573     cit_end = attr->ColorsEnd();
01574     // iterate over all colors of the current state
01575     for (cit = attr->ColorsBegin(); cit != cit_end; cit++) {
01576 #ifdef FAUDES_CHECKED
01577       try {
01578         // insert color indices and color names to new color symbol table
01579         tmp->InsEntry(*cit, attr->Colors().SymbolicName(*cit));
01580       }
01581       catch (faudes::Exception& exception){
01582         std::stringstream errstr;
01583         errstr << "Could not insert index \"" << *cit << "\" and symbol \"" << 
01584     attr->Colors().SymbolicName(*cit) << "\" to symbol table" << std::endl;
01585         throw Exception("mtcGenerator::NewColorSymbolTable()", errstr.str(), 44);
01586       }
01587 #else
01588       tmp->InsEntry(*cit, attr->Colors().SymbolicName(*cit));
01589 #endif
01590     }
01591     // reset color symbol table pointers
01592     mpColorSymbolTable = tmp;
01593     attr->ColorSymTab(tmp);
01594   }
01595 }
01596 
01597 // ClearStateAttributes()
01598 TEMP void THIS::ClearStateAttributes() {
01599   if(ColorSet::StaticSymbolTablep() != mpColorSymbolTable) mpColorSymbolTable->Clear();
01600   BASE::ClearStateAttributes();
01601 }
01602 
01603 
01604 // DoSWrite(rTw&)
01605 TEMP void THIS::DoSWrite(TokenWriter& rTw) const {
01606   // set up color statistics
01607   std::set<Idx> colcount;
01608   StateSet::Iterator sit;
01609   for(sit = BASE::StatesBegin(); sit != BASE::StatesEnd(); sit++) {
01610     colcount.insert(Colors(*sit).Size());
01611   }
01612   // convert to string
01613   std::multiset<Idx>::iterator cit;
01614   std::stringstream countstr;
01615   for(cit = colcount.begin(); cit != colcount.end(); cit++) {
01616     countstr << *cit << " ";
01617   }
01618   // write
01619   BASE::DoSWrite(rTw);
01620   rTw.WriteComment(" Colors (all):  " + ToStringInteger(Colors().Size()) );
01621   rTw.WriteComment(" Colors (dist): " + countstr.str());
01622   rTw.WriteComment("");
01623 }
01624 
01625 #undef BASE
01626 #undef THIS
01627 #undef TEMP
01628 
01629 } // namespace faudes
01630 
01631 #endif

libFAUDES 2.18b --- 2010-12-17 --- c++ source docu by doxygen 1.6.3