pd_controller_test.cpp
Go to the documentation of this file.
1 /** @file pd_controller_test.cpp
2 
3  Tests the result of the synthesis algorithm
4 
5 
6  @ingroup Tutorials
7 
8  @include pd_tutorial.cpp
9 
10  */
11 
12 #include "libfaudes.h"
13 
14 // make the faudes namespace available to our program
15 using namespace faudes;
16 
17 /** Run the tutorial */
18 int main() {
19 
20  //*******************************
21  //create the specification, a pushdown generator
22  //*******************************
24 
25  //insert states
26  g.InsState("s1");
27  g.InsState("s2");
28  g.InsState("s3");
29 
30  //insert stack symbols
31  Idx lambda = g.InsStackSymbol(FAUDES_PD_LAMBDA); //always use FAUDES_PD_LAMBDA for empty stack symbol!
32  Idx dot = g.InsStackSymbol("dot");
33  Idx square = g.SetStackBottom("square");
34 
35  //insert events
36  g.InsControllableEvent("a");
37  g.InsEvent("b");
38  g.InsUncontrollableEvent(FAUDES_PD_LAMBDA); //always use FAUDES_PD_LAMBDA for empty event!
39 
40  //build stack symbol vectors to be inserted as pop and push attributes of transitions
41  std::vector<Idx> vLambda;
42  vLambda.push_back(lambda);
43  std::vector<Idx> vSquare;
44  vSquare.push_back(square);
45  std::vector<Idx> vDot;
46  vDot.push_back(dot);
47  std::vector<Idx> vDotSquare;
48  vDotSquare.push_back(dot);
49  vDotSquare.push_back(square);
50 
51  //insert transitions
52  g.SetTransition("s1", "a", "s2", vSquare, vDotSquare);
53  g.SetTransition("s2", "b", "s3", vDot, vDot);
54 
55  //set state attributes
56  g.SetInitState("s1");
57  g.SetMarkedState("s1");
58  g.SetMarkedState("s2");
59  g.SetMarkedState("s3");
60 
61  // Record test case
62  FAUDES_TEST_DUMP("specification", g)
63 
64  //*******************************
65  //create the plant, a DFA
66  //*******************************
67  System s;
68 
69  s.InsState("s1");
70  s.InsState("s2");
71  s.InsState("s3");
72 
73  s.InsControllableEvent("a");
74  s.InsEvent("b");
75 
76  s.SetTransition("s1", "a", "s1");
77  s.SetTransition("s1", "a", "s2");
78  s.SetTransition("s2", "b", "s3");
79 
80  s.SetInitState("s1");
81  s.SetMarkedState("s3");
82 
83  // Record test case
84  FAUDES_TEST_DUMP("plant", s)
85 
86  //*******************************
87  //print plant and specification
88  //*******************************
89  g.Write();
90  s.Write();
91 
92  //*******************************
93  //call synthesis algorithm
94  //*******************************
96  PushdownConstructController(g, s, rPd);
97 
98  //*******************************
99  //print result
100  //*******************************
101  std::cout << "***************** RESULT *****************" << std::endl;
102  rPd.Write();
103 
104  // Record test case
105  FAUDES_TEST_DUMP("controller", rPd)
106 
107  //*******************************
108  //print words that are possible in the closed loop (only "ab" expected)
109  //*******************************
110  LangK test(rPd);
111  test.FindLangK(50);
112  test.PrintWords();
113 
114  // Validate result
116 
117  // done
118  return 0;
119 }
120 

libFAUDES 2.28c --- 2016.09.30 --- c++ api documentaion by doxygen