hyb_2_reachability.cpp
Go to the documentation of this file.
1 /** @file hyb_2_reachability.cpp
2 
3 Tutorial, hybrid systems plugin.
4 This tutorial demonstrates reachability analysis on linear hybrid automata.
5 
6 @ingroup Tutorials
7 
8 @include hyb_2_reachability.cpp
9 
10 */
11 
12 #include "libfaudes.h"
13 
14 // make the faudes namespace available to our program
15 using namespace faudes;
16 
17 
18 /** Run the tutorial */
19 int main() {
20 
21 
22 
23  /** load from file */
24  LinearHybridAutomaton lha("data/hyb_lhautomaton.gen");
25 
26  // Report to console
27  std::cout << "################################\n";
28  std::cout << "# linear hybrid automaton from file: \n";
29  lha.Write();
30  std::cout << "################################\n";
31  std::cout << "# Valid() returns " << lha.Valid() << "\n";
32  std::cout << "################################\n";
33 
34  // get initial state
35  HybridStateSet istates;
36  StateSet::Iterator qit=lha.InitStatesBegin();
37  StateSet::Iterator qit_end=lha.InitStatesEnd();
38  for(;qit!=qit_end;++qit){
39  Polyhedron* poly = new Polyhedron(lha.InitialConstraint(*qit));
40  PolyIntersection(lha.StateSpace(),*poly);
41  PolyFinalise(*poly);
42  istates.Insert(*qit,poly);
43  }
44  std::cout << "################################\n";
45  std::cout << "# dumping initial states\n";
46  istates.DWrite(lha);
47  std::cout << "################################\n";
48 
49 
50  // loop maxmimal 50 jumps with alternating north/south events
51  for(int i=1; i<=50; ++ i) {
52 
53  // compute reachable states per event
54  std::map< Idx, HybridStateSet* > sstates;
55  LhaReach(lha,istates,sstates);
56 
57  // dump successor states
58  std::cout << "################################\n";
59  std::cout << "# dumping successor stage " << i << "\n";
60  std::map< Idx, HybridStateSet* >::iterator sit=sstates.begin();
61  std::map< Idx, HybridStateSet* >::iterator sit_end=sstates.end();
62  for(;sit!=sit_end;++sit){
63  std::cout << "### event " << lha.EventName(sit->first) << "\n";
64  sit->second->DWrite(lha);
65  }
66  std::cout << "################################\n";
67 
68  // choose next event to track
69  std::string evstr;
70  if(i % 2 ==1) evstr="north";
71  else evstr="south";
72  Idx ev = lha.EventIndex(evstr);
73  if(sstates.find(ev)==sstates.end()) break;
74  istates.Assign(*sstates[ev]);
75  }
76 
77  // done
78  return 0;
79 }
80 
81 
82 
Set of states in an hybrid automata.
void DWrite(const LinearHybridAutomaton &lha)
inspect
void Assign(const HybridStateSet &rOther)
assignment
void Insert(Idx q)
insert / erase (we take owvership of polyhedra)
Polyhedron in R^n.
Generator with linear hybrid automata extensions.
virtual bool Valid(void) const
Check if generator is valid.
const Polyhedron & InitialConstraint(Idx idx) const
Get initial constraint of state by index.
const Polyhedron & StateSpace(void) const
Get continuous statespace.
void Write(const Type *pContext=0) const
Write configuration data to console.
Definition: cfl_types.cpp:139
StateSet::Iterator InitStatesBegin(void) const
Iterator to Begin() of mInitStates.
Idx EventIndex(const std::string &rName) const
Event index lookup.
StateSet::Iterator InitStatesEnd(void) const
Iterator to End() of mInitStates.
std::string EventName(Idx index) const
Event name lookup.
void PolyFinalise(const Polyhedron &fpoly)
convert PPL polyhedron back to faudes data structures; this is required if we manipulate a polyhedron...
Definition: hyb_compute.cpp:53
void PolyIntersection(const Polyhedron &poly, Polyhedron &res)
intersection
int main()
Run the tutorial.
Includes all libFAUDES headers, incl plugings
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
void LhaReach(const LinearHybridAutomaton &lha, const HybridStateSet &states, std::map< Idx, HybridStateSet * > &ostates, int *pCnt)
compute sets of reachable state per successor event

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