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

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen