source: CSE3210/agent68/utils/grid_search.py

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

#6 Added CSE3210 parties

File size: 3.0 KB
Line 
1import numpy as np
2import os
3
4from utils.runners import run_tournament
5from utils.PlotTournament import PlotTournament
6
7
8if not os.path.exists("results"):
9 os.mkdir("results")
10
11class TournamentInfo(PlotTournament):
12 def __init__(self, results_summaries, my_agent):
13 super().__init__(results_summaries, my_agent)
14
15 def getTournamentInfo(self):
16 self.update_tournament_results()
17
18 utilAvgs = [np.mean(value) for value in self.utilities.values()]
19
20 nashAvgs = [np.mean(value) for value in self.nash_products.values()]
21
22 socialAvgs = [np.mean(value) for value in self.social_welfares.values()]
23
24 return (np.average(utilAvgs), np.average(nashAvgs), np.average(socialAvgs))
25
26def scoringFunction(utilScore, nashProduct, socialWelfare):
27 #Normalize socialWelfare [0,2] and add more weight to utilScore?
28 #Higher score == better
29 return ((1.5*utilScore) + nashProduct + (socialWelfare/2))/(1.5 + 1 + 1)
30
31e1_min = 0.1
32e1_max = 0.6
33e2_min = 0.1
34e2_max = 0.6
35e3_min = 0.1
36e3_max = 0.6
37utilGoalW_min = 0.4
38utilGoalW_max = 1.0
39leniBaseW_min = 0.0
40leniBaseW_max = 0.5
41step = 0.5
42
43# with open("../results/gridSearch.csv", "w") as f:
44# f.write("")
45# f.close()
46for e1 in np.arange(e1_min, e1_max, step):
47 for e2 in np.arange(e2_min, e2_max, step):
48 for e3 in np.arange(e3_min, e3_max, step):
49 for utilGoal in np.arange(utilGoalW_min, utilGoalW_max, step):
50 for leniBase in np.arange(leniBaseW_min, leniBaseW_max, step):
51 tournament_settings = {
52 "agents": [
53 # "agents.boulware_agent.boulware_agent.BoulwareAgent",
54 "agents.conceder_agent.conceder_agent.ConcederAgent",
55 # "agents.linear_agent.linear_agent.LinearAgent",
56 # "agents.random_agent.random_agent.RandomAgent",
57 # "agents.template_agent.template_agent.TemplateAgent",
58 "main.threephase_agent.threephase_agent.ThreePhaseAgent",
59 ],
60 "profile_sets": [
61 ["domains/domain00/profileA.json", "domains/domain00/profileB.json"],
62 # ["domains/domain01/profileA.json", "domains/domain01/profileB.json"],
63 ],
64 "deadline_rounds": 200,
65 "parameters": {"e1": e1, "e2":e2, "e3":e3, "utilWeight" : utilGoal, "leniencyWeight" : (1-utilGoal), "leniencyBase" : leniBase},
66 }
67 # run a session and obtain results in dictionaries
68 print("Touring\n", flush=True)
69 tournament, results_summaries = run_tournament(tournament_settings)
70
71 print("Calcing\n", flush=True)
72
73 my_agent = "ThreePhaseAgent"
74 tour = TournamentInfo(results_summaries, my_agent)
75 util, nash, social = tour.getTournamentInfo()
76 score = scoringFunction(util, nash, social)
77 params = f'{e1},{e2},{e3},{utilGoal},{1-utilGoal},{leniBase}'
78 print("Writing\n", flush=True)
79 with open("results/gridSearch.csv", "a") as f:
80 f.write("{},{}\n".format(params, score))
81
Note: See TracBrowser for help on using the repository browser.