pd_tutorial.cpp
Go to the documentation of this file.
1 /** @file pd_tutorial.cpp
2 
3  Tutorial, example plugin. This tutorial demonstrates
4  how to use pushdown generators.
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  //print dot-file
62  g.DotWrite("tmp_pd_tutorial_specification.dot");
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", "s2");
77  s.SetTransition("s2", "a", "s2");
78  s.SetTransition("s2", "b", "s3");
79 
80  s.SetInitState("s1");
81  s.SetMarkedState("s3");
82 
83  //print dot-file
84  s.DotWrite("tmp_pd_tutorial_plant.dot");
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  //print controller
99  rPd.DotWrite("tmp_pd_tutorial_controller.png");
100 
101  //*******************************
102  //print result
103  //*******************************
104  std::cout << "***************** RESULT *****************" << std::endl;
105  rPd.Write();
106 
107 
108  //*******************************
109  //print words that are possible in the closed loop (only "ab" expected)
110  //*******************************
111  LangK test(rPd);
112  test.FindLangK(50);
113  test.PrintWords();
114 
115 
116  //*******************************
117  //parse former constructed generators from dot-file
118  //*******************************
119  PushdownGenerator g2("data/graph/pd_tut_spec.dot");
120  System s2 = SystemFromDot("data/graph/pd_tut_plant.dot");
121 
122  //call synthesis algorithm
123  PushdownGenerator rPd2;
124  PushdownConstructController(g2, s2, rPd2);
125 
126  //print controller graph
127  rPd2.DotWrite("tmp__pd_tutorial_controllerFromDot.png");
128 
129  // done
130  return 0;
131 }
132 

libFAUDES 2.26g --- 2015.08.17 --- c++ api documentaion by doxygen