diag_4_decentralizeddiagnosis.cpp

Go to the documentation of this file.
00001 /** @file diag_4_decentralizeddiagnosis.cpp
00002 Illustrate decentralized diagnosability test and synthesis. 
00003 @ingroup Tutorials
00004 @include diag_4_decentralizeddiagnosis.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 plant, spec;  
00017   EventSet *alph1, *alph2;
00018   EventSetVector alphVector;
00019   string report;
00020 
00021   // **********************************************************************
00022   //
00023   // Decentralized Language-Diagnosability Verification (condition is not fulfilled)
00024   //
00025   
00026   // Report to console
00027   std::cout << "################################\n";
00028   std::cout << "# decentralized language-diagnosability (system 1)\n";
00029   std::cout << "# a) read data \n";
00030 
00031   // Read subsystems and associated specifications and abstraction alphabets from files
00032   plant = System("data/diag_system_4_decentralized1.gen");
00033   spec = System("data/diag_specification_4_decentralized1.gen");
00034   
00035   // Write subsystems and specifications to gen files (for html docu)
00036   plant.Write("tmp_diag_system_4_decentralized1.gen");
00037   spec.Write("tmp_diag_specification_4_decentralized1.gen");
00038 
00039   // Write subsystems and specifications to png files (for inspection)
00040   plant.GraphWrite("tmp_demo_system_4_decentralized1.png");
00041   spec.GraphWrite("tmp_demo_specification_4_decentralized1.png");
00042 
00043   // Relevant abstractions for the modular diagnosability verification (for HTML docu)
00044 
00045   alph1 = new EventSet("data/diag_obsAlph_4_decentralized1_1.alph");
00046   alph2 = new EventSet("data/diag_obsAlph_4_decentralized1_2.alph");
00047   alphVector.Append(alph1 );
00048   alphVector.Append(alph2 );
00049 
00050 
00051   // Report to console
00052   std::cout << "# b) run decentralized diagnosability test (expect result FAIL)\n";
00053 
00054   // Test for modular diagnosability of the overall system
00055   bool ok=IsCoDiagnosable(plant, spec, alphVector);
00056   if(ok) {
00057     cout << "The overall system G is co-diagnosable with respect to overall specification K." << endl;
00058   } else {
00059     cout << "The overall system G is not co-diagnosable with respect to overall specification K." << endl;
00060   }
00061   // Compute local decentralzed diagnosers for the example
00062   GeneratorVector diagVector;
00063   DecentralizedDiagnoser(plant,spec,alphVector,diagVector);
00064   // Write diagnosers to .gen file (for html docu)
00065   diagVector.At(0).Write("tmp_diag_diagnoser_4_decentralized1_1.gen");
00066   diagVector.At(1).Write("tmp_diag_diagnoser_4_decentralized1_2.gen");
00067   // Write diagnosers to png (for inspection)
00068   diagVector.At(0).GraphWrite("tmp_demo_diagnoser_4_decentralized1_1.png");
00069   diagVector.At(1).GraphWrite("tmp_demo_diagnoser_4_decentralized1_2.png");
00070   
00071   // Record test case
00072   FAUDES_TEST_DUMP("decentralized 1",ok);
00073 
00074     // **********************************************************************
00075   //
00076   // Decentralized Language-Diagnosability Verification (condition is fulfilled)
00077   //
00078     // Report to console
00079   std::cout << "################################\n";
00080   std::cout << "# decentralized language-diagnosability (system 2)\n";
00081   std::cout << "# a) read data \n";
00082 
00083   // Read subsystems and associated specifications and abstraction alphabets from files
00084   plant = System("data/diag_system_4_decentralized2.gen");
00085   spec = System("data/diag_specification_4_decentralized2.gen");
00086   
00087   // Write subsystems and specifications to gen files (for html docu)
00088   plant.Write("tmp_diag_system_4_decentralized2.gen");
00089   spec.Write("tmp_diag_specification_4_decentralized2.gen");
00090 
00091   // Write subsystems and specifications to png files (for inspection)
00092   plant.GraphWrite("tmp_demo_system_4_decentralized2.png");
00093   spec.GraphWrite("tmp_demo_specification_4_decentralized2.png");
00094 
00095   // Relevant abstractions for the modular diagnosability verification (for HTML docu)
00096   alphVector.Clear();
00097   alph1 = new EventSet("data/diag_obsAlph_4_decentralized2_1.alph");
00098   alph2 = new EventSet("data/diag_obsAlph_4_decentralized2_2.alph");
00099   alphVector.Append(alph1 );
00100   alphVector.Append(alph2 );
00101 
00102   // Report to console
00103   std::cout << "# b) run decentralized diagnosability test (expect result FAIL)\n";
00104 
00105   // Test for modular diagnosability of the overall system
00106   ok=IsCoDiagnosable(plant, spec, alphVector);
00107   if(ok) {
00108     cout << "The overall system G is co-diagnosable with respect to overall specification K." << endl;
00109     cout << report << endl;
00110   } else {
00111     cout << "The overall system G is not co-diagnosable with respect to overall specification K." << endl;
00112     cout << "The overall system G is not co-diagnosable with respect to overall specification K." << endl;
00113     cout << report << endl;
00114   }
00115   diagVector.Clear();
00116   // Compute decentralized diagnosers for the local sites 
00117   DecentralizedDiagnoser(plant,spec,alphVector,diagVector);
00118   // Write diagnosers to .gen file (for html docu)
00119   diagVector.At(0).Write("tmp_diag_diagnoser_4_decentralized2_1.gen");
00120   diagVector.At(1).Write("tmp_diag_diagnoser_4_decentralized2_2.gen");
00121   // Write diagnosers to png (for inspection)
00122   diagVector.At(0).GraphWrite("tmp_demo_diagnoser_4_decentralized2_1.png");
00123   diagVector.At(1).GraphWrite("tmp_demo_diagnoser_4_decentralized2_2.png");
00124   // Record test case
00125   FAUDES_TEST_DUMP("decentralized 2",ok);
00126 
00127   // **********************************************************************
00128   //
00129   // Decentralized Language-Diagnosability Verification (condition is not fulfilled)
00130   //
00131     // Report to console
00132   std::cout << "################################\n";
00133   std::cout << "# decentralized language-diagnosability (system 3)\n";
00134   std::cout << "# a) read data \n";
00135 
00136   // Read subsystems and associated specifications and abstraction alphabets from files
00137   plant = System("data/diag_system_2_language.gen");
00138   spec = System("data/diag_specification_2_language.gen");
00139 
00140   // Write subsystems and specifications to png files (for inspection)
00141   plant.GraphWrite("tmp_demo_system_2_language.png");
00142   spec.GraphWrite("tmp_demo_specification_2_language.png");
00143 
00144   // Relevant abstractions for the modular diagnosability verification (for HTML docu)
00145   alphVector.Clear();
00146   alph1 = new EventSet;
00147   alph1->Insert("alpha");
00148   alph1->Insert("beta");
00149   alph2 = new EventSet();
00150   alph2->Insert("alpha");
00151   alphVector.Append(alph1 );
00152   alphVector.Append(alph2 );
00153 
00154   // Report to console
00155   std::cout << "# b) run decentralized diagnosability test (expect result FAIL)\n";
00156 
00157   // Test for modular diagnosability of the overall system
00158   ok=IsCoDiagnosable(plant, spec, alphVector);
00159   if(ok) {
00160     cout << "The overall system G is co-diagnosable with respect to overall specification K." << endl;
00161     cout << report << endl;
00162   } else {
00163     cout << "The overall system G is not co-diagnosable with respect to overall specification K." << endl;
00164     cout << report << endl;
00165   }
00166   
00167   // Record test case
00168   FAUDES_TEST_DUMP("decentralized 3",ok);
00169  
00170  
00171    // **********************************************************************
00172   //
00173   // Decentralized Language-Diagnosability Verification for Application Example (condition is  fulfilled)
00174   //
00175     // Report to console
00176   std::cout << "################################\n";
00177   std::cout << "# decentralized language-diagnosability (system sf/c1)\n";
00178   std::cout << "# a) read data \n";
00179 
00180   // Read subsystems and associated specifications and abstraction alphabets from files
00181   System sf,c1,sfc1Spec;
00182   sf = System("data/diag_system_4_decentralized_sf.gen");
00183   c1 = System("data/diag_system_4_decentralized_c1.gen");
00184   
00185   // Write generators (for html docu)
00186   sf.Write("tmp_diag_system_4_decentralized_sf.gen");
00187   c1.Write("tmp_diag_system_4_decentralized_c1.gen");
00188   // Write generators (for inspection)
00189   sf.GraphWrite("tmp_demo_system_4_decentralized_sf.png");
00190   c1.GraphWrite("tmp_demo_system_4_decentralized_c1.png");
00191   sfc1Spec = Generator("data/diag_specification_4_decentralized_sfc1.gen");
00192   aParallel(sf,c1,plant);
00193   aParallel(plant,sfc1Spec,spec);
00194 
00195   // Write subsystems and specifications to png files (for inspection)
00196   plant.GraphWrite("tmp_demo_system_4_decentralized_sfc1.png");
00197   spec.GraphWrite("tmp_demo_specification_4_decentralized_sfc1.png");
00198 
00199   // Observable events for the system components
00200   alphVector.Clear();
00201   alph1 = new EventSet();
00202   *alph1 = plant.ObservableEvents() * sf.Alphabet();
00203   alph2 = new EventSet();
00204   *alph2 = plant.ObservableEvents() * c1.Alphabet();
00205   alphVector.Append(alph1 );
00206   alphVector.Append(alph2 );
00207 
00208   // Report to console
00209   std::cout << "# b) run decentralized diagnosability test (expect result PASS)\n";
00210 
00211   // Test for modular diagnosability of the overall system
00212   ok=IsCoDiagnosable(plant, spec, alphVector);
00213   if(ok) {
00214     cout << "The overall system G is co-diagnosable with respect to overall specification K." << endl;
00215     cout << report << endl;
00216   } else {
00217     cout << "The overall system G is not co-diagnosable with respect to overall specification K." << endl;
00218     cout << report << endl;
00219   }
00220   // Compute decentralized diagnosers for the local sites 
00221   SystemVector plantVector;
00222   plantVector.Append(&sf);
00223   plantVector.Append(&c1);
00224   diagVector.Clear();
00225   DecentralizedModularDiagnoser(plantVector,spec,diagVector);
00226   // Write diagnosers to .gen file (for html docu)
00227   diagVector.At(0).Write("tmp_diag_diagnoser_4_decentralized_sf.gen");
00228   diagVector.At(1).Write("tmp_diag_diagnoser_4_decentralized_c1.gen");
00229   // Write diagnosers to png (for inspection)
00230   diagVector.At(0).GraphWrite("tmp_demo_diagnoser_4_decentralized_sf.png");
00231   diagVector.At(1).GraphWrite("tmp_demo_diagnoser_4_decentralized_c1.png"); 
00232   // Record test case
00233   FAUDES_TEST_DUMP("decentralized sf/c1",ok);
00234 
00235   
00236   // // **********************************************************************
00237   //
00238   // Abstraction-based Decentralized Language-Diagnosability Verification for Application Example (condition is  fulfilled)
00239   //
00240     // Report to console
00241   std::cout << "################################\n";
00242   std::cout << "# Abstraction-based decentralized language-diagnosability (system sf/c1)\n";
00243   std::cout << "# a) read data \n";
00244 
00245   // Compute abstracted system components and verify the loop-preserving observer condition
00246   System sfAbst, c1Abst;
00247   EventSet abstAlph;
00248   abstAlph.Read("data/diag_abstAlph_4_decentralized_sf.alph","Alphabet");
00249   if(IsLoopPreservingObserver(sf,abstAlph) )
00250   std::cout << "The abstraction for SF is a loop-preserving observer" << std::endl;
00251   else 
00252   std::cout << "The abstraction for SF is not a loop-preserving observer" << std::endl;
00253   aProject(sf,abstAlph,sfAbst);
00254   sfAbst.Write("tmp_diag_system_4_decentralized_sf_abstracted.gen");
00255   sfAbst.GraphWrite("tmp_demo_system_4_decentralized_sf_abstracted.png");
00256   abstAlph.Read("data/diag_abstAlph_4_decentralized_c1.alph","Alphabet");
00257   if(IsLoopPreservingObserver(c1,abstAlph) )
00258   std::cout << "The abstraction for C1 is a loop-preserving observer" << std::endl;
00259   else 
00260   std::cout << "The abstraction for C1 is not a loop-preserving observer" << std::endl;
00261 
00262   aProject(c1,abstAlph,c1Abst);
00263   c1Abst.Write("tmp_diag_system_4_decentralized_c1_abstracted.gen");
00264   c1Abst.GraphWrite("tmp_demo_system_4_decentralized_c1_abstracted.png");
00265   sfc1Spec = Generator("data/diag_specification_4_decentralized_sfc1.gen");
00266   aParallel(sfAbst,c1Abst,plant);
00267   aParallel(plant,sfc1Spec,spec);
00268 
00269   // Write subsystems and specifications to png files (for inspection)
00270   plant.GraphWrite("tmp_demo_system_4_decentralized_sfc1_abstracted.png");
00271   spec.GraphWrite("tmp_demo_specification_4_decentralized_sfc1_abstract.png");
00272 
00273   // Observable events for the system components
00274   alphVector.Clear();
00275   *alph1 = plant.ObservableEvents() * sfAbst.Alphabet();
00276   *alph2 = plant.ObservableEvents() * c1Abst.Alphabet();
00277   alphVector.Append(alph1);
00278   alphVector.Append(alph2);
00279 
00280   // Report to console
00281   std::cout << "# b) run decentralized diagnosability test (expect result PASS)\n";
00282 
00283   // Test for modular diagnosability of the overall system
00284   ok=IsCoDiagnosable(plant, spec, alphVector);
00285   if(ok) {
00286     cout << "The overall system G is co-diagnosable with respect to overall specification K." << endl;
00287     cout << report << endl;
00288   } else {
00289     cout << "The overall system G is not co-diagnosable with respect to overall specification K." << endl;
00290     cout << report << endl;
00291   }
00292   // // Record test case
00293   // FAUDES_TEST_DUMP("decentralized abstracted sf/c1",ok);
00294 
00295   
00296   // // Done
00297   // cout << endl;
00298   return 0;
00299 }

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