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 #include "tp_include.h"
16 #include "sp_include.h"
17 
18 using namespace faudes;
19 using namespace std;
20 
21 int main(int argc, char* argv[])
22 {
23  // first argument has to be a .gen-file
24  if(argc!=2) {
25  cerr<<"usage: ./exefaudes <gen-File>"<<endl;
26  return(-1);
27  }
28 
29  // executor objekt
30  Executor sim(argv[1]);
31 
32  // until user breaks simulation
33  while(true) {
34 
35  // report current state
36  cout << "##########################################" << endl;
37  cout << "# interactive simulation of " << sim.Generator().Name() << endl;
38  cout << "# at state " << endl;
39  cout << "(time " << sim.CurrentTime() << ") " ;
40  cout << sim.CurrentTimedStateStr() << endl;
41 
42  // request feasibility information
43  TimeInterval etime=sim.EnabledTime();
44  TimeInterval einterval=sim.EnabledInterval();
45  EventSet eevents=sim.EnabledEvents();
46 
47  // report deadlock
48  if(sim.IsDeadlocked()) {
49  cout<<">> Simulation is deadlocked."<<endl;
50  cout<<">> Abort (a) or reset simulation (r)?"<<endl;
51  std::string choice;
52  cin >> choice;
53  if(choice=="a") break;
54  else if(choice=="r") {
55  sim.Reset();
56  continue;
57  } else {
58  cerr<<">> ignoring invalid choice"<<endl;
59  continue;
60  }
61  }
62 
63  // report feasibility: a) no events
64  if(eevents.Empty()) {
65  cout << ">> Time may pass up to " << etime.Str() << endl;
66  cout << ">> No events are enabled for " << einterval.Str() << endl;
67  cout << ">> Abort (a), or let time pass (t): ";
68  }
69  // report feasibility: b) events nonempty
70  else {
71  cout << ">> Time may pass up to " << etime.Str() << endl;
72  cout << ">> The following events are enabled for time " << einterval.Str() << endl;
73  eevents.DWrite();
74  cout<<">> Abort (a), let time pass (t) or execute transition (e): ";
75  }
76  std::string choice;
77  cin>>choice;
78  if(choice=="a") {
79  break;
80  } else if(choice=="e") {
81  cout<< ">> Event index: ";
82  Idx event;
83  cin >> event;
84  if(eevents.Exists(event)==false) {
85  cout<< ">> ignoring invalid event index "<<endl;
86  continue;
87  } else {
88  sim.ExecuteEvent(event);
89  continue;
90  }
91  } else if (choice=="t") {
92  cout<<">> Let time pass t: ";
93  tpTime::Type time;
94  cin>>time;
95  if(! etime.In(time)) {
96  cout<<">> ignoring invalid time "<<endl;
97  continue;
98  }
99  else sim.ExecuteTime(time);
100  } else {
101  cout<<">> ignoring invalid choice "<<endl;
102  continue;
103  }
104  } // end while
105 
106 
107  return(0);
108 }

libFAUDES 2.24g --- 2014.09.15 --- c++ api documentaion by doxygen