| |
libFAUDES
Sections
Index
|
hio_1_hiogenerators.cpp File ReferenceDetailed DescriptionTutorial, i/o system generator classes.This tutorial demonstrates basic maintenance of HioPlant, HioController and HioEnvironment objects.
/** @file hio_1_hiogenerators.cpp Tutorial, i/o system generator classes. This tutorial demonstrates basic maintenance of HioPlant, HioController and HioEnvironment objects. @ingroup Tutorials @include hio_1_hiogenerators.cpp */ #include "libfaudes.h" // make the faudes namespace available to our program using namespace faudes; ///////////////// // main program ///////////////// int main() { /************************************************** * HIO PLANT ***************************************************/ /****************** * constructor and file io ********************/ // At first we create an empty HioPlant object HioPlant g1; // We create a HioPlant by reading a HioPlant file HioPlant g2("data/hio_simplemachine_A.gen"); // We create a HioPlant by reading a plain Generator file (no event attributes) g1.Read("data/simplemachine_A.gen"); // We copy a plain Generator to a HioPlant (no event attributes) HioPlant g3; Generator g4("data/simplemachine_A.gen"); g4.Copy(g3); // construct HioPlant from plain generator HioPlant g5(g4); // construct HioPlant from plain generator and event sets EventSet ypEvents,upEvents,yeEvents,ueEvents; ypEvents=g2.YpEvents(); upEvents=g2.UpEvents(); yeEvents=g2.YeEvents(); ueEvents=g2.UeEvents(); HioPlant g6(g4,ypEvents,upEvents,yeEvents,ueEvents); // We write the HioPlant to files g1.Write("tmp_hiosimplemachine_A1.gen"); g2.Write("tmp_hiosimplemachine_A2.gen"); g3.Write("tmp_hiosimplemachine_A3.gen"); g5.Write("tmp_hiosimplemachine_A5.gen"); g6.Write("tmp_hiosimplemachine_A6.gen"); g1.GraphWrite("tmp_hiosimplemachine_A.png"); // See result on console std::cout << "######################################\n"; std::cout << "# hio simple machine\n"; g2.Write(); std::cout << "######################################\n"; /***************************** * check if HioPlant meets IO-Plant form ******************************/ std::cout << "######################################\n"; // fails for g1 due to missing event attributes std::cout << "# IsIoPlantForm A: expect to fail for missing attributes\n"; std::string report; IsIoPlantForm(g1,report); std::cout<<report; // fulfilled for g2: std::cout << "# IsIoPlantForm B: expect to pass\n"; IsIoPlantForm(g2,report); std::cout<<report; // remove some transitions with input-event TransSet::Iterator tit; for (tit = g2.TransRelBegin(); tit != g2.TransRelEnd(); ++tit) { //if(g2.IsUp(tit->Ev)) { if(g2.EventName(tit->Ev)=="A_stp" || g2.EventName(tit->Ev)=="A_nack") { g2.ClrTransition(*tit); } } g2.Write("tmp_hiosimplemachine_A_broken.gen"); g2.GraphWrite("tmp_hiosimplemachine_A_broken.png"); // now, the input is no longer free in g2 std::cout << "# IsIoPlantForm C: expect to fail for missing input transitions\n"; IsIoPlantForm(g2,report); std::cout<<report; // repair FreeInput(g2,g2); g2.Write("tmp_hiosimplemachine_A_fixed.gen"); // IoPlantForm is retrieved for g2: std::cout << "# IsIoPlantForm D: expect to pass\n"; IsIoPlantForm(g2,report); std::cout<<report; g2.Write(); g2.Write("tmp_hiosimplemachine_A_repaired.gen"); g2.GraphWrite("tmp_hiosimplemachine_A_repaired.png"); std::cout << "######################################\n"; /******************************************* * access to hio-property of states * * note: hio state properties need not be up to date * - always run IsIoPlantForm() to set state attributes **************************************/ // Get states of g2 sorted according to their active event sets StateSet QYpYe,QUp,QUe; QYpYe=g2.QYpYeStates(); QUp=g2.QUpStates(); QUe=g2.QUeStates(); std::cout<<std::endl; // show on console std::cout << "######################################\n"; std::cout << "# QYpYe,QUp and QUe of simple machine:\n"; QYpYe.Write(); QUp.Write(); QUe.Write(); std::cout << "######################################\n"; /************************* * access to hio-property of events **************************/ // Retrieve EventSets containing all YP-, UP-, YE-, UE-events from g2 ypEvents=g2.YpEvents(); upEvents=g2.UpEvents(); yeEvents=g2.YeEvents(); ueEvents=g2.UeEvents(); // Set YP-, UP-, YE-, UE-events in g1 g1.SetYp(ypEvents); g1.SetUp(upEvents); g1.SetYe(yeEvents); g1.SetUe(ueEvents); // now, also g1 is in IoPlantForm std::cout << "######################################\n"; std::cout << "# IsIoPlantForm:\n"; IsIoPlantForm(g1,report); std::cout<<report; std::cout << "######################################\n"; // file i/o and access to attributes are analogous for HioConstraint, HioController and HioEnvironment. std::cout<<std::endl<<std::endl; /************************************************** * HIO CONTROLLER ***************************************************/ // Construct simple HioController structure HioController c1; c1.Name("HioController"); Idx yp1=c1.InsYpEvent("yp1"); Idx yp2=c1.InsYpEvent("yp2"); Idx yc=c1.InsYcEvent("yc"); Idx uc1=c1.InsUcEvent("uc1"); Idx uc2=c1.InsUcEvent("uc2"); Idx up=c1.InsUpEvent("up"); Idx st1=c1.InsInitState(); c1.SetMarkedState(st1); Idx st2=c1.InsMarkedState(); Idx st3=c1.InsMarkedState(); Idx st4=c1.InsMarkedState(); c1.SetTransition(st1,yp1,st2); c1.SetTransition(st2,yc,st3); c1.SetTransition(st3,uc1,st4); c1.SetTransition(st4,up,st1); // up to now, no I/O-controller form as inputs yp2 and uc2 are not accepted: std::cout<<std::endl<<"######################################\n"; std::cout<<"######################################\n"; std::cout<<"####### I/O CONTROLLER: #########\n"; IsIoControllerForm(c1,report); // test correct file I/O c1.Write(); c1.Write("tmp_hiocontroller_incomplete.gen"); c1.Read("tmp_hiocontroller_incomplete.gen"); c1.Write(); std::cout<<report; c1.GraphWrite("tmp_hiocontroller_incomplete.png"); // repair IoControllerForm using FreeInput FreeInput(c1,c1); IsIoControllerForm(c1,report); std::cout<<report; c1.Write("tmp_hiocontroller_repaired.gen"); c1.GraphWrite("tmp_hiocontroller_repaired.png"); std::cout<<"######################################\n"; std::cout<<std::endl<<std::endl; /************************************************** * HIO ENVIRONMENT ***************************************************/ // Construct simple HioEnvironment structure HioEnvironment e1; e1.Name("HioEnvironment"); Idx ye1=e1.InsYeEvent("ye1"); Idx ye2=e1.InsYeEvent("ye2"); Idx yl=e1.InsYlEvent("yl"); Idx ul1=e1.InsUlEvent("ul1"); Idx ul2=e1.InsUlEvent("ul2"); Idx ue=e1.InsUeEvent("ue"); st1=e1.InsInitState(); e1.SetMarkedState(st1); st2=e1.InsMarkedState(); st3=e1.InsMarkedState(); st4=e1.InsMarkedState(); e1.SetTransition(st1,ye1,st2); e1.SetTransition(st2,yl,st3); e1.SetTransition(st3,ul1,st4); e1.SetTransition(st4,ue,st1); // up to now, no I/O-environment form as inputs ye2 and ul2 are not accepted: std::cout<<std::endl<<"######################################\n"; std::cout<<"######################################\n"; std::cout<<"####### I/O ENVIRONMENT: #########\n"; IsIoEnvironmentForm(e1,report); // test correct file I/O e1.Write(); e1.Write("tmp_hioenvironment_incomplete.gen"); e1.Read("tmp_hioenvironment_incomplete.gen"); e1.Write(); std::cout<<report; e1.GraphWrite("tmp_hioenvironment_incomplete.png"); // repair IoEnvironmentForm using FreeInput FreeInput(e1,e1); IsIoEnvironmentForm(e1,report); e1.Write(); std::cout<<report; e1.Write("tmp_hioenvironment_repaired.gen"); e1.GraphWrite("tmp_hioenvironment_repaired.png"); std::cout<<"######################################\n"; std::cout<<std::endl<<std::endl; /************************************************** * HIO CONSTRAINT ***************************************************/ // Construct simple HioConstraint structure HioConstraint cnstr1; cnstr1.Name("HioConstraint"); Idx y1=cnstr1.InsYEvent("y1"); Idx y2=cnstr1.InsYEvent("y2"); Idx u=cnstr1.InsUEvent("u"); st1=cnstr1.InsInitState(); cnstr1.SetMarkedState(st1); st2=cnstr1.InsMarkedState(); cnstr1.SetTransition(st1,y1,st2); cnstr1.SetTransition(st2,u,st1); // up to now, no I/O-constraint form as input u2 is not accepted: std::cout<<std::endl<<"######################################\n"; std::cout<<"######################################\n"; std::cout<<"####### I/O CONSTRAINT: #########\n"; std::cout<<"#######\n"; // access to event properties: EventSet yEvents=cnstr1.YEvents(); yEvents.Name("####### HioConstraint: Y-Events"); yEvents.Write(); IsIoConstraintForm(cnstr1,report); // test correct file I/O cnstr1.Write(); cnstr1.Write("tmp_hioconstraint_incomplete.gen"); cnstr1.Read("tmp_hioconstraint_incomplete.gen"); cnstr1.Write(); std::cout<<report; cnstr1.GraphWrite("tmp_hioconstraint_incomplete.png"); // repair IoEnvironmentForm using FreeInput FreeInput(cnstr1,cnstr1); IsIoConstraintForm(cnstr1,report); cnstr1.Write(); std::cout<<report; cnstr1.Write("tmp_hioconstraint_repaired.gen"); cnstr1.GraphWrite("tmp_hioconstraint_repaired.png"); std::cout<<"######################################\n"; return 0; }
Function Documentation
|
libFAUDES 2.13a c++ source docu by doxygen 1.5.6