summaryrefslogtreecommitdiffstats
path: root/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Master/Real-Time Systems/Praktikum1/Aufgabe3/src/main.cpp')
-rw-r--r--Master/Real-Time Systems/Praktikum1/Aufgabe3/src/main.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/main.cpp b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/main.cpp
new file mode 100644
index 0000000..c616f9b
--- /dev/null
+++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/main.cpp
@@ -0,0 +1,99 @@
+/*
+ * main.cpp
+ *
+ * Created on: 31.10.2010
+ * Author: sven
+ */
+#ifndef GLOBAL_H_
+ #include "Global.h"
+#endif
+#ifndef TASK_H_
+ #include "Task.h"
+#endif
+#ifndef RMSSCHEDULER_H_
+ #include "RMSScheduler.h"
+#endif
+#ifndef DMSSCHEDULER_H_
+ #include "DMSScheduler.h"
+#endif
+#ifndef EDFSCHEDULER_H_
+ #include "EDFScheduler.h"
+#endif
+#ifndef RESPONSETIMEANALYSIS_H_
+ #include "ResponseTimeAnalysis.h"
+#endif
+
+#include <stdlib.h>
+#include <iostream>
+#include <fstream>
+#include <queue>
+
+const char* TASKS_FILE_NAME = "tasks.txt";
+
+int lcm(int,int);
+int gcd(int,int);
+int load_tasks(const char*,task_set&);
+
+int main(int argc,char* argv[])
+{
+ int ci = 1;
+ task_set tasks;
+ load_tasks(TASKS_FILE_NAME,tasks);
+ for(uint i=0;i<tasks.size();i++) {
+ Task t = tasks[i];
+ ci = lcm(ci,t.getOrigP());
+ }
+ cout << "CI: " << ci << endl;
+// RMSScheduler rms;
+// rms.run(tasks,ci);
+//
+// DMSScheduler dms;
+// dms.run(tasks,ci);
+
+ EDFScheduler edf;
+ edf.run(tasks,ci);
+
+// ResponseTimeAnalysis rta;
+// rta.calcOptimalStaticPriorities(tasks);
+
+ return EXIT_SUCCESS;
+}
+
+int load_tasks(const char* task_file_name,task_set& tasks)
+{
+ char name[2];
+ int c,p,d;
+ ifstream task_file(task_file_name);
+ if(!task_file) {
+ cout << "error opening file: " << task_file_name << endl;
+ return 1;
+ }
+ while(!task_file.eof()) {
+ name[0] = 0; name[1] = 0;
+ task_file >> name >> c >> p >> d;
+ if(name[0] != 0) {
+ Task t(&name[0],c,p,d);
+ tasks.push_back(t);
+ }
+ }
+ task_file.close();
+ return EXIT_SUCCESS;
+}
+// Least Common Multiple
+int lcm(int a, int b)
+{
+ return (a*b)/gcd(a, b);
+}
+// Greatest Common Divisor
+int gcd(int a, int b)
+{
+ if(b == 0)
+ {
+ return a;
+ }
+ if(a == 0)
+ {
+ return b;
+ }
+ return gcd(b, a%b);
+}