FSM Library - C++ version
Fsm.h
1 /*
2  * Copyright. GaĆ«l Dottel, Christoph Hilken, and Jan Peleska 2016 - 2021
3  *
4  * Licensed under the EUPL V.1.1
5  */
6 #ifndef FSM_FSM_FSM_H_
7 #define FSM_FSM_FSM_H_
8 
9 #include <fstream>
10 #include <iostream>
11 #include <memory>
12 #include <set>
13 #include <sstream>
14 #include <string>
15 #include <unordered_set>
16 #include <vector>
17 
18 class Dfsm;
19 class FsmNode;
20 class Tree;
21 class OutputTree;
22 class InputTrace;
24 class OFSMTable;
25 class IOListContainer;
26 class TestSuite;
27 
28 enum Minimal
29 {
30  True, False, Maybe
31 };
32 
33 class Fsm
34 {
35 protected:
36 
40  Fsm(const std::shared_ptr<FsmPresentationLayer> presentationLayer);
41 
42 
43 
44 
45  std::string name;
46  std::vector<std::shared_ptr<FsmNode>> nodes;
47  std::shared_ptr<FsmNode> currentParsedNode;
48  int maxInput;
49  int maxOutput;
50  int maxState;
51  int initStateIdx;
52  std::vector<std::shared_ptr<OFSMTable>> ofsmTableLst;
53  std::shared_ptr<Tree> characterisationSet;
54  std::vector<std::shared_ptr<Tree>> stateIdentificationSets;
55  std::shared_ptr<FsmPresentationLayer> presentationLayer;
56  Minimal minimal;
57  std::shared_ptr<FsmNode> newNode(const int id, const std::shared_ptr<std::pair<std::shared_ptr<FsmNode>, std::shared_ptr<FsmNode>>> p);
58  bool contains(const std::vector<std::shared_ptr<std::pair<std::shared_ptr<FsmNode>, std::shared_ptr<FsmNode>>>>& lst, const std::shared_ptr<std::pair<std::shared_ptr<FsmNode>, std::shared_ptr<FsmNode>>> p);
59  bool contains(const std::vector<std::shared_ptr<FsmNode>>& lst, const std::shared_ptr<FsmNode> n);
60  std::shared_ptr<FsmNode> findp(const std::vector<std::shared_ptr<FsmNode>>& lst, const std::shared_ptr<std::pair<std::shared_ptr<FsmNode>, std::shared_ptr<FsmNode>>> p);
61  void parseLine(const std::string & line);
62  void readFsm(const std::string & fname);
63 
64  void parseLineInitial (const std::string & line);
65  void readFsmInitial (const std::string & fname);
66 
67 
68  std::string labelString(std::unordered_set<std::shared_ptr<FsmNode>>& lbl) const;
69 public:
70 
74  Fsm(const std::string & fname,
75  const std::string & fsmName,
76  const int maxNodes,
77  const int maxInput,
78  const int maxOutput,
79  const std::shared_ptr<FsmPresentationLayer> presentationLayer);
80 
106  Fsm(const std::string& fname,
107  const std::shared_ptr<FsmPresentationLayer> presentationLayer,
108  const std::string& fsmName);
109 
110 
111 
112 
113 
114 
125  Fsm(const std::string & fsmName,
126  const int maxInput,
127  const int maxOutput,
128  const std::vector<std::shared_ptr<FsmNode>> lst,
129  const std::shared_ptr<FsmPresentationLayer> presentationLayer);
130 
131 
132 
133 
146  void dumpFsm(std::ofstream & outputFile) const;
147  std::shared_ptr<FsmNode> getInitialState() const;
148 
153  std::string getName() const;
154  virtual int getMaxNodes() const;//TODO NOT PRESENT IN JAVA
155  int getMaxInput() const;//TODO NOT PRESENT IN JAVA
156  int getMaxOutput() const;//TODO NOT PRESENT IN JAVA
157  std::vector<std::shared_ptr<FsmNode>> getNodes() const;//TODO NOT PRESENT IN JAVA
158  std::shared_ptr<FsmPresentationLayer> getPresentationLayer() const;//TODO NOT PRESENT IN JAVA
159  int getInitStateIdx() const;//TODO NOT PRESENT IN JAVA
160  void resetColor();
161  void toDot(const std::string & fname);
162 
168  Fsm intersect(const Fsm & f);
169  std::shared_ptr<Tree> getStateCover();
170  std::shared_ptr<Tree> getTransitionCover();
171  OutputTree apply(const InputTrace & itrc);
172  Fsm transformToObservableFSM() const;
173 
178  bool isObservable() const;
179  Minimal isMinimal() const;
180 
187 
194  Fsm minimise();
195  bool isCharSet(const std::shared_ptr<Tree> w) const;
196  void minimiseCharSet(const std::shared_ptr<Tree> w);
197 
211 
220  void appendStateIdentificationSets(const std::shared_ptr<Tree> Wp2) const;
221 
233  IOListContainer wpMethod(const int m);
234  TestSuite createTestSuite(const IOListContainer & testCases);
235  bool isCompletelyDefined() const;
236 
241  bool isDeterministic() const;
242  void setPresentationLayer(const std::shared_ptr<FsmPresentationLayer> ppresentationLayer);//TODO NOT PRESENT IN JAVA
243  friend std::ostream & operator<<(std::ostream & out, const Fsm & fsm);
244 };
245 #endif //FSM_FSM_FSM_H_
void dumpFsm(std::ofstream &outputFile) const
Definition: Fsm.cpp:268
void calcStateIdentificationSets()
Definition: Fsm.cpp:720
Definition: Fsm.h:33
bool isObservable() const
Definition: Fsm.cpp:570
std::string getName() const
Definition: Fsm.cpp:290
Definition: OutputTree.h:15
IOListContainer wpMethod(const int m)
Definition: Fsm.cpp:837
Definition: IOListContainer.h:15
Fsm intersect(const Fsm &f)
Definition: Fsm.cpp:340
Fsm minimiseObservableFSM()
Definition: Fsm.cpp:587
Definition: Tree.h:19
IOListContainer getCaracterisationSet()
Definition: Fsm.cpp:665
Definition: OFSMTable.h:37
Definition: InputTrace.h:15
bool isDeterministic() const
Definition: Fsm.cpp:932
Fsm minimise()
Definition: Fsm.cpp:614
Definition: FsmPresentationLayer.h:16
Definition: FsmNode.h:27
Definition: TestSuite.h:15
Fsm(const std::shared_ptr< FsmPresentationLayer > presentationLayer)
Definition: Fsm.cpp:222
Definition: Dfsm.h:24