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()
Test protocol diff macro.
Definition: cfl_helper.h:493
#define FAUDES_TEST_DUMP(mes, dat)
Test protocol record macro ("mangle" filename for platform independance)
Definition: cfl_helper.h:483
Set of indices with symbolic names.
Definition: cfl_nameset.h:69
bool Insert(const Idx &rIndex)
Add an element by index.
A SymbolTable associates sybolic names with indices.
std::string Symbol(Idx index) const
Symbolic name lookup.
Iterator class for high-level api to TBaseSet.
Definition: cfl_baseset.h:387
std::vector< int >::size_type Position
convenience typedef for positions
virtual const T & At(const Position &pos) const
Access element.
Set of Transitions.
Definition: cfl_transset.h:242
Iterator EndByEv(Idx ev) const
Iterator to first Transition after specified by event.
Iterator BeginByEv(Idx ev) const
Iterator to first Transition specified by event.
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
virtual void PushBack(const Type &rElem)
Append specified entry.
Idx Size(void) const
Get size of vector.
Base class of all FAUDES generators.
const TransSet & TransRel(void) const
Return reference to transition relation.
bool SetTransition(Idx x1, Idx ev, Idx x2)
Add a transition to generator by indices.
SymbolTable * EventSymbolTablep(void) const
Get Pointer to EventSymbolTable currently used by this vGenerator.
bool DelEvent(Idx index)
Delete event from generator by index.
bool InsEvent(Idx index)
Add an existing event to alphabet by index.
Idx TransRelSize(void) const
Get number of transitions.
Idx Size(void) const
Get generator size (number of states)
void aParallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Parallel composition.
void Parallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Parallel composition.
bool IsControllable(const Generator &rPlantGen, const EventSet &rCAlph, const Generator &rSupCandGen)
Test controllability.
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)
Compositional synthesis.
Includes all libFAUDES headers, incl plugings
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
bool IsNonblocking(const GeneratorVector &rGvec)
int main()

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