|
libFAUDES
Sections
Index
|
op_obserververification.cppGo to the documentation of this file.00001 /** @file op_obserververification.cpp 00002 00003 Methods to verify the obsrver condition for natural projections. 00004 The observer condition is, e.g., defined in 00005 K. C. Wong and W. M. Wonham, “Hierarchical control of discrete-event 00006 systems,” Discrete Event Dynamic Systems: Theory and Applications, 1996. 00007 In addition, methods to verify output control consistency (OCC) and 00008 local control consistency (LCC) are provided. See for example 00009 K. Schmidt and C. Breindl, "On Maximal Permissiveness of Hierarchical and Modular Supervisory 00010 Control Approaches for Discrete Event Systems," Workshop on Discrete Event Systems, 2008. 00011 */ 00012 00013 /* FAU Discrete Event Systems Library (libfaudes) 00014 00015 Copyright (C) 2006 Bernd Opitz 00016 Exclusive copyright is granted to Klaus Schmidt 00017 00018 This library is free software; you can redistribute it and/or 00019 modify it under the terms of the GNU Lesser General Public 00020 License as published by the Free Software Foundation; either 00021 version 2.1 of the License, or (at your option) any later version. 00022 00023 This library is distributed in the hope that it will be useful, 00024 but WITHOUT ANY WARRANTY; without even the implied warranty of 00025 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00026 Lesser General Public License for more details. 00027 00028 You should have received a copy of the GNU Lesser General Public 00029 License along with this library; if not, write to the Free Software 00030 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00031 #include "op_obserververification.h" 00032 00033 00034 using namespace std; 00035 00036 namespace faudes { 00037 00038 bool IsObs(const Generator& rLowGen, const EventSet& rHighAlph){ 00039 OP_DF("IsObs(" << rLowGen.Name() << "," << rHighAlph.Name() << ")"); 00040 // Initialization of variables 00041 EventSet newHighAlph = rHighAlph; 00042 EventSet controllableEvents; 00043 map<Transition,Idx> mapChangedTrans; 00044 Generator genDyn(rLowGen); 00045 map<Transition,Transition> mapChangedTransReverse; 00046 vector<Idx> newPartitions; 00047 map<Idx,Idx> mapStateToPartition; 00048 map<Idx, EventSet> mapRelabeledEvents; 00049 // One step of the observer algorithm: A dynamic system is computed that fulfills the one-step observer condition. 00050 // if the result is equal to the original generator, then the natural projection on the high-level alphabet fulfills the observer property 00051 calculateDynamicSystemClosedObs(rLowGen, newHighAlph, genDyn); 00052 calculateDynamicSystemObs(rLowGen, newHighAlph, genDyn); 00053 Generator genPart; 00054 // compute coarsest quasi-congruence on the dynamic system 00055 calcBisimulation(genDyn, mapStateToPartition, genPart, newPartitions); 00056 // Extend the high-level alphabet according to the algorithm of Lei 00057 ExtendHighAlphabet(rLowGen, newHighAlph, mapStateToPartition); 00058 // return the result of the event extension 00059 return newHighAlph == rHighAlph; 00060 00061 } 00062 00063 bool IsMSA(const Generator& rLowGen, const EventSet& rHighAlph){ 00064 OP_DF("IsMSA(" << rLowGen.Name() << "," << rHighAlph.Name() << ")"); 00065 // Initialization of variables 00066 EventSet newHighAlph = rHighAlph; 00067 EventSet controllableEvents; 00068 map<Transition,Idx> mapChangedTrans; 00069 Generator genDyn(rLowGen); 00070 map<Transition,Transition> mapChangedTransReverse; 00071 vector<Idx> newPartitions; 00072 map<Idx,Idx> mapStateToPartition; 00073 map<Idx, EventSet> mapRelabeledEvents; 00074 // One step of the observer algorithm: A dynamic system is computed that fulfills the one-step observer condition. 00075 // if the result is equal to the original generator, then the natural projection on the high-level alphabet fulfills the observer property 00076 calculateDynamicSystemClosedObs(rLowGen, newHighAlph, genDyn); 00077 calculateDynamicSystemMSA(rLowGen, newHighAlph, genDyn); 00078 Generator genPart; 00079 // compute coarsest quasi-congruence on the dynamic system 00080 calcBisimulation(genDyn, mapStateToPartition, genPart, newPartitions); 00081 // Extend the high-level alphabet according to the algorithm of Lei 00082 ExtendHighAlphabet(rLowGen, newHighAlph, mapStateToPartition); 00083 // return the result of the event extension 00084 return newHighAlph == rHighAlph; 00085 00086 } 00087 00088 bool IsOCC(const cGenerator& rLowGen, const EventSet& rHighAlph){ 00089 OP_DF("IsOCC(" << rLowGen.Name() << "," << rHighAlph.Name() << ")"); 00090 EventSet controllableEvents = rLowGen.ControllableEvents(); 00091 // call the function that implements the algorithm 00092 return IsOCC(rLowGen, controllableEvents, rHighAlph); 00093 } 00094 00095 bool IsOCC(const Generator& rLowGen, const EventSet& rControllableEvents, const EventSet& rHighAlph){ 00096 OP_DF("IsOCC(" << rLowGen.Name() << "," << rHighAlph.Name() << ")"); 00097 //helpers: 00098 StateSet::Iterator stIt, stEndIt; 00099 stIt = rLowGen.StatesBegin(); 00100 stEndIt = rLowGen.StatesEnd(); 00101 TransSet::Iterator tIt, tEndIt; 00102 // iteration over all states of rLowGen. If there is an uncontrollable feasible high-level event, backward reachability is conducted to determine if OCC holds. 00103 for( ; stIt != stEndIt; stIt++){ 00104 tIt = rLowGen.TransRelBegin(*stIt); 00105 tEndIt = rLowGen.TransRelEnd(*stIt); 00106 for( ; tIt != tEndIt; tIt++){ 00107 if(rHighAlph.Exists(tIt->Ev) && !rControllableEvents.Exists(tIt->Ev) ){ 00108 // check if all local backward paths are uncontrollable 00109 bool uncontrollable = backwardVerificationOCC(rLowGen, rControllableEvents, rHighAlph, *stIt); 00110 // if not all paths are uncontrollable, OCC is violated 00111 if(uncontrollable == false) 00112 return false; 00113 // otherwise, go to the next state 00114 else 00115 break; 00116 } 00117 } 00118 } 00119 return true; 00120 } 00121 00122 bool backwardVerificationOCC(const Generator& rLowGen, const EventSet& rControllableEvents, const EventSet& rHighAlph, Idx currentState){ 00123 OP_DF("backwardVerificationOCC(" << rLowGen.Name() << "," << rControllableEvents.Name() << "," << rHighAlph.Name() << "," << currentState << ")"); 00124 // reverse transition relation 00125 TransSetX2EvX1 tset_X2EvX1; 00126 rLowGen.TransRel(tset_X2EvX1); 00127 TransSetX2EvX1::Iterator tsIt, tsEndIt; 00128 // todo list 00129 std::stack<Idx> todo; 00130 // algorithm: the locally backwards reachable states from current staet are 00131 // evaluated. If a controllable event is found, OCC is violated. 00132 StateSet doneStates; 00133 doneStates.Insert(currentState); 00134 todo.push(currentState); 00135 // the local reachability is evaluated until no new state is found 00136 while( !todo.empty() ){ 00137 const Idx current = todo.top(); 00138 todo.pop(); 00139 tsIt = tset_X2EvX1.BeginByX2(current); 00140 tsEndIt = tset_X2EvX1.EndByX2(current); 00141 for(; tsIt != tsEndIt; tsIt++){ 00142 // if the current transition is labeled with a high-level evnet 00143 // it is skipped 00144 if(rHighAlph.Exists(tsIt->Ev) ) 00145 continue; 00146 // if the current transition is controllable, OCC is violated 00147 else if( rControllableEvents.Exists(tsIt->Ev) ) 00148 return false; 00149 else if( !doneStates.Exists(tsIt->X1) ){ 00150 todo.push(tsIt->X1); 00151 doneStates.Insert(tsIt->X1); 00152 } 00153 } 00154 } 00155 return true; 00156 } 00157 00158 00159 bool IsLCC(const cGenerator& rLowGen, const EventSet& rHighAlph){ 00160 OP_DF("IsLCC(" << rLowGen.Name() << "," << rHighAlph.Name() << ")"); 00161 EventSet controllableEvents = rLowGen.ControllableEvents(); 00162 // call the function that implements the algorithm 00163 return IsLCC(rLowGen, controllableEvents, rHighAlph); 00164 } 00165 00166 bool IsLCC(const Generator& rLowGen, const EventSet& rControllableEvents, const EventSet& rHighAlph){ 00167 OP_DF("IsLCC(" << rLowGen.Name() << "," << rHighAlph.Name() << ")"); 00168 // reverse transition relation 00169 TransSetX2EvX1 tset_X2EvX1; 00170 rLowGen.TransRel(tset_X2EvX1); 00171 //helpers: 00172 StateSet::Iterator stIt, stEndIt; 00173 stIt = rLowGen.StatesBegin(); 00174 stEndIt = rLowGen.StatesEnd(); 00175 TransSet::Iterator tIt, tEndIt; 00176 StateSet doneStates; 00177 map<Idx, bool> localStatesMap; 00178 map<Idx, bool>::const_iterator lsIt, lsEndIt; 00179 // iteration over all states of rLowGen. If there is an uncontrollable feasible high-level event, backward reachability is conducted to determine if LCC holds. 00180 for( ; stIt != stEndIt; stIt++){ 00181 tIt = rLowGen.TransRelBegin(*stIt); 00182 tEndIt = rLowGen.TransRelEnd(*stIt); 00183 for( ; tIt != tEndIt; tIt++){ 00184 if(rHighAlph.Exists(tIt->Ev) && !rControllableEvents.Exists(tIt->Ev) ){ 00185 doneStates.Clear(); 00186 localStatesMap.clear(); 00187 localStatesMap[*stIt] = false; 00188 doneStates.Insert(*stIt); 00189 // check if for all backward reachable states, a local uncontrollable backward paths exists 00190 backwardVerificationLCC(tset_X2EvX1, rControllableEvents, rHighAlph, *stIt, *stIt, false, localStatesMap, doneStates); 00191 // if for some state, all paths are controllable, LCC is violated 00192 lsIt = localStatesMap.begin(); 00193 lsEndIt = localStatesMap.end(); 00194 for( ; lsIt != lsEndIt; lsIt++){ 00195 // if there is a state with only controllable paths, LCC is violated 00196 if(lsIt->second == true) 00197 return false; 00198 } 00199 // the evaluation for the current state is finished 00200 break; 00201 } 00202 } 00203 } 00204 return true; 00205 } 00206 00207 00208 void backwardVerificationLCC(const TransSetX2EvX1& rTransSetX2EvX1, const EventSet& rControllableEvents, const EventSet& rHighAlph, Idx exitState, Idx currentState, bool controllablePath, map<Idx, bool>& rLocalStatesMap, StateSet& rDoneStates){ 00209 OP_DF("backwardVerificationLCC(rTransSetX2EvX1," << rControllableEvents.Name() << "," << rHighAlph.Name() << "," << exitState << "," << currentState << "," << controllablePath << ",rExitLocalStatesMap, rDoneStates)"); 00210 // go along all backward transitions. Discard the goal state if it is reached via a high-level event or if it is in the rDoneStates and 00211 // the controllability properties of the state do not change on the current path 00212 00213 // helpers 00214 TransSetX2EvX1::Iterator tsIt, tsEndIt; 00215 tsIt = rTransSetX2EvX1.BeginByX2(currentState); 00216 tsEndIt = rTransSetX2EvX1.EndByX2(currentState); 00217 bool currentControllablePath; 00218 // we iterate over all backward transitions of the currentState to establish backward reachability 00219 for( ;tsIt != tsEndIt; tsIt++){ 00220 // states reachable via a high-level event are not in the local backward reach and the controllability property of the current exitState does not change 00221 if( !rHighAlph.Exists(tsIt->Ev) && tsIt->X1 != exitState){ 00222 // if the state has not been visited, yet, the controllability of the current path are set in the rExitLocalStatesMap 00223 if( !rDoneStates.Exists(tsIt->X1) ){ 00224 rDoneStates.Insert(tsIt->X1); 00225 // the path is uncontrollable if the current transition has an uncontrollable event or the path was already uncontrollable 00226 currentControllablePath = rControllableEvents.Exists(tsIt->Ev) || controllablePath; 00227 rLocalStatesMap[tsIt->X1] = currentControllablePath; 00228 // as the state has not been visited, yet, it is subject to a new backward reachability 00229 backwardVerificationLCC(rTransSetX2EvX1, rControllableEvents, rHighAlph, exitState, tsIt->X1, currentControllablePath, rLocalStatesMap, rDoneStates); 00230 } 00231 else{ // for an existing state, the controllability value can change from controllable to uncontrollable (if 00232 // a new uncontrollable path has been found). It is important to note, that the LCC condition implies that 00233 // if there is one uncontrollable path, then the state is flagged uncontrollable except for the case of the 00234 // given exitState that is always uncontrollable 00235 currentControllablePath = rControllableEvents.Exists(tsIt->Ev) || controllablePath; 00236 if(rLocalStatesMap[tsIt->X1] != currentControllablePath && currentControllablePath == false){ 00237 rLocalStatesMap[tsIt->X1] = false; 00238 // as the controllabiity attribute of the current state changed it is subject to a new backward reachability 00239 backwardVerificationLCC(rTransSetX2EvX1, rControllableEvents, rHighAlph, exitState, tsIt->X1, false, rLocalStatesMap, rDoneStates); 00240 } 00241 } 00242 } 00243 } 00244 } 00245 00246 00247 00248 00249 00250 00251 }// namespace faudes |
libFAUDES 2.16b --- 2010-9-8 --- c++ source docu by doxygen 1.6.3