hio_controller.cpp

Go to the documentation of this file.
00001 /** @file hio_controller.cpp Generator with I/O-controller 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_controller.h"
00012 
00013 namespace faudes {
00014 
00015 // IsHioControllerForm()
00016 bool IsHioControllerForm(HioController& rHioController,
00017                 StateSet& rQUc,
00018                 StateSet& rQYP,
00019                 StateSet& rQUp,
00020                 StateSet& rQYcUp,
00021                 EventSet& rErrEvSet,
00022                 TransSet& rErrTrSet,
00023                 StateSet& rErrStSet,
00024                 std::string& rReportStr)
00025     {
00026     FD_DF("IsHioControllerForm("<< rHioController.Name() << ",...)");
00027     
00028     // prepare results
00029     rQUc.Clear();
00030     rQYP.Clear();
00031     rQUp.Clear();
00032     rQYcUp.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 yp = rHioController.YpEvents();
00057     EventSet up = rHioController.UpEvents();
00058     EventSet yc = rHioController.YcEvents();
00059     EventSet uc = rHioController.UcEvents();
00060     
00061     StateSet initStates = rHioController.InitStates();
00062     StateSet accessibleStates = rHioController.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("########## IsHioControllerForm("+rHioController.Name()+",...) - test results:\n");
00072 
00073     /**************************** Precondition: determinism ***********************/
00074     // HioController must be deterministic
00075     if(!rHioController.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     rReportStr.append("#####\n");
00085     
00086     // test all conditions verifying I/O-controller form:
00087     
00088     /**************************** Condition (i) ***********************/
00089     localResult = true;
00090     rReportStr.append("########## Condition (i):\n");
00091     
00092     //YP, UP, YC, UC nonempty?
00093     if (yp.Empty()) {
00094        rReportStr.append("##### fail: empty YP alphabet.\n");
00095        localResult=false;
00096        finalResult = false;
00097     }
00098     if (up.Empty()) {
00099        rReportStr.append("##### fail: empty UP alphabet.\n");
00100        localResult=false;
00101        finalResult = false;
00102     }
00103     if (yc.Empty()) {
00104        rReportStr.append("##### fail: empty YC alphabet.\n");
00105        localResult=false;
00106        finalResult = false;
00107     }
00108     if (uc.Empty()) {
00109        rReportStr.append("##### fail: empty UC alphabet.\n");
00110        localResult=false;
00111        finalResult = false;
00112     }
00113   
00114     // check for disjoint eventsets YP, YC, UP, UC and for
00115     // YP u YC u UP u UC == Sigma, ie unique HioEventFlags.
00116     // note: testing disjoint C- and P-Alphabet is sufficient
00117     //       as properties U and Y are exclusive by construction.
00118         
00119     rErrEvSet=(rHioController.PEvents()*rHioController.CEvents()) + (rHioController.Alphabet()-rHioController.PEvents()-rHioController.CEvents());
00120     
00121     // In case of failing condition (i) further inspection is omitted, as too many consecutive faults are expected.
00122     if(!rErrEvSet.Empty()){
00123             rReportStr.append("##### fail: found events with missing or ambiguous attribute, see rErrEvSet:\n");
00124             rReportStr.append(rErrEvSet.ToString()+"\n");
00125             rReportStr.append("##### Condition (i) failed.\n");
00126             rReportStr.append("########## Termination due to crucial failure. ##########\n");
00127             rReportStr.append("#########################################################\n");
00128             return false;
00129         }
00130     if(localResult) rReportStr.append("##### Condition (i) passed.\n");
00131     else rReportStr.append("##### Condition (i) failed.\n");
00132     rReportStr.append("#####\n");
00133     /*************************** Condition (i) finished *****************************/
00134     
00135     
00136     /*************************** Condition (ii) ***********************/ 
00137     localResult = true;
00138     rReportStr.append("########## Condition (ii):\n");
00139     
00140     // Check if in states QUc, QYcUp, QUp and QYP only UC-, YC-/UP-, UP and YP-events are active, respectively.
00141     // Also, dead ends are stored for condition (xi)
00142     for(sit = accessibleStates.Begin(); sit != accessibleStates.End(); ++sit) {
00143          
00144             bool isUc  = false;
00145             bool isYcUp = false;
00146             bool isUp = false;
00147             bool isYp = false;
00148             bool goodState = true;
00149                
00150             EventSet activeEv = rHioController.ActiveEventSet(*sit);
00151             
00152             if(activeEv.Empty()) {
00153                 //dead ends violate condition (xi)
00154                 deadEnds.Insert(*sit);
00155             }
00156             else {
00157                 
00158                 // get attribute of first event and compare with remaining events
00159                 evit = activeEv.Begin();
00160                 isUc  = rHioController.IsUc(*evit);
00161                 isYcUp = rHioController.IsYc(*evit); // YcEvents can only be active in YcUp states
00162                 isUp = rHioController.IsUp(*evit); // is reset (and YcUp is set) in case YcEvent is found in activeEv
00163                 isYp = rHioController.IsYp(*evit);
00164                 
00165                 for(; evit != activeEv.End(); evit++) {
00166                     if( (isUc && !rHioController.IsUc(*evit)) ||            
00167             ((isYcUp||isUp) && (!rHioController.IsYc(*evit) && (!rHioController.IsUp(*evit)))) ||
00168                         (isYp &&  !rHioController.IsYp(*evit)) ){
00169                         goodState = false;
00170                         localResult = false;
00171                         finalResult = false;
00172                         // add state to error set, go to next state
00173                         locErrStSet.Insert(*sit);
00174                         break; // leave loop over active events
00175                     }
00176                     if(isUp && rHioController.IsYc(*evit)) {
00177                         isYcUp = true;
00178                         isUp   = false;
00179                     }
00180                 }
00181                 
00182                 activeEv.Clear();
00183                 
00184                 if(!goodState) continue; // if undecidable go on with next state
00185                 
00186                 // set state attribute
00187                 if(isUc) {
00188                    rQUc.Insert(*sit);
00189                    rHioController.SetQUc(*sit);
00190                 }
00191                 else if(isYcUp) {
00192                    rQYcUp.Insert(*sit);
00193                    rHioController.SetQYcUp(*sit);
00194                 }
00195                 else if(isUp) {
00196                    rQUp.Insert(*sit);
00197                    rHioController.SetQUp(*sit);
00198                 }
00199                 else if(isYp){
00200                     rQYP.Insert(*sit);
00201                     rHioController.SetQYp(*sit);
00202                 }
00203             }
00204         }
00205             
00206     if(localResult) rReportStr.append("##### Condition (ii) passed.\n");
00207      // In case of failing condition (ii) further inspection is omitted, as too many consecutive faults are expected.
00208     else {
00209         rReportStr.append("##### fail: found states with undecidable attribute:\n");
00210         rReportStr.append(locErrStSet.ToString()+"\n");
00211         rReportStr.append("##### Condition (ii) failed.\n");
00212         rReportStr.append("########## Termination due to crucial failure. ##########\n");
00213         rReportStr.append("###################### No success. ######################\n");
00214         rReportStr.append("#########################################################\n");
00215     rErrStSet.SetUnion(locErrStSet);
00216     locErrStSet.Clear();
00217         return false;
00218     }
00219     rReportStr.append("#####\n");
00220     /*************************** Condition (ii) finished ****************************/  
00221     
00222     
00223     /*************************** Condition (iii) **********************/
00224     localResult = true;
00225     rReportStr.append("########## Condition (iii):\n");
00226     
00227     //check if the initial state is a QYP-state
00228     if(!(initStates <= rQYP)) {
00229         rReportStr.append("##### fail: some init state(s) is (are) not a QYP-state:\n");
00230     locErrStSet=initStates-rQYP;
00231         rReportStr.append(locErrStSet.ToString()+"\n");
00232         rErrStSet.SetUnion(locErrStSet);
00233     locErrStSet.Clear();
00234         localResult = false;
00235         finalResult = false;
00236     }
00237     if(localResult) rReportStr.append("##### Condition (iii) passed.\n");
00238     else rReportStr.append("##### Condition (iii) failed.\n");
00239     rReportStr.append("#####\n");
00240     
00241     /*************************** Condition (iii) finished ***************************/
00242     
00243     
00244     /*************************** Condition (iv) ***********************/
00245     localResult = true; 
00246     rReportStr.append("########## Condition (iv):\n");
00247     
00248     // YP-events have to lead to a QYcUp or a QUp-state
00249     for(sit = rQYP.Begin(); sit != rQYP.End(); ++sit) {
00250         for(tit = rHioController.TransRelBegin(*sit); tit != rHioController.TransRelEnd(*sit); ++tit) {
00251             // YP-event to QYcUp or QUp-state
00252             if ( !( rQYcUp.Exists(tit->X2) || rQUp.Exists(tit->X2) ) ) {
00253                 // add transition to error transition set
00254         locErrTrSet.Insert(*tit);
00255                 rErrTrSet.Insert(*tit);
00256                 finalResult = false;
00257                 localResult = false;
00258             }
00259         }
00260     }
00261     
00262     if(localResult) rReportStr.append("##### Condition (iv) passed.\n");
00263     else {
00264         rReportStr.append("##### fail: found YP-transitions leading to wrong states:\n");
00265         rReportStr.append(locErrTrSet.ToString()+"\n");
00266     locErrTrSet.Clear();
00267         rReportStr.append("##### Condition (iv) failed.\n");
00268     }
00269     rReportStr.append("#####\n");
00270     /*************************** Condition (iv) finished ****************************/
00271     
00272     
00273     /*************************** Condition (v) ************************/
00274     localResult = true;
00275     rReportStr.append("########## Condition (v):\n");
00276     
00277     // UP-events have to lead to a QYP-state
00278     for(sit = rQUp.Begin(); sit != rQUp.End(); ++sit) {
00279         for(tit = rHioController.TransRelBegin(*sit); tit != rHioController.TransRelEnd(*sit); ++tit) {
00280             if(!rQYP.Exists(tit->X2)) {
00281                 locErrTrSet.Insert(*tit);
00282                 rErrTrSet.Insert(*tit);
00283                 finalResult = false;
00284                 localResult = false;
00285             } 
00286         }
00287     }
00288     
00289     if(localResult) rReportStr.append("##### Condition (v) passed.\n");
00290     else {
00291         rReportStr.append("##### fail: found UP-transitions leading to wrong states, see rErrTrSet:\n");
00292         rReportStr.append(locErrTrSet.ToString()+"\n");
00293     locErrTrSet.Clear();
00294         rReportStr.append("##### Condition (v) failed.\n");
00295     }
00296     rReportStr.append("#####\n");
00297     /*************************** Condition (v) finished *****************************/
00298     
00299     
00300     /*************************** Condition (vi) ***********************/ 
00301     localResult = true;
00302     rReportStr.append("########## Condition (vi):\n");
00303     
00304     // From QYcUp states, UP-events have to lead to a QYP-state and YC-events
00305     // have to lead to a UC-state
00306     for(sit = rQYcUp.Begin(); sit != rQYcUp.End(); ++sit) {
00307         for(tit = rHioController.TransRelBegin(*sit); tit != rHioController.TransRelEnd(*sit); ++tit) {
00308             
00309             if( (rHioController.IsUp(tit->Ev) && !rQYP.Exists(tit->X2)) ||
00310                 (rHioController.IsYc(tit->Ev) && !rQUc.Exists(tit->X2)) ){
00311                 rErrTrSet.Insert(*tit);
00312                 locErrTrSet.Insert(*tit);
00313                 finalResult = false;
00314                 localResult = false;
00315             }    
00316         }
00317     }
00318     
00319     if(localResult) rReportStr.append("##### Condition (vi) passed.\n");
00320     else {
00321         rReportStr.append("##### fail: found YC- or UP-transitions leading to wrong states:\n");
00322         rReportStr.append(locErrTrSet.ToString()+"\n");
00323     locErrTrSet.Clear();
00324         rReportStr.append("##### Condition (vi) failed.\n");
00325     }
00326     rReportStr.append("#####\n");
00327     /*************************** Condition (vi) finished ****************************/
00328     
00329 
00330     /*************************** Condition (vii) ************************/
00331     localResult = true;
00332     rReportStr.append("########## Condition (vii):\n");
00333     
00334     // UC-events have to lead to a QUp-state
00335     for(sit = rQUc.Begin(); sit != rQUc.End(); ++sit) {
00336         for(tit = rHioController.TransRelBegin(*sit); tit != rHioController.TransRelEnd(*sit); ++tit) {
00337             if(!rQUp.Exists(tit->X2)) {
00338                 locErrTrSet.Insert(*tit);
00339                 rErrTrSet.Insert(*tit);
00340                 finalResult = false;
00341                 localResult = false;
00342             } 
00343         }
00344     }
00345     
00346     if(localResult) rReportStr.append("##### Condition (vii) passed.\n");
00347     else {
00348         rReportStr.append("##### fail: found UC-transitions leading to wrong states:\n");
00349         rReportStr.append(locErrTrSet.ToString()+"\n");
00350     locErrTrSet.Clear();
00351         rReportStr.append("##### Condition (vii) failed.\n");
00352     }
00353     rReportStr.append("#####\n");
00354     /*************************** Condition (vii) finished *****************************/
00355 
00356     
00357     /*************************** Condition (viii) **********************/    
00358     localResult = true;
00359     rReportStr.append("########## Condition (viii):\n");
00360     
00361     // UC must be free in QUc-states
00362     for(sit = rQUc.Begin(); sit != rQUc.End(); ++sit) {
00363         
00364         if(!(uc <= rHioController.ActiveEventSet(*sit))) {
00365                locErrStSet.Insert(*sit);
00366                rErrStSet.Insert(*sit);
00367                finalResult = false;
00368                localResult = false;
00369         }
00370     }
00371     
00372     if(localResult) rReportStr.append("##### Condition (viii) passed.\n");
00373     else {
00374         rReportStr.append("##### fail: found QUc-states with inactive UC-events:\n");
00375         rReportStr.append(locErrStSet.ToString()+"\n");
00376     locErrStSet.Clear();
00377         rReportStr.append("##### Condition (viii) failed.\n");
00378     }
00379     rReportStr.append("#####\n");
00380     /*************************** Condition (viii) finished ***************************/
00381     
00382     
00383     /*************************** Condition (ix) **********************/    
00384     localResult = true;
00385     rReportStr.append("########## Condition (ix):\n");
00386     
00387     // YP must be free in QYP-states
00388     for(sit = rQYP.Begin(); sit != rQYP.End(); ++sit) {
00389         
00390         if(!(yp <= rHioController.ActiveEventSet(*sit))) {
00391                locErrStSet.Insert(*sit);
00392                rErrStSet.Insert(*sit);
00393                finalResult = false;
00394                localResult = false;
00395         }
00396     }
00397     
00398     if(localResult) rReportStr.append("##### Condition (ix) passed.\n");
00399     else {
00400         rReportStr.append("##### fail: found QYP-states with inactive YP-events:\n");
00401         rReportStr.append(locErrStSet.ToString()+"\n");
00402     locErrStSet.Clear();
00403         rReportStr.append("##### Condition (ix) failed.\n");
00404     }
00405     rReportStr.append("#####\n");
00406     /*************************** Condition (ix) finished ***************************/
00407     
00408     
00409     /*************************** Condition (x) ***********************/
00410     localResult = true;
00411     rReportStr.append("########## Condition (x):\n");
00412     
00413     // Qm==Q?
00414     if(!(accessibleStates<=rHioController.MarkedStates())) {
00415         finalResult = false;
00416         localResult = false;
00417     }
00418     
00419     if(localResult) rReportStr.append("##### Condition (x) passed.\n");
00420     else {
00421         rReportStr.append("##### fail: not all accessible states are marked:\n");
00422         locErrStSet = accessibleStates - rHioController.MarkedStates();
00423     rErrStSet.SetUnion(locErrStSet);
00424         rReportStr.append(locErrStSet.ToString()+"\n");
00425     locErrStSet.Clear();
00426         rReportStr.append("##### Condition (x) failed.\n");
00427     }
00428     rReportStr.append("#####\n");       
00429     /*************************** Condition (x) finished ****************************/
00430     
00431     
00432     /*************************** Condition (xi) ************************/
00433     localResult = true;
00434     rReportStr.append("########## Condition (xi):\n");
00435     
00436     // found dead ends?
00437     if(!deadEnds.Empty()) {
00438         finalResult = false;
00439         localResult = false;
00440         rErrStSet.SetUnion(deadEnds);
00441         rReportStr.append("##### fail: found dead ends:\n");
00442         rReportStr.append(deadEnds.ToString()+"\n");
00443         deadEnds.Clear();
00444         rReportStr.append("##### Condition (xi) failed.\n");
00445     }
00446     rReportStr.append("##### Condition (xi) passed.\n");
00447     /*************************** Condition (xi) finished *****************************/
00448     
00449     
00450     /*************************** Condition (xii) ************************/
00451     rReportStr.append("########## Condition (xii):\n");
00452     
00453     // make accessible if necessary    
00454     if(!rHioController.IsAccessible()) {
00455         rHioController.Accessible();
00456         rReportStr.append("##### warning: non-accessible states have been removed.\n");
00457     rReportStr.append("##### Condition (xii) repaired.\n");
00458     }
00459     else rReportStr.append("##### Condition (xii) passed.\n");
00460     /*************************** Condition (xii) finished *****************************/
00461     
00462     
00463     
00464     /*************************** Final result ****************************/
00465     rReportStr.append("##################### Final result: #####################\n");
00466     if(finalResult) {
00467         rReportStr.append("######### Generator is in HioControllerForm. #########\n");
00468         rReportStr.append("#########################################################\n");
00469         return true;
00470     }
00471     else {
00472         rReportStr.append("########### Generator is NOT in HioControllerForm. ###########\n");
00473         rReportStr.append("#########################################################\n");
00474         return false;
00475     }
00476 
00477 }// END OF IsHioControllerForm()
00478 
00479 //IsHioControllerForm wrapper functions
00480 bool IsHioControllerForm(HioController& rHioController,std::string& rReportStr)
00481 {
00482      StateSet QUc, QYP, QUp, QYcUp;
00483      EventSet ErrEvSet;
00484      TransSet ErrTrSet;
00485      StateSet ErrStSet;
00486      
00487      return IsHioControllerForm(rHioController, QUc, QYP, QUp, QYcUp, ErrEvSet, ErrTrSet, ErrStSet, rReportStr);
00488 }
00489 
00490 bool IsHioControllerForm(HioController& rHioController)
00491 {
00492      StateSet QUc, QYP, QUp, QYcUp;
00493      EventSet ErrEvSet;
00494      TransSet ErrTrSet;
00495      StateSet ErrStSet;
00496      std::string ReportStr;
00497      
00498      return IsHioControllerForm(rHioController, QUc, QYP, QUp, QYcUp, ErrEvSet, ErrTrSet, ErrStSet, ReportStr);
00499 }
00500 
00501 // rti function interface
00502 void HioStatePartition(HioController& rHioController) {
00503  IsHioControllerForm(rHioController);
00504 }
00505 
00506 } // end namespace

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