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 
25 namespace faudes {
26 
27 
28 
29 
30 /*
31 ***************************************************************************************
32 ***************************************************************************************
33  Implementation
34 ***************************************************************************************
35 ***************************************************************************************
36 */
37 
38 
39 // SupReduce(rPlantGen, rSupGen, rReducedSup)
40 bool 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)
Debug: optional report on user functions.
Faudes exception class.
Set of indices with symbolic names.
Definition: cfl_nameset.h:69
bool Insert(const Idx &rIndex)
Add an element by index.
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
Iterator on transition.
Definition: cfl_transset.h:273
Generator with controllability attributes.
bool Controllable(Idx index) const
Is event controllable (by index)
TransSet::Iterator TransRelBegin(void) const
Iterator to Begin() of transition relation.
TransSet::Iterator TransRelEnd(void) const
Iterator to End() of transition relation.
bool IsDeterministic(void) const
Check if generator is deterministic.
virtual void Clear(void)
Clear all set.
Definition: cfl_baseset.h:1911
void aProjectNonDet(Generator &rGen, const EventSet &rProjectAlphabet)
Language projection.
void Deterministic(const Generator &rGen, Generator &rResGen)
Make generator deterministic.
void aParallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Parallel composition.
void aProject(const Generator &rGen, const EventSet &rProjectAlphabet, Generator &rResGen)
Deterministic projection.
bool IsObs(const Generator &rLowGen, const EventSet &rHighAlph)
Verification of the natural observer property.
libFAUDES resides within the namespace faudes.
bool LocalObservationConsistency(const System &rPlantGen, const System &rSpecGen, const EventSet &rHighAlph, const EventSet &rObsAlph)
Supervisor Reduction algorithm.
Local Observation Consistency.

libFAUDES 2.32f --- 2024.12.22 --- c++ api documentaion by doxygen