Last active
May 23, 2021 04:04
-
-
Save ThomRoman/78881c24bb2a61893cec96f9619e108c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == "__main__": | |
numeroDeProcesos = int(input("Digite el numero de procesos : ")) | |
print("\n") | |
arrProcesos = [] | |
arrTemporalProcesos = [] | |
for i in range(numeroDeProcesos): | |
tiempoLlegada = int(input("Ingrese el tiempo de llegada : ")) | |
tiempoRafaga = int(input("Ingrese el tiempo de rafaga : ")) | |
print("\n") | |
process = (i+1) | |
arrProcesos.append([process,tiempoLlegada,tiempoRafaga]) | |
arrTemporalProcesos.append([process,tiempoLlegada,tiempoRafaga]) | |
# Ordenar por el tiempo de rafaga y luego el tiempo de llegada | |
newIndex = 0 | |
if arrProcesos[0][1] == 0 : | |
newIndex = 1 | |
# rafaga | |
for mainIndex in range(newIndex,len(arrProcesos)) : | |
for secIndex in range(newIndex,len(arrProcesos)-1) : | |
if arrTemporalProcesos[secIndex][2]>arrTemporalProcesos[secIndex+1][2] : | |
arrTemporalProcesos[secIndex],arrTemporalProcesos[secIndex+1]=arrTemporalProcesos[secIndex+1],arrTemporalProcesos[secIndex] | |
# llegada | |
index = newIndex | |
indexTemporal = newIndex | |
repetidas = 1 | |
while((index+1) <= len(arrTemporalProcesos) ): | |
if(indexTemporal+1<len(arrTemporalProcesos) and arrTemporalProcesos[indexTemporal][2]==arrTemporalProcesos[indexTemporal+1][2]): | |
repetidas+=1 | |
indexTemporal+=1 | |
continue | |
index = indexTemporal - repetidas + 1 | |
if repetidas >= 2 : | |
for i in range(index,indexTemporal+1): | |
j=i | |
while (j>index and arrTemporalProcesos[j-1][1]>arrTemporalProcesos[j][1]): | |
arrTemporalProcesos[j],arrTemporalProcesos[j-1]=arrTemporalProcesos[j-1],arrTemporalProcesos[j] | |
j-=1 | |
repetidas = 1 | |
index = indexTemporal + 1 | |
indexTemporal = index | |
print("Procesos inicial ",arrProcesos) | |
print("Procesos ordenados",arrTemporalProcesos) | |
print("\n") | |
tiempoEspera = 0 | |
tiempoRespuesta = 0 | |
SumatoriaTiempoEspera = 0 | |
SumatoriaTiempoRespuesta = 0 | |
for i in range(len(arrTemporalProcesos)) : | |
if i == 0 : | |
tiempoEspera = 0 - 0 | |
tiempoRespuesta += 0 + arrTemporalProcesos[i][2] | |
else : | |
tiempoEspera=tiempoRespuesta - arrTemporalProcesos[i][1] | |
tiempoRespuesta += arrTemporalProcesos[i][2] | |
SumatoriaTiempoRespuesta+=tiempoRespuesta | |
SumatoriaTiempoEspera+=tiempoEspera | |
print("Tiempo Promedio de Espera",(SumatoriaTiempoEspera/len(arrTemporalProcesos))) | |
print("Tiempo Promedio de Respuesta", (SumatoriaTiempoRespuesta/len(arrTemporalProcesos))) | |
""" | |
proc = [ | |
[1, 0,25], | |
[2, 1,25], | |
[3, 4,2], | |
[4, 1,25], | |
[4, 2,2] | |
] | |
n = 5 | |
0 47 | |
4 37 | |
2 33 | |
4 37 | |
5 31 | |
2 33 | |
0 25 | |
4 10 | |
3 10 | |
2 4 | |
1 4 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment