hio_environment.cppGo to the documentation of this file.00001 /** @file hio_environment.cpp Generator with I/O-environment attributes */ 00002 00003 /* Hierarchical IO Systems Plug-In for FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2006 Sebastian Perk 00006 Copyright (C) 2006 Thomas Moor 00007 Copyright (C) 2006 Klaus Schmidt 00008 00009 */ 00010 00011 #include "hio_environment.h" 00012 00013 namespace faudes { 00014 00015 // IsHioEnvironmentForm() 00016 bool IsHioEnvironmentForm(HioEnvironment& rHioEnvironment, 00017 StateSet& rQYe, 00018 StateSet& rQUe, 00019 StateSet& rQUl, 00020 StateSet& rQYlUe, 00021 EventSet& rErrEvSet, 00022 TransSet& rErrTrSet, 00023 StateSet& rErrStSet, 00024 std::string& rReportStr) 00025 { 00026 FD_DF("IsHioEnvironmentForm("<< rHioEnvironment.Name() << ",...)"); 00027 00028 // prepare results 00029 rQYe.Clear(); 00030 rQUe.Clear(); 00031 rQUl.Clear(); 00032 rQYlUe.Clear(); 00033 00034 rErrEvSet.Clear(); 00035 rErrEvSet.Name("rErrEvSet"); 00036 00037 rErrTrSet.Clear(); 00038 rErrTrSet.Name("rErrTrSet"); 00039 00040 rErrStSet.Clear(); 00041 rErrStSet.Name("rErrStSet"); 00042 00043 // used to locally store error states/transitions on each condition 00044 StateSet locErrStSet; 00045 TransSet locErrTrSet; 00046 00047 rReportStr.clear(); 00048 00049 // meant to be set false on violation of any condition: 00050 bool finalResult = true; 00051 // used to locally store result on each condition 00052 bool localResult = true; 00053 00054 // helpers 00055 00056 EventSet ye = rHioEnvironment.YeEvents(); 00057 EventSet ue = rHioEnvironment.UeEvents(); 00058 EventSet yl = rHioEnvironment.YlEvents(); 00059 EventSet ul = rHioEnvironment.UlEvents(); 00060 00061 StateSet initStates = rHioEnvironment.InitStates(); 00062 StateSet accessibleStates = rHioEnvironment.AccessibleSet(); 00063 StateSet deadEnds; 00064 00065 EventSet::Iterator evit; 00066 StateSet::Iterator sit; 00067 TransSet::Iterator tit; 00068 00069 // Info string header 00070 rReportStr.append("#########################################################\n"); 00071 rReportStr.append("########## IsHioEnvironmentForm("+rHioEnvironment.Name()+",...) - test results:\n"); 00072 00073 /**************************** Precondition: determinism ***********************/ 00074 // HioEnvironment must be deterministic 00075 if(!rHioEnvironment.IsDeterministic()){ 00076 rReportStr.append("##### fail: generator is not deterministic!\n"); 00077 if(initStates.Size()>1) { 00078 rErrStSet = initStates; 00079 rReportStr.append("##### (amongst others, there is more than one initial state)\n"); 00080 } 00081 finalResult = false; 00082 } 00083 00084 00085 rReportStr.append("#####\n"); 00086 00087 // test all conditions verifying I/O-environment form: 00088 00089 /**************************** Condition (i) ***********************/ 00090 localResult = true; 00091 rReportStr.append("########## Condition (i):\n"); 00092 00093 //YE, UE, YL, UL nonempty? 00094 if (ye.Empty()) { 00095 rReportStr.append("##### fail: empty YE alphabet.\n"); 00096 localResult=false; 00097 finalResult = false; 00098 } 00099 if (ue.Empty()) { 00100 rReportStr.append("##### fail: empty UE alphabet.\n"); 00101 localResult=false; 00102 finalResult = false; 00103 } 00104 if (yl.Empty()) { 00105 rReportStr.append("##### fail: empty YL alphabet.\n"); 00106 localResult=false; 00107 finalResult = false; 00108 } 00109 if (ul.Empty()) { 00110 rReportStr.append("##### fail: empty UL alphabet.\n"); 00111 localResult=false; 00112 finalResult = false; 00113 } 00114 00115 // check for disjoint eventsets YE, YL, UE, UL and for 00116 // YE u YL u UE u UL == Sigma, ie unique HioEventFlags. 00117 // note: testing disjoint E- and L-Alphabet is sufficient 00118 // as properties U and Y are exclusive by construltion. 00119 00120 rErrEvSet=(rHioEnvironment.EEvents()*rHioEnvironment.LEvents()) + (rHioEnvironment.Alphabet()-rHioEnvironment.EEvents()-rHioEnvironment.LEvents()); 00121 00122 // In case of failing condition (i) further inspection is omitted, as too many consecutive faults are expected. 00123 if(!rErrEvSet.Empty()){ 00124 rReportStr.append("##### fail: found events with missing or ambiguous attribute:\n"); 00125 rReportStr.append(rErrEvSet.ToString()+"\n"); 00126 rReportStr.append("##### Condition (i) failed.\n"); 00127 rReportStr.append("########## Termination due to crucial failure. ##########\n"); 00128 rReportStr.append("#########################################################\n"); 00129 return false; 00130 } 00131 if(localResult) rReportStr.append("##### Condition (i) passed.\n"); 00132 else rReportStr.append("##### Condition (i) failed.\n"); 00133 rReportStr.append("#####\n"); 00134 /*************************** Condition (i) finished *****************************/ 00135 00136 00137 /*************************** Condition (ii) ***********************/ 00138 localResult = true; 00139 rReportStr.append("########## Condition (ii):\n"); 00140 00141 // Check if in states QUl, QYlUe, QUe and QYe only UL-, YL-/UE-, UE and YE-events are active, respectively. 00142 // Also, dead ends are stored for condition (xi) 00143 for(sit = accessibleStates.Begin(); sit != accessibleStates.End(); ++sit) { 00144 00145 bool isUl = false; 00146 bool isYlUe = false; 00147 bool isUe = false; 00148 bool isYe = false; 00149 bool goodState = true; 00150 00151 EventSet activeEv = rHioEnvironment.ActiveEventSet(*sit); 00152 00153 if(activeEv.Empty()) { 00154 //dead ends violate condition (xi) 00155 deadEnds.Insert(*sit); 00156 } 00157 else { 00158 00159 // get attribute of first event and compare with remaining events 00160 evit = activeEv.Begin(); 00161 isUl = rHioEnvironment.IsUl(*evit); 00162 isYlUe = rHioEnvironment.IsYl(*evit); // YlEvents can only be active in YlUe states 00163 isUe = rHioEnvironment.IsUe(*evit); // is reset (and YlUe is set) in case YlEvent is found in activeEv 00164 isYe = rHioEnvironment.IsYe(*evit); 00165 00166 for(; evit != activeEv.End(); evit++) { 00167 if( (isUl && !rHioEnvironment.IsUl(*evit)) || 00168 ((isYlUe||isUe) && (!rHioEnvironment.IsYl(*evit) && (!rHioEnvironment.IsUe(*evit)))) || 00169 (isYe && !rHioEnvironment.IsYe(*evit)) ){ 00170 goodState = false; 00171 localResult = false; 00172 finalResult = false; 00173 // add state to error set, go to next state 00174 locErrStSet.Insert(*sit); 00175 rErrStSet.Insert(*sit); 00176 break; // leave loop over active events 00177 } 00178 if(isUe && rHioEnvironment.IsYl(*evit)) { 00179 isYlUe = true; 00180 isUe = false; 00181 } 00182 } 00183 00184 activeEv.Clear(); 00185 00186 if(!goodState) continue; // if undecidable go on with next state 00187 00188 // set state attribute 00189 if(isUl) { 00190 rQUl.Insert(*sit); 00191 rHioEnvironment.SetQUl(*sit); 00192 } 00193 else if(isYlUe) { 00194 rQYlUe.Insert(*sit); 00195 rHioEnvironment.SetQYlUe(*sit); 00196 } 00197 else if(isUe) { 00198 rQUe.Insert(*sit); 00199 rHioEnvironment.SetQUe(*sit); 00200 } 00201 else if(isYe){ 00202 rQYe.Insert(*sit); 00203 rHioEnvironment.SetQYe(*sit); 00204 } 00205 } 00206 } 00207 00208 if(localResult) rReportStr.append("##### Condition (ii) passed.\n"); 00209 // In case of failing condition (ii) further inspection is omitted, as too many consecutive faults are expected. 00210 else { 00211 rReportStr.append("##### fail: found states with undecidable attribute:\n"); 00212 rReportStr.append(locErrStSet.ToString()+"\n"); 00213 locErrStSet.Clear(); 00214 rReportStr.append("##### Condition (ii) failed.\n"); 00215 rReportStr.append("########## Termination due to crulial failure. ##########\n"); 00216 rReportStr.append("###################### No sulcess. ######################\n"); 00217 rReportStr.append("#########################################################\n"); 00218 return false; 00219 } 00220 rReportStr.append("#####\n"); 00221 /*************************** Condition (ii) finished ****************************/ 00222 00223 00224 /*************************** Condition (iii) **********************/ 00225 localResult = true; 00226 rReportStr.append("########## Condition (iii):\n"); 00227 00228 //check if the initial state is a QYe-state 00229 if(!(initStates <= rQYe)) { 00230 rReportStr.append("##### fail: some init state(s) is (are) not a QYe-state:\n"); 00231 locErrStSet=initStates-rQYe; 00232 rReportStr.append(locErrStSet.ToString()+"\n"); 00233 rErrStSet.SetUnion(locErrStSet); 00234 locErrStSet.Clear(); 00235 localResult = false; 00236 finalResult = false; 00237 } 00238 if(localResult) rReportStr.append("##### Condition (iii) passed.\n"); 00239 else rReportStr.append("##### Condition (iii) failed.\n"); 00240 rReportStr.append("#####\n"); 00241 00242 /*************************** Condition (iii) finished ***************************/ 00243 00244 00245 /*************************** Condition (iv) ***********************/ 00246 localResult = true; 00247 rReportStr.append("########## Condition (iv):\n"); 00248 00249 // YE-events have to lead to a QYlUe or a QUe-state 00250 for(sit = rQYe.Begin(); sit != rQYe.End(); ++sit) { 00251 for(tit = rHioEnvironment.TransRelBegin(*sit); tit != rHioEnvironment.TransRelEnd(*sit); ++tit) { 00252 // YE-event to QYlUe or QUe-state 00253 if ( !( rQYlUe.Exists(tit->X2) || rQUe.Exists(tit->X2) ) ) { 00254 // add transition to error transition set 00255 rErrTrSet.Insert(*tit); 00256 locErrTrSet.Insert(*tit); 00257 finalResult = false; 00258 localResult = false; 00259 } 00260 } 00261 } 00262 00263 if(localResult) rReportStr.append("##### Condition (iv) passed.\n"); 00264 else { 00265 rReportStr.append("##### fail: found YE-transitions leading to wrong states:\n"); 00266 rReportStr.append(locErrTrSet.ToString()+"\n"); 00267 locErrTrSet.Clear(); 00268 rReportStr.append("##### Condition (iv) failed.\n"); 00269 } 00270 rReportStr.append("#####\n"); 00271 /*************************** Condition (iv) finished ****************************/ 00272 00273 00274 /*************************** Condition (v) ************************/ 00275 localResult = true; 00276 rReportStr.append("########## Condition (v):\n"); 00277 00278 // UE-events have to lead to a QYe-state 00279 for(sit = rQUe.Begin(); sit != rQUe.End(); ++sit) { 00280 for(tit = rHioEnvironment.TransRelBegin(*sit); tit != rHioEnvironment.TransRelEnd(*sit); ++tit) { 00281 if(!rQYe.Exists(tit->X2)) { 00282 rErrTrSet.Insert(*tit); 00283 locErrTrSet.Insert(*tit); 00284 finalResult = false; 00285 localResult = false; 00286 } 00287 } 00288 } 00289 00290 if(localResult) rReportStr.append("##### Condition (v) passed.\n"); 00291 else { 00292 rReportStr.append("##### fail: found UE-transitions leading to wrong states:\n"); 00293 rReportStr.append(locErrTrSet.ToString()+"\n"); 00294 locErrTrSet.Clear(); 00295 rReportStr.append("##### Condition (v) failed.\n"); 00296 } 00297 rReportStr.append("#####\n"); 00298 /*************************** Condition (v) finished *****************************/ 00299 00300 00301 /*************************** Condition (vi) ***********************/ 00302 localResult = true; 00303 rReportStr.append("########## Condition (vi):\n"); 00304 00305 // From QYlUe states, UE-events have to lead to a QYe-state and YL-events 00306 // have to lead to a UL-state 00307 for(sit = rQYlUe.Begin(); sit != rQYlUe.End(); ++sit) { 00308 for(tit = rHioEnvironment.TransRelBegin(*sit); tit != rHioEnvironment.TransRelEnd(*sit); ++tit) { 00309 00310 if( (rHioEnvironment.IsUe(tit->Ev) && !rQYe.Exists(tit->X2)) || 00311 (rHioEnvironment.IsYl(tit->Ev) && !rQUl.Exists(tit->X2)) ){ 00312 locErrTrSet.Insert(*tit); 00313 rErrTrSet.Insert(*tit); 00314 finalResult = false; 00315 localResult = false; 00316 } 00317 } 00318 } 00319 00320 if(localResult) rReportStr.append("##### Condition (vi) passed.\n"); 00321 else { 00322 rReportStr.append("##### fail: found YL- or UE-transitions leading to wrong states:\n"); 00323 rReportStr.append(locErrTrSet.ToString()+"\n"); 00324 locErrTrSet.Clear(); 00325 rReportStr.append("##### Condition (vi) failed.\n"); 00326 } 00327 rReportStr.append("#####\n"); 00328 /*************************** Condition (vi) finished ****************************/ 00329 00330 00331 /*************************** Condition (vii) ************************/ 00332 localResult = true; 00333 rReportStr.append("########## Condition (vii):\n"); 00334 00335 // UL-events have to lead to a QUe-state 00336 for(sit = rQUl.Begin(); sit != rQUl.End(); ++sit) { 00337 for(tit = rHioEnvironment.TransRelBegin(*sit); tit != rHioEnvironment.TransRelEnd(*sit); ++tit) { 00338 if(!rQUe.Exists(tit->X2)) { 00339 locErrTrSet.Insert(*tit); 00340 rErrTrSet.Insert(*tit); 00341 finalResult = false; 00342 localResult = false; 00343 } 00344 } 00345 } 00346 00347 if(localResult) rReportStr.append("##### Condition (vii) passed.\n"); 00348 else { 00349 rReportStr.append("##### fail: found UL-transitions leading to wrong states, see rErrTrSet:\n"); 00350 rReportStr.append(locErrTrSet.ToString()+"\n"); 00351 locErrTrSet.Clear(); 00352 rReportStr.append("##### Condition (vii) failed.\n"); 00353 } 00354 rReportStr.append("#####\n"); 00355 /*************************** Condition (vii) finished *****************************/ 00356 00357 00358 /*************************** Condition (viii) **********************/ 00359 localResult = true; 00360 rReportStr.append("########## Condition (viii):\n"); 00361 00362 // UL must be free in QUl-states 00363 for(sit = rQUl.Begin(); sit != rQUl.End(); ++sit) { 00364 00365 if(!(ul <= rHioEnvironment.ActiveEventSet(*sit))) { 00366 locErrStSet.Insert(*sit); 00367 rErrStSet.Insert(*sit); 00368 finalResult = false; 00369 localResult = false; 00370 } 00371 } 00372 00373 if(localResult) rReportStr.append("##### Condition (viii) passed.\n"); 00374 else { 00375 rReportStr.append("##### fail: found QUl-states with inactive UL-events:\n"); 00376 rReportStr.append(locErrStSet.ToString()+"\n"); 00377 locErrStSet.Clear(); 00378 rReportStr.append("##### Condition (viii) failed.\n"); 00379 } 00380 rReportStr.append("#####\n"); 00381 /*************************** Condition (viii) finished ***************************/ 00382 00383 00384 /*************************** Condition (ix) **********************/ 00385 localResult = true; 00386 rReportStr.append("########## Condition (ix):\n"); 00387 00388 // YE must be free in QYe-states 00389 for(sit = rQYe.Begin(); sit != rQYe.End(); ++sit) { 00390 00391 if(!(ye <= rHioEnvironment.ActiveEventSet(*sit))) { 00392 locErrStSet.Insert(*sit); 00393 rErrStSet.Insert(*sit); 00394 finalResult = false; 00395 localResult = false; 00396 } 00397 } 00398 00399 if(localResult) rReportStr.append("##### Condition (ix) passed.\n"); 00400 else { 00401 rReportStr.append("##### fail: found QYe-states with inactive YE-events:\n"); 00402 rReportStr.append(locErrStSet.ToString()+"\n"); 00403 locErrStSet.Clear(); 00404 rReportStr.append("##### Condition (ix) failed.\n"); 00405 } 00406 rReportStr.append("#####\n"); 00407 /*************************** Condition (ix) finished ***************************/ 00408 00409 00410 /*************************** Condition (x) ***********************/ 00411 localResult = true; 00412 rReportStr.append("########## Condition (x):\n"); 00413 00414 // Qm==Q? 00415 if(!(accessibleStates<=rHioEnvironment.MarkedStates())) { 00416 finalResult = false; 00417 localResult = false; 00418 } 00419 00420 if(localResult) rReportStr.append("##### Condition (x) passed.\n"); 00421 else { 00422 rReportStr.append("##### fail: not all accessible states are marked, see rErrStSet:\n"); 00423 locErrStSet= accessibleStates - rHioEnvironment.MarkedStates(); 00424 rErrStSet.SetUnion(locErrStSet); 00425 rReportStr.append(locErrStSet.ToString()+"\n"); 00426 locErrStSet.Clear(); 00427 rReportStr.append("##### Condition (x) failed.\n"); 00428 } 00429 rReportStr.append("#####\n"); 00430 /*************************** Condition (x) finished ****************************/ 00431 00432 00433 /*************************** Condition (xi) ************************/ 00434 localResult = true; 00435 rReportStr.append("########## Condition (xi):\n"); 00436 00437 // found dead ends? 00438 if(!deadEnds.Empty()) { 00439 finalResult = false; 00440 localResult = false; 00441 rErrStSet.SetUnion(deadEnds); 00442 rReportStr.append("##### fail: found dead ends:\n"); 00443 rReportStr.append(deadEnds.ToString()+"\n"); 00444 deadEnds.Clear(); 00445 rReportStr.append("##### Condition (xi) failed.\n"); 00446 } 00447 rReportStr.append("##### Condition (xi) passed.\n"); 00448 /*************************** Condition (xi) finished *****************************/ 00449 00450 00451 /*************************** Condition (xii) ************************/ 00452 rReportStr.append("########## Condition (xii):\n"); 00453 00454 // make accessible if necessary 00455 if(!rHioEnvironment.IsAccessible()) { 00456 rHioEnvironment.Accessible(); 00457 rReportStr.append("##### warning: non-accessible states have been removed.\n"); 00458 rReportStr.append("##### Condition (xii) repaired.\n"); 00459 } 00460 else rReportStr.append("##### Condition (xii) passed.\n"); 00461 /*************************** Condition (xii) finished *****************************/ 00462 00463 00464 00465 /*************************** Final result ****************************/ 00466 rReportStr.append("##################### Final result: #####################\n"); 00467 if(finalResult) { 00468 rReportStr.append("######### Generator is in HioEnvironmentForm. #########\n"); 00469 rReportStr.append("#########################################################\n"); 00470 return true; 00471 } 00472 else { 00473 rReportStr.append("########### Generator is NOT in HioEnvironmentForm. ###########\n"); 00474 rReportStr.append("#########################################################\n"); 00475 return false; 00476 } 00477 00478 }// END OF IsHioEnvironmentForm() 00479 00480 00481 //IsHioEnvironmentForm wrapper functions 00482 bool IsHioEnvironmentForm(HioEnvironment& rHioEnvironment,std::string& rReportStr) 00483 { 00484 StateSet QYe, QUe, QUl, QYlUe; 00485 EventSet ErrEvSet; 00486 TransSet ErrTrSet; 00487 StateSet ErrStSet; 00488 00489 return IsHioEnvironmentForm(rHioEnvironment, QYe, QUe, QUl, QYlUe, ErrEvSet, ErrTrSet, ErrStSet, rReportStr); 00490 } 00491 00492 // rti function interface 00493 bool IsHioEnvironmentForm(HioEnvironment& rHioEnvironment) 00494 { 00495 StateSet QYe, QUe, QUl, QYlUe; 00496 EventSet ErrEvSet; 00497 TransSet ErrTrSet; 00498 StateSet ErrStSet; 00499 std::string ReportStr; 00500 00501 return IsHioEnvironmentForm(rHioEnvironment, QYe, QUe, QUl, QYlUe, ErrEvSet, ErrTrSet, ErrStSet, ReportStr); 00502 } 00503 00504 // rti function interface 00505 void HioStatePartition(HioEnvironment& rHioEnvironment) { 00506 IsHioEnvironmentForm(rHioEnvironment); 00507 } 00508 00509 00510 } // end namespace libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |