omg_4_rabinctrl.cpp
Go to the documentation of this file.
1 /** @file omg_4_rabinctrl.cpp
2 
3 Supervision of omega-languages w.r.t. Rabin acceptance
4 
5 @ingroup Tutorials
6 
7 @include omg_4_rabinctrl.cpp
8 
9 */
10 
11 #include "libfaudes.h"
12 
13 
14 // we make the faudes namespace available to our program
15 using namespace faudes;
16 
17 
18 int main() {
19 
20  // Early stage of development ... see whether we can recover
21  // the test cases from Buechi supervisory control.
22 
23  /////////////////////////////////////////////
24  // Control w.r.t Rabin specifications
25  //
26  // The A-B-Machine is a machine that can run process A (event a) or process B (event b).
27  // Per operation, the machine may succeed (event c) of fail (event d). However, it is
28  // guaranteed to eventually suceed when running the same process over and over again.
29  // We have three variations:
30  //
31  // 1: the std case
32  // 2: process B exhausts the machine: it will succeed in process B once and then
33  // fail on further processes B until process A was run.
34  // 3: process B breaks the machine: it will succeed in process B once and
35  // then fail in any further processes
36  //
37  // We synthesise controllers for 3 variant specifications
38  //
39  // 1. Alternate in successfully processing A and B
40  // 2. Keep on eventually succeeding in some process
41  // 3. Run optionally process A, eventually turn to B until success, repeat
42  //
43  /////////////////////////////////////////////
44 
45 
46  // Read A-B-Machines and specifications
47  System machineab1("data/omg_machineab1_alt.gen");
48  System machineab2("data/omg_machineab2.gen");
49  System machineab3("data/omg_machineab3.gen");
50  Generator specab1("data/omg_specab1.gen");
51  Generator specab2("data/omg_specab2.gen");
52  Generator specab3("data/omg_specab3.gen");
53 
54  // Additional lower bound specification
55  //Generator lbspecab1("data/omg_lspecab1.gen");
56  //Generator lbspecab2("data/omg_lspecab2.gen");
57  Generator lspecab3("data/omg_lspecab3.gen");
58 
59  // select test case plant=1 spec=3
60  const System& plant=machineab1;
61  plant.Write("tmp_omg_4_plant1.gen");
62  const Generator& spec=specab3;
63  spec.Write("tmp_omg_4_spec3_buechi.gen");
64  const Generator& lspec=lspecab3;
65  lspec.Write("tmp_omg_4_lspec3.gen");
66  EventSet sigall = plant.Alphabet() + spec.Alphabet();
67  EventSet sigctrl = plant.ControllableEvents();
68 
69  // preprocess lazy spec
70  RabinAutomaton rspec=spec;
71  rspec.RabinAcceptance(rspec.MarkedStates());
72  rspec.ClearMarkedStates();
73  InvProject(rspec,sigall);
74  Automaton(rspec);
75  rspec.Write("tmp_omg_4_spec3_rabin.gen");
76 
77  // construct rabin-buechi automaton as base candidate
78  RabinAutomaton cand;
79  RabinBuechiAutomaton(rspec,plant,cand); // dox only
80  cand.Write("tmp_omg_4_rbaut13.gen"); // dox only
81  RabinBuechiProduct(rspec,plant,cand);
82  cand.Write("tmp_omg_4_cand13.gen");
83  std::cout << "====== first candidate" << std::endl;
84  cand.Write();
85 
86  // record test case
87  FAUDES_TEST_DUMP("cand13",cand);
88 
89  // turn on mu-nu protocol
90  Verbosity(10);
91 
92  // controllability prefix
93  StateSet ctrlpfx;
94  RabinCtrlPfx(cand,sigctrl,ctrlpfx);
95  std::cout << "====== controllability prefix" << std::endl;
96  cand.WriteStateSet(ctrlpfx);
97  std::cout << std::endl;
98 
99  // record test case
100  FAUDES_TEST_DUMP("ctrlpfx13",ctrlpfx);
101 
102  // dox only: have a visual by a muck rabin R-Set
103  RabinAutomaton cpxaut=cand;
104  RabinPair rpair;
105  cpxaut.RabinAcceptance().Append(rpair);
106  cpxaut.RabinAcceptance().Append(rpair);
107  rpair.RSet().InsertSet(ctrlpfx);
108  cpxaut.RabinAcceptance().Append(rpair);
109  cpxaut.Write("tmp_omg_4_ctrlpfx13.gen");
110 
111  // supcon API wrapper
112  RabinAutomaton supcon;
113  SupRabinCon(plant,rspec,supcon);
114  supcon.Write("tmp_omg_4_supcon13.gen");
115 
116  // record test case
117  FAUDES_TEST_DUMP("supcon13",supcon);
118 
119  // minimze supcon to compare with SupBuechiCon
120  Generator test=supcon;
121  test.StateNamesEnabled(false);
122  test.InjectMarkedStates(cand.RabinAcceptance().Begin()->RSet());
123  StateMin(test,test);
124  test.Write("tmp_omg_4_supmin13.gen");
125 
126  // controller
127  TaIndexSet<EventSet> controller;
128  RabinCtrlPfx(cand,sigctrl,controller);
129  std::cout << "====== controller" << std::endl;
130  cand.WriteStateSet(controller);
131  std::cout << std::endl;
132 
133  // record test case
134  FAUDES_TEST_DUMP("ctrl13",controller);
135 
136  // greedy controller API wrapper
137  Generator ctrl;
138  ctrl.StateNamesEnabled(false);
139  RabinCtrl(plant,rspec,ctrl);
140  StateMin(ctrl,ctrl);
141  ctrl.Write("tmp_omg_4_ctrl13.gen");
142 
143  // record test case
144  FAUDES_TEST_DUMP("loop13",ctrl);
145 
146  // greedy controller with lower bound
147  ctrl.StateNamesEnabled(false);
148  RabinCtrl(plant,sigctrl,lspec,rspec,ctrl);
149  StateMin(ctrl,ctrl);
150  ctrl.Write("tmp_omg_4_lctrl13.gen");
151 
152  // record test case
153  FAUDES_TEST_DUMP("lloop13",ctrl);
154 
155  // validate
157 
158  return 0;
159 }
160 
#define FAUDES_TEST_DIFF()
Definition: cfl_utils.h:515
#define FAUDES_TEST_DUMP(mes, dat)
Definition: cfl_utils.h:505
StateSet & RSet(void)
Definition: omg_rabinacc.h:68
const TaEventSet< EventAttr > & Alphabet(void) const
EventSet ControllableEvents(void) const
void RabinAcceptance(const faudes::RabinAcceptance &rRabAcc)
Definition: omg_rabinaut.h:326
void Write(const Type *pContext=0) const
Definition: cfl_types.cpp:145
const StateSet & MarkedStates(void) const
const EventSet & Alphabet(void) const
void WriteStateSet(const StateSet &rStateSet) const
void ClearMarkedStates(void)
void InjectMarkedStates(const StateSet &rNewMarkedStates)
bool StateNamesEnabled(void) const
virtual void InsertSet(const TBaseSet &rOtherSet)
Definition: cfl_baseset.h:2194
void StateMin(const Generator &rGen, Generator &rResGen)
Idx Automaton(Generator &rGen, const EventSet &rAlphabet)
void InvProject(Generator &rGen, const EventSet &rProjectAlphabet)
void RabinBuechiAutomaton(const RabinAutomaton &rRAut, const Generator &rBAut, RabinAutomaton &rRes)
void SupRabinCon(const Generator &rBPlant, const EventSet &rCAlph, const RabinAutomaton &rRSpec, RabinAutomaton &rRes)
void RabinBuechiProduct(const RabinAutomaton &rRAut, const Generator &rBAut, RabinAutomaton &rRes)
void RabinCtrlPfx(const RabinAutomaton &rRAut, const EventSet &rSigmaCtrl, StateSet &rCtrlPfx)
void RabinCtrl(const Generator &rBPlant, const EventSet &rCAlph, const RabinAutomaton &rRSpec, Generator &rRes)
void Verbosity(int v)
Definition: cfl_utils.cpp:504
int main()

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