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

libFAUDES 2.24g --- 2014.09.15 --- c++ api documentaion by doxygen