hyb_experiment.h
Go to the documentation of this file.
1 /** @file hyb_experiment.h Exhaustive experments on linear hybris automata */
2 
3 
4 /*
5  Hybrid systems plug-in for FAU Discrete Event Systems Library
6 
7  Copyright (C) 2017 Thomas Moor, Stefan Goetz
8 
9 */
10 
11 #ifndef HYP_EXPERIMENT_H
12 #define HYP_EXPERIMENT_H
13 
14 #include "corefaudes.h"
15 #include "hyb_reachability.h"
16 
17 namespace faudes {
18 
19 // forward declaration of dynamics operator
20 class CompatibleStates;
21 
22 
23 /**
24  * Finite fragment of a computation tree.
25  *
26  * An Experiment represents a finite fragment of a computation tree of. Formaly, an Experiment
27  * avoids an explicit reference to the
28  * underlying state set of the transition system; i.e., each node represents the finite sequence of
29  * events generated when traversing from the root the respective node.
30  * Experiments are used to construct deterministic finite state abstractions.
31  *
32  * Although an explicit reference to the underlying state set is avoided, implictly
33  * each node is associated with the set of state in which the transition could
34  * possibly reside after execution of the respective finite string. These sets of
35  * CompatibleStates can be computed by an iterative forward reachability analysis, where
36  * the choice of available computational procedures depends of the
37  * class of transition systems under consideration.
38  *
39  *
40  *
41  * @ingroup HybridPlugin
42  *
43  */
45 
46 
47  public:
48  // basic maintenance
49  Experiment(const EventSet& alph);
50  ~Experiment(void);
51  void InitialStates(CompatibleStates* istates);
52  void Clear(void);
53  Idx Size(void) const;
54  const EventSet& Alphabet(void) const;
55  int Cost(void) const { return mCost;};
56 
57  // convenience methods
58  void SWrite(void) const;
59  void DWrite(void) const;
60  void DWrite(Idx nid) const;
61 
62  /**
63  * Navigate tree
64  * This interface is intended for external use.
65  * All methods throw an exception when accessing a non-existent node.
66  */
67  Idx Root(void) const;
68  EventSet EnabledEvents(Idx nid) const;
69  Idx SuccessorNode(Idx nid, Idx ev) const; // 0 for has no such succesor
70  bool IsLeave(Idx nid) const; // false for nonex
71  bool IsLock(Idx nid) const;
72  Idx Find(const std::deque< Idx >& seq) const;
73  std::deque< Idx > Sequence(Idx nid) const;
74  const IndexSet& Leaves() const;
75 
76  /**
77  * Access compatible states
78  * (note: implememtation dependant data type)
79  */
80  const CompatibleStates* States(Idx nid) const;
81 
82  // forward reachability analysis
83  void RefineAt(Idx idx);
84  Idx RefineSequence(const std::deque< Idx >& seq);
85  void RefineUniformly(unsigned int depth);
86 
87 
88  protected:
89 
90  /** hide Node from intended interface */
91  class Node;
92 
93  /** core experiment data: have root and track all nodes by index */
95  std::map< Idx , Node* > mNodeMap;
96  typedef std::map<Idx, Node*>::const_iterator Iterator;
98  int mCost;
99 
100  /** reference to alphabet */
102 
103  /** Node record to form a tree */
104  class Node {
105  public:
106  Node(void) : mId(0), pParent(0), mRecEvent(0), mDepth(0), mpStates(0), mLock(false) {};
107  /* unique id */
109  /* pointer to parent, NULL for root */
111  /* event by which we got here */
113  /* distance from root */
115  /* children by event */
116  std::map<Idx, Node*> mChildren;
117  /* payload: set of compatible states */
119  bool mLock;
120  /* convenience typedef */
121  typedef std::map<Idx, Node*>::const_iterator Iterator;
122  };
123 
124 
125  /** Node related methods, hosted by Experiment for convenience */
126 
127  /** tree member access */
128  Idx& Index(Node* node)
129  { return node->mId; };
130  const Idx& Index(const Node* node) const
131  { return node->mId;};
132  Node*& Parent(Node* node)
133  { return node->pParent; };
134  Node* const & Parent(const Node* node) const
135  { return node->pParent; };
136  Idx& RecEvent(Node* node)
137  { return node->mRecEvent; };
138  const Idx& RecEvent(const Node* node) const
139  { return node->mRecEvent;};
140  Idx& Depth(Node* node)
141  { return node->mDepth; };
142  const Idx& Depth(const Node* node) const
143  { return node->mDepth;};
144  std::map< Idx, Node*>& Children(Node* node)
145  { return node->mChildren; };
146  const std::map< Idx, Node*>& Children(const Node* node) const
147  { return node->mChildren; };
148  bool IsLeave(const Node* node) const
149  { return Children(node).empty(); }
150  Node* Child(Node* node, Idx ev) {
151  Node::Iterator nit = Children(node).find(ev);
152  if(nit==Children(node).end()) return 0;
153  return nit->second;
154  };
155 
156  /** grow tree */
157  Node* Insert(Node* parent, Idx ev) {
158  if(IsLeave(parent)) mLeaves.Erase(Index(parent));
159  Node* node= new Node();
160  node->mId = mNodeMap.size()+1; // should use max
161  mNodeMap[node->mId]=node;
162  Parent(node)=parent;
163  RecEvent(node) = ev;
164  Depth(node)=Depth(parent)+1;
165  Children(parent)[ev]=node;
166  mLeaves.Insert(Index(node));
167  return node;
168  }
169 
170  /** payload access */
172  { return node->mpStates; };
173  CompatibleStates* const & States(const Node* node) const
174  { return node->mpStates; };
175  bool& IsLock(Node* node)
176  { return node->mLock; };
177  const bool& IsLock(const Node* node) const
178  { return node->mLock; };
179 
180  /** get node ptr by index (for API wrappers)*/
181  Node* NodePtr(Idx idx) const {
182  Node::Iterator mit = mNodeMap.find(idx);
183  if(mit==mNodeMap.end()) return 0;
184  return mit->second;
185  };
186 
187 
188 };// class
189 
190 
191 /**
192  * Abstract dynamics operator, i.e., some set of states,
193  * that knows where it eveolves when it next triggers an event.
194  * Technically, CompatibleStates provide a minimal interface that
195  * allows the Experiment to refine itself.
196  */
197 
199  public:
201  virtual ~CompatibleStates(void) {};
202  virtual void InitialiseFull(void) = 0;
203  virtual void InitialiseConstraint(void) = 0;
204  virtual void ExecuteTransitions(void) = 0;
205  virtual CompatibleStates* TakeByEvent(Idx ev) = 0;
206  virtual void DWrite(void) const = 0;
207  virtual const int Cost(void) {return 0;};
208 };
209 
210 // DES dynamics operator
212 public:
213  DesCompatibleStates(const Generator& gen);
214  virtual ~DesCompatibleStates(void);
215  virtual void InitialiseFull();
216  virtual void InitialiseConstraint();
217  virtual void ExecuteTransitions(void);
218  virtual DesCompatibleStates* TakeByEvent(Idx ev);
219  virtual void DWrite(void) const;
220 protected:
221  const Generator& rGen;
223  std::map<Idx, StateSet*> mReachSets;
224 };
225 
226 // LHA dynamics operator
228 public:
230  virtual ~LhaCompatibleStates(void);
231  virtual void InitialiseFull();
232  virtual void InitialiseConstraint();
233  virtual void ExecuteTransitions(void);
234  virtual LhaCompatibleStates* TakeByEvent(Idx ev);
235  virtual void DWrite(void) const;
236  virtual const int Cost(void) {return mCnt;};
237  const HybridStateSet* States(void) const { return mpStates; };
238 protected:
241  std::map<Idx, HybridStateSet*> mHybridReachSets;
242  int mCnt;
243 };
244 
245 
246 } // namespace
247 #endif // EXPERIMENT_H
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:81
Abstract dynamics operator, i.e., some set of states, that knows where it eveolves when it next trigg...
virtual void InitialiseConstraint(void)=0
virtual const int Cost(void)
virtual void InitialiseFull(void)=0
virtual ~CompatibleStates(void)
virtual void DWrite(void) const =0
virtual void ExecuteTransitions(void)=0
virtual CompatibleStates * TakeByEvent(Idx ev)=0
std::map< Idx, StateSet * > mReachSets
Node record to form a tree.
CompatibleStates * mpStates
std::map< Idx, Node * > mChildren
std::map< Idx, Node * >::const_iterator Iterator
Finite fragment of a computation tree.
std::map< Idx, Node * > & Children(Node *node)
bool & IsLock(Node *node)
Idx & RecEvent(Node *node)
Idx & Index(Node *node)
Node related methods, hosted by Experiment for convenience.
CompatibleStates *& States(Node *node)
payload access
CompatibleStates *const & States(const Node *node) const
Node * Child(Node *node, Idx ev)
std::map< Idx, Node * >::const_iterator Iterator
Node * Insert(Node *parent, Idx ev)
grow tree
std::map< Idx, Node * > mNodeMap
bool IsLeave(const Node *node) const
const bool & IsLock(const Node *node) const
Node * mpRoot
core experiment data: have root and track all nodes by index
Node *const & Parent(const Node *node) const
const faudes::EventSet & rAlphabet
reference to alphabet
const Idx & RecEvent(const Node *node) const
Node *& Parent(Node *node)
const Idx & Depth(const Node *node) const
int Cost(void) const
const std::map< Idx, Node * > & Children(const Node *node) const
Idx & Depth(Node *node)
const Idx & Index(const Node *node) const
Node * NodePtr(Idx idx) const
get node ptr by index (for API wrappers)
Set of states in an hybrid automata.
Set of indices.
Definition: cfl_indexset.h:78
Idx Insert(void)
Insert new index to set.
const HybridStateSet * States(void) const
std::map< Idx, HybridStateSet * > mHybridReachSets
const LinearHybridAutomaton & rLha
virtual const int Cost(void)
Set of indices with symbolic names.
Definition: cfl_nameset.h:69
Generator with linear hybrid automata extensions.
Base class of all FAUDES generators.
Includes all libFAUDES headers, no plugins.
TaNameSet< AttributeCFlags > Alphabet
Convenience typedef for event sets with controllability attributes.
virtual bool Erase(const T &rElem)
Erase element by reference.
Definition: cfl_baseset.h:2019
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
TNode< Idx, Idx > Node
A node represents the edges related to one individual vertex.
An iterator over the set of edges related to one vertex is interpreted as a transition.

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen