syn_2_ctrlpfx.cpp
Go to the documentation of this file.
1 /** @file syn_2_ctrlpfx.cpp
2 
3 Tutorial, controllability prefix
4 
5 
6 @ingroup Tutorials
7 
8 @include syn_2_ctrlpfx.cpp
9 
10 */
11 
12 #include "libfaudes.h"
13 
14 
15 // we make the faudes namespace available to our program
16 using namespace faudes;
17 
18 
19 
20 
21 /////////////////
22 // main program
23 /////////////////
24 
25 int main() {
26 
27  /////////////////////////////////////////////
28  // Demo of mu/nu fixpoint iterations
29  // (this is the example used in out IFAC2020 contribution)
30  /////////////////////////////////////////////
31 
32 
33  // Read example data from file
34  System sys("data/syn_2_ctrlpfx.gen");
35 
36  // Have controllabe events
37  EventSet sigctrl=sys.ControllableEvents();
38 
39  // Report to console
40  std::cout << "################################\n";
41  std::cout << "# generator \n";
42  sys.DWrite();
43  std::cout << "################################\n";
44  std::cout << std::endl;
45 
46  // Turn on logging
47  Verbosity(10);
48 
49  // Instantiate my operator
50  CtrlPfxOperator cfxop_Y_X(sys,sigctrl);
51 
52  // Have the inner mu-iteration
53  MuIteration cfxop_Y_muX(cfxop_Y_X);
54 
55  // Have the outer nu--iteration
56  NuIteration cfxop_nuY_muX(dynamic_cast<StateSetOperator&>(cfxop_Y_muX));
57 
58  // run
59  std::cout << "################################\n";
60  std::cout << "# running nu-mu nested fixpoint iteration: " << cfxop_nuY_muX.Name() << std::endl;
61  StateSet cfx;
62  cfxop_nuY_muX.Evaluate(cfx);
63  std::cout << "# resulting fixpoint: " << std::endl;
64  cfx.Write();
65  std::cout << "################################\n";
66  std::cout << std::endl;
67 
68  // record result
69  FAUDES_TEST_DUMP("ifac2020 example",cfx);
70 
71  /////////////////////////////////////////////
72  // Demo of implementing SupCon as nu-mu iteration
73  // (also along the line of our IFAC 2020 contribution)
74  /////////////////////////////////////////////
75 
76  // read problem data L and E
77  System plant("./data/syn_eleplant.gen");
78  Generator spec("./data/syn_elespec.gen");
79  EventSet sigall = plant.Alphabet() + spec.Alphabet();
80  sigctrl = plant.ControllableEvents() + (spec.Alphabet()-plant.Alphabet());
81 
82  // closded-loop candidate: mark L cap E
83  Generator sup;
84  Automaton(spec,sup);
85  sup.StateNamesEnabled(false);
86  ParallelLive(plant,sup,sup);
87 
88  // take controllability prefix
89  std::cout << "################################\n";
90  std::cout << "# computing controllability prefix\n";
91  std::cout << "# state count: " << sup.Size() << std::endl;
92  CtrlPfxOperator xcfxop_Y_X(sup,sigctrl);
93  MuIteration xcfxop_Y_muX(xcfxop_Y_X);
94  NuIteration xcfxop_nuY_muX(dynamic_cast<StateSetOperator&>(xcfxop_Y_muX));
95  StateSet xcfx;
96  xcfxop_nuY_muX.Evaluate(xcfx);
97  std::cout << "# state count of fixpoint: " << xcfx.Size() << std::endl;
98 
99  // figure the ranking (run inner mu with outer fixpoint set)
100  std::cout << "################################\n";
101  std::map<Idx,int> rmap;
102  xcfxop_Y_muX.Rank(xcfx,rmap);
103  std::cout << "# state count in ranking: " << rmap.size() << std::endl;
104  auto rit=rmap.begin();
105  for(;rit!=rmap.end();++rit)
106  std::cout << "# state " << rit->first << " rank " << rit->second << std::endl;
107 
108 
109  // derive supremal closed-loop behaviour
110  sup.InjectMarkedStates(xcfx);
111  SupClosed(sup,sup);
112  Trim(sup);
113  Parallel(sup,spec,sup);
114  Parallel(sup,plant,sup);
115  std::cout << "# closed-loop statistics" << std::endl;
116  sup.SWrite();
117 
118  // validate against std SupCon
119  std::cout << "# validate w.r.t. std implementation of SupCon\n";
120  Generator ssup;
121  InvProject(plant,sigall);
122  plant.SetControllable(sigctrl);
123  InvProject(spec,sigall);
124  ssup.StateNamesEnabled(false);
125  SupCon(plant,spec,ssup);
126  StateMin(ssup,ssup);
127  ssup.SWrite();
128  bool eql=LanguageEquality(ssup,sup);
129  if(eql)
130  std::cout << "# closed-loop behaviours match (tast case pass)\n";
131  else
132  std::cout << "# closed-loop behaviours do not match (test case FAIL)\n";
133  std::cout << "################################\n";
134  std::cout << std::endl;
135 
136  // record result
137  FAUDES_TEST_DUMP("elesup",sup);
138  FAUDES_TEST_DUMP("elessup",ssup);
139  FAUDES_TEST_DUMP("validate",eql);
140 
141  // validate
143 }
144 
#define FAUDES_TEST_DIFF()
Definition: cfl_utils.h:515
#define FAUDES_TEST_DUMP(mes, dat)
Definition: cfl_utils.h:505
const std::string & Name(void) const
Definition: cfl_types.cpp:422
void Rank(StateSetVector &rArgs, std::map< Idx, int > &rRMap) const
void Evaluate(StateSetVector &rArgs, StateSet &rRes) const
Definition: syn_ctrlpfx.cpp:43
const TaEventSet< EventAttr > & Alphabet(void) const
EventSet ControllableEvents(void) const
void SetControllable(Idx index)
void DWrite(const Type *pContext=0) const
Definition: cfl_types.cpp:231
void Write(const Type *pContext=0) const
Definition: cfl_types.cpp:145
void SWrite(TokenWriter &rTw) const
Definition: cfl_types.cpp:262
const EventSet & Alphabet(void) const
void InjectMarkedStates(const StateSet &rNewMarkedStates)
bool StateNamesEnabled(void) const
Idx Size(void) const
Idx Size(void) const
Definition: cfl_baseset.h:1899
void StateMin(const Generator &rGen, Generator &rResGen)
void Trim(vGenerator &rGen)
Idx Automaton(Generator &rGen, const EventSet &rAlphabet)
bool LanguageEquality(const Generator &rGen1, const Generator &rGen2)
void Parallel(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void InvProject(Generator &rGen, const EventSet &rProjectAlphabet)
void SupCon(const Generator &rPlantGen, const EventSet &rCAlph, const Generator &rSpecGen, Generator &rResGen)
Definition: syn_supcon.cpp:757
void ParallelLive(const GeneratorVector &rGenVec, Generator &rResGen)
bool SupClosed(const Generator &rK, Generator &rResult)
void Verbosity(int v)
Definition: cfl_utils.cpp:504
int main()

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