diag_1_eventdiagnosis.cppGo to the documentation of this file.00001 /** @file diag_1_eventdiagnosis.cpp 00002 Demonstrate diagnoser structure and methods for std event diagnosability. 00003 @ingroup Tutorials 00004 @include diag_1_eventdiagnosis.cpp 00005 */ 00006 00007 #include "diag_include.h" 00008 00009 00010 using namespace std; 00011 using namespace faudes; 00012 00013 00014 int main(void) { 00015 00016 // ******************** Basic usage of diagnoser objects 00017 00018 // The diagnoser is derived from the basic generator and, hence, 00019 // provides std access to states, events and transitions 00020 00021 // Declare diagnoser 00022 Diagnoser d1, d2; 00023 00024 // Assign name to diagnoser d1 00025 d1.Name("Diagnoser"); 00026 00027 // Insert some states in diagnoser d1 00028 Idx s1 = d1.InsInitState("s1"); 00029 Idx s2 = d1.InsState("s2"); 00030 Idx s3 = d1.InsState("s3"); 00031 00032 // Insert some events in diagnoser d1 00033 Idx eventA = d1.InsEvent("a"); 00034 Idx eventB = d1.InsEvent("b"); 00035 00036 // Set transitions in diagnoser d1 00037 d1.SetTransition(s1, eventA, s2); 00038 d1.SetTransition(s2, eventB, s3); 00039 d1.SetTransition(s3, eventA, s3); 00040 00041 00042 // ******************** Failure type map of diagnoser objects 00043 00044 // Declare some two failure event sets 00045 EventSet failures1, failures2; 00046 00047 failures1.Insert("WPblocked"); 00048 failures1.Insert("WPfelldown"); 00049 failures2.Insert("sfRunsContinuously"); 00050 failures2.Insert("cb1RunsContinuously"); 00051 00052 // Introduce failure types to diagnoser 00053 Idx F1 = d1.InsFailureTypeMapping("F1", failures1); 00054 Idx F2 = d1.InsFailureTypeMapping("F2", failures2); 00055 00056 // delete all failure types 00057 // d1.ClearFailureTypeMap(); 00058 00059 00060 // ******************** State estimate attributes of diagnoser objects 00061 00062 // Attatch generator state estimates to the diagnoser states 00063 00064 // Diagnoser state s1 carries the generator state estimate 1N 00065 d1.InsStateLabelMapping(s1,1,DiagLabelSet::IndexOfLabelN()); 00066 // Diagnoser state s2 carries the generator state estimate 3F1, 5N 00067 d1.InsStateLabelMapping(s2,3,F1); 00068 d1.InsStateLabelMapping(s2,5,DiagLabelSet::IndexOfLabelN()); 00069 // Diagnoser state s3 carries the generator state estimate 7F1F2, 9A 00070 d1.InsStateLabelMapping(s3,7,F1); 00071 d1.InsStateLabelMapping(s3,7,F2); 00072 d1.InsStateLabelMapping(s3,9,DiagLabelSet::IndexOfLabelA()); 00073 00074 // delete all state estimates 00075 // d1.ClearStateAttributes(); 00076 00077 // ******************** Diagnoser file io 00078 00079 // write diagnoser d1 to file 00080 d1.Write("tmp_diag_diagnoser_1.gen"); 00081 d1.GraphWrite("tmp_demo_diagnoser_1.svg"); 00082 00083 // Dead diagnoser d2 from file 00084 d2.Read("tmp_diag_diagnoser_1.gen"); 00085 00086 // Report to console 00087 std::cout << "################################\n"; 00088 std::cout << "# tutorial, diagnoser d2\n"; 00089 d2.Write(); 00090 std::cout << "################################\n"; 00091 00092 00093 // Report to console 00094 AttributeDiagnoserState currDStateAttr; 00095 TaIndexSet<DiagLabelSet> currDStateMap; 00096 TaIndexSet<DiagLabelSet>::Iterator currDStateMapIt; 00097 currDStateAttr = d2.StateAttribute(s3); 00098 currDStateMap = currDStateAttr.DiagnoserStateMap(); 00099 00100 std::cout << "################################\n"; 00101 std::cout << "# tutorial, parsing state estimates for state s3 of d2\n"; 00102 for(currDStateMapIt = currDStateMap.Begin(); currDStateMapIt != currDStateMap.End(); ++ currDStateMapIt){ 00103 cout << *currDStateMapIt << " " << currDStateMap.Attribute(*currDStateMapIt).ToString() << endl; 00104 } 00105 std::cout << "################################\n"; 00106 00107 // Test protocol 00108 FAUDES_TEST_DUMP("diagnoser d2", d2); 00109 00110 // ******************** Failure typemaps 00111 00112 // AttributeFailureEvents stores a set of failure and indicator events 00113 AttributeFailureEvents attrFE; 00114 00115 // Add indicator events to attrFE 00116 attrFE.mIndicatorEvents.Insert("Indicator1"); 00117 attrFE.mIndicatorEvents.Insert("Indicator2"); 00118 // Add failure events to attrFE 00119 attrFE.mFailureEvents.Insert("Failure1"); 00120 attrFE.mFailureEvents.Insert("Failure2"); 00121 attrFE.mFailureEvents.Insert("Failure3"); 00122 00123 // Declare a AttributeFailureTypeMap (to store the failure and indicator partition) 00124 AttributeFailureTypeMap failureTypes; 00125 00126 // Insert attrFE in the partition and associate it with the failure type name "FailureType1" 00127 failureTypes.mFailureTypeMap.Insert("FailureType1",attrFE); 00128 00129 // Write the failure and indicator partition to console and file 00130 std::cout << "################################\n"; 00131 std::cout << "# tutorial, failure types\n"; 00132 failureTypes.Write(); 00133 std::cout << "################################\n"; 00134 failureTypes.Write("tmp_diag_failure_typemap_2.txt"); 00135 00136 // ******************** Event-diagnosability with respect to a failure partition 00137 00138 // Declare needed variables 00139 System gen; 00140 Diagnoser diag; 00141 AttributeFailureTypeMap failurePartition; 00142 string reportString; 00143 00144 // Report to console 00145 std::cout << "################################\n"; 00146 std::cout << "# diagnosability, failure types, system 4 \n"; 00147 std::cout << "# a) read data \n"; 00148 00149 // Read input generator and failure/indicator partition from file 00150 gen.Read("data/diag_system_4.gen"); 00151 failureTypes.Read("data/diag_failure_typemap_4.txt"); 00152 00153 // Write input generator to png file 00154 gen.GraphWrite("tmp_demo_system_4.png"); 00155 00156 // Report to console 00157 std::cout << "# b) run diagnosability test (expect result FALSE and warning)\n"; 00158 00159 // Test generator gen for diagnosability with respect to failure partition failureTypes 00160 bool isdiagft=IsEventDiagnosable(gen,failureTypes,reportString); 00161 if(isdiagft){ 00162 cout << "System is diagnosable." << endl; 00163 } else { 00164 cout << "System is not diagnosable." << endl; 00165 cout << reportString << endl; 00166 } 00167 00168 // Report to console 00169 std::cout << "# c) run i-diagnosability test (expect result TRUE)\n"; 00170 00171 // Test protocol 00172 FAUDES_TEST_DUMP("diag failuretype",isdiagft); 00173 00174 // Test generator gen for I-diagnosability with respect to failure partition failureTypes 00175 bool isdiagie=IsIndicatorEventDiagnosable(gen,failureTypes,reportString); 00176 if(isdiagie) { 00177 cout << "System is I-diagnosable." << endl; 00178 } else { 00179 cout << "System is not I-diagnosable." << endl; 00180 cout << reportString << endl; 00181 } 00182 00183 // Report to console 00184 std::cout << "# done \n"; 00185 std::cout << "################################\n"; 00186 00187 // Test protocol 00188 FAUDES_TEST_DUMP("diag indicator",isdiagie); 00189 00190 00191 // ******************** Event-diagnoser synthesis w.r.t. failure types 00192 00193 // Report to console 00194 std::cout << "################################\n"; 00195 std::cout << "# tutorial, event-diagnoser synthesis, wrt failure types\n"; 00196 00197 // Read the generator from file 00198 gen.Read("data/diag_system_3.gen"); 00199 00200 // Read the failure partition from file 00201 failurePartition.Read("data/diag_failure_typemap_3.txt"); 00202 00203 // Write generator to file 00204 gen.Write("tmp_diag_system_3.gen"); 00205 00206 // compute the diagnoser 00207 EventDiagnoser(gen,failurePartition,diag); 00208 00209 // Write the diagnoser to file 00210 diag.Write("tmp_diag_diagnoser_3.gen"); 00211 00212 // Report result 00213 std::cout << "Diagnoser statistics\n"; 00214 diag.SWrite(); 00215 std::cout << "################################\n"; 00216 00217 // Test protocol 00218 FAUDES_TEST_DUMP("synthesis failure types", diag); 00219 00220 00221 return 0; 00222 } 00223 libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |