#include #include #include using namespace std; enum DU_State { Up, Failed, Under_M }; enum Event_Type { DU_Failed, DU_Repaired, DU_Maint_Begin, DU_Maint_End, Simulation_Over }; class Dist_Unit { public: DU_State state; int id; }; class Event { public: Event_Type type; Dist_Unit *du; double time; }; typedef multimap EQ; class Simulation_System { public: Simulation_System(int argc, char **argv); void Run(); void Print_Event(Event *e); protected: int n; double duration; double beta_f; double eta_f; double beta_r; double eta_r; double gamma_r; double mi; double mt; vector dus; EQ eventq; double simtime; }; void Simulation_System::Print_Event(Event *e) { } Simulation_System::Simulation_System(int argc, char **argv) { int i; Dist_Unit *du; Event *e; if (argc != 10) { cerr << "usage: patron n duration(years) beta_f eta_f beta_r eta_r gamma_r maintenance_time maintenance_interval\n"; cerr << " all other units are days\n"; exit(1); } if (sscanf(argv[1], "%d", &n) != 1 || n <= 0) { cerr << "Bad n" << endl; exit(0); } if (sscanf(argv[2], "%lf", &duration) != 1 || duration <= 0) { cerr << "Bad duration" << endl; exit(0); } duration *= 365.0; if (sscanf(argv[3], "%lf", &beta_f) != 1 || beta_f <= 0) { cerr << "Bad beta_f" << endl; exit(0); } if (sscanf(argv[4], "%lf", &eta_f) != 1 || eta_f <= 0) { cerr << "Bad eta_f" << endl; exit(0); } if (sscanf(argv[5], "%lf", &beta_r) != 1 || beta_r <= 0) { cerr << "Bad beta_r" << endl; exit(0); } if (sscanf(argv[6], "%lf", &eta_r) != 1 || eta_r <= 0) { cerr << "Bad eta_r" << endl; exit(0); } if (sscanf(argv[7], "%lf", &gamma_r) != 1 || gamma_r < 0) { cerr << "Bad gamma_r" << endl; exit(0); } if (sscanf(argv[8], "%lf", &mt) != 1 || mt <= 0) { cerr << "Bad mt" << endl; exit(0); } if (sscanf(argv[9], "%lf", &mi) != 1 || mi <= 0) { cerr << "Bad mi" << endl; exit(0); } for (i = 0; i < n; i++) { du = new Dist_Unit; du->id = i; du->state = Up; dus.push_back(du); } simtime = 0; e = new Event; e->type = Simulation_Over; e->time = duration; e->du = NULL; eventq.insert(make_pair(e->time, e)); } void Simulation_System::Run() { EQ::iterator eqit; Event *e; while(1) { eqit = eventq.begin(); if (eqit == eventq.end()) { cerr << "Event Queue is empty\n"; exit(1); } e = eqit->second; eventq.erase(eqit); switch(e->type) { default: cerr << "Event not implemented " << e->type << endl; exit(1); } } } main(int argc, char **argv) { int ndu; int i; Simulation_System *ss; double simtime, mttf, mttr; srand48(0); ss = new Simulation_System(argc, argv); ss->Run(); }