source: CSE3210/agent41/evaluator.py

Last change on this file was 74, checked in by wouter, 21 months ago

#6 Added CSE3210 parties

File size: 2.8 KB
Line 
1import sys
2import os
3import utils.runners
4import itertools
5import json
6import numpy as np
7from alive_progress import alive_bar
8
9
10our_agent = "agents.orange_agent.orange_agent.OrangeAgent"
11
12agents = [
13 "agents.boulware_agent.boulware_agent.BoulwareAgent",
14 "agents.linear_agent.linear_agent.LinearAgent",
15 "agents.gamer_agent.gamer_agent.GamerAgent",
16 "agents.shreker.shreker.Shreker",
17 "agents.hope_agent.hope_agent.HopeAgent",
18]
19
20param_grid = [
21 [0.0,0.2,0.4],
22 [0.1,0.25],
23 [0.5,0.8],
24 [0.6,0.8],
25 [0.9,0.95],
26 [0.9,0.95],
27 [0.1,0.2],
28 [0.00025,0.0005],
29 [0.00075,0.001],
30 [0.00125,0.002],
31 [0.4,0.5,0.6]
32]
33
34def conf_to_json(conf, name):
35 data = {
36 "util_adv_from_accept" : conf[0],
37 "util_adv_from_offer" : conf[1],
38 "util_adv_to_offer" : conf[2],
39 "progress_mid" : conf[3],
40 "progress_fast": conf[4],
41 "utility_range_from" : conf[5],
42 "utility_range_to" : conf[5] + conf[6],
43 "slow_decrease" : conf[7],
44 "mid_decrease" : conf[8],
45 "fast_decrease" : conf[9],
46 "minimal_reservation_val": conf[10]
47 }
48 if name is None:
49 name = "params.json"
50 with open(name, 'w', encoding='utf-8') as f:
51 json.dump(data, f, ensure_ascii=False, indent=2)
52
53class HiddenPrints:
54 def __enter__(self):
55 self._original_stdout = sys.stdout
56 sys.stdout = open(os.devnull, 'w')
57
58 def __exit__(self, exc_type, exc_val, exc_tb):
59 sys.stdout.close()
60 sys.stdout = self._original_stdout
61
62max_wins = 0
63avg_sw = 0
64winning_conf = {}
65
66iters = 1
67for arr in param_grid:
68 iters *= len(arr)
69
70confs = itertools.product(*param_grid)
71i = 0
72
73bar = alive_bar(iters)
74
75with alive_bar(iters) as bar:
76 for conf in confs:
77 i += 1
78 conf_to_json(conf, None)
79
80 curr_wins = 0
81 social_welfare = []
82 for agent in agents:
83 settings = {
84 "agents": [
85 our_agent,
86 agent
87 ],
88 "profiles": ["domains/domain00/profileA.json", "domains/domain00/profileB.json"],
89 "deadline_rounds": 200,
90 }
91
92 _, results_summary = utils.runners.run_session(settings)
93
94 if results_summary["result"] != "ERROR":
95 social_welfare.append(results_summary['social_welfare'])
96 if results_summary["result"] != "ERROR" and results_summary['utility_1'] > results_summary['utility_2']:
97 curr_wins += 1
98
99 sw = np.average(social_welfare)
100
101 if curr_wins > max_wins or (curr_wins == max_wins and sw > avg_sw):
102 max_wins = curr_wins
103 avg_sw = sw
104 winning_conf = conf
105 print("NEW WINNING CONF WITH {} WINS IS WITH AVG SOCIAL WELFARE OF {}:".format(max_wins, sw))
106 print(json.dumps(winning_conf, indent=2))
107 conf_to_json(conf, "best.json")
108 bar()
109
110
111
112conf_to_json(winning_conf, "params.json")
113print("WINNING CONF WITH {} WINS IS:".format(max_wins))
114print(json.dumps(winning_conf, indent=2))
Note: See TracBrowser for help on using the repository browser.