import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import math
import random
#import scipy.stats as st
file0 = open("valores_teoricos.txt","r")
file1 = open("log_1.txt","r")
file2 = open("log_2.txt","r")
file3 = open("log_3.txt","r")
file4 = open("log_4.txt","r")
f0_dat = file0.readlines()
datos_f0 = []
for i in f0_dat:
a = i.split(',')
del a[-1]
a = map(float, a)
datos_f0.append(a)
f1_dat = file1.readlines()
datos_f1 = []
for i in f1_dat:
a = i.split(',')
del a[-1]
a = map(float, a)
datos_f1.append(a)
f2_dat = file2.readlines()
datos_f2 = []
for i in f2_dat:
a = i.split(',')
del a[-1]
a = map(float, a)
datos_f2.append(a)
f3_dat = file3.readlines()
datos_f3 = []
for i in f3_dat:
a = i.split(',')
del a[-1]
a = map(float, a)
datos_f3.append(a)
f4_dat = file4.readlines()
datos_f4 = []
for i in f4_dat:
a = i.split(',')
del a[-1]
a = map(float, a)
datos_f4.append(a)
t = [] #tiempo
x1 = [] #lista tiempo
y1 = [] #largo cola
n1 = [] #cantidad procesados
f1 = [] #fila media entre mediciones (Lq)
r1 = [] #numero medio clientes en servicio (Ls)
e1 = [] #espera fila (wq)
a1 = [] #tiempo atencion en servidor (ws)
o1 = [] #ocupacion media servidores
l1 = [] #numero medio clientes en sistema (L)
x2 = []
y2 = []
n2 = []
f2 = []
r2 = []
e2 = []
a2 = []
o2 = []
l2 = []
x3 = []
y3 = []
n3 = []
f3 = []
r3 = []
e3 = []
a3 = []
o3 = []
l3 = []
x4 = []
y4 = []
n4 = []
f4 = []
r4 = []
e4 = []
a4 = []
o4 = []
l4 = []
y_t = []
f_t = []
r_t = []
e_t = []
a_t = []
l_t = []
x1_prom = []
y1_prom = []
n1_prom = []
f1_prom = []
r1_prom = []
e1_prom = []
a1_prom = []
o1_prom = []
l1_prom = []
x2_prom = []
y2_prom = []
n2_prom = []
f2_prom = []
r2_prom = []
e2_prom = []
a2_prom = []
o2_prom = []
l2_prom = []
x3_prom = []
y3_prom = []
n3_prom = []
f3_prom = []
r3_prom = []
e3_prom = []
a3_prom = []
o3_prom = []
l3_prom = []
x4_prom = []
y4_prom = []
n4_prom = []
f4_prom = []
r4_prom = []
e4_prom = []
a4_prom = []
o4_prom = []
l4_prom = []
y_prom_total = []
f_prom_total = []
r_prom_total = []
e_prom_total = []
a_prom_total = []
l_prom_total = []
y_desv = []
f_desv = []
r_desv = []
e_desv = []
a_desv = []
l_desv = []
lamda = datos_f0[0][1]
mu = datos_f0[0][2]
rho = datos_f0[0][3]
wq = datos_f0[0][4]
ws = datos_f0[0][5]
Lq = datos_f0[0][6]
Ls = datos_f0[0][7]
max_tiempo = min(datos_f1[-1][1],datos_f2[-1][1],datos_f3[-1][1],datos_f4[-1][1])
ventana = 10 # ventana de 10 unidades de tiempo
t = range(0, int(math.floor(max_tiempo)), ventana)
for j in range(len(datos_f1)):
x1.append(datos_f1[j][1])
y1.append(datos_f1[j][2])
n1.append(datos_f1[j][0])
a1.append(datos_f1[j][5])
e1.append(datos_f1[j][4])
f1.append(datos_f1[j][6])
r1.append(datos_f1[j][7])
l1.append(datos_f1[j][6]+datos_f1[j][7])
for j in range(len(datos_f2)):
x2.append(datos_f2[j][1])
y2.append(datos_f2[j][2])
n2.append(datos_f2[j][0])
a2.append(datos_f2[j][5])
e2.append(datos_f2[j][4])
f2.append(datos_f2[j][6])
r2.append(datos_f2[j][7])
l2.append(datos_f2[j][6]+datos_f2[j][7])
for j in range(len(datos_f3)):
x3.append(datos_f3[j][1])
y3.append(datos_f3[j][2])
n3.append(datos_f3[j][0])
a3.append(datos_f3[j][5])
e3.append(datos_f3[j][4])
f3.append(datos_f3[j][6])
r3.append(datos_f3[j][7])
l3.append(datos_f3[j][6]+datos_f3[j][7])
for j in range(len(datos_f4)):
x4.append(datos_f4[j][1])
y4.append(datos_f4[j][2])
n4.append(datos_f4[j][0])
a4.append(datos_f4[j][5])
e4.append(datos_f4[j][4])
f4.append(datos_f4[j][6])
r4.append(datos_f4[j][7])
l4.append(datos_f4[j][6]+datos_f4[j][7])
j=0
for i in range(len(y1)):
if j == len(t)-1: # para que no intente acceder a t[len(t)] que no existe
break
if x1[i] < t[j+1]:
y_t.append(y1[i])
f_t.append(f1[i])
r_t.append(r1[i])
e_t.append(e1[i])
a_t.append(a1[i])
l_t.append(l1[i])
else:
y1_prom.append(np.mean(y_t))
f1_prom.append(np.mean(f_t))
r1_prom.append(np.mean(r_t))
e1_prom.append(np.mean(e_t))
a1_prom.append(np.mean(a_t))
l1_prom.append(np.mean(l_t))
j=j+1
del y_t[:]
del f_t[:]
del r_t[:]
del e_t[:]
del a_t[:]
del l_t[:]
y_t.append(y1[i])
f_t.append(f1[i])
r_t.append(r1[i])
e_t.append(e1[i])
a_t.append(a1[i])
l_t.append(l1[i])
del y_t[:]
del f_t[:]
del r_t[:]
del e_t[:]
del a_t[:]
del l_t[:]
j=0
for i in range(len(y2)):
if j == len(t)-1:
break
if x2[i] < t[j+1]:
y_t.append(y2[i])
f_t.append(f2[i])
r_t.append(r2[i])
e_t.append(e2[i])
a_t.append(a2[i])
l_t.append(l2[i])
else:
y2_prom.append(np.mean(y_t))
f2_prom.append(np.mean(f_t))
r2_prom.append(np.mean(r_t))
e2_prom.append(np.mean(e_t))
a2_prom.append(np.mean(a_t))
l2_prom.append(np.mean(l_t))
j=j+1
del y_t[:]
del f_t[:]
del r_t[:]
del e_t[:]
del a_t[:]
del l_t[:]
y_t.append(y2[i])
f_t.append(f2[i])
r_t.append(r2[i])
e_t.append(e2[i])
a_t.append(a2[i])
l_t.append(l2[i])
del y_t[:]
del f_t[:]
del r_t[:]
del e_t[:]
del a_t[:]
del l_t[:]
j=0
for i in range(len(y3)):
if j == len(t)-1:
break
if x3[i] < t[j+1]:
y_t.append(y3[i])
f_t.append(f3[i])
r_t.append(r3[i])
e_t.append(e3[i])
a_t.append(a3[i])
l_t.append(l3[i])
else:
y3_prom.append(np.mean(y_t))
f3_prom.append(np.mean(f_t))
r3_prom.append(np.mean(r_t))
e3_prom.append(np.mean(e_t))
a3_prom.append(np.mean(a_t))
l3_prom.append(np.mean(l_t))
j=j+1
del y_t[:]
del f_t[:]
del r_t[:]
del e_t[:]
del a_t[:]
del l_t[:]
y_t.append(y3[i])
f_t.append(f3[i])
r_t.append(r3[i])
e_t.append(e3[i])
a_t.append(a3[i])
l_t.append(l3[i])
del y_t[:]
del f_t[:]
del r_t[:]
del e_t[:]
del a_t[:]
del l_t[:]
j=0
for i in range(len(y4)):
if j == len(t)-1:
break
if x4[i] < t[j+1]:
y_t.append(y4[i])
f_t.append(f4[i])
r_t.append(r4[i])
e_t.append(e4[i])
a_t.append(a4[i])
l_t.append(l4[i])
else:
y4_prom.append(np.mean(y_t))
f4_prom.append(np.mean(f_t))
r4_prom.append(np.mean(r_t))
e4_prom.append(np.mean(e_t))
a4_prom.append(np.mean(a_t))
l4_prom.append(np.mean(l_t))
j=j+1
del y_t[:]
del f_t[:]
del r_t[:]
del e_t[:]
del a_t[:]
del l_t[:]
y_t.append(y4[i])
f_t.append(f4[i])
r_t.append(r4[i])
e_t.append(e4[i])
a_t.append(a4[i])
l_t.append(l4[i])
for k in range(len(y1_prom)):
y_prom_total.append(np.mean([y1_prom[k], y2_prom[k], y3_prom[k], y4_prom[k]]))
f_prom_total.append(np.mean([f1_prom[k], f2_prom[k], f3_prom[k], f4_prom[k]]))
r_prom_total.append(np.mean([r1_prom[k], r2_prom[k], r3_prom[k], r4_prom[k]]))
e_prom_total.append(np.mean([e1_prom[k], e2_prom[k], e3_prom[k], e4_prom[k]]))
a_prom_total.append(np.mean([a1_prom[k], a2_prom[k], a3_prom[k], a4_prom[k]]))
l_prom_total.append(np.mean([l1_prom[k], l2_prom[k], l3_prom[k], l4_prom[k]]))
del t[-1] # hacer que len(t)==len(_prom_total) para poder graficar
line, = plt.plot(t, y_prom_total, 'g-', linewidth=1)
plt.xlabel('Tiempo')
plt.ylabel('Largo fila')
plt.title(r'Evolucion temporal del largo de la fila con $\lambda={}$, $\mu={}$')
plt.figure()
line, = plt.plot(t, f_prom_total, 'g-', linewidth=1)
plt.plot(t, [Lq] * len(t), 'r--')
plt.xlabel('Tiempo')
plt.ylabel('Largo fila promedio')
plt.title(r'Largo promedio de la fila por unidad de tiempo (Lq) con $\lambda={}$, $\mu={}$')
plt.figure()
line, = plt.plot(t, l_prom_total, 'g-', linewidth=1)
plt.plot(t, [(Lq+Ls)] * len(t), 'r--')
plt.xlabel('Tiempo')
plt.ylabel('Clientes')
plt.title(r'Numero medio de clientes en el sistema (L) con $\lambda={}$, $\mu={}$')
plt.figure()
line, = plt.plot(t, a_prom_total, 'g-', linewidth=1)
plt.plot(t, [ws] * len(t), 'r--')
plt.xlabel('Tiempo')
plt.ylabel('Tiempo atencion')
plt.title(r'Tiempo medio de atencion de un cliente en servidor (ws) con $\lambda={}$, $\mu={}$')
plt.figure()
line, = plt.plot(t, r_prom_total, 'g-', linewidth=1)
plt.plot(t, [Ls] * len(t), 'r--')
plt.xlabel('Tiempo')
plt.ylabel('Clientes')
plt.title(r'Numero medio de clientes en atencion (Ls) con $\lambda={}$, $\mu={}$')
plt.figure()
#line, = plt.plot(x, o, '-', linewidth=1)
#plt.xlabel('Tiempo')
#plt.ylabel('% ocupacion')
#plt.title(r'Ocupacion media de los servidores')
#plt.figure()
line, = plt.plot(t, e_prom_total, 'g-', linewidth=1)
plt.plot(t, [wq] * len(t), 'r--')
plt.xlabel('Tiempo')
plt.ylabel('Tiempo espera en fila')
plt.title(r'Tiempo de espera en la fila para cada llegada (wq) con $\lambda={}$, $\mu={}$')
#plt.figure()
plt.show()
file0.close()
file1.close()
file2.close()
file3.close()
file4.close()