diag_3_modulardiagnosis.cpp
Go to the documentation of this file.
1 /** @file diag_3_modulardiagnosis.cpp
2 Illustrate modular diagnosability test and synthesis.
3 @ingroup Tutorials
4 @include diag_3_modulardiagnosis.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 *g1, *g2, *k1, *k2;
16  System g12, k12;
17  SystemVector plant;
18  GeneratorVector spec;
19  GeneratorVector diag;
20  std::string report;
21 
22  // **********************************************************************
23  //
24  // Modular Language-Diagnosability Verification (condition is fulfilled)
25  //
26 
27  // Report to console
28  std::cout << "################################\n";
29  std::cout << "# modular language-diagnosability (system 1/2)\n";
30  std::cout << "# a) read data \n";
31 
32  // Read subsystems and associated specifications and abstraction alphabets from files
33  g1 = new System("data/diag_system_3_modular1.gen");
34  g2 = new System("data/diag_system_3_modular2.gen");
35  k1 = new System("data/diag_specification_3_modular1.gen");
36  k2 = new System("data/diag_specification_3_modular2.gen");
37 
38  // Write subsystems and specifications to gen files (for html docu)
39  g1->Write("tmp_diag_system_3_modular1.gen");
40  g2->Write("tmp_diag_system_3_modular2.gen");
41  k1->Write("tmp_diag_specification_3_modular1.gen");
42  k2->Write("tmp_diag_specification_3_modular2.gen");
43 
44  // Write subsystems and specifications to png files (for inspection)
45  g1->GraphWrite("tmp_demo_system_3_modular1.png");
46  g2->GraphWrite("tmp_demo_system_3_modular2.png");
47  k1->GraphWrite("tmp_demo_specification_3_modular1.png");
48  k2->GraphWrite("tmp_demo_specification_3_modular2.png");
49 
50  // Relevant abstractions for the modular diagnosability verification (for HTML docu)
51  EventSet abstAlph;
52  abstAlph.Read("data/diag_abstrAlph_3_modular12.alph");
53  Generator g1Abst, g2Abst;
54  Project(*g1,abstAlph,g1Abst);
55  Project(*g2,abstAlph,g2Abst);
56  g1Abst.Write("tmp_diag_system_3_modular1_hat.gen");
57  g2Abst.Write("tmp_diag_system_3_modular2_hat.gen");
58 
59  // Set up vector containers
60  plant.Append(g1);
61  plant.Append(g2);
62  spec.Append(k1);
63  spec.Append(k2);
64  // Fix ownership
65  plant.TakeOwnership();
66  spec.TakeOwnership();
67 
68  // Report to console
69  std::cout << "# b) run modular diagnosability test (expect result PASS)\n";
70 
71  // Test for modular diagnosability of the overall system
72  bool ok=IsModularDiagnosable(plant, spec, report);
73  if(ok) {
74  std::cout << "The overall system G is modularly diagnosable with respect to overall specification K." << std::endl;
75  std::cout << report << std::endl;
76  } else {
77  std::cout << "The overall system G is not modularly diagnosable with respect to overall specification K." << std::endl;
78  std::cout << report << std::endl;
79  }
80 
81  // Record test case
82  FAUDES_TEST_DUMP("modular 1/2",ok);
83 
84 
85  // **********************************************************************
86  //
87  // Modular Diagnoser Computation
88  //
89 
90  // Report to console
91  std::cout << "# c) compute modular diagnoser\n";
92 
93  // Diagnoser synthesis
94  ModularDiagnoser(plant,spec,diag,report);
95 
96  // Write diagnoser moduls to gen files (for html docu)
97  diag.At(0).Write("tmp_diag_diagnoser_3_modular1.gen");
98  diag.At(1).Write("tmp_diag_diagnoser_3_modular2.gen");
99 
100  // Write diagnoser to png files (for inspection)
101  diag.At(0).GraphWrite("tmp_demo_diagnoser_3_modular1.png");
102  diag.At(1).GraphWrite("tmp_demo_diagnoser_3_modular2.png");
103 
104  // Record test case
105  FAUDES_TEST_DUMP("modular 1/2",diag);
106 
107  // Report to console
108  std::cout << "# done \n";
109  std::cout << "################################\n";
110 
111  // Clear vectors
112  // Note: includes releasing member memory
113  plant.Clear();
114  spec.Clear();
115 
116 
117  // **********************************************************************
118  // **********************************************************************
119  //
120  // Modular Diagnosability Verification (Condition is not fulfilled)
121  //
122 
123  // Report to console
124  std::cout << "################################\n";
125  std::cout << "# modular diagnosability (system 3/4)\n";
126  std::cout << "# a) read data \n";
127 
128  // Read subsystems and associated specifications and abstraction alphabets from files
129  g1 = new System("data/diag_system_3_modular3.gen");
130  g2 = new System("data/diag_system_3_modular4.gen");
131  k1 = new System("data/diag_specification_3_modular3.gen");
132  k2 = new System("data/diag_specification_3_modular4.gen");
133 
134  // Write subsystems and specifications to gen files (for html docu)
135  g1->Write("tmp_diag_system_3_modular3.gen");
136  g2->Write("tmp_diag_system_3_modular4.gen");
137  k1->Write("tmp_diag_specification_3_modular3.gen");
138  k2->Write("tmp_diag_specification_3_modular4.gen");
139 
140  // Write subsystems and specifications to png files (for inspection)
141  g1->GraphWrite("tmp_demo_system_3_modular3.png");
142  g2->GraphWrite("tmp_demo_system_3_modular4.png");
143  k1->GraphWrite("tmp_demo_specification_3_modular3.png");
144  k2->GraphWrite("tmp_demo_specification_3_modular4.png");
145 
146  // Set up vector containers
147  plant.Append(g1);
148  plant.Append(g2);
149  spec.Append(k1);
150  spec.Append(k2);
151  // Fix ownership
152  plant.TakeOwnership();
153  spec.TakeOwnership();
154 
155  // Report to console
156  std::cout << "# b) run modular diagnosability test (expect result FAIL)\n";
157 
158  // Test for modular diagnosability of the overall system
159  ok=IsModularDiagnosable(plant, spec, report);
160  if(ok) {
161  std::cout << "The overall system G is modularly diagnosable with respect to overall specification K." << std::endl;
162  std::cout << report << std::endl;
163  } else {
164  std::cout << "The overall system G is not modularly diagnosable with respect to overall specification K." << std::endl;
165  std::cout << report << std::endl;
166  }
167 
168  // Record test case
169  FAUDES_TEST_DUMP("modular 3/4",ok);
170 
171  // Report to console
172  std::cout << "# done \n";
173  std::cout << "################################\n";
174 
175  // Clear vectors
176  // Note: includes releasing member memory
177  plant.Clear();
178  spec.Clear();
179 
180  // **********************************************************************
181  // **********************************************************************
182  //
183  // Modular diagnosability Verification (application example)
184  //
185 
186  // Report to console
187  std::cout << "################################\n";
188  std::cout << "# modular diagnosability (system sf/cb1a)\n";
189  std::cout << "# a) read data \n";
190 
191  // Read subsystems and associated specifications and abstraction alphabets from files
192  g1 = new System("data/diag_system_3_modular_sf.gen");
193  g2 = new System("data/diag_system_3_modular_c1.gen");
194  k1 = new System("data/diag_specification_3_modular_sf.gen");
195  k2 = new System("data/diag_specification_3_modular_c1.gen");
196 
197  // Write subsystems and specifications to gen files (for html docu)
198  g1->Write("tmp_diag_system_3_modular_sf.gen");
199  g2->Write("tmp_diag_system_3_modular_c1.gen");
200  k1->Write("tmp_diag_specification_3_modular_sf.gen");
201  k2->Write("tmp_diag_specification_3_modular_c1.gen");
202 
203  // Write subsystems and specifications to png files (for inspection)
204  g1->GraphWrite("tmp_demo_system_3_modular_sf.png");
205  g2->GraphWrite("tmp_demo_system_3_modular_c1.png");
206  k1->GraphWrite("tmp_demo_specification_3_modular_sf.png");
207  k2->GraphWrite("tmp_demo_specification_3_modular_c1.png");
208 
209  // Set up vector containers
210  plant.Append(g1);
211  plant.Append(g2);
212  spec.Append(k1);
213  spec.Append(k2);
214  // Fix ownership
215  plant.TakeOwnership();
216  spec.TakeOwnership();
217 
218  // Report to console
219  std::cout << "# b) run diagnosability test (expect result PASS)\n";
220 
221  // Test for decentralized diagnosability of the overall system
222  if(IsModularDiagnosable(plant, spec, report)) {
223  std::cout << "The overall system G is modularly diagnosable with respect to overall specification K." << std::endl;
224  std::cout << report << std::endl;
225  } else {
226  std::cout << "The overall system G is not modularly diagnosable with respect to overall specification K." << std::endl;
227  std::cout << report << std::endl;
228  }
229 
230  // **********************************************************************
231  //
232  // Modular Diagnoser Computation
233  //
234 
235  // Report to console
236  std::cout << "# c) compute modular diagnoser\n";
237  diag.Clear();
238  // Diagnoser synthesis
239  ModularDiagnoser(plant,spec,diag,report);
240 
241  // Write diagnoser moduls to gen files (for html docu)
242  diag.At(0).Write("tmp_diag_diagnoser_3_modular_sf.gen");
243  diag.At(1).Write("tmp_diag_diagnoser_3_modular_c1.gen");
244 
245  // Write diagnoser to png files (for inspection)
246  diag.At(0).GraphWrite("tmp_demo_diagnoser_3_modular_sf.png");
247  diag.At(1).GraphWrite("tmp_demo_diagnoser_3_modular_c1.png");
248 
249  // Record test case
250  FAUDES_TEST_DUMP("modular sf/c1",diag);
251 
252  // Report to console
253  std::cout << "# done \n";
254  std::cout << "################################\n";
255 
256  // Clear vectors
257  // Note: includes releasing member memory
258  plant.Clear();
259  spec.Clear();
260 
261  // Done
262  std::cout << std::endl;
263  return 0;
264 }

libFAUDES 2.26g --- 2015.08.17 --- c++ api documentaion by doxygen