Exemplo n.º 1
0
def example1(policy_id):
    params = Params(
        mu=3,
        lambda1=4,
        lambda2=4,
        servers_number=5,
        fragments_numbers=[2, 3],
        queues_capacities=[3, 3],
    )

    all_states = get_all_states(params)
    states_with_policy = get_policed_states(all_states, params)
    policies = get_all_possible_policies(states_with_policy)
    # print("All possible policies number: ", len(policies))

    selected_policy_vector = None
    for idx, p in enumerate(policies):
        selected_policy_vector = p
        if idx == policy_id:
            break

    print("Current policy:")
    policy = Policy(selected_policy_vector, states_with_policy, params)
    for state in states_with_policy:
        print(
            f"    state = {state}, action = {policy.get_action_for_state(state)}"
        )

    calculations = Calculations(params)
    calculations.calculate(policy)
    performance_measures = calculations.performance_measures
    print(performance_measures, "\n")
Exemplo n.º 2
0
def example3(queue_id):
    params = Params(
        mu=3,
        lambda1=4,
        lambda2=4,
        servers_number=6,
        fragments_numbers=[3, 2],
        queues_capacities=[3, 3],
    )

    all_states = get_all_states(params)
    states_with_policy = get_policed_states(all_states, params)

    selected_policy_vector = [queue_id] * len(states_with_policy)

    print("Current policy:")
    policy = Policy(selected_policy_vector, states_with_policy, params)
    for state in states_with_policy:
        print(
            f"    state = {state}, action = {policy.get_action_for_state(state)}"
        )

    calculations = Calculations(params)
    calculations.calculate(policy)
    performance_measures = calculations.performance_measures
    print(performance_measures, "\n")
def get_performance_measures(params):
    calculations = Calculations(params)
    strategy = (0, 0, 0, 0)
    all_states = calculations.get_all_states()
    states_with_policy = get_policed_states(all_states, params)
    states_policy = StatesPolicy(strategy, states_with_policy, params)
    calculations.calculate(states_policy)
    print(calculations.performance_measures)
    return calculations.performance_measures
Exemplo n.º 4
0
def example2():
    params = Params(
        mu=3,
        lambda1=5,
        lambda2=5,
        servers_number=6,
        fragments_numbers=[3, 2],
        queues_capacities=[1, 1],
    )

    all_states = get_all_states(params)
    states_with_policy = get_policed_states(all_states, params)
    print("All states where policy is possible:")
    pprint(states_with_policy)

    strategies = get_all_possible_policies(states_with_policy)
    states_policy = Policy(tuple(), states_with_policy, params)
    states_policy.print_adjacent_states()

    storage = PerformanceMeasuresStorage()
    print()

    for strategy in strategies:
        states_policy.policy_vector = strategy
        print(strategy)
        calculations = Calculations(params)
        calculations.calculate(states_policy)
        performance_measures = calculations.performance_measures
        print(performance_measures, "\n")

        storage.append(strategy, performance_measures)

    print(storage)
    print()
    storage.show_difference()

    print("executed")
Exemplo n.º 5
0
    params = Params(mu=3,
                    lambda1=.5,
                    lambda2=1,
                    servers_number=4,
                    fragments_numbers=[3, 2],
                    queues_capacities=[10, 30])

    print("Dependence on the arrival flow rates:")
    rate_dep = RateDependency()

    for i, lam1 in enumerate(rate_dep.lambdas):
        for j, lam2 in enumerate(rate_dep.lambdas):
            params.lambda1 = lam1
            params.lambda2 = lam2
            calculations = Calculations(params)
            calculations.calculate(strategy)

            print(
                f"measures for {calculations} \n{calculations.performance_measures}"
            )

            rate_dep.response_time[
                i, j] = calculations.performance_measures.response_time
            rate_dep.response_time1[
                i, j] = calculations.performance_measures.response_time1
            rate_dep.response_time2[
                i, j] = calculations.performance_measures.response_time2

            rate_dep.failure_prob[
                i, j] = calculations.performance_measures.failure_probability
            rate_dep.failure_prob1[
Exemplo n.º 6
0
def example1(lambdas, queue_id):
    storage = PerformanceMeasuresStorage()
    for lambd in lambdas:
        params = Params(
            mu=3,
            lambda1=lambd,
            lambda2=lambd,
            servers_number=5,
            fragments_numbers=[2, 3],
            queues_capacities=[3, 3],
        )

        all_states = get_all_states(params)
        states_with_policy = get_policed_states(all_states, params)

        selected_policy_vector = [queue_id] * len(states_with_policy)

        policy = Policy(selected_policy_vector, states_with_policy, params)

        calculations = Calculations(params)
        calculations.calculate(policy)
        performance_measures = calculations.performance_measures
        print(performance_measures, "\n")

        storage.append(lambd, performance_measures)

    print(storage)
    print()
    storage.show_difference()

    plt.title("Зависимость T от интенсивности входящего потока")
    plt.xlabel("lambdas")
    plt.ylabel("T")
    plt.grid()
    plt.plot(lambdas, storage.response_times, "g", linewidth=2, markersize=12)
    plt.show()

    plt.title("Зависимость T1 и T2 от интенсивности входящего потока")
    plt.xlabel("lambdas")
    plt.ylabel("T")
    plt.grid()
    plt.plot(lambdas,
             storage.response_times1,
             "g",
             label="T1",
             linewidth=2,
             markersize=12)
    plt.plot(lambdas,
             storage.response_times2,
             "b",
             label="T2",
             linewidth=2,
             markersize=12)
    plt.legend()
    plt.show()

    plt.title("Зависимость pf от интенсивности входящего потока")
    plt.xlabel("lambdas")
    plt.ylabel("pf")
    plt.grid()
    plt.plot(lambdas,
             storage.blocked_all_queues_probability,
             "b",
             linewidth=2,
             markersize=12)
    plt.show()

    plt.title("Зависимость pf1 и pf2 от интенсивности входящего потока")
    plt.xlabel("lambdas")
    plt.ylabel("pf")
    plt.grid()
    plt.plot(
        lambdas,
        storage.failure_probabilities1,
        "g",
        label="pf1",
        linewidth=2,
        markersize=12,
    )
    plt.plot(
        lambdas,
        storage.failure_probabilities2,
        "b",
        label="pf2",
        linewidth=2,
        markersize=12,
    )
    plt.legend()
    plt.show()
                    queues_capacities=[1, 1])
    calculations = Calculations(params)

    all_states = calculations.get_all_states()
    states_with_policy = get_policed_states(all_states, params)
    print("All states where policy is possible:")
    pprint(states_with_policy)

    strategies = get_strategy(states_with_policy)
    states_policy = StatesPolicy(tuple(), states_with_policy, params)
    states_policy.print_adjacent_states()

    storage = PerformanceMeasuresStorage()
    print()

    for strategy in strategies:
        states_policy.strategy = strategy
        print(strategy)
        calculations = Calculations(params)
        calculations.calculate(states_policy)
        performance_measures = calculations.performance_measures
        print(performance_measures, "\n")

        storage.append(strategy, performance_measures)

    print(storage)
    print()
    storage.show_difference()

    print("executed")
Exemplo n.º 8
0
from calculations import Calculations

while True:
    calculation = input("Calculator : ")
    
    try:
        result = Calculations.calculate(calculation)
        print(result)
    except:
        print('Error')