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