-
Notifications
You must be signed in to change notification settings - Fork 0
/
SchedulerType.java
118 lines (98 loc) · 3.33 KB
/
SchedulerType.java
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
*Contine tipurile de planificatoare
*/
import java.io.*;
import java.util.Random;
public class SchedulerType {
/**
*Calculeaza cmmdc dintre cotele proceselor
* @param1 - vectorul de procese
*/
public static int cmmdc(Proces[] Procese){
int cmmdc = Procese[0].weight;
for(int i = 1; i < Procese.length; i++) {
int copy = Procese[i].weight;
while(copy != cmmdc) {
if(copy > cmmdc) {
copy -= cmmdc;
}
else if(copy < cmmdc) {
cmmdc -= copy;
}
}
}
return cmmdc;
}
/**
*Planificatorul Random care selecteaza aleatoriu tipul de proces
* @param1 - fisierul incarcat in memorie
* @param2 - vectorul de procese
* @param3 - fisierul de iesire
*/
public static void random(FileRead F,Proces[] Procese, String out) throws IOException {
Writer writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(out)));
Random randomGenerator = new Random();
for(int j = 0; j < F.NumberofNumbersToBeProcessed; j++){
int random = randomGenerator.nextInt(F.NumberOfEvents);
Procese[random].setX(F.Numbers[j]);
Procese[random].compute();
Procese[random].showResult(writer);
}
writer.close();
}
/**
*Planificatorul Round care selecteaza cate un proces
* @param1 - fisierul incarcat in memorie
* @param2 - vectorul de procese
* @param3 - fisierul de iesire
*/
public static void round(FileRead F,Proces[] Procese, String out) throws IOException {
Writer writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(out)));
int i = 0;
while(true) {
for(int j = 0; j < F.NumberOfEvents; j++){
if(i == F.NumberofNumbersToBeProcessed) {
writer.close();
return;
}
Procese[j].setX(F.Numbers[i]);
Procese[j].compute();
Procese[j].showResult(writer);
i++;
}
}
}
/**
*Planificatorul Weighted care selecteaza procesele in functie de cmmdc
* @param1 - fisierul incarcat in memorie
* @param2 - vectorul de procese
* @param3 - fisierul de iesire
*/
public static void weighted(FileRead F, Proces[] Procese, String out) throws IOException {
int current = 0;
Writer writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(out)));
int s = 0;
for (int i = 0; i < F.NumberOfEvents; i++) {
s += Procese[i].weight;
}
int t = cmmdc(Procese);
int i = 0;
while (true) {
for(int j = 0; j < F.NumberOfEvents; j++) {
for(int k = 0; k < Procese[j].weight / t; k++) {
if(i == F.NumberofNumbersToBeProcessed) {
writer.close();
return;
}
Procese[j].setX(F.Numbers[i]);
Procese[j].compute();
Procese[j].showResult(writer);
i++;
}
}
}
}
}