hio_1_introduction.cpp
Go to the documentation of this file.
1 /** @file hio_1_introduction.cpp
2 
3 Tutorial, simple i/o-based controller synthesis.
4 
5 This tutorial uses a very simple example to exhibit
6 monolithic input-/output based controller synthesis.
7 The purpose is to generate graphs for the
8 introduction of hiosys in the libFAUDES user
9 reference, see "hiosys_index.html".
10 For other purposes such as learning how to use hiosys,
11 we refer to the tutorials hio_2_hiogenerators,
12 hio_3_hiofunctions and hio_4_transport_unit.
13 
14 @ingroup Tutorials
15 
16 @include hio_1_introduction.cpp
17 
18 */
19 
20 #include "libfaudes.h"
21 
22 // make the faudes namespace available to our program
23 using namespace faudes;
24 
25 /////////////////
26 // main program
27 /////////////////
28 
29 int main() {
30 
31  ////////////////////////////////////////////
32  // PLANT MODEL WITH INPUTS AND OUTPUTS
33  ////////////////////////////////////////////
34 
35  // plant dynamics of machines 1 and 2
36  // note: only the plant-I/O port (Up,Yp) of HioPlant is used in this
37  // simple non-hierarchical example. The remaining port (Ue,Ye)
38  // is introduced as dummmy.
39  HioPlant tempgen, machine1, machine2;
40  tempgen.Read("data/1_introduction/hio_simplemachine_intro.gen");
41  tempgen.Version("1",machine1);
42  tempgen.Version("2",machine2);
43  machine1.Write("tmp_hio_machine1_intro.gen");
44  machine1.GraphWrite("tmp_hio_machine1_intro.png");
45  machine2.Write("tmp_hio_machine2_intro.gen");
46  machine2.GraphWrite("tmp_hio_machine2_intro.png");
47 
48  // plant inputs up and outputs yp
49  EventSet up1, up2, yp1, yp2;
50  up1=machine1.UpEvents();
51  up2=machine2.UpEvents();
52  yp1=machine1.YpEvents();
53  yp2=machine2.YpEvents();
54 
55  ////////////////////
56  // IOSHUFFLE
57  ////////////////////
58 
59  // note: only the plant-I/O port (Up,Yp) of HioPlant is used in this
60  // simple non-hierarchical example. The remaining port (Ue,Ye)
61  // is introduced as dummmy.
62  HioPlant plant;
63  HioShuffle(machine1,machine2,plant);
64  // ignore marking
65  PrefixClosure(plant);
66  // cosmetics
67  StateMin(plant,plant);
68  plant.StateNamesEnabled(false);
69  //remove dummy events for file output
70  tempgen=plant;
71  Project(plant,yp1+yp2+up1+up2,tempgen);
72  tempgen.SetYp(yp1+yp2);
73  tempgen.SetUp(up1+up2);
74  tempgen.Name("HioShuffle(Simple Machine_1,Simple Machine_2)");
75  tempgen.Write("tmp_hio_ioshuffle_intro.gen");
76  tempgen.GraphWrite("tmp_hio_ioshuffle_intro.png");
77  // constraint to avoid err-states of ioshuffle
78  HioConstraint ioconstr("data/1_introduction/hio_ioconstraint_intro.gen");
79 
80  ////////////////////
81  // SPECIFICATION
82  // (poses a constraint, in the non-hierarchical case)
83  ////////////////////
84 
85  HioConstraint spec("data/1_introduction/hio_specification_intro.gen");
86  spec.Write("tmp_hio_specification_intro.gen");
87  spec.GraphWrite("tmp_hio_specification_intro.png");
88  // compose constraint and specification to compound requirement to be met by controller
89  Parallel(spec,ioconstr,spec);
90  // in the hierarchical case, the actual specification is formulated over additional alphabets.
91  // here, this spec and according alphabets and constraint are introduced as dummies
92  HioPlant dummy_spec;
93  Idx ds1=dummy_spec.InsInitState();
94  dummy_spec.SetMarkedState(ds1);
95  EventSet dummy_yc, dummy_uc;
96  dummy_yc.Insert("yc");
97  dummy_uc.Insert("uc");
98  HioConstraint dummy_constraint;
99  ds1=dummy_constraint.InsInitState();
100  dummy_constraint.SetMarkedState(ds1);
101 
102  ////////////////////
103  // SYNTHESIS
104  ////////////////////
105 
106  // note: only the controller-I/O port (Up,Yp) of HioController is used in this
107  // simple non-hierarchical example. The remaining port (Uc,Yc)
108  // is introduced as dummmy.
109  HioController controller;
110  HioSynthUnchecked(plant,dummy_spec,dummy_constraint,spec,dummy_yc,dummy_uc,yp1+yp2,up1+up2,plant.YeEvents(),plant.UeEvents(),controller);
111 
112  // remove dummies yc,uc,ye,ue
113  Project(controller,yp1+up1+yp2+up2,controller);
114  // restore event attributes
115  controller.SetYp(yp1+yp2);
116  controller.SetUp(up1+up2);
117  controller.Write("tmp_hio_controller_intro.gen");
118 
119  ////////////////////
120  // CLOSED LOOP
121  ////////////////////
122  Generator closedloop;
123  Parallel(plant,controller,closedloop);
124  // remove dummy events
125  Project(closedloop,yp1+up1+yp2+up2,closedloop);
126  closedloop.Write("tmp_hio_closedloop_intro.gen");
127 
128  ////////////////////
129  // COMPARE WITH SCT
130  ////////////////////
131 
132  // remove nonphysical io events
133  Generator supervisor;
134  EventSet alphabeta;
135  alphabeta.Insert("alpha_1");
136  alphabeta.Insert("alpha_2");
137  alphabeta.Insert("beta_1");
138  alphabeta.Insert("beta_2");
139  Project(closedloop,alphabeta,supervisor);
140  supervisor.Write("tmp_hio_physical_intro.gen");
141  // -> should lead to same supervisor as in Synthesis PlugIn example !
142 
143  return 0;
144 }
145 
146 
147 
Set of indices with symbolic names.
Definition: cfl_nameset.h:69
bool Insert(const Idx &rIndex)
Add an element by index.
void SetYp(Idx index)
Mark event as Yp-event (by index)
void SetUp(Idx index)
Mark event Up-event(by index)
void SetYp(Idx index)
Mark event as Yp-event (by index)
Definition: hio_plant.h:1033
EventSet UeEvents(void) const
Get EventSet with Ue-events.
Definition: hio_plant.h:1252
EventSet UpEvents(void) const
Get EventSet with Up-events.
Definition: hio_plant.h:1118
void SetUp(Idx index)
Mark event Up-event(by index)
Definition: hio_plant.h:1058
EventSet YpEvents(void) const
Get EventSet with Yp-events.
Definition: hio_plant.h:1107
EventSet YeEvents(void) const
Get EventSet with Ye-events.
Definition: hio_plant.h:1241
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
Definition: cfl_types.cpp:261
void Write(const Type *pContext=0) const
Write configuration data to console.
Definition: cfl_types.cpp:139
Base class of all FAUDES generators.
void Name(const std::string &rName)
Set the generator's name.
void SetMarkedState(Idx index)
Set an existing state as marked state by index.
Idx InsInitState(void)
Create new anonymous state and set as initial state.
bool StateNamesEnabled(void) const
Whether libFAUEDS functions are requested to generate state names.
void GraphWrite(const std::string &rFileName, const std::string &rOutFormat="", const std::string &rDotExec="dot") const
Produce graphical representation of this generator.
virtual void Version(const std::string &rVersion, vGenerator &rResGen) const
Create another version of this generator.
void StateMin(const Generator &rGen, Generator &rResGen)
State set minimization.
void PrefixClosure(Generator &rGen)
Prefix Closure.
void Project(const Generator &rGen, const EventSet &rProjectAlphabet, Generator &rResGen)
Deterministic projection.
void Parallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Parallel composition.
void HioSynthUnchecked(const Generator &rPlant, const Generator &rSpec, const Generator &rExtConstr, const Generator &rLocConstr, const EventSet &rYc, const EventSet &rUc, const EventSet &rYp, const EventSet &rUp, const EventSet &rYel, const EventSet &rUel, Generator &rController)
HioSynthUnchecked: I/O controller synthesis procedure, no parameter check.
void HioShuffle(const Generator &rPlantA, const Generator &rPlantB, const EventSet &rYp, const EventSet &rUp, const EventSet &rYe, const EventSet &rUe, Generator &rIOShuffAB)
HioShuffle: IO-shuffle of rPlantA and rPlantB according to definition.
int main()
Includes all libFAUDES headers, incl plugings
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen