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
17namespace faudes {
18
19// forward declaration of dynamics operator
20class 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; };
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;
206 virtual void DWrite(void) const = 0;
207 virtual const int Cost(void) {return 0;};
208};
209
210// DES dynamics operator
212public:
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;
220protected:
223 std::map<Idx, StateSet*> mReachSets;
224};
225
226// LHA dynamics operator
228public:
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; };
238protected:
241 std::map<Idx, HybridStateSet*> mHybridReachSets;
242 int mCnt;
243};
244
245
246} // namespace
247#endif // EXPERIMENT_H
#define FAUDES_API
virtual CompatibleStates * TakeByEvent(Idx ev)=0
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
std::map< Idx, StateSet * > mReachSets
CompatibleStates * mpStates
std::map< Idx, Node * > mChildren
std::map< Idx, Node * >::const_iterator Iterator
Node * NodePtr(Idx idx) const
const Idx & Depth(const Node *node) const
Node * Insert(Node *parent, Idx ev)
Node * Child(Node *node, Idx ev)
std::map< Idx, Node * > & Children(Node *node)
CompatibleStates *const & States(const Node *node) const
const Idx & RecEvent(const Node *node) const
Idx & Index(Node *node)
Node *const & Parent(const Node *node) const
CompatibleStates *& States(Node *node)
std::map< Idx, Node * > mNodeMap
Node *& Parent(Node *node)
bool IsLeave(const Node *node) const
bool & IsLock(Node *node)
const faudes::EventSet & rAlphabet
Idx & RecEvent(Node *node)
std::map< Idx, Node * >::const_iterator Iterator
const bool & IsLock(const Node *node) const
int Cost(void) const
const Idx & Index(const Node *node) const
const std::map< Idx, Node * > & Children(const Node *node) const
Idx & Depth(Node *node)
std::map< Idx, HybridStateSet * > mHybridReachSets
const LinearHybridAutomaton & rLha
virtual const int Cost(void)
const HybridStateSet * States(void) const
virtual bool Erase(const T &rElem)
uint32_t Idx

libFAUDES 2.34d --- 2026.03.11 --- c++ api documentaion by doxygen