cfl_localgen.cpp
Go to the documentation of this file.
1/** @file cfl_localgen.cpp Helper functions for projected generators */
2
3/* FAU Discrete Event Systems Library (libfaudes)
4
5 Copyright (C) 2006 Bernd Opitz
6 Exclusive copyright is granted to Klaus Schmidt
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
21
22#include "cfl_localgen.h"
23
24namespace faudes {
25
26// LowExitStates(rHighAlph, rEntryStatesMap, rLowRevTransRel, highState)
27StateSet LowExitStates(const Generator& rLowGen, const EventSet& rHighAlph,
28 const std::map<Idx,StateSet>& rEntryStatesMap, const TransSetX2EvX1& rLowRevTransRel,
29 Idx highState) {
30 // prepare result:
31 StateSet lo_exitstates;
32 // algorithm:
33 LowExitStates(rHighAlph, rEntryStatesMap, rLowRevTransRel, highState, lo_exitstates);
34 // return result:
35 return lo_exitstates;
36}
37
38
39// LowExitStates(rHighAlph, rEntryStatesMap, rLowRevTransRel, highState, rLowExitStates)
40void LowExitStates(const EventSet& rHighAlph, const std::map<Idx,StateSet>& rEntryStatesMap,
41 const TransSetX2EvX1& rLowRevTransRel, Idx highState, StateSet& rLowExitStates) {
42 FD_DF("LowExitStates: computing low level exit states for high level"
43 << " state " << rLowExitStates.Str(highState));
44 // helpers:
45 std::map<Idx,StateSet>::const_iterator esmap_it;
46 StateSet::Iterator lit;
49 // algorithm:
50 esmap_it = rEntryStatesMap.find(highState);
51#ifdef FAUDES_CHECKED
52 if (esmap_it == rEntryStatesMap.end()) {
53 std::stringstream errstr;
54 errstr << "Hi level state " << rHighAlph.Str(highState)
55 << " not found in entry states map";
56 throw Exception("LowExitStates", errstr.str(), 502);
57 }
58#endif
59 // find predecessor states of low_level entry states
60 for (lit = esmap_it->second.Begin(); lit != esmap_it->second.End(); ++lit) {
61 FD_DF("LowExitStates: current low level entry state "
62 << rLowExitStates.Str(*lit));
63 rtit = rLowRevTransRel.BeginByX2(*lit);
64 rtit_end = rLowRevTransRel.EndByX2(*lit);
65 for (; rtit != rtit_end; ++rtit) {
66 if (rHighAlph.Exists(rtit->Ev)) {
67 FD_DF("LowExitStates: found low level exit state "
68 << rLowExitStates.Str(rtit->X1));
69 rLowExitStates.Insert(rtit->X1);
70 }
71 }
72 }
73}
74
75// ReachableEvents(lo, rHighAlph, lowState)
76EventSet ReachableEvents(const Generator& rLowGen, const EventSet& rHighAlph,
77 Idx lowState) {
78 // prepare result:
79 EventSet reachable_events = rLowGen.NewEventSet();
80 // algorithm:
81 ReachableEvents(rLowGen, rHighAlph, lowState, reachable_events);
82 // return result:
83 return reachable_events;
84}
85
86
87// ReachableEvents(lo, rHighAlph, lowState, rReachableEvents)
88void ReachableEvents(const Generator& rLowGen, const EventSet& rHighAlph,
89 Idx lowState, EventSet& rReachableEvents) {
90 // helpers:
91 // iterators
93 TransSet::Iterator tit_end;
94 // todo list
95 std::stack<Idx> todo;
96 // done set
97 StateSet done;
98
99 // prepare result:
100 rReachableEvents.Clear();
101
102 // algorithm:
103 todo.push(lowState);
104 done.Insert(lowState);
105 while (! todo.empty()) {
106 const Idx current = todo.top();
107 todo.pop();
108 tit = rLowGen.TransRelBegin(current);
109 tit_end = rLowGen.TransRelEnd(current);
110 for (; tit != tit_end; ++tit) {
111 if (rHighAlph.Exists(tit->Ev)) {
112 rReachableEvents.Insert(tit->Ev);
113 // if high level event
114 if (rReachableEvents.Size() == rHighAlph.Size()) {
115 return;
116 }
117 }
118 // if low level event and not already in done set
119 else if (! done.Exists(tit->X2)) {
120 todo.push(tit->X2);
121 done.Insert(tit->X2);
122 }
123 }
124 }
125}
126
127
128// LocalCoaccessibleReach(rRevTransRel, rHighAlph, lowState, rCoaccessibleReach)
129void LocalCoaccessibleReach(const TransSetX2EvX1& rRevTransRel,
130 const EventSet& rHighAlph, Idx lowState, StateSet& rCoaccessibleReach) {
131 // helpers:
132 // iterators
135 // todo list
136 std::stack<Idx> todo;
137
138 // algorithm:
139 todo.push(lowState);
140 rCoaccessibleReach.Insert(lowState);
141 while (! todo.empty()) {
142 const Idx current = todo.top();
143 todo.pop();
144 tit = rRevTransRel.BeginByX2(current);
145 tit_end = rRevTransRel.EndByX2(current);
146 for (; tit != tit_end; ++tit) {
147 // if high level event skip transition
148 if (rHighAlph.Exists(tit->Ev)) {
149 continue;
150 }
151 // if predecessor notin rCoaccessibleReach set
152 else if (! rCoaccessibleReach.Exists(tit->X1)) {
153 todo.push(tit->X1);
154 rCoaccessibleReach.Insert(tit->X1);
155 }
156 }
157 }
158}
159
160// LocalAccessibleReach(rLowGen, rHighAlph, lowState, rAccessibleReach
161void LocalAccessibleReach(const Generator& rLowGen, const EventSet& rHighAlph,
162 Idx lowState, StateSet& rAccessibleReach) {
163 // helpers:
164 // iterators
166 TransSet::Iterator tit_end;
167 // todo list
168 std::stack<Idx> todo;
169
170 // algorithm:
171 todo.push(lowState);
172 rAccessibleReach.Insert(lowState);
173 while (! todo.empty()) {
174 const Idx current = todo.top();
175 todo.pop();
176 tit = rLowGen.TransRelBegin(current);
177 tit_end = rLowGen.TransRelEnd(current);
178 for (; tit != tit_end; ++tit) {
179 // if high level event skip transition
180 if (rHighAlph.Exists(tit->Ev)) {
181 continue;
182 }
183 // if successor not in rAccessibleReach set
184 if (! rAccessibleReach.Exists(tit->X2)) {
185 todo.push(tit->X2);
186 rAccessibleReach.Insert(tit->X2);
187 }
188 }
189 }
190}
191
192} // namespace faudes
#define FD_DF(message)
virtual std::string Str(const Idx &rIndex) const
bool Exists(const Idx &rIndex) const
virtual std::string Str(const Idx &rIndex) const
bool Insert(const Idx &rIndex)
Iterator BeginByX2(Idx x2) const
Iterator EndByX2(Idx x2) const
TransSet::Iterator TransRelBegin(void) const
EventSet NewEventSet(void) const
TransSet::Iterator TransRelEnd(void) const
bool Exists(const T &rElem) const
virtual void Clear(void)
Idx Size(void) const
uint32_t Idx
EventSet ReachableEvents(const Generator &rLowGen, const EventSet &rHighAlph, Idx lowState)
StateSet LowExitStates(const Generator &rLowGen, const EventSet &rHighAlph, const std::map< Idx, StateSet > &rEntryStatesMap, const TransSetX2EvX1 &rLowRevTransRel, Idx highState)
void LocalCoaccessibleReach(const TransSetX2EvX1 &rRevTransRel, const EventSet &rHighAlph, Idx lowState, StateSet &rCoaccessibleReach)
void LocalAccessibleReach(const Generator &rLowGen, const EventSet &rHighAlph, Idx lowState, StateSet &rAccessibleReach)

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