diag_3_modulardiagnosis.cpp

Go to the documentation of this file.
00001 /** @file diag_3_modulardiagnosis.cpp
00002 Illustrate modular diagnosability test and synthesis. 
00003 @ingroup Tutorials
00004 @include diag_3_modulardiagnosis.cpp
00005 */
00006 
00007 #include "libfaudes.h"
00008 
00009 using namespace std;
00010 using namespace faudes;
00011 
00012 
00013 int main(void) {
00014 
00015   // Declare common variables
00016   System *g1, *g2, *k1, *k2;
00017   System g12, k12; 
00018   SystemVector plant;
00019   GeneratorVector spec;
00020   GeneratorVector diag;    
00021   string report;
00022 
00023   // **********************************************************************
00024   //
00025   // Modular Language-Diagnosability Verification (condition is fulfilled)
00026   //
00027   
00028   // Report to console
00029   std::cout << "################################\n";
00030   std::cout << "# modular language-diagnosability (system 1/2)\n";
00031   std::cout << "# a) read data \n";
00032 
00033   // Read subsystems and associated specifications and abstraction alphabets from files
00034   g1 = new System("data/diag_system_3_modular1.gen");
00035   g2 = new System("data/diag_system_3_modular2.gen");
00036   k1 = new System("data/diag_specification_3_modular1.gen");
00037   k2 = new System("data/diag_specification_3_modular2.gen");
00038   
00039   // Write subsystems and specifications to gen files (for html docu)
00040   g1->Write("tmp_diag_system_3_modular1.gen");
00041   g2->Write("tmp_diag_system_3_modular2.gen");
00042   k1->Write("tmp_diag_specification_3_modular1.gen");
00043   k2->Write("tmp_diag_specification_3_modular2.gen");
00044 
00045   // Write subsystems and specifications to png files (for inspection)
00046   g1->GraphWrite("tmp_demo_system_3_modular1.png");
00047   g2->GraphWrite("tmp_demo_system_3_modular2.png");
00048   k1->GraphWrite("tmp_demo_specification_3_modular1.png");
00049   k2->GraphWrite("tmp_demo_specification_3_modular2.png");
00050 
00051   // Relevant abstractions for the modular diagnosability verification (for HTML docu)
00052   EventSet abstAlph;
00053   abstAlph.Read("data/diag_abstrAlph_3_modular12.alph");
00054   Generator g1Abst, g2Abst;
00055   Project(*g1,abstAlph,g1Abst);
00056   Project(*g2,abstAlph,g2Abst);
00057   g1Abst.Write("tmp_diag_system_3_modular1_hat.gen");
00058   g2Abst.Write("tmp_diag_system_3_modular2_hat.gen"); 
00059 
00060   // Set up vector containers
00061   plant.Append(g1);
00062   plant.Append(g2);
00063   spec.Append(k1);
00064   spec.Append(k2);
00065   // Fix ownership 
00066   plant.TakeOwnership();
00067   spec.TakeOwnership();
00068 
00069   // Report to console
00070   std::cout << "# b) run modular diagnosability test (expect result PASS)\n";
00071 
00072   // Test for modular diagnosability of the overall system
00073   bool ok=IsModularDiagnosable(plant, spec, report);
00074   if(ok) {
00075     cout << "The overall system G is modularly diagnosable with respect to overall specification K." << endl;
00076     cout << report << endl;
00077   } else {
00078     cout << "The overall system G is not modularly diagnosable with respect to overall specification K." << endl;
00079     cout << report << endl;
00080   }
00081   
00082   // Record test case
00083   FAUDES_TEST_DUMP("modular 1/2",ok);
00084 
00085 
00086   // **********************************************************************
00087   //
00088   // Modular Diagnoser Computation 
00089   //
00090   
00091   // Report to console
00092   std::cout << "# c) compute modular diagnoser\n";
00093   
00094   // Diagnoser synthesis
00095   ModularDiagnoser(plant,spec,diag,report);
00096 
00097   // Write diagnoser moduls to gen files (for html docu)
00098   diag.At(0).Write("tmp_diag_diagnoser_3_modular1.gen");
00099   diag.At(1).Write("tmp_diag_diagnoser_3_modular2.gen");
00100 
00101   // Write diagnoser to png files (for inspection)
00102   diag.At(0).GraphWrite("tmp_demo_diagnoser_3_modular1.png");
00103   diag.At(1).GraphWrite("tmp_demo_diagnoser_3_modular2.png");
00104 
00105   // Record test case
00106   FAUDES_TEST_DUMP("modular 1/2",diag);
00107 
00108   // Report to console
00109   std::cout << "# done \n";
00110   std::cout << "################################\n";
00111 
00112   // Clear vectors
00113   // Note: includes releasing member memory
00114   plant.Clear();
00115   spec.Clear();
00116 
00117 
00118   // **********************************************************************
00119   // **********************************************************************
00120   //
00121   // Modular Diagnosability Verification (Condition is not fulfilled)
00122   //
00123 
00124   // Report to console
00125   std::cout << "################################\n";
00126   std::cout << "# modular diagnosability (system 3/4)\n";
00127   std::cout << "# a) read data \n";
00128   
00129   // Read subsystems and associated specifications and abstraction alphabets from files
00130   g1 = new System("data/diag_system_3_modular3.gen");
00131   g2 = new System("data/diag_system_3_modular4.gen");
00132   k1 = new System("data/diag_specification_3_modular3.gen");
00133   k2 = new System("data/diag_specification_3_modular4.gen");
00134   
00135   // Write subsystems and specifications to gen files (for html docu)
00136   g1->Write("tmp_diag_system_3_modular3.gen");
00137   g2->Write("tmp_diag_system_3_modular4.gen");
00138   k1->Write("tmp_diag_specification_3_modular3.gen");
00139   k2->Write("tmp_diag_specification_3_modular4.gen");
00140 
00141   // Write subsystems and specifications to png files (for inspection)
00142   g1->GraphWrite("tmp_demo_system_3_modular3.png");
00143   g2->GraphWrite("tmp_demo_system_3_modular4.png");
00144   k1->GraphWrite("tmp_demo_specification_3_modular3.png");
00145   k2->GraphWrite("tmp_demo_specification_3_modular4.png");
00146   
00147   // Set up vector containers
00148   plant.Append(g1);
00149   plant.Append(g2);
00150   spec.Append(k1);
00151   spec.Append(k2);
00152   // Fix ownership
00153   plant.TakeOwnership();
00154   spec.TakeOwnership();
00155   
00156   // Report to console
00157   std::cout << "# b) run modular diagnosability test (expect result FAIL)\n";
00158 
00159   // Test for modular diagnosability of the overall system
00160   ok=IsModularDiagnosable(plant, spec, report);
00161   if(ok) {
00162     cout << "The overall system G is modularly diagnosable with respect to overall specification K." << endl;
00163     cout << report << endl;
00164   } else {
00165     cout << "The overall system G is not modularly diagnosable with respect to overall specification K." << endl;
00166     cout << report << endl;
00167   }
00168   
00169   // Record test case
00170   FAUDES_TEST_DUMP("modular 3/4",ok);
00171 
00172   // Report to console
00173   std::cout << "# done \n";
00174   std::cout << "################################\n";
00175 
00176   // Clear vectors
00177   // Note: includes releasing member memory
00178   plant.Clear();
00179   spec.Clear();
00180 
00181   // **********************************************************************
00182   // **********************************************************************
00183   //
00184   // Modular diagnosability Verification (application example) 
00185   //
00186 
00187   // Report to console
00188   std::cout << "################################\n";
00189   std::cout << "# modular diagnosability (system sf/cb1a)\n";
00190   std::cout << "# a) read data \n";
00191 
00192   // Read subsystems and associated specifications and abstraction alphabets from files
00193   g1 = new System("data/diag_system_3_modular_sf.gen");
00194   g2 = new System("data/diag_system_3_modular_c1.gen");
00195   k1 = new System("data/diag_specification_3_modular_sf.gen");
00196   k2 = new System("data/diag_specification_3_modular_c1.gen");
00197   
00198   // Write subsystems and specifications to gen files (for html docu)
00199   g1->Write("tmp_diag_system_3_modular_sf.gen");
00200   g2->Write("tmp_diag_system_3_modular_c1.gen");
00201   k1->Write("tmp_diag_specification_3_modular_sf.gen");
00202   k2->Write("tmp_diag_specification_3_modular_c1.gen");
00203 
00204   // Write subsystems and specifications to png files (for inspection)
00205   g1->GraphWrite("tmp_demo_system_3_modular_sf.png");
00206   g2->GraphWrite("tmp_demo_system_3_modular_c1.png");
00207   k1->GraphWrite("tmp_demo_specification_3_modular_sf.png");
00208   k2->GraphWrite("tmp_demo_specification_3_modular_c1.png");
00209 
00210   // Set up vector containers
00211   plant.Append(g1);
00212   plant.Append(g2);
00213   spec.Append(k1);
00214   spec.Append(k2);
00215   // Fix ownership
00216   plant.TakeOwnership();
00217   spec.TakeOwnership();
00218   
00219   // Report to console
00220   std::cout << "# b) run diagnosability test (expect result PASS)\n";
00221 
00222   // Test for decentralized diagnosability of the overall system
00223   if(IsModularDiagnosable(plant, spec, report)) {
00224     cout << "The overall system G is modularly diagnosable with respect to overall specification K." << endl;
00225     cout << report << endl;
00226   } else {
00227     cout << "The overall system G is not modularly diagnosable with respect to overall specification K." << endl;
00228     cout << report << endl;
00229   }
00230   
00231   // **********************************************************************
00232   //
00233   // Modular Diagnoser Computation 
00234   //
00235   
00236   // Report to console
00237   std::cout << "# c) compute modular diagnoser\n";
00238   diag.Clear();
00239   // Diagnoser synthesis
00240   ModularDiagnoser(plant,spec,diag,report);
00241 
00242   // Write diagnoser moduls to gen files (for html docu)
00243   diag.At(0).Write("tmp_diag_diagnoser_3_modular_sf.gen");
00244   diag.At(1).Write("tmp_diag_diagnoser_3_modular_c1.gen");
00245 
00246   // Write diagnoser to png files (for inspection)
00247   diag.At(0).GraphWrite("tmp_demo_diagnoser_3_modular_sf.png");
00248   diag.At(1).GraphWrite("tmp_demo_diagnoser_3_modular_c1.png");
00249 
00250   // Record test case
00251   FAUDES_TEST_DUMP("modular sf/c1",diag);
00252   
00253   // Report to console
00254   std::cout << "# done \n";
00255   std::cout << "################################\n";
00256 
00257   // Clear vectors
00258   // Note: includes releasing member memory
00259   plant.Clear();
00260   spec.Clear();
00261   
00262   // Done
00263   cout << endl;
00264   return 0;
00265 }

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen