def stability_check(arr: Arrival,
                    ser: Server,
                    theta: float,
                    indep=True,
                    p=1.0,
                    q=1.0) -> None:
    if indep:
        # if (arr.rho(theta=theta) < 0 or ser.rho(theta=theta) < 0
        #         or arr.sigma(theta=theta) < 0 or ser.sigma(theta=theta) < 0):
        #     raise ParameterOutOfBounds("parameters must be positive")

        if arr.rho(theta=theta) >= ser.rho(theta=theta):
            raise ParameterOutOfBounds(
                f"The arrivals' rho={arr.rho(theta=theta)} has to be "
                f"smaller than the service's rho={ser.rho(theta=theta)}")
    else:
        # if (arr.rho(theta=p * theta) < 0 or ser.rho(theta=q * theta) < 0
        #         or arr.sigma(theta=p * theta) < 0
        #         or ser.sigma(theta=q * theta) < 0):
        #     raise ParameterOutOfBounds("parameters must be positive")

        if arr.rho(theta=p * theta) >= ser.rho(theta=q * theta):
            raise ParameterOutOfBounds(
                f"The arrivals' rho={arr.rho(theta=p * theta)} has to be "
                f"smaller than the service's rho={ser.rho(theta=q * theta)}")
Exemple #2
0
def output_power_mit(arr: Arrival,
                     ser: Server,
                     theta: float,
                     delta_time: int,
                     l_power=1.0) -> float:
    """Implements stationary standard_bound method"""
    if l_power < 1.0:
        l_power = 1.0
        # raise ParameterOutOfBounds("l must be >= 1")

    l_theta = l_power * theta

    stability_check(arr=arr, ser=ser, theta=l_theta, indep=True)
    sigma_l_sum, rho_l_diff = get_sigma_rho(arr=arr,
                                            ser=ser,
                                            theta=l_theta,
                                            indep=True)

    if arr.is_discrete():
        numerator = exp(theta * arr.rho(theta=l_theta) * delta_time) * exp(
            theta * sigma_l_sum)

    else:
        numerator = exp(theta * arr.rho(theta=l_theta) *
                        (delta_time + 1)) * exp(theta * sigma_l_sum)

    denominator = (1 - exp(l_theta * rho_l_diff))**(1 / l_power)

    try:
        return numerator / denominator

    except ZeroDivisionError:
        return inf
def delay_prob_power(arr: Arrival,
                     ser: Service,
                     theta: float,
                     delay: int,
                     l_power=1.0) -> float:
    """Implements stationary bound method"""
    if l_power < 1.0:
        l_power = 1.0
        # raise ParameterOutOfBounds("l must be >= 1")

    l_theta = l_power * theta

    if arr.rho(theta=l_theta) >= ser.rho(theta=l_theta):
        raise ParameterOutOfBounds(
            f"The arrivals' rho {arr.rho(theta)} has to be smaller than"
            f"the service's rho {ser.rho(theta)}")

    sigma_l_arr_ser = arr.sigma(theta=l_theta) + ser.sigma(theta=l_theta)
    rho_l_arr_ser = arr.rho(theta=l_theta) - ser.rho(theta=l_theta)

    numerator = exp(theta * ser.rho(theta=l_theta) * delay) * exp(
        theta * sigma_l_arr_ser)
    denominator = (1 - exp(l_theta * rho_l_arr_ser))**(1 / l_power)

    try:
        return numerator / denominator

    except ZeroDivisionError:
        return inf
Exemple #4
0
def output(arr: Arrival,
           ser: Server,
           theta: float,
           delta_time: int,
           indep=True,
           p=1.0) -> float:
    """Implements stationary standard_bound method"""
    if indep:
        p = 1.0
        q = 1.0
    else:
        q = get_q(p=p)

    stability_check(arr=arr, ser=ser, theta=theta, indep=indep, p=p, q=q)
    sigma_sum, rho_diff = get_sigma_rho(arr=arr,
                                        ser=ser,
                                        theta=theta,
                                        indep=indep,
                                        p=p,
                                        q=q)

    try:
        if arr.is_discrete():
            return exp(theta * arr.rho(theta=p * theta) * delta_time) * exp(
                theta * sigma_sum) / (1 - exp(theta * rho_diff))

        else:
            return exp(theta * arr.rho(theta=p * theta) *
                       (delta_time + 1)) * exp(
                           theta * sigma_sum) / (1 - exp(theta * rho_diff))

    except ZeroDivisionError:
        return inf
Exemple #5
0
def backlog(arr: Arrival,
            ser: Service,
            theta: float,
            prob_b: float,
            tau=1.0,
            indep=True,
            p=1.0) -> float:
    """Implements stationary bound method"""
    if indep:
        p = 1.0

    q = get_q(p=p, indep=indep)

    rho_a_p = arr.rho(theta=p * theta)
    sigma_a_p = arr.sigma(theta=p * theta)
    rho_s_q = ser.rho(theta=q * theta)
    sigma_s_q = ser.sigma(theta=q * theta)

    if rho_a_p >= rho_s_q:
        raise ParameterOutOfBounds(
            f"The arrivals' rho {rho_a_p} has to be smaller than"
            f"the service's rho {rho_s_q}")

    rho_arr_ser = rho_a_p - rho_s_q
    sigma_arr_ser = sigma_a_p + sigma_s_q

    if arr.is_discrete():
        log_part = log(prob_b * (1 - exp(theta * rho_arr_ser)))

        return sigma_arr_ser - log_part / theta

    else:
        log_part = log(prob_b * (1 - exp(theta * tau * rho_arr_ser)))

        return tau * rho_a_p + sigma_arr_ser - log_part / theta
def get_sigma_rho(arr: Arrival,
                  ser: Server,
                  theta: float,
                  indep=True,
                  p=1.0,
                  q=1.0) -> (float, float):
    if indep:
        return arr.sigma(theta=theta) + ser.sigma(theta=theta), arr.rho(
            theta=theta) - ser.rho(theta=theta)

    else:
        return arr.sigma(theta=p * theta) + ser.sigma(
            theta=q * theta), arr.rho(theta=p * theta) - ser.rho(theta=q *
                                                                 theta)
Exemple #7
0
def delay_prob(arr: Arrival,
               ser: Server,
               theta: float,
               delay_value: int,
               indep=True,
               p=1.0,
               geom_series=False) -> float:
    """Implements stationary standard_bound method"""
    if indep:
        p = 1.0
        q = 1.0
    else:
        q = get_q(p=p)

    stability_check(arr=arr, ser=ser, theta=theta, indep=indep, p=p, q=q)
    sigma_sum, rho_diff = get_sigma_rho(arr=arr,
                                        ser=ser,
                                        theta=theta,
                                        indep=indep,
                                        p=p,
                                        q=q)

    try:
        if not geom_series:
            if arr.is_discrete():
                return exp(
                    -theta * ser.rho(theta=q * theta) * delay_value) * exp(
                        theta * sigma_sum) / (-rho_diff * theta)
            else:
                tau_opt = 1 / (theta * ser.rho(theta=q * theta))
                return exp(
                    -theta * ser.rho(theta=q * theta) * delay_value) * exp(
                        theta *
                        (ser.rho(theta=q * theta) * tau_opt + sigma_sum)) / (
                            -rho_diff * theta * tau_opt)

        if arr.is_discrete():
            return exp(-theta * ser.rho(theta=q * theta) * delay_value) * exp(
                theta * sigma_sum) / (1 - exp(theta * rho_diff))
        else:
            tau_opt = log(arr.rho(theta=p * theta) /
                          ser.rho(theta=q * theta)) / (theta * rho_diff)
            return exp(-theta * ser.rho(theta=q * theta) * delay_value) * exp(
                theta * (arr.rho(theta=p * theta) * tau_opt + sigma_sum)) / (
                    1 - exp(theta * tau_opt * rho_diff))

    except ZeroDivisionError:
        return inf
Exemple #8
0
def delay_prob_power_mit(arr: Arrival,
                         ser: Server,
                         theta: float,
                         delay: int,
                         l_power=1.0) -> float:
    """Implements stationary standard_bound method"""
    if l_power < 1.0:
        l_power = 1.0
        # raise ParameterOutOfBounds("l must be >= 1")

    l_theta = l_power * theta

    stability_check(arr=arr, ser=ser, theta=l_theta, indep=True)
    sigma_l_sum, rho_l_diff = get_sigma_rho(arr=arr,
                                            ser=ser,
                                            theta=l_theta,
                                            indep=True)

    if not arr.is_discrete():
        warn("discretized version is not implemented")

    numerator = exp(-theta * ser.rho(theta=l_theta) * delay) * exp(
        theta * sigma_l_sum)
    denominator = (1 - exp(l_theta * rho_l_diff))**(1 / l_power)

    try:
        return numerator / denominator

    except ZeroDivisionError:
        return inf
Exemple #9
0
def delay(arr: Arrival,
          ser: Server,
          theta: float,
          prob_d: float,
          indep=True,
          p=1.0,
          geom_series=False) -> float:
    """Implements stationary standard_bound method"""
    if prob_d < 0.0 or prob_d > 1.0:
        raise IllegalArgumentError(f"prob_b={prob_d} must be in (0,1)")

    if indep:
        p = 1.0
        q = 1.0
    else:
        q = get_q(p=p)

    stability_check(arr=arr, ser=ser, theta=theta, indep=indep, p=p, q=q)
    sigma_sum, rho_diff = get_sigma_rho(arr=arr,
                                        ser=ser,
                                        theta=theta,
                                        indep=indep,
                                        p=p,
                                        q=q)

    if not geom_series:
        if arr.is_discrete():
            log_part = log(prob_d * theta * (-rho_diff))
            return (sigma_sum - log_part / theta) / ser.rho(theta=q * theta)
        else:
            tau_opt = 1 / (theta * ser.rho(theta=q * theta))
            log_part = log(prob_d * theta * tau_opt * (-rho_diff))
            return (tau_opt * ser.rho(theta=q * theta) + sigma_sum -
                    log_part / theta) / ser.rho(theta=q * theta)

    if arr.is_discrete():
        log_part = log(prob_d * (1 - exp(theta * rho_diff)))
        return (sigma_sum - log_part / theta) / ser.rho(theta=q * theta)
    else:
        tau_opt = log(arr.rho(theta=p * theta) /
                      ser.rho(theta=q * theta)) / (theta * rho_diff)
        log_part = log(prob_d * (1 - exp(theta * tau_opt * rho_diff)))
        return (tau_opt * arr.rho(theta=p * theta) + sigma_sum -
                log_part / theta) / ser.rho(theta=q * theta)
Exemple #10
0
def backlog_prob(arr: Arrival,
                 ser: Service,
                 theta: float,
                 backlog_value: float,
                 tau=1.0,
                 indep=True,
                 p=1.0) -> float:
    """Implements stationary bound method"""
    if indep:
        p = 1.0

    q = get_q(p=p, indep=indep)

    rho_a_p = arr.rho(theta=p * theta)
    sigma_a_p = arr.sigma(theta=p * theta)
    rho_s_q = ser.rho(theta=q * theta)
    sigma_s_q = ser.sigma(theta=q * theta)

    if rho_a_p >= rho_s_q:
        raise ParameterOutOfBounds(
            f"The arrivals' rho {rho_a_p} has to be smaller than"
            f"the service's rho {rho_s_q}")

    rho_arr_ser = rho_a_p - rho_s_q
    sigma_arr_ser = sigma_a_p + sigma_s_q

    try:
        if arr.is_discrete():
            return exp(-theta * backlog_value) * exp(
                theta * sigma_arr_ser) / (1 - exp(theta * rho_arr_ser))

        else:
            return exp(-theta * backlog_value) * exp(
                theta * (rho_a_p * tau + sigma_arr_ser)) / (
                    1 - exp(theta * tau * rho_arr_ser))

    except ZeroDivisionError:
        return inf