cfl_generator.h
Go to the documentation of this file.
1/** @file cfl_generator.h Class vGenerator */
2
3/* FAU Discrete Event Systems Library (libfaudes)
4
5Copyright (C) 2006 Bernd Opitz
6Copyright (C) 2007-2024 Thomas Moor
7Exclusive copyright is granted to Klaus Schmidt
8
9This library is free software; you can redistribute it and/or
10modify it under the terms of the GNU Lesser General Public
11License as published by the Free Software Foundation; either
12version 2.1 of the License, or (at your option) any later version.
13
14This library is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
17Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public
20License along with this library; if not, write to the Free Software
21Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23
24#ifndef FAUDES_VGENERATOR_H
25#define FAUDES_VGENERATOR_H
26
27#include "cfl_definitions.h"
28#include "cfl_exception.h"
29#include "cfl_types.h"
30#include "cfl_symboltable.h"
31#include "cfl_indexset.h"
32#include "cfl_nameset.h"
33#include "cfl_transset.h"
34#include "cfl_token.h"
35#include "cfl_tokenreader.h"
36#include "cfl_tokenwriter.h"
37
38#include <map>
39#include <set>
40#include <sstream>
41#include <cstdlib>
42#include <cassert>
43
44namespace faudes {
45
46/**
47 * Base class of all FAUDES generators.
48 *
49 * @subsection GeneratorMembers Overview
50 *
51 * The faudes::vGenerator models the plain five-tupel G = (X, Sigma, Delta, X_0, X_m) to represent
52 * the marked language L(G) and closed language L_m(G), respectively. It provides read and write
53 * access to core menbers, e.g. methods for inserting/deleting events, states
54 * and transitions.
55 *
56 *
57 * States, events and transitions in a generator can be addressed in three alternative methods:
58 *
59 * - by index, involves a search on a sorted set (efficient)
60 * - by name, involves two searches on sorted sets (not quite so efficient)
61 * - by iterator, involves pointer dereferencing (very efficient)
62 *
63 * For read access, const refererences to sets are provided. In order to allow for consistency checks,
64 * write access is via generator methods only. When the compiletime option FAUDES_CHECKED is
65 * defined, write methods throw an exception on inconsistent data, eg. setting an initial state
66 * that is not an element of the state set, or introducing a transition with an event label that
67 * is not in the alphabet.
68 *
69 *
70 * @subsection SecEventsVersusStates Events Versus States
71 *
72 * While both, events and states, are represented by the integer type faudes::Idx, there
73 * is a fundamental distinction between both, which stems from the design choice to use generators
74 * as a tool to represent formal languages. From this perspective, events are global enteties while states
75 * are local to the respective generator. Any two events within libFAUDES are related while states only
76 * compare within a generator.
77 *
78 * In consequence, there is global sybmoltable for event name resolution,
79 * while there is one local state symboltable for
80 * each generator. Furthermore, state names are considered cosmetic and hence are optional, while
81 * event names are mandatory.
82 *
83 * Example: two machines both refer to the event name "alpha" that models the process of passing
84 * a workpiece from one machine to the other. In libFAUDES this is indeed modelled as one event
85 * which is represented by one index. However, both machines may have a state "Idle" which indicates
86 * that the respective machine is idle. In libFAUDES the two states are treated locally to the
87 * generators and whether or not they have the same index is regarded irrelevant.
88 *
89 * The generator class carries a flag to indicate that functions with result type
90 * generator shall attach names to the newly created states, based on the state names
91 * of the respective arguments. Turning of this feature and avoiding state names alltogether
92 * considerably increases libFAUDES performance.
93 *
94 * @subsection GeneratorFileFormat File I/O (default format)
95 *
96 * Generators inherit the standard token IO interface from the libFAUDES general purpose base Type,
97 * so you may use Read and Write functions for generators. The file-format consists of a generator
98 * section that includes one subsection for each core member. It is illustrated by the below example
99 *
100 * @code
101 * <Generator name="simple machine">
102 * % libFAUDES Generator for the simple machine
103 *
104 * <Alphabet>
105 * alpha beta mue lambda
106 * </Alphabet>
107 *
108 * <States>
109 * idle busy down
110 * </States>
111 *
112 * <TransRel>
113 * idle alpha busy
114 * busy beta idle
115 * busy mue down
116 * down lambda idle
117 * </TransRel>
118 *
119 * <InitStates>
120 * idle
121 * </InitStates>
122 *
123 * <MarkedStates>
124 * idle
125 * </MarkedStates>
126 * </Generator>
127 * @endcode
128 *
129 * Technical Detail: Since symbolic state names are optional, states may alternatively be represented
130 * by their index. In order to consitently read a generator from a token stream, the convention
131 * was that states are indexed consecutively starting from 1. This convention produces nice and human-readable output.
132 * However, it requires a re-indexing when writing the generator. As of libFAUDES 2.20j, the token format was extended to
133 * allow for explicit symbol table entries in the format "symbolic_state_name#index". Whether or not re-indexing
134 * is applied can be configured via ReindexOnWrite(bool). The default is not to re-index. If you want to read your token
135 * stream with libFAUDES pre 2.20j, you must turn re-index on.
136 *
137 *
138 * Technical Detail: The generator name, the alphabet and the state set are optional. The generator
139 * name defaults to "generator"; the alphabet and the state set are extracted from the transition relation.
140 * Furthermore, there alternative short labels "A" for "Alphabet", "S" for "States" etc. are accepted.
141 * This short format has been introduced in 2.24e and is meant for embedding data concisely into luafaudes scripts.
142 * In general, the full format is preferable.
143 *
144 * @code
145 * <Generator>
146 * <T>
147 * idle alpha busy
148 * busy beta idle
149 * busy mue down
150 * down lambda idle
151 * </T>
152 * <I> idle </I>
153 * <M> idle </M>
154 * </Generator>
155 * @endcode
156 *
157 * @subsection GeneratorFileFormatXML File I/O (XML file-format)
158 *
159 * The alternative file file format prodiced by XWrite() is meant to accomodate
160 * for additional attributes attached to states, events and transitions, including e.g.
161 * graph data for a graphical representation. It starts with the outer element "Generator" with
162 * name attribute (optionally) and type attribute (mandatory).
163 *
164 *
165 * @code
166 * <Generator name="simpla machine" ftype="Generator">
167 * <Alphabet>
168 * <Event name="alpha"/>
169 * <Event name="beta"/>
170 * <Event name="mue"/>
171 * <Event name="lambda"/>
172 * </Alphabet>
173 *
174 * <StateSet>
175 * <State name="idle" id="1">
176 <Marked/><Initial/>
177 <State/>
178 * <State name="busy" id="2"/>
179 * <State name="down" id="3"/>
180 * </StateSet>
181 *
182 * <TransitionRelation>
183 * <Transition x1="1" event="alphs" x2="2"/>
184 * <Transition x1="2" event="beta" x2="2"/>
185 * <Transition x1="2" event="mue" x2="3"/>
186 * <Transition x1="3" event="lambda" x2="1"/>
187 * <TransitionRelation/>
188 *
189 * </Generator>
190 * @endcode
191 *
192 *
193 * @subsection GeneratorAttributes Attributes
194 *
195 * libFAUDES generators provide an interface to access so called attributes, ie data that
196 * is optionally attached to individual states, events, transitions, or globally to the generator.
197 *
198 * The faudes::Generator's interface to attributes is abstract in the sense that a generator
199 * is not aware of the actual type of its attributes.
200 * Instances of the class Generator indeed have trivial attributes that hold no data at all.
201 * To use attributes, you are meant to instantiate objects of the derived class TaGenerator
202 * with template parameters to specify attribute types. Basic algorithms
203 * implemented for plain generators will accept attributed generators as arguments. Such algorithms may
204 * occasionally inspect or set attributes using the abstract interface and C++ dynamic casts. For
205 * specialised algorithms that refer to extended generator semantics, we recommend derived
206 * generator classes as argument type.
207 *
208 *
209 * @ingroup GeneratorClasses
210 */
211
212
214
215 public:
216
217 /** @name Constructors & Destructor */
218 /** @{ doxygen group */
219
220 /**
221 * Default constructor
222 */
223 vGenerator(void);
224
225 /**
226 * Copy-constructror
227 */
228 vGenerator(const vGenerator& rOtherGen);
229
230 /**
231 * Construct from file. This constructor
232 * effectively uses the DoRead(TokenReader&) function to read.
233 *
234 * @param rFileName
235 * Name of file
236 *
237 * @exception Exception
238 * - IO errors (id 1)
239 * - Token mismatch (id 50, 51, 52, 80, 85)
240 */
241 vGenerator(const std::string& rFileName);
242
243 /**
244 * Construct on heap.
245 * Technically not a constructor, this function creates a vGenerator with the
246 * same event symboltable. It is the callers responsebilty to delete the object
247 * when no longer needed. Derived classes must reimplement
248 * this function to create an object of the same class and the same event
249 * symboltable.
250 *
251 * @return
252 * New vGenerator
253 */
254 virtual vGenerator* New(void) const;
255
256 /**
257 * Construct copy on heap.
258 * Technically not a constructor, this function creates a vGenerator with the
259 * same event symboltable. It is the callers responsebilty to delete the object
260 * when no longer needed. Derived classes must reimplement
261 * this function to create an object of the same class and the same event
262 * symboltable.
263 *
264 * @return
265 * New vGenerator
266 */
267 virtual vGenerator* Copy(void) const;
268
269 /**
270 * Type test.
271 * Uses C++ dynamic cast to test whether the specified object
272 * casts to a vGenerator.
273 *
274 * @return
275 * vGenerator reference if dynamic cast succeeds, else NULL
276 */
277 virtual const Type* Cast(const Type* pOther) const;
278
279 /**
280 * Destructor
281 */
282 virtual ~vGenerator(void);
283
284 /** @} doxygen group */
285
286 /*****************************************
287 *****************************************
288 *****************************************
289 *****************************************/
290
291 /** @name Copy and Assignment */
292 /** @{ doxygen group */
293
294
295 /**
296 * Copy from other faudes type.
297 * The current implementation tests whether the source
298 * object can be casted to a generator and then performs
299 * the according assignment.
300 *
301 * @param rSrc
302 * Source to copy from.
303 */
304 virtual vGenerator& Assign(const Type& rSrc);
305
306 /**
307 * Copy from other vGenerator, ignore attributes.
308 *
309 * @param rGen
310 * Source to copy from.
311 */
312 virtual vGenerator& AssignWithoutAttributes(const vGenerator& rGen);
313
314 /**
315 * Destructive copy to other vGenerator.
316 * Copy method with increased performance at the cost of invalidating
317 * the source data. If attribute types of source and destination differ,
318 * a std copy is invoked.
319 *
320 *
321 * @param rGen
322 * Destination for copy operation.
323 */
324 virtual void Move(vGenerator& rGen);
325
326 /**
327 * Assignment operator (uses Assign method)
328 *
329 * Note: you must reimplement this operator in derived
330 * classes in order to handle internal pointers correctly.
331 *
332 * @param rOtherGen
333 * Other generator
334 */
335 /*virtual*/ vGenerator& operator= (const vGenerator& rOtherGen);
336 //using Type::operator=;
337
338
339 /**
340 * Create another version of this generator.
341 * Assembles a copy of this generator, however, with versioned events.
342 * The new event names are created by appending an underscore and a specified string.
343 * State names and indices as well as any attributes are maintained.
344 *
345 * @param rVersion
346 * String value to be appended to event names
347 * @param rResGen
348 * Resulting versioned generator
349 *
350 * @exception Exception
351 * - Source must not match destination (id 96)
352 */
353 virtual void Version(const std::string& rVersion, vGenerator& rResGen) const;
354
355 /**
356 * Create another version of this generator.
357 * Assembles a copy of this generator, however, with versioned events.
358 * The new event names are created by appending an underscore and a numeric index.
359 * State names and indices as well as any attributes are maintained.
360 *
361 * @param version
362 * Numeric value to be appended to event names
363 * @param rResGen
364 * Resulting versioned generator
365 * @exception Exception
366 * - Source must not match destination (id 96)
367 */
368 virtual void Version(Idx version, vGenerator& rResGen) const;
369
370 /**
371 * Create another version of this generator.
372 * Assembles a copy of this generator, however, with versioned events.
373 * The new event names are created by replacing all substrings matching
374 * a specified string pattern by a replacement string.
375 * State names and indices as well as any attributes are maintained.
376 *
377 * @param rPattern
378 * String value to be replaced in event names
379 * @param rReplacement
380 * String value to be inserted in event names in place of rPattern
381 * @param rResGen
382 * Resulting versioned generator
383 * @exception Exception
384 * - Source must not match destination (id 96)
385 */
386 virtual void Version(const std::string& rPattern,const std::string& rReplacement, vGenerator& rResGen) const;
387
388
389
390 /** @} doxygen group */
391
392
393 /*****************************************
394 *****************************************
395 *****************************************
396 *****************************************/
397
398 /** @name Basic Maintenance */
399 /** @{ doxygen group */
400
401
402 /**
403 * Check if generator is valid.
404 * Performs internal consistency tests, This method is intendend
405 * to test generators that have been manipulated by methods without
406 * consistency tests, eg InjectAlphabet.
407 *
408 * @return
409 * True for success
410 */
411 virtual bool Valid(void) const;
412
413 /**
414 * Clear generator data.
415 * Clears state set, alphabet and transitionrealtion. Behavioural flags
416 * eg StateNamesEnabled are maintained.
417 */
418 virtual void Clear(void);
419
420
421 /**
422 * Clear all states and transitions, maintain alphabet.
423 */
424 void ClearStates(void);
425
426 /**
427 * Get number of events in alphabet
428 *
429 * @return
430 * Number of events
431 */
432 Idx AlphabetSize(void) const;
433
434 /**
435 * Get generator size (number of states)
436 *
437 * @return
438 * Number of states
439 */
440 Idx Size(void) const;
441
442 /**
443 * Get number of transitions
444 *
445 * @return
446 * Number of transitions
447 */
448 Idx TransRelSize(void) const;
449
450 /**
451 * Get number of initial states
452 *
453 * @return
454 * Number of initial states
455 */
456 Idx InitStatesSize(void) const;
457
458 /**
459 * Get number of marked states
460 *
461 * @return
462 * Number of marked states
463 */
464 Idx MarkedStatesSize(void) const;
465
466 /**
467 * Check if generator is empty (no states)
468 *
469 * @return
470 * True if state set is empty
471 */
472 bool Empty(void) const;
473
474 /**
475 * Check if alphabet is Empty
476 *
477 * @return
478 * True if mpAlphabet is empty
479 */
480 bool AlphabetEmpty(void) const;
481
482 /**
483 * Check if transition relation is empty
484 *
485 * @return
486 * True if transition relation is empty
487 */
488 bool TransRelEmpty(void) const;
489
490 /**
491 * Check if set of initial states are empty
492 *
493 * @return
494 * True if mInitStates is empty
495 */
496 bool InitStatesEmpty(void) const;
497
498 /**
499 * Check if set of marked states are empty
500 *
501 * @return
502 * True if mMarkedStates is empty
503 */
504 bool MarkedStatesEmpty(void) const;
505
506
507 /** @} doxygen group */
508
509 /*****************************************
510 *****************************************
511 *****************************************
512 *****************************************/
513
514 /** @name Event Symboltable */
515 /** @{ doxygen group */
516
517 /**
518 * Get Pointer to EventSymbolTable currently used
519 * by this vGenerator.
520 *
521 * @return
522 * Pointer to EventSymbolTable
523 */
524 SymbolTable* EventSymbolTablep(void) const;
525
526 /**
527 * Set EventSymbolTable to be used by this vGenerator.
528 * This function sets the reference to the event symboltable. The current implementation
529 * in derived classes clears the generator, future versions may implement a re-indexing.
530 *
531 * @param pSymTab
532 * Pointer to SymbolTable
533 */
534 virtual void EventSymbolTablep(SymbolTable* pSymTab);
535
536 /**
537 * Set EventSymbolTable as given by rOtherGen.
538 * This function sets the reference to the event symboltable. The current implementation
539 * clears the generator, future versions may implement a re-indexing.
540 *
541 * @param rOtherGen
542 * Other generator
543 *
544 */
545 virtual void EventSymbolTablep(const vGenerator& rOtherGen);
546
547 /**
548 * Create EventSet with generator's EventSymbolTable (on stack).
549 *
550 * @return
551 * New empty EventSet on stack
552 */
553 EventSet NewEventSet(void) const;
554
555 /**
556 * Create EventSet with generator's EventSymbolTable (on heap).
557 *
558 * @return
559 * Pointer to new empty EventSet on heap
560 */
561 EventSet* NewEventSetp(void) const;
562
563 /**
564 * Event index lookup
565 *
566 * @param rName
567 * Name of event to lookup
568 *
569 * @return
570 * Valid index or 0 if name unknown to symboltable
571 */
572 Idx EventIndex(const std::string& rName) const;
573
574 /**
575 * Event name lookup
576 *
577 * @param index
578 * Index of event to look up
579 *
580 * @return
581 * Name or empty std::string if non-existent
582 */
583 std::string EventName(Idx index) const;
584
585 /**
586 * Set name for existing event
587 *
588 * Note: since the event symboltable is global, this affect all
589 * generators that refer to the specified event.
590 *
591 * @param index
592 * Event index
593 * @param rName
594 * New name
595 *
596 * @exception Exception
597 * - index not found in EventSymbolMap (id 42)
598 * - name already associated with another index (id 44)
599 * - event does not exist in generator (id 89)
600 */
601 void EventName(Idx index, const std::string& rName);
602
603 /**
604 * Create a new unique symbolic event name.
605 * See also SymbolTable::UniqueSymbol().
606 *
607 * @param rName
608 * suggestion for new state name
609 */
610 std::string UniqueEventName(const std::string& rName) const;
611
612
613 /**
614 * Rename event in this generator.
615 * This method renames the specified event. It does so by
616 * removing and adding transitions. This does not
617 * effect other generators.
618 *
619 * @param event
620 * Event to rename
621 * @param rNewName
622 * New name
623 * @return
624 * True, if the new name did already exist
625 *
626 * @exception Exception
627 * - specified event does not exist (id 89)
628 */
629 bool EventRename(Idx event, const std::string& rNewName);
630
631
632 /**
633 * Rename event in this generator.
634 * Convenience wrapper for EventRename(Idx, const std::string&).
635 *
636 * @param rOldName
637 * Event to rename
638 * @param rNewName
639 * New name
640 * @return
641 * True, if the new name did already exist
642 *
643 * @exception Exception
644 * - specified event does not exist (id 89)
645 */
646 bool EventRename(const std::string& rOldName, const std::string& rNewName);
647
648
649 /** @} doxygen group */
650
651 /* statics outside doxygen group */
652
653 /**
654 * Get Pointer to global EventSymbolTable. This is
655 * a static member of SymbolTable and used as default
656 * for all derived generator classes and instantiated objects.
657 *
658 * @return
659 * Pointer to global EventSymbolTable
660 */
661 static SymbolTable* GlobalEventSymbolTablep(void);
662
663
664 /*****************************************
665 *****************************************
666 *****************************************
667 *****************************************/
668
669 /** @name State Symboltable */
670 /** @{ doxygen group */
671
672
673 /**
674 * Get StateSymbolTable.
675 *
676 * @return
677 * ref to state-symboltable
678 */
679 const SymbolTable& StateSymbolTable(void) const;
680
681 /**
682 * Set StateSymbolTable.
683 *
684 * By convention, state names and indices are local to the
685 * respective generator. It is most unlikely that you want to use
686 * this function.
687 *
688 */
689 void StateSymbolTable(const SymbolTable& rSymTab);
690
691 /**
692 * State index lookup.
693 *
694 * @param rName
695 *
696 * @return
697 * Valid index (or 0 for non-existent)
698 */
699 Idx StateIndex(const std::string& rName) const;
700
701 /**
702 * State name lookup
703 *
704 * @param index
705 *
706 * @return name (or empty string if no such exists)
707 */
708 std::string StateName(Idx index) const;
709
710 /**
711 * Set name of state
712 *
713 * @param index
714 * Index
715 * @param rName
716 * Name
717 *
718 * @exception Exception
719 * - name already associated with another index (id 44)
720 * - state does not exist in generator (id 90)
721 */
722 void StateName(Idx index, const std::string& rName);
723
724 /**
725 * Remove all names from generator's StateSymbolTable
726 */
727 void ClearStateNames(void);
728
729 /**
730 * Clear name for individual state
731 *
732 * @param index
733 * State index
734 * @exception Exception
735 * - state does not exist in generator (id 90)
736 */
737 void ClrStateName(Idx index);
738
739 /**
740 * Clear name for individual state
741 *
742 * @param rName
743 * State name
744 */
745 void ClrStateName(const std::string& rName);
746
747 /**
748 * Whether libFAUEDS functions are requested to generate state names.
749 * Most libFAUDES functions that introduce new states to a generator can be enabled
750 * to also assign (more or less sensible) names to those states. This feature is
751 * purely cosmetic and may be disabled for performance reasons.
752 *
753 *
754 * @return
755 * True, if generation of statenames is enabled.
756 */
757 bool StateNamesEnabled(void) const;
758
759 /**
760 * Enable/disable libFAUEDS functions to automatically generate state names.
761 * Disabling state name generation implies ClearStateNames().
762 *
763 * @param flag
764 * True enables statenames / false disables them
765 */
766 void StateNamesEnabled(bool flag);
767
768 /**
769 * Assign each state a default name based on its index.
770 */
771 void SetDefaultStateNames(void);
772
773 /**
774 * For all states without a symbolic name, assign a name
775 * based on suggested template and the index.
776 *
777 * @param rTemplate
778 * Basis for name generation
779 */
780 void EnforceStateNames(const std::string& rTemplate);
781
782 /**
783 * Create a new unique symbolic state name.
784 * See also SymbolTable::UniqueSymbol().
785 *
786 * @param rName
787 * suggestion for new state name
788 */
789 std::string UniqueStateName(const std::string& rName) const;
790
791
792 /** @} doxygen group */
793
794 /* statics outside doxygen group */
795
796 /**
797 * Sets the default for automatic state name generation.
798 * This flag takes effect only on generators newly created by the default
799 * constructor. The copy constructor copies the state name flag from the
800 * source generator. See also StateNamesEnabled(bool).
801 *
802 * @param flag
803 * True enables statenames / false disables them
804 */
805 static void StateNamesEnabledDefault(bool flag);
806
807
808 /*****************************************
809 *****************************************
810 *****************************************
811 *****************************************
812 *****************************************/
813
814 /** @name Read Access to Core Members */
815 /** @{ doxygen group */
816
817 /**
818 * Iterator to Begin() of alphabet
819 *
820 * @return
821 * Iterator to begin of mpAlphabet
822 */
823 EventSet::Iterator AlphabetBegin(void) const;
824
825 /**
826 * Iterator to End() of alphabet
827 *
828 * @return
829 * Iterator to end of mpAlphabet
830 */
831 EventSet::Iterator AlphabetEnd(void) const;
832
833 /**
834 * Test existence of event in alphabet
835 *
836 * @param index
837 * Event index
838 *
839 * @return
840 * True / false
841 */
842 bool ExistsEvent(Idx index) const;
843
844 /**
845 * Test existence of event in alphabet
846 *
847 * @param rName
848 * Event name
849 *
850 * @return
851 * True / false
852 */
853 bool ExistsEvent(const std::string& rName) const;
854
855 /**
856 * Returns a iterator to event index in alphabet
857 *
858 * @param index
859 * Index to find
860 *
861 * @return
862 * Iterator to event index
863 */
864 EventSet::Iterator FindEvent(Idx index) const;
865
866 /**
867 * Returns a iterator to event index in alphabet
868 *
869 * @param rName
870 * Event name of index to find
871 *
872 * @return
873 * Iterator to event index
874 */
875 EventSet::Iterator FindEvent(const std::string& rName) const;
876
877 /**
878 * Return const reference to alphabet
879 *
880 * @return EventSet
881 * Reference to mpAlphabet
882 */
883 const EventSet& Alphabet(void) const;
884
885 /**
886 * Iterator to Begin() of state set
887 *
888 * @return
889 * Iterator to begin of state set
890 */
891 StateSet::Iterator StatesBegin(void) const;
892
893 /**
894 * Iterator to End() of state set
895 *
896 * @return
897 * Iterator to end of state set
898 */
899 StateSet::Iterator StatesEnd(void) const;
900
901 /**
902 * Test existence of state in state set
903 *
904 * @param index
905 * State index
906 *
907 * @return
908 * true / false
909 */
910 bool ExistsState(Idx index) const;
911
912 /**
913 * Test existence of state in state set
914 *
915 * @param name
916 * State name
917 *
918 * @return
919 * true / false
920 */
921 bool ExistsState(const std::string& name) const;
922
923 /**
924 * Returns a iterator to state index in state set
925 *
926 * @param index
927 * Index to find
928 *
929 * @return
930 * StateSet::Iterator to state index
931 */
932 StateSet::Iterator FindState(Idx index) const;
933
934 /**
935 * Returns a iterator to state with specified name
936 *
937 * @param rName
938 * name of state to find
939 *
940 * @return
941 * StateSet::Iterator to state
942 */
943 StateSet::Iterator FindState(const std::string& rName) const;
944
945
946 /**
947 * Return reference to state set
948 *
949 * @return
950 * StateSet reference incl actual attribute type
951 */
952 const StateSet& States(void) const;
953
954 /**
955 * Return initial state
956 *
957 * If the initial state is not unique, this function
958 * returns 0.
959 *
960 * @return
961 * Index of initial state
962 *
963 */
964 Idx InitState(void) const;
965
966 /**
967 * Iterator to Begin() of mInitStates
968 *
969 * @return
970 * Iterator to begin of mInitStates
971 */
972 StateSet::Iterator InitStatesBegin(void) const;
973
974 /**
975 * Iterator to End() of mInitStates
976 *
977 * @returns
978 * Iterator to end of mInitStates
979 */
980 StateSet::Iterator InitStatesEnd(void) const;
981
982 /**
983 * Test existence of state in mInitStates
984 *
985 * @param index
986 * State index
987 *
988 * @return
989 * true / false
990 */
991 bool ExistsInitState(Idx index) const;
992
993 /**
994 * Iterator to state index in mInitStates
995 *
996 * @param index
997 * Index to find
998 *
999 * @return
1000 * StateSet::Iterator to state index
1001 */
1002 StateSet::Iterator FindInitState(Idx index) const;
1003
1004 /**
1005 * Const ref to initial states
1006 *
1007 * @return StateSet
1008 */
1009 const StateSet& InitStates(void) const;
1010
1011 /**
1012 * Iterator to Begin() of mMarkedStates
1013 *
1014 * @returns
1015 * iterator to Begin of mMarkedStates
1016 */
1017 StateSet::Iterator MarkedStatesBegin(void) const;
1018
1019 /**
1020 * Iterator to End() of mMarkedStates
1021 *
1022 * @returns
1023 * iterator to End of mMarkedStates
1024 */
1025 StateSet::Iterator MarkedStatesEnd(void) const;
1026
1027 /**
1028 * Test existence of state in mMarkedStates
1029 *
1030 * @param index
1031 * State index
1032 *
1033 * @return
1034 * true / false
1035 */
1036 bool ExistsMarkedState(Idx index) const;
1037
1038 /**
1039 * Returns a iterator to state index in mMarkedStates
1040 *
1041 * @param index
1042 * Index to find
1043 *
1044 * @return
1045 * StateSet::Iterator to state index
1046 */
1047 StateSet::Iterator FindMarkedState(Idx index) const;
1048
1049 /**
1050 * Return const ref of marked states
1051 *
1052 * @return StateSet
1053 */
1054 const StateSet& MarkedStates(void) const;
1055
1056 /**
1057 * Iterator to Begin() of transition relation
1058 *
1059 * @return
1060 * Iterator to Begin of mpTransRel
1061 */
1062 TransSet::Iterator TransRelBegin(void) const;
1063
1064 /**
1065 * Iterator to End() of transition relation
1066 *
1067 * @return
1068 * Iterator to End of mpTransRel
1069 */
1070 TransSet::Iterator TransRelEnd(void) const;
1071
1072 /**
1073 * Iterator to begin of transitions with x1 as predecessor state.
1074 *
1075 * @param x1
1076 * Predecessor state
1077 *
1078 * @return
1079 * iterator to begin of transitions with x1
1080 */
1081 TransSet::Iterator TransRelBegin(Idx x1) const;
1082
1083 /**
1084 * iterator to end of transitions with x1 as predecessor state.
1085 *
1086 * Note: Set the End(x1) iterator to a variable, so it won't be
1087 * recalculated every iteration.
1088 *
1089 * @param x1
1090 * Predecessor state
1091 *
1092 * @return
1093 * iterator to end of transitions with x1
1094 * (one after last matching transition)
1095 */
1096 TransSet::Iterator TransRelEnd(Idx x1) const;
1097
1098 /**
1099 * iterator to begin of transitions with x1 as predecessor state and
1100 * event ev.
1101 *
1102 * @param x1
1103 * Predecessor state
1104 * @param ev
1105 * Event
1106 *
1107 * @return
1108 * iterator to begin of transitions with x1 and ev
1109 */
1110 TransSet::Iterator TransRelBegin(Idx x1, Idx ev) const;
1111
1112 /**
1113 * Iterator to end of transitions with x1 as predecessor state and
1114 * event ev.
1115 *
1116 * Note: Set the End(x1,ev) iterator to a variable, so it won't be
1117 * recalculated every iteration.
1118 *
1119 * @param x1
1120 * Predecessor state
1121 * @param ev
1122 * Event
1123 *
1124 * @return
1125 * iterator to end of transitions with x1 and ev
1126 * (one after last matching transition)
1127 */
1128 TransSet::Iterator TransRelEnd(Idx x1, Idx ev) const;
1129
1130 /**
1131 * iterator to transition given by x1, ev, x2
1132 *
1133 *
1134 * @param rX1
1135 * name of Predecessor state
1136 * @param rEv
1137 * name of Event
1138 * @param rX2
1139 * name of Successor state
1140 *
1141 * @return
1142 * iterator to transition or end() if not exists
1143 */
1144 TransSet::Iterator FindTransition(
1145 const std::string& rX1, const std::string& rEv, const std::string& rX2) const;
1146
1147 /**
1148 * Iterator to transition given by x1, ev, x2
1149 *
1150 *
1151 * @param x1
1152 * Predecessor state
1153 * @param ev
1154 * Event
1155 * @param x2
1156 * Successor state
1157 *
1158 * @return
1159 * iterator to transition or End() if not exists
1160 */
1161 TransSet::Iterator FindTransition(Idx x1, Idx ev, Idx x2) const;
1162
1163 /**
1164 * Iterator to transition
1165 *
1166 *
1167 * @param rTrans
1168 * transition
1169 *
1170 * @return
1171 * iterator to transition or end() if not exists
1172 */
1173 TransSet::Iterator FindTransition(const Transition& rTrans) const;
1174
1175 /**
1176 * Test for transition given by x1, ev, x2
1177 *
1178 *
1179 * @param rX1
1180 * name of Predecessor state
1181 * @param rEv
1182 * name of Event
1183 * @param rX2
1184 * name of Successor state
1185 *
1186 * @return
1187 * true / false
1188 */
1189 bool ExistsTransition(
1190 const std::string& rX1, const std::string& rEv, const std::string& rX2) const;
1191
1192 /**
1193 * Test for transition given by x1, ev, x2
1194 *
1195 * @param x1
1196 * Predecessor state
1197 * @param ev
1198 * Event
1199 * @param x2
1200 * Successor state
1201 *
1202 * @return
1203 * true / false
1204 */
1205 bool ExistsTransition(Idx x1, Idx ev, Idx x2) const;
1206
1207 /**
1208 * test for transition
1209 *
1210 *
1211 * @param rTrans
1212 * transition
1213 *
1214 * @return
1215 * true / false
1216 */
1217 bool ExistsTransition(const Transition& rTrans) const;
1218
1219 /**
1220 * Test for transition given by x1, ev
1221 *
1222 * @param x1
1223 * Predecessor state
1224 * @param ev
1225 * Event
1226 *
1227 * @return
1228 * true / false
1229 */
1230 bool ExistsTransition(Idx x1, Idx ev) const;
1231
1232 /**
1233 * Test for transition given by x1
1234 *
1235 * @param x1
1236 * Predecessor state
1237 *
1238 * @return
1239 * true / false
1240 */
1241 bool ExistsTransition(Idx x1) const;
1242
1243 /**
1244 * Return reference to transition relation
1245 *
1246 * @return TransRel
1247 */
1248 const TransSet& TransRel(void) const;
1249
1250 /**
1251 * Get copy of trantision relation sorted by other compare
1252 * operator, e.g. "x2,ev,x1"
1253 *
1254 * @param res
1255 * resulting transition relation
1256 */
1257 void TransRel(TransSetX1EvX2& res) const;
1258 void TransRel(TransSetEvX1X2& res) const;
1259 void TransRel(TransSetEvX2X1& res) const;
1260 void TransRel(TransSetX2EvX1& res) const;
1261 void TransRel(TransSetX2X1Ev& res) const;
1262 void TransRel(TransSetX1X2Ev& res) const;
1263
1264 /**
1265 * Convebience function.
1266 *
1267 * @param rX1
1268 * Name of Predecessor state
1269 * @param rEv
1270 * Name of Event
1271 * @param rX2
1272 * Name of Successor state
1273 *
1274 * @return
1275 * Transition as specified.
1276 */
1277 Transition TransitionByNames(
1278 const std::string& rX1, const std::string& rEv, const std::string& rX2) const;
1279
1280 /** @} doxygen group */
1281
1282
1283
1284 /*****************************************
1285 *****************************************
1286 *****************************************
1287 *****************************************/
1288
1289 /** @name Write Access to Core Members */
1290 /** @{ doxygen group */
1291
1292
1293 /**
1294 * Add an existing event to alphabet by index. It is an error to insert
1295 * an event index that is not known to the mpEventSymbolTable.
1296 *
1297 * @param index
1298 * Event index
1299 * @return
1300 * True, if event was new to alphabet
1301 */
1302 bool InsEvent(Idx index);
1303
1304 /**
1305 * Add named event to generator. An entry in the mpEventSymbolTable will
1306 * be made if event name is not known so far.
1307 *
1308 * @param rName
1309 * Name of the event to add
1310 *
1311 * @return
1312 * New unique index
1313 */
1314 Idx InsEvent(const std::string& rName);
1315
1316 /**
1317 * Add new named events to generator.
1318 * If the event allready exists, the attribute is maintained.
1319 *
1320 * @param events
1321 * EventSet
1322 */
1323 void InsEvents(const EventSet& events);
1324
1325 /**
1326 * Delete event from generator by index. mpEventSymbolTable stays untouched.
1327 * Transitions containing event will be removed too.
1328 *
1329 * @param index
1330 * Index of event
1331 * @return
1332 * True, if event was in alphabet
1333 *
1334 */
1335 bool DelEvent(Idx index);
1336
1337 /**
1338 * Delete event from generator by name. mpEventSymbolTable stays untouched.
1339 * Transitions containing event will be removed too.
1340 *
1341 * @param rName
1342 * Name of event
1343 * @return
1344 * True, if event was in alphabet
1345 *
1346 */
1347 bool DelEvent(const std::string& rName);
1348
1349 /**
1350 * Delete a set of events from generator. mpEventSymbolTable stays untouched.
1351 * Transitions containing events will be removed too.
1352 *
1353 * @param rEvents
1354 * EventSet containing events to remove
1355 */
1356 void DelEvents(const EventSet& rEvents);
1357
1358 /**
1359 * Delete event from alphabet without consistency check. The event is only
1360 * deleted from mpAlphabet but not from transition relation.
1361 *
1362 * @param index
1363 * Index of event
1364 * @return
1365 * True, if event was in alphabet
1366 *
1367 */
1368 bool DelEventFromAlphabet(Idx index);
1369
1370 /**
1371 * Set mpAlphabet without consistency check.
1372 * Sets the alphabet incl attributes, if provided.
1373 *
1374 * @param rNewalphabet
1375 * EventSet with new alphabet
1376 */
1377 void InjectAlphabet(const EventSet& rNewalphabet);
1378
1379 /**
1380 * Restricts mpAlphabet incl removing resp. transition.
1381 * Maintains attributes if any.
1382 *
1383 * Note: before libFAUDES 2.23, this method did not remove
1384 * transitions. Use InjectAlphabet(const EventSet&) for direct
1385 * write acces to the alphabet.
1386 *
1387 * @param rNewalphabet
1388 * EventSet with alphabet
1389 */
1390 virtual void RestrictAlphabet(const EventSet& rNewalphabet);
1391
1392 /**
1393 * Add new anonymous state to generator
1394 *
1395 * @return
1396 * Index of new unique state
1397 */
1398 Idx InsState(void);
1399
1400 /**
1401 * Add (perhaps new) state to generator
1402 *
1403 * @return
1404 * True to indicate that state was new to generator
1405 */
1406 bool InsState(Idx index);
1407
1408 /**
1409 * Add new named state to generator.
1410 *
1411 * @param rName
1412 * Name of the state to add
1413 *
1414 * @return
1415 * Index of new unique state
1416 *
1417 * @exception Exception
1418 * Name already exists (id 44)
1419 */
1420 Idx InsState(const std::string& rName);
1421
1422 /**
1423 * Add anonymous states to generator
1424 *
1425 * @param rStates
1426 * Set of states to add
1427 */
1428 void InsStates(const StateSet& rStates);
1429
1430 /**
1431 * Delete a state from generator by index.
1432 * Cleans mpStates, mInitStates, mMarkedStates, mpTransRel and mpStateSymbolTable.
1433 *
1434 * @param index
1435 * Index of state to delete.
1436 * @return
1437 * True, if state was in stateset
1438 */
1439 bool DelState(Idx index);
1440
1441 /**
1442 * Delete a state from generator by name.
1443 * Cleans mpStates, mInitStates, mMarkedStates, mpTransRel and mpStateSymbolTable.
1444 *
1445 * @param rName
1446 * Name of state to delete. Will be erased in mpStateSymbolTable too
1447 * @return
1448 * True, if state was in stateset
1449 *
1450 * @exception Exception
1451 * - Symbolic name not known (id 90)
1452 */
1453 bool DelState(const std::string& rName);
1454
1455 /**
1456 * Delete a set of states
1457 * Cleans mpStates, mInitStates, mMarkedStates, mpTransrel, and mpStateSymboltable
1458 *
1459 * @param rDelStates
1460 * StateSet containing states aka indicees to delete
1461 */
1462 void DelStates(const StateSet& rDelStates);
1463
1464
1465 /**
1466 * Delete a state from generator without consistency check. This removes the
1467 * state from mpStates and mpStateSymbolTable but doesn't touch mpTransRel,
1468 * mInitStates and mMarkedStates.
1469 *
1470 * @param index
1471 * Index of state to delete.
1472 * @return
1473 * True, if state was in stateset
1474 *
1475 */
1476 bool DelStateFromStates(Idx index);
1477
1478 /**
1479 * Delete a state from generator without consistency check. This removes the
1480 * state from mpStates and mpStateSymbolTable but doesn't touch mpTransRel,
1481 * mInitStates and mMarkedStates.
1482 * Index to delete is given by iterator.
1483 *
1484 * @param pos
1485 * StateSet::Iterator
1486 * @return
1487 * Iteraror to next state
1488 */
1489 StateSet::Iterator DelStateFromStates(StateSet::Iterator pos);
1490
1491 /**
1492 * Restrict states
1493 * Cleans mpStates, mInitStates, mMarkedStates, mpTransrel, and mpStateSymboltable
1494 *
1495 * @param rStates
1496 * StateSet containing valid states
1497 */
1498 virtual void RestrictStates(const StateSet& rStates);
1499
1500
1501 /**
1502 * Inject an existing state index into generators mStates
1503 * Use with care! For use in performance optimized functions.
1504 *
1505 * @param index
1506 * State index to inject
1507 */
1508 void InjectState(Idx index);
1509
1510 /**
1511 * Inject a complete state set without consistency checks (without attributes)
1512 *
1513 * @param rNewStates
1514 * StateSet
1515 */
1516 void InjectStates(const StateSet& rNewStates);
1517
1518
1519 /**
1520 * Create new anonymous state and set as initial state
1521 *
1522 * @return
1523 * Index of new unique
1524 */
1525 Idx InsInitState(void);
1526
1527 /**
1528 * Add (perhaps new) state to generator and turn it
1529 * into a initial state.
1530 *
1531 * @param index
1532 * State to insert
1533 * @return
1534 * True to indicate that state was new to generator
1535 */
1536 bool InsInitState(Idx index);
1537
1538 /**
1539 * Create a new named state and set as initial state
1540 *
1541 * @param rName
1542 * Name of the state to add
1543 *
1544 * @return
1545 * Index of new unique state
1546 */
1547 Idx InsInitState(const std::string& rName);
1548
1549 /**
1550 * Add (perhaps new) anonymous initial states to generator
1551 *
1552 * @param rStates
1553 * Set of states to add
1554 */
1555 void InsInitStates(const StateSet& rStates);
1556
1557 /**
1558 * Create new anonymous state and set as marked state
1559 *
1560 * @return
1561 * Index of new unique state
1562 */
1563 Idx InsMarkedState(void);
1564
1565 /**
1566 * Add (perhaps new) state to generator and turn it
1567 * into a marked state.
1568 *
1569 * @param index
1570 * State to insert
1571 * @return
1572 * True to indicate that state was new to generator
1573 */
1574 bool InsMarkedState(Idx index);
1575
1576 /**
1577 * Create a new named state and set as marked state
1578 *
1579 * @param rName
1580 * Name of the state to add
1581 *
1582 * @return
1583 * Index of new unique state
1584 */
1585 Idx InsMarkedState(const std::string& rName);
1586
1587 /**
1588 * Add (perhaps new/anonymous) marked states to generator
1589 *
1590 * @param rStates
1591 * Set of states to add
1592 */
1593 void InsMarkedStates(const StateSet& rStates);
1594
1595 /**
1596 * Set an existing state as initial state by index.
1597 *
1598 * @param index
1599 * Index of state to set as initial state
1600 * @exception Exception
1601 * - State index not found in generator (id 91)
1602 */
1603 void SetInitState(Idx index);
1604
1605 /**
1606 * Set an existing state as initial state by name.
1607 *
1608 * @param rName
1609 * Name of state to set as initial state
1610 *
1611 * @exception Exception
1612 * - State name not known in generator (id 90)
1613 */
1614 void SetInitState(const std::string& rName);
1615
1616 /**
1617 * Replace mInitStates with StateSet given as parameter without consistency checks.
1618 *
1619 * @param rNewInitStates
1620 * StateSet containing new mInitStates
1621 */
1622 void InjectInitStates(const StateSet& rNewInitStates);
1623
1624 /**
1625 * Unset an existing state as initial state by index
1626 *
1627 * Define FAUDES_CHECKED for consistency checks.
1628 *
1629 * @param index
1630 * State index
1631 *
1632 * @exception Exception
1633 * - State index not found in generator (id 91)
1634 */
1635 void ClrInitState(Idx index);
1636
1637 /**
1638 * Unset an existing state as initial state by name
1639 *
1640 * @param rName
1641 * State name
1642 *
1643 * @exception Exception
1644 * - State name not known in generator (id 90)
1645 */
1646 void ClrInitState(const std::string& rName);
1647
1648 /**
1649 * Unset an existing state as initial state by iterator
1650 *
1651 * @param pos
1652 * StateSet::iterator
1653 * @return
1654 * Iterator to next init state
1655 */
1656 StateSet::Iterator ClrInitState(StateSet::Iterator pos);
1657
1658 /**
1659 * Clear all mInitStates
1660 */
1661 void ClearInitStates(void);
1662
1663 /**
1664 * Set an existing state as marked state by index
1665 *
1666 * @param index
1667 * Index of state to set as initial state
1668 * @exception Exception
1669 * - State index not found in generator (id 91)
1670 */
1671 void SetMarkedState(Idx index);
1672
1673 /**
1674 * Set an existing state as marked state by name.
1675 *
1676 * @param rName
1677 * Name of state to set as marked state
1678 *
1679 * @exception Exception
1680 * - State name not known in generator (id 90)
1681 */
1682 void SetMarkedState(const std::string& rName);
1683
1684 /**
1685 * Unset an existing state as marked state by index
1686 *
1687 * @param index
1688 * State index
1689 *
1690 * @exception Exception
1691 * - State index not found in generator (id 91)
1692 */
1693 void ClrMarkedState(Idx index);
1694
1695 /**
1696 * Unset an existing state as marked state by name
1697 *
1698 * @param rName
1699 * State name
1700 *
1701 * @exception Exception
1702 * - State index not found in generator (id 91)
1703 */
1704 void ClrMarkedState(const std::string& rName);
1705
1706 /**
1707 * Unset an existing state as marked state by iterator
1708 *
1709 * @param pos
1710 * StateSet::iterator
1711 * @return
1712 * Iterator to next marked state
1713 */
1714 StateSet::Iterator ClrMarkedState(StateSet::Iterator pos);
1715
1716 /**
1717 * Clear all marked states
1718 */
1719 void ClearMarkedStates(void);
1720
1721 /**
1722 * Replace mMarkedStates with StateSet given as parameter without consistency checks.
1723 *
1724 * @param rNewMarkedStates
1725 * StateSet containing new marked states
1726 */
1727 void InjectMarkedStates(const StateSet& rNewMarkedStates);
1728
1729 /**
1730 * Add a transition to generator by indices. States and event
1731 * must already exist.
1732 *
1733 * @param x1
1734 * Predecessor state index
1735 * @param ev
1736 * Event index
1737 * @param x2
1738 * Successor state index
1739 *
1740 * @return
1741 * True, if the transition was new the generator
1742 *
1743 * @exception Exception
1744 * - state or event not in generator (id 95)
1745 */
1746 bool SetTransition(Idx x1, Idx ev, Idx x2);
1747
1748 /**
1749 * Add a transition to generator by names. Statename and eventname
1750 * must already exist.
1751 *
1752 * @param rX1
1753 * Predecessor state name
1754 * @param rEv
1755 * Event name
1756 * @param rX2
1757 * Successor state name
1758 *
1759 * @return
1760 * True, if the transition was new the generator
1761 *
1762 * @exception Exception
1763 * - state or event not in generator (id 95)
1764 * - state name not known (id 90)
1765 * - event name not known (id 66)
1766 */
1767 bool SetTransition(const std::string& rX1, const std::string& rEv,
1768 const std::string& rX2);
1769
1770 /**
1771 * Add a transition to generator. States and event
1772 * must already exist.
1773 *
1774 *
1775 * @param rTransition
1776 * Transition
1777 *
1778 * @return
1779 * True, if the transition was new the generator
1780 * @exception Exception
1781 * - state or event not in generator (id 95)
1782 */
1783 bool SetTransition(const Transition& rTransition);
1784
1785 /**
1786 * Remove a transition by indices
1787 *
1788 * @param x1
1789 * Predecessor state index
1790 * @param ev
1791 * Event index
1792 * @param x2
1793 * Successor state index
1794 */
1795 void ClrTransition(Idx x1, Idx ev, Idx x2);
1796
1797 /**
1798 * Remove a transition by transition object
1799 *
1800 * @param rTrans
1801 * Transition object
1802 */
1803 void ClrTransition(const Transition& rTrans);
1804
1805 /**
1806 * Remove a transition by iterator
1807 *
1808 * @param it
1809 * TransSet::iterator
1810 * @return
1811 * Iterator to next transition
1812 */
1813 TransSet::Iterator ClrTransition(TransSet::Iterator it);
1814
1815 /**
1816 * Remove a transitions by state and event
1817 *
1818 * @param x1
1819 * Predecessor state index
1820 * @param ev
1821 * Event index
1822 */
1823 void ClrTransitions(Idx x1, Idx ev);
1824
1825 /**
1826 * Remove a transitions by state
1827 *
1828 * @param x1
1829 * Predecessor state index
1830 */
1831 void ClrTransitions(Idx x1);
1832
1833 /**
1834 * Clear all transitions
1835 */
1836 void ClearTransRel(void);
1837
1838 /**
1839 * Set transition without consistency check.
1840 *
1841 * @param rTrans
1842 * Transition to insert
1843 */
1844 void InjectTransition(const Transition& rTrans);
1845
1846 /**
1847 * Set transition relation without consistency check (no attributes)
1848 *
1849 * @param rNewtransrel
1850 * TransRel to insert
1851 */
1852 void InjectTransRel(const TransSet& rNewtransrel);
1853
1854 /** @} doxygen group */
1855
1856
1857
1858 /*****************************************
1859 *****************************************
1860 *****************************************
1861 *****************************************/
1862
1863 /** @name Attributes */
1864 /** @{ doxygen group */
1865
1866
1867 /**
1868 * Clear Attributes
1869 */
1870 virtual void ClearAttributes(void);
1871
1872 /**
1873 * Updates internal attributes.
1874 * This method does nothing and may be reimplemented
1875 * by a any class that adds semantics to attributes
1876 * Eg. you may set a particular state flag, if this state
1877 * is reachable.
1878 *
1879 * @return True if value changed
1880 */
1881 virtual bool UpdateAttributes(void) {return false;};
1882
1883 /**
1884 * Clear event attributes
1885 */
1886 virtual void ClearEventAttributes(void);
1887
1888 /**
1889 * Clear attribute for existing event
1890 *
1891 * @param index
1892 * Event index
1893 */
1894 virtual void ClrEventAttribute(Idx index);
1895
1896 /**
1897 * Set attribute for existing event.
1898 * This version uses a dynamic cast
1899 * to test the actual type of the provided attribute. An exception is
1900 * thrown for an invalid attribute type.
1901 * In a context where
1902 * the attribute type is known, you may prefer the TaGenerator method.
1903 *
1904 * @param index
1905 * Event index
1906 * @param rAttr
1907 * New attribute
1908 *
1909 * @exception Exception
1910 * - Index not found in alphabet (id 60)
1911 * - Cannot cast attribute (id 63)
1912 */
1913 virtual void EventAttribute(Idx index, const Type& rAttr);
1914
1915 /**
1916 * Set attributes for existing events.
1917 * This version uses a dynamic cast
1918 * to test the actual type of the provided attributes. An exception is
1919 * thrown for an invalid attribute type.
1920 *
1921 * @param rEventSet
1922 * Set of attributed events
1923 * @exception Exception
1924 * - Element not found in alphabet (id 60)
1925 * - Cannot cast attribute (id 63)
1926 */
1927 virtual void EventAttributes(const EventSet& rEventSet);
1928
1929 /**
1930 * Event attribute lookup.
1931 * In a context where
1932 * the attribute type is known, you may prefer the TaGenerator method.
1933 *
1934 * @param index
1935 *
1936 * @return
1937 * reference to attribute
1938 */
1939 virtual const AttributeVoid& EventAttribute(Idx index) const;
1940
1941 /**
1942 * Event attribute lookup.
1943 * In a context where the attribute type is known,
1944 * you may prefer the TaGenerator method.
1945 *
1946 * @param rName
1947 *
1948 * @return
1949 * reference to attribute
1950 */
1951 virtual const AttributeVoid& EventAttribute(const std::string& rName) const;
1952
1953 /**
1954 * Event attribute pointer to access Attribute methods.
1955 * If there are no attributes (plain vGenerator) this method
1956 * returs 0. If there are attributes, an explicit default value
1957 * may be inserted.
1958 * In a context where the attribute type is known,
1959 * you may prefer the TaGenerator method.
1960 *
1961 * @param index
1962 *
1963 * @return
1964 * pointer to attribute
1965 */
1966 virtual AttributeVoid* EventAttributep(Idx index);
1967
1968 /**
1969 * Event attribute pointer to access Attribute methods.
1970 * If there are no attributes (plain vGenerator) this method
1971 * returs 0. If there are attributes, an explicit default value
1972 * may be inserted.
1973 * In a context where the attribute type is known,
1974 * you may prefer the TaGenerator method.
1975 *
1976 * @param rName
1977 *
1978 * @return
1979 * pointer to attribute
1980 */
1981 virtual AttributeVoid* EventAttributep(const std::string& rName);
1982
1983
1984 /**
1985 * Clear state attributes
1986 */
1987 virtual void ClearStateAttributes(void);
1988
1989 /**
1990 * Clear attribute for existing state
1991 *
1992 * @param index
1993 * State index
1994 */
1995 virtual void ClrStateAttribute(Idx index);
1996
1997 /**
1998 * Set attribute for existing state.
1999 * This version uses a dynamic cast
2000 * to test the actual type of the provided attribute. An exception is
2001 * thrown for an invalid attribute type.
2002 * In a context where
2003 * the attribute type is known, you may prefer the TaGenerator method.
2004 *
2005 * @param index
2006 * State index
2007 * @param rAttr
2008 * New attribute
2009 *
2010 * @exception Exception
2011 * - Index not found in Stateset (id 60)
2012 * - Cannot cast attribute (id 63)
2013 */
2014 virtual void StateAttribute(Idx index, const Type& rAttr);
2015
2016 /**
2017 * State attribute lookup.
2018 * In a context where the attribute type is known,
2019 * you may prefer the TaGenerator method.
2020 *
2021 * @param index
2022 * State index
2023 *
2024 * @return Ref to attribute of state
2025 */
2026 virtual const AttributeVoid& StateAttribute(Idx index) const;
2027
2028 /**
2029 * State attribute pointer to access Attribute methods.
2030 * If there are no attributes (plain vGenerator) this method
2031 * returns 0. If there are attributes, an explicit default value
2032 * may be inserted.
2033 * In a context where the attribute type is known,
2034 * you may prefer the TaGenerator method.
2035 *
2036 * @param index
2037 * State index
2038 *
2039 * @return Pointer to attribute of state
2040 */
2041 virtual AttributeVoid* StateAttributep(Idx index);
2042
2043 /**
2044 * Clear transition attributes
2045 */
2046 virtual void ClearTransAttributes(void);
2047
2048 /**
2049 * Set attribute for existing transition.
2050 * This version uses a dynamic cast
2051 * to test the actual type of the provided attribute. An exception is
2052 * thrown for an invalid attribute type.
2053 * In a context where
2054 * the attribute type is known, you may prefer the TaGenerator method.
2055 *
2056 * @param rTrans
2057 * Transition
2058 * @param rAttr
2059 * New attribute
2060 *
2061 * @exception Exception
2062 * - Transition not found in transition relation(id 60)
2063 * - Cannot cast attribute (id 63)
2064 */
2065 virtual void TransAttribute(const Transition& rTrans, const Type& rAttr);
2066
2067
2068 /**
2069 * Clear attribute for existing transition
2070 *
2071 * @param rTrans
2072 * transition
2073 */
2074 virtual void ClrTransAttribute(const Transition& rTrans);
2075
2076 /**
2077 * Transition attribute lookup.
2078 * In a context where the attribute type is known,
2079 * you may prefer the TaGenerator method.
2080 *
2081 * @return
2082 * Attribute
2083 *
2084 */
2085 virtual const AttributeVoid& TransAttribute(const Transition& rTrans) const;
2086
2087 /**
2088 * Transition attribute pointer to access Attribute methods.
2089 * If there are no attributes (plain vGenerator) this method
2090 * returns 0. If there are attributes, an explicit default value
2091 * may be inserted.
2092 * In a context where the attribute type is known,
2093 * you may prefer the TaGenerator method.
2094 *
2095 * @return
2096 * Attribute pointer
2097 *
2098 */
2099 virtual AttributeVoid* TransAttributep(const Transition& rTrans);
2100
2101 /**
2102 * Clear global attribute
2103 */
2104 virtual void ClearGlobalAttribute(void);
2105
2106 /**
2107 * Set global attribute.
2108 * The vGenerator does not have attributes, so this function throws an exception for
2109 * any specified attribute different to AttributeVoid.
2110 * The TaGenarator provides a re-implementation to actually set the global attribute.
2111 *
2112 * @param rAttr
2113 * Attribute
2114 * @exception Exception
2115 * - Cannot cast attribute (id 63)
2116 */
2117 virtual void GlobalAttribute(const Type& rAttr);
2118
2119 /**
2120 * Set global attribute.
2121 * The vGenerator does not have attributes, so this function does nothing.
2122 * The TaGenarator provides a re-implementation to actually set the global attribute.
2123 *
2124 * @param rAttr
2125 * Attribute
2126 */
2127 virtual void GlobalAttributeTry(const Type& rAttr);
2128
2129 /**
2130 * Global attribute lookup.
2131 * In a context where the attribute type is known,
2132 * you may prefer the TaGenerator method.
2133 */
2134 virtual const AttributeVoid& GlobalAttribute(void) const;
2135
2136
2137 /**
2138 * Get attribute pointer
2139 * The global attribute allways exits. For the vGenerator its of
2140 * type AttributeVoid, the TaGenerator sets a nontrivial type.
2141 * In a context where the attribute type is known,
2142 * you may prefer the TaGenerator method.
2143 */
2144 virtual AttributeVoid* GlobalAttributep(void);
2145
2146
2147 /** @} doxygen group */
2148
2149
2150
2151 /*****************************************
2152 *****************************************
2153 *****************************************
2154 *****************************************/
2155
2156 /** @name Reachability */
2157 /** @{ doxygen group */
2158
2159
2160 /**
2161 * Compute set of accessible states
2162 */
2163 StateSet AccessibleSet(void) const;
2164
2165 /**
2166 * Make generator accessible.
2167 *
2168 * @return
2169 * True if generator contains at least one initial state
2170 */
2171 bool Accessible(void);
2172
2173 /**
2174 * Check if generator is accessible
2175 *
2176 * @return
2177 * True if generator is accesssible
2178 */
2179 bool IsAccessible(void) const;
2180
2181 /**
2182 * Compute set of Coaccessible states
2183 */
2184 StateSet CoaccessibleSet(void) const;
2185
2186 /**
2187 * Make generator Coaccessible
2188 *
2189 * @return
2190 * True if generator contains at least one marked state
2191 */
2192 bool Coaccessible(void);
2193
2194 /**
2195 * Check if generator is Coaccessible
2196 *
2197 * @return
2198 * True if generator is coaccessible
2199 */
2200 bool IsCoaccessible(void) const;
2201
2202 /**
2203 * Compute set of blocking states.
2204 *
2205 * A state is considered blocking if it is accessible but not coaccessible.
2206 */
2207 StateSet BlockingStates(void) const;
2208
2209
2210 /**
2211 * Compute set of terminal states.
2212 *
2213 * A terminal state is a state with no successor state.
2214 * If and only if the set of terminal states is empty, the generator is complete.
2215 * @return
2216 * Set of terminal states.
2217 */
2218 StateSet TerminalStates(void) const;
2219
2220
2221 /**
2222 * Compute set of terminal states.
2223 *
2224 * A terminal state is a state with no successor state.
2225 * This function returns the the set terminal states contained
2226 * in the specified state ste.
2227 *
2228 * @param rStates
2229 * Set of state indices to restrict the search
2230 * @return
2231 * Set of terminal states.
2232 */
2233 StateSet TerminalStates(const StateSet& rStates) const;
2234
2235 /**
2236 * Check if generator is complete.
2237 *
2238 * A generator is considered complete, if each state has at least
2239 * one successor state.
2240 *
2241 * If the generator is accessible, completeness
2242 * is equivalent to completeness of the generated language, ie
2243 * forall s in L(G) there exists r>s such that r in L(G)
2244 *
2245 * If the generator is trim, completeness is equivalent to
2246 * completeness of the markede language, ie forall s in Lm(G) there exists
2247 * r>s such that r in Lm(G)
2248 *
2249 * @return
2250 * True if generator is complete
2251 */
2252 bool IsComplete(void) const;
2253
2254 /**
2255 * Check if generator is complete.
2256 *
2257 * Same as IsComplete(void), however, only the specified
2258 * states are considered. The rational is to e.g. apply the test
2259 * to accessible (resp. trim) states only. Then, test is equivalent
2260 * to completeness of the generated (resp. marked) language.
2261 *
2262 * @param rStates
2263 * Set of state indices to restrict the completeness test
2264 * @return
2265 * True if generator is relatively complete
2266 */
2267 bool IsComplete(const StateSet& rStates) const;
2268
2269
2270 /**
2271 * Check if generator is complete w.r.t. an alphabet
2272 *
2273 * A generator is considered complete w.r.t. an alphabet Sigma_o,
2274 * if each state can be continued to a state in which a symbol
2275 * of Sigma_c is enabled.
2276 *
2277 * If the generator is accessible, completeness w.r.t. Sigma_o
2278 * is equivalent to:
2279 *
2280 * forall s in L(G) there exists t in (Sigma*)Sigma_u such that st in L(G)
2281 *
2282 * @param rSigmaO
2283 * Specified alphabet Sigma_o
2284 *
2285 * @return
2286 * True if generator is complete
2287 */
2288 bool IsComplete(const EventSet& rSigmaO) const;
2289
2290
2291 /**
2292 * Make generator Complete.
2293 *
2294 * This procedure removes all states that are guaranteed to evolve
2295 * into a terminal state within a finite number of transitios.
2296 * The current implementations is initialized by
2297 * the set of terminal states and then performs a backward
2298 * reachability analysis.
2299 *
2300 * @return
2301 * True if generator contains at least one initial state
2302 */
2303 bool Complete(void);
2304
2305 /**
2306 * Make generator Complete w.r.t. an alphabet
2307 *
2308 * This procedure removes all states that conflict with
2309 * completes w.r.t. the specified alphabet Sigma_o until
2310 * a fixpoint is reached. The current implementation consists of
2311 * an outer iteration to restrict a domain of states and an inner iteration
2312 * for abcakwar reachability analyis.
2313 *
2314 * THIS IS EXPERIMENTAL / NEEDS TESTING
2315 *
2316 * @param rSigmaO
2317 * Specified alphabet Sigma_o
2318 *
2319 * @return
2320 * True if generator contains at least one initial state
2321 */
2322 bool Complete(const EventSet& rSigmaO);
2323
2324
2325
2326
2327 /**
2328 * Compute set of trim states
2329 */
2330 StateSet TrimSet(void) const;
2331
2332 /**
2333 * Make generator trim
2334 *
2335 * This function removes all states are not accessible or not
2336 * coaccessible. In other words: only those states are kept, that
2337 * contribute to that marked language.
2338 *
2339 * @return
2340 * True if resulting generator contains at least one initial state and at least one marked state.
2341 */
2342 bool Trim(void);
2343
2344 /**
2345 * Check if generator is trim.
2346 *
2347 * Returns true if all states are rechable and coreachale.
2348 *
2349 * @return
2350 * True if generator is trim
2351 */
2352 bool IsTrim(void) const;
2353
2354
2355
2356
2357 /** @} doxygen group */
2358
2359 /*****************************************
2360 *****************************************
2361 *****************************************
2362 *****************************************/
2363
2364 /** @name File IO */
2365 /** @{ doxygen group */
2366
2367 /**
2368 * Write generators alphabet to console
2369 */
2370 void WriteAlphabet(void) const;
2371
2372 /**
2373 * Write generators alphabet to string
2374 *
2375 * @return
2376 * std::string
2377 * @exception Exception
2378 * - IO errors (id 2)
2379 */
2380 std::string AlphabetToString(void) const;
2381
2382 /**
2383 * Write generators alphabet to tokenwriter
2384 *
2385 * @param rTw
2386 * Reference to TokenWriter
2387 *
2388 * @exception Exception
2389 * - IO errors (id 2)
2390 */
2391 void WriteAlphabet(TokenWriter& rTw) const;
2392
2393 /**
2394 * Write a stateset to console (no re-indexing).
2395 * Uses WriteStateSet(TokenWriter& rTw, const StateSet&) const to write
2396 * the specified state set to console referring to this generators state names.
2397 *
2398 * @param rStateSet
2399 * Reference to stateset
2400 */
2401 void WriteStateSet(const StateSet& rStateSet) const;
2402
2403 /**
2404 * Write a stateset to string (no re-indexing).
2405 * Uses WriteStateSet(TokenWriter& rTw, const StateSet&) const to write
2406 * the specified state set to a string referring to this generators state names.
2407 *
2408 * @param rStateSet
2409 * Reference to stateset
2410 * @return
2411 * std::string
2412 * @exception Exception
2413 * - IO errors (id 2)
2414 */
2415 std::string StateSetToString(const StateSet& rStateSet) const;
2416
2417 /**
2418 * Write a stateset to formated text (no re-indexing).
2419 * Uses WriteStateSet(TokenWriter& rTw, const StateSet&) const to write
2420 * the specified state set to a string referring to this generators state names.
2421 *
2422 * @param rStateSet
2423 * Reference to stateset
2424 * @return
2425 * std::string
2426 * @exception Exception
2427 * - IO errors (id 2)
2428 */
2429 std::string StateSetToText(const StateSet& rStateSet) const;
2430
2431 /**
2432 * Write a stateset to TokenWriter.
2433 * All native output of external state sets done with this function.
2434 * Technically, a StateSet is a set of plain indices with no references
2435 * to symbolic names. Thus, it is only the context of a Generator that provides
2436 * the symbolic names for file output.
2437 *
2438 * Output of state sets always uses the mMinStateIndexMap to re-index states.
2439 * However, this map is only set up automatically for file output. If You require
2440 * re-indexed output to e.g. a string, you must set up the map by calling SetMinStateIndexMap().
2441 * To ensure that no re-indexing takes place, call ClearMinStateIndexMap().
2442 *
2443 * @param rTw
2444 * Reference to TokenWriter
2445 * @param rStateSet
2446 * Reference to stateset
2447 * @param rLabel
2448 * Optional outer tag, defaults to name of the set
2449 *
2450 * @exception Exception
2451 * - IO errors (id 2)
2452 */
2453 void WriteStateSet(TokenWriter& rTw, const StateSet& rStateSet, const std::string& rLabel="") const;
2454
2455 /**
2456 * Write a stateset to TokenWriter in XML format.
2457 *
2458 * This version for file IO supports the XML format introduced with libFAUDES 2.20.
2459 * Note that for Generators and derived classes, the native libFAUDES token
2460 * format is considered the default. To obtain XML fromated output of a Generator,
2461 * use the XWrite() interface.
2462 *
2463 * @param rTw
2464 * Reference to TokenWriter
2465 * @param rStateSet
2466 * Reference to stateset
2467 * @param rLabel
2468 * Section name, defaults to name of set
2469 *
2470 * @exception Exception
2471 * - IO errors (id 2)
2472 */
2473 void XWriteStateSet(TokenWriter& rTw, const StateSet& rStateSet, const std::string& rLabel="") const;
2474
2475 /**
2476 * Write a stateset to TokenWriter (debug version, no re-indexing)
2477 *
2478 * @param rTw
2479 * Reference to TokenWriter
2480 * @param rStateSet
2481 * Reference to stateset
2482 *
2483 * @exception Exception
2484 * - IO errors (id 2)
2485 */
2486 void DWriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const;
2487
2488 /**
2489 * Write stateset of this generator to a string (no re-indexing)
2490 *
2491 * @return
2492 * std::string
2493 * @exception Exception
2494 * - IO errors (id 2)
2495 */
2496 std::string StatesToString(void) const;
2497
2498 /**
2499 * Write stateset of this generator to formated text (no re-indexing)
2500 *
2501 * @return
2502 * std::string
2503 * @exception Exception
2504 * - IO errors (id 2)
2505 */
2506 std::string StatesToText(void) const;
2507
2508 /**
2509 * Write set of marked states to a string (no re-indexing)
2510 *
2511 * @return
2512 * std::string
2513 * @exception Exception
2514 * - IO errors (id 2)
2515 */
2516 std::string MarkedStatesToString(void) const;
2517
2518 /**
2519 * Write set of initial states to a string (no re-indexing)
2520 *
2521 * @return
2522 * std::string
2523 * @exception Exception
2524 * - IO errors (id 2)
2525 */
2526 std::string InitStatesToString(void) const;
2527
2528 /**
2529 * Write transition relation to console (no re-indexing)
2530 */
2531 void WriteTransRel(void) const;
2532
2533 /**
2534 * Write transition relation to string (no re-indexing)
2535 */
2536 std::string TransRelToString(void) const;
2537
2538 /**
2539 * Write transition relation to formated text (no re-indexing)
2540 */
2541 std::string TransRelToText(void) const;
2542
2543 /**
2544 * Write transition relation to tokenwriter.
2545 * Re-indexing and symbolic state names are handled in the same way
2546 * as with state sets: this function refers to the generators state symboltable to
2547 * obtain state names and uses the mMinStateIndexMap to re-index the output.
2548 *
2549 * @param rTw
2550 * Reference to TokenWriter
2551 *
2552 * @exception Exception
2553 * - IO errors (id 2)
2554 */
2555 void WriteTransRel(TokenWriter& rTw) const;
2556
2557 /**
2558 * Write transition relation to tokenwriter (debug version)
2559 * @param rTw
2560 * Reference to TokenWriter
2561 *
2562 * @exception Exception
2563 * - IO errors (id 2)
2564 */
2565 void DWriteTransRel(TokenWriter& rTw) const;
2566
2567
2568 /**
2569 * Writes generator to dot input format.
2570 * The dot file format is specified by the graphiz package; see http://www.graphviz.org.
2571 * The package includes the dot command line tool to generate a graphical
2572 * representation of the generators graph. See also GraphWrite().
2573 * This functions sets the re-indexing to minimal indices.
2574 *
2575 * @param rFileName
2576 * File to write
2577 *
2578 * @exception Exception
2579 * - IO errors (id 2)
2580 */
2581 virtual void DotWrite(const std::string& rFileName) const;
2582
2583 /**
2584 * Writes generator to dot input format (no re-indexing).
2585 * Variant of DotWrite() without re-indexing.
2586 *
2587 * @param rFileName
2588 * File to write
2589 *
2590 * @exception Exception
2591 * - IO errors (id 2)
2592 */
2593 virtual void DDotWrite(const std::string& rFileName) const;
2594
2595 /**
2596 * Writes generator to dot input format for export to VioLib.
2597 * Variant of DotWrite() using strategic state and event names
2598 * to simplify import to VioLib (qt widget for graphical representation
2599 * of FAUDES generators).
2600 *
2601 * @param rFileName
2602 * File to write
2603 * @exception Exception
2604 * - IO errors (id 2)
2605 */
2606 virtual void XDotWrite(const std::string& rFileName) const;
2607
2608 /**
2609 * Read a state set.
2610 * Refer to the generators state symboltable while reading a state set.
2611 * Ignore any attributes.
2612 *
2613 * @param rTr
2614 * Reference to TokenReader
2615 * @param rLabel
2616 * Label of set in source
2617 * @param rStateSet
2618 * Destination state set
2619 *
2620 * @exception Exception
2621 * - IO errors (id 1)
2622 * - token mismatch (id 50, 51, 52, 80, 85)
2623 */
2624 void ReadStateSet(TokenReader& rTr, const std::string& rLabel, StateSet& rStateSet) const;
2625
2626 /**
2627 * Test whether file-i/o uses minimal state indicees.
2628 *
2629 * @return
2630 * True when minimal state indicees are enabled
2631 */
2632 bool ReindexOnWrite(void) const;
2633
2634 /**
2635 * Enable/disable minimal state indicees for file-i/o.
2636 *
2637 * @param flag
2638 * True enables reindexing.
2639 */
2640 void ReindexOnWrite(bool flag);
2641
2642
2643 /**
2644 * Enable/disable reindexing states for file-i/o.
2645 *
2646 * Set default value for re-indexing. Initially, the default
2647 * is set to "false".
2648 *
2649 * @param flag
2650 * True enables reindexing.
2651 */
2652 static void ReindexOnWriteDefault(bool flag);
2653
2654
2655 /**
2656 * Enable/disable reindexing states for file-i/o.
2657 *
2658 * Set default value for re-indexing.
2659 *
2660 * @return
2661 * True for reindexing enabled.
2662 */
2663 static bool ReindexOnWriteDefault(void);
2664
2665
2666 /** @} doxygen group */
2667
2668
2669 /*****************************************
2670 *****************************************
2671 *****************************************
2672 *****************************************/
2673
2674 /** @name Misc */
2675 /** @{ doxygen group */
2676
2677 /**
2678 * Return used events (executed in transitions)
2679 *
2680 * @return EventSet
2681 */
2682 EventSet UsedEvents(void) const;
2683
2684 /**
2685 * Return unused events
2686 *
2687 * @return EventSet
2688 */
2689 EventSet UnusedEvents(void) const;
2690
2691 /**
2692 * Set the alphabet to used events
2693 */
2694 void MinimizeAlphabet(void);
2695
2696 /**
2697 * Return active event set at state x1
2698 *
2699 * @param x1
2700 * Index of x1
2701 *
2702 * @return EventSet
2703 */
2704 EventSet ActiveEventSet(Idx x1) const;
2705
2706 /**
2707 * Return active transition set at state x1
2708 *
2709 * @param x1
2710 * Index of x1
2711 *
2712 * @return EventSet
2713 */
2714 TransSet ActiveTransSet(Idx x1) const;
2715
2716 /**
2717 * Return the states covered by transitions
2718 *
2719 * @return StateSet
2720 */
2721 StateSet TransRelStates(void) const;
2722
2723 /**
2724 * Return the successor state of state x1 with event ev.
2725 * If no such transition exists, return 0.
2726 * If multiple such transitions exit, through expection.
2727 *
2728 * A more egeneral set valued interface is provided by TransSet
2729 *
2730 * @return next state
2731 * @exception Exception
2732 * - Successor state does not exist uniquely (id 92)
2733 */
2734 Idx SuccessorState(Idx x1, Idx ev) const;
2735
2736 /**
2737 * Return the successor states of state x1
2738 *
2739 * @return StateSet
2740 */
2741 StateSet SuccessorStates(Idx x1) const;
2742
2743 /**
2744 * Return the successor states of state x1 with event ev
2745 *
2746 * @return StateSet
2747 */
2748 StateSet SuccessorStates(Idx x1, Idx ev) const;
2749
2750 /**
2751 * Check if generator is deterministic.
2752 *
2753 * We require the transition relation to be a partial function
2754 * and at most one initial state.
2755 *
2756 * Note: pre 2.19 libFAUDES also insisted in exactly one initial state.
2757 *
2758 *
2759 * @return
2760 * True if generator is deterministic
2761 */
2762 bool IsDeterministic(void) const;
2763
2764 /**
2765 * Set minimal index map for file io of generator states
2766 *
2767 * This function is implemented as fake-const to allow for
2768 * const Write function.
2769 *
2770 */
2771 void SetMinStateIndexMap(void) const;
2772
2773 /**
2774 * Clear minimal index map for 1:1 file io
2775 *
2776 */
2777 void ClearMinStateIndexMap(void) const;
2778
2779 /**
2780 * Get state index as is it will be written to file.
2781 *
2782 * @param index
2783 * state index
2784 * @return
2785 * minimal index
2786 */
2787 Idx MinStateIndex(Idx index) const;
2788
2789
2790 /**
2791 * Re-enumerate states.
2792 *
2793 * This method re-enumerates states such that the resulting
2794 * state set consist of consecutive indexes; i.e. Size()=MaxStateIndex().
2795 * The current implementation sets up the minimal-state-index map used for
2796 * file i/o and applies it to the state set and the transition relation.
2797 *
2798 * Note: libFAUDES does not maintain consecutive state indices.
2799 * This was a design decision and it comes pros and cons. The method MinStateIndex()
2800 * was implemented to provide some limited support for the implementation of algorithms in a
2801 * consecutive state enumeration paradigm. However, mixing both paradigms most likely
2802 * involves an overall performace penalty.
2803 */
2804 void MinStateIndex(void);
2805
2806
2807 /**
2808 * Get maximum state index used in this generator.
2809 * Returns 0 if no states at all.
2810 * @return
2811 * maximal index
2812 */
2813 Idx MaxStateIndex(void) const;
2814
2815
2816 /**
2817 * Get state index translation map
2818 *
2819 * @return
2820 * minimal index map
2821 */
2822 const std::map<Idx,Idx>& MinStateIndexMap(void) const;
2823
2824
2825 /**
2826 * Pretty printable event name for index (eg for debugging).
2827 *
2828 * @param index
2829 * Event index
2830 *
2831 * @return
2832 * std::string
2833 */
2834 std::string EStr(Idx index) const;
2835
2836 /**
2837 * Return pretty printable state name for index (eg for debugging)
2838 *
2839 * @param index
2840 * State index
2841 *
2842 * @return
2843 * std::string
2844 */
2845 std::string SStr(Idx index) const;
2846
2847
2848 /**
2849 * Return pretty printable transition (eg for debugging)
2850 *
2851 * @param rTrans
2852 * Transition
2853 *
2854 * @return
2855 * std::string
2856 */
2857 std::string TStr(const Transition& rTrans) const;
2858
2859
2860 /**
2861 * Produce graphical representation of this generator.
2862 * This method calls the generator's DotWrite function and then processes the output
2863 * with the dot tool from graphiz package. If no output format is given,
2864 * try to guess from filename extension. See also ProcessDot().
2865 *
2866 * @param rFileName
2867 * Name of output file
2868 * @param rOutFormat
2869 * Graphics file format, eg "png", "jpg", "svg"
2870 * @param rDotExec
2871 * path/name of executable
2872 * @exception Exception
2873 * - IO errors (id 2)
2874 * - error during systemcall for dot (id 3)
2875 */
2876 void GraphWrite(const std::string& rFileName, const std::string& rOutFormat="",
2877 const std::string& rDotExec="dot") const;
2878
2879 /**
2880 * Order for sorting containers of generators
2881 */
2882 bool operator < (const vGenerator& rOtherGen) const {
2883 return (mId < rOtherGen.mId);
2884 }
2885
2886
2887 /** @} doxygen group */
2888
2889
2890 protected:
2891
2892 /** Number of generator */
2894
2895 /** Number of generator objects */
2897
2898 /** State symbol table (local per Generator)*/
2900
2901 /** Pointer to State symbol table */
2903
2904 /** Pointer to Event symbol table */
2906
2907 /** Automatic state names */
2909
2910 /** Default for automatic statenames */
2912
2913 /** Reindex states on file-i/o */
2915
2916 /** Default for automatic statenames */
2918
2919 /** Pointer to alphabet (actual type depends on attributes) */
2921
2922 /** Pointer to state set (actual type depends on attributes) */
2924
2925 /** Pointer to ransition relation (actual type depends on attributes) */
2927
2928 /** Pointer to lobal attribute (actual type depends on attributes) */
2930
2931 /** Pointer to alphabet prototype (incl. attribute type) */
2933
2934 /** Pointer to state set prototype (incl. attribute type) */
2936
2937 /** Pointer to transition relation prototype (incl. attribute type) */
2939
2940 /** Pointer to global attribute prototype (configures global attribute type) */
2942
2943 /** Static default alphabet prototype (incl. attribute type) */
2944 static const EventSet& AlphabetVoid(void);
2945
2946 /** Static default state set prototype (incl. attribute type) */
2947 static const StateSet& StatesVoid(void);
2948
2949 /** Static default transition relation prototype (incl. attribute type) */
2950 static const TransSet& TransRelVoid(void);
2951
2952 /** Static default global attribute prototype (configures global attribute type) */
2953 static const AttributeVoid& GlobalVoid(void);
2954
2955 /** Initial states */
2957
2958 /** Marked states */
2960
2961 /** Map State indices to consecutive indices */
2962 std::map<Idx,Idx> mMinStateIndexMap;
2963
2964 /** Allocate my heap members (attribute dependent types) */
2965 virtual void NewCore(void);
2966
2967 /** Free my heap members (attribute dependent types) */
2968 virtual void DeleteCore(void);
2969
2970 /** Callback for core update */
2971 virtual void UpdateCore(void);
2972
2973 /** Configure attribute types */
2974 void ConfigureAttributeTypes(const AttributeVoid* pNewGlobalPrototype,
2975 const StateSet* pNewStatesPrototype, const EventSet* pNewAlphabetPrototype,
2976 const TransSet* pNewTransRelPrototype);
2977
2978 /** Assignment for matching type */
2979 void DoAssign(const vGenerator& rSrc);
2980
2981 /**
2982 * Read generator object from TokenReader, see Type::Read for public wrappers.
2983 *
2984 * Virtual function for std token io interface. Context is ignored,
2985 * label defaults to "Generator".
2986 *
2987 * @param rTr
2988 * TokenReader to read from
2989 * @param rLabel
2990 * Section to read
2991 * @param pContext
2992 * Read context to provide contextual information (ignored)
2993 *
2994 * @exception Exception
2995 * - token mismatch (id 50, 51, 52, 80, 85)
2996 * - IO error (id 1)
2997 */
2998 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
2999
3000 /**
3001 * Write generator to TokenWriter, see Type::Write for public wrappers.
3002 *
3003 * Virtual function for std token io interface. Context is ignored,
3004 * label defaults to "Generator". If the tokenwriter writes to a file,
3005 * state indices will be re-indext to start from 1.
3006 *
3007 * @param rTw
3008 * Reference to TokenWriter
3009 * @param rLabel
3010 * Label of section to write
3011 * @param pContext
3012 * Write context to provide contextual information (ignored)
3013 *
3014 * @exception Exception
3015 * - IO errors (id 2)
3016 */
3017 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
3018
3019 /**
3020 * Write generator in debugging format to TokenWriter, see Type::DWrite for public wrappers.
3021 *
3022 * Reimplement this method in derived classes to provide the std token io
3023 * interface defined in the public section of Type.
3024 *
3025 * @param rTw
3026 * Reference to TokenWriter
3027 * @param rLabel
3028 * Label of section to write
3029 * @param pContext
3030 * Write context to provide contextual information (ignored)
3031 *
3032 * @exception Exception
3033 * - IO errors (id 2)
3034 */
3035 virtual void DoDWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
3036
3037 /**
3038 * Write generator statistics as comment to TokenWriter, see Type::SWrite for public wrappers.
3039 *
3040 * Reimplement this method in derived classes to provide the std token io
3041 * interface defined in the public section of Type.
3042 *
3043 * @param rTw
3044 * Reference to TokenWriter
3045 *
3046 * @exception Exception
3047 * - IO errors (id 2)
3048 */
3049 virtual void DoSWrite(TokenWriter& rTw) const;
3050
3051 /**
3052 * Write generator to TokenWriter, see Type::XWrite for public wrappers.
3053 *
3054 * Virtual function for std token io interface. Context is ignored,
3055 * label defaults to "Generator".
3056 *
3057 * @param rTw
3058 * Reference to TokenWriter
3059 * @param rLabel
3060 * Label of section to write
3061 * @param pContext
3062 * Write context to provide contextual information (ignored)
3063 *
3064 * @exception Exception
3065 * - IO errors (id 2)
3066 */
3067 virtual void DoXWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
3068
3069 /**
3070 * Read the generator's alphabet from a TokenReader.
3071 * As of 2.24e, this method returns silently if no alphabet-tag is found.
3072 *
3073 * @param rTr
3074 * Reference to TokenReader
3075 *
3076 * @exception Exception
3077 * - IO errors (id 1)
3078 * - token mismatch (id 50, 51, 52)
3079 */
3080 void ReadAlphabet(TokenReader& rTr);
3081
3082 /**
3083 * Write generators stateset to TokenWriter.
3084 *
3085 * This method differs from the general purpos version
3086 * WriteStateSet(TokenWriter&, const StateSet&) in that it
3087 * can optionally write an explicit symbol table for state names.
3088 * This will happen whenever writing is done without re-indexing
3089 * states.
3090 *
3091 * @param rTw
3092 * Reference to TokenWriter
3093 *
3094 * @exception Exception
3095 * - IO errors (id 2)
3096 */
3097 void WriteStates(TokenWriter& rTw) const;
3098
3099 /**
3100 * Read the generator's stateset from a TokenReader.
3101 * This sets up the StateSymbolTable.
3102 * As of 2.24e, this method returns silently if no alphabet-tag is found.
3103 *
3104 * @param rTr
3105 * Reference to TokenReader
3106 * @exception Exception
3107 * - IO errors (id 1)
3108 * - token mismatch (id 50, 51, 52)
3109 */
3110 void ReadStates(TokenReader& rTr);
3111
3112 /**
3113 * Read a stateset from TokenReader in XML format.
3114 *
3115 * This version for file IO supports the XML format introduced with libFAUDES 2.20.
3116 * Note that for Generators and derived classes, the native libFAUDES token
3117 * format is considered the default. To read XML fromated data,
3118 * use the XRead() interface.
3119 *
3120 * @param rTr
3121 * Reference to TokenReader
3122 * @param rStateSet
3123 * Reference to stateset
3124 * @param rLabel
3125 * Section name, defaults to name of set
3126 *
3127 * @exception Exception
3128 * - IO errors (id 1)
3129 * - token mismatch (id 50, 51, 52)
3130 */
3131 void XReadStateSet(TokenReader& rTr, StateSet& rStateSet, const std::string& rLabel="") const;
3132
3133 /**
3134 * Read the generator's transition relation from a file.
3135 *
3136 * @param rFileName
3137 * File to read from
3138 *
3139 * @exception Exception
3140 * - IO errors (id 1)
3141 * - token mismatch (id 50, 51, 52)
3142 */
3143 void ReadTransRel(const std::string& rFileName);
3144
3145 /**
3146 * Read the generator's transition relation from a TokenReader.
3147 *
3148 * @param rTr
3149 * Reference to TokenReader
3150 *
3151 * @exception Exception
3152 * - IO errors (id 1)
3153 * - token mismatch (id 50, 51, 52)
3154 */
3155 void ReadTransRel(TokenReader& rTr);
3156
3157 /**
3158 * Read the generator's transition relation from a TokenReader.
3159 *
3160 * @param rTr
3161 * Reference to TokenReader
3162 *
3163 * @exception Exception
3164 * - IO errors (id 1)
3165 * - token mismatch (id 50, 51, 52)
3166 */
3167 void XReadTransRel(TokenReader& rTr);
3168
3169
3170 /**
3171 * Write transition relation to tokenwriter in XML format.
3172 *
3173 * This version for file IO supports the XML format introduced with libFAUDES 2.20.
3174 * Note that for Generators and derived classes, the native libFAUDES token
3175 * format is considered the default. To obtain XML fromated output of a Generator,
3176 * use the XWrite() interface.
3177 *
3178 *
3179 * @param rTw
3180 * Reference to TokenWriter
3181 *
3182 * @exception Exception
3183 * - IO errors (id 2)
3184 */
3185 void XWriteTransRel(TokenWriter& rTw) const;
3186
3187
3188};
3189
3190/**
3191 * Plain generator, api typedef for generator with no attributes.
3192 * \ingroup GeneratorClasses
3193 */
3195
3196/**
3197 * Convenience typedef for vectors og generators
3198 * \ingroup GeneratorClasses
3199 */
3201
3202
3203/**
3204 * RTI wrapper function. See also vGenerator::IsAccessible().
3205 * \ingroup GeneratorFunctions
3206 */
3207extern FAUDES_API bool IsAccessible(const vGenerator& rGen);
3208
3209/**
3210 * RTI wrapper function. See also vGenerator::IsCoaccessible().
3211 * \ingroup GeneratorFunctions
3212 */
3213extern FAUDES_API bool IsCoaccessible(const vGenerator& rGen);
3214
3215/**
3216 * RTI wrapper function. See also vGenerator::IsTrim().
3217 * \ingroup GeneratorFunctions
3218 */
3219extern FAUDES_API bool IsTrim(const vGenerator& rGen);
3220
3221/**
3222 * RTI wrapper function. See also vGenerator::IsComplete().
3223 * \ingroup GeneratorFunctions
3224 */
3225extern FAUDES_API bool IsComplete(const vGenerator& rGen);
3226
3227/**
3228 * RTI wrapper function. See also vGenerator::IsComplete().
3229 * \ingroup GeneratorFunctions
3230 */
3231extern FAUDES_API bool IsComplete(const vGenerator& rGen, const EventSet& rSigmaO);
3232
3233/**
3234 * RTI wrapper function. See also vGenerator::IsDeterministic().
3235 * \ingroup GeneratorFunctions
3236 */
3237extern FAUDES_API bool IsDeterministic(const vGenerator& rGen);
3238
3239
3240/**
3241 * RTI wrapper function. See also vGenerator::Accessible().
3242 * \ingroup GeneratorFunctions
3243 */
3244extern FAUDES_API void Accessible(vGenerator& rGen);
3245
3246/**
3247 * RTI wrapper function. See also vGenerator::Accessible().
3248 * \ingroup GeneratorFunctions
3249 */
3250extern FAUDES_API void Accessible(const vGenerator& rGen, vGenerator& rRes);
3251
3252/**
3253 * RTI wrapper function. See also vGenerator::Coaccessible().
3254 * \ingroup GeneratorFunctions
3255 */
3256extern FAUDES_API void Coaccessible(vGenerator& rGen);
3257
3258/**
3259 * RTI wrapper function. See also vGenerator::Coaccessible().
3260 * \ingroup GeneratorFunctions
3261 */
3262extern FAUDES_API void Coaccessible(const vGenerator& rGen, vGenerator& rRes);
3263
3264/**
3265 * RTI wrapper function. See also vGenerator::Complete().
3266 * \ingroup GeneratorFunctions
3267 */
3268extern FAUDES_API void Complete(vGenerator& rGen);
3269
3270/**
3271 * RTI wrapper function. See also vGenerator::Complete().
3272 * \ingroup GeneratorFunctions
3273 */
3274extern FAUDES_API void Complete(const vGenerator& rGen, vGenerator& rRes);
3275
3276/**
3277 * RTI wrapper function. See also vGenerator::Complete().
3278 * \ingroup GeneratorFunctions
3279 */
3280extern FAUDES_API void Complete(vGenerator& rGen, const EventSet& rSigmaO);
3281
3282/**
3283 * RTI wrapper function. See also vGenerator::Complete().
3284 * \ingroup GeneratorFunctions
3285 */
3286extern FAUDES_API void Complete(const vGenerator& rGen, const EventSet& rSigmaO, vGenerator& rRes);
3287
3288/**
3289 * RTI wrapper function. See also vGenerator::Trim().
3290 * \ingroup GeneratorFunctions
3291 */
3292extern FAUDES_API void Trim(vGenerator& rGen);
3293
3294/**
3295 * RTI wrapper function. See also vGenerator::Trim().
3296 * \ingroup GeneratorFunctions
3297 */
3298extern FAUDES_API void Trim(const vGenerator& rGen, vGenerator& rRes);
3299
3300
3301/**
3302 * RTI wrapper function.
3303 * \ingroup GeneratorFunctions
3304 */
3305extern FAUDES_API void MarkAllStates(vGenerator& rGen);
3306
3307/**
3308 * RTI wrapper function.
3309 * \ingroup GeneratorFunctions
3310 */
3311extern FAUDES_API void AlphabetExtract(const vGenerator& rGen, EventSet& rRes);
3312
3313
3314/**
3315 * RTI convenience function.
3316 */
3317extern FAUDES_API void SetIntersection(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes);
3318
3319/**
3320 * RTI convenience function.
3321 */
3322extern FAUDES_API void SetIntersection(const GeneratorVector& rGenVec, EventSet& rRes);
3323
3324/**
3325 * RTI convenience function.
3326 */
3327extern FAUDES_API void SetUnion(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes);
3328
3329/**
3330 * RTI convenience function.
3331 */
3332extern FAUDES_API void SetUnion(const GeneratorVector& rGenVec, EventSet& rRes);
3333
3334/**
3335 * RTI convenience function.
3336 */
3337extern FAUDES_API void SetDifference(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes);
3338
3339
3340/**
3341 * Apply relable map to generator
3342 *
3343 * This implementation tries to keep the atributtes from the
3344 * domain elements.
3345 *
3346 * @param rMap
3347 * map to apply
3348 * @param rGen
3349 * generator to apply the map to
3350 * @param rRes
3351 * relabled generator
3352 * @exceptions
3353 * - symboltable must match
3354 */
3355extern FAUDES_API void ApplyRelabelMap(const RelabelMap& rMap, const vGenerator& rGen, vGenerator& rRes);
3356
3357
3358
3359} // namespace faudes
3360
3361/*
3362
3363#define FAUDES_GENERATOR_DECLARATION(gtype,GlobalAttr,StateAttr,EventAttr,TransAttr) \
3364 public: \
3365 virtual void EventAttribute(Idx index, const EventAttr& rAttr); \
3366 virtual void EventAttributes(const TaEventSet<EventAttr>& rEventSet); \
3367 virtual const EventAttr& EventAttribute(Idx index) const; \
3368 virtual const EventAttr& EventAttribute(const std::string& rName) const; \
3369 virtual EventAttr* EventAttributep(Idx index); \
3370 virtual EventAttr* EventAttributep(const std::string& rName); \
3371 virtual void StateAttribute(Idx index, const StateAttr& rAttr); \
3372 virtual const StateAttr& StateAttribute(Idx index) const; \
3373 virtual StateAttr* StateAttributep(Idx index); \
3374 virtual void TransAttribute(const Transition& rTrans, const TransAttr& rAttr); \
3375 virtual const TransAttr& TransAttribute(const Transition& rTrans) const; \
3376 virtual TransAttr* TransAttributep(const Transition& rTrans); \
3377 virtual void GlobalAttribute(const GlobalAttr& rAttr); \
3378 virtual void GlobalAttributeTry(const Type& rAttr); \
3379 virtual const GlobalAttr& GlobalAttribute(void) const; \
3380 virtual GlobalAttr* GlobalAttributep(void);
3381
3382#define FAUDES_GENERATOR_IMPLEMENTATION(gtype,GlobalAttr,StateAttr,EventAttr,TransAttr) \
3383 public: \
3384 virtual void EventAttribute(Idx index, const EventAttr& rAttr); \
3385 virtual void EventAttributes(const TaEventSet<EventAttr>& rEventSet); \
3386 virtual const EventAttr& EventAttribute(Idx index) const; \
3387 virtual const EventAttr& EventAttribute(const std::string& rName) const; \
3388 virtual EventAttr* EventAttributep(Idx index); \
3389 virtual EventAttr* EventAttributep(const std::string& rName); \
3390 virtual void StateAttribute(Idx index, const StateAttr& rAttr); \
3391 virtual const StateAttr& StateAttribute(Idx index) const; \
3392 virtual StateAttr* StateAttributep(Idx index); \
3393 virtual void TransAttribute(const Transition& rTrans, const TransAttr& rAttr); \
3394 virtual const TransAttr& TransAttribute(const Transition& rTrans) const; \
3395 virtual TransAttr* TransAttributep(const Transition& rTrans); \
3396 virtual void GlobalAttribute(const GlobalAttr& rAttr); \
3397 virtual void GlobalAttributeTry(const Type& rAttr); \
3398 virtual const GlobalAttr& GlobalAttribute(void) const; \
3399 virtual GlobalAttr* GlobalAttributep(void);
3400
3401*/
3402
3403
3404#endif
3405
Classes IndexSet, TaIndexSet.
Classes NameSet, TaNameSet.
#define FAUDES_API
Class SymbolTable.
Class Token.
Class TokenReader.
Class TokenWriter.
Classes Transition, TTransSet and TaTransSet.
const EventSet * pAlphabetPrototype
const AttributeVoid * pGlobalPrototype
virtual bool UpdateAttributes(void)
AttributeVoid * mpGlobalAttribute
void TransRel(TransSetX1X2Ev &res) const
static bool msReindexOnWriteDefault
SymbolTable mStateSymbolTable
SymbolTable * mpEventSymbolTable
void TransRel(TransSetEvX2X1 &res) const
void TransRel(TransSetX2X1Ev &res) const
const TransSet * pTransRelPrototype
static bool msStateNamesEnabledDefault
std::map< Idx, Idx > mMinStateIndexMap
const StateSet * pStatesPrototype
SymbolTable * mpStateSymbolTable
void ReadTransRel(const std::string &rFileName)
void SetDifference(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
void SetUnion(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
void SetIntersection(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
vGenerator Generator
TBaseVector< Generator > GeneratorVector
bool IsComplete(const vGenerator &rGen)
void Trim(vGenerator &rGen)
void Complete(vGenerator &rGen)
bool IsAccessible(const vGenerator &rGen)
bool IsTrim(const vGenerator &rGen)
void MarkAllStates(vGenerator &rGen)
bool IsCoaccessible(const vGenerator &rGen)
void AlphabetExtract(const vGenerator &rGen, EventSet &rRes)
void Accessible(vGenerator &rGen)
void Coaccessible(vGenerator &rGen)
bool IsDeterministic(const vGenerator &rGen)
uint32_t Idx
void ApplyRelabelMap(const RelabelMap &rMap, const vGenerator &rGen, vGenerator &rRes)

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