-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessScheduler.java
More file actions
230 lines (213 loc) · 12.2 KB
/
Copy pathProcessScheduler.java
File metadata and controls
230 lines (213 loc) · 12.2 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import java.io.BufferedReader;
import java.io.InputStreamReader;
import scheduler.scheduling.policies.*;
import java.util.LinkedList;
import scheduler.processing.*;
import scheduler.*;
public class ProcessScheduler {
public static void main(String[] args) throws Exception {
Generador g = null;
Procesador p = null;
// variables del programa
BufferedReader tec = new BufferedReader(new InputStreamReader(System.in));
int rangoF = 0, rangoI = 0;
int aritht = 0, iot = 0, condt = 0, loopt = 0, quantumt = 0;
String s = "";
boolean quit = true;
// variables de tiempo ingresadas por el usuario
double arith = 0, io = 0, cond = 0, loop = 0, quantum = 0;
String rango = "";
String politica = "";
Double Rangoinicial = 0.0, Rangofinal = 0.0;
// Se obtienen los datos ingresados por el usuario.
try {
while (quit == true) {
// comprabamos si correra en uno o dos procesadores
// dual
if (args[0].equals("-dual")) {
// asignamos los valores para los tiempos segun el usuario los ingrese
try {
arith = Double.parseDouble(args[3]);
aritht = (int) (arith * 1000);
io = Double.parseDouble(args[4]);
iot = (int) (io * 1000);
cond = Double.parseDouble(args[5]);
condt = (int) (cond * 1000);
loop = Double.parseDouble(args[6]);
loopt = (int) (loop * 1000);
if (args.length > 7) {
quantum = Double.parseDouble(args[7]);
quantumt = (int) (quantum * 1000);
}
} catch (Exception e) {
System.out.println("Por favor ingrese valores numericos para los tiempos.");
}
// Se obtienen los rangos de tiempo
for (int i = 0; i <= args[2].length(); i++) {
if (args[2].charAt(i) == '-') {
Rangoinicial = Double.parseDouble(args[2].substring(0, i));
Rangofinal = Double.parseDouble(args[2].substring(i + 1, args[2].length()));
break;
}
}
// Rangos convertidos a milisegundos
rangoF = (int) (Rangofinal * 1000);
rangoI = (int) (Rangoinicial * 1000);
// obtememos del usuario la politica (en el caso que sea dual)
switch (args[1]) {
case "-fcfs":
politica = "First Come First Served";
g = new Generador("fcfs", rangoF, rangoI, aritht, condt, iot, loopt);
g.start();
p = new Procesador(2, "fcfs");
p.start();
break;
case "-lcfs":
politica = "Last Come First Served";
g = new Generador("lcfs", rangoF, rangoI, aritht, condt, iot, loopt);
g.start();
p = new Procesador(2, "lcfs");
p.start();
break;
case "-rr":
politica = "Round Robin";
g = new Generador("rr", rangoF, rangoI, aritht, condt, iot, loopt);
g.start();
p = new Procesador(2, "rr",quantumt );
p.start();
break;
case "-pp":
politica = "Priority Policy";
g = new Generador("pp", rangoF, rangoI, aritht, condt, iot, loopt);
g.start();
p = new Procesador(2, "pp");
p.start();
break;
default:
System.out.println("Por favor ingrese una politica correcta.");
}
s = tec.readLine();
s = s.toLowerCase();
if (s.equals("q")) {
if (Procesador.politicausada() == "First-Come First-Served") {
System.out.println("\nLa cantidad de procesos que se atendieron fue de: "
+ Procesador.totalProcesosFCFS());
System.out.println("La cantidad de procesos que quedaron sin atencion fue de: "
+ Procesador.restantesFCFS());
} else if (Procesador.politicausada() == "Last-Come First-Served") {
System.out.println("\nLa cantidad de procesos que se atendieron fue de: "
+ Procesador.totalProcesosLCFS());
System.out.println("La cantidad de procesos que quedaron sin atencion fue de: "
+ Procesador.restantesLCFS());
} else if (Procesador.politicausada() == "Priority Policy") {
System.out.println(
"\nLa cantidad de procesos que se atendieron fue de: " + Procesador.totalProcesosPP());
System.out.println("La cantidad de procesos que quedaron sin atencion fue de: "
+ Procesador.restantesPP());
} else if (Procesador.politicausada() == "Round-Robin") {
System.out.println(
"\nLa cantidad de procesos que se atendieron fue de: " + Procesador.totalProcesosRR());
System.out.println("La cantidad de procesos que quedaron sin atencion fue de: "
+ Procesador.restantesRR());
}
System.out.println("El tiempo promedio de atencion por proceso es de: " + Procesador.promedio());
System.out.println("Politica utilizada: " + Procesador.politicausada());
System.exit(0);
}
//------------------------------------------------TERMINA DUAL-------------------------------------------------------------------
} else {
// asignamos los valores para los tiempos segun el usuario los ingrese
try {
arith = Double.parseDouble(args[2]);
io = Double.parseDouble(args[3]);
cond = Double.parseDouble(args[4]);
loop = Double.parseDouble(args[5]);
aritht = (int) (arith * 1000);
iot = (int) (io * 1000);
condt = (int) (cond * 1000);
loopt = (int) (loop * 1000);
if (args.length > 6) {
quantum = Double.parseDouble(args[6]);
quantumt = (int) (quantum * 1000);
}
} catch (Exception e) {
System.out.println("Por favor ingrese valores numericos para los tiempos.");
}
// Se obtienen los rangos de tiempo
for (int i = 0; i <= args[1].length(); i++) {
if (args[1].charAt(i) == '-') {
Rangoinicial = Double.parseDouble(args[1].substring(0, i));
Rangofinal = Double.parseDouble(args[1].substring(i + 1, args[1].length()));
break;
}
}
rangoF = (int) (Rangofinal * 1000);
rangoI = (int) (Rangoinicial * 1000);
// obtememos del usuario la politica (en caso que no sea dual)
switch (args[0]) {
case "-fcfs":
politica = "First Come First Served";
g = new Generador("fcfs", rangoF, rangoI, aritht, condt, iot, loopt);
g.start();
p = new Procesador(1, "fcfs");
p.start();
break;
case "-lcfs":
politica = "Last Come First Served";
g = new Generador("lcfs", rangoF, rangoI, aritht, condt, iot, loopt);
g.start();
p = new Procesador(1, "lcfs");
p.start();
break;
case "-rr":
politica = "Round Robin";
g = new Generador("rr", rangoF, rangoI, aritht, condt, iot, loopt);
g.start();
p = new Procesador(1, "rr", quantumt);
p.start();
break;
case "-pp":
politica = "Priority Policy";
g = new Generador("pp", rangoF, rangoI, aritht, condt, iot, loopt);
g.start();
p = new Procesador(1, "pp");
p.start();
break;
default:
System.out.println("Por favor ingrese una politica correcta.");
}
}
s = tec.readLine();
s = s.toLowerCase();
if (s.equals("q")) {
if (Procesador.politicausada() == "First-Come First-Served") {
System.out.println("\nLa cantidad de procesos que se atendieron fue de: "
+ Procesador.totalProcesosFCFS());
System.out.println("La cantidad de procesos que quedaron sin atencion fue de: "
+ Procesador.restantesFCFS());
} else if (Procesador.politicausada() == "Last-Come First-Served") {
System.out.println("\nLa cantidad de procesos que se atendieron fue de: "
+ Procesador.totalProcesosLCFS());
System.out.println("La cantidad de procesos que quedaron sin atencion fue de: "
+ Procesador.restantesLCFS());
} else if (Procesador.politicausada() == "Priority Policy") {
System.out.println(
"\nLa cantidad de procesos que se atendieron fue de: " + Procesador.totalProcesosPP());
System.out.println("La cantidad de procesos que quedaron sin atencion fue de: "
+ Procesador.restantesPP());
} else if (Procesador.politicausada() == "Round-Robin") {
System.out.println(
"\nLa cantidad de procesos que se atendieron fue de: " + Procesador.totalProcesosRR());
System.out.println("La cantidad de procesos que quedaron sin atencion fue de: "
+ Procesador.restantesRR());
}
System.out.println("El tiempo promedio de atencion por proceso es de: " + Procesador.promedio());
System.out.println("Politica utilizada: " + Procesador.politicausada());
System.exit(0);
}
}
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Por favor ingrese argumentos en la linea de comandos.");
}
}
}