syn_7_compsynth.cpp
Go to the documentation of this file.
1/**
2 * @file syn_7_compsynth.cpp
3 *
4 * Test case for compositional synthesis algorithm:
5 * Abfuellanlage
6
7 * @ingroup Tutorials
8*/
9
10#include "libfaudes.h"
11
12using namespace faudes;
13
14/////////////////
15// main program
16/////////////////
17
18int main() {
19
20 ////////////////////////////////////////////////////////////////
21 // prepare data
22 ////////////////////////////////////////////////////////////////
23
24 // helper
26
27 // input1: plants
28 faudes::GeneratorVector PlantGenVec;
29 gen.Read("data/syn_lfeed.gen");
30 PlantGenVec.PushBack(gen);
31 gen.Read("data/syn_lplace2.gen");
32 PlantGenVec.PushBack(gen);
33 gen.Read("data/syn_lplace3.gen");
34 PlantGenVec.PushBack(gen);
35 gen.Read("data/syn_lplace4.gen");
36 PlantGenVec.PushBack(gen);
37 gen.Read("data/syn_lplace5.gen");
38 PlantGenVec.PushBack(gen);
39 gen.Read("data/syn_lplace6.gen");
40 PlantGenVec.PushBack(gen);
41 gen.Read("data/syn_lplace7.gen");
42 PlantGenVec.PushBack(gen);
43 gen.Read("data/syn_lexit7.gen");
44 PlantGenVec.PushBack(gen);
45
46 // input2: controllable events
47 faudes::EventSet ConAlph;
48 ConAlph.Insert("V");
49 ConAlph.Insert("R");
50
51 // input3: specifications
52 faudes::GeneratorVector SpecGenVec;
53 gen.Read("data/syn_efeeda.gen");
54 SpecGenVec.PushBack(gen);
55 gen.Read("data/syn_eexit7.gen");
56 SpecGenVec.PushBack(gen);
57
58 // output1: map
59 std::map<faudes::Idx,faudes::Idx> MapEventsToPlant;
60 // output2: distinguishers
61 faudes::GeneratorVector DisGenVec;
62 // output3: supervisors
63 faudes::GeneratorVector SupGenVec;
64
65 ////////////////////////////////////////////////////////////////
66 // run algorithm
67 ////////////////////////////////////////////////////////////////
68
69 CompositionalSynthesis(PlantGenVec, ConAlph, SpecGenVec,
70 MapEventsToPlant, DisGenVec, SupGenVec);
71
72 ////////////////////////////////////////////////////////////////
73 // inspect result
74 ////////////////////////////////////////////////////////////////
75 using namespace faudes;
76
77 std::cout << "################################\n";
78 std::cout << "Hello, this is a test case for compositional synthesis \n";
79 std::cout << "################################\n";
80
81 // SHOW the map
82 faudes::SymbolTable* pEvSymTab = SupGenVec.At(0).EventSymbolTablep();
83 std::map<faudes::Idx,faudes::Idx>::iterator mit = MapEventsToPlant.begin();
84 std::cout << "################\n";
85 std::cout << "this is map\n";
86 std::cout << "################\n";
87 for(; mit != MapEventsToPlant.end(); ++mit) {
88 std::cout << "map "<<pEvSymTab->Symbol(mit->first) << " to ";
89 std::cout << pEvSymTab->Symbol(mit->second) << std::endl;
90 }
91
92 // SHOW the distinguisher
94 for(; i < DisGenVec.Size(); ++i) {
95 DisGenVec.At(i).Write();
96 // LOG
97 FAUDES_TEST_DUMP("DisGenVec_i",DisGenVec.At(i));
98 }
99
100 // SHOW the supervisor
101 for(i=0; i < SupGenVec.Size(); ++i) {
102 SupGenVec.At(i).Write();
103 // LOG
104 FAUDES_TEST_DUMP("SupGenVec_i",SupGenVec.At(i));
105 }
106
107 // SHOW the statistic
108 faudes::Idx Size = 0;
109 faudes::Idx TransRelSize = 0;
110 for(i=0; i < SupGenVec.Size(); ++i) {
111 Size += SupGenVec.At(i).Size();
112 TransRelSize += SupGenVec.At(i).TransRelSize();
113 }
114
115 std::cout<<" the number of supervisors is "<<SupGenVec.Size()<<std::endl;
116 std::cout<<" the total size is "<<Size<<std::endl;
117 std::cout<<" the total number of TransRel is "<<TransRelSize<<std::endl;
118 std::cout << "################################\n";
119
120 ////////////////////////////////////////////////////////////////
121 // monolithic representation
122 ////////////////////////////////////////////////////////////////
123
124 // !!ATTENTION: There must exist at least one distinguisher-generator
125 // in this case no distinguisher
126
127 /*
128 // single distinguisher
129 faudes::Generator SigDisGen;
130 faudes::aParallel(DisGenVec, SigDisGen);
131
132 // single supervisor
133 faudes::Generator SigSupGen;
134 faudes::aParallel(SupGenVec, SigSupGen);
135
136 // monolithic representation of supervisor with Sigma2 (alias)
137 faudes::Generator My_Closed;
138 faudes::Parallel(SigSupGen, SigDisGen, My_Closed);
139
140 // restore original events (Sigma2 -> Sigma1)
141 // construct inverse transition relation
142 faudes::TransSetEvX1X2 invtr;
143 My_Closed.TransRel(invtr);
144
145 // if need
146 mit = MapEventsToPlant.begin();
147 for(; mit != MapEventsToPlant.end(); ++mit) {
148 if(mit->first == mit->second) continue;
149
150 faudes::Idx kid = mit->first;
151 faudes::Idx parent = mit->second;
152
153 // insert parent
154 My_Closed.InsEvent(parent);
155 // replace transition
156 faudes::TransSetEvX1X2::Iterator tit = invtr.BeginByEv(kid);
157 for(; tit != invtr.EndByEv(kid); ++tit)
158 My_Closed.SetTransition(tit->X1, parent, tit->X2);
159 // remove kid
160 My_Closed.DelEvent(kid);
161 }
162 */
163
164 faudes::Generator My_Closed;
165 faudes::aParallel(SupGenVec,My_Closed);
166
167 // LOG
168 FAUDES_TEST_DUMP("Monolithic Representation",My_Closed);
169
170 // SHOW the statistic
171 std::cout << "the size of closed behavior is :\n";
172 std::cout << "the states : " << My_Closed.Size() << std::endl;
173 std::cout << "the TransRel : " << My_Closed.TransRelSize() << std::endl;
174 std::cout << "################################\n";
175
176 ////////////////////////////////////////////////////////////////
177 // Controllablity and Nonblocking
178 ////////////////////////////////////////////////////////////////
179
180 faudes::Generator Plant;
181 faudes::aParallel(PlantGenVec, Plant);
182
183 bool my_iscon = false;
184 my_iscon = faudes::IsControllable(Plant, ConAlph, My_Closed);
185
186 bool my_isNB = false;
187 my_isNB = faudes::IsNonblocking(My_Closed);
188
189 // LOG
190 FAUDES_TEST_DUMP("Controllablity Test",my_iscon);
191 FAUDES_TEST_DUMP("Nonblocking Test",my_isNB);
192
193 // SHOW
194 std::cout <<"the supervisor is " << (my_iscon?"":" not ") << "controllable\n";
195 std::cout <<"the supervisor is " << (my_isNB?"":" not ") << "nonblocking\n";
196
198
199 return 0;
200}
201
#define FAUDES_TEST_DIFF()
Definition cfl_utils.h:515
#define FAUDES_TEST_DUMP(mes, dat)
Definition cfl_utils.h:505
bool Insert(const Idx &rIndex)
std::string Symbol(Idx index) const
std::vector< int >::size_type Position
virtual const T & At(const Position &pos) const
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
void Write(const Type *pContext=0) const
virtual void PushBack(const Type &rElem)
SymbolTable * EventSymbolTablep(void) const
Idx TransRelSize(void) const
Idx Size(void) const
void aParallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
bool IsControllable(const Generator &rPlantGen, const EventSet &rCAlph, const Generator &rSupCandGen)
void CompositionalSynthesis(const GeneratorVector &rPlantGenVec, const EventSet &rConAlph, const GeneratorVector &rSpecGenVec, std::map< Idx, Idx > &rMapEventsToPlant, GeneratorVector &rDisGenVec, GeneratorVector &rSupGenVec)
uint32_t Idx
bool IsNonblocking(const GeneratorVector &rGvec)
int main()

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