-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMain.java
More file actions
599 lines (563 loc) · 20.5 KB
/
Main.java
File metadata and controls
599 lines (563 loc) · 20.5 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
/* Integrantes:
* Garcia Delgado Jorge Alberto
* Lopez Sanchez Ary Daniel
*
* Repositorio Github:
* https://github.com/Alberto2425/SimuladordeProcesos
*/
import java.util.Scanner;
import java.util.Random;
import java.util.ArrayList;
import java.util.Collections;
public class Main {
static Reporte r=new Reporte();
static Random random = new Random();
static I Comparator=new I();
static ArrayList<Proceso> c2=new ArrayList<Proceso>();
static int tiempoM=random.nextInt(11)+18;
static int nUsuarios = 2;
static int quantum=random.nextInt(4)+1;
public static void main(String[] args) {
Scanner leer=new Scanner(System.in);
String cadena;
int tipoPlanificacion;
int tipoAlgoritmo;
Random random = new Random();
int nProcesos = random.nextInt(5) + 5;
ArrayList<Proceso>procesos=new ArrayList<Proceso>();
//menu
do{
for(int i=0; i<nProcesos; i++) {
Proceso p=new Proceso(quantum);
procesos.add(p);
}
System.out.println("Que tipo de algoritmo de planificacion usar por default?");
System.out.println("1.- apropiativo \n2.- no apropiativo\n3.- Cerrar programa");
do{
cadena=leer.nextLine();
if(isNumeric(cadena)==true){
tipoPlanificacion = Integer.parseInt(cadena);
}else{
tipoPlanificacion=3;
}
if(tipoPlanificacion<1 || tipoPlanificacion>3){
System.out.println("Agregue un dato entero entre 1 y 3 para continuar.\n1.- apropiativo n\2.- no apropiativo\2.- Cerrar Programa");
}
}while(tipoPlanificacion<1 || tipoPlanificacion>3);
if(tipoPlanificacion==3){break;}
System.out.println("Que algoritmo usaras?");
System.out.println("1.- Round-robin\n2.- Prioridades\n3.- Multiples colar de prioridad\n4.- Proceso mas corto primero\n5.- Participacion garantizada\n6.-Boletos de Loteria\n7.- Participacion equitativa");
do{
cadena=leer.nextLine();
if(isNumeric(cadena)==true){
tipoAlgoritmo = Integer.parseInt(cadena);
}else{
tipoAlgoritmo=7;
}
if(tipoAlgoritmo<1 || tipoAlgoritmo>6){
System.out.println("Agregue un dato entero entre 1 al 7.");
System.out.println("1.- Round-robin\n2.- Prioridades\n3.- Multiples colar de prioridad\n4.- Proceso mas corto primero\n5.- Planificación garantizada\n6.-Boletos de Loteria\n7.- Participacion equitativa");
}
}while(tipoAlgoritmo<1 || tipoAlgoritmo>7);
imprimirEspecificacionesGenerales(procesos, tipoPlanificacion, tipoAlgoritmo, nProcesos);
switch (tipoAlgoritmo) {
case 1:
//Llamar al metodo RoundRobin
roundRobin(procesos, tipoPlanificacion);
break;
case 2:
// Llamar al método de Prioridades
prioridades(procesos, tipoPlanificacion);
break;
case 3:
// Llamar al método de Múltiples colas de prioridad
prioridadesMultiples(procesos, tipoPlanificacion);
break;
case 4:
// Llamar al método de Proceso más corto primero
cortoF(procesos,tipoPlanificacion);
break;
case 5:
// Llamar al método de Planificacion Garantizada
planificacionG(procesos, tipoPlanificacion);
break;
case 6:
// Llamar al método de Boletos de loteria
boletos(procesos, tipoPlanificacion);
break;
case 7:
// Llamar al método de Participacion equitativa
participacionEquitativa(procesos, tipoPlanificacion);
break;
default:
System.out.println("Opción no válida");
}
Ejecuto(procesos);
r.imprimirReporte();
imprimirProcesos(procesos);
tiempoM=random.nextInt(11)+15;
nProcesos = random.nextInt(10) + 1;
}while(tipoPlanificacion!=3);
leer.close();
}
//Round-Robin
public static void roundRobin(ArrayList<Proceso>c,int tipoPlanificacion) {
System.out.println("El tiempo de simulacion es : "+tiempoM);
imprimirProcesos(c);
if(tipoPlanificacion==1/*Apropiativo */){
//con cada iteracion entra un proceso nuevo.
for(int i=0;i<c.size();i++){
if(tiempoM<=0){break;}
r.setD(1);
System.out.print(". Entra Proceso "+c.get(i).getId()+" ");
//se verifica que el proceso este listo
if(c.get(i).getEstado()!=2){
//si el proceso aun no esta listo se genera un random para saber si se desbloqueo
c.get(i).setEstado(random.nextInt(2)+1);
}
if(c.get(i).getEstado()==2){
//si el proceso esta listo se resta el valor del quantum al tiempo restante
c.get(i).setTiempoR(c.get(i).getTiempoR()-c.get(i).getQuantum());
tiempoM-=c.get(i).getQuantum();
if(tiempoM<=0){
c.get(i).setTiempoR(c.get(i).getTiempoR()-tiempoM);
tiempoM=0;
}
if(c.get(i).getTiempoR()<=0/*El proceso termino*/){
r.setA(c.get(i).getId());
System.out.print(", se ejecuta "+(c.get(i).getQuantum()+c.get(i).getTiempoR())+" unidades y termina\n");
tiempoM-=c.get(i).getTiempoR();/*si el proceso termino el tiempo de simulacion se le suma el resto del tiempo restante*/
c.remove(i);/*se remueve el proceso de la lista*/
i--;
}else{
System.out.print(", se ejecuta "+c.get(i).getQuantum()+" unidades\n");
c.get(i).setQuantum(c.get(i).getQuantum()*2);/*Si el proceso no termino el quantum se dobla*/
}
}else{
System.out.print(", no se ejcuta porque sigue bloqueado \n");/*el proceso nu uso la CPU */
}
if(i==c.size()-1){i=-1;}
}
}else{/*No Apropiativo */
int x=0;
int xaux=0;
for(int i=0;i<c.size();i++){
if(tiempoM<=0){break;}
r.setD(1);
System.out.print(". Entra Proceso "+c.get(i).getId()+" ");
//se verifica que el proceso este listo
if(c.get(i).getEstado()!=2){
//si el proceso aun no esta listo se genera un random para saber si se desbloqueo
c.get(i).setEstado(random.nextInt(2)+1);
}
if(c.get(i).getEstado()==2){
//si el proceso esta listo se resta el valor un valor aleatorio al tiempo restante
for(int j=0;j<200;j++){
x=random.nextInt(3)+2;
xaux+=x;
c.get(i).setTiempoR(c.get(i).getTiempoR()-x);
tiempoM-=x;
if(tiempoM<=0){
c.get(i).setTiempoR(c.get(i).getTiempoR()-tiempoM);
xaux+=tiempoM;
tiempoM=0;
}
if(tiempoM<=0){
c.get(i).setTiempoR(c.get(i).getTiempoR()-tiempoM);
xaux+=tiempoM;
tiempoM=0;
}
if(c.get(i).getTiempoR()<=0/*El proceso termino*/){
xaux+=c.get(i).getTiempoR();
break;
}
c.get(i).setEstado(random.nextInt(2)+1);
if(c.get(i).getEstado()!=2){
c.get(i).setEstado(random.nextInt(2)+1);
break;
}
}
if(c.get(i).getTiempoR()<=0/*El proceso termino*/){
System.out.print(", se ejecuta "+xaux+" unidades y termina\n");
r.setA(c.get(i).getId());
tiempoM=tiempoM-c.get(i).getTiempoR();/*si el proceso termino el tiempo de simulacion se le suma el resto del tiempo restante*/
c.remove(i);/*se remueve el proceso de la lista*/
i--;
}else{
System.out.print(", se ejecuta "+xaux+" unidades\n");
/*Si el proceso no termino*/
}
}else{System.out.print(", no se ejcuta porque sigue bloqueado \n");/*el proceso nu uso la CPU */}
x=0;
xaux=0;
if(i==c.size()-1){i=-1;}
}
}
}
//método de Prioridades
public static void prioridades(ArrayList<Proceso>c,int tipoPlanificacion) {
Collections.sort(c);
roundRobin(c, tipoPlanificacion);
}
//método de Múltiples colas de prioridad
public static void prioridadesMultiples(ArrayList<Proceso>c,int tipoPlanificacion) {
ArrayList<Proceso> p4=new ArrayList<Proceso>();
ArrayList<Proceso> p3=new ArrayList<Proceso>();
ArrayList<Proceso> p2=new ArrayList<Proceso>();
ArrayList<Proceso> p1=new ArrayList<Proceso>();
for(int i=0;i<c.size();i++){
if(c.get(i).getPrioridad()==4){
p4.add(c.get(i));
}
if(c.get(i).getPrioridad()==3){
p3.add(c.get(i));
}
if(c.get(i).getPrioridad()==2){
p2.add(c.get(i));
}
if(c.get(i).getPrioridad()==1){p1.add(c.get(i));}
}
roundRobin(p4, tipoPlanificacion);
roundRobin(p3, tipoPlanificacion);
roundRobin(p2, tipoPlanificacion);
roundRobin(p1, tipoPlanificacion);
for(int i=c.size()-1;i>-1;i--){
c.remove(0);
}
for(int i=0;i<p4.size();i++){
c2.add(p4.get(i));
}
for(int i=0;i<p3.size();i++){
c2.add(p3.get(i));
}
for(int i=0;i<p2.size();i++){
c2.add(p2.get(i));
}
for(int i=0;i<p1.size();i++){
c2.add(p1.get(i));
}
for(int i=0;i<c2.size();i++){
c.add(c2.get(i));
}
}
// 4 - método de Proceso más corto primero
public static void cortoF(ArrayList<Proceso>c,int tipoPlanificacion){
System.out.println("El tiempo de simulacion es : "+tiempoM);
imprimirProcesos(c);
Collections.sort(c,Comparator);
roundRobin(c, tipoPlanificacion);
}
//método de Planificacion Garantizada
public static void planificacionG(ArrayList<Proceso>c,int tipoPlanificacion) {
ArrayList<Proceso> usuario1 = new ArrayList<Proceso>();
ArrayList<Proceso> usuario2 = new ArrayList<Proceso>();
for(int i=0;i<c.size();i++){
if(c.get(i).getPrioridad()==4 || c.get(i).getPrioridad()==2){
usuario1.add(c.get(i));
}
if(c.get(i).getPrioridad()==3 || c.get(i).getPrioridad()==1){
usuario2.add(c.get(i));
}
}
imprimirProcesos(usuario1);
imprimirProcesos(usuario2);
recoridoDeParticiones(usuario1, tipoPlanificacion, 2);
recoridoDeParticiones(usuario2, tipoPlanificacion, 2);
}
// 6 - método de Boletos de loteria
public static void boletos(ArrayList<Proceso>c,int tipoPlanificacion) {
System.out.println("El tiempo de simulacion es : "+tiempoM);
imprimirProcesos(c);
System.out.println("\nInforme de ejecución con Boletos de Lotería:");
if(tipoPlanificacion==1){
do{
if(c.size() <= 0){
break;
}
Proceso proceso = calcularSorteoBoleto(c);
r.setD(1);
System.out.print("Entra Proceso "+proceso.getId()+" ");
if(proceso.getEstado()!=2){
//si el proceso aun no esta listo se genera un random para saber si se desbloqueo
proceso.setEstado(random.nextInt(2)+1);
}
if(proceso.getEstado()==2){
//si el proceso esta listo se resta el valor del quantum al tiempo restante
proceso.setTiempoR(proceso.getTiempoR()-proceso.getQuantum());
tiempoM-=proceso.getQuantum();
if(tiempoM<=0){
proceso.setTiempoR(proceso.getTiempoR()-tiempoM);
tiempoM=0;
}
if(proceso.getTiempoR()<=0/*El proceso termino*/){
r.setA(proceso.getId());
System.out.print(", se ejecuta "+(proceso.getQuantum()+proceso.getTiempoR())+" unidades y termina\n");
tiempoM-=proceso.getTiempoR();/*si el proceso termino el tiempo de simulacion se le suma el resto del tiempo restante*/
c.remove(proceso);
}else{
System.out.print(", se ejecuta "+proceso.getQuantum()+" unidades\n");
proceso.setQuantum(proceso.getQuantum()*2);/*Si el proceso no termino el quantum se dobla*/
}
}else{
System.out.print(", no se ejcuta porque sigue bloqueado \n");/*el proceso nu uso la CPU */
}
}while(tiempoM > 0);
}else{/*No Apropiativo */
do{
int x=0;
int xaux=0;
if(tiempoM<=0){break;}
if(c.size() <= 0){break;}
r.setD(1);
Proceso proceso = calcularSorteoBoleto(c);
System.out.print("Entra Proceso "+proceso.getId()+" ");
//se verifica que el proceso este listo
if(proceso.getEstado()!=2){
//si el proceso aun no esta listo se genera un random para saber si se desbloqueo
proceso.setEstado(random.nextInt(2)+1);
}
if(proceso.getEstado()==2){
//si el proceso esta listo se resta el valor un valor aleatorio al tiempo restante
for(int j=0;j<200;j++){
x=random.nextInt(3)+2;
xaux+=x;
proceso.setTiempoR(proceso.getTiempoR()-x);
tiempoM-=x;
if(tiempoM<=0){
proceso.setTiempoR(proceso.getTiempoR()-tiempoM);
xaux+=tiempoM;
tiempoM=0;
}
if(proceso.getTiempoR()<=0/*El proceso termino*/){
xaux+=proceso.getTiempoR();
break;
}
proceso.setEstado(random.nextInt(2)+1);
if(proceso.getEstado()!=2){
proceso.setEstado(random.nextInt(2)+1);
break;
}
}
if(proceso.getTiempoR()<=0/*El proceso termino*/){
System.out.print(", se ejecuta "+xaux+" unidades y termina\n");
r.setA(proceso.getId());
tiempoM=tiempoM-proceso.getTiempoR();/*si el proceso termino el tiempo de simulacion se le suma el resto del tiempo restante*/
c.remove(proceso);
}else{
System.out.print(", se ejecuta "+xaux+" unidades\n");
/*Si el proceso no termino*/
}
}else{System.out.print(", no se ejcuta porque sigue bloqueado \n");/*el proceso nu uso la CPU */}
}while(tiempoM > 0);
}
}
// 7 - método de Participacion Equitativa
public static void participacionEquitativa(ArrayList<Proceso>c,int tipoPlanificacion) {
int nProcesosUsuario1=0;
int nProcesosUsuario2=0;
ArrayList<Proceso> usuario1 = new ArrayList<Proceso>();
ArrayList<Proceso> usuario2 = new ArrayList<Proceso>();
for(int i=0;i<c.size();i++){
if(c.get(i).getPrioridad()==4 || c.get(i).getPrioridad()==2){
usuario1.add(c.get(i));
nProcesosUsuario1++;
}
if(c.get(i).getPrioridad()==3 || c.get(i).getPrioridad()==1){
usuario2.add(c.get(i));
nProcesosUsuario2++;
}
}
imprimirProcesos(usuario1);
imprimirProcesos(usuario2);
recoridoDeParticiones(usuario1, tipoPlanificacion, nProcesosUsuario1);
recoridoDeParticiones(usuario2, tipoPlanificacion, nProcesosUsuario2);
}
// static Proceso indica el tipo de valor que este método va a devolver
private static Proceso calcularSorteoBoleto(ArrayList<Proceso> c) {
int total = 0;
for(int i=0;i<c.size();i++){
total += c.get(i).getBoletos();
}
int boletoGanador = random.nextInt(total) + 1;
int acumulador = 0;
for(int i=0;i<c.size();i++){
acumulador += c.get(i).getBoletos();
if (boletoGanador <= acumulador) {
return c.get(i);
}
}
return null;
}
public static boolean isNumeric(String cadena) {
boolean resultado;
try {
Integer.parseInt(cadena);
resultado = true;
} catch (NumberFormatException excepcion) {
resultado = false;
}
return resultado;
}
public static void Ejecuto(ArrayList<Proceso>c){
for(int i=0;i<c.size();i++){
if(c.get(i).getSeEjecuto()==true){
r.setC(c.get(i).getId());
}
if(c.get(i).getSeEjecuto()==false){
r.setB(c.get(i).getId());
}
}
}
public static void imprimirProcesos(ArrayList<Proceso>c){
System.out.println("=================================================");
System.out.println("|| proceso || TiempoRes || estado || prioridad ||");
System.out.println("=================================================");
for(int i=0;i<c.size();i++){
System.out.println(c.get(i).toString());
}
System.out.println("=================================================");
}
public static void imprimirEspecificacionesGenerales(ArrayList<Proceso> c, int tipoPlanificacion, int tipoAlgoritmo, int nProcesos){
int total = 0;
for(int i=0;i<c.size();i++){
total += c.get(i).getBoletos();
}
System.out.println("**************************************************");
System.out.println("************ESPECIFICACIONES GENERALES************");
if(tipoPlanificacion == 1){
System.out.println("tipo planificacion: APROPIATIVO");
}else{
System.out.println("tipo planificacion: NO APROPIATIVO");
}
switch (tipoAlgoritmo) {
case 1:
System.out.println("tipo planificacion: Round-Robin");
break;
case 2:
System.out.println("tipo planificacion: Prioridades");
break;
case 3:
System.out.println("tipo planificacion: Múltiples colas de prioridad");
break;
case 4:
System.out.println("tipo planificacion: Proceso más corto primero");
break;
case 5:
System.out.println("tipo planificacion: Planificacion Garantizada");
break;
case 6:
System.out.println("tipo planificacion: Boletos de loteria");
break;
case 7:
System.out.println("tipo planificacion: Participacion equitativa");
break;
}
System.out.println("tipo algoritmo: "+tipoAlgoritmo);
System.out.println("quantum: "+quantum);
System.out.println("prioridad:");
if((tipoAlgoritmo == 1 ) || (tipoAlgoritmo == 2 ) || (tipoAlgoritmo == 4 ) || (tipoAlgoritmo == 6 )){
System.out.println("No. Usuarios:"+ 1);
}else if(tipoAlgoritmo == 3){
System.out.println("No. Usuarios:"+ 4);
}else{ // 5 - Planificacion Garantizada, 7 - Participacion Equitativa
System.out.println("No. Usuarios:"+ nUsuarios);
}
System.out.println("No. Procesos:"+ nProcesos);
if(tipoAlgoritmo == 6){
System.out.println("boletos:" + total);
}
System.out.println("**************************************************");
}
public static void recoridoDeParticiones(ArrayList<Proceso> c, int tipoPlanificacion, int nCantidad){
int cpuPorProceso = tiempoM / nCantidad;
if(tipoPlanificacion==1/*Apropiativo */){
//con cada iteracion entra un proceso nuevo.
for(int i=0;i<c.size();i++){
if(cpuPorProceso<=0){break;}
r.setD(1);
System.out.print(". Entra Proceso "+c.get(i).getId()+" ");
//se verifica que el proceso este listo
if(c.get(i).getEstado()!=2){
//si el proceso aun no esta listo se genera un random para saber si se desbloqueo
c.get(i).setEstado(random.nextInt(2)+1);
}
if(c.get(i).getEstado()==2){
//si el proceso esta listo se resta el valor del quantum al tiempo restante
c.get(i).setTiempoR(c.get(i).getTiempoR()-c.get(i).getQuantum());
cpuPorProceso-=c.get(i).getQuantum();
if(cpuPorProceso<=0){
c.get(i).setTiempoR(c.get(i).getTiempoR()-cpuPorProceso);
cpuPorProceso=0;
}
if(c.get(i).getTiempoR()<=0/*El proceso termino*/){
r.setA(c.get(i).getId());
System.out.print(", se ejecuta "+(c.get(i).getQuantum()+c.get(i).getTiempoR())+" unidades y termina\n");
cpuPorProceso-=c.get(i).getTiempoR();/*si el proceso termino el tiempo de simulacion se le suma el resto del tiempo restante*/
c.remove(i);/*se remueve el proceso de la lista*/
i--;
}else{
System.out.print(", se ejecuta "+c.get(i).getQuantum()+" unidades\n");
c.get(i).setQuantum(c.get(i).getQuantum()*2);/*Si el proceso no termino el quantum se dobla*/
}
}else{
System.out.print(", no se ejcuta porque sigue bloqueado \n");/*el proceso nu uso la CPU */
}
if(i==c.size()-1){i=-1;}
}
}else{/*No Apropiativo */
int x=0;
int xaux=0;
for(int i=0;i<c.size();i++){
if(cpuPorProceso<=0){break;}
r.setD(1);
System.out.print(". Entra Proceso "+c.get(i).getId()+" ");
//se verifica que el proceso este listo
if(c.get(i).getEstado()!=2){
//si el proceso aun no esta listo se genera un random para saber si se desbloqueo
c.get(i).setEstado(random.nextInt(2)+1);
}
if(c.get(i).getEstado()==2){
//si el proceso esta listo se resta el valor un valor aleatorio al tiempo restante
for(int j=0;j<200;j++){
x=random.nextInt(3)+2;
xaux+=x;
c.get(i).setTiempoR(c.get(i).getTiempoR()-x);
cpuPorProceso-=x;
if(cpuPorProceso<=0){
c.get(i).setTiempoR(c.get(i).getTiempoR()-cpuPorProceso);
xaux+=cpuPorProceso;
cpuPorProceso=0;
}
if(cpuPorProceso<=0){
c.get(i).setTiempoR(c.get(i).getTiempoR()-cpuPorProceso);
xaux+=cpuPorProceso;
cpuPorProceso=0;
}
if(c.get(i).getTiempoR()<=0/*El proceso termino*/){
xaux+=c.get(i).getTiempoR();
break;
}
c.get(i).setEstado(random.nextInt(2)+1);
if(c.get(i).getEstado()!=2){
c.get(i).setEstado(random.nextInt(2)+1);
break;
}
}
if(c.get(i).getTiempoR()<=0/*El proceso termino*/){
System.out.print(", se ejecuta "+xaux+" unidades y termina\n");
r.setA(c.get(i).getId());
cpuPorProceso=cpuPorProceso-c.get(i).getTiempoR();/*si el proceso termino el tiempo de simulacion se le suma el resto del tiempo restante*/
c.remove(i);/*se remueve el proceso de la lista*/
i--;
}else{
System.out.print(", se ejecuta "+xaux+" unidades\n");
/*Si el proceso no termino*/
}
}else{System.out.print(", no se ejcuta porque sigue bloqueado \n");/*el proceso nu uso la CPU */}
x=0;
xaux=0;
if(i==c.size()-1){i=-1;}
}
}
}
}