exefaudes.cpp
Go to the documentation of this file.
1 /** @file exefaudes.cpp Example application for executor class
2 
3 This application reads the specified generator file to initialize an
4 Executor and then runs the generator interactively. For more advanced
5 simulation, see the tutoriyl simfaudes.cpp.
6 
7 @ingroup Tutorials
8 
9 @include exefaudes.cpp
10 
11 */
12 
13 
14 #include "libfaudes.h"
15 
16 using namespace faudes;
17 using namespace std;
18 
19 int main(int argc, char* argv[])
20 {
21  // first argument has to be a .gen-file
22  if(argc!=2) {
23  cerr<<"usage: ./exefaudes <gen-File>"<<endl;
24  return(-1);
25  }
26 
27  // executor objekt
28  Executor sim(argv[1]);
29 
30  // until user breaks simulation
31  while(true) {
32 
33  // report current state
34  cout << "##########################################" << endl;
35  cout << "# interactive simulation of " << sim.Generator().Name() << endl;
36  cout << "# at state " << endl;
37  cout << "(time " << sim.CurrentTime() << ") " ;
38  cout << sim.CurrentTimedStateStr() << endl;
39 
40  // request feasibility information
41  TimeInterval etime=sim.EnabledTime();
42  TimeInterval einterval=sim.EnabledInterval();
43  EventSet eevents=sim.EnabledEvents();
44 
45  // report deadlock
46  if(sim.IsDeadlocked()) {
47  cout<<">> Simulation is deadlocked."<<endl;
48  cout<<">> Abort (a) or reset simulation (r)?"<<endl;
49  std::string choice;
50  cin >> choice;
51  if(choice=="a") break;
52  else if(choice=="r") {
53  sim.Reset();
54  continue;
55  } else {
56  cerr<<">> ignoring invalid choice"<<endl;
57  continue;
58  }
59  }
60 
61  // report feasibility: a) no events
62  if(eevents.Empty()) {
63  cout << ">> Time may pass up to " << etime.Str() << endl;
64  cout << ">> No events are enabled for " << einterval.Str() << endl;
65  cout << ">> Abort (a), or let time pass (t): ";
66  }
67  // report feasibility: b) events nonempty
68  else {
69  cout << ">> Time may pass up to " << etime.Str() << endl;
70  cout << ">> The following events are enabled for time " << einterval.Str() << endl;
71  eevents.DWrite();
72  cout<<">> Abort (a), let time pass (t) or execute transition (e): ";
73  }
74  std::string choice;
75  cin>>choice;
76  if(choice=="a") {
77  break;
78  } else if(choice=="e") {
79  cout<< ">> Event index: ";
80  Idx event;
81  cin >> event;
82  if(eevents.Exists(event)==false) {
83  cout<< ">> ignoring invalid event index "<<endl;
84  continue;
85  } else {
86  sim.ExecuteEvent(event);
87  continue;
88  }
89  } else if (choice=="t") {
90  cout<<">> Let time pass t: ";
91  Time::Type time;
92  cin>>time;
93  if(! etime.In(time)) {
94  cout<<">> ignoring invalid time "<<endl;
95  continue;
96  }
97  else sim.ExecuteTime(time);
98  } else {
99  cout<<">> ignoring invalid choice "<<endl;
100  continue;
101  }
102  } // end while
103 
104 
105  return(0);
106 }
An Executor is a timed generator that maintains a current state.
Definition: sp_executor.h:93
const TimeInterval & EnabledTime() const
Get maximal interval of time that can pass without executing an event.
bool ExecuteTime(Time::Type time)
Let time pass.
const EventSet & EnabledEvents() const
Get set of events that are enabled at current (timed) state.
bool ExecuteEvent(Idx event)
Execute transition.
void CurrentTime(Time::Type time)
Set current time.
void Generator(const TimedGenerator &rGen)
Initialise from TimedGenerator.
Definition: sp_executor.cpp:46
const TimeInterval & EnabledInterval() const
Get maximal interval on which set of enabled events is constant.
void Reset()
Reset all clocks and assign initial state.
bool IsDeadlocked() const
Returns true if timed generator is in a deadlocked state.
std::string CurrentTimedStateStr(void) const
Pretty printable string of current state.
Set of indices with symbolic names.
Definition: cfl_nameset.h:69
bool Exists(const Idx &rIndex) const
Test existence of index.
Model of a time interval.
bool In(Time::Type time) const
Test whether a point satisfies interval.
std::string Str(void) const
Pretty printable string.
Int Type
Datatype for point on time axis.
void DWrite(const Type *pContext=0) const
Write configuration data to console, debugging format.
Definition: cfl_types.cpp:225
int main(int argc, char *argv[])
Definition: exefaudes.cpp:19
bool Empty(void) const
Test whether if the TBaseSet is Empty.
Definition: cfl_baseset.h:1824
Includes all libFAUDES headers, incl plugings
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