diag_4_decentralizeddiagnosis.cpp
Go to the documentation of this file.
1 /** @file diag_4_decentralizeddiagnosis.cpp
2 Illustrate decentralized diagnosability test and synthesis.
3 @ingroup Tutorials
4 @include diag_4_decentralizeddiagnosis.cpp
5 */
6 
7 #include "libfaudes.h"
8 
9 using namespace faudes;
10 
11 
12 int main(void) {
13 
14  // Declare common variables
15  System plant, spec;
16  EventSet *alph1, *alph2;
17  EventSetVector alphVector;
18  std::string report;
19 
20  // **********************************************************************
21  //
22  // Decentralized Language-Diagnosability Verification (condition is not fulfilled)
23  //
24 
25  // Report to console
26  std::cout << "################################\n";
27  std::cout << "# decentralized language-diagnosability (system 1)\n";
28  std::cout << "# a) read data \n";
29 
30  // Read subsystems and associated specifications and abstraction alphabets from files
31  plant = System("data/diag_system_4_decentralized1.gen");
32  spec = System("data/diag_specification_4_decentralized1.gen");
33 
34  // Write subsystems and specifications to gen files (for html docu)
35  plant.Write("tmp_diag_system_4_decentralized1.gen");
36  spec.Write("tmp_diag_specification_4_decentralized1.gen");
37 
38  // Write subsystems and specifications to png files (for inspection)
39  plant.GraphWrite("tmp_demo_system_4_decentralized1.png");
40  spec.GraphWrite("tmp_demo_specification_4_decentralized1.png");
41 
42  // Relevant abstractions for the modular diagnosability verification (for HTML docu)
43 
44  alph1 = new EventSet("data/diag_obsAlph_4_decentralized1_1.alph");
45  alph2 = new EventSet("data/diag_obsAlph_4_decentralized1_2.alph");
46  alphVector.Append(alph1 );
47  alphVector.Append(alph2 );
48 
49 
50  // Report to console
51  std::cout << "# b) run decentralized diagnosability test (expect result FAIL)\n";
52 
53  // Test for modular diagnosability of the overall system
54  bool ok=IsCoDiagnosable(plant, spec, alphVector);
55  if(ok) {
56  std::cout << "The overall system G is co-diagnosable with respect to overall specification K." << std::endl;
57  } else {
58  std::cout << "The overall system G is not co-diagnosable with respect to overall specification K." << std::endl;
59  }
60  // Compute local decentralzed diagnosers for the example
61  GeneratorVector diagVector;
62  DecentralizedDiagnoser(plant,spec,alphVector,diagVector);
63  // Write diagnosers to .gen file (for html docu)
64  diagVector.At(0).Write("tmp_diag_diagnoser_4_decentralized1_1.gen");
65  diagVector.At(1).Write("tmp_diag_diagnoser_4_decentralized1_2.gen");
66  // Write diagnosers to png (for inspection)
67  diagVector.At(0).GraphWrite("tmp_demo_diagnoser_4_decentralized1_1.png");
68  diagVector.At(1).GraphWrite("tmp_demo_diagnoser_4_decentralized1_2.png");
69 
70  // Record test case
71  FAUDES_TEST_DUMP("decentralized 1",ok);
72 
73  // **********************************************************************
74  //
75  // Decentralized Language-Diagnosability Verification (condition is fulfilled)
76  //
77  // Report to console
78  std::cout << "################################\n";
79  std::cout << "# decentralized language-diagnosability (system 2)\n";
80  std::cout << "# a) read data \n";
81 
82  // Read subsystems and associated specifications and abstraction alphabets from files
83  plant = System("data/diag_system_4_decentralized2.gen");
84  spec = System("data/diag_specification_4_decentralized2.gen");
85 
86  // Write subsystems and specifications to gen files (for html docu)
87  plant.Write("tmp_diag_system_4_decentralized2.gen");
88  spec.Write("tmp_diag_specification_4_decentralized2.gen");
89 
90  // Write subsystems and specifications to png files (for inspection)
91  plant.GraphWrite("tmp_demo_system_4_decentralized2.png");
92  spec.GraphWrite("tmp_demo_specification_4_decentralized2.png");
93 
94  // Relevant abstractions for the modular diagnosability verification (for HTML docu)
95  alphVector.Clear();
96  alph1 = new EventSet("data/diag_obsAlph_4_decentralized2_1.alph");
97  alph2 = new EventSet("data/diag_obsAlph_4_decentralized2_2.alph");
98  alphVector.Append(alph1 );
99  alphVector.Append(alph2 );
100 
101  // Report to console
102  std::cout << "# b) run decentralized diagnosability test (expect result FAIL)\n";
103 
104  // Test for modular diagnosability of the overall system
105  ok=IsCoDiagnosable(plant, spec, alphVector);
106  if(ok) {
107  std::cout << "The overall system G is co-diagnosable with respect to overall specification K." << std::endl;
108  std::cout << report << std::endl;
109  } else {
110  std::cout << "The overall system G is not co-diagnosable with respect to overall specification K." << std::endl;
111  std::cout << "The overall system G is not co-diagnosable with respect to overall specification K." << std::endl;
112  std::cout << report << std::endl;
113  }
114  diagVector.Clear();
115  // Compute decentralized diagnosers for the local sites
116  DecentralizedDiagnoser(plant,spec,alphVector,diagVector);
117  // Write diagnosers to .gen file (for html docu)
118  diagVector.At(0).Write("tmp_diag_diagnoser_4_decentralized2_1.gen");
119  diagVector.At(1).Write("tmp_diag_diagnoser_4_decentralized2_2.gen");
120  // Write diagnosers to png (for inspection)
121  diagVector.At(0).GraphWrite("tmp_demo_diagnoser_4_decentralized2_1.png");
122  diagVector.At(1).GraphWrite("tmp_demo_diagnoser_4_decentralized2_2.png");
123  // Record test case
124  FAUDES_TEST_DUMP("decentralized 2",ok);
125 
126  // **********************************************************************
127  //
128  // Decentralized Language-Diagnosability Verification (condition is not fulfilled)
129  //
130  // Report to console
131  std::cout << "################################\n";
132  std::cout << "# decentralized language-diagnosability (system 3)\n";
133  std::cout << "# a) read data \n";
134 
135  // Read subsystems and associated specifications and abstraction alphabets from files
136  plant = System("data/diag_system_2_language.gen");
137  spec = System("data/diag_specification_2_language.gen");
138 
139  // Write subsystems and specifications to png files (for inspection)
140  plant.GraphWrite("tmp_demo_system_2_language.png");
141  spec.GraphWrite("tmp_demo_specification_2_language.png");
142 
143  // Relevant abstractions for the modular diagnosability verification (for HTML docu)
144  alphVector.Clear();
145  alph1 = new EventSet;
146  alph1->Insert("alpha");
147  alph1->Insert("beta");
148  alph2 = new EventSet();
149  alph2->Insert("alpha");
150  alphVector.Append(alph1 );
151  alphVector.Append(alph2 );
152 
153  // Report to console
154  std::cout << "# b) run decentralized diagnosability test (expect result FAIL)\n";
155 
156  // Test for modular diagnosability of the overall system
157  ok=IsCoDiagnosable(plant, spec, alphVector);
158  if(ok) {
159  std::cout << "The overall system G is co-diagnosable with respect to overall specification K." << std::endl;
160  std::cout << report << std::endl;
161  } else {
162  std::cout << "The overall system G is not co-diagnosable with respect to overall specification K." << std::endl;
163  std::cout << report << std::endl;
164  }
165 
166  // Record test case
167  FAUDES_TEST_DUMP("decentralized 3",ok);
168 
169 
170  // **********************************************************************
171  //
172  // Decentralized Language-Diagnosability Verification for Application Example (condition is fulfilled)
173  //
174  // Report to console
175  std::cout << "################################\n";
176  std::cout << "# decentralized language-diagnosability (system sf/c1)\n";
177  std::cout << "# a) read data \n";
178 
179  // Read subsystems and associated specifications and abstraction alphabets from files
180  System sf,c1,sfc1Spec;
181  sf = System("data/diag_system_4_decentralized_sf.gen");
182  c1 = System("data/diag_system_4_decentralized_c1.gen");
183 
184  // Write generators (for html docu)
185  sf.Write("tmp_diag_system_4_decentralized_sf.gen");
186  c1.Write("tmp_diag_system_4_decentralized_c1.gen");
187  // Write generators (for inspection)
188  sf.GraphWrite("tmp_demo_system_4_decentralized_sf.png");
189  c1.GraphWrite("tmp_demo_system_4_decentralized_c1.png");
190  sfc1Spec = Generator("data/diag_specification_4_decentralized_sfc1.gen");
191  aParallel(sf,c1,plant);
192  aParallel(plant,sfc1Spec,spec);
193 
194  // Write subsystems and specifications to png files (for inspection)
195  plant.GraphWrite("tmp_demo_system_4_decentralized_sfc1.png");
196  spec.GraphWrite("tmp_demo_specification_4_decentralized_sfc1.png");
197 
198  // Observable events for the system components
199  alphVector.Clear();
200  alph1 = new EventSet();
201  *alph1 = plant.ObservableEvents() * sf.Alphabet();
202  alph2 = new EventSet();
203  *alph2 = plant.ObservableEvents() * c1.Alphabet();
204  alphVector.Append(alph1 );
205  alphVector.Append(alph2 );
206 
207  // Report to console
208  std::cout << "# b) run decentralized diagnosability test (expect result PASS)\n";
209 
210  // Test for modular diagnosability of the overall system
211  ok=IsCoDiagnosable(plant, spec, alphVector);
212  if(ok) {
213  std::cout << "The overall system G is co-diagnosable with respect to overall specification K." << std::endl;
214  std::cout << report << std::endl;
215  } else {
216  std::cout << "The overall system G is not co-diagnosable with respect to overall specification K." << std::endl;
217  std::cout << report << std::endl;
218  }
219  // Compute decentralized diagnosers for the local sites
220  SystemVector plantVector;
221  plantVector.Append(&sf);
222  plantVector.Append(&c1);
223  diagVector.Clear();
224  DecentralizedModularDiagnoser(plantVector,spec,diagVector);
225  // Write diagnosers to .gen file (for html docu)
226  diagVector.At(0).Write("tmp_diag_diagnoser_4_decentralized_sf.gen");
227  diagVector.At(1).Write("tmp_diag_diagnoser_4_decentralized_c1.gen");
228  // Write diagnosers to png (for inspection)
229  diagVector.At(0).GraphWrite("tmp_demo_diagnoser_4_decentralized_sf.png");
230  diagVector.At(1).GraphWrite("tmp_demo_diagnoser_4_decentralized_c1.png");
231  // Record test case
232  FAUDES_TEST_DUMP("decentralized sf/c1",ok);
233 
234 
235  // // **********************************************************************
236  //
237  // Abstraction-based Decentralized Language-Diagnosability Verification for Application Example (condition is fulfilled)
238  //
239  // Report to console
240  std::cout << "################################\n";
241  std::cout << "# Abstraction-based decentralized language-diagnosability (system sf/c1)\n";
242  std::cout << "# a) read data \n";
243 
244  // Compute abstracted system components and verify the loop-preserving observer condition
245  System sfAbst, c1Abst;
246  EventSet abstAlph;
247  abstAlph.Read("data/diag_abstAlph_4_decentralized_sf.alph","Alphabet");
248  if(IsLoopPreservingObserver(sf,abstAlph) )
249  std::cout << "The abstraction for SF is a loop-preserving observer" << std::endl;
250  else
251  std::cout << "The abstraction for SF is not a loop-preserving observer" << std::endl;
252  aProject(sf,abstAlph,sfAbst);
253  sfAbst.Write("tmp_diag_system_4_decentralized_sf_abstracted.gen");
254  sfAbst.GraphWrite("tmp_demo_system_4_decentralized_sf_abstracted.png");
255  abstAlph.Read("data/diag_abstAlph_4_decentralized_c1.alph","Alphabet");
256  if(IsLoopPreservingObserver(c1,abstAlph) )
257  std::cout << "The abstraction for C1 is a loop-preserving observer" << std::endl;
258  else
259  std::cout << "The abstraction for C1 is not a loop-preserving observer" << std::endl;
260 
261  aProject(c1,abstAlph,c1Abst);
262  c1Abst.Write("tmp_diag_system_4_decentralized_c1_abstracted.gen");
263  c1Abst.GraphWrite("tmp_demo_system_4_decentralized_c1_abstracted.png");
264  sfc1Spec = Generator("data/diag_specification_4_decentralized_sfc1.gen");
265  aParallel(sfAbst,c1Abst,plant);
266  aParallel(plant,sfc1Spec,spec);
267 
268  // Write subsystems and specifications to png files (for inspection)
269  plant.GraphWrite("tmp_demo_system_4_decentralized_sfc1_abstracted.png");
270  spec.GraphWrite("tmp_demo_specification_4_decentralized_sfc1_abstract.png");
271 
272  // Observable events for the system components
273  alphVector.Clear();
274  *alph1 = plant.ObservableEvents() * sfAbst.Alphabet();
275  *alph2 = plant.ObservableEvents() * c1Abst.Alphabet();
276  alphVector.Append(alph1);
277  alphVector.Append(alph2);
278 
279  // Report to console
280  std::cout << "# b) run decentralized diagnosability test (expect result PASS)\n";
281 
282  // Test for modular diagnosability of the overall system
283  ok=IsCoDiagnosable(plant, spec, alphVector);
284  if(ok) {
285  std::cout << "The overall system G is co-diagnosable with respect to overall specification K." << std::endl;
286  std::cout << report << std::endl;
287  } else {
288  std::cout << "The overall system G is not co-diagnosable with respect to overall specification K." << std::endl;
289  std::cout << report << std::endl;
290  }
291  // // Record test case
292  // FAUDES_TEST_DUMP("decentralized abstracted sf/c1",ok);
293 
294 
295  // // Done
296  // cout << endl;
297  return 0;
298 }
#define FAUDES_TEST_DUMP(mes, dat)
Test protocol record macro ("mangle" filename for platform independance)
Definition: cfl_helper.h:483
Set of indices with symbolic names.
Definition: cfl_nameset.h:69
bool Insert(const Idx &rIndex)
Add an element by index.
Vector template.
virtual const T & At(const Position &pos) const
Access element.
const TaEventSet< EventAttr > & Alphabet(void) const
Return const reference to alphabet.
Generator with controllability attributes.
EventSet ObservableEvents(void) const
Get EventSet with observable events.
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
Definition: cfl_types.cpp:261
void Write(const Type *pContext=0) const
Write configuration data to console.
Definition: cfl_types.cpp:139
virtual void Append(const Type &rElem)
Append specified entry.
virtual void Clear(void)
Clear all vector.
void GraphWrite(const std::string &rFileName, const std::string &rOutFormat="", const std::string &rDotExec="dot") const
Produce graphical representation of this generator.
NameSet EventSet
Convenience typedef for plain event sets.
Definition: cfl_nameset.h:531
void DecentralizedModularDiagnoser(const std::vector< const System * > &rGens, const Generator &rSpec, std::vector< Diagnoser * > &rDiags, std::string &rReportString)
Function that computes decentralized diagnosers for the respective subsystems of a composed (modular)...
bool IsLoopPreservingObserver(const System &rGen, const EventSet &rHighAlph)
Verifies a loop-preserving observer.
bool DecentralizedDiagnoser(const System &rGen, const Generator &rSpec, const std::vector< const EventSet * > &rAlphabets, std::vector< Diagnoser * > &rDiags, std::string &rReportString)
Computes decentralized diagnosers for multiple local sites.
vGenerator Generator
Plain generator, api typedef for generator with no attributes.
TcGenerator< AttributeVoid, AttributeVoid, AttributeCFlags, AttributeVoid > System
Convenience typedef for std System.
void aParallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Parallel composition.
void aProject(const Generator &rGen, const EventSet &rProjectAlphabet, Generator &rResGen)
Deterministic projection.
Includes all libFAUDES headers, incl plugings
libFAUDES resides within the namespace faudes.
bool IsCoDiagnosable(const System &rGen, const Generator &rSpec, const vector< const EventSet * > &rAlphabets, std::string &rReportString)

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen