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
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  // derive supremal closed-loop behaviour
100  sup.InjectMarkedStates(xcfx);
101  SupClosed(sup,sup);
102  Trim(sup);
103  Parallel(sup,spec,sup);
104  Parallel(sup,plant,sup);
105  std::cout << "# closed-loop statistics" << std::endl;
106  sup.SWrite();
107 
108  // validate against std SupCon
109  std::cout << "# validate w.r.t. std implementation of SupCon\n";
110  Generator ssup;
111  InvProject(plant,sigall);
112  plant.SetControllable(sigctrl);
113  InvProject(spec,sigall);
114  ssup.StateNamesEnabled(false);
115  SupCon(plant,spec,ssup);
116  StateMin(ssup,ssup);
117  ssup.SWrite();
118  bool eql=LanguageEquality(ssup,sup);
119  if(eql)
120  std::cout << "# closed-loop behaviours match (tast case pass)\n";
121  else
122  std::cout << "# closed-loop behaviours do not match (test case FAIL)\n";
123  std::cout << "################################\n";
124  std::cout << std::endl;
125 
126  // record result
127  FAUDES_TEST_DUMP("elesup",sup);
128  FAUDES_TEST_DUMP("elessup",ssup);
129  FAUDES_TEST_DUMP("validate",eql);
130 
131  // validate
133 }
134 
#define FAUDES_TEST_DIFF()
Definition: cfl_utils.h:504
#define FAUDES_TEST_DUMP(mes, dat)
Definition: cfl_utils.h:494
const std::string & Name(void) const
Definition: cfl_types.cpp:422
static void LogMuNu(bool on)
void Evaluate(StateSetVector &rArgs, StateSet &rRes) const
Definition: syn_ctrlpfx.cpp:46
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:1782
void StateMin(const Generator &rGen, Generator &rResGen)
void Trim(vGenerator &rGen)
void 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)
int main()

libFAUDES 2.33h --- 2025.06.18 --- c++ api documentaion by doxygen