cfl_localgen.cppGo to the documentation of this file.00001 /** @file cfl_localgen.cpp Helper functions for projected generators */ 00002 00003 /* FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2006 Bernd Opitz 00006 Exclusive copyright is granted to Klaus Schmidt 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00021 00022 #include "cfl_localgen.h" 00023 00024 namespace faudes { 00025 00026 // LowExitStates(rHighAlph, rEntryStatesMap, rLowRevTransRel, highState) 00027 StateSet LowExitStates(const Generator& rLowGen, const EventSet& rHighAlph, 00028 const std::map<Idx,StateSet>& rEntryStatesMap, const TransSetX2EvX1& rLowRevTransRel, 00029 Idx highState) { 00030 // prepare result: 00031 StateSet lo_exitstates; 00032 // algorithm: 00033 LowExitStates(rHighAlph, rEntryStatesMap, rLowRevTransRel, highState, lo_exitstates); 00034 // return result: 00035 return lo_exitstates; 00036 } 00037 00038 00039 // LowExitStates(rHighAlph, rEntryStatesMap, rLowRevTransRel, highState, rLowExitStates) 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 // helpers: 00045 std::map<Idx,StateSet>::const_iterator esmap_it; 00046 StateSet::Iterator lit; 00047 TransSetX2EvX1::Iterator rtit; 00048 TransSetX2EvX1::Iterator rtit_end; 00049 // algorithm: 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 // find predecessor states of low_level entry states 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 // ReachableEvents(lo, rHighAlph, lowState) 00076 EventSet ReachableEvents(const Generator& rLowGen, const EventSet& rHighAlph, 00077 Idx lowState) { 00078 // prepare result: 00079 EventSet reachable_events = rLowGen.NewEventSet(); 00080 // algorithm: 00081 ReachableEvents(rLowGen, rHighAlph, lowState, reachable_events); 00082 // return result: 00083 return reachable_events; 00084 } 00085 00086 00087 // ReachableEvents(lo, rHighAlph, lowState, rReachableEvents) 00088 void ReachableEvents(const Generator& rLowGen, const EventSet& rHighAlph, 00089 Idx lowState, EventSet& rReachableEvents) { 00090 // helpers: 00091 // iterators 00092 TransSet::Iterator tit; 00093 TransSet::Iterator tit_end; 00094 // todo list 00095 std::stack<Idx> todo; 00096 // done set 00097 StateSet done; 00098 00099 // prepare result: 00100 rReachableEvents.Clear(); 00101 00102 // algorithm: 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 // if high level event 00114 if (rReachableEvents.Size() == rHighAlph.Size()) { 00115 return; 00116 } 00117 } 00118 // if low level event and not already in done set 00119 else if (! done.Exists(tit->X2)) { 00120 todo.push(tit->X2); 00121 done.Insert(tit->X2); 00122 } 00123 } 00124 } 00125 } 00126 00127 00128 // LocalCoaccessibleReach(rRevTransRel, rHighAlph, lowState, rCoaccessibleReach) 00129 void LocalCoaccessibleReach(const TransSetX2EvX1& rRevTransRel, 00130 const EventSet& rHighAlph, Idx lowState, StateSet& rCoaccessibleReach) { 00131 // helpers: 00132 // iterators 00133 TransSetX2EvX1::Iterator tit; 00134 TransSetX2EvX1::Iterator tit_end; 00135 // todo list 00136 std::stack<Idx> todo; 00137 00138 // algorithm: 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 // if high level event skip transition 00148 if (rHighAlph.Exists(tit->Ev)) { 00149 continue; 00150 } 00151 // if predecessor notin rCoaccessibleReach set 00152 else if (! rCoaccessibleReach.Exists(tit->X1)) { 00153 todo.push(tit->X1); 00154 rCoaccessibleReach.Insert(tit->X1); 00155 } 00156 } 00157 } 00158 } 00159 00160 // LocalAccessibleReach(rLowGen, rHighAlph, lowState, rAccessibleReach 00161 void LocalAccessibleReach(const Generator& rLowGen, const EventSet& rHighAlph, 00162 Idx lowState, StateSet& rAccessibleReach) { 00163 // helpers: 00164 // iterators 00165 TransSet::Iterator tit; 00166 TransSet::Iterator tit_end; 00167 // todo list 00168 std::stack<Idx> todo; 00169 00170 // algorithm: 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 // if high level event skip transition 00180 if (rHighAlph.Exists(tit->Ev)) { 00181 continue; 00182 } 00183 // if successor not in rAccessibleReach set 00184 if (! rAccessibleReach.Exists(tit->X2)) { 00185 todo.push(tit->X2); 00186 rAccessibleReach.Insert(tit->X2); 00187 } 00188 } 00189 } 00190 } 00191 00192 } // namespace faudes libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |