obs_local_observation_consistency.cppGo to the documentation of this file.00001 /** @file local_observation_consistency.cpp Supervisor Reduction */ 00002 00003 /* FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2010 Klaus Schmidt 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00020 00021 00022 #include "obs_local_observation_consistency.h" 00023 00024 00025 namespace faudes { 00026 00027 00028 00029 00030 /* 00031 *************************************************************************************** 00032 *************************************************************************************** 00033 Implementation 00034 *************************************************************************************** 00035 *************************************************************************************** 00036 */ 00037 00038 00039 // SupReduce(rPlantGen, rSupGen, rReducedSup) 00040 bool LocalObservationConsistency(const System& rPlantGen, const System& rSpecGen, const EventSet& rHighAlph, const EventSet& rObsAlph) { 00041 FD_DF("LocalObservationConsistency..."); 00042 00043 // CONSISTENCY CHECK: 00044 00045 // plant and spec must be deterministic 00046 bool plant_det = rPlantGen.IsDeterministic(); 00047 bool sup_det = rSpecGen.IsDeterministic(); 00048 00049 if ((plant_det == false) && (sup_det == true)) { 00050 std::stringstream errstr; 00051 errstr << "Plant generator must be deterministic, " << "but is nondeterministic"; 00052 throw Exception("LocalObservationConsistency", errstr.str(), 201); 00053 } 00054 else if ((plant_det == true) && (sup_det == false)) { 00055 std::stringstream errstr; 00056 errstr << "Specification generator must be deterministic, " << "but is nondeterministic"; 00057 throw Exception("LocalObservationConsistency", errstr.str(), 203); 00058 } 00059 else if ((plant_det == false) && (sup_det == false)) { 00060 std::stringstream errstr; 00061 errstr << "Plant and specification generator must be deterministic, " 00062 << "but both are nondeterministic"; 00063 throw Exception("LocalObservationConsistency", errstr.str(), 204); 00064 } 00065 // Compute the parallel composition of abstraction and specification 00066 System parallelGen; 00067 aParallel(rPlantGen,rSpecGen,parallelGen); 00068 System highGen; 00069 if(!IsObs(parallelGen,rHighAlph) ) 00070 return false; 00071 00072 aProject(parallelGen,rHighAlph,highGen); 00073 //highGen.GraphWrite("data/highGen.png"); 00074 aProjectNonDet(highGen,rHighAlph*rObsAlph); 00075 // make projected generator deterministic and record the state tuples 00076 std::vector<StateSet> powerStates; 00077 std::vector<Idx> detStates; 00078 System detGen; 00079 Deterministic(highGen,powerStates,detStates,detGen); 00080 //detGen.GraphWrite("data/detGen.png"); 00081 // Go through all power states and check the feasible controllable events 00082 std::vector<StateSet>::const_iterator pIt, pEndIt; 00083 pIt = powerStates.begin(); 00084 pEndIt = powerStates.end(); 00085 for(; pIt != pEndIt; pIt++){// go through all power states 00086 StateSet::Iterator stIt; 00087 // Determine the controllable events that should be present in each state 00088 stIt = pIt->Begin(); 00089 //std::cout << "State: " << *stIt; 00090 EventSet controllableEvents; 00091 TransSet::Iterator tIt = highGen.TransRelBegin(*stIt); 00092 for( ; tIt != highGen.TransRelEnd(*stIt); tIt++){ 00093 //std::cout << " event " << highGen.EventName(tIt->Ev); 00094 if(highGen.Controllable(tIt->Ev) ) 00095 controllableEvents.Insert(tIt->Ev); 00096 } 00097 stIt++; 00098 EventSet otherControllableEvents; 00099 for(; stIt != pIt->End(); stIt++ ){// go through all remaining states and compare 00100 //std::cout << "State: " << *stIt; 00101 otherControllableEvents.Clear(); 00102 tIt = highGen.TransRelBegin(*stIt); 00103 for( ; tIt != highGen.TransRelEnd(*stIt); tIt++){ 00104 //std::cout << " event " << highGen.EventName(tIt->Ev); 00105 if(highGen.Controllable(tIt->Ev) ) 00106 otherControllableEvents.Insert(tIt->Ev); 00107 } 00108 // // //std::cout << std::endl; 00109 //controllableEvents.Write(); 00110 //otherControllableEvents.Write(); 00111 if(controllableEvents != otherControllableEvents) 00112 return false; 00113 } 00114 } 00115 00116 return true; 00117 } 00118 00119 } // name space libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |