def test_priority_nonidling_heuristic_agent_multiple_buffers_eye_condition():
    # One station scheduling two buffers, one larger than the other, both above safety stock.
    buffer_processing_matrix = -np.eye(2)
    safety_stock = 10.0
    state = np.array([30, 20])[:, None]
    env_params = get_null_env_params(
        state, buffer_processing_matrix=buffer_processing_matrix)
    env_params["constituency_matrix"] = np.ones((1, 2))
    env_params["list_boundary_constraint_matrices"] = [np.eye(2)]

    env = crw.ControlledRandomWalk(**env_params)
    agent = longest_priority_agent.LongestBufferPriorityAgent(
        env, safety_stock)
    action = agent.map_state_to_actions(state)
    assert np.all(action == np.array([1, 0])[:, None])
def test_priority_nonidling_heuristic_agent_starving():
    # Single server queue
    buffer_processing_matrix = -np.ones((1, 1))
    safety_stock = 10.0
    state = 5 * np.ones((1, 1))
    env_params = get_null_env_params(
        state, buffer_processing_matrix=buffer_processing_matrix)
    env_params["constituency_matrix"] = np.ones((1, 1))
    env_params["list_boundary_constraint_matrices"] = [np.ones((1, 1))]

    env = crw.ControlledRandomWalk(**env_params)
    agent = longest_priority_agent.LongestBufferPriorityAgent(
        env, safety_stock)
    action = agent.map_state_to_actions(state)
    assert action == np.zeros((1, 1))
def test_priority_nonidling_heuristic_agent_multi_buffers_eye_cond_small_one_starve_reverse_ord(
):
    # One station scheduling two buffers, one larger than the other. Only the large one is above
    # safety stock, swap order with respect to previous test.
    buffer_processing_matrix = -np.eye(2)
    safety_stock = 10.0
    state = np.array([11, 10])[:, None]
    env_params = get_null_env_params(
        state, buffer_processing_matrix=buffer_processing_matrix)
    env_params["constituency_matrix"] = np.ones((1, 2))
    env_params["list_boundary_constraint_matrices"] = [np.eye(2)]

    env = crw.ControlledRandomWalk(**env_params)
    agent = longest_priority_agent.LongestBufferPriorityAgent(
        env, safety_stock)
    action = agent.map_state_to_actions(state)
    assert np.all(action == np.array([1, 0])[:, None])
def test_priority_nonidling_heuristic_agent_multiple_buffers_and_resources_sum_cond_2_starve(
):
    # Two stations, each one scheduling two buffers. The stations are connected in serial, such that
    # buffer 1 is connected with buffer 3, and 2 with 4.
    # Kind of condition doesn't matter since the largest buffer has to be above safety stock in this
    # agent.
    buffer_processing_matrix = np.array([[-1, 0, 0, 0], [0, -1, 0, 0],
                                         [1, 0, -1, 0], [0, 1, 0, -1]])
    safety_stock = 10
    state = np.array([30, 20, 9, 5])[:, None]
    env_params = get_null_env_params(
        state, buffer_processing_matrix=buffer_processing_matrix)
    env_params["constituency_matrix"] = np.array([[1, 1, 0, 0], [0, 0, 1, 1]])
    env_params["list_boundary_constraint_matrices"] = [
        np.array([[1, 1, 0, 0]]),
        np.array([[0, 0, 1, 1]])
    ]

    env = crw.ControlledRandomWalk(**env_params)
    agent = longest_priority_agent.LongestBufferPriorityAgent(
        env, safety_stock)
    action = agent.map_state_to_actions(state)
    assert np.all(action == np.array([1, 0, 0, 0])[:, None])