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

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