mtc_generator.hGo 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 * MtcSystems 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 MtcSystem 00062 */ 00063 TmtcGenerator(void); 00064 00065 /** 00066 * Creates an mtcgenerator from another mtcgenerator - copy constructor: 00067 * 00068 * If the other MtcSystem 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 MtcSystem 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 MtcSystem 00101 * 00102 */ 00103 ~TmtcGenerator(void) { FD_DG("TmtcGenerator(" << this << ")::~TmtcGenerator()");}; 00104 00105 /** 00106 * Construct on heap. 00107 * 00108 * @return 00109 * New Generator 00110 */ 00111 virtual TmtcGenerator* New(void) const; 00112 00113 /** 00114 * Construct copy on heap. 00115 * 00116 * @return 00117 * New Generator 00118 */ 00119 virtual TmtcGenerator* Copy(void) const; 00120 00121 00122 /** 00123 * Copy from other mtcgenerator 00124 * 00125 * @param rSrc 00126 * MtcSystem 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 MtcSystem. 00156 * 00157 * @return 00158 * Pointer to ColorSymbolTable 00159 */ 00160 SymbolTable* ColorSymbolTablep(void) const; 00161 00162 /** 00163 * Set ColorSymbolTable to be used by this MtcSystem. 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 MtcSystem. 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 MtcSystem. 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 MtcSystem. 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 MtcSystem! 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 Generator::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 MtcSystem </h4> 00617 * <table border=0> <tr> <td> 00618 * <table width=100%> 00619 * <tr> <td> <center> Original MtcSystem 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 MtcSystem 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 MtcSystem 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 MtcSystem</h4> 00658 * <table border=0> <tr> <td> 00659 * <table width=100%> 00660 * <tr> <td> <center> Original MtcSystem 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 MtcSystem 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 MtcSystem 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 MtcSystem 00740 typedef TmtcGenerator<AttributeVoid,AttributeColoredState,AttributeCFlags,AttributeVoid> MtcSystem; 00741 00742 00743 /** Compatibility: pre 2.20b used mtcGenerator as C++ class name*/ 00744 #ifdef FAUDES_COMPATIBILITY 00745 typedef TmtcGenerator<AttributeVoid,AttributeColoredState,AttributeCFlags,AttributeVoid> mtcGenerator; 00746 #endif 00747 00748 // convenient scope macors 00749 #define THIS TmtcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr> 00750 #define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr> 00751 #define TEMP template<class GlobalAttr, class StateAttr, class EventAttr, class TransAttr> 00752 00753 00754 /** 00755 * RTI wrapper function. See also MtcSystem::IsStronglyCoaccessible(). 00756 * \ingroup GeneratorFunctions 00757 */ 00758 bool IsStronglyCoaccessible(const MtcSystem& rGen); 00759 00760 /** 00761 * RTI wrapper function. See also MtcSystem::IsStronglyTrim(). 00762 * \ingroup GeneratorFunctions 00763 */ 00764 bool IsStronglyTrim(const MtcSystem& rGen); 00765 00766 /** 00767 * RTI wrapper function. See also MtcSystem::Coaccessible(). 00768 * \ingroup GeneratorFunctions 00769 */ 00770 void StronglyCoaccessible(MtcSystem& rGen); 00771 00772 /** 00773 * RTI wrapper function. See also MtcSystem::Coaccessible(). 00774 * \ingroup GeneratorFunctions 00775 */ 00776 void StronglyCoaccessible(const MtcSystem& rGen, MtcSystem& rRes); 00777 00778 /** 00779 * RTI wrapper function. See also MtcSystem::Trim(). 00780 * \ingroup GeneratorFunctions 00781 */ 00782 void StronglyTrim(MtcSystem& rGen); 00783 00784 /** 00785 * RTI wrapper function. See also MtcSystem::Trim(). 00786 * \ingroup GeneratorFunctions 00787 */ 00788 void StronglyTrim(const MtcSystem& rGen, MtcSystem& rRes); 00789 00790 00791 00792 // TmtcGenerator(void) 00793 TEMP THIS::TmtcGenerator(void) : BASE() { 00794 FD_DG("MtcSystem(" << this << ")::MtcSystem()"); 00795 mpColorSymbolTable = GlobalColorSymbolTablep(); 00796 } 00797 00798 // TmtcGenerator(rOtherGen) 00799 TEMP THIS::TmtcGenerator(const TmtcGenerator& rOtherGen) : BASE() { 00800 FD_DG("MtcSystem(" << this << ")::MtcSystem(rOtherGen)"); 00801 if (rOtherGen.ColorSymbolTablep() != ColorSet::StaticSymbolTablep()) 00802 NewColorSymbolTable(); 00803 else ColorSymbolTable(GlobalColorSymbolTablep()); 00804 Assign(rOtherGen); 00805 } 00806 00807 // TmtcGenerator(rOtherGen) 00808 TEMP THIS::TmtcGenerator(const vGenerator& rOtherGen) : BASE() { 00809 FD_DG("MtcSystem(" << this << ")::MtcSystem(rOtherGen)"); 00810 ColorSymbolTable(GlobalColorSymbolTablep()); 00811 Assign(rOtherGen); 00812 } 00813 00814 // TmtcGenerator(rFilename) 00815 TEMP THIS::TmtcGenerator(const std::string& rFileName) : BASE() { 00816 FD_DG("MtcSystem(" << this << ")::MtcSystem(" << rFileName << ")"); 00817 ColorSymbolTable(GlobalColorSymbolTablep()); 00818 BASE::Read(rFileName); 00819 } 00820 00821 // New/Copy 00822 TEMP THIS* THIS::New(void) const { 00823 // allocate 00824 THIS* res = new THIS; 00825 // fix base data 00826 res->EventSymbolTablep(BASE::mpEventSymbolTable); 00827 res->mStateNamesEnabled=BASE::mStateNamesEnabled; 00828 res->mReindexOnWrite=BASE::mReindexOnWrite; 00829 // fix my data 00830 res->ColorSymbolTable(GlobalColorSymbolTablep()); 00831 // done 00832 return res; 00833 } 00834 00835 // Copy 00836 TEMP THIS* THIS::Copy(void) const { 00837 // allocate 00838 THIS* res = new THIS(*this); 00839 // done 00840 return res; 00841 } 00842 00843 00844 00845 00846 // Assign(gen) 00847 TEMP THIS& THIS::Assign(const TmtcGenerator& rSrc) { 00848 FD_DG("MtcSystem(" << this << ")::Assign(gen&)"); 00849 // call base method 00850 BASE::Assign(rSrc); 00851 // my members 00852 ColorSymbolTable(rSrc.ColorSymbolTablep()); 00853 // fix non std symboltable (broken) 00854 /* 00855 if (rSrc.ColorSymbolTablep() != ColorSet::StaticSymbolTablep()) { 00856 NewColorSymbolTable(); 00857 00858 ColorSet mycolors(mpColorSymbolTable); 00859 Colors(mycolors); 00860 ColorSet::Iterator cit; 00861 ColorSet::Iterator cit_end = mycolors.End(); 00862 00863 for (cit = mycolors.Begin(); cit != cit_end; cit++) { 00864 ColorSymbolTablep()->SetEntry(*cit, ColorName(*cit)); 00865 } 00866 } 00867 */ 00868 // done 00869 return *this; 00870 } 00871 00872 // Assign(gen) 00873 TEMP THIS& THIS::Assign(const vGenerator& rSrc) { 00874 FD_DG("MtcSystem(" << this << ")::Assign(vgen&)"); 00875 // call base method 00876 BASE::Assign(rSrc); 00877 // done 00878 return *this; 00879 } 00880 00881 // GlobalColorSymbolTablep() 00882 TEMP SymbolTable* THIS::GlobalColorSymbolTablep(void) const { 00883 return ColorSet::StaticSymbolTablep(); 00884 } 00885 00886 // ColorSymbolTablep() 00887 TEMP SymbolTable* THIS::ColorSymbolTablep(void) const { 00888 return mpColorSymbolTable; 00889 } 00890 00891 // ColorSymbolTable(SymbolTable*) 00892 TEMP void THIS::ColorSymbolTable(SymbolTable* pSymTab) { 00893 mpColorSymbolTable=pSymTab; 00894 } 00895 00896 // ColorSymbolTable(rOtherGen) 00897 TEMP void THIS::ColorSymbolTable(const TmtcGenerator& rOtherGen) { 00898 ColorSymbolTable(rOtherGen.ColorSymbolTablep()); 00899 } 00900 00901 // InsColoredState(rStateName, rColorName) 00902 TEMP Idx THIS::InsColoredState(const std::string& rStateName, const std::string& rColorName) { 00903 FD_DG("MtcSystem(" << this << ")::InsColoredState(rStateName, colorName)"); 00904 StateAttr *attr; 00905 Idx index; 00906 #ifdef FAUDES_CHECKED 00907 try { 00908 index = BASE::InsState(rStateName); 00909 } 00910 catch (faudes::Exception& exception){ 00911 std::stringstream errstr; 00912 errstr << "Name \"" << rStateName << "\" already exists" << std::endl; 00913 throw Exception("MtcSystem::InsColoredState(rStateName, rColorName)", errstr.str(), 104); 00914 } 00915 try { 00916 attr = BASE::StateAttributep(index); 00917 } 00918 catch (faudes::Exception& exception){ 00919 std::stringstream errstr; 00920 errstr << "Index " << index << " not member of set" << std::endl; 00921 throw Exception("MtcSystem::InsColoredState(stateIndex, colorIndex)", errstr.str(), 200); 00922 } 00923 try { 00924 attr->Colors().Insert(rColorName); 00925 } 00926 catch (faudes::Exception& exception){ 00927 std::stringstream errstr; 00928 errstr << "Name already exists / invalid name: " << rColorName << std::endl; 00929 throw Exception("MtcSystem::InsColoredState(stateIndex, rColorName)", errstr.str(), 104); 00930 } 00931 #else 00932 index = BASE::InsState(rStateName); 00933 attr = this->Attributep(index); 00934 attr->Colors().Insert(rColorName); 00935 #endif 00936 return index; 00937 } 00938 00939 // InsColoredState(rStateName, colorIndex) 00940 TEMP Idx THIS::InsColoredState(const std::string& rStateName, const Idx colorIndex) { 00941 Idx index = BASE::InsState(rStateName); 00942 StateAttr *attr = BASE::StateAttributep(index); 00943 #ifdef FAUDES_CHECKED 00944 try { 00945 attr->Colors().Insert(colorIndex); 00946 } 00947 catch (faudes::Exception& exception){ 00948 std::stringstream errstr; 00949 errstr << "Color index " << colorIndex << " not known to symbol table" << std::endl; 00950 throw Exception("MtcSystem::InsColoredState(rStateName, colorIndex)", errstr.str(), 200); 00951 } 00952 #else 00953 attr->Colors().Insert(colorIndex); 00954 #endif 00955 return index; 00956 } 00957 00958 // InsColoredState(rStateName, rColors) 00959 TEMP Idx THIS::InsColoredState(const std::string& rStateName, const ColorSet& rColors) { 00960 Idx index = BASE::InsState(rStateName); 00961 InsColors(index, rColors); 00962 return index; 00963 } 00964 00965 // InsColoredState(rColors) 00966 TEMP Idx THIS::InsColoredState(const ColorSet& rColors) { 00967 Idx index = BASE::InsState(); 00968 InsColors(index, rColors); 00969 return index; 00970 } 00971 00972 // InsColor(stateIndex, rColorName) 00973 TEMP Idx THIS::InsColor(Idx stateIndex, const std::string& rColorName) { 00974 StateAttr *attr; 00975 Idx index; 00976 #ifdef FAUDES_CHECKED 00977 try { 00978 attr = BASE::StateAttributep(stateIndex); 00979 } 00980 catch (faudes::Exception& exception){ 00981 std::stringstream errstr; 00982 errstr << "State index " << stateIndex << " not member of set" << std::endl; 00983 throw Exception("MtcSystem::InsColor(stateIndex, colorIndex)", errstr.str(), 200); 00984 } 00985 try { 00986 index = attr->Colors().Insert(rColorName); 00987 } 00988 catch (faudes::Exception& exception){ 00989 std::stringstream errstr; 00990 errstr << "Name already exists / invalid name: " << rColorName << std::endl; 00991 throw Exception("MtcSystem::InsColor(stateIndex, rColorName)", errstr.str(), 104); 00992 } 00993 #else 00994 attr = Attributep(stateIndex); 00995 index = attr->Colors().Insert(rColorName); 00996 #endif 00997 return index; 00998 } 00999 01000 // InsColor(stateIndex, colorIndex) 01001 TEMP void THIS::InsColor(Idx stateIndex, Idx colorIndex) { 01002 StateAttr *attr; 01003 #ifdef FAUDES_CHECKED 01004 try { 01005 attr = BASE::StateAttributep(stateIndex); 01006 } 01007 catch (faudes::Exception& exception){ 01008 std::stringstream errstr; 01009 errstr << "State index " << stateIndex << " not member of set" << std::endl; 01010 throw Exception("MtcSystem::InsColor(stateIndex, colorIndex)", errstr.str(), 200); 01011 } 01012 try { 01013 attr->Colors().Insert(colorIndex); 01014 } 01015 catch (faudes::Exception& exception){ 01016 std::stringstream errstr; 01017 errstr << "Color index " << colorIndex << " not known to symbol table" << std::endl; 01018 throw Exception("MtcSystem::InsColor(stateIndex, colorIndex)", errstr.str(), 200); 01019 } 01020 #else 01021 attr = Attributep(stateIndex); 01022 attr->Colors().Insert(colorIndex); 01023 #endif 01024 } 01025 01026 // InsColors(stateIndex, rColors) 01027 TEMP void THIS::InsColors(Idx stateIndex, const ColorSet& rColors) { 01028 #ifdef FAUDES_CHECKED 01029 if(rColors.SymbolTablep() != mpColorSymbolTable) { 01030 std::stringstream errstr; 01031 errstr << "Symbol table mismatch" << std::endl; 01032 throw Exception("MtcSystem::InsColors(stateIndex, rColors)", errstr.str(), 88); 01033 } 01034 #endif 01035 StateAttr *attr; 01036 #ifdef FAUDES_CHECKED 01037 try { 01038 attr = BASE::StateAttributep(stateIndex); 01039 } 01040 catch (faudes::Exception& exception){ 01041 std::stringstream errstr; 01042 errstr << "State index " << stateIndex << " not member of set" << std::endl; 01043 throw Exception("MtcSystem::InsColors(stateIndex, rColors)", errstr.str(), 200); 01044 } 01045 try { 01046 attr->Colors().InsertSet(rColors); 01047 } 01048 catch (faudes::Exception& exception){ 01049 std::stringstream errstr; 01050 errstr << "Symbol table mismach" << std::endl; 01051 throw Exception("MtcSystem::InsColors(stateIndex, rColors)", errstr.str(), 200); 01052 } 01053 #else 01054 attr = Attributep(stateIndex); 01055 attr->Colors().InsertSet(rColors); 01056 #endif 01057 } 01058 01059 // DelColor(stateIndex, rColorName) 01060 TEMP void THIS::DelColor(Idx stateIndex, const std::string& rColorName) { 01061 StateAttr *attr; 01062 Idx index; 01063 #ifdef FAUDES_CHECKED 01064 try { 01065 attr = BASE::StateAttributep(stateIndex); 01066 } 01067 catch (faudes::Exception& exception){ 01068 std::stringstream errstr; 01069 errstr << "State index " << stateIndex << " not member of set" << std::endl; 01070 throw Exception("MtcSystem::DelColor(stateIndex, rColorName)", errstr.str(), 200); 01071 } 01072 index = ColorIndex(rColorName); 01073 try { 01074 attr->Colors().Erase(index); 01075 } 01076 catch (faudes::Exception& exception){ 01077 std::stringstream errstr; 01078 errstr << "Color name \"" << rColorName << "\" not found in NameSet" << std::endl; 01079 throw Exception("MtcSystem::DelColor(stateIndex, rColorName)", errstr.str(), 202); 01080 } 01081 #else 01082 attr = Attributep(stateIndex); 01083 index = ColorIndex(rColorName); 01084 attr->Colors().Erase(index); 01085 #endif 01086 CheckSymbolTable(index); 01087 } 01088 01089 // DelColor(stateIndex, colorIndex) 01090 TEMP void THIS::DelColor(Idx stateIndex, Idx colorIndex) { 01091 StateAttr *attr; 01092 bool res; 01093 #ifdef FAUDES_CHECKED 01094 try { 01095 attr = BASE::StateAttributep(stateIndex); 01096 } 01097 catch (faudes::Exception& exception){ 01098 std::stringstream errstr; 01099 errstr << "State index " << stateIndex << " not member of set" << std::endl; 01100 throw Exception("MtcSystem::DelColor(stateIndex, colorIndex)", errstr.str(), 200); 01101 } 01102 #else 01103 attr = BASE::StateAttributep(stateIndex); 01104 #endif 01105 res = attr->Colors().Erase(colorIndex); 01106 if (!res) { 01107 std::stringstream errstr; 01108 errstr << "Color index " << colorIndex << " not found in generator" << std::endl; 01109 throw Exception("MtcSystem::DelColor(stateIndex, colorIndex)", errstr.str(), 205); 01110 } 01111 CheckSymbolTable(colorIndex); 01112 } 01113 01114 // DelColor(rColorName) 01115 TEMP void THIS::DelColor(const std::string& rColorName) { 01116 StateSet::Iterator lit; 01117 StateAttr *attr; 01118 01119 Idx index = ColorIndex(rColorName); 01120 01121 for (lit = BASE::pStates->Begin(); lit != BASE::pStates->End(); lit++) { 01122 attr = BASE::StateAttributep(*lit); 01123 attr->Colors().Erase(index); 01124 } 01125 CheckSymbolTable(index); 01126 } 01127 01128 // DelColor(colorIndex) 01129 TEMP void THIS::DelColor(Idx colorIndex) { 01130 StateSet::Iterator lit; 01131 StateAttr *attr; 01132 for (lit = BASE::pStates->Begin(); lit != BASE::pStates->End(); lit++) { 01133 attr = BASE::StateAttributep(*lit); 01134 attr->Colors().Erase(colorIndex); 01135 } 01136 CheckSymbolTable(colorIndex); 01137 } 01138 01139 // ClrColors(stateIndex) 01140 TEMP void THIS::ClrColors(Idx stateIndex) { 01141 StateAttr *attr; 01142 ColorSet::Iterator cit; 01143 ColorSet delColors(mpColorSymbolTable); 01144 #ifdef FAUDES_CHECKED 01145 try { 01146 attr = BASE::StateAttributep(stateIndex); 01147 } 01148 catch (faudes::Exception& exception){ 01149 std::stringstream errstr; 01150 errstr << "State index " << stateIndex << " not member of set" << std::endl; 01151 throw Exception("MtcSystem::ClrColors(stateIndex)", errstr.str(), 200); 01152 } 01153 #else 01154 attr = BASE::StateAttributep(stateIndex); 01155 #endif 01156 delColors.InsertSet(attr->Colors()); 01157 attr->Colors().Clear(); 01158 CheckSymbolTable(delColors); 01159 } 01160 01161 // DelColorName(colorIndex) 01162 TEMP void THIS::DelColorName(Idx colorIndex) { 01163 ColorSymbolTablep()->ClrEntry(colorIndex); 01164 } 01165 01166 // Colors(rColors) 01167 TEMP void THIS::Colors(ColorSet& rColors) const { 01168 #ifdef FAUDES_CHECKED 01169 if(rColors.SymbolTablep() != mpColorSymbolTable) { 01170 std::stringstream errstr; 01171 errstr << "Symbol table mismatch" << std::endl; 01172 throw Exception("MtcSystem::Colors", errstr.str(), 88); 01173 } 01174 #endif 01175 StateSet::Iterator lit; 01176 for (lit = BASE::pStates->Begin(); lit != BASE::pStates->End(); lit++) { 01177 const StateAttr& attr = BASE::pStates->Attribute(*lit); 01178 rColors.InsertSet(attr.Colors()); 01179 } 01180 } 01181 01182 // Colors() 01183 TEMP ColorSet THIS::Colors(void) const { 01184 StateSet::Iterator lit; 01185 ColorSet colors(mpColorSymbolTable); 01186 for (lit = BASE::pStates->Begin(); lit != BASE::pStates->End(); lit++) { 01187 const StateAttr& attr = BASE::pStates->Attribute(*lit); 01188 colors.InsertSet(attr.Colors()); 01189 } 01190 return colors; 01191 } 01192 01193 // Colors(stateIndex) 01194 TEMP const ColorSet& THIS::Colors(Idx stateIndex) const { 01195 const StateAttr* attrp; 01196 #ifdef FAUDES_CHECKED 01197 try { 01198 attrp = &BASE::pStates->Attribute(stateIndex); 01199 } 01200 catch (faudes::Exception& exception){ 01201 std::stringstream errstr; 01202 errstr << "State index " << stateIndex << " not member of set" << std::endl; 01203 throw Exception("MtcSystem::Colors(stateIndex)", errstr.str(), 200); 01204 } 01205 #else 01206 attrp = &BASE::pStates->Attribute(stateIndex); 01207 #endif 01208 return attrp->Colors(); 01209 } 01210 01211 // CheckSymbolTable(colorIndex) 01212 TEMP void THIS::CheckSymbolTable(Idx colorIndex) { 01213 if (ColorSymbolTablep() != ColorSet::StaticSymbolTablep()) { 01214 ColorSet colors(mpColorSymbolTable); 01215 Colors(colors); 01216 if (!colors.Exists(colorIndex)) 01217 DelColorName(colorIndex); 01218 } 01219 } 01220 01221 // CheckSymbolTable(rColors) 01222 TEMP void THIS::CheckSymbolTable(ColorSet& rColors) { 01223 #ifdef FAUDES_CHECKED 01224 if(rColors.SymbolTablep() != mpColorSymbolTable) { 01225 std::stringstream errstr; 01226 errstr << "Symbol table mismatch" << std::endl; 01227 throw Exception("MtcSystem::CheckSymbolTable", errstr.str(), 88); 01228 } 01229 #endif 01230 if (ColorSymbolTablep() != ColorSet::StaticSymbolTablep()) { 01231 ColorSet colors(mpColorSymbolTable); 01232 // all generator's colors are inserted 01233 Colors(colors); 01234 ColorSet::Iterator cit; 01235 for(cit = rColors.Begin(); cit != rColors.End(); cit++) { 01236 // are colors from rColors still in use? 01237 if(!colors.Exists(*cit)) DelColorName(*cit); 01238 } 01239 } 01240 } 01241 01242 // ExistsColor(colorIndex) 01243 TEMP bool THIS::ExistsColor(Idx colorIndex) const { 01244 StateSet::Iterator lit; 01245 for (lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) { 01246 if (ExistsColor(*lit, colorIndex)) return true; 01247 } 01248 return false; 01249 } 01250 01251 // ExistsColor(colorName) 01252 TEMP bool THIS::ExistsColor(const std::string& rColorName) const { 01253 Idx colorIndex = ColorIndex(rColorName); 01254 #ifdef FAUDES_CHECKED 01255 if (colorIndex == 0) { 01256 std::stringstream errstr; 01257 errstr << "Color name \"" << rColorName << "\" not found in symbol table " << std::endl; 01258 throw Exception("MtcSystem::ExistsColor(rColorName)", errstr.str(), 202); 01259 } 01260 #endif 01261 return ExistsColor(colorIndex); 01262 } 01263 01264 // ColorName(index) 01265 TEMP std::string THIS::ColorName(Idx colorIndex) const { 01266 return ColorSymbolTablep()->Symbol(colorIndex); 01267 } 01268 01269 // ColorIndex(rColorName) 01270 TEMP Idx THIS::ColorIndex(const std::string& rColorName) const { 01271 return ColorSymbolTablep()->Index(rColorName); 01272 } 01273 01274 // CStr(index) 01275 TEMP std::string THIS::CStr(Idx index) const { 01276 return ColorName(index); 01277 } 01278 01279 // ExistsColor(stateIndex, colorIndex) 01280 TEMP bool THIS::ExistsColor(Idx stateIndex, Idx colorIndex) const { 01281 #ifdef FAUDES_CHECKED 01282 try { 01283 return BASE::pStates->Attribute(stateIndex).Colors().Exists(colorIndex); 01284 } 01285 catch (faudes::Exception& exception){ 01286 std::stringstream errstr; 01287 errstr << "State index " << stateIndex << " not member of set" << std::endl; 01288 throw Exception("MtcSystem::ExistsColor(stateIndex, colorIndex)", errstr.str(), 200); 01289 } 01290 #else 01291 return BASE::pStates->Attribute(stateIndex).Colors().Exists(colorIndex); 01292 #endif 01293 } 01294 01295 // DotWrite(rFileName) 01296 TEMP void THIS::DotWrite(const std::string& rFileName) const { 01297 FD_DG("TmtcGenerator(" << this << ")::DotWrite(" << rFileName << ")"); 01298 TaIndexSet<StateAttr> coloredStates; 01299 StateSet::Iterator it; 01300 BASE::SetMinStateIndexMap(); 01301 typename TransSet::Iterator tit; 01302 try { 01303 std::ofstream stream; 01304 stream.exceptions(std::ios::badbit|std::ios::failbit); 01305 stream.open(rFileName.c_str()); 01306 stream << "// dot output generated by libFAUDES TmtcGenerator" << std::endl; 01307 stream << "digraph \"" << BASE::Name() << "\" {" << std::endl; 01308 stream << " rankdir=LR" << std::endl; 01309 stream << " node [shape=circle];" << std::endl; 01310 stream << std::endl; 01311 stream << " // initial states" << std::endl; 01312 int i = 1; 01313 for (it = BASE::InitStatesBegin(); it != BASE::InitStatesEnd(); ++it) { 01314 std::string xname= BASE::StateName(*it); 01315 if(xname=="") xname=ToStringInteger(static_cast<long int>(BASE::MinStateIndex(*it))); 01316 stream << " dot_dummyinit_" << i << " [shape=none, label=\"\" ];" << std::endl; 01317 stream << " dot_dummyinit_" << i << " -> \"" << xname << "\";" << std::endl; 01318 i++; 01319 } 01320 stream << std::endl; 01321 01322 // uncolored states - output 01323 stream << " // uncolored states" << std::endl; 01324 for (it = BASE::pStates->Begin(); it != BASE::pStates->End(); ++it) { 01325 // does the state have a colored attribute? 01326 const StateAttr& attr = BASE::StateAttribute(*it); 01327 // handling colored states - copy to coloredStates 01328 if (!attr.IsDefault()) { 01329 coloredStates.Insert(*it, attr); 01330 } 01331 else { 01332 std::string xname=BASE::StateName(*it); 01333 if(xname=="") xname=ToStringInteger(BASE::MinStateIndex(*it)); 01334 stream << " \"" << xname << "\";" << std::endl; 01335 } 01336 } 01337 01338 // colored states - output 01339 std::vector<std::string> ColorVector; 01340 ColorVector.push_back("blue"); 01341 ColorVector.push_back("red"); 01342 ColorVector.push_back("magenta"); 01343 ColorVector.push_back("green"); 01344 ColorVector.push_back("darkorange"); 01345 ColorVector.push_back("cyan"); 01346 ColorVector.push_back("navy"); 01347 ColorVector.push_back("brown"); 01348 ColorVector.push_back("green4"); 01349 ColorVector.push_back("yellow"); 01350 ColorVector.push_back("darkviolet"); 01351 ColorVector.push_back("firebrick"); 01352 ColorVector.push_back("greenyellow"); 01353 ColorVector.push_back("peru"); 01354 ColorVector.push_back("skyblue"); 01355 ColorVector.push_back("darkgreen"); 01356 ColorVector.push_back("violetred"); 01357 ColorVector.push_back("lightsalmon"); 01358 ColorVector.push_back("seagreen"); 01359 ColorVector.push_back("saddlebrown"); 01360 ColorVector.push_back("slateblue"); 01361 ColorVector.push_back("thistle"); 01362 ColorVector.push_back("turquoise4"); 01363 ColorVector.push_back("gold2"); 01364 ColorVector.push_back("sandybrown"); 01365 ColorVector.push_back("aquamarine3"); 01366 ColorVector.push_back("darkolivegreen"); 01367 ColorVector.push_back("yellow4"); 01368 01369 stream << std::endl; 01370 stream << " // colored states" << std::endl; 01371 int clustNr = 0; 01372 for (it = coloredStates.Begin(); it != coloredStates.End(); it++) { 01373 int count = 0; 01374 std::string xname=BASE::StateName(*it); 01375 if(xname=="") xname=ToStringInteger(static_cast<long int>(BASE::MinStateIndex(*it))); 01376 const StateAttr& attr = coloredStates.Attribute(*it); 01377 if (attr.Colors().Size() > 1) { 01378 for(ColorSet::Iterator cit = attr.ColorsBegin(); cit != attr.ColorsEnd(); cit++) { 01379 stream << " subgraph cluster_" << clustNr++ << " {color=" << ColorVector.at(*cit-1) << ";" << std::endl; 01380 count++; 01381 } 01382 stream << " \"" << xname << "\" " << std::endl << " "; 01383 for (int i=0; i<count; i++) { 01384 stream << "}"; 01385 } 01386 stream << std::endl; 01387 } 01388 else if (attr.Colors().Size() == 1) { 01389 ColorSet::Iterator cit; 01390 if ((cit = attr.ColorsBegin()) != attr.ColorsEnd()) 01391 stream << " \"" << xname << "\" " << "[color=" << ColorVector.at(*cit-1) << "]" << std::endl; 01392 } 01393 } 01394 stream << std::endl; 01395 01396 // marked states 01397 stream << " // marked states" << std::endl; 01398 for (it = BASE::MarkedStatesBegin(); it != BASE::MarkedStatesEnd(); ++it) { 01399 std::string xname= BASE::StateName(*it); 01400 if(xname=="") xname=ToStringInteger(static_cast<long int>(BASE::MinStateIndex(*it))); 01401 stream << " \"" << xname << "\";" << std::endl; 01402 i++; 01403 } 01404 01405 // transitions 01406 stream << std::endl; 01407 stream << " // transition relation" << std::endl; 01408 for (tit = BASE::TransRelBegin(); tit != BASE::TransRelEnd(); ++tit) { 01409 std::string x1name= BASE::StateName(tit->X1); 01410 if(x1name=="") x1name=ToStringInteger(BASE::MinStateIndex(tit->X1)); 01411 std::string x2name= BASE::StateName(tit->X2); 01412 if(x2name=="") x2name=ToStringInteger(BASE::MinStateIndex(tit->X2)); 01413 stream << " \"" << x1name << "\" -> \"" << x2name << "\" [label=\"" << BASE::EventName(tit->Ev) << "\"];" << std::endl; 01414 } 01415 stream << "};" << std::endl; 01416 stream.close(); 01417 } 01418 catch (std::ios::failure&) { 01419 throw Exception("TaGenerator::DotWrite", 01420 "Exception opening/writing dotfile \""+rFileName+"\"", 3); 01421 } 01422 BASE::ClearMinStateIndexMap(); 01423 } 01424 01425 // StateColorMap() 01426 TEMP 01427 typename std::map<Idx,ColorSet> 01428 THIS::StateColorMap(void) const { 01429 StateSet::Iterator lit; 01430 std::map<Idx,ColorSet> map; 01431 StateSet cstates = ColoredStates(); 01432 for (lit = cstates.Begin(); lit != cstates.End(); lit++) { 01433 map.insert(std::make_pair(*lit, Colors(*lit))); 01434 FD_DF("make_pair(" << ToStringInteger(*lit) << ", " << (THIS::Colors(*lit).ToString()) << ")"); 01435 } 01436 return map; 01437 } 01438 01439 // ColoredStates(ColorIndex) 01440 TEMP StateSet THIS::ColoredStates(Idx colorIndex) const { 01441 StateSet::Iterator lit; 01442 StateSet coloredStates; 01443 for (lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) { 01444 if(ExistsColor(*lit, colorIndex)) coloredStates.Insert(*lit); 01445 } 01446 return coloredStates; 01447 } 01448 01449 // ColoredStates(ColorName) 01450 TEMP StateSet THIS::ColoredStates(const std::string& rColorName) const{ 01451 Idx colorIndex = ColorIndex(rColorName); 01452 return ColoredStates(colorIndex); 01453 } 01454 01455 // ColoredStates() 01456 TEMP StateSet THIS::ColoredStates() const { 01457 StateSet::Iterator lit; 01458 StateSet coloredStates; 01459 for(lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) { 01460 if(IsColored(*lit)) coloredStates.Insert(*lit); 01461 } 01462 return coloredStates; 01463 } 01464 01465 // UncoloredStates() 01466 TEMP StateSet THIS::UncoloredStates() const { 01467 StateSet::Iterator lit; 01468 StateSet uncoloredStates; 01469 for (lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) { 01470 if (!IsColored(*lit)) uncoloredStates.Insert(*lit); 01471 } 01472 return uncoloredStates; 01473 } 01474 01475 // IsColored() 01476 TEMP bool THIS::IsColored(void) const { 01477 StateSet::Iterator lit; 01478 for(lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) { 01479 if(IsColored(*lit)) return true; 01480 } 01481 return false; 01482 } 01483 01484 // IsColored(stateIndex) 01485 TEMP bool THIS::IsColored(Idx stateIndex) const { 01486 #ifdef FAUDES_CHECKED 01487 try { 01488 return !BASE::pStates->Attribute(stateIndex).Colors().Empty(); 01489 } 01490 catch (faudes::Exception& exception){ 01491 std::stringstream errstr; 01492 errstr << "State index " << stateIndex << " not member of set" << std::endl; 01493 throw Exception("MtcSystem::IsColored(stateIndex)", errstr.str(), 200); 01494 } 01495 #else 01496 return !BASE::pStates->Attribute(stateIndex).Colors().Empty(); 01497 #endif 01498 } 01499 01500 TEMP StateSet THIS::StronglyCoaccessibleSet(void) const { 01501 MtcSystem tmp(*this); 01502 StateSet stronglyCoac, notStronglyCoac; 01503 ColorSet colors; 01504 stronglyCoac = BASE::States(); 01505 Colors(colors); 01506 01507 ColorSet::Iterator cit = colors.Begin(); 01508 ColorSet::Iterator cit_end = colors.End(); 01509 01510 for (; cit != cit_end; cit++) { 01511 StateSet tmp1, tmp2; 01512 StateSet states = ColoredStates(*cit); 01513 tmp.InjectMarkedStates(states); 01514 tmp1 = tmp.CoaccessibleSet(); 01515 tmp2 = stronglyCoac * tmp1; 01516 stronglyCoac = tmp2; 01517 } 01518 tmp.ClearMarkedStates(); 01519 return stronglyCoac; 01520 } 01521 01522 TEMP bool THIS::StronglyCoaccessible(void) { 01523 StateSet stronglyCoacSet = StronglyCoaccessibleSet(); 01524 StateSet notStronglyCoac = BASE::States() - stronglyCoacSet; 01525 BASE::DelStates(notStronglyCoac); 01526 return (StronglyCoaccessibleSet() == BASE::States()); 01527 } 01528 01529 TEMP bool THIS::IsStronglyCoaccessible(void) const { 01530 return (StronglyCoaccessibleSet() == BASE::States()); 01531 } 01532 01533 // StronglyTrimSet() 01534 TEMP StateSet THIS::StronglyTrimSet(void) const { 01535 FD_DF("TmtcGenerator::StronglyTrimSet: trim states: " 01536 << StateSet(BASE::AccessibleSet() * StronglyCoaccessibleSet()).ToString()); 01537 return BASE::AccessibleSet() * StronglyCoaccessibleSet(); 01538 } 01539 01540 // StronglyTrim() 01541 TEMP bool THIS::StronglyTrim(void) { 01542 // better: compute sets and do one state delete 01543 bool accessiblebool = BASE::Accessible(); 01544 bool coaccessiblebool = StronglyCoaccessible(); 01545 FD_DF("TmtcGenerator::StronglyTrim: trim states: " << (THIS::mpStates->ToString())); 01546 if (accessiblebool && coaccessiblebool) { 01547 FD_DF("TmtcGenerator::StronglyTrim: generator is trim"); 01548 return true; 01549 } 01550 FD_DF("TmtcGenerator::StronglyTrim: generator is not trim"); 01551 return false; 01552 } 01553 01554 // IsStronglyTrim() 01555 TEMP bool THIS::IsStronglyTrim(void) const { 01556 if (BASE::IsAccessible() && IsStronglyCoaccessible()) { 01557 FD_DF("TmtcGenerator::IsStronglyTrim: generator is strongly trim"); 01558 return true; 01559 } 01560 else { 01561 FD_DF("TmtcGenerator::IsStronglyTrim: generator is not strongly trim"); 01562 return false; 01563 } 01564 } 01565 01566 // NewColorSymbolTable() 01567 TEMP void THIS::NewColorSymbolTable() { 01568 01569 StateSet::Iterator lit; 01570 StateAttr *attr; 01571 01572 StateSet coloredStates = ColoredStates(); 01573 coloredStates.Write(); 01574 SymbolTable *tmp; 01575 tmp = new SymbolTable; 01576 01577 // iterate over all colored states 01578 for (lit = coloredStates.Begin(); lit != coloredStates.End(); lit++) { 01579 // get attributes for current state 01580 attr = BASE::pStates->Attributep(*lit); 01581 ColorSet::Iterator cit, cit_end; 01582 cit_end = attr->ColorsEnd(); 01583 // iterate over all colors of the current state 01584 for (cit = attr->ColorsBegin(); cit != cit_end; cit++) { 01585 #ifdef FAUDES_CHECKED 01586 try { 01587 // insert color indices and color names to new color symbol table 01588 tmp->InsEntry(*cit, attr->Colors().SymbolicName(*cit)); 01589 } 01590 catch (faudes::Exception& exception){ 01591 std::stringstream errstr; 01592 errstr << "Could not insert index \"" << *cit << "\" and symbol \"" << 01593 attr->Colors().SymbolicName(*cit) << "\" to symbol table" << std::endl; 01594 throw Exception("MtcSystem::NewColorSymbolTable()", errstr.str(), 44); 01595 } 01596 #else 01597 tmp->InsEntry(*cit, attr->Colors().SymbolicName(*cit)); 01598 #endif 01599 } 01600 // reset color symbol table pointers 01601 mpColorSymbolTable = tmp; 01602 attr->ColorSymTab(tmp); 01603 } 01604 } 01605 01606 // ClearStateAttributes() 01607 TEMP void THIS::ClearStateAttributes() { 01608 if(ColorSet::StaticSymbolTablep() != mpColorSymbolTable) mpColorSymbolTable->Clear(); 01609 BASE::ClearStateAttributes(); 01610 } 01611 01612 01613 // DoSWrite(rTw&) 01614 TEMP void THIS::DoSWrite(TokenWriter& rTw) const { 01615 // set up color statistics 01616 std::set<Idx> colcount; 01617 StateSet::Iterator sit; 01618 for(sit = BASE::StatesBegin(); sit != BASE::StatesEnd(); sit++) { 01619 colcount.insert(Colors(*sit).Size()); 01620 } 01621 // convert to string 01622 std::multiset<Idx>::iterator cit; 01623 std::stringstream countstr; 01624 for(cit = colcount.begin(); cit != colcount.end(); cit++) { 01625 countstr << *cit << " "; 01626 } 01627 // write 01628 BASE::DoSWrite(rTw); 01629 rTw.WriteComment(" Colors (all): " + ToStringInteger(Colors().Size()) ); 01630 rTw.WriteComment(" Colors (dist): " + countstr.str()); 01631 rTw.WriteComment(""); 01632 } 01633 01634 #undef BASE 01635 #undef THIS 01636 #undef TEMP 01637 01638 } // namespace faudes 01639 01640 #endif libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |