obs_local_observation_consistency.cpp
Go to the documentation of this file.
1/** @file obs_local_observation_consistency.cpp Supervisor Reduction */
2
3/* FAU Discrete Event Systems Library (libfaudes)
4
5 Copyright (C) 2010 Klaus Schmidt
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
20
21
23
24
25namespace faudes {
26
27
28
29
30/*
31***************************************************************************************
32***************************************************************************************
33 Implementation
34***************************************************************************************
35***************************************************************************************
36*/
37
38
39// SupReduce(rPlantGen, rSupGen, rReducedSup)
40bool LocalObservationConsistency(const System& rPlantGen, const System& rSpecGen, const EventSet& rHighAlph, const EventSet& rObsAlph) {
41 FD_DF("LocalObservationConsistency...");
42
43 // CONSISTENCY CHECK:
44
45 // plant and spec must be deterministic
46 bool plant_det = rPlantGen.IsDeterministic();
47 bool sup_det = rSpecGen.IsDeterministic();
48
49 if ((plant_det == false) && (sup_det == true)) {
50 std::stringstream errstr;
51 errstr << "Plant generator must be deterministic, " << "but is nondeterministic";
52 throw Exception("LocalObservationConsistency", errstr.str(), 201);
53 }
54 else if ((plant_det == true) && (sup_det == false)) {
55 std::stringstream errstr;
56 errstr << "Specification generator must be deterministic, " << "but is nondeterministic";
57 throw Exception("LocalObservationConsistency", errstr.str(), 203);
58 }
59 else if ((plant_det == false) && (sup_det == false)) {
60 std::stringstream errstr;
61 errstr << "Plant and specification generator must be deterministic, "
62 << "but both are nondeterministic";
63 throw Exception("LocalObservationConsistency", errstr.str(), 204);
64 }
65 // Compute the parallel composition of abstraction and specification
66 System parallelGen;
67 aParallel(rPlantGen,rSpecGen,parallelGen);
68 System highGen;
69 if(!IsObs(parallelGen,rHighAlph) )
70 return false;
71
72 aProject(parallelGen,rHighAlph,highGen);
73 //highGen.GraphWrite("data/highGen.png");
74 aProjectNonDet(highGen,rHighAlph*rObsAlph);
75 // make projected generator deterministic and record the state tuples
76 std::vector<StateSet> powerStates;
77 std::vector<Idx> detStates;
78 System detGen;
79 Deterministic(highGen,powerStates,detStates,detGen);
80 //detGen.GraphWrite("data/detGen.png");
81 // Go through all power states and check the feasible controllable events
82 std::vector<StateSet>::const_iterator pIt, pEndIt;
83 pIt = powerStates.begin();
84 pEndIt = powerStates.end();
85 for(; pIt != pEndIt; pIt++){// go through all power states
86 StateSet::Iterator stIt;
87 // Determine the controllable events that should be present in each state
88 stIt = pIt->Begin();
89 //std::cout << "State: " << *stIt;
90 EventSet controllableEvents;
91 TransSet::Iterator tIt = highGen.TransRelBegin(*stIt);
92 for( ; tIt != highGen.TransRelEnd(*stIt); tIt++){
93 //std::cout << " event " << highGen.EventName(tIt->Ev);
94 if(highGen.Controllable(tIt->Ev) )
95 controllableEvents.Insert(tIt->Ev);
96 }
97 stIt++;
98 EventSet otherControllableEvents;
99 for(; stIt != pIt->End(); stIt++ ){// go through all remaining states and compare
100 //std::cout << "State: " << *stIt;
101 otherControllableEvents.Clear();
102 tIt = highGen.TransRelBegin(*stIt);
103 for( ; tIt != highGen.TransRelEnd(*stIt); tIt++){
104 //std::cout << " event " << highGen.EventName(tIt->Ev);
105 if(highGen.Controllable(tIt->Ev) )
106 otherControllableEvents.Insert(tIt->Ev);
107 }
108// // //std::cout << std::endl;
109 //controllableEvents.Write();
110 //otherControllableEvents.Write();
111 if(controllableEvents != otherControllableEvents)
112 return false;
113 }
114 }
115
116 return true;
117}
118
119} // name space
#define FD_DF(message)
bool Insert(const Idx &rIndex)
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
bool Controllable(Idx index) const
TransSet::Iterator TransRelBegin(void) const
TransSet::Iterator TransRelEnd(void) const
bool IsDeterministic(void) const
virtual void Clear(void)
void aProjectNonDet(Generator &rGen, const EventSet &rProjectAlphabet)
void Deterministic(const Generator &rGen, Generator &rResGen)
void aParallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void aProject(const Generator &rGen, const EventSet &rProjectAlphabet, Generator &rResGen)
bool IsObs(const Generator &rLowGen, const EventSet &rHighAlph)
bool LocalObservationConsistency(const System &rPlantGen, const System &rSpecGen, const EventSet &rHighAlph, const EventSet &rObsAlph)

libFAUDES 2.34d --- 2026.03.11 --- c++ api documentaion by doxygen