mtc_generator.h
Go to the documentation of this file.
1 /** @file mtc_generator.h
2 
3 Methods for handling multitasking generators
4 
5 */
6 
7 /* FAU Discrete Event Systems Library (libfaudes)
8 
9  Copyright (C) 2008 Matthias Singer
10  Exclusive copyright is granted to Klaus Schmidt
11 
12  This library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU Lesser General Public
14  License as published by the Free Software Foundation; either
15  version 2.1 of the License, or (at your option) any later version.
16 
17  This library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  Lesser General Public License for more details.
21 
22  You should have received a copy of the GNU Lesser General Public
23  License along with this library; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25 
26 
27 #ifndef FAUDES_MTCGENERATOR_H
28 #define FAUDES_MTCGENERATOR_H
29 
30 #include "corefaudes.h"
31 #include "mtc_attributes.h"
32 #include <map>
33 
34 namespace faudes {
35 
36 
37 /**
38  * Allows to create colored marking generators (CMGs) as the common
39  * five tupel consisting of alphabet, stateset, transition relation,
40  * initial states, marked states, and attributes for state and event
41  * properties. Thus, it is possible to set a control status for
42  * events and to add or delete colored markings to single states.
43  * Doing so, multitasking generators can be computed and their
44  * behaviour be analysed.Methods for examining the color status are
45  * included as well as those for making a CMG accessible or strongly
46  * coaccessible. Furthermore, input and output methods for
47  * MtcSystems are included.
48  *
49  * @ingroup MultitaskingPlugin
50  */
51 
52 template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
53 class FAUDES_API TmtcGenerator : public TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr> {
54 
55  public:
56 
57  /** @name Constructor, Destructor and Copy-Methods */
58  /** @{ doxygen group */
59 
60  /**
61  * Creates an emtpy MtcSystem
62  */
63  TmtcGenerator(void);
64 
65  /**
66  * Creates an mtcgenerator from another mtcgenerator - copy constructor:
67  *
68  * If the other MtcSystem uses a local color symbol table, the new
69  * generator also creates a local symbol table. This new one is empty! If
70  * you use a local symbol table, you should implement a copy mechanism
71  * for the entries of the original generator's symbol table.
72  *
73  * @param rOtherGen
74  * Other mtcgenerator to copy
75  */
76  TmtcGenerator(const TmtcGenerator& rOtherGen);
77 
78  /**
79  * Creates an mtcgenerator from another generator - copy constructor
80  *
81  * @param rOtherGen
82  * Other generator to copy
83  */
84  TmtcGenerator(const vGenerator& rOtherGen);
85 
86  /**
87  * Constructs an MtcSystem from file
88  *
89  * Define FAUDES_CHECKED for consistency checks
90  *
91  * @param rFileName
92  * Filename
93  *
94  * @exception Exception
95  * - Opening/reading failed (ids 1, 50, 51)
96  */
97  TmtcGenerator(const std::string& rFileName);
98 
99  /**
100  * Destructor for MtcSystem
101  *
102  */
103  ~TmtcGenerator(void) { FD_DG("TmtcGenerator(" << this << ")::~TmtcGenerator()");};
104 
105  /**
106  * Construct on heap.
107  *
108  * @return
109  * New Generator
110  */
111  virtual TmtcGenerator* New(void) const;
112 
113  /**
114  * Construct copy on heap.
115  *
116  * @return
117  * New Generator
118  */
119  virtual TmtcGenerator* Copy(void) const;
120 
121 
122  /**
123  * Assignment
124  *
125  * @param rSrc
126  * MtcSystem to copy from
127  */
128  virtual TmtcGenerator& Assign(const Type& rSrc);
129 
130  /**
131  * Assignment operator (uses Assign)
132  *
133  * Note: you must reimplement this operator in derived
134  * classes in order to handle internal pointers correctly
135  *
136  * @param rOtherGen
137  * Other generator
138  */
139  virtual TmtcGenerator& operator= (const TmtcGenerator& rOtherGen) {return this->Assign(rOtherGen);};
140 
141  /** @} doxygen group */
142 
143  /** @name Color Symbol Table */
144  /** @{ doxygen group */
145 
146  /**
147  * Get Pointer to global ColorSymbolTable. This is
148  * a static member of ColorSet and used as default
149  * for all derived classes and instantiated objects.
150  *
151  * @return
152  * Pointer to global ColorSymbolTable
153  */
154  SymbolTable* GlobalColorSymbolTablep(void) const;
155 
156  /**
157  * Get Pointer to ColorSymbolTable currently used
158  * by this MtcSystem.
159  *
160  * @return
161  * Pointer to ColorSymbolTable
162  */
163  SymbolTable* ColorSymbolTablep(void) const;
164 
165  /**
166  * Set ColorSymbolTable to be used by this MtcSystem.
167  * Note: the managemnt of local color symbol tables needs
168  * a re-design. Dont use thus feature.
169  *
170  * @param pSymTab
171  * Pointer to SymbolTable
172  */
173  void ColorSymbolTable(SymbolTable* pSymTab);
174 
175  /**
176  * Set ColorSymbolTable as given by rOtherGen.
177  *
178  * @param rOtherGen
179  * Other generator
180  */
181  void ColorSymbolTable(const TmtcGenerator& rOtherGen);
182 
183  /** @} doxygen group */
184 
185  /** @name Editing Colored States */
186  /** @{ doxygen group */
187 
188  /**
189  * Create a new named state and set the color rColorName
190  *
191  * Define FAUDES_CHECKED for consistency checks
192  *
193  * @param rStateName
194  * Name of the state to add
195  *
196  * @param rColorName
197  * Name of the state color
198  *
199  * @return
200  * Index of new unique state
201  *
202  * @exception Exception
203  * - Name already exists (id 104)
204  * - Index not member of set (id 200)
205  */
206  Idx InsColoredState(const std::string& rStateName, const std::string& rColorName);
207 
208  /**
209  * Create a new named state and set the color colorIndex
210  *
211  * Define FAUDES_CHECKED for consistency checks
212  *
213  * @param rStateName
214  * Name of the state to add
215  *
216  * @param colorIndex
217  * Index of the state color, must already exist in symbol table
218  *
219  * @return
220  * Index of new unique state
221  *
222  * @exception Exception
223  * - Color index not known to symbol table (id 200)
224  */
225  Idx InsColoredState(const std::string& rStateName, Idx colorIndex);
226 
227  /**
228  * Create a new named state and set the colors from rColors
229  *
230  * @param rStateName
231  * Name of the state to add
232  *
233  * @param rColors
234  * Color set
235  *
236  * @return
237  * Index of new unique state
238  */
239  Idx InsColoredState(const std::string& rStateName, const ColorSet& rColors);
240 
241  /**
242  * Create a new unnamed state and set the colors from rColors
243  *
244  * @param rColors
245  * Color set
246  *
247  * @return
248  * Index of new unique state
249  */
250  Idx InsColoredState(const ColorSet& rColors);
251 
252  /**
253  * Insert a color by name into an existing state
254  *
255  * Define FAUDES_CHECKED for consistency checks
256  *
257  * @param stateIndex
258  * Index of state to be set as colored state
259  *
260  * @param rColorName
261  * Name of state color to be added
262  *
263  * @return Index of inserted color
264  *
265  * @exception Exception
266  * - Index not member of set (id 200)
267  * - Name already exists / invalid name (id 104)
268  */
269  Idx InsColor(Idx stateIndex, const std::string& rColorName);
270 
271  /**
272  * Insert a color by index into an existing state
273  *
274  * Define FAUDES_CHECKED for consistency checks
275  *
276  * @param stateIndex
277  * Index of state to be set as colored state
278  *
279  * @param colorIndex
280  * Index of color to be added to state, must already exist in symbol table
281  *
282  * @exception Exception
283  * - State index not member of set (id 200)
284  * - Color index not known to symbol table (id 200)
285  */
286  void InsColor(Idx stateIndex, Idx colorIndex);
287 
288  /**
289  * Insert multiple colors from a color set into an existing state
290  *
291  * Define FAUDES_CHECKED for consistency checks
292  *
293  * @param stateIndex
294  * Index of state to be set as colored state
295  *
296  * @param rColors
297  * Reference to color set with colors to set for state, colors must already exist in symbol table
298  *
299  * @exception Exception
300  * - State index not member of set (id 200)
301  * - Symbol table mismach (id 200)
302  * - Symbol table mismatch (id 88)
303  */
304  void InsColors(Idx stateIndex, const ColorSet& rColors);
305 
306  /**
307  * Remove color by name from an existing state specified by index
308  *
309  * Define FAUDES_CHECKED for consistency checks.
310  *
311  * @param stateIndex
312  * State index
313  *
314  * @param rColorName
315  * Name of the state color
316  *
317  * @exception Exception
318  * - Index not member of set (id 200)
319  * - Name not found in NameSet (id 202)
320  */
321  void DelColor(Idx stateIndex, const std::string& rColorName);
322 
323  /**
324  * Remove color by index form an existing state specified by index
325  *
326  * Define FAUDES_CHECKED for consistency checks.
327  *
328  * @param stateIndex
329  * State index
330  *
331  * @param colorIndex
332  * Index of the state color
333  *
334  * @exception Exception
335  * - Index not member of set (id 200)
336  * - Color index not found in generator (id 205)
337  */
338  void DelColor(Idx stateIndex, Idx colorIndex);
339 
340  /**
341  * Remove color by name from all states
342  *
343  * @param rColorName
344  * Name of state color
345  */
346  void DelColor(const std::string& rColorName);
347 
348  /**
349  * Remove color by index from all states
350  *
351  * @param colorIndex
352  * Index of state color
353  */
354  void DelColor(Idx colorIndex);
355 
356  /**
357  * Remove all colors from a particular state. If symbol table
358  * is local, unused colors are deleted from it, global symbol
359  * table stays untouched.
360  *
361  * Define FAUDES_CHECKED for consistency checks
362  *
363  * @param stateIndex
364  * State where colors should be removed
365  *
366  * @exception Exception
367  * - Index not member of set (id 200)
368  */
369  void ClrColors(Idx stateIndex);
370 
371  /**
372  * Clear all the generator's state attributes. The current implementation
373  * also clears the color symbol table if it is local. This behaviour may
374  * change in future.
375  */
376  void ClearStateAttributes();
377 
378  /** @} doxygen group */
379 
380  /** @name Analyse Colored States and State Colors */
381  /** @{ doxygen group */
382 
383  /**
384  * Insert all colors used in the generator to a given ColorSet.
385  *
386  * @param rColors
387  * Color set in which all colors of the generator will be inserted
388  *
389  * @exception Exception
390  * - Symbol table mismatch (id 88)
391  */
392  void Colors(ColorSet& rColors) const;
393 
394  /**
395  * Returns a color set containing all the generator's colors.
396  *
397  * @return
398  * Color set with generators colors
399  */
400  ColorSet Colors(void) const;
401 
402  /**
403  * Return a color set which contains all colors of one state.
404  *
405  * @return
406  * Color set with state's colors
407  *
408  * @exception Exception
409  * - Index not member of set (id 200)
410  */
411  const ColorSet& Colors(Idx stateIndex) const;
412 
413  /**
414  * Returns a state set containing all states that are colored with the color given by index.
415  *
416  * @param colorIndex
417  * Color whose corresponding states shall be returned
418  *
419  * @return
420  * State set containing appropriate states
421  */
422  StateSet ColoredStates(Idx colorIndex) const;
423 
424  /**
425  * Returns a state set containing all states that are colored with the color given by name.
426  *
427  * @param rColorName
428  * Color whose corresponding states shall be returned
429  *
430  * @return
431  * State set containing appropriate states
432  */
433  StateSet ColoredStates(const std::string& rColorName) const;
434 
435  /**
436  * Returns a state set containing all colored states of the MtcSystem.
437  *
438  * @return
439  * State set containing colored states
440  */
441  StateSet ColoredStates() const;
442 
443  /**
444  * Returns a state set containing all states that are not colored.
445  *
446  * @return
447  * State set containing uncolored states
448  */
449  StateSet UncoloredStates() const;
450 
451  /**
452  * Check if color exists in generator.
453  *
454  * @param colorIndex
455  * Index which will be examined regarding existence in the generator
456  *
457  * @return
458  * true if color exists
459  */
460  bool ExistsColor(Idx colorIndex) const;
461 
462  /**
463  * Check if color exists in generator.
464  *
465  * Define FAUDES_CHECKED for consistency checks
466  *
467  * @param rColorName
468  * Color name which will be examined regarding existence in the generator
469  *
470  * @return
471  * true if color exists
472  *
473  * @exception Exception
474  * - Color name not found in symbol table (id 202)
475  */
476  bool ExistsColor(const std::string& rColorName) const;
477 
478  /**
479  * Check if color exists in a given state of the MtcSystem.
480  *
481  * Define FAUDES_CHECKED for consistency checks
482  *
483  * @param stateIndex
484  * Index which determines the generator's state
485  *
486  * @param colorIndex
487  * Color index to look for in given state
488  *
489  * @return
490  * true if color exists in state
491  *
492  * @exception Exception
493  * - Index not member of set (id 200)
494  */
495  bool ExistsColor(Idx stateIndex, Idx colorIndex) const;
496 
497  /**
498  * Check if there is at least one colored state in the MtcSystem.
499  *
500  * @return
501  * True if there is at least one colored state
502  */
503  bool IsColored(void) const;
504 
505  /**
506  * Check if the given state is colored or not.
507  *
508  * Define FAUDES_CHECKED for consistency checks
509  *
510  * @param stateIndex
511  * State to examine
512  *
513  * @return
514  * True if given state is colored
515  *
516  * @exception Exception
517  * - State index not member of set (id 200)
518  */
519  bool IsColored(Idx stateIndex) const;
520 
521  /** @} doxygen group */
522 
523  /** @name Symbol Table */
524  /** @{ doxygen group */
525 
526  /**
527  * Finally deletes a color name and its index from the currently used symbol table.
528  *
529  * @param colorIndex
530  * Index of color to delete from symbol table
531  */
532  void DelColorName(Idx colorIndex);
533 
534  /**
535  * Delete the given color from the symbol table if it is not used anymore in the generator by calling DelColorName.
536  *
537  * @param colorIndex
538  * Color which will be deleted from symbol table if not used anymore
539  */
540  void CheckSymbolTable(Idx colorIndex);
541 
542  /**
543  * 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!
544  *
545  * @param rColors
546  * Color set with all colors that will be deleted from symbol table if not used anymore
547  *
548  * @exception Exception
549  * - Symbol table mismatch (id 88)
550  */
551  void CheckSymbolTable(ColorSet& rColors);
552 
553  /**
554  * Look up the color name for a given color index.
555  *
556  * @param colorIndex
557  *
558  * @return
559  * Color name
560  */
561  std::string ColorName(Idx colorIndex) const;
562 
563  /**
564  * Look up the color index for a given color name.
565  *
566  * @param rColorName
567  *
568  * @return
569  * Color index
570  */
571  Idx ColorIndex(const std::string& rColorName) const;
572 
573  /** @} doxygen group */
574 
575  /** @name Output Methods */
576  /** @{ doxygen group */
577 
578  /**
579  * Writes generator to dot input format.
580 
581  * The dot file format is specified by the graphiz package; see http://www.graphviz.org. The package includes the dot command
582  * line tool to generate a graphical representation of the generators graph. See also Generator::GraphWrite().
583  * This functions sets the re-indexing to minimal indices.
584  *
585  * @param rFileName
586  * Name of file to save result
587  */
588  virtual void DotWrite(const std::string& rFileName) const;
589 
590  /**
591  * Return pretty printable color name for index. Primary meant for debugging messages.
592  *
593  * @param index
594  *
595  * @return std::string
596  * Color name
597  */
598  std::string CStr(Idx index) const;
599 
600  /** @} doxygen group */
601 
602  /** @name Reachability */
603  /** @{ doxygen group */
604 
605  /**
606  * Generate a state set with all strongly coaccessible states.
607  *
608  * @return StateSet
609  * Coaccessible states
610  */
611  StateSet StronglyCoaccessibleSet(void) const;
612 
613  /**
614  * Make generator strongly coaccessible. Forbidden states are deleted.
615  *
616  * @return
617  * True if generator is strongly coaccessible
618  *
619  * <h4>Example: Computation of the strongly coaccessible form of an MtcSystem </h4>
620  * <table border=0> <tr> <td>
621  * <table width=100%>
622  * <tr> <td> <center> Original MtcSystem gen</center> </td> </tr>
623  * <tr> <td> @image html tmp_mtc_functions_1b_acc.png </td> </tr>
624  * <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>
625  * </table>
626  * </td> </tr>
627  * <tr> <td>
628  * <table width=100%>
629  * <tr> <td> <center> Result of gen.StronglyCoaccessible(); </center> </td> </tr>
630  * <tr> <td> @image html tmp_mtc_functions_1d_str_trim.png </td> </tr>
631  * <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>
632  * </table>
633  * </td> </tr>
634  * </table>
635  */
636  bool StronglyCoaccessible(void);
637 
638  /**
639  * Check if MtcSystem is strongly coaccessible.
640  *
641  * @return
642  * True if generator is strongly coaccessible
643  */
644  bool IsStronglyCoaccessible(void) const;
645 
646  /**
647  * Generate a state set with all the strongly trim generator's states.
648  *
649  * @return StateSet
650  * All states for which generator is strongly trim
651  */
652  StateSet StronglyTrimSet(void) const;
653 
654  /**
655  * Make generator strongly trim. Therefore, the forbidden states are deleted.
656  *
657  * @return
658  * True if generator is strongly trim
659  *
660  * <h4>Example: Computation of the strongly trim form of an MtcSystem</h4>
661  * <table border=0> <tr> <td>
662  * <table width=100%>
663  * <tr> <td> <center> Original MtcSystem gen</center> </td> </tr>
664  * <tr> <td> @image html tmp_mtc_functions_1a_not_trim.png </td> </tr>
665  * <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>
666  * </table>
667  * </td> </tr>
668  * <tr> <td>
669  * <table width=100%>
670  * <tr> <td> <center> Result of gen.StronglyTrim(); </center> </td> </tr>
671  * <tr> <td> @image html tmp_mtc_functions_1d_str_trim.png </td> </tr>
672  * <tr> <td> <center> Resulting MtcSystem is strongly trim, which means accessible and strongly coaccessible w.r.t its color set </center> </td> </tr>
673  * </table>
674  * </td> </tr>
675  * </table>
676  */
677  bool StronglyTrim(void);
678 
679  /**
680  * Check if the MtcSystem is strongly trim.
681  *
682  * @return
683  * True if generator is strongly trim
684  */
685  bool IsStronglyTrim(void) const;
686 
687  /** @} doxygen group */
688 
689 
690  /** @name Further Methods */
691  /** @{ doxygen group */
692 
693  /**
694  * Insert a new local color symbol table. mpColorSymbolTable is reset.
695  * The color symbol table pointer in every state attribute's mColors is
696  * also reset to the new symbol table. If there already exist color entries
697  * in the current symbol table, they are copied to the new local one.
698  *
699  * Define FAUDES_CHECKED for consistency checks
700  *
701  * @exception Exception
702  * - Could not insert index and symbol to symbol table (id 44)
703  */
704  void NewColorSymbolTable();
705 
706  /**
707  * Return a color map with state indices and their corresponding colors.
708  * Only states with asociated colors are part of this list.
709  *
710  * @return color map
711  * Standard library map where states and corresponding colors are saved
712  */
713  std::map<Idx,ColorSet> StateColorMap(void) const;
714 
715  /** @} doxygen group */
716 
717  protected:
718  /**
719  * Pointer to currently used symbol table
720  */
722 
723  /** Assignment */
724  void DoAssign(const TmtcGenerator& rSrc);
725 
726  /**
727  * Token output, see Type::SWrite for public wrappers.
728  * The method assumes that the type parameter is a faudes type and uses
729  * the provide write method per entry. Reimplement this function in derived
730  * classes for non-faudes type vectors.
731  *
732  * @param rTw
733  * Reference to TokenWriter
734  *
735  * @exception Exception
736  * - IO errors (id 2)
737  */
738  virtual void DoSWrite(TokenWriter& rTw) const;
739 
740 
741 }; // end class TmtcGeneraator
742 
743 
744 
745 // convenience typedef for std MtcSystem
747 
748 
749 /** Compatibility: pre 2.20b used mtcGenerator as C++ class name*/
750 #ifdef FAUDES_COMPATIBILITY
752 #endif
753 
754 // convenient scope macors
755 #define THIS TmtcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
756 #define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
757 #define TEMP template<class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
758 
759 
760 /**
761  * RTI wrapper function. See also MtcSystem::IsStronglyCoaccessible().
762  * \ingroup GeneratorFunctions
763  */
764 extern FAUDES_API bool IsStronglyCoaccessible(const MtcSystem& rGen);
765 
766 /**
767  * RTI wrapper function. See also MtcSystem::IsStronglyTrim().
768  * \ingroup GeneratorFunctions
769  */
770 extern FAUDES_API bool IsStronglyTrim(const MtcSystem& rGen);
771 
772 /**
773  * RTI wrapper function. See also MtcSystem::Coaccessible().
774  * \ingroup GeneratorFunctions
775  */
776 extern FAUDES_API void StronglyCoaccessible(MtcSystem& rGen);
777 
778 /**
779  * RTI wrapper function. See also MtcSystem::Coaccessible().
780  * \ingroup GeneratorFunctions
781  */
782 extern FAUDES_API void StronglyCoaccessible(const MtcSystem& rGen, MtcSystem& rRes);
783 
784 /**
785  * RTI wrapper function. See also MtcSystem::Trim().
786  * \ingroup GeneratorFunctions
787  */
788 extern FAUDES_API void StronglyTrim(MtcSystem& rGen);
789 
790 /**
791  * RTI wrapper function. See also MtcSystem::Trim().
792  * \ingroup GeneratorFunctions
793  */
794 extern FAUDES_API void StronglyTrim(const MtcSystem& rGen, MtcSystem& rRes);
795 
796 
797 
798 // TmtcGenerator(void)
799 TEMP THIS::TmtcGenerator(void) : BASE() {
800  FD_DG("MtcSystem(" << this << ")::MtcSystem()");
802 }
803 
804 // TmtcGenerator(rOtherGen)
805 TEMP THIS::TmtcGenerator(const TmtcGenerator& rOtherGen) : BASE() {
806  FD_DG("MtcSystem(" << this << ")::MtcSystem(rOtherGen)");
807  if (rOtherGen.ColorSymbolTablep() != ColorSet::StaticSymbolTablep())
810  DoAssign(rOtherGen);
811 }
812 
813 // TmtcGenerator(rOtherGen)
814 TEMP THIS::TmtcGenerator(const vGenerator& rOtherGen) : BASE() {
815  FD_DG("MtcSystem(" << this << ")::MtcSystem(rOtherGen)");
817  Assign(rOtherGen);
818 }
819 
820 // TmtcGenerator(rFilename)
821  TEMP THIS::TmtcGenerator(const std::string& rFileName) : BASE() {
822  FD_DG("MtcSystem(" << this << ")::MtcSystem(" << rFileName << ")");
824  BASE::Read(rFileName);
825 }
826 
827 // New/Copy
828 TEMP THIS* THIS::New(void) const {
829  // allocate
830  THIS* res = new THIS;
831  // fix base data
832  res->EventSymbolTablep(BASE::mpEventSymbolTable);
833  res->mStateNamesEnabled=BASE::mStateNamesEnabled;
834  res->mReindexOnWrite=BASE::mReindexOnWrite;
835  // fix my data
836  res->ColorSymbolTable(GlobalColorSymbolTablep());
837  // done
838  return res;
839 }
840 
841 // Copy
842 TEMP THIS* THIS::Copy(void) const {
843  // allocate
844  THIS* res = new THIS(*this);
845  // done
846  return res;
847 }
848 
849 
850 
851 
852 // DoAssign(gen)
853 TEMP void THIS::DoAssign(const TmtcGenerator& rSrc) {
854  FD_DG("MtcSystem(" << this << ")::DoAssign(gen&)");
855  // call base method
856  BASE::DoAssign(rSrc);
857  // my members
858  ColorSymbolTable(rSrc.ColorSymbolTablep());
859  // fix non std symboltable (broken)
860  /*
861  if (rSrc.ColorSymbolTablep() != ColorSet::StaticSymbolTablep()) {
862  NewColorSymbolTable();
863 
864  ColorSet mycolors(mpColorSymbolTable);
865  Colors(mycolors);
866  ColorSet::Iterator cit;
867  ColorSet::Iterator cit_end = mycolors.End();
868 
869  for (cit = mycolors.Begin(); cit != cit_end; cit++) {
870  ColorSymbolTablep()->SetEntry(*cit, ColorName(*cit));
871  }
872  }
873  */
874 }
875 
876 // copy from other faudes type
877 TEMP THIS& THIS::Assign(const Type& rSrc) {
878  FD_DG("TmtcGenerator(" << this << ")::Assign([type] " << &rSrc << ")");
879  // bail out on match
880  if(&rSrc==static_cast<Type*>(this)) return *this;
881  // clear to default
882  this->Clear();
883  // try to cast to this class
884  const TmtcGenerator* mtcgen=dynamic_cast<const TmtcGenerator*>(&rSrc);
885  if(mtcgen) {
886  DoAssign(*mtcgen);
887  return *this;
888  }
889  // pass on to base
890  BASE::Assign(rSrc);
891  return *this;
892 }
893 
894 // GlobalColorSymbolTablep()
895 TEMP SymbolTable* THIS::GlobalColorSymbolTablep(void) const {
897 }
898 
899 // ColorSymbolTablep()
900 TEMP SymbolTable* THIS::ColorSymbolTablep(void) const {
901  return mpColorSymbolTable;
902 }
903 
904 // ColorSymbolTable(SymbolTable*)
905 TEMP void THIS::ColorSymbolTable(SymbolTable* pSymTab) {
906  mpColorSymbolTable=pSymTab;
907 }
908 
909 // ColorSymbolTable(rOtherGen)
910 TEMP void THIS::ColorSymbolTable(const TmtcGenerator& rOtherGen) {
911  ColorSymbolTable(rOtherGen.ColorSymbolTablep());
912 }
913 
914 // InsColoredState(rStateName, rColorName)
915 TEMP Idx THIS::InsColoredState(const std::string& rStateName, const std::string& rColorName) {
916  FD_DG("MtcSystem(" << this << ")::InsColoredState(rStateName, colorName)");
917  StateAttr *attr;
918  Idx index;
919 #ifdef FAUDES_CHECKED
920  try {
921  index = BASE::InsState(rStateName);
922  }
923  catch (faudes::Exception& exception){
924  std::stringstream errstr;
925  errstr << "Name \"" << rStateName << "\" already exists" << std::endl;
926  throw Exception("MtcSystem::InsColoredState(rStateName, rColorName)", errstr.str(), 104);
927  }
928  try {
929  attr = BASE::StateAttributep(index);
930  }
931  catch (faudes::Exception& exception){
932  std::stringstream errstr;
933  errstr << "Index " << index << " not member of set" << std::endl;
934  throw Exception("MtcSystem::InsColoredState(stateIndex, colorIndex)", errstr.str(), 200);
935  }
936  try {
937  attr->Colors().Insert(rColorName);
938  }
939  catch (faudes::Exception& exception){
940  std::stringstream errstr;
941  errstr << "Name already exists / invalid name: " << rColorName << std::endl;
942  throw Exception("MtcSystem::InsColoredState(stateIndex, rColorName)", errstr.str(), 104);
943  }
944 #else
945  index = BASE::InsState(rStateName);
946  attr = Attributep(index);
947  attr->Colors().Insert(rColorName);
948 #endif
949  return index;
950 }
951 
952 // InsColoredState(rStateName, colorIndex)
953 TEMP Idx THIS::InsColoredState(const std::string& rStateName, const Idx colorIndex) {
954  Idx index = BASE::InsState(rStateName);
955  StateAttr *attr = BASE::StateAttributep(index);
956 #ifdef FAUDES_CHECKED
957  try {
958  attr->Colors().Insert(colorIndex);
959  }
960  catch (faudes::Exception& exception){
961  std::stringstream errstr;
962  errstr << "Color index " << colorIndex << " not known to symbol table" << std::endl;
963  throw Exception("MtcSystem::InsColoredState(rStateName, colorIndex)", errstr.str(), 200);
964  }
965 #else
966  attr->Colors().Insert(colorIndex);
967 #endif
968  return index;
969 }
970 
971 // InsColoredState(rStateName, rColors)
972 TEMP Idx THIS::InsColoredState(const std::string& rStateName, const ColorSet& rColors) {
973  Idx index = BASE::InsState(rStateName);
974  InsColors(index, rColors);
975  return index;
976 }
977 
978 // InsColoredState(rColors)
979 TEMP Idx THIS::InsColoredState(const ColorSet& rColors) {
980  Idx index = BASE::InsState();
981  InsColors(index, rColors);
982  return index;
983 }
984 
985 // InsColor(stateIndex, rColorName)
986 TEMP Idx THIS::InsColor(Idx stateIndex, const std::string& rColorName) {
987  StateAttr *attr;
988  Idx index;
989 #ifdef FAUDES_CHECKED
990  try {
991  attr = BASE::StateAttributep(stateIndex);
992  }
993  catch (faudes::Exception& exception){
994  std::stringstream errstr;
995  errstr << "State index " << stateIndex << " not member of set" << std::endl;
996  throw Exception("MtcSystem::InsColor(stateIndex, colorIndex)", errstr.str(), 200);
997  }
998  try {
999  index = attr->Colors().Insert(rColorName);
1000  }
1001  catch (faudes::Exception& exception){
1002  std::stringstream errstr;
1003  errstr << "Name already exists / invalid name: " << rColorName << std::endl;
1004  throw Exception("MtcSystem::InsColor(stateIndex, rColorName)", errstr.str(), 104);
1005  }
1006 #else
1007  attr = Attributep(stateIndex);
1008  index = attr->Colors().Insert(rColorName);
1009 #endif
1010  return index;
1011 }
1012 
1013 // InsColor(stateIndex, colorIndex)
1014 TEMP void THIS::InsColor(Idx stateIndex, Idx colorIndex) {
1015  StateAttr *attr;
1016 #ifdef FAUDES_CHECKED
1017  try {
1018  attr = BASE::StateAttributep(stateIndex);
1019  }
1020  catch (faudes::Exception& exception){
1021  std::stringstream errstr;
1022  errstr << "State index " << stateIndex << " not member of set" << std::endl;
1023  throw Exception("MtcSystem::InsColor(stateIndex, colorIndex)", errstr.str(), 200);
1024  }
1025  try {
1026  attr->Colors().Insert(colorIndex);
1027  }
1028  catch (faudes::Exception& exception){
1029  std::stringstream errstr;
1030  errstr << "Color index " << colorIndex << " not known to symbol table" << std::endl;
1031  throw Exception("MtcSystem::InsColor(stateIndex, colorIndex)", errstr.str(), 200);
1032  }
1033 #else
1034  attr = Attributep(stateIndex);
1035  attr->Colors().Insert(colorIndex);
1036 #endif
1037 }
1038 
1039 // InsColors(stateIndex, rColors)
1040 TEMP void THIS::InsColors(Idx stateIndex, const ColorSet& rColors) {
1041 #ifdef FAUDES_CHECKED
1042  if(rColors.SymbolTablep() != mpColorSymbolTable) {
1043  std::stringstream errstr;
1044  errstr << "Symbol table mismatch" << std::endl;
1045  throw Exception("MtcSystem::InsColors(stateIndex, rColors)", errstr.str(), 88);
1046  }
1047 #endif
1048  StateAttr *attr;
1049 #ifdef FAUDES_CHECKED
1050  try {
1051  attr = BASE::StateAttributep(stateIndex);
1052  }
1053  catch (faudes::Exception& exception){
1054  std::stringstream errstr;
1055  errstr << "State index " << stateIndex << " not member of set" << std::endl;
1056  throw Exception("MtcSystem::InsColors(stateIndex, rColors)", errstr.str(), 200);
1057  }
1058  try {
1059  attr->Colors().InsertSet(rColors);
1060  }
1061  catch (faudes::Exception& exception){
1062  std::stringstream errstr;
1063  errstr << "Symbol table mismach" << std::endl;
1064  throw Exception("MtcSystem::InsColors(stateIndex, rColors)", errstr.str(), 200);
1065  }
1066 #else
1067  attr = Attributep(stateIndex);
1068  attr->Colors().InsertSet(rColors);
1069 #endif
1070 }
1071 
1072 // DelColor(stateIndex, rColorName)
1073 TEMP void THIS::DelColor(Idx stateIndex, const std::string& rColorName) {
1074  StateAttr *attr;
1075  Idx index;
1076 #ifdef FAUDES_CHECKED
1077  try {
1078  attr = BASE::StateAttributep(stateIndex);
1079  }
1080  catch (faudes::Exception& exception){
1081  std::stringstream errstr;
1082  errstr << "State index " << stateIndex << " not member of set" << std::endl;
1083  throw Exception("MtcSystem::DelColor(stateIndex, rColorName)", errstr.str(), 200);
1084  }
1085  index = ColorIndex(rColorName);
1086  try {
1087  attr->Colors().Erase(index);
1088  }
1089  catch (faudes::Exception& exception){
1090  std::stringstream errstr;
1091  errstr << "Color name \"" << rColorName << "\" not found in NameSet" << std::endl;
1092  throw Exception("MtcSystem::DelColor(stateIndex, rColorName)", errstr.str(), 202);
1093  }
1094 #else
1095  attr = Attributep(stateIndex);
1096  index = ColorIndex(rColorName);
1097  attr->Colors().Erase(index);
1098 #endif
1099  CheckSymbolTable(index);
1100 }
1101 
1102 // DelColor(stateIndex, colorIndex)
1103 TEMP void THIS::DelColor(Idx stateIndex, Idx colorIndex) {
1104  StateAttr *attr;
1105  bool res;
1106 #ifdef FAUDES_CHECKED
1107  try {
1108  attr = BASE::StateAttributep(stateIndex);
1109  }
1110  catch (faudes::Exception& exception){
1111  std::stringstream errstr;
1112  errstr << "State index " << stateIndex << " not member of set" << std::endl;
1113  throw Exception("MtcSystem::DelColor(stateIndex, colorIndex)", errstr.str(), 200);
1114  }
1115 #else
1116  attr = BASE::StateAttributep(stateIndex);
1117 #endif
1118  res = attr->Colors().Erase(colorIndex);
1119  if (!res) {
1120  std::stringstream errstr;
1121  errstr << "Color index " << colorIndex << " not found in generator" << std::endl;
1122  throw Exception("MtcSystem::DelColor(stateIndex, colorIndex)", errstr.str(), 205);
1123  }
1124  CheckSymbolTable(colorIndex);
1125 }
1126 
1127 // DelColor(rColorName)
1128 TEMP void THIS::DelColor(const std::string& rColorName) {
1129  StateSet::Iterator lit;
1130  StateAttr *attr;
1131 
1132  Idx index = ColorIndex(rColorName);
1133 
1134  for (lit = BASE::pStates->Begin(); lit != BASE::pStates->End(); lit++) {
1135  attr = BASE::StateAttributep(*lit);
1136  attr->Colors().Erase(index);
1137  }
1138  CheckSymbolTable(index);
1139 }
1140 
1141 // DelColor(colorIndex)
1142 TEMP void THIS::DelColor(Idx colorIndex) {
1143  StateSet::Iterator lit;
1144  StateAttr *attr;
1145  for (lit = BASE::pStates->Begin(); lit != BASE::pStates->End(); lit++) {
1146  attr = BASE::StateAttributep(*lit);
1147  attr->Colors().Erase(colorIndex);
1148  }
1149  CheckSymbolTable(colorIndex);
1150 }
1151 
1152 // ClrColors(stateIndex)
1153 TEMP void THIS::ClrColors(Idx stateIndex) {
1154  StateAttr *attr;
1155  ColorSet::Iterator cit;
1156  ColorSet delColors(mpColorSymbolTable);
1157 #ifdef FAUDES_CHECKED
1158  try {
1159  attr = BASE::StateAttributep(stateIndex);
1160  }
1161  catch (faudes::Exception& exception){
1162  std::stringstream errstr;
1163  errstr << "State index " << stateIndex << " not member of set" << std::endl;
1164  throw Exception("MtcSystem::ClrColors(stateIndex)", errstr.str(), 200);
1165  }
1166 #else
1167  attr = BASE::StateAttributep(stateIndex);
1168 #endif
1169  delColors.InsertSet(attr->Colors());
1170  attr->Colors().Clear();
1171  CheckSymbolTable(delColors);
1172 }
1173 
1174 // DelColorName(colorIndex)
1175 TEMP void THIS::DelColorName(Idx colorIndex) {
1176  ColorSymbolTablep()->ClrEntry(colorIndex);
1177 }
1178 
1179 // Colors(rColors)
1180 TEMP void THIS::Colors(ColorSet& rColors) const {
1181 #ifdef FAUDES_CHECKED
1182  if(rColors.SymbolTablep() != mpColorSymbolTable) {
1183  std::stringstream errstr;
1184  errstr << "Symbol table mismatch" << std::endl;
1185  throw Exception("MtcSystem::Colors", errstr.str(), 88);
1186  }
1187 #endif
1188  StateSet::Iterator lit;
1189  for (lit = BASE::pStates->Begin(); lit != BASE::pStates->End(); lit++) {
1190  const StateAttr& attr = BASE::pStates->Attribute(*lit);
1191  rColors.InsertSet(attr.Colors());
1192  }
1193 }
1194 
1195 // Colors()
1196 TEMP ColorSet THIS::Colors(void) const {
1197  StateSet::Iterator lit;
1198  ColorSet colors(mpColorSymbolTable);
1199  for (lit = BASE::pStates->Begin(); lit != BASE::pStates->End(); lit++) {
1200  const StateAttr& attr = BASE::pStates->Attribute(*lit);
1201  colors.InsertSet(attr.Colors());
1202  }
1203  return colors;
1204 }
1205 
1206 // Colors(stateIndex)
1207 TEMP const ColorSet& THIS::Colors(Idx stateIndex) const {
1208  const StateAttr* attrp;
1209 #ifdef FAUDES_CHECKED
1210  try {
1211  attrp = &BASE::pStates->Attribute(stateIndex);
1212  }
1213  catch (faudes::Exception& exception){
1214  std::stringstream errstr;
1215  errstr << "State index " << stateIndex << " not member of set" << std::endl;
1216  throw Exception("MtcSystem::Colors(stateIndex)", errstr.str(), 200);
1217  }
1218 #else
1219  attrp = &BASE::pStates->Attribute(stateIndex);
1220 #endif
1221  return attrp->Colors();
1222 }
1223 
1224 // CheckSymbolTable(colorIndex)
1225 TEMP void THIS::CheckSymbolTable(Idx colorIndex) {
1226  if (ColorSymbolTablep() != ColorSet::StaticSymbolTablep()) {
1227  ColorSet colors(mpColorSymbolTable);
1228  Colors(colors);
1229  if (!colors.Exists(colorIndex))
1230  DelColorName(colorIndex);
1231  }
1232 }
1233 
1234 // CheckSymbolTable(rColors)
1235 TEMP void THIS::CheckSymbolTable(ColorSet& rColors) {
1236 #ifdef FAUDES_CHECKED
1237  if(rColors.SymbolTablep() != mpColorSymbolTable) {
1238  std::stringstream errstr;
1239  errstr << "Symbol table mismatch" << std::endl;
1240  throw Exception("MtcSystem::CheckSymbolTable", errstr.str(), 88);
1241  }
1242 #endif
1243  if (ColorSymbolTablep() != ColorSet::StaticSymbolTablep()) {
1244  ColorSet colors(mpColorSymbolTable);
1245  // all generator's colors are inserted
1246  Colors(colors);
1247  ColorSet::Iterator cit;
1248  for(cit = rColors.Begin(); cit != rColors.End(); cit++) {
1249  // are colors from rColors still in use?
1250  if(!colors.Exists(*cit)) DelColorName(*cit);
1251  }
1252  }
1253 }
1254 
1255 // ExistsColor(colorIndex)
1256 TEMP bool THIS::ExistsColor(Idx colorIndex) const {
1257  StateSet::Iterator lit;
1258  for (lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
1259  if (ExistsColor(*lit, colorIndex)) return true;
1260  }
1261  return false;
1262 }
1263 
1264 // ExistsColor(colorName)
1265 TEMP bool THIS::ExistsColor(const std::string& rColorName) const {
1266  Idx colorIndex = ColorIndex(rColorName);
1267 #ifdef FAUDES_CHECKED
1268  if (colorIndex == 0) {
1269  std::stringstream errstr;
1270  errstr << "Color name \"" << rColorName << "\" not found in symbol table " << std::endl;
1271  throw Exception("MtcSystem::ExistsColor(rColorName)", errstr.str(), 202);
1272  }
1273 #endif
1274  return ExistsColor(colorIndex);
1275 }
1276 
1277 // ColorName(index)
1278 TEMP std::string THIS::ColorName(Idx colorIndex) const {
1279  return ColorSymbolTablep()->Symbol(colorIndex);
1280 }
1281 
1282 // ColorIndex(rColorName)
1283 TEMP Idx THIS::ColorIndex(const std::string& rColorName) const {
1284  return ColorSymbolTablep()->Index(rColorName);
1285 }
1286 
1287 // CStr(index)
1288 TEMP std::string THIS::CStr(Idx index) const {
1289  return ColorName(index);
1290 }
1291 
1292 // ExistsColor(stateIndex, colorIndex)
1293 TEMP bool THIS::ExistsColor(Idx stateIndex, Idx colorIndex) const {
1294 #ifdef FAUDES_CHECKED
1295  try {
1296  return BASE::pStates->Attribute(stateIndex).Colors().Exists(colorIndex);
1297  }
1298  catch (faudes::Exception& exception){
1299  std::stringstream errstr;
1300  errstr << "State index " << stateIndex << " not member of set" << std::endl;
1301  throw Exception("MtcSystem::ExistsColor(stateIndex, colorIndex)", errstr.str(), 200);
1302  }
1303 #else
1304  return BASE::pStates->Attribute(stateIndex).Colors().Exists(colorIndex);
1305 #endif
1306 }
1307 
1308 // DotWrite(rFileName)
1309 TEMP void THIS::DotWrite(const std::string& rFileName) const {
1310  FD_DG("TmtcGenerator(" << this << ")::DotWrite(" << rFileName << ")");
1311  TaIndexSet<StateAttr> coloredStates;
1312  StateSet::Iterator it;
1313  BASE::SetMinStateIndexMap();
1314  typename TransSet::Iterator tit;
1315  try {
1316  std::ofstream stream;
1317  stream.exceptions(std::ios::badbit|std::ios::failbit);
1318  stream.open(rFileName.c_str());
1319  stream << "// dot output generated by libFAUDES TmtcGenerator" << std::endl;
1320  stream << "digraph \"" << BASE::Name() << "\" {" << std::endl;
1321  stream << " rankdir=LR" << std::endl;
1322  stream << " node [shape=circle];" << std::endl;
1323  stream << std::endl;
1324  stream << " // initial states" << std::endl;
1325  int i = 1;
1326  for (it = BASE::InitStatesBegin(); it != BASE::InitStatesEnd(); ++it) {
1327  std::string xname= BASE::StateName(*it);
1328  if(xname=="") xname=ToStringInteger(static_cast<long int>(BASE::MinStateIndex(*it)));
1329  stream << " dot_dummyinit_" << i << " [shape=none, label=\"\" ];" << std::endl;
1330  stream << " dot_dummyinit_" << i << " -> \"" << xname << "\";" << std::endl;
1331  i++;
1332  }
1333  stream << std::endl;
1334 
1335  // uncolored states - output
1336  stream << " // uncolored states" << std::endl;
1337  for (it = BASE::pStates->Begin(); it != BASE::pStates->End(); ++it) {
1338  // does the state have a colored attribute?
1339  const StateAttr& attr = BASE::StateAttribute(*it);
1340  // handling colored states - copy to coloredStates
1341  if (!attr.IsDefault()) {
1342  coloredStates.Insert(*it, attr);
1343  }
1344  else {
1345  std::string xname=BASE::StateName(*it);
1346  if(xname=="") xname=ToStringInteger(BASE::MinStateIndex(*it));
1347  stream << " \"" << xname << "\";" << std::endl;
1348  }
1349  }
1350 
1351  // colored states - output
1352  std::vector<std::string> ColorVector;
1353  ColorVector.push_back("blue");
1354  ColorVector.push_back("red");
1355  ColorVector.push_back("magenta");
1356  ColorVector.push_back("green");
1357  ColorVector.push_back("darkorange");
1358  ColorVector.push_back("cyan");
1359  ColorVector.push_back("navy");
1360  ColorVector.push_back("brown");
1361  ColorVector.push_back("green4");
1362  ColorVector.push_back("yellow");
1363  ColorVector.push_back("darkviolet");
1364  ColorVector.push_back("firebrick");
1365  ColorVector.push_back("greenyellow");
1366  ColorVector.push_back("peru");
1367  ColorVector.push_back("skyblue");
1368  ColorVector.push_back("darkgreen");
1369  ColorVector.push_back("violetred");
1370  ColorVector.push_back("lightsalmon");
1371  ColorVector.push_back("seagreen");
1372  ColorVector.push_back("saddlebrown");
1373  ColorVector.push_back("slateblue");
1374  ColorVector.push_back("thistle");
1375  ColorVector.push_back("turquoise4");
1376  ColorVector.push_back("gold2");
1377  ColorVector.push_back("sandybrown");
1378  ColorVector.push_back("aquamarine3");
1379  ColorVector.push_back("darkolivegreen");
1380  ColorVector.push_back("yellow4");
1381 
1382  stream << std::endl;
1383  stream << " // colored states" << std::endl;
1384  int clustNr = 0;
1385  for (it = coloredStates.Begin(); it != coloredStates.End(); it++) {
1386  int count = 0;
1387  std::string xname=BASE::StateName(*it);
1388  if(xname=="") xname=ToStringInteger(static_cast<long int>(BASE::MinStateIndex(*it)));
1389  const StateAttr& attr = coloredStates.Attribute(*it);
1390  if (attr.Colors().Size() > 1) {
1391  for(ColorSet::Iterator cit = attr.ColorsBegin(); cit != attr.ColorsEnd(); cit++) {
1392  stream << " subgraph cluster_" << clustNr++ << " {color=" << ColorVector.at(*cit-1) << ";" << std::endl;
1393  count++;
1394  }
1395  stream << " \"" << xname << "\" " << std::endl << " ";
1396  for (int i=0; i<count; i++) {
1397  stream << "}";
1398  }
1399  stream << std::endl;
1400  }
1401  else if (attr.Colors().Size() == 1) {
1402  ColorSet::Iterator cit;
1403  if ((cit = attr.ColorsBegin()) != attr.ColorsEnd())
1404  stream << " \"" << xname << "\" " << "[color=" << ColorVector.at(*cit-1) << "]" << std::endl;
1405  }
1406  }
1407  stream << std::endl;
1408 
1409  // marked states
1410  stream << " // marked states" << std::endl;
1411  for (it = BASE::MarkedStatesBegin(); it != BASE::MarkedStatesEnd(); ++it) {
1412  std::string xname= BASE::StateName(*it);
1413  if(xname=="") xname=ToStringInteger(static_cast<long int>(BASE::MinStateIndex(*it)));
1414  stream << " \"" << xname << "\";" << std::endl;
1415  i++;
1416  }
1417 
1418  // transitions
1419  stream << std::endl;
1420  stream << " // transition relation" << std::endl;
1421  for (tit = BASE::TransRelBegin(); tit != BASE::TransRelEnd(); ++tit) {
1422  std::string x1name= BASE::StateName(tit->X1);
1423  if(x1name=="") x1name=ToStringInteger(BASE::MinStateIndex(tit->X1));
1424  std::string x2name= BASE::StateName(tit->X2);
1425  if(x2name=="") x2name=ToStringInteger(BASE::MinStateIndex(tit->X2));
1426  stream << " \"" << x1name << "\" -> \"" << x2name << "\" [label=\"" << BASE::EventName(tit->Ev) << "\"];" << std::endl;
1427  }
1428  stream << "}" << std::endl;
1429  stream.close();
1430  }
1431  catch (std::ios::failure&) {
1432  throw Exception("TaGenerator::DotWrite",
1433  "Exception opening/writing dotfile \""+rFileName+"\"", 3);
1434  }
1435  BASE::ClearMinStateIndexMap();
1436 }
1437 
1438 // StateColorMap()
1439 TEMP
1440 typename std::map<Idx,ColorSet>
1441 THIS::StateColorMap(void) const {
1442  StateSet::Iterator lit;
1443  std::map<Idx,ColorSet> map;
1444  StateSet cstates = ColoredStates();
1445  for (lit = cstates.Begin(); lit != cstates.End(); lit++) {
1446  map.insert(std::make_pair(*lit, Colors(*lit)));
1447  FD_DF("make_pair(" << ToStringInteger(*lit) << ", " << (THIS::Colors(*lit).ToString()) << ")");
1448  }
1449  return map;
1450 }
1451 
1452 // ColoredStates(ColorIndex)
1453 TEMP StateSet THIS::ColoredStates(Idx colorIndex) const {
1454  StateSet::Iterator lit;
1455  StateSet coloredStates;
1456  for (lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
1457  if(ExistsColor(*lit, colorIndex)) coloredStates.Insert(*lit);
1458  }
1459  return coloredStates;
1460 }
1461 
1462 // ColoredStates(ColorName)
1463 TEMP StateSet THIS::ColoredStates(const std::string& rColorName) const{
1464  Idx colorIndex = ColorIndex(rColorName);
1465  return ColoredStates(colorIndex);
1466 }
1467 
1468 // ColoredStates()
1469 TEMP StateSet THIS::ColoredStates() const {
1470  StateSet::Iterator lit;
1471  StateSet coloredStates;
1472  for(lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
1473  if(IsColored(*lit)) coloredStates.Insert(*lit);
1474  }
1475  return coloredStates;
1476 }
1477 
1478 // UncoloredStates()
1479 TEMP StateSet THIS::UncoloredStates() const {
1480  StateSet::Iterator lit;
1481  StateSet uncoloredStates;
1482  for (lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
1483  if (!IsColored(*lit)) uncoloredStates.Insert(*lit);
1484  }
1485  return uncoloredStates;
1486 }
1487 
1488 // IsColored()
1489 TEMP bool THIS::IsColored(void) const {
1490  StateSet::Iterator lit;
1491  for(lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); lit++) {
1492  if(IsColored(*lit)) return true;
1493  }
1494  return false;
1495 }
1496 
1497 // IsColored(stateIndex)
1498 TEMP bool THIS::IsColored(Idx stateIndex) const {
1499 #ifdef FAUDES_CHECKED
1500  try {
1501  return !BASE::pStates->Attribute(stateIndex).Colors().Empty();
1502  }
1503  catch (faudes::Exception& exception){
1504  std::stringstream errstr;
1505  errstr << "State index " << stateIndex << " not member of set" << std::endl;
1506  throw Exception("MtcSystem::IsColored(stateIndex)", errstr.str(), 200);
1507  }
1508 #else
1509  return !BASE::pStates->Attribute(stateIndex).Colors().Empty();
1510 #endif
1511 }
1512 
1513 TEMP StateSet THIS::StronglyCoaccessibleSet(void) const {
1514  MtcSystem tmp(*this);
1515  StateSet stronglyCoac, notStronglyCoac;
1516  ColorSet colors;
1517  stronglyCoac = BASE::States();
1518  Colors(colors);
1519 
1520  ColorSet::Iterator cit = colors.Begin();
1521  ColorSet::Iterator cit_end = colors.End();
1522 
1523  for (; cit != cit_end; cit++) {
1524  StateSet tmp1, tmp2;
1525  StateSet states = ColoredStates(*cit);
1526  tmp.InjectMarkedStates(states);
1527  tmp1 = tmp.CoaccessibleSet();
1528  tmp2 = stronglyCoac * tmp1;
1529  stronglyCoac = tmp2;
1530  }
1531  tmp.ClearMarkedStates();
1532  return stronglyCoac;
1533 }
1534 
1536  StateSet stronglyCoacSet = StronglyCoaccessibleSet();
1537  StateSet notStronglyCoac = BASE::States() - stronglyCoacSet;
1538  BASE::DelStates(notStronglyCoac);
1539  return (StronglyCoaccessibleSet() == BASE::States());
1540 }
1541 
1543  return (StronglyCoaccessibleSet() == BASE::States());
1544 }
1545 
1546 // StronglyTrimSet()
1547 TEMP StateSet THIS::StronglyTrimSet(void) const {
1548  FD_DF("TmtcGenerator::StronglyTrimSet: trim states: "
1549  << StateSet(BASE::AccessibleSet() * StronglyCoaccessibleSet()).ToString());
1550  return BASE::AccessibleSet() * StronglyCoaccessibleSet();
1551 }
1552 
1553 // StronglyTrim()
1555  // better: compute sets and do one state delete
1556  bool accessiblebool = BASE::Accessible();
1557  bool coaccessiblebool = StronglyCoaccessible();
1558  FD_DF("TmtcGenerator::StronglyTrim: trim states: " << (THIS::mpStates->ToString()));
1559  if (accessiblebool && coaccessiblebool) {
1560  FD_DF("TmtcGenerator::StronglyTrim: generator is trim");
1561  return true;
1562  }
1563  FD_DF("TmtcGenerator::StronglyTrim: generator is not trim");
1564  return false;
1565 }
1566 
1567 // IsStronglyTrim()
1568 TEMP bool THIS::IsStronglyTrim(void) const {
1570  FD_DF("TmtcGenerator::IsStronglyTrim: generator is strongly trim");
1571  return true;
1572  }
1573  else {
1574  FD_DF("TmtcGenerator::IsStronglyTrim: generator is not strongly trim");
1575  return false;
1576  }
1577 }
1578 
1579 // NewColorSymbolTable()
1580 TEMP void THIS::NewColorSymbolTable() {
1581 
1582  StateSet::Iterator lit;
1583  StateAttr *attr;
1584 
1585  StateSet coloredStates = ColoredStates();
1586  coloredStates.Write();
1587  SymbolTable *tmp;
1588  tmp = new SymbolTable;
1589 
1590  // iterate over all colored states
1591  for (lit = coloredStates.Begin(); lit != coloredStates.End(); lit++) {
1592  // get attributes for current state
1593  attr = BASE::pStates->Attributep(*lit);
1594  ColorSet::Iterator cit, cit_end;
1595  cit_end = attr->ColorsEnd();
1596  // iterate over all colors of the current state
1597  for (cit = attr->ColorsBegin(); cit != cit_end; cit++) {
1598 #ifdef FAUDES_CHECKED
1599  try {
1600  // insert color indices and color names to new color symbol table
1601  tmp->InsEntry(*cit, attr->Colors().SymbolicName(*cit));
1602  }
1603  catch (faudes::Exception& exception){
1604  std::stringstream errstr;
1605  errstr << "Could not insert index \"" << *cit << "\" and symbol \"" <<
1606  attr->Colors().SymbolicName(*cit) << "\" to symbol table" << std::endl;
1607  throw Exception("MtcSystem::NewColorSymbolTable()", errstr.str(), 44);
1608  }
1609 #else
1610  tmp->InsEntry(*cit, attr->Colors().SymbolicName(*cit));
1611 #endif
1612  }
1613  // reset color symbol table pointers
1614  mpColorSymbolTable = tmp;
1615  attr->ColorSymTab(tmp);
1616  }
1617 }
1618 
1619 // ClearStateAttributes()
1620 TEMP void THIS::ClearStateAttributes() {
1621  if(ColorSet::StaticSymbolTablep() != mpColorSymbolTable) mpColorSymbolTable->Clear();
1622  BASE::ClearStateAttributes();
1623 }
1624 
1625 
1626 // DoSWrite(rTw&)
1627 TEMP void THIS::DoSWrite(TokenWriter& rTw) const {
1628  // set up color statistics
1629  std::set<Idx> colcount;
1630  StateSet::Iterator sit;
1631  for(sit = BASE::StatesBegin(); sit != BASE::StatesEnd(); sit++) {
1632  colcount.insert(Colors(*sit).Size());
1633  }
1634  // convert to string
1635  std::multiset<Idx>::iterator cit;
1636  std::stringstream countstr;
1637  for(cit = colcount.begin(); cit != colcount.end(); cit++) {
1638  countstr << *cit << " ";
1639  }
1640  // write
1641  BASE::DoSWrite(rTw);
1642  rTw.WriteComment(" Colors (all): " + ToStringInteger(Colors().Size()) );
1643  rTw.WriteComment(" Colors (dist): " + countstr.str());
1644  rTw.WriteComment("");
1645 }
1646 
1647 #undef BASE
1648 #undef THIS
1649 #undef TEMP
1650 
1651 } // namespace faudes
1652 
1653 #endif
#define FD_DG(message)
Debug: optional report on generator operations.
#define FD_DF(message)
Debug: optional report on user functions.
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:81
Container for colors: this is a NameSet with its own static symboltable.
Definition: mtc_colorset.h:41
static SymbolTable * StaticSymbolTablep(void)
Get pointer to static ColorSymbolTable.
Faudes exception class.
Set of indices.
Definition: cfl_indexset.h:78
Idx Insert(void)
Insert new index to set.
bool Exists(const Idx &rIndex) const
Test existence of index.
virtual void InsertSet(const NameSet &rOtherSet)
Inserts all elements of rOtherSet.
SymbolTable * SymbolTablep(void) const
Get Pointer mpSymbolTable.
A SymbolTable associates sybolic names with indices.
Idx InsEntry(Idx index, const std::string &rName)
Add new entry (aka symbolic name and index) to symboltable,.
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
Iterator on transition.
Definition: cfl_transset.h:269
Idx Insert(void)
Insert new index to set using default attribute.
Definition: cfl_indexset.h:647
const Attr & Attribute(const Idx &rElem) const
Definition: cfl_indexset.h:528
Generator with controllability attributes.
Allows to create colored marking generators (CMGs) as the common five tupel consisting of alphabet,...
Definition: mtc_generator.h:53
SymbolTable * ColorSymbolTablep(void) const
Get Pointer to ColorSymbolTable currently used by this MtcSystem.
void NewColorSymbolTable()
Insert a new local color symbol table.
~TmtcGenerator(void)
Destructor for MtcSystem.
SymbolTable * GlobalColorSymbolTablep(void) const
Get Pointer to global ColorSymbolTable.
virtual TmtcGenerator & Assign(const Type &rSrc)
Assignment.
void DoAssign(const TmtcGenerator &rSrc)
Assignment.
SymbolTable * mpColorSymbolTable
Pointer to currently used symbol table.
void ColorSymbolTable(SymbolTable *pSymTab)
Set ColorSymbolTable to be used by this MtcSystem.
A TokenWriter writes sequential tokens to a file, a string or stdout.
void WriteComment(const std::string &rComment)
Write comment in faudes format.
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
void Write(const Type *pContext=0) const
Write configuration data to console.
Definition: cfl_types.cpp:139
Base class of all FAUDES generators.
void ClearMarkedStates(void)
Clear all marked states.
void InjectMarkedStates(const StateSet &rNewMarkedStates)
Replace mMarkedStates with StateSet given as parameter without consistency checks.
StateSet CoaccessibleSet(void) const
Compute set of Coaccessible states.
Includes all libFAUDES headers, no plugins.
IndexSet StateSet
Definition: cfl_indexset.h:271
Iterator End(void) const
Iterator to the end of set.
Definition: cfl_baseset.h:1896
Iterator Begin(void) const
Iterator to the begin of set.
Definition: cfl_baseset.h:1891
virtual const AttributeVoid & Attribute(const T &rElem) const
Attribute access.
Definition: cfl_baseset.h:2290
bool IsStronglyTrim(const MtcSystem &rGen)
RTI wrapper function.
void StronglyTrim(MtcSystem &rGen)
RTI wrapper function.
bool IsAccessible(const vGenerator &rGen)
RTI wrapper function.
void StronglyCoaccessible(MtcSystem &rGen)
RTI wrapper function.
bool IsStronglyCoaccessible(const MtcSystem &rGen)
RTI wrapper function.
void Accessible(vGenerator &rGen)
RTI wrapper function.
Color attributes for states.
#define TEMP
#define BASE
#define THIS
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
TmtcGenerator< AttributeVoid, AttributeColoredState, AttributeCFlags, AttributeVoid > mtcGenerator
Compatibility: pre 2.20b used mtcGenerator as C++ class name.
TmtcGenerator< AttributeVoid, AttributeColoredState, AttributeCFlags, AttributeVoid > MtcSystem
std::string ToStringInteger(Int number)
integer to string
Definition: cfl_helper.cpp:43

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen