def test_get_state_probabilities_array(): """ Test to ensure that the sum of elements of the pi array equate to 1 """ all_states = build_states( threshold=3, system_capacity=5, buffer_capacity=4, ) transition_matrix = get_transition_matrix( lambda_2=0.1, lambda_1=0.2, mu=0.2, num_of_servers=3, threshold=3, system_capacity=5, buffer_capacity=4, ) pi = get_steady_state_algebraically( Q=transition_matrix, algebraic_function=np.linalg.solve ) pi_array = get_markov_state_probabilities( pi=pi, all_states=all_states, output=np.ndarray ) assert round(np.nansum(pi_array), NUMBER_OF_DIGITS_TO_ROUND) == 1
def test_get_steady_state_algebraically_lstsq(a, b, c, d, e, f): """ Ensures that getting the steady state numerically using numpy's lstsq function returns the steady state for different transition-like matrices """ Q = np.array([[-a - b, a, b], [c, -c - d, d], [e, f, -e - f]]) steady = get_steady_state_algebraically(Q=Q, algebraic_function=np.linalg.lstsq) assert is_steady_state(state=steady, Q=Q)
def test_get_mean_number_of_individuals_examples(): """ Some examples to ensure that the correct mean number of individuals are output """ all_states = build_states(threshold=4, system_capacity=20, buffer_capacity=20) transition_matrix = get_transition_matrix( lambda_2=0.2, lambda_1=0.2, mu=0.2, num_of_servers=3, threshold=4, system_capacity=20, buffer_capacity=20, ) pi = get_steady_state_algebraically( Q=transition_matrix, algebraic_function=np.linalg.solve ) assert ( round( get_mean_number_of_individuals_in_system(pi=pi, states=all_states), NUMBER_OF_DIGITS_TO_ROUND, ) == 2.88827497 ) assert ( round( get_mean_number_of_individuals_in_service_area(pi=pi, states=all_states), NUMBER_OF_DIGITS_TO_ROUND, ) == 2.44439504 ) assert ( round( get_mean_number_of_individuals_in_buffer_center(pi=pi, states=all_states), NUMBER_OF_DIGITS_TO_ROUND, ) == 0.44387993 )