from math import factorial, floor

def multicanal(lam, mu, k):
    """Características operativas M/M/k con las fórmulas del EC2."""
    if lam >= k * mu:
        return None  # sistema inestable
    r = lam / mu
    suma = sum(r**n / factorial(n) for n in range(k))
    termino_k = (r**k / factorial(k)) * (k * mu / (k * mu - lam))
    Po = 1 / (suma + termino_k)
    Lq = (r**k * lam * mu) / (factorial(k - 1) * (k * mu - lam)**2) * Po
    L = Lq + r
    Wq = Lq / lam
    W = Wq + 1 / mu
    Pw = termino_k * Po
    return {"Po": Po, "Lq": Lq, "L": L, "Wq": Wq, "W": W, "Pw": Pw}

# ---------- Datos del ejemplo (entidad pensional) ----------
lam = 1.85   # llegadas por unidad de tiempo
mu = 2       # atenciones por servidor por unidad de tiempo
k = 3        # servidores iniciales
a_minutos = 1   # factor para Wq y W: 1 si las tasas ya son por minuto,
                # 60 si las tasas son por hora (Wq sale en horas)

# ---------- Tabla k vs k+1 ----------
nombres = ["Po", "Lq", "L", "Wq", "W", "Pw"]
resultados = {kk: multicanal(lam, mu, kk) for kk in (k, k + 1)}

print(f"{'Medida':<8}{'k=' + str(k):>12}{'k=' + str(k + 1):>12}")
for n in nombres:
    fila = []
    for kk in (k, k + 1):
        r = resultados[kk]
        if r is None:
            fila.append("inestable")
            continue
        v = r[n] * (a_minutos if n in ("Wq", "W") else 1)
        fila.append(f"{v:.4f}")
    print(f"{n:<8}{fila[0]:>12}{fila[1]:>12}")

# ---------- Estabilidad ----------
k_min = floor(lam / mu) + 1   # menor k con lam < k*mu
print(f"\nλ/μ = {lam/mu:.3f}")
print(f"Estable solo si k > λ/μ, es decir k >= {k_min}.")
if k_min > 1:
    print(f"Con k <= {k_min - 1} la fila crece sin parar (λ >= k·μ).")
else:
    print("Con λ/μ < 1 el sistema es estable desde k = 1.")

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: