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