summaryrefslogtreecommitdiffstats
path: root/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/main.cpp
blob: c616f9bb7076b4aa858c22b1f07ed5f7232cca8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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);
}