exefaudes.cppGo to the documentation of this file.00001 /** @file exefaudes.cpp Example application for executor class 00002 00003 This application reads the specified generator file to initialize an 00004 Executor and then runs the generator interactively. For more advanced 00005 simulation, see the tutoriyl simfaudes.cpp. 00006 00007 @ingroup Tutorials 00008 00009 @include exefaudes.cpp 00010 00011 */ 00012 00013 00014 #include "libfaudes.h" 00015 #include "tp_include.h" 00016 #include "sp_include.h" 00017 00018 using namespace faudes; 00019 using namespace std; 00020 00021 int main(int argc, char* argv[]) 00022 { 00023 // first argument has to be a .gen-file 00024 if(argc!=2) { 00025 cerr<<"usage: ./exefaudes <gen-File>"<<endl; 00026 return(-1); 00027 } 00028 00029 // executor objekt 00030 Executor sim(argv[1]); 00031 00032 // until user breaks simulation 00033 while(true) { 00034 00035 // report current state 00036 cout << "##########################################" << endl; 00037 cout << "# interactive simulation of " << sim.Generator().Name() << endl; 00038 cout << "# at state " << endl; 00039 cout << "(time " << sim.CurrentTime() << ") " ; 00040 cout << sim.CurrentTimedStateStr() << endl; 00041 00042 // request feasibility information 00043 TimeInterval etime=sim.EnabledTime(); 00044 TimeInterval einterval=sim.EnabledInterval(); 00045 EventSet eevents=sim.EnabledEvents(); 00046 00047 // report deadlock 00048 if(sim.IsDeadlocked()) { 00049 cout<<">> Simulation is deadlocked."<<endl; 00050 cout<<">> Abort (a) or reset simulation (r)?"<<endl; 00051 std::string choice; 00052 cin >> choice; 00053 if(choice=="a") break; 00054 else if(choice=="r") { 00055 sim.Reset(); 00056 continue; 00057 } else { 00058 cerr<<">> ignoring invalid choice"<<endl; 00059 continue; 00060 } 00061 } 00062 00063 // report feasibility: a) no events 00064 if(eevents.Empty()) { 00065 cout << ">> Time may pass up to " << etime.Str() << endl; 00066 cout << ">> No events are enabled for " << einterval.Str() << endl; 00067 cout << ">> Abort (a), or let time pass (t): "; 00068 } 00069 // report feasibility: b) events nonempty 00070 else { 00071 cout << ">> Time may pass up to " << etime.Str() << endl; 00072 cout << ">> The following events are enabled for time " << einterval.Str() << endl; 00073 eevents.DWrite(); 00074 cout<<">> Abort (a), let time pass (t) or execute transition (e): "; 00075 } 00076 std::string choice; 00077 cin>>choice; 00078 if(choice=="a") { 00079 break; 00080 } else if(choice=="e") { 00081 cout<< ">> Event index: "; 00082 Idx event; 00083 cin >> event; 00084 if(eevents.Exists(event)==false) { 00085 cout<< ">> ignoring invalid event index "<<endl; 00086 continue; 00087 } else { 00088 sim.ExecuteEvent(event); 00089 continue; 00090 } 00091 } else if (choice=="t") { 00092 cout<<">> Let time pass t: "; 00093 tpTime::Type time; 00094 cin>>time; 00095 if(! etime.In(time)) { 00096 cout<<">> ignoring invalid time "<<endl; 00097 continue; 00098 } 00099 else sim.ExecuteTime(time); 00100 } else { 00101 cout<<">> ignoring invalid choice "<<endl; 00102 continue; 00103 } 00104 } // end while 00105 00106 00107 return(0); 00108 } libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |