mtc_3_observer.cpp
Go to the documentation of this file.
1/** @file mtc_3_observer.cpp
2
3Tutorial, MtcSystem observer computation
4
5@ingroup Tutorials
6
7@include mtc_3_observer.cpp
8*/
9
10// This tutotial is BROKEN. Need to go back to version 2.13a and FIX. Sorry.
11
12#include "libfaudes.h"
13#include "mtc_include.h"
14
15
16// Make namespaces available to our program (lazy)
17using namespace faudes;
18using namespace std;
19
20
21/////////////////
22// main program
23/////////////////
24
25int main() {
26
27
28
29 MtcSystem cb4_0, cb4_0_spec1, cb4_0_spec2, cb4_0_spec, cb4_0_sup, cb4_1,
30 mh1d1_0_sup, mh1d1_1,
31 cb4_1_spec, cb11_1_spec, mh1d1_1_spec,
32 rt1_1_spec, rt1_1_spec1, rt1_1_spec2,
33 cb4mh1d1_1, cb4mh1d1_1_spec, cb4mh1d1_1_sup, cb4mh1d1_2, cb4mh1d1_2_orig;
34
35// We explain the relevant methods using a manufacturing system example that is
36// a part of the example in
37// K. Schmidt and J.E.R. Cury, "Redundant Tasks in Multitasking Control of Discrete Event Systems", Workshop on Dependable Control of Discrete Event Systems, 2009.
38
39
40// First a synthesis without removing redundant colors is performed
41// Read Plant generators
42 // cb4[0]
43 cb4_0.Read("data/cb4[0].gen");
44 cb4_0.GraphWrite("tmp_mtc_cb4[0].png");
45 // mh1d1[0]_sup
46 mh1d1_0_sup.Read("data/mh1d1[0]_sup.gen");
47 mh1d1_0_sup.GraphWrite("tmp_mtc_mh1d1[0]_sup.png");
48
49// Read Specifications
50 // cb4[0]_spec1
51 cb4_0_spec1.Read("data/cb4[0]_spec1.gen");
52 cb4_0_spec1.GraphWrite("tmp_mtc_cb4[0]_spec1.png");
53 mtcInvProject(cb4_0_spec1, cb4_0.Alphabet());
54 // cb4[0]_spec2
55 cb4_0_spec2.Read("data/cb4[0]_spec2.gen");
56 cb4_0_spec2.GraphWrite("tmp_mtc_cb4[0]_spec2.png");
57
58 // cb4[1]_spec
59 cb4_1_spec.Read("data/cb4[1]_spec.gen");
60 cb4_1_spec.GraphWrite("tmp_mtc_cb4[1]_spec.png");
61 // mh1d1[1]_spec
62 mh1d1_1_spec.Read("data/mh1d1[1]_spec.gen");
63 mh1d1_1_spec.GraphWrite("tmp_mtc_mh1d1[1]_spec.png");
64
65 // Supervisor Synthesis
66
67 // cb4[0]_sup
68 {
69 std::cout << std::endl << "MtcParallel(cb4[0]_spec1, cb4[0]_spec2) => cb4[0]_spec" << std::endl;
70 mtcParallel(cb4_0_spec1, cb4_0_spec2, cb4_0_spec);
71 cb4_0_spec.Write("tmp_mtc_cb4[0]_spec.gen");
72 cb4_0_spec.GraphWrite("tmp_mtc_cb4[0]_spec.png");
73
74 std::cout << "MtcSupCon(cb4[0], cb4[0]_spec) => cb4[0]_sup" << std::endl << std::endl;
75 mtcSupCon(cb4_0, cb4_0_spec, cb4_0_sup);
76
77 cb4_0_sup.Write("tmp_mtc_cb4[0]_sup.gen");
78 cb4_0_sup.GraphWrite("tmp_mtc_cb4[0]_sup.png");
79 }
80
81/////////////////
82// Level 1
83/////////////////
84
85 // cb4[1]
86 {
87 EventSet cb4_1_alph;
88 cb4_1_alph.Insert("cb11-cb4");
89 cb4_1_alph.Insert("cb12-cb4");
90 cb4_1_alph.Insert("cb4-cb11");
91 cb4_1_alph.Insert("cb4-cb12");
92 cb4_1_alph.Insert("cb4stp");
93
94 if (IsMtcObs(cb4_0_sup, cb4_1_alph)) {
95 std::cout << "Project(cb4[0]_sup) => cb4[1], with alphabet: " << cb4_1_alph.ToString() << std::endl << std::endl;
96 mtcProject(cb4_0_sup, cb4_1_alph, cb4_1);
97 }
98 else std::cout << "cb4[0]_sup: Observer condition is not fulfilled" << std::endl;
99
100 cb4_1.StateNamesEnabled(false);
101 cb4_1.Write("tmp_mtc_cb4[1].gen");
102 cb4_1.GraphWrite("tmp_mtc_cb4[1].png");
103 }
104 // mh1d1[1]
105 {
106 EventSet mh1d1_1_alph;
107 mh1d1_1_alph.Insert("mh1start");
108 mh1d1_1_alph.Insert("mh1end");
109
110 if (IsMtcObs(mh1d1_0_sup, mh1d1_1_alph)) {
111 std::cout << "Project(mh1d1[0]_sup) => mh1d1[1], with alphabet: " << mh1d1_1_alph.ToString() << std::endl << std::endl;
112 mtcProject(mh1d1_0_sup, mh1d1_1_alph, mh1d1_1);
113 }
114 else std::cout << "mh1d1[0]_sup: Observer condition is not fulfilled" << std::endl;
115
116 mh1d1_1.StateNamesEnabled(false);
117 mh1d1_1.Write("tmp_mtc_mh1d1[1].gen");
118 mh1d1_1.GraphWrite("tmp_mtc_mh1d1[1].png");
119 }
120 // cb4mh1d1[1]_sup
121 {
122 std::cout << "MtcParallel(cb4[1], mh1d1[1]) => cb4mh1d1[1]" << std::endl;
123 mtcParallel(cb4_1, mh1d1_1, cb4mh1d1_1);
124 cb4mh1d1_1.Write("tmp_mtc_cb4mh1d1_1.gen");
125 cb4mh1d1_1.GraphWrite("tmp_mtc_cb4mh1d_1.png");
126 std::cout << "MtcSupCon(cb4mh1d1[1], cb4mh1d1[1]_spec) => cb4mh1d1[1]_sup" << std::endl << std::endl;
127 mtcInvProject(mh1d1_1_spec, cb4mh1d1_1.Alphabet() );
128 //MtcInvProject(cb4mh1d1_1, cb4mh1d1_1.Alphabet()+cb4mh1d1_1_spec.Alphabet());
129 mtcSupCon(cb4mh1d1_1, mh1d1_1_spec, cb4mh1d1_1_sup);
130
131 cb4mh1d1_1_sup.Write("tmp_mtc_cb4mh1d1_1_sup.gen");
132 cb4mh1d1_1_sup.GraphWrite("tmp_mtc_cb4mh1d1_1_sup.png");
133 }
134
135
136/////////////////
137// Level 2
138/////////////////
139 // cb4mh1d1[2]
140 {
141 EventSet cb4mh1d1_2_alph;
142 cb4mh1d1_2_alph.Insert("cb11-cb4");
143 cb4mh1d1_2_alph.Insert("cb12-cb4");
144 cb4mh1d1_2_alph.Insert("cb4-cb11");
145 cb4mh1d1_2_alph.Insert("cb4-cb12");
146 cb4mh1d1_2_alph.Insert("mh1end");
147 // compute the abstraction with the original colors
148 mtcProject(cb4mh1d1_1_sup, cb4mh1d1_2_alph, cb4mh1d1_2_orig);
149 // cb4mh1d1[2]
150 {
151 EventSet cb4mh1d1_2_alph;
152 cb4mh1d1_2_alph.Insert("cb11-cb4");
153 cb4mh1d1_2_alph.Insert("cb12-cb4");
154 cb4mh1d1_2_alph.Insert("cb4-cb11");
155 cb4mh1d1_2_alph.Insert("cb4-cb12");
156 cb4mh1d1_2_alph.Insert("mh1end");
157 // compute the abstraction with the original colors
158 mtcProject(cb4mh1d1_1_sup, cb4mh1d1_2_alph, cb4mh1d1_2_orig);
159 cb4mh1d1_2_orig.StateNamesEnabled(false);
160 cb4mh1d1_2_orig.Write("tmp_mtc_cb4mh1d1_2_orig.gen");
161 cb4mh1d1_2_orig.GraphWrite("tmp_mtc_cb4mh1d1_2_orig.png");
162 }
163 cb4mh1d1_2_orig.StateNamesEnabled(false);
164 cb4mh1d1_2_orig.Write("tmp_mtc_cb4mh1d1_2_orig.gen");
165 cb4mh1d1_2_orig.GraphWrite("tmp_mtc_cb4mh1d1_2_orig.png");
166 }
167
168// ==============================
169// computation with color removal
170// ==============================
171
172/////////////////
173// Level 2
174/////////////////
175 // cb4mh1d1[2]
176 {
177 // reduction of the color set
178 ColorSet optimalColors;
179 EventSet cb4mh1d1_2_alph;
180 cb4mh1d1_2_alph.Clear();
181 cb4mh1d1_2_alph.Insert("cb11-cb4");
182 cb4mh1d1_2_alph.Insert("cb12-cb4");
183 cb4mh1d1_2_alph.Insert("cb4-cb11");
184 cb4mh1d1_2_alph.Insert("cb4-cb12");
185 OptimalColorSet(cb4mh1d1_1_sup,optimalColors, cb4mh1d1_2_alph);
186 cout << "these are the optimal colors " << endl;
187 optimalColors.Write();
188 cout << "this is the optimal alphabet " << endl;
189 cb4mh1d1_2_alph.Write();
190
191 ColorSet redundantColors = cb4mh1d1_1_sup.Colors() - optimalColors;
192 ColorSet::Iterator cIt = redundantColors.Begin();
193 for( ; cIt != redundantColors.End(); cIt++){
194 cb4mh1d1_1_sup.DelColor(*cIt);
195 }
196
197 if (IsMtcObs(cb4mh1d1_1_sup, cb4mh1d1_2_alph)) {
198 std::cout << "Project(cb4mh1d1[0]_sup) => cb4mh1d1[2], with alphabet: " << cb4mh1d1_2_alph.ToString() << std::endl << std::endl;
199 mtcProject(cb4mh1d1_1_sup, cb4mh1d1_2_alph, cb4mh1d1_2);
200 }
201 else std::cout << "cb4mh1d1[1]_sup: Observer condition is not fulfilled" << std::endl;
202
203 cb4mh1d1_2.StateNamesEnabled(false);
204 cb4mh1d1_2.Write("tmp_mtc_cb4mh1d1_2.gen");
205 cb4mh1d1_2.GraphWrite("tmp_mtc_cb4mh1d1_2.png");
206 }
207
208} // end main()
bool Insert(const Idx &rIndex)
const TaEventSet< EventAttr > & Alphabet(void) const
void Colors(ColorSet &rColors) const
void DelColor(Idx stateIndex, const std::string &rColorName)
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
void Write(const Type *pContext=0) const
bool StateNamesEnabled(void) const
void GraphWrite(const std::string &rFileName, const std::string &rOutFormat="", const std::string &rDotExec="dot") const
virtual void Clear(void)
Iterator End(void) const
Iterator Begin(void) const
void mtcProject(const MtcSystem &rGen, const EventSet &rProjectAlphabet, MtcSystem &rResGen)
void OptimalColorSet(const MtcSystem &rGen, ColorSet &rOptimalColors, EventSet &rHighAlph)
void mtcInvProject(MtcSystem &rGen, const EventSet &rProjectAlphabet)
bool IsMtcObs(const MtcSystem &rLowGen, const EventSet &rHighAlph)
void mtcSupCon(const MtcSystem &rPlantGen, const MtcSystem &rSpecGen, MtcSystem &rResGen)
void mtcParallel(const MtcSystem &rGen1, const MtcSystem &rGen2, MtcSystem &rResGen)
int main()

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen