def find_nash(la, mu, n, print_matrix=False): model = DispatcherAndHospitalsModel(la, mu, n, N_lim, t_c) matrix = model.game_matrix(disp_strategies_number=2) if print_matrix: print(matrix) game = GameWith3Players(matrix) equs = game.find_pne_for_dispatcher_and_hospitals() if is_inconsistent(equs, matrix): return ['Inconsistent'] return equs
def find_solution(self, l, mu, n, disp_strategy_index): hospital = DispatcherAndHospitalsModel(l, mu, n, N_lim, t_c) G = hospital.game_matrix()[disp_strategy_index] A = self.extract_player_utility(G, 1) B = self.extract_player_utility(G, 2) game = nash.Game(A, B) eqs = list(game.support_enumeration()) if self.is_system_consistent(A, B, eqs): sol = self.mixed_or_pure_solution_value(eqs) return sol else: return 255, 255, 255
def disp_regulation(n): points = 10 matches = np.array([0] * 3) for la in np.linspace(0.05, 5, points): for mu in np.linspace(0.05, 5, points): model = DispatcherAndHospitalsModel(la, mu, n, N_lim, t_c) game_matrix = model.game_matrix() global_matrix = model.global_average_time_matrix() nash_equs = [find_nash(game_matrix, i) for i in range(3)] global_equs = [find_global(global_matrix, i) for i in range(3)] matches += intersection(nash_equs, global_equs) return matches / ([points**2] * 3)
def find_nash(la, mu, n, print_matrix=False): model = DispatcherAndHospitalsModel(la, mu, n, 3, 10) matrix = model.game_matrix() if print_matrix: print(matrix) text = "NFG 1 R \"Ambulance Dispatching Game\" { \"Dispatcher\" \"Hospital1\" \"Hospital2\" }\n\n" text += "{ { \"N2\" \"N1\" }\n" text += "{ \"A\" \"R\" }\n" text += "{ \"A\" \"R\" }\n" text += "}\n\"\"\n\n" text += "{\n" for k in range(2): for j in range(2): for i in range(2): text += "{ \"\" %f, %f, %f }\n" % (matrix[i][j][k][0], matrix[i][j][k][2], matrix[i][j][k][2]) text += "}\n" text += "1 2 3 4 5 6 7 8" game = Game(text) sol = game.findEquilibria('pne') return extract_strategies_from_solutions(sol)
for dominated_strategy_payoff in dominated_strategies_payoff: if dominate_strategy_payoff[ player_idx] < dominated_strategy_payoff[player_idx]: return False return True def find_pne_for_dispatcher_and_hospitals(self): equs = self.find_pure_nash_equ() return sorted( set([self.convert_strategy_idx_to_name(equ) for equ in equs])) def convert_strategy_idx_to_name(self, str_indices): disp_strategy = 'N2' if str_indices[0] == 1: disp_strategy = 'N1' elif str_indices[0] == 2: return 'BE' hosp1_strategy = 'A' if str_indices[1] == 0 else 'R' hosp2_strategy = 'A' if str_indices[2] == 0 else 'R' return '{}-{}{}'.format(disp_strategy, hosp1_strategy, hosp2_strategy) if __name__ == '__main__': model = DispatcherAndHospitalsModel(2, 2, [2, 2], 5, 10) matrix = model.game_matrix(2) print(matrix) game = GameWith3Players(matrix) print(game.find_pne_for_dispatcher_and_hospitals())