con_supcc.cpp
Go to the documentation of this file.
1 /** @file con_controllability.cpp Conditionalcontrollability */
2 
3 /*
4  * Implementation of the conditionally controllable algorithm
5  *
6  * Copyright (C) 2012 Tomas Masopust
7  *
8  */
9 
10 
11 #include "con_supcc.h"
12 #include "con_include.h"
13 #include "op_include.h"
14 #include <vector>
15 
16 namespace faudes {
17 
19  const Generator& gen,
20  const GeneratorVector& genVector,
21  const EventSet& ACntrl,
22  const EventSet& InitEk,
23  GeneratorVector& supVector,
24  Generator& Coord) {
25 
26  /* Steps of the algorithm
27  * 1. compute Ek so that it contains all shared events
28  * 2. extend Ek so that K = L(gen) is CD
29  * 3. extend Ek so that Pk is Li-observer, i=1,2,...,n
30  * 4. compute the coordinator Gk and supCk, supCi+k
31  * 5. if supCk subseteq Pk(supCi+k), return supCi+k and the supervised coordinator (supCk)
32  * 6. extend Ek so that P^{i+k}_k is (P^{i+k}_k)^{-1}(Li)-observer and OCC for that language
33  * 7. recompute supCi+k a return them and the supervised coordinator
34  */
35 
36  Idx i;
37 
38  // the generators must be deterministic and prefix-closed
39  if (gen.IsDeterministic() == false || IsPrefixClosed(gen) == false) {
40  std::stringstream errstr;
41  errstr << "Generators must be deterministic and prefix-closed";
42  throw Exception("ConditionalControllability", errstr.str(), 201);
43  }
44  for (i = 0; i < genVector.Size(); i++) {
45  if (genVector.At(i).IsDeterministic() == false || IsPrefixClosed(genVector.At(i)) == false) {
46  std::stringstream errstr;
47  errstr << "Generators of genVector must be deterministic and prefix-closed";
48  throw Exception("ConditionalControllability", errstr.str(), 201);
49  }
50  }
51 
52 /* 1. compute Ek so that it contains all shared events */
53  EventSet unionset; // contains union of Ei
54  EventSet shared; // contains union of intersections
55 
56  // Compute unionset
57  for (i = 0; i < genVector.Size(); i++) {
58  SetUnion(unionset,genVector.At(i).Alphabet(),unionset);
59  }
60 
61  // Compute the set of shared events
62  for (i = 0; i < genVector.Size(); i++) {
63  for (Idx j = 0; j < genVector.Size(); j++) {
64  if (j != i) {
65  EventSet eHelpInt;
66  SetIntersection(genVector.At(i).Alphabet(),genVector.At(j).Alphabet(),eHelpInt);
67  SetUnion(shared,eHelpInt,shared);
68  }
69  }
70  }
71 
72  EventSet ek = shared + InitEk;
73  std::cerr << "Initial Ek = { ";
74  EventSet::Iterator eit;
75  for (eit=ek.Begin(); eit != ek.End(); ++eit) {
76  std::cerr << ek.SymbolicName(*eit) << " ";
77  }
78  std::cerr << "}" << std::endl;
79 
80  // Alphabet of the generator must be under union Ei
81  bool ok = SetInclusion(gen.Alphabet(),unionset);
82  if (ok == false) {
83  std::stringstream errstr;
84  errstr << "Generator alphabet is not included in union of the alphabets";
85  throw Exception("ConditionalDecomposability", errstr.str(), 100);
86  }
87 
88  // Alphabet of the generator must contain Ek
89  ok = SetInclusion(ek,gen.Alphabet());
90  if (ok == false) {
91  std::stringstream errstr;
92  errstr << "Generator alphabet does not include the alphabet ek";
93  throw Exception("ConditionalDecomposability", errstr.str(), 100);
94  }
95 
96 /* 2. extend Ek so that K = L(gen) is CD */
97  std::cerr << "Extension of Ek for Conditional Decomposability..." << std::endl;
98  EventSetVector ee;
99  for (i = 0; i < genVector.Size(); i++) {
100  ee.Append(genVector.At(i).Alphabet());
101  }
102  ConDecExtension(gen,ee,ek);
103 
104 /* 3. extend Ek so that Pk is Li-observer, i=1,2,...,n */
105  bool repeat = true;
106  std::cerr << "Extension of Ek for Li-observers..." << std::endl;
107  while (repeat) {
108  repeat = false;
109  for (i = 0; i < genVector.Size(); i++) {
110  if (IsObs(genVector.At(i),ek*genVector.At(i).Alphabet()) == false ) {
111  repeat = true;
112  EventSet ekHelp = ek * genVector.At(i).Alphabet();
113  calcNaturalObserver(genVector.At(i),ekHelp);
114  SetUnion(ek,ekHelp,ek);
115  }
116  }
117  }
118  std::cerr << "Extended Ek = { ";
119  for (eit=ek.Begin(); eit != ek.End(); ++eit) {
120  std::cerr << ek.SymbolicName(*eit) << " ";
121  }
122  std::cerr << "}" << std::endl;
123 
124 /* 4. compute the coordinator Gk and supCk, supCi+k */
125  // coordinator Gk = || P_k(G_i)
126  Generator gk;
127  FullLanguage(ek,gk);
128  for (i = 0; i < genVector.Size(); i++) {
129  Generator pomGen;
130  Project(genVector.At(i),ek,pomGen);
131  Parallel(gk,pomGen,gk);
132  }
133 
134  // compute P_k(K) and the vector of P_{i+k}(K)
135  Generator pk;
136  Project(gen,ek,pk);
137  GeneratorVector specVect;
138  for (i = 0; i < genVector.Size(); i++) {
139  Generator pomGen;
140  Project(gen,ek+genVector.At(i).Alphabet(),pomGen);
141  specVect.Append(pomGen);
142  }
143 
144  // the set of controllable events E_{k,c}
145  EventSet ekc;
146  SetIntersection(ek,ACntrl,ekc);
147  // supCk supervisor
148  Generator supCk;
149  // vector of supC_{i+k} supervisors
150  GeneratorVector supCkVector;
151 
152  // compute supremal controllable sublanguage of P_k(K) wrt L(G_k) and E_{k,c}
153  // if (IsControllable(gk,ekc,pk)) -- DO NOT USE, if K not subset of L, then the results are wrong!!!
154  SupConClosed(gk,ekc,pk,supCk);
155 
156  // compute supremal controllable sublanguage of P_{i+k}(K) wrt L(G_i)||supCk and E_{1+k,c}
157  for (i = 0; i < genVector.Size(); i++) {
158  Generator helpPlant;
159  Parallel(genVector.At(i),supCk,helpPlant);
160  Generator supCik;
161  SupConClosed(helpPlant,helpPlant.Alphabet()*ACntrl,specVect.At(i),supCik);
162  supCkVector.Append(supCik); // supC_{i+k} = supCik
163  }
164 
165 /* 5. if supCk subseteq Pk(supCi+k), return supCi+k and the supervised coordinator*/
166  bool incl = true;
167  // TODO -- implement this test nodeterministically!!!
168  for (i = 0; i < supCkVector.Size(); i++) {
169  Generator PkHelp;
170  Project(supCkVector.At(i),ek,PkHelp);
171  incl = incl && LanguageInclusion(supCk,PkHelp);
172  }
173  // incl = true ==> ok
174  if (incl) {
175  Coord = supCk;
176  supVector = supCkVector;
177  std::cout << "Finished: supCk is a subset of all Pk(supCi+k)." << std::endl;
178  return true;
179  }
180 
181 /* 6. extend Ek so that P^{i+k}_k is (P^{i+k}_i)^{-1}(Li)-observer and OCC for that language */
182 // Here LCC is used instead of OCC
183  // compute a vector of (P^{i+k}_k)^{-1}(Li)
184  GeneratorVector invLiVect;
185  for (i = 0; i < genVector.Size(); i++) {
186  Generator invLi;
187  aInvProject(genVector.At(i),ek+genVector.At(i).Alphabet(),invLi);
188  invLiVect.Append(invLi);
189  }
190  repeat = true;
191  while (repeat) {
192  repeat = false;
193  for (i = 0; i < invLiVect.Size(); i++) {
194  if (IsObs(invLiVect.At(i),ek) && IsLCC(invLiVect.At(i),ek) == false ) {
195  repeat = true;
196  calcNaturalObserverLCC(genVector.At(i),ekc,ek);
197  }
198  }
199  }
200 
201 /* 7. recompute supCi+k a return them and the supervised coordinator*/
202  // recompute the set of controllable events E_{k,c}
203  ekc = ek * ACntrl;
204  supCk.Clear();
205  supCkVector.Clear();
206 
207  // coordinator Gk = || P_k(G_i)
208  gk.Clear();
209  FullLanguage(ek,gk);
210  for (i = 0; i < genVector.Size(); i++) {
211  Generator pomGen;
212  Project(genVector.At(i),ek,pomGen);
213  Parallel(gk,pomGen,gk);
214  }
215 
216  // compute P_k(K) and the vector of P_{i+k}(K)
217  pk.Clear();
218  Project(gen,ek,pk);
219  specVect.Clear();
220  for (i = 0; i < genVector.Size(); i++) {
221  Generator pomGen;
222  Project(gen,ek+genVector.At(i).Alphabet(),pomGen);
223  specVect.Append(pomGen);
224  }
225 
226  // compute supremal controllable sublanguage of P_k(K) wrt L(G_k) and E_{k,c}
227  SupConClosed(gk,ekc,pk,supCk);
228 
229  // compute supremal controllable sublanguages of P_{i+k}(K) wrt L(G_i)||supCk and E_{1+k,c}
230  for (i = 0; i < genVector.Size(); i++) {
231  Generator helpPlant;
232  Parallel(genVector.At(i),supCk,helpPlant);
233  Generator supCik;
234  SupConClosed(helpPlant,helpPlant.Alphabet()*ACntrl,specVect.At(i),supCik);
235  supCkVector.Append(supCik); // supC_{i+k} = supCik
236  }
237 
238  // the resulting supervisors
239  supVector = supCkVector;
240  Coord = supCk;
241  std::cout << "Finished: supCk was NOT a subset of all Pk(supCi+k)." << std::endl;
242  return true;
243 
244 }
245 
246 
247 } // name space
248 
249 
250 
Faudes exception class.
Set of indices with symbolic names.
Definition: cfl_nameset.h:69
void SymbolicName(Idx index, const std::string &rName)
Set new name for existing index.
virtual const T & At(const Position &pos) const
Access element.
virtual void Append(const Type &rElem)
Append specified entry.
Idx Size(void) const
Get size of vector.
virtual void Clear(void)
Clear all vector.
Base class of all FAUDES generators.
const EventSet & Alphabet(void) const
Return const reference to alphabet.
bool IsDeterministic(void) const
Check if generator is deterministic.
virtual void Clear(void)
Clear generator data.
Includes all header files of the coordinationcontrol plug-in.
bool SetInclusion(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB)
Definition: cfl_baseset.h:1128
Iterator End(void) const
Iterator to the end of set.
Definition: cfl_baseset.h:1896
Iterator Begin(void) const
Iterator to the begin of set.
Definition: cfl_baseset.h:1891
void SetUnion(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
Definition: cfl_baseset.h:1019
void SetIntersection(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
Definition: cfl_baseset.h:1049
void ConDecExtension(const Generator &gen, const EventSetVector &rAlphabets, EventSet &ek)
Conditionaldecomposability Extension Algorithm.
bool SupConditionalControllable(const Generator &gen, const GeneratorVector &genVector, const EventSet &ACntrl, const EventSet &InitEk, GeneratorVector &supVector, Generator &Coord)
Conditionalcontrollability Checking Algorithm.
Definition: con_supcc.cpp:18
void FullLanguage(const EventSet &rAlphabet, Generator &rResGen)
Full Language, L(G)=Lm(G)=Sigma*.
bool LanguageInclusion(const Generator &rGen1, const Generator &rGen2)
Test language inclusion, Lm1<=Lm2.
void aInvProject(Generator &rGen, const EventSet &rProjectAlphabet)
Inverse projection.
bool IsPrefixClosed(const Generator &rGen)
Test for prefix closed marked language.
void Project(const Generator &rGen, const EventSet &rProjectAlphabet, Generator &rResGen)
Deterministic projection.
void Parallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Parallel composition.
Int calcNaturalObserverLCC(const Generator &rGen, const EventSet &rControllableEvents, EventSet &rHighAlph)
Lm(G)-observer computation including local control consistency (LCC) by adding events to the high-lev...
bool IsLCC(const System &rLowGen, const EventSet &rHighAlph)
Verification of local control consistency (LCC).
bool IsObs(const Generator &rLowGen, const EventSet &rHighAlph)
Verification of the natural observer property.
Int calcNaturalObserver(const Generator &rGen, EventSet &rHighAlph)
Lm(G)-observer computation by adding events to the high-level alphabet.
void SupConClosed(const Generator &rPlantGen, const EventSet &rCAlph, const Generator &rSpecGen, Generator &rResGen)
Supremal Controllable and Closed Sublanguage.
Definition: syn_supcon.cpp:778
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
Includes all observer plugin headers.

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