hio_1_introduction.cpp

Go to the documentation of this file.
00001 /** @file hio_1_introduction.cpp 
00002 
00003 Tutorial, simple i/o-based controller synthesis.
00004 
00005 This tutorial uses a very simple example to exhibit
00006 monolithic input-/output based controller synthesis.
00007 The purpose is to generate graphs for the
00008 introduction of hiosys in the libFAUDES user
00009 reference, see "hiosys_index.html".
00010 For other purposes such as learning how to use hiosys,
00011 we refer to the tutorials hio_2_hiogenerators,
00012 hio_3_hiofunctions and hio_4_transport_unit.
00013 
00014 @ingroup Tutorials 
00015 
00016 @include hio_1_introduction.cpp
00017 
00018 */
00019 
00020 #include "libfaudes.h"
00021 
00022 // make the faudes namespace available to our program
00023 using namespace faudes;
00024 
00025 /////////////////
00026 // main program
00027 /////////////////
00028 
00029 int main() {
00030 
00031   ////////////////////////////////////////////
00032   // PLANT MODEL WITH INPUTS AND OUTPUTS
00033   ////////////////////////////////////////////
00034   
00035   // plant dynamics of machines 1 and 2
00036   // note: only the plant-I/O port (Up,Yp)  of HioPlant is used in this
00037   //         simple non-hierarchical example. The remaining port (Ue,Ye)
00038   //         is introduced as dummmy.
00039   HioPlant tempgen, machine1, machine2;
00040   tempgen.Read("data/1_introduction/hio_simplemachine_intro.gen");
00041   tempgen.Version("1",machine1);
00042   tempgen.Version("2",machine2);
00043   machine1.Write("tmp_hio_machine1_intro.gen");
00044   machine1.GraphWrite("tmp_hio_machine1_intro.png");
00045   machine2.Write("tmp_hio_machine2_intro.gen");
00046   machine2.GraphWrite("tmp_hio_machine2_intro.png");
00047   
00048   // plant inputs up and outputs yp
00049   EventSet up1, up2, yp1, yp2;
00050   up1=machine1.UpEvents();
00051   up2=machine2.UpEvents();
00052   yp1=machine1.YpEvents();
00053   yp2=machine2.YpEvents();
00054 
00055   ////////////////////
00056   // IOSHUFFLE
00057   ////////////////////  
00058   
00059   // note: only the plant-I/O port (Up,Yp)  of HioPlant is used in this
00060   //         simple non-hierarchical example. The remaining port (Ue,Ye)
00061   //         is introduced as dummmy.
00062   HioPlant plant;
00063   HioShuffle(machine1,machine2,plant);
00064   // ignore marking
00065   PrefixClosure(plant);
00066   // cosmetics
00067   StateMin(plant,plant);
00068   plant.StateNamesEnabled(false);
00069   //remove dummy events for file output
00070   tempgen=plant;
00071   Project(plant,yp1+yp2+up1+up2,tempgen);
00072   tempgen.SetYp(yp1+yp2);
00073   tempgen.SetUp(up1+up2);
00074   tempgen.Name("HioShuffle(Simple Machine_1,Simple Machine_2)");
00075   tempgen.Write("tmp_hio_ioshuffle_intro.gen");
00076   tempgen.GraphWrite("tmp_hio_ioshuffle_intro.png");
00077   // constraint to avoid err-states of ioshuffle
00078   HioConstraint ioconstr("data/1_introduction/hio_ioconstraint_intro.gen");
00079 
00080   ////////////////////
00081   // SPECIFICATION
00082   // (poses a constraint, in the non-hierarchical case)
00083   ////////////////////  
00084   
00085   HioConstraint spec("data/1_introduction/hio_specification_intro.gen");
00086   spec.Write("tmp_hio_specification_intro.gen");
00087   spec.GraphWrite("tmp_hio_specification_intro.png");
00088   // compose constraint and specification to compound requirement to be met by controller
00089   Parallel(spec,ioconstr,spec);  
00090   // in the hierarchical case, the actual specification is formulated over additional alphabets.
00091   // here, this spec and according alphabets and constraint are introduced as dummies
00092   HioPlant dummy_spec;
00093   Idx ds1=dummy_spec.InsInitState();
00094   dummy_spec.SetMarkedState(ds1);
00095   EventSet dummy_yc, dummy_uc;
00096   dummy_yc.Insert("yc");
00097   dummy_uc.Insert("uc");
00098   HioConstraint dummy_constraint;
00099   ds1=dummy_constraint.InsInitState();
00100   dummy_constraint.SetMarkedState(ds1);
00101   
00102   ////////////////////
00103   // SYNTHESIS
00104   ////////////////////    
00105   
00106   // note: only the controller-I/O port (Up,Yp)  of HioController is used in this
00107   //         simple non-hierarchical example. The remaining port (Uc,Yc)
00108   //         is introduced as dummmy.
00109   HioController controller;
00110   HioSynthUnchecked(plant,dummy_spec,dummy_constraint,spec,dummy_yc,dummy_uc,yp1+yp2,up1+up2,plant.YeEvents(),plant.UeEvents(),controller);
00111   
00112   // remove dummies yc,uc,ye,ue
00113   Project(controller,yp1+up1+yp2+up2,controller);
00114   // restore event attributes
00115   controller.SetYp(yp1+yp2);
00116   controller.SetUp(up1+up2);
00117   controller.Write("tmp_hio_controller_intro.gen");
00118   
00119     ////////////////////
00120     // CLOSED LOOP
00121     ////////////////////      
00122   Generator closedloop;
00123   Parallel(plant,controller,closedloop);
00124   // remove dummy events
00125   Project(closedloop,yp1+up1+yp2+up2,closedloop);
00126   closedloop.Write("tmp_hio_closedloop_intro.gen");
00127   
00128     ////////////////////
00129     // COMPARE WITH SCT
00130     ////////////////////   
00131   
00132   // remove nonphysical io events
00133   Generator supervisor;
00134   EventSet alphabeta;
00135   alphabeta.Insert("alpha_1");
00136   alphabeta.Insert("alpha_2");
00137   alphabeta.Insert("beta_1");
00138   alphabeta.Insert("beta_2");
00139   Project(closedloop,alphabeta,supervisor);
00140   supervisor.Write("tmp_hio_physical_intro.gen");
00141   //   ->  should lead to same supervisor as in Synthesis PlugIn example !
00142 
00143   return 0;
00144 }
00145 
00146 
00147 

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