00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "localgen.h"
00023
00024 namespace faudes {
00025
00026
00027 StateSet LowExitStates(const vGenerator& rLowGen, const EventSet& rHighAlph,
00028 const std::map<Idx,StateSet>& rEntryStatesMap, const TransSetX2EvX1& rLowRevTransRel,
00029 Idx highState) {
00030
00031 StateSet lo_exitstates;
00032
00033 LowExitStates(rHighAlph, rEntryStatesMap, rLowRevTransRel, highState, lo_exitstates);
00034
00035 return lo_exitstates;
00036 }
00037
00038
00039
00040 void LowExitStates(const EventSet& rHighAlph, const std::map<Idx,StateSet>& rEntryStatesMap,
00041 const TransSetX2EvX1& rLowRevTransRel, Idx highState, StateSet& rLowExitStates) {
00042 FD_DF("LowExitStates: computing low level exit states for high level"
00043 << " state " << rLowExitStates.Str(highState));
00044
00045 std::map<Idx,StateSet>::const_iterator esmap_it;
00046 StateSet::Iterator lit;
00047 TransSetX2EvX1::Iterator rtit;
00048 TransSetX2EvX1::Iterator rtit_end;
00049
00050 esmap_it = rEntryStatesMap.find(highState);
00051 #ifdef FAUDES_CHECKED
00052 if (esmap_it == rEntryStatesMap.end()) {
00053 std::stringstream errstr;
00054 errstr << "Hi level state " << rHighAlph.Str(highState)
00055 << " not found in entry states map";
00056 throw Exception("LowExitStates", errstr.str(), 502);
00057 }
00058 #endif
00059
00060 for (lit = esmap_it->second.Begin(); lit != esmap_it->second.End(); ++lit) {
00061 FD_DF("LowExitStates: current low level entry state "
00062 << rLowExitStates.Str(*lit));
00063 rtit = rLowRevTransRel.BeginByX2(*lit);
00064 rtit_end = rLowRevTransRel.EndByX2(*lit);
00065 for (; rtit != rtit_end; ++rtit) {
00066 if (rHighAlph.Exists(rtit->Ev)) {
00067 FD_DF("LowExitStates: found low level exit state "
00068 << rLowExitStates.Str(rtit->X1));
00069 rLowExitStates.Insert(rtit->X1);
00070 }
00071 }
00072 }
00073 }
00074
00075
00076 EventSet ReachableEvents(const vGenerator& rLowGen, const EventSet& rHighAlph,
00077 Idx lowState) {
00078
00079 EventSet reachable_events = rLowGen.NewEventSet();
00080
00081 ReachableEvents(rLowGen, rHighAlph, lowState, reachable_events);
00082
00083 return reachable_events;
00084 }
00085
00086
00087
00088 void ReachableEvents(const vGenerator& rLowGen, const EventSet& rHighAlph,
00089 Idx lowState, EventSet& rReachableEvents) {
00090
00091
00092 TransSet::Iterator tit;
00093 TransSet::Iterator tit_end;
00094
00095 std::stack<Idx> todo;
00096
00097 StateSet done;
00098
00099
00100 rReachableEvents.Clear();
00101
00102
00103 todo.push(lowState);
00104 done.Insert(lowState);
00105 while (! todo.empty()) {
00106 const Idx current = todo.top();
00107 todo.pop();
00108 tit = rLowGen.TransRelBegin(current);
00109 tit_end = rLowGen.TransRelEnd(current);
00110 for (; tit != tit_end; ++tit) {
00111 if (rHighAlph.Exists(tit->Ev)) {
00112 rReachableEvents.Insert(tit->Ev);
00113
00114 if (rReachableEvents.Size() == rHighAlph.Size()) {
00115 return;
00116 }
00117 }
00118
00119 else if (! done.Exists(tit->X2)) {
00120 todo.push(tit->X2);
00121 done.Insert(tit->X2);
00122 }
00123 }
00124 }
00125 }
00126
00127
00128
00129 void LocalCoaccessibleReach(const TransSetX2EvX1& rRevTransRel,
00130 const EventSet& rHighAlph, Idx lowState, StateSet& rCoaccessibleReach) {
00131
00132
00133 TransSetX2EvX1::Iterator tit;
00134 TransSetX2EvX1::Iterator tit_end;
00135
00136 std::stack<Idx> todo;
00137
00138
00139 todo.push(lowState);
00140 rCoaccessibleReach.Insert(lowState);
00141 while (! todo.empty()) {
00142 const Idx current = todo.top();
00143 todo.pop();
00144 tit = rRevTransRel.BeginByX2(current);
00145 tit_end = rRevTransRel.EndByX2(current);
00146 for (; tit != tit_end; ++tit) {
00147
00148 if (rHighAlph.Exists(tit->Ev)) {
00149 continue;
00150 }
00151
00152 else if (! rCoaccessibleReach.Exists(tit->X1)) {
00153 todo.push(tit->X1);
00154 rCoaccessibleReach.Insert(tit->X1);
00155 }
00156 }
00157 }
00158 }
00159
00160
00161 void LocalAccessibleReach(const vGenerator& rLowGen, const EventSet& rHighAlph,
00162 Idx lowState, StateSet& rAccessibleReach) {
00163
00164
00165 TransSet::Iterator tit;
00166 TransSet::Iterator tit_end;
00167
00168 std::stack<Idx> todo;
00169
00170
00171 todo.push(lowState);
00172 rAccessibleReach.Insert(lowState);
00173 while (! todo.empty()) {
00174 const Idx current = todo.top();
00175 todo.pop();
00176 tit = rLowGen.TransRelBegin(current);
00177 tit_end = rLowGen.TransRelEnd(current);
00178 for (; tit != tit_end; ++tit) {
00179
00180 if (rHighAlph.Exists(tit->Ev)) {
00181 continue;
00182 }
00183
00184 else if (! rAccessibleReach.Exists(tit->X2)) {
00185 todo.push(tit->X2);
00186 rAccessibleReach.Insert(tit->X2);
00187 }
00188 }
00189 }
00190 }
00191
00192 }