Example #1
0
def test_three_station_network_model():
    """Example 5.3.2 from CTCN online (Example 5.3.5 from printed version). Figure 5.2."""
    env = envex.three_station_network_model()

    # Compute load, workload and sensitivity vectors sorted by load
    load, workload, nu = wl.compute_load_workload_matrix(env)
    # Third method of computing the network load:
    network_load_bis = alt_methods_test.compute_network_load(env)
    # Compute network load and associated workload and sensitivity vectors. Useful to validate that
    # we obtain the same results with two different methods.
    network_load, xi_bottleneck, nu_bottleneck, constraints \
        = alt_methods_test.compute_network_load_and_bottleneck_workload(env)

    workload_theory = np.array([[1, 1, 0, 1, 0, 1], [1, 0, 1, 1, 0, 1], [1, 0, 1, 0, 1, 1]])
    # Due to numerical noise, different computers can obtain the barc vectors in different order.
    # So we will compare sets instead of ndarrays.
    np.around(workload, decimals=6, out=workload)
    np.around(workload_theory, decimals=6, out=workload_theory)
    workload_set = set(map(tuple, workload))
    workload_theory_set = set(map(tuple, workload_theory))

    # Compare the three methods of obtaining the network load.
    np.testing.assert_almost_equal(network_load, network_load_bis, decimal=6)
    np.testing.assert_almost_equal(network_load, load[0], decimal=6)
    # We don't compare the two methods of obtaining the bottleneck workload for zero demand.
    # Compare workload with theoretical result from CTCN book.
    assert workload_set == workload_theory_set
Example #2
0
def test_compute_network_load_and_workload_dai_wang_model():
    """Example 4.6.4 and Figure 4.15 from CTCN online ed."""

    alpha1 = 0.2
    mu1 = 0.66
    mu2 = mu1
    mu3 = 0.42
    mu4 = mu3
    mu5 = mu1
    env = envex.dai_wang_model(alpha1=alpha1, mu1=mu1, mu2=mu2, mu3=mu3, mu4=mu4, mu5=mu5)
    load_theory = np.array([2 * alpha1/mu3, 3 * alpha1/mu1])
    workload_theory = np.array([[1/mu3 + 1/mu4, 1/mu3 + 1/mu4, 1/mu3 + 1/mu4, 1/mu4, 0],
                                [1/mu1 + 1/mu2 + 1/mu5, 1/mu2 + 1/mu5, 1/mu5, 1/mu5, 1/mu5]])

    # Compute load, workload and sensitivity vectors sorted by load
    load, workload, nu = wl.compute_load_workload_matrix(env)
    # Compute network load and associated workload and sensitivity vectors. Useful to validate that
    # we obtain the same results with two different methods.
    network_load, xi_bottleneck, nu_bottleneck, constraints \
        = alt_methods_test.compute_network_load_and_bottleneck_workload(env)
    # Third method of computing the network load:
    network_load_bis = alt_methods_test.compute_network_load(env)

    # Compare the three methods of obtaining the network load.
    np.testing.assert_almost_equal(network_load, network_load_bis, decimal=6)
    np.testing.assert_almost_equal(network_load, load[0], decimal=6)
    np.testing.assert_almost_equal(xi_bottleneck.value, np.reshape(workload[0, :],
                                                                   (env.num_buffers, 1)), decimal=6)
    # Compare results with theoretical result from CTCN book.
    np.testing.assert_almost_equal(load, load_theory, decimal=6)
    np.testing.assert_almost_equal(workload, workload_theory, decimal=6)
Example #3
0
def test_compute_network_load_and_workload_ksrs_network_model_different_parameters():
    """Trying different parameters for Example 4.2.4. KSRS model from CTCN online."""
    alpha1 = 0.4
    alpha3 = 0.2
    mu1 = 0.7
    mu2 = 0.75
    mu3 = 0.8
    mu4 = 0.8

    env = envex.ksrs_network_model(alpha1, alpha3, mu1, mu2, mu3, mu4)

    # Compute load, workload and sensitivity vectors sorted by load
    load, workload, nu = wl.compute_load_workload_matrix(env)
    # Compute network load and associated workload and sensitivity vectors. Useful to validate that
    # we obtain the same results with two different methods.
    network_load, xi_bottleneck, nu_bottleneck, constraints \
        = alt_methods_test.compute_network_load_and_bottleneck_workload(env)
    # Third method of computing the network load:
    network_load_bis = alt_methods_test.compute_network_load(env)

    workload_theory = np.array([[1 / mu1, 0, 1 / mu4, 1 / mu4], [1 / mu2, 1 / mu2, 1 / mu3, 0]])
    # Due to numerical noise, different computers can obtain the barc vectors in different order.
    # So we will compare sets instead of ndarrays.
    np.around(workload, decimals=6, out=workload)
    np.around(workload_theory, decimals=6, out=workload_theory)
    workload_set = set(map(tuple, workload))
    workload_theory_set = set(map(tuple, workload_theory))
    assert workload_set == workload_theory_set

    # Compare the three methods of obtaining the network load.
    np.testing.assert_almost_equal(network_load, network_load_bis, decimal=6)
    np.testing.assert_almost_equal(network_load, load[0], decimal=6)
    # Compare the two methods of obtaining the bottleneck workload.
    np.testing.assert_almost_equal(xi_bottleneck.value, np.reshape(workload[0, :],
                                                                   (env.num_buffers, 1)), decimal=6)
Example #4
0
def test_compute_network_load_and_workload_simple_reentrant_line_model():
    """Example 4.2.3. Simple re-entrant line from CTCN online."""
    alpha1 = 0.3
    mu1 = 0.67
    mu2 = 0.35
    mu3 = 0.67

    env = envex.simple_reentrant_line_model(alpha1, mu1, mu2, mu3)

    # Compute load, workload and sensitivity vectors sorted by load
    load, workload, nu = wl.compute_load_workload_matrix(env)
    # Compute network load and associated workload and sensitivity vectors. Useful to validate that
    # we obtain the same results with two different methods.
    network_load, xi_bottleneck, nu_bottleneck, constraints \
        = alt_methods_test.compute_network_load_and_bottleneck_workload(env)
    # Third method of computing the network load:
    network_load_bis = alt_methods_test.compute_network_load(env)

    # Compare the three methods of obtaining the network load.
    np.testing.assert_almost_equal(network_load, network_load_bis, decimal=6)
    np.testing.assert_almost_equal(network_load, load[0], decimal=6)
    np.testing.assert_almost_equal(xi_bottleneck.value, np.reshape(workload[0, :],
                                                                   (env.num_buffers, 1)), decimal=6)
    # Compare results with theoretical result from CTCN book.
    load_theory = np.array([alpha1 * (1/mu1 + 1/mu3), alpha1/mu2])
    workload_theory = np.vstack(([1/mu1 + 1/mu3, 1/mu3, 1/mu3],
                                 [1/mu2, 1/mu2, 0]))
    np.testing.assert_almost_equal(load, load_theory, decimal=6)
    np.testing.assert_almost_equal(workload, workload_theory, decimal=6)
Example #5
0
def test_compute_network_load_and_workload_klimov_model():
    """Example 4.2.1. Klimov model form CTCN online"""
    alpha1 = .1
    alpha2 = .12
    alpha3 = .13
    alpha4 = .14
    mu1 = 0.6
    mu2 = 0.7
    mu3 = 0.8
    mu4 = 0.9

    env = envex.klimov_model(alpha1, alpha2, alpha3, alpha4, mu1, mu2, mu3, mu4)

    # Compute load, workload and sensitivity vectors sorted by load
    load, workload, nu = wl.compute_load_workload_matrix(env)
    # Compute network load and associated workload and sensitivity vectors. Useful to validate that
    # we obtain the same results with two different methods.
    network_load, xi_bottleneck, nu_bottleneck, constraints \
        = alt_methods_test.compute_network_load_and_bottleneck_workload(env)
    # Third method of computing the network load:
    network_load_bis = alt_methods_test.compute_network_load(env)

    # Compare the three methods of obtaining the network load.
    np.testing.assert_almost_equal(network_load, network_load_bis, decimal=6)
    np.testing.assert_almost_equal(network_load, load[0], decimal=6)
    np.testing.assert_almost_equal(xi_bottleneck.value, np.reshape(workload[0, :],
                                                                   (env.num_buffers, 1)), decimal=6)
    # Compare results with theoretical result from CTCN book.
    np.testing.assert_almost_equal(load, alpha1/mu1 + alpha2/mu2 + alpha3/mu3 + alpha4/mu4,
                                   decimal=6)
    np.testing.assert_almost_equal(workload, np.array([[1/mu1, 1/mu2, 1/mu3, 1/mu4]]), decimal=6)
Example #6
0
def test_compute_network_load_and_workload_single_server_queue():
    """Check Sec. 5.1.1, W(t) = mu^{-1} x."""
    env = envex.single_server_queue()
    load, xi, nu, constraints = alt_methods_test.compute_network_load_and_bottleneck_workload(env)
    load_bis = alt_methods_test.compute_network_load(env)
    # Compare two different methods of computing the network load
    np.testing.assert_almost_equal(load, load_bis, decimal=6)
    # Compare results with theoretical solution
    np.testing.assert_almost_equal(load, env.job_generator.demand_rate, decimal=6)
    np.testing.assert_almost_equal(xi.value, [[1.]], decimal=6)
    np.testing.assert_almost_equal(nu.value, [[1.]], decimal=6)
Example #7
0
def test_compute_network_load_and_workload_simple_routing_model():
    """Example 6.2.2. from CTCN online, Example 6.2.4 from printed version."""
    alpha_r = 0.18
    mu1 = 0.13
    mu2 = 0.07
    mu_r = 0.3

    env = envex.simple_routing_model(alpha_r, mu1, mu2, mu_r)

    # Compute load, workload and sensitivity vectors sorted by load
    load, workload, nu = wl.compute_load_workload_matrix(env)
    # Compute network load and associated workload and sensitivity vectors. Useful to validate that
    # we obtain the same results with two different methods.
    network_load, xi_bottleneck, nu_bottleneck, constraints \
        = alt_methods_test.compute_network_load_and_bottleneck_workload(env)
    # Third method of computing the network load:
    network_load_bis = alt_methods_test.compute_network_load(env)

    # Compare the two methods of obtaining the network load, directly and as the highest load.
    np.testing.assert_almost_equal(network_load, network_load_bis, decimal=6)
    np.testing.assert_almost_equal(network_load, load[0], decimal=6)
    np.testing.assert_almost_equal(xi_bottleneck.value, np.reshape(workload[0, :],
                                                                   (env.num_buffers, 1)), decimal=6)
    # Compare results with theoretical result from CTCN book, for the 4 resources.
    load_theory = np.array([alpha_r / (mu1 + mu2),
                            alpha_r / mu_r,
                            0,
                            0])
    workload_theory = np.vstack((1 / (mu1 + mu2) * np.ones(env.num_buffers),
                                 [0, 0, 1/mu_r],
                                 [0, 1 / mu2, 0],
                                 [1/mu1, 0, 0]))
    nu_theory = np.array([[mu1 / (mu1 + mu2), mu2 / (mu1 + mu2), 0],
                          [0, 0, 1],
                          [0, 1, 0],
                          [1, 0, 0]])

    # Due to numerical noise, different computers can obtain the barc vectors in different order.
    # So we will compare sets instead of ndarrays.
    np.around(workload, decimals=6, out=workload)
    np.around(workload_theory, decimals=6, out=workload_theory)
    np.around(nu, decimals=6, out=nu)
    np.around(nu_theory, decimals=6, out=nu_theory)
    workload_set = set(map(tuple, workload))
    workload_theory_set = set(map(tuple, workload_theory))
    nu_set = set(map(tuple, nu))
    nu_theory_set = set(map(tuple, nu_theory))

    np.testing.assert_almost_equal(load, load_theory, decimal=6)
    assert workload_set == workload_theory_set
    assert nu_set == nu_theory_set
Example #8
0
def test_compute_network_load_and_workload_simple_link_constrained_model():
    """Example 6.3.1. Simple link-constrained model from CTCN online (Example 6.3.5 from printed
    version). Corresponds with Figure 6.7."""
    alpha1 = 4
    mu12 = 2
    mu13 = 10
    mu25 = 1
    mu32 = 5
    mu34 = 2
    mu35 = 2
    mu45 = 10
    mu5 = 100

    env = envex.simple_link_constrained_model(alpha1, mu12, mu13, mu25, mu32, mu34, mu35, mu45, mu5)

    # Compute load, workload and sensitivity vectors sorted by load
    load, workload, nu = wl.compute_load_workload_matrix(env)
    # Third method of computing the network load:
    network_load_bis = alt_methods_test.compute_network_load(env)
    # Compute network load and associated workload and sensitivity vectors. Useful to validate that
    # we obtain the same results with two different methods.
    network_load, xi_bottleneck, nu_bottleneck, constraints \
        = alt_methods_test.compute_network_load_and_bottleneck_workload(env)

    # Compare the three methods of obtaining the network load.
    np.testing.assert_almost_equal(network_load, network_load_bis, decimal=3)
    np.testing.assert_almost_equal(network_load, load[0], decimal=3)
    # Compare the two methods of obtaining the bottleneck workload.
    np.testing.assert_almost_equal(xi_bottleneck.value, np.reshape(workload[0, :],
                                                                   (env.num_buffers, 1)), decimal=3)
    # Compare results with theoretical result from CTCN book, for the 4 resources.
    alpha_star = 5
    np.testing.assert_almost_equal(load[0], alpha1/alpha_star, decimal=6)
    np.testing.assert_almost_equal(workload[0, :] * env.job_generator.sim_time_interval,
                                   np.array([1/alpha_star, 1/alpha_star, 1/alpha_star, 0, 0]),
                                   decimal=6)
    np.testing.assert_almost_equal(nu[0, :], np.array([0, 0, 1/alpha_star, 0, 2/alpha_star,
                                                       2/alpha_star, 0, 0]), decimal=6)
Example #9
0
def test_compute_network_load_and_workload_simple_link_constrained_with_route_scheduling_model():
    """We follow Figure 6.7 from CTCN book, but we model the resources as being able to schedule one
    output route at a time, as opposed to Example 6.3.1 where each link is a resource. By using the
    Min-Cut Max-Flow theorem, we obtain alpha_star = 3."""
    alpha1 = 4 / 100
    mu12 = 2 / 100
    mu13 = 10 / 100
    mu25 = 1 / 100
    mu32 = 5 / 100
    mu34 = 2 / 100
    mu35 = 2 / 100
    mu45 = 10 / 100
    mu5 = 100 / 100

    env = envex.simple_link_constrained_with_route_scheduling_model(alpha1, mu12, mu13, mu25, mu32,
                                                                    mu34, mu35, mu45, mu5)

    # Compute load, workload and sensitivity vectors sorted by load
    load, workload, nu = wl.compute_load_workload_matrix(env)
    # Third method of computing the network load:
    network_load_bis = alt_methods_test.compute_network_load(env)
    # Compute network load and associated workload and sensitivity vectors. Useful to validate that
    # we obtain the same results with two different methods.
    network_load, xi_bottleneck, nu_bottleneck, constraints \
        = alt_methods_test.compute_network_load_and_bottleneck_workload(env)

    # Compare the three methods of obtaining the network load.
    np.testing.assert_almost_equal(network_load, network_load_bis, decimal=3)
    np.testing.assert_almost_equal(network_load, load[0], decimal=3)
    # Compare the two methods of obtaining the bottleneck workload.
    np.testing.assert_almost_equal(xi_bottleneck.value, np.reshape(workload[0, :],
                                                                   (env.num_buffers, 1)), decimal=3)
    # Compare results with theoretical result from CTCN book, for the 4 resources.
    alpha_star = 3 / 100
    np.testing.assert_almost_equal(load[0], alpha1/alpha_star, decimal=6)
    np.testing.assert_almost_equal(workload[0, :], np.array([1/alpha_star, 1/alpha_star,
                                                             1/alpha_star, 0, 0]), decimal=6)
Example #10
0
def test_input_queued_switch_3x3_model():
    """Example 6.5.2. Input-queued switch, Figure 6. 10, Proposition 6.6.2, from CTCN book."""
    alpha11 = 0.11
    alpha12 = 0.12
    alpha13 = 0.13
    alpha21 = 0.21
    alpha22 = 0.22
    alpha23 = 0.23
    alpha31 = 0.31
    alpha32 = 0.32
    alpha33 = 0.33
    demand_rate = np.array([alpha11, alpha12, alpha13, alpha21, alpha22, alpha23, alpha31, alpha32,
                            alpha33])[:, None]
    env = envex.input_queued_switch_3x3_model(demand_rate=demand_rate)

    # Compute load, workload and sensitivity vectors sorted by load
    load, workload, nu = wl.compute_load_workload_matrix(env)
    # Third method of computing the network load:
    network_load_bis = alt_methods_test.compute_network_load(env)
    # Compute network load and associated workload and sensitivity vectors. Useful to validate that
    # we obtain the same results with two different methods.
    network_load, xi_bottleneck, nu_bottleneck, constraints \
        = alt_methods_test.compute_network_load_and_bottleneck_workload(env)

    # Compare the three methods of obtaining the network load.
    np.testing.assert_almost_equal(network_load, network_load_bis, decimal=6)
    np.testing.assert_almost_equal(network_load, load[0], decimal=6)
    # Compare the two methods of obtaining the bottleneck workload.
    np.testing.assert_almost_equal(xi_bottleneck.value, np.reshape(workload[0, :],
                                                                   (env.num_buffers, 1)), decimal=2)
    # Compare results with theoretical result from CTCN book, for the 4 resources.
    demand_rate_mat = demand_rate.reshape((3, 3))
    network_load_theory = np.max((np.max(np.sum(demand_rate_mat, axis=0)),
                                  np.max(np.sum(demand_rate_mat, axis=1))))
    np.testing.assert_almost_equal(load[0], network_load_theory, decimal=6)
    assert snctools.is_approx_binary(workload)