hyb_abstraction.cpp
Go to the documentation of this file.
1 /** @file hyb_abstraction.cpp Abstractions based on experments on linear hybrid automata */
2 
3 /*
4  Hybrid systems plug-in for FAU Discrete Event Systems Library
5 
6  Copyright (C) 2017 Thomas Moor, Stefan Goetz
7 
8 */
9 
10 #include "hyb_abstraction.h"
11 
12 using namespace faudes;
13 
14 
15 
16 // construct/destruct
18  mpExperiment(0), mExpChanged(true) {
19 }
21  if(mpExperiment) delete mpExperiment;
22 }
23 
24 
25 // set/get experiment (we own)
27  if(mpExperiment) delete mpExperiment;
28  mpExperiment=exp;
29  mExpChanged=true;
30  mTivMode=false;
31  mTvMode=false;
32 }
34  if(!mpExperiment)
35  throw Exception("LbdAbstraction::Experiment()", "experiment not set yet", 90);
36  return *mpExperiment;
37 }
38 
39 
40 // refine interface
42  if(!mpExperiment)
43  throw Exception("LbdAbstraction::RefineAt(..)", "experiment not set yet", 90);
44  mpExperiment->RefineAt(nid);
45  mExpChanged=true;
46 }
47 void LbdAbstraction::RefineUniformly(unsigned int depth) {
48  if(!mpExperiment)
49  throw Exception("LbdAbstraction::RefineAt(..)", "experiment not set yet", 90);
51  mExpChanged=true;
52 }
53 
54 // access abstractions
56  // build from scartch
57  if(!mTivMode) { doTivAbstractionMG(); mTivMode=true; mTvMode=false; mExpChanged=false;}
58  // optionl inclemental methods .. put here
60  // done
61  return mAbstraction;
62 }
63 
64 // access abstractions
66  // build from scartch
67  if(!mTvMode) { doTvAbstraction(); mTvMode=true; mTivMode=false; mExpChanged=false;}
68  // optionl inclemental methods .. put here
69  if(mExpChanged) { doTvAbstraction(); mExpChanged=false;}
70  // done
71  return mAbstraction;
72 }
73 
74 
75 // workers: copy tree
77  // prepare
79  mLeaves.Clear();
81  // loop todo
82  std::stack<Idx> todo;
83  todo.push(mpExperiment->Root());
85  while(!todo.empty()) {
86  Idx nid=todo.top();
87  todo.pop();
89  if(mpExperiment->IsLeave(nid)) mLeaves.Insert(nid);
90  EventSet events=mpExperiment->EnabledEvents(nid);
91  EventSet::Iterator eit=events.Begin();
92  for(;eit!=events.End();++eit) {
93  Idx x2=mpExperiment->SuccessorNode(nid,*eit);
95  mAbstraction.SetTransition(nid,*eit,x2);
96  todo.push(x2);
97  }
98  }
99 }
100 
101 // workers: time variant
104  /*
105  // without dumpstate
106  StateSet::Iterator sit=mLeaves.Begin();
107  StateSet::Iterator sit_end=mLeaves.End();
108  for(;sit!=sit_end;++sit) {
109  EventSet::Iterator eit=mpExperiment->Alphabet().Begin();
110  EventSet::Iterator eit_end=mpExperiment->Alphabet().End();
111  if(mpExperiment->IsLock(*sit)) continue;
112  for(;eit!=eit_end;++eit)
113  mAbstraction.SetTransition(*sit,*eit,*sit);
114  }
115  */
116  // with dumpstate
118  EventSet::Iterator eit=mpExperiment->Alphabet().Begin();
119  EventSet::Iterator eit_end=mpExperiment->Alphabet().End();
120  for(;eit!=eit_end;++eit)
121  mAbstraction.SetTransition(qd,*eit,qd);
122  StateSet::Iterator sit=mLeaves.Begin();
123  StateSet::Iterator sit_end=mLeaves.End();
124  for(;sit!=sit_end;++sit) {
125  EventSet::Iterator eit=mpExperiment->Alphabet().Begin();
126  EventSet::Iterator eit_end=mpExperiment->Alphabet().End();
127  if(mpExperiment->IsLock(*sit)) continue;
128  for(;eit!=eit_end;++eit)
129  mAbstraction.SetTransition(*sit,*eit,qd);
130  }
131 
132 
133 }
134 
135 // workers: time invariant (Moor/Goetz style)
138  StateSet::Iterator sit=mLeaves.Begin();
139  StateSet::Iterator sit_end=mLeaves.End();
140  // assert: root must not be a leave here
141  for(;sit!=sit_end;++sit) {
142  if(mpExperiment->IsLock(*sit)) continue;
143  std::deque<Idx> seq=mpExperiment->Sequence(*sit);
144  while(seq.size()>0) {
145  seq.pop_front();
146  Idx x1=mpExperiment->Find(seq);
147  if(x1==0) continue;
148  if(mpExperiment->IsLock(x1)) break;
149  if(mpExperiment->IsLeave(x1)) continue;
150  EventSet events=mpExperiment->EnabledEvents(x1);
151  EventSet::Iterator eit=events.Begin();
152  EventSet::Iterator eit_end=events.End();
153  for(;eit!=eit_end;++eit) {
154  Idx x2=mpExperiment->SuccessorNode(x1,*eit);
155  mAbstraction.SetTransition(*sit,*eit,x2);
156  }
157  break;
158  }
159  }
160 }
161 
162 // workers: time invariant (Raisch/Yang style)
164  // prepare
166  mLeaves.Clear();
168  // loop todo: copy tree except leaves
169  // should assert that root is not a leave
170  std::stack<Idx> todo;
171  todo.push(mpExperiment->Root());
173  while(!todo.empty()) {
174  Idx nid=todo.top();
175  todo.pop();
176  if(mpExperiment->IsLeave(nid)) mLeaves.Insert(nid);
177  EventSet events=mpExperiment->EnabledEvents(nid);
178  EventSet::Iterator eit=events.Begin();
179  for(;eit!=events.End();++eit) {
180  Idx x2=mpExperiment->SuccessorNode(nid,*eit);
181  if(mpExperiment->IsLeave(x2) && !mpExperiment->IsLock(x2)) continue;
182  mAbstraction.InsState(nid);
184  mAbstraction.SetTransition(nid,*eit,x2);
185  todo.push(x2);
186  }
187  }
188  // fix ends
189  StateSet::Iterator sit=mAbstraction.StatesBegin();
190  StateSet::Iterator sit_end=mAbstraction.StatesEnd();
191  for(;sit!=sit_end;++sit) {
192  if(mpExperiment->IsLock(*sit)) continue;
193  EventSet events=mpExperiment->EnabledEvents(*sit);
194  EventSet::Iterator eit=events.Begin();
195  for(;eit!=events.End();++eit) {
196  if(mAbstraction.ExistsTransition(*sit,*eit)) continue;
197  std::deque<Idx> seq=mpExperiment->Sequence(*sit);
198  seq.push_back(*eit);
199  while(seq.size()>0) {
200  seq.pop_front();
201  Idx x2=mpExperiment->Find(seq);
202  if(x2==0) continue;
203  mAbstraction.SetTransition(*sit,*eit,x2);
204  break;
205  }
206  }
207  }
208 }
Faudes exception class.
Finite fragment of a computation tree.
bool IsLock(Idx nid) const
bool IsLeave(Idx nid) const
void RefineUniformly(unsigned int depth)
Idx Find(const std::deque< Idx > &seq) const
void RefineAt(Idx idx)
EventSet EnabledEvents(Idx nid) const
Idx Root(void) const
Navigate tree This interface is intended for external use.
const EventSet & Alphabet(void) const
std::deque< Idx > Sequence(Idx nid) const
Idx SuccessorNode(Idx nid, Idx ev) const
Idx Insert(void)
Insert new index to set.
void RefineUniformly(unsigned int depth)
const Generator & TivAbstraction(void)
const Generator & TvAbstraction(void)
faudes::Experiment * mpExperiment
const faudes::Experiment & Experiment(void)
Set of indices with symbolic names.
Definition: cfl_nameset.h:69
Base class of all FAUDES generators.
StateSet::Iterator StatesBegin(void) const
Iterator to Begin() of state set.
bool SetTransition(Idx x1, Idx ev, Idx x2)
Add a transition to generator by indices.
bool ExistsTransition(const std::string &rX1, const std::string &rEv, const std::string &rX2) const
Test for transition given by x1, ev, x2.
StateSet::Iterator StatesEnd(void) const
Iterator to End() of state set.
Idx InsState(void)
Add new anonymous state to generator.
Idx InsInitState(void)
Create new anonymous state and set as initial state.
virtual void Clear(void)
Clear generator data.
void InjectAlphabet(const EventSet &rNewalphabet)
Set mpAlphabet without consistency check.
virtual void Clear(void)
Clear all set.
Definition: cfl_baseset.h:1902
Iterator End(void) const
Iterator to the end of set.
Definition: cfl_baseset.h:1896
Iterator Begin(void) const
Iterator to the begin of set.
Definition: cfl_baseset.h:1891
Abstractions by experiments for linear hybrid automata.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)

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