diff --git a/agents/super_agent/super_agent.py b/agents/super_agent/super_agent.py index 84751d6..379ead1 100644 --- a/agents/super_agent/super_agent.py +++ b/agents/super_agent/super_agent.py @@ -51,6 +51,8 @@ def __init__(self): self._me = None self._profile_interface: ProfileInterface = None self._progress = None + self._util_threshold_calculator = None + self.pick_acceptence_pattern(random.randint(0, 4)) self._protocol = None self._parameters: Parameters = None self._utility_space = None @@ -211,7 +213,10 @@ def notifyChange(self, info: Inform): self._progress = self._progress.advance() # self.initialize_storage(self._opponent_name) action = self._my_turn() - val(self.getConnection()).send(action) + try: + self.getConnection().send(action) + except Exception as ex: + self.getReporter().log(logging.WARNING, "action:{}:{}".format(action, ex)) elif isinstance(info, Finished): # TODO:: handle NEGOTIATIONDATA @@ -338,30 +343,71 @@ def is_good(self, bid): avg_max_utility = self._persistent_data.get_avg_max_utility(self._opponent_name) \ if self._persistent_data._known_opponent(self._opponent_name) \ else self._avg_utility - self._util_threshold = max_value - ( - max_value - 0.55 * self._avg_utility - 0.4 * avg_max_utility + 0.5 * pow(self._std_utility, 2)) * \ - (math.exp(self.alpha * self._progress.get(get_ms_current_time())) - 1) / (math.exp( - self.alpha) - 1) + + self._util_threshold = self._util_threshold_calculator(max_value, avg_max_utility) if self._util_threshold < self._min_utility: self._util_threshold = self._min_utility return float(self.calc_utility(bid)) >= self._util_threshold + def pick_acceptence_pattern(self, pattern): + patterns_desc = {0: 'Noraml Decay', 1: 'Decaying with sinus', 2: 'Decaying with step (alpha changing)', 3:'Decaying with cosinus', 4:'Linear decay'} + self.getReporter().log(logging.INFO, f"Acceptence pattern selected {patterns_desc[pattern]}") + if pattern == 0: + self._util_threshold_calculator = lambda max_value, avg_max_utility: max_value - ( + max_value - 0.55 * self._avg_utility - 0.4 * avg_max_utility + 0.5 * pow(self._std_utility, 2)) * \ + (math.exp( + self.alpha * self._progress.get( + get_ms_current_time())) - 1) / ( + math.exp( + self.alpha) - 1) + elif pattern == 1: + self._util_threshold_calculator = lambda max_value, avg_max_utility: max_value - ( + max_value - 0.55 * self._avg_utility - 0.4 * avg_max_utility + 0.5 * pow(self._std_utility, 2)) * \ + (math.exp( + self.alpha * self._progress.get( + get_ms_current_time())) - 1) / ( + math.exp( + self.alpha) - 1) - ( + math.sin(5 * ( + self._progress.get( + get_ms_current_time()))) / 20) + elif pattern == 2: + self._util_threshold_calculator = lambda max_value, avg_max_utility: max_value - ( + max_value - 0.55 * self._avg_utility - 0.4 * avg_max_utility + 0.5 * pow(self._std_utility, 2)) * \ + (math.exp( + self.alpha * self._progress.get( + get_ms_current_time())) - 1) / ( + math.exp( + self.alpha) - 1) if self._progress.get( + get_ms_current_time()) < 0.7 else max_value - ( + max_value - 0.55 * self._avg_utility - 0.4 * avg_max_utility + 0.5 * pow(self._std_utility, 2)) * \ + (math.exp(3 * self._progress.get(get_ms_current_time())) - 1) / ( + math.exp(3) - 1) + + elif pattern == 3: + self._util_threshold_calculator = lambda max_value, avg_max_utility: max_value - ( + max_value - 0.55 * self._avg_utility - 0.4 * avg_max_utility + 0.5 * pow(self._std_utility, 2)) * \ + (math.exp( + self.alpha * self._progress.get( + get_ms_current_time())) - 1) / ( + math.exp( + self.alpha) - 1) - ( + math.cos(5 * ( + self._progress.get( + get_ms_current_time()))) / 20) + elif pattern == 4: + self._util_threshold_calculator = lambda max_value, avg_max_utility: max_value - ( + max_value - 0.55 * self._avg_utility - 0.4 * avg_max_utility + 0.5 * pow(self._std_utility, 2)) * (self._progress.get( + get_ms_current_time())/2) + def first_is_good_idx(self): for i in range(len(self._sorted_bid_list)): if not self.is_good(self._sorted_bid_list[i]): return i return len(self._sorted_bid_list) - 1 - def filter_only_op_good(self, bid_list): - bid_good_for_both = [] - for bid in bid_list: - if self.is_op_good(bid): - bid_good_for_both.append(bid) - return bid_good_for_both - def on_negotiation_near_end(self): slice_idx = self.first_is_good_idx() - # print("A:{}".format(self._len_sorted_bid_list)) end_slice = int(min(slice_idx + 0.005 * self._len_sorted_bid_list - 1, self._len_sorted_bid_list - 1)) idx = random.randint(0, end_slice) if self._progress.get(get_ms_current_time()) > 0.99 and self.is_good(self._best_offer_bid): @@ -395,8 +441,6 @@ def _find_bid(self): self._best_offer_bid = self._last_received_bid elif self.cmp_utility(self._last_received_bid, self._best_offer_bid): self._best_offer_bid = self._last_received_bid - # if self.is_social_welfare_time(): - # self.on_negotiation_social_welfare() if self.is_near_negotiation_end(): bid = self.on_negotiation_near_end() else: diff --git a/run_tournament.py b/run_tournament.py index eade575..d8b6917 100644 --- a/run_tournament.py +++ b/run_tournament.py @@ -17,29 +17,32 @@ # You need to specify a time deadline (is milliseconds (ms)) we are allowed to negotiate before we end without agreement. tournament_settings = { "agents": [ + {"class": "agents.CSE3210.agent11.agent11.Agent11"}, + {"class": "agents.CSE3210.agent14.agent14.Agent14"}, + {"class": "agents.CSE3210.agent18.agent18.Agent18"}, + {"class": "agents.CSE3210.agent19.agent19.Agent19"}, + {"class": "agents.CSE3210.agent2.agent2.Agent2"}, + {"class": "agents.CSE3210.agent22.agent22.Agent22"}, + {"class": "agents.CSE3210.agent24.agent24.Agent24"}, + {"class": "agents.CSE3210.agent25.agent25.Agent25"}, + {"class": "agents.CSE3210.agent26.agent26.Agent26"}, + {"class": "agents.CSE3210.agent27.agent27.Agent27"}, + {"class": "agents.CSE3210.agent29.agent29.Agent29"}, + {"class": "agents.CSE3210.agent3.agent3.Agent3"}, + {"class": "agents.CSE3210.agent32.agent32.Agent32"}, + {"class": "agents.CSE3210.agent33.agent33.Agent33"}, + {"class": "agents.CSE3210.agent41.agent41.Agent41"}, + {"class": "agents.CSE3210.agent43.agent43.Agent43"}, + {"class": "agents.CSE3210.agent50.agent50.Agent50"}, + {"class": "agents.CSE3210.agent52.agent52.Agent52"}, + {"class": "agents.CSE3210.agent55.agent55.Agent55"}, + {"class": "agents.CSE3210.agent58.agent58.Agent58"}, + {"class": "agents.CSE3210.agent61.agent61.Agent61"}, + {"class": "agents.CSE3210.agent64.agent64.Agent64"}, + {"class": "agents.CSE3210.agent67.agent67.Agent67"}, + {"class": "agents.CSE3210.agent68.agent68.Agent68"}, + {"class": "agents.CSE3210.agent7.agent7.Agent7"}, { - "class": "agents.boulware_agent.boulware_agent.BoulwareAgent", - }, - { - "class": "agents.conceder_agent.conceder_agent.ConcederAgent", - }, - { - "class": "agents.hardliner_agent.hardliner_agent.HardlinerAgent", - }, - { - "class": "agents.linear_agent.linear_agent.LinearAgent", - }, - { - "class": "agents.random_agent.random_agent.RandomAgent", - }, - { - "class": "agents.stupid_agent.stupid_agent.StupidAgent", - }, - { - "class": "agents.template_agent.template_agent.TemplateAgent", - "parameters": {"storage_dir": "agent_storage/TemplateAgent"}, - }, -{ "class": "agents.super_agent.super_agent.SuperAgent", "parameters": {"storage_dir": "agent_storage/SuperAgent"}, }