diag_3_modulardiagnosis.cpp File Reference

Illustrate modular diagnosability test and synthesis. More...

#include "libfaudes.h"

Go to the source code of this file.

Functions

int main (void)

Detailed Description

Illustrate modular diagnosability test and synthesis.

/** @file diag_3_modulardiagnosis.cpp
Illustrate modular diagnosability test and synthesis. 
@ingroup Tutorials
@include diag_3_modulardiagnosis.cpp
*/

#include "libfaudes.h"

using namespace std;
using namespace faudes;


int main(void) {

  // Declare common variables
  System *g1, *g2, *k1, *k2;
  System g12, k12; 
  SystemVector plant;
  GeneratorVector spec;
  GeneratorVector diag;    
  string report;

  // **********************************************************************
  //
  // Modular Language-Diagnosability Verification (condition is fulfilled)
  //
  
  // Report to console
  std::cout << "################################\n";
  std::cout << "# modular language-diagnosability (system 1/2)\n";
  std::cout << "# a) read data \n";

  // Read subsystems and associated specifications and abstraction alphabets from files
  g1 = new System("data/diag_system_3_modular1.gen");
  g2 = new System("data/diag_system_3_modular2.gen");
  k1 = new System("data/diag_specification_3_modular1.gen");
  k2 = new System("data/diag_specification_3_modular2.gen");
  
  // Write subsystems and specifications to gen files (for html docu)
  g1->Write("tmp_diag_system_3_modular1.gen");
  g2->Write("tmp_diag_system_3_modular2.gen");
  k1->Write("tmp_diag_specification_3_modular1.gen");
  k2->Write("tmp_diag_specification_3_modular2.gen");

  // Write subsystems and specifications to png files (for inspection)
  g1->GraphWrite("tmp_demo_system_3_modular1.png");
  g2->GraphWrite("tmp_demo_system_3_modular2.png");
  k1->GraphWrite("tmp_demo_specification_3_modular1.png");
  k2->GraphWrite("tmp_demo_specification_3_modular2.png");

  // Relevant abstractions for the modular diagnosability verification (for HTML docu)
  EventSet abstAlph;
  abstAlph.Read("data/diag_abstrAlph_3_modular12.alph");
  Generator g1Abst, g2Abst;
  Project(*g1,abstAlph,g1Abst);
  Project(*g2,abstAlph,g2Abst);
  g1Abst.Write("tmp_diag_system_3_modular1_hat.gen");
  g2Abst.Write("tmp_diag_system_3_modular2_hat.gen"); 

  // Set up vector containers
  plant.Append(g1);
  plant.Append(g2);
  spec.Append(k1);
  spec.Append(k2);
  // Fix ownership 
  plant.TakeOwnership();
  spec.TakeOwnership();

  // Report to console
  std::cout << "# b) run modular diagnosability test (expect result PASS)\n";

  // Test for modular diagnosability of the overall system
  bool ok=IsModularDiagnosable(plant, spec, report);
  if(ok) {
    cout << "The overall system G is modularly diagnosable with respect to overall specification K." << endl;
    cout << report << endl;
  } else {
    cout << "The overall system G is not modularly diagnosable with respect to overall specification K." << endl;
    cout << report << endl;
  }
  
  // Record test case
  FAUDES_TEST_DUMP("modular 1/2",ok);


  // **********************************************************************
  //
  // Modular Diagnoser Computation 
  //
  
  // Report to console
  std::cout << "# c) compute modular diagnoser\n";
  
  // Diagnoser synthesis
  ModularDiagnoser(plant,spec,diag,report);

  // Write diagnoser moduls to gen files (for html docu)
  diag.At(0).Write("tmp_diag_diagnoser_3_modular1.gen");
  diag.At(1).Write("tmp_diag_diagnoser_3_modular2.gen");

  // Write diagnoser to png files (for inspection)
  diag.At(0).GraphWrite("tmp_demo_diagnoser_3_modular1.png");
  diag.At(1).GraphWrite("tmp_demo_diagnoser_3_modular2.png");

  // Record test case
  FAUDES_TEST_DUMP("modular 1/2",diag);

  // Report to console
  std::cout << "# done \n";
  std::cout << "################################\n";

  // Clear vectors
  // Note: includes releasing member memory
  plant.Clear();
  spec.Clear();


  // **********************************************************************
  // **********************************************************************
  //
  // Modular Diagnosability Verification (Condition is not fulfilled)
  //

  // Report to console
  std::cout << "################################\n";
  std::cout << "# modular diagnosability (system 3/4)\n";
  std::cout << "# a) read data \n";
  
  // Read subsystems and associated specifications and abstraction alphabets from files
  g1 = new System("data/diag_system_3_modular3.gen");
  g2 = new System("data/diag_system_3_modular4.gen");
  k1 = new System("data/diag_specification_3_modular3.gen");
  k2 = new System("data/diag_specification_3_modular4.gen");
  
  // Write subsystems and specifications to gen files (for html docu)
  g1->Write("tmp_diag_system_3_modular3.gen");
  g2->Write("tmp_diag_system_3_modular4.gen");
  k1->Write("tmp_diag_specification_3_modular3.gen");
  k2->Write("tmp_diag_specification_3_modular4.gen");

  // Write subsystems and specifications to png files (for inspection)
  g1->GraphWrite("tmp_demo_system_3_modular3.png");
  g2->GraphWrite("tmp_demo_system_3_modular4.png");
  k1->GraphWrite("tmp_demo_specification_3_modular3.png");
  k2->GraphWrite("tmp_demo_specification_3_modular4.png");
  
  // Set up vector containers
  plant.Append(g1);
  plant.Append(g2);
  spec.Append(k1);
  spec.Append(k2);
  // Fix ownership
  plant.TakeOwnership();
  spec.TakeOwnership();
  
  // Report to console
  std::cout << "# b) run modular diagnosability test (expect result FAIL)\n";

  // Test for modular diagnosability of the overall system
  ok=IsModularDiagnosable(plant, spec, report);
  if(ok) {
    cout << "The overall system G is modularly diagnosable with respect to overall specification K." << endl;
    cout << report << endl;
  } else {
    cout << "The overall system G is not modularly diagnosable with respect to overall specification K." << endl;
    cout << report << endl;
  }
  
  // Record test case
  FAUDES_TEST_DUMP("modular 3/4",ok);

  // Report to console
  std::cout << "# done \n";
  std::cout << "################################\n";

  // Clear vectors
  // Note: includes releasing member memory
  plant.Clear();
  spec.Clear();

  // **********************************************************************
  // **********************************************************************
  //
  // Modular diagnosability Verification (application example) 
  //

  // Report to console
  std::cout << "################################\n";
  std::cout << "# modular diagnosability (system sf/cb1a)\n";
  std::cout << "# a) read data \n";

  // Read subsystems and associated specifications and abstraction alphabets from files
  g1 = new System("data/diag_system_3_modular_sf.gen");
  g2 = new System("data/diag_system_3_modular_c1.gen");
  k1 = new System("data/diag_specification_3_modular_sf.gen");
  k2 = new System("data/diag_specification_3_modular_c1.gen");
  
  // Write subsystems and specifications to gen files (for html docu)
  g1->Write("tmp_diag_system_3_modular_sf.gen");
  g2->Write("tmp_diag_system_3_modular_c1.gen");
  k1->Write("tmp_diag_specification_3_modular_sf.gen");
  k2->Write("tmp_diag_specification_3_modular_c1.gen");

  // Write subsystems and specifications to png files (for inspection)
  g1->GraphWrite("tmp_demo_system_3_modular_sf.png");
  g2->GraphWrite("tmp_demo_system_3_modular_c1.png");
  k1->GraphWrite("tmp_demo_specification_3_modular_sf.png");
  k2->GraphWrite("tmp_demo_specification_3_modular_c1.png");

  // Set up vector containers
  plant.Append(g1);
  plant.Append(g2);
  spec.Append(k1);
  spec.Append(k2);
  // Fix ownership
  plant.TakeOwnership();
  spec.TakeOwnership();
  
  // Report to console
  std::cout << "# b) run diagnosability test (expect result PASS)\n";

  // Test for decentralized diagnosability of the overall system
  if(IsModularDiagnosable(plant, spec, report)) {
    cout << "The overall system G is modularly diagnosable with respect to overall specification K." << endl;
    cout << report << endl;
  } else {
    cout << "The overall system G is not modularly diagnosable with respect to overall specification K." << endl;
    cout << report << endl;
  }
  
  // **********************************************************************
  //
  // Modular Diagnoser Computation 
  //
  
  // Report to console
  std::cout << "# c) compute modular diagnoser\n";
  diag.Clear();
  // Diagnoser synthesis
  ModularDiagnoser(plant,spec,diag,report);

  // Write diagnoser moduls to gen files (for html docu)
  diag.At(0).Write("tmp_diag_diagnoser_3_modular_sf.gen");
  diag.At(1).Write("tmp_diag_diagnoser_3_modular_c1.gen");

  // Write diagnoser to png files (for inspection)
  diag.At(0).GraphWrite("tmp_demo_diagnoser_3_modular_sf.png");
  diag.At(1).GraphWrite("tmp_demo_diagnoser_3_modular_c1.png");

  // Record test case
  FAUDES_TEST_DUMP("modular sf/c1",diag);
  
  // Report to console
  std::cout << "# done \n";
  std::cout << "################################\n";

  // Clear vectors
  // Note: includes releasing member memory
  plant.Clear();
  spec.Clear();
  
  // Done
  cout << endl;
  return 0;
}

Definition in file diag_3_modulardiagnosis.cpp.


Function Documentation

int main ( void   ) 

Definition at line 13 of file diag_3_modulardiagnosis.cpp.

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