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  // Relevant abstractions for the modular diagnosability verification (for HTML docu)
45  EventSet abstAlph;
46  abstAlph.Read("data/diag_abstrAlph_3_modular12.alph");
47  Generator g1Abst, g2Abst;
48  Project(*g1,abstAlph,g1Abst);
49  Project(*g2,abstAlph,g2Abst);
50  g1Abst.Write("tmp_diag_system_3_modular1_hat.gen");
51  g2Abst.Write("tmp_diag_system_3_modular2_hat.gen");
52 
53  // Set up vector containers
54  plant.Append(g1);
55  plant.Append(g2);
56  spec.Append(k1);
57  spec.Append(k2);
58  // Fix ownership
59  plant.TakeOwnership();
60  spec.TakeOwnership();
61 
62  // Report to console
63  std::cout << "# b) run modular diagnosability test (expect result PASS)\n";
64 
65  // Test for modular diagnosability of the overall system
66  bool ok=IsModularDiagnosable(plant, spec, report);
67  if(ok) {
68  std::cout << "The overall system G is modularly diagnosable with respect to overall specification K." << std::endl;
69  std::cout << report << std::endl;
70  } else {
71  std::cout << "The overall system G is not modularly diagnosable with respect to overall specification K." << std::endl;
72  std::cout << report << std::endl;
73  }
74 
75  // Record test case
76  FAUDES_TEST_DUMP("modular 1/2",ok);
77 
78 
79  // **********************************************************************
80  //
81  // Modular Diagnoser Computation
82  //
83 
84  // Report to console
85  std::cout << "# c) compute modular diagnoser\n";
86 
87  // Diagnoser synthesis
88  ModularDiagnoser(plant,spec,diag,report);
89 
90  // Write diagnoser moduls to gen files (for html docu)
91  diag.At(0).Write("tmp_diag_diagnoser_3_modular1.gen");
92  diag.At(1).Write("tmp_diag_diagnoser_3_modular2.gen");
93 
94  // Record test case
95  FAUDES_TEST_DUMP("modular 1/2",diag);
96 
97  // Report to console
98  std::cout << "# done \n";
99  std::cout << "################################\n";
100 
101  // Clear vectors
102  // Note: includes releasing member memory
103  plant.Clear();
104  spec.Clear();
105 
106 
107  // **********************************************************************
108  // **********************************************************************
109  //
110  // Modular Diagnosability Verification (Condition is not fulfilled)
111  //
112 
113  // Report to console
114  std::cout << "################################\n";
115  std::cout << "# modular diagnosability (system 3/4)\n";
116  std::cout << "# a) read data \n";
117 
118  // Read subsystems and associated specifications and abstraction alphabets from files
119  g1 = new System("data/diag_system_3_modular3.gen");
120  g2 = new System("data/diag_system_3_modular4.gen");
121  k1 = new System("data/diag_specification_3_modular3.gen");
122  k2 = new System("data/diag_specification_3_modular4.gen");
123 
124  // Write subsystems and specifications to gen files (for html docu)
125  g1->Write("tmp_diag_system_3_modular3.gen");
126  g2->Write("tmp_diag_system_3_modular4.gen");
127  k1->Write("tmp_diag_specification_3_modular3.gen");
128  k2->Write("tmp_diag_specification_3_modular4.gen");
129 
130  // Set up vector containers
131  plant.Append(g1);
132  plant.Append(g2);
133  spec.Append(k1);
134  spec.Append(k2);
135  // Fix ownership
136  plant.TakeOwnership();
137  spec.TakeOwnership();
138 
139  // Report to console
140  std::cout << "# b) run modular diagnosability test (expect result FAIL)\n";
141 
142  // Test for modular diagnosability of the overall system
143  ok=IsModularDiagnosable(plant, spec, report);
144  if(ok) {
145  std::cout << "The overall system G is modularly diagnosable with respect to overall specification K." << std::endl;
146  std::cout << report << std::endl;
147  } else {
148  std::cout << "The overall system G is not modularly diagnosable with respect to overall specification K." << std::endl;
149  std::cout << report << std::endl;
150  }
151 
152  // Record test case
153  FAUDES_TEST_DUMP("modular 3/4",ok);
154 
155  // Report to console
156  std::cout << "# done \n";
157  std::cout << "################################\n";
158 
159  // Clear vectors
160  // Note: includes releasing member memory
161  plant.Clear();
162  spec.Clear();
163 
164  // **********************************************************************
165  // **********************************************************************
166  //
167  // Modular diagnosability Verification (application example)
168  //
169 
170  // Report to console
171  std::cout << "################################\n";
172  std::cout << "# modular diagnosability (system sf/cb1a)\n";
173  std::cout << "# a) read data \n";
174 
175  // Read subsystems and associated specifications and abstraction alphabets from files
176  g1 = new System("data/diag_system_3_modular_sf.gen");
177  g2 = new System("data/diag_system_3_modular_c1.gen");
178  k1 = new System("data/diag_specification_3_modular_sf.gen");
179  k2 = new System("data/diag_specification_3_modular_c1.gen");
180 
181  // Write subsystems and specifications to gen files (for html docu)
182  g1->Write("tmp_diag_system_3_modular_sf.gen");
183  g2->Write("tmp_diag_system_3_modular_c1.gen");
184  k1->Write("tmp_diag_specification_3_modular_sf.gen");
185  k2->Write("tmp_diag_specification_3_modular_c1.gen");
186 
187  // Set up vector containers
188  plant.Append(g1);
189  plant.Append(g2);
190  spec.Append(k1);
191  spec.Append(k2);
192  // Fix ownership
193  plant.TakeOwnership();
194  spec.TakeOwnership();
195 
196  // Report to console
197  std::cout << "# b) run diagnosability test (expect result PASS)\n";
198 
199  // Test for decentralized diagnosability of the overall system
200  if(IsModularDiagnosable(plant, spec, report)) {
201  std::cout << "The overall system G is modularly diagnosable with respect to overall specification K." << std::endl;
202  std::cout << report << std::endl;
203  } else {
204  std::cout << "The overall system G is not modularly diagnosable with respect to overall specification K." << std::endl;
205  std::cout << report << std::endl;
206  }
207 
208  // **********************************************************************
209  //
210  // Modular Diagnoser Computation
211  //
212 
213  // Report to console
214  std::cout << "# c) compute modular diagnoser\n";
215  diag.Clear();
216  // Diagnoser synthesis
217  ModularDiagnoser(plant,spec,diag,report);
218 
219  // Write diagnoser moduls to gen files (for html docu)
220  diag.At(0).Write("tmp_diag_diagnoser_3_modular_sf.gen");
221  diag.At(1).Write("tmp_diag_diagnoser_3_modular_c1.gen");
222 
223  // Record test case
224  FAUDES_TEST_DUMP("modular sf/c1",diag);
225 
226  // Report to console
227  std::cout << "# done \n";
228  std::cout << "################################\n";
229 
230  // Clear vectors
231  // Note: includes releasing member memory
232  plant.Clear();
233  spec.Clear();
234 
235  // Done
236  std::cout << std::endl;
237  return 0;
238 }
#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
Vector template.
virtual const T & At(const Position &pos) const
Access element.
Generator with controllability attributes.
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
void TakeOwnership(void)
Take ownership of all entries.
virtual void Append(const Type &rElem)
Append specified entry.
virtual void Clear(void)
Clear all vector.
Base class of all FAUDES generators.
int main(void)
TcGenerator< AttributeVoid, AttributeVoid, AttributeCFlags, AttributeVoid > System
Convenience typedef for std System.
void Project(const Generator &rGen, const EventSet &rProjectAlphabet, Generator &rResGen)
Deterministic projection.
Includes all libFAUDES headers, incl plugings
libFAUDES resides within the namespace faudes.
bool ModularDiagnoser(const SystemVector &rGsubs, const GeneratorVector &rKsubs, GeneratorVector &rDiagSubs, string &rReportString)
bool IsModularDiagnosable(const SystemVector &rGsubs, const GeneratorVector &rKsubs, string &rReportString)

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