def test_update_array_roulette_vacancy_picker_01(self): array = np.array([[0, 0, 0], [0, 1, 1], [1, 2, 2]]) utility = get_utility_for_array(create_flat_utility(0.5), array, True) states_for_picked = [ (0.1, np.array([[0, 0, 2], [0, 1, 1], [1, 0, 2]])), (0.2, np.array([[2, 0, 0], [0, 1, 1], [1, 0, 2]])), (1.2, np.array([[2, 0, 0], [0, 1, 1], [1, 0, 2]])), (2.3, np.array([[0, 2, 0], [0, 1, 1], [1, 0, 2]])), (3.4, np.array([[0, 0, 0], [2, 1, 1], [1, 0, 2]])), (3.5, np.array([[0, 0, 0], [2, 1, 1], [1, 0, 2]])), ] result = SimulationResult() for picked_value, expected_state in states_for_picked: array = np.array([[0, 0, 0], [0, 1, 1], [1, 2, 2]]) vacancy_picker = _create_roulette_picker(0.1, utility, False, lambda *a: picked_value) agent_picker = _create_roulette_picker(0.0, utility, True, lambda *a: 0.0) update_array(array, utility, result, agent_picker, vacancy_picker, True, ['entropy_average'], True) with self.subTest(v=picked_value, out=array, exp=expected_state): self.assertTrue(np.array_equal(array, expected_state))
def test_update_array_multiple_utilities(self): array = np.array([[0, 0, 0], [0, 1, 1], [1, 2, 2]]) utilities = [create_flat_utility(0.25), create_flat_utility(0.75)] utility = get_utility_for_array(utilities, array, True) result = SimulationResult() #dummy result output = update_array(array, utility, result, _first_picker, _first_picker, False, ['entropy_average']) expected_output = np.array([[1, 0, 0], [0, 1, 0], [1, 2, 2]]) self.assertTrue(np.array_equal(array, expected_output))
def test_update_array_no_better_vacancies_first_picker(self): no_better_vacancies_array = np.array([[0, 2, 0, 0], [1, 1, 1, 1], [1, 1, 1, 1], [0, 2, 0, 2]]) result = SimulationResult() expected_output = True utility = get_utility_for_array(create_flat_utility(0.5), no_better_vacancies_array) output = update_array(no_better_vacancies_array, utility, result, _first_picker, _first_picker, False, ['entropy_average']) self.assertEqual(output, expected_output)
def test_update_array_all_agents_satisfied_should_end_simulation(self): all_satisfied_array = np.array([[0, 0, 0, 0], [1, 1, 1, 1], [1, 1, 1, 1], [0, 0, 0, 0]]) result = SimulationResult() expected_output = True utility = get_utility_for_array(create_flat_utility(0.5), all_satisfied_array) output = update_array(all_satisfied_array, utility, result, _first_picker, _first_picker, False, ['entropy_average']) self.assertEqual(output, expected_output)