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 std;
10 using namespace faudes;
11 
12 
13 int main(void) {
14 
15  // Declare common variables
16  System plant, spec;
17  EventSet *alph1, *alph2;
18  EventSetVector alphVector;
19  string report;
20 
21  // **********************************************************************
22  //
23  // Decentralized Language-Diagnosability Verification (condition is not fulfilled)
24  //
25 
26  // Report to console
27  std::cout << "################################\n";
28  std::cout << "# decentralized language-diagnosability (system 1)\n";
29  std::cout << "# a) read data \n";
30 
31  // Read subsystems and associated specifications and abstraction alphabets from files
32  plant = System("data/diag_system_4_decentralized1.gen");
33  spec = System("data/diag_specification_4_decentralized1.gen");
34 
35  // Write subsystems and specifications to gen files (for html docu)
36  plant.Write("tmp_diag_system_4_decentralized1.gen");
37  spec.Write("tmp_diag_specification_4_decentralized1.gen");
38 
39  // Write subsystems and specifications to png files (for inspection)
40  plant.GraphWrite("tmp_demo_system_4_decentralized1.png");
41  spec.GraphWrite("tmp_demo_specification_4_decentralized1.png");
42 
43  // Relevant abstractions for the modular diagnosability verification (for HTML docu)
44 
45  alph1 = new EventSet("data/diag_obsAlph_4_decentralized1_1.alph");
46  alph2 = new EventSet("data/diag_obsAlph_4_decentralized1_2.alph");
47  alphVector.Append(alph1 );
48  alphVector.Append(alph2 );
49 
50 
51  // Report to console
52  std::cout << "# b) run decentralized diagnosability test (expect result FAIL)\n";
53 
54  // Test for modular diagnosability of the overall system
55  bool ok=IsCoDiagnosable(plant, spec, alphVector);
56  if(ok) {
57  cout << "The overall system G is co-diagnosable with respect to overall specification K." << endl;
58  } else {
59  cout << "The overall system G is not co-diagnosable with respect to overall specification K." << endl;
60  }
61  // Compute local decentralzed diagnosers for the example
62  GeneratorVector diagVector;
63  DecentralizedDiagnoser(plant,spec,alphVector,diagVector);
64  // Write diagnosers to .gen file (for html docu)
65  diagVector.At(0).Write("tmp_diag_diagnoser_4_decentralized1_1.gen");
66  diagVector.At(1).Write("tmp_diag_diagnoser_4_decentralized1_2.gen");
67  // Write diagnosers to png (for inspection)
68  diagVector.At(0).GraphWrite("tmp_demo_diagnoser_4_decentralized1_1.png");
69  diagVector.At(1).GraphWrite("tmp_demo_diagnoser_4_decentralized1_2.png");
70 
71  // Record test case
72  FAUDES_TEST_DUMP("decentralized 1",ok);
73 
74  // **********************************************************************
75  //
76  // Decentralized Language-Diagnosability Verification (condition is fulfilled)
77  //
78  // Report to console
79  std::cout << "################################\n";
80  std::cout << "# decentralized language-diagnosability (system 2)\n";
81  std::cout << "# a) read data \n";
82 
83  // Read subsystems and associated specifications and abstraction alphabets from files
84  plant = System("data/diag_system_4_decentralized2.gen");
85  spec = System("data/diag_specification_4_decentralized2.gen");
86 
87  // Write subsystems and specifications to gen files (for html docu)
88  plant.Write("tmp_diag_system_4_decentralized2.gen");
89  spec.Write("tmp_diag_specification_4_decentralized2.gen");
90 
91  // Write subsystems and specifications to png files (for inspection)
92  plant.GraphWrite("tmp_demo_system_4_decentralized2.png");
93  spec.GraphWrite("tmp_demo_specification_4_decentralized2.png");
94 
95  // Relevant abstractions for the modular diagnosability verification (for HTML docu)
96  alphVector.Clear();
97  alph1 = new EventSet("data/diag_obsAlph_4_decentralized2_1.alph");
98  alph2 = new EventSet("data/diag_obsAlph_4_decentralized2_2.alph");
99  alphVector.Append(alph1 );
100  alphVector.Append(alph2 );
101 
102  // Report to console
103  std::cout << "# b) run decentralized diagnosability test (expect result FAIL)\n";
104 
105  // Test for modular diagnosability of the overall system
106  ok=IsCoDiagnosable(plant, spec, alphVector);
107  if(ok) {
108  cout << "The overall system G is co-diagnosable with respect to overall specification K." << endl;
109  cout << report << endl;
110  } else {
111  cout << "The overall system G is not co-diagnosable with respect to overall specification K." << endl;
112  cout << "The overall system G is not co-diagnosable with respect to overall specification K." << endl;
113  cout << report << endl;
114  }
115  diagVector.Clear();
116  // Compute decentralized diagnosers for the local sites
117  DecentralizedDiagnoser(plant,spec,alphVector,diagVector);
118  // Write diagnosers to .gen file (for html docu)
119  diagVector.At(0).Write("tmp_diag_diagnoser_4_decentralized2_1.gen");
120  diagVector.At(1).Write("tmp_diag_diagnoser_4_decentralized2_2.gen");
121  // Write diagnosers to png (for inspection)
122  diagVector.At(0).GraphWrite("tmp_demo_diagnoser_4_decentralized2_1.png");
123  diagVector.At(1).GraphWrite("tmp_demo_diagnoser_4_decentralized2_2.png");
124  // Record test case
125  FAUDES_TEST_DUMP("decentralized 2",ok);
126 
127  // **********************************************************************
128  //
129  // Decentralized Language-Diagnosability Verification (condition is not fulfilled)
130  //
131  // Report to console
132  std::cout << "################################\n";
133  std::cout << "# decentralized language-diagnosability (system 3)\n";
134  std::cout << "# a) read data \n";
135 
136  // Read subsystems and associated specifications and abstraction alphabets from files
137  plant = System("data/diag_system_2_language.gen");
138  spec = System("data/diag_specification_2_language.gen");
139 
140  // Write subsystems and specifications to png files (for inspection)
141  plant.GraphWrite("tmp_demo_system_2_language.png");
142  spec.GraphWrite("tmp_demo_specification_2_language.png");
143 
144  // Relevant abstractions for the modular diagnosability verification (for HTML docu)
145  alphVector.Clear();
146  alph1 = new EventSet;
147  alph1->Insert("alpha");
148  alph1->Insert("beta");
149  alph2 = new EventSet();
150  alph2->Insert("alpha");
151  alphVector.Append(alph1 );
152  alphVector.Append(alph2 );
153 
154  // Report to console
155  std::cout << "# b) run decentralized diagnosability test (expect result FAIL)\n";
156 
157  // Test for modular diagnosability of the overall system
158  ok=IsCoDiagnosable(plant, spec, alphVector);
159  if(ok) {
160  cout << "The overall system G is co-diagnosable with respect to overall specification K." << endl;
161  cout << report << endl;
162  } else {
163  cout << "The overall system G is not co-diagnosable with respect to overall specification K." << endl;
164  cout << report << endl;
165  }
166 
167  // Record test case
168  FAUDES_TEST_DUMP("decentralized 3",ok);
169 
170 
171  // **********************************************************************
172  //
173  // Decentralized Language-Diagnosability Verification for Application Example (condition is fulfilled)
174  //
175  // Report to console
176  std::cout << "################################\n";
177  std::cout << "# decentralized language-diagnosability (system sf/c1)\n";
178  std::cout << "# a) read data \n";
179 
180  // Read subsystems and associated specifications and abstraction alphabets from files
181  System sf,c1,sfc1Spec;
182  sf = System("data/diag_system_4_decentralized_sf.gen");
183  c1 = System("data/diag_system_4_decentralized_c1.gen");
184 
185  // Write generators (for html docu)
186  sf.Write("tmp_diag_system_4_decentralized_sf.gen");
187  c1.Write("tmp_diag_system_4_decentralized_c1.gen");
188  // Write generators (for inspection)
189  sf.GraphWrite("tmp_demo_system_4_decentralized_sf.png");
190  c1.GraphWrite("tmp_demo_system_4_decentralized_c1.png");
191  sfc1Spec = Generator("data/diag_specification_4_decentralized_sfc1.gen");
192  aParallel(sf,c1,plant);
193  aParallel(plant,sfc1Spec,spec);
194 
195  // Write subsystems and specifications to png files (for inspection)
196  plant.GraphWrite("tmp_demo_system_4_decentralized_sfc1.png");
197  spec.GraphWrite("tmp_demo_specification_4_decentralized_sfc1.png");
198 
199  // Observable events for the system components
200  alphVector.Clear();
201  alph1 = new EventSet();
202  *alph1 = plant.ObservableEvents() * sf.Alphabet();
203  alph2 = new EventSet();
204  *alph2 = plant.ObservableEvents() * c1.Alphabet();
205  alphVector.Append(alph1 );
206  alphVector.Append(alph2 );
207 
208  // Report to console
209  std::cout << "# b) run decentralized diagnosability test (expect result PASS)\n";
210 
211  // Test for modular diagnosability of the overall system
212  ok=IsCoDiagnosable(plant, spec, alphVector);
213  if(ok) {
214  cout << "The overall system G is co-diagnosable with respect to overall specification K." << endl;
215  cout << report << endl;
216  } else {
217  cout << "The overall system G is not co-diagnosable with respect to overall specification K." << endl;
218  cout << report << endl;
219  }
220  // Compute decentralized diagnosers for the local sites
221  SystemVector plantVector;
222  plantVector.Append(&sf);
223  plantVector.Append(&c1);
224  diagVector.Clear();
225  DecentralizedModularDiagnoser(plantVector,spec,diagVector);
226  // Write diagnosers to .gen file (for html docu)
227  diagVector.At(0).Write("tmp_diag_diagnoser_4_decentralized_sf.gen");
228  diagVector.At(1).Write("tmp_diag_diagnoser_4_decentralized_c1.gen");
229  // Write diagnosers to png (for inspection)
230  diagVector.At(0).GraphWrite("tmp_demo_diagnoser_4_decentralized_sf.png");
231  diagVector.At(1).GraphWrite("tmp_demo_diagnoser_4_decentralized_c1.png");
232  // Record test case
233  FAUDES_TEST_DUMP("decentralized sf/c1",ok);
234 
235 
236  // // **********************************************************************
237  //
238  // Abstraction-based Decentralized Language-Diagnosability Verification for Application Example (condition is fulfilled)
239  //
240  // Report to console
241  std::cout << "################################\n";
242  std::cout << "# Abstraction-based decentralized language-diagnosability (system sf/c1)\n";
243  std::cout << "# a) read data \n";
244 
245  // Compute abstracted system components and verify the loop-preserving observer condition
246  System sfAbst, c1Abst;
247  EventSet abstAlph;
248  abstAlph.Read("data/diag_abstAlph_4_decentralized_sf.alph","Alphabet");
249  if(IsLoopPreservingObserver(sf,abstAlph) )
250  std::cout << "The abstraction for SF is a loop-preserving observer" << std::endl;
251  else
252  std::cout << "The abstraction for SF is not a loop-preserving observer" << std::endl;
253  aProject(sf,abstAlph,sfAbst);
254  sfAbst.Write("tmp_diag_system_4_decentralized_sf_abstracted.gen");
255  sfAbst.GraphWrite("tmp_demo_system_4_decentralized_sf_abstracted.png");
256  abstAlph.Read("data/diag_abstAlph_4_decentralized_c1.alph","Alphabet");
257  if(IsLoopPreservingObserver(c1,abstAlph) )
258  std::cout << "The abstraction for C1 is a loop-preserving observer" << std::endl;
259  else
260  std::cout << "The abstraction for C1 is not a loop-preserving observer" << std::endl;
261 
262  aProject(c1,abstAlph,c1Abst);
263  c1Abst.Write("tmp_diag_system_4_decentralized_c1_abstracted.gen");
264  c1Abst.GraphWrite("tmp_demo_system_4_decentralized_c1_abstracted.png");
265  sfc1Spec = Generator("data/diag_specification_4_decentralized_sfc1.gen");
266  aParallel(sfAbst,c1Abst,plant);
267  aParallel(plant,sfc1Spec,spec);
268 
269  // Write subsystems and specifications to png files (for inspection)
270  plant.GraphWrite("tmp_demo_system_4_decentralized_sfc1_abstracted.png");
271  spec.GraphWrite("tmp_demo_specification_4_decentralized_sfc1_abstract.png");
272 
273  // Observable events for the system components
274  alphVector.Clear();
275  *alph1 = plant.ObservableEvents() * sfAbst.Alphabet();
276  *alph2 = plant.ObservableEvents() * c1Abst.Alphabet();
277  alphVector.Append(alph1);
278  alphVector.Append(alph2);
279 
280  // Report to console
281  std::cout << "# b) run decentralized diagnosability test (expect result PASS)\n";
282 
283  // Test for modular diagnosability of the overall system
284  ok=IsCoDiagnosable(plant, spec, alphVector);
285  if(ok) {
286  cout << "The overall system G is co-diagnosable with respect to overall specification K." << endl;
287  cout << report << endl;
288  } else {
289  cout << "The overall system G is not co-diagnosable with respect to overall specification K." << endl;
290  cout << report << endl;
291  }
292  // // Record test case
293  // FAUDES_TEST_DUMP("decentralized abstracted sf/c1",ok);
294 
295 
296  // // Done
297  // cout << endl;
298  return 0;
299 }

libFAUDES 2.24g --- 2014.09.15 --- c++ api documentaion by doxygen