exefaudes.cpp
Go to the documentation of this file.
1/** @file exefaudes.cpp Example application for executor class
2
3This application reads the specified generator file to initialize an
4Executor and then runs the generator interactively. For more advanced
5simulation, see the tutoriyl simfaudes.cpp.
6
7@ingroup Tutorials
8
9@include exefaudes.cpp
10
11*/
12
13
14#include "libfaudes.h"
15
16using namespace faudes;
17using namespace std;
18
19int 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}
int main()
const TimeInterval & EnabledTime() const
bool ExecuteTime(Time::Type time)
const EventSet & EnabledEvents() const
bool ExecuteEvent(Idx event)
void CurrentTime(Time::Type time)
void Generator(const TimedGenerator &rGen)
const TimeInterval & EnabledInterval() const
bool IsDeadlocked() const
std::string CurrentTimedStateStr(void) const
bool Exists(const Idx &rIndex) const
bool In(Time::Type time) const
std::string Str(void) const
void DWrite(const Type *pContext=0) const
bool Empty(void) const
uint32_t Idx

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen