From 2637c7b2327edef8217712c6c101c10b932a521b Mon Sep 17 00:00:00 2001 From: yokkon <0506422606e@gmail.com> Date: Tue, 31 May 2022 23:17:44 +0300 Subject: [PATCH 1/9] fixed conflicts --- agents/super_agent/super_agent.py | 35 ++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/agents/super_agent/super_agent.py b/agents/super_agent/super_agent.py index 754f456..0dff2ce 100644 --- a/agents/super_agent/super_agent.py +++ b/agents/super_agent/super_agent.py @@ -61,6 +61,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,2)) self._protocol = None self._parameters: Parameters = None self._utility_space = None @@ -334,15 +336,38 @@ 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): + 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) + def on_negotiation_near_end(self): bid: Bid = None for attempt in range(1000): From 976a58eed0a9ebe709ab1cce90ebc0fe292447ca Mon Sep 17 00:00:00 2001 From: yokkon <0506422606e@gmail.com> Date: Tue, 31 May 2022 23:23:59 +0300 Subject: [PATCH 2/9] Added pattern description log --- agents/super_agent/super_agent.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/agents/super_agent/super_agent.py b/agents/super_agent/super_agent.py index 0dff2ce..2f2056c 100644 --- a/agents/super_agent/super_agent.py +++ b/agents/super_agent/super_agent.py @@ -344,6 +344,8 @@ def is_good(self, bid): 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)'} + 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)) * \ From 747015350b1323466feedeaf3d89f90a01c8cf10 Mon Sep 17 00:00:00 2001 From: Ben Nageris Date: Tue, 31 May 2022 23:28:05 +0300 Subject: [PATCH 3/9] added multiagents in run tournament and format super_agent --- agents/super_agent/super_agent.py | 42 ++++++++++++++++----------- run_tournament.py | 47 ++++++++++++++++--------------- 2 files changed, 50 insertions(+), 39 deletions(-) diff --git a/agents/super_agent/super_agent.py b/agents/super_agent/super_agent.py index 2f2056c..17ac7c6 100644 --- a/agents/super_agent/super_agent.py +++ b/agents/super_agent/super_agent.py @@ -62,7 +62,7 @@ def __init__(self): self._profile_interface: ProfileInterface = None self._progress = None self._util_threshold_calculator = None - self.pick_acceptence_pattern(random.randint(0,2)) + self.pick_acceptence_pattern(random.randint(0, 2)) self._protocol = None self._parameters: Parameters = None self._utility_space = None @@ -344,31 +344,39 @@ def is_good(self, bid): 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)'} + patterns_desc = {0: 'Noraml Decay', 1: 'Decaying with sinus', 2: 'Decaying with step (alpha changing)'} 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) + 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) + (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 - ( + (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) + (math.exp(3 * self._progress.get(get_ms_current_time())) - 1) / ( + math.exp(3) - 1) def on_negotiation_near_end(self): bid: Bid = None 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"}, } From c7030df9f33b2a757f7a694aa7e681f3e2f46785 Mon Sep 17 00:00:00 2001 From: Ben Nageris Date: Fri, 3 Jun 2022 10:38:40 +0300 Subject: [PATCH 4/9] fixed functions to pythonic conventions --- agents/super_agent/super_agent.py | 5 +++-- agents/super_agent/utils/persistent_data.py | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/agents/super_agent/super_agent.py b/agents/super_agent/super_agent.py index 754f456..d69b86e 100644 --- a/agents/super_agent/super_agent.py +++ b/agents/super_agent/super_agent.py @@ -121,8 +121,9 @@ def notifyChange(self, info: Inform): else: self._persistent_data = PersistentData() # TODO: add negotiondata - if "negotiationdata" in self._parameters.getParameters(): - self._data_paths_raw = self._parameters.get("negotiationdata") + if "storage_dir" in self._parameters.getParameters(): + self._storage_dir = self._parameters.get("storage_dir") + self._data_paths_raw = self._parameters.get("storage_dir") self._data_paths = [] if isinstance(self._data_paths_raw, List): for data_path in self._data_paths_raw: diff --git a/agents/super_agent/utils/persistent_data.py b/agents/super_agent/utils/persistent_data.py index bd9867c..af30515 100644 --- a/agents/super_agent/utils/persistent_data.py +++ b/agents/super_agent/utils/persistent_data.py @@ -29,20 +29,20 @@ def __init__(self): self._opponent_utility_by_time = defaultdict() def update(self, negotiation_data: NegotiationData): - new_util = negotiation_data.getAgreementUtil() if negotiation_data.getAgreementUtil() > 0 else ( + new_util = negotiation_data.get_agreement_util() if negotiation_data.get_agreement_util() > 0 else ( self._avg_utility - 1.1 * math.pow(self._std_utility, 2)) self._avg_utility = (self._avg_utility * self._negotiations + new_util) / (self._negotiations + 1) self._negotiations += 1 - self._nego_results.append(negotiation_data.getAgreementUtil()) + self._nego_results.append(negotiation_data.get_agreement_util()) self._std_utility = 0.0 for util in self._nego_results: self._std_utility += math.pow(util - self._avg_utility, 2) self._std_utility = math.sqrt(self._std_utility / self._negotiations) - opponent = negotiation_data.getOpponentName() + opponent = negotiation_data.get_opponent_name() if opponent is not None: encounters = self._opponent_encounters.get(opponent) if opponent in self._opponent_encounters else 0 @@ -52,10 +52,10 @@ def update(self, negotiation_data: NegotiationData): opponent) if opponent in self._avg_max_utility_opponent else 0.0 self._avg_max_utility_opponent[opponent] = ( - (self._avg_utility * encounters + negotiation_data.getMaxReceivedUtil()) / (encounters + 1)) + (self._avg_utility * encounters + negotiation_data.get_max_received_util()) / (encounters + 1)) avg_op_util = self._avg_opponent_utility.get(opponent) if opponent in self._avg_opponent_utility else 0.0 - self._avg_opponent_utility[opponent] = (avg_op_util * encounters + negotiation_data.getOpponentUtil()) / ( + self._avg_opponent_utility[opponent] = (avg_op_util * encounters + negotiation_data.get_opponent_util()) / ( encounters + 1) opponent_time_util: List[float] = [] @@ -64,7 +64,7 @@ def update(self, negotiation_data: NegotiationData): else: opponent_time_util = [0.0] * self._t_split - new_util_data: List[float] = negotiation_data.getOpponentUtilByTime() + new_util_data: List[float] = negotiation_data.get_opponent_util_by_time() ratio = ((1 - self._new_weight) * opponent_time_util[0] + self._new_weight * new_util_data[0]) / \ opponent_time_util[0] if opponent_time_util[0] > 0.0 else 1 From 7fc4428954e5cc836cc640bbd881291240b8b19f Mon Sep 17 00:00:00 2001 From: Ben Nageris Date: Fri, 3 Jun 2022 21:21:13 +0300 Subject: [PATCH 5/9] fixed negotiation data storage, wip: persistentdata --- agents/super_agent/super_agent.py | 273 +++++++++++-------- agents/super_agent/utils/negotiation_data.py | 17 +- 2 files changed, 164 insertions(+), 126 deletions(-) diff --git a/agents/super_agent/super_agent.py b/agents/super_agent/super_agent.py index d69b86e..6f75326 100644 --- a/agents/super_agent/super_agent.py +++ b/agents/super_agent/super_agent.py @@ -4,7 +4,9 @@ import os.path import random import sys -import json +# import json +import pickle +from pathlib import Path import uuid from typing import Dict, Any from time import time @@ -65,6 +67,7 @@ def __init__(self): self._parameters: Parameters = None self._utility_space = None self._domain = None + self._settings: Settings = None self._best_offer_bid: Bid = None self._profile = None @@ -73,7 +76,8 @@ def __init__(self): # NeogtiationData self._negotiation_data: NegotiationData = None self._data_paths_raw: List[str] = [] - self._data_paths: List[str] = [] + # self._data_paths: List[str] = [] + self._negotiation_data_paths: List[str] = [] self._opponent_name = None self._freq_map = defaultdict() self._avg_utility = 0.95 @@ -91,145 +95,169 @@ def __init__(self): self._max_bid_space_iteration = 50000 self._optimal_bid: Bid = None self._all_bid_list: AllBidsList = None + self._storage_dir: str = None + + def create_empty_negotiation_data(self, opponent_name): + self._negotiation_data = NegotiationData(opponent_name=opponent_name) + + def initialize_negotiation_data(self, opponent_name): + self._negotiation_data_paths = [] + data_path_raw = os.path.join(self._storage_dir, f"negotiation_data_{opponent_name}.log") + self._negotiation_data_paths.append(data_path_raw) + if self._negotiation_data is not None and os.path.exists(data_path_raw): + # print("non-empty NegotiationData") + with open(data_path_raw, "rb") as negotiation_data_file: + self._negotiation_data: NegotiationData = pickle.load(negotiation_data_file) + else: + # print("empty NegotiationData") + self.create_empty_negotiation_data(opponent_name=opponent_name) + + def initialize_persistent_data(self, opponent_name): + self._persistent_path = os.path.join(self._storage_dir, f"persistent_data_{opponent_name}.log") + if self._persistent_path is not None and os.path.exists(self._persistent_path): + # json load + # print("non-empty PersistentData") + with open(self._persistent_path, "rb") as persistent_file: + self._persistent_data: PersistentData = pickle.load(persistent_file) + self._avg_utility = self._persistent_data.get_avg_utility() + self._std_utility = self._persistent_data.get_std_utility() + print("avg: {} std: {}".format(self._avg_utility, self._std_utility * self._std_utility)) + else: + # print("empty PersistentData") + self._persistent_data: PersistentData = PersistentData() + + @classmethod + def parse_opponent_name(cls, full_opponent_name): + agent_index = full_opponent_name.rindex("_") + if agent_index != -1: + return full_opponent_name[:agent_index] + return None + + def initialize_storage(self, opponent_name): + self.initialize_persistent_data(opponent_name=opponent_name) + self.initialize_negotiation_data(opponent_name=opponent_name) # Override def notifyChange(self, info: Inform): # self.getReporter().log(logging.INFO, "received info:" + str(info)) if isinstance(info, Settings): + self.getReporter().log(logging.WARNING, "SETTINGS") settings: Settings = cast(Settings, info) + self._settings = settings self._me: PartyId = settings.getID() self._progress = settings.getProgress() - self._protocol = settings.getProtocol().getURI().getPath() + self._protocol = str(settings.getProtocol().getURI()) self._parameters = settings.getParameters() - - if "persistentstate" in self._parameters.getParameters(): - # TODO: fix persistent path initialization - persistent_state_path = self._parameters.get('persistentstate') - if isinstance(persistent_state_path, str): - persistent_state_path_str = cast(str, persistent_state_path) - path_persistent_state_uuid = uuid.UUID(persistent_state_path_str) - self._persistent_path = FileLocation(path_persistent_state_uuid).getFile() - else: - print("persistent_state in not string") - # print("persistent_space:{}".format(self._persistent_path)) - if self._persistent_path is not None and os.path.exists(self._persistent_path): - # json load - self._persistent_data: PersistentData = json.loads(self._persistent_path) - self._avg_utility = self._persistent_data.get_avg_utility() - self._std_utility = self._persistent_data.get_std_utility() - print("avg: {} std: {}".format(self._avg_utility, self._std_utility * self._std_utility)) - else: - self._persistent_data = PersistentData() - # TODO: add negotiondata if "storage_dir" in self._parameters.getParameters(): + self.getReporter().log(logging.INFO, "storage_dir is on parameters") self._storage_dir = self._parameters.get("storage_dir") - self._data_paths_raw = self._parameters.get("storage_dir") - self._data_paths = [] - if isinstance(self._data_paths_raw, List): - for data_path in self._data_paths_raw: - self._data_paths.append(FileLocation(uuid.UUID(data_path)).getFile()) + + try: + self._profile_interface: ProfileInterface = ProfileConnectionFactory.create( + settings.getProfile().getURI(), self.getReporter() + ) + self._profile = self._profile_interface.getProfile() + self._domain = self._profile.getDomain() + + if self._freq_map is None: + self._freq_map = defaultdict() else: - self.getReporter().log(logging.INFO, "negotiationdata param is not a list") - - if "Learn" == self._protocol: - # learning - self.learn() - self.getConnection().send(LearningDone(self._me)) - else: - # We are in the negotiation step. - # Obtain all of the issues in the current negotiation domain - self._negotiation_data = NegotiationData() - try: - self._profile_interface: ProfileInterface = ProfileConnectionFactory.create( - settings.getProfile().getURI(), self.getReporter() - ) - self._profile = self._profile_interface.getProfile() - self._domain = self._profile.getDomain() - - if self._freq_map is None: - self._freq_map = defaultdict() - else: - self._freq_map.clear() - - issues = self._domain.getIssues() - for issue in issues: - p = Pair() - - vs = self._domain.getValues(issue) - if isinstance(vs.get(0), DiscreteValue.DiscreteValue): - p.value_type = 0 - elif isinstance(vs.get(0), NumberValue.NumberValue): - p.value_type = 1 - for v in vs: - vstr = self.value_to_str(v, p) - p.vlist[vstr] = 0 - self._freq_map[issue] = p - - self._utility_space = self._profile_interface.getProfile() - self._all_bid_list: AllBidsList = AllBidsList(domain=self._domain) - r = self._max_bid_space_iteration > self._all_bid_list.size() - if r is True: - mx_util = 0 - bid_space_size = self._all_bid_list.size() - for i in range(bid_space_size): - bid = self._all_bid_list.get(i) - candidate = self._utility_space.getUtility(bid=bid) - if candidate > mx_util: - mx_util = candidate - self._optimal_bid = bid - else: - mx_util = 0 - bid_space_size = self._all_bid_list.size() - for attempt in range(self._max_bid_space_iteration): - i = random.randint(0, bid_space_size) - bid = self._all_bid_list.get(i) - candidate = self._utility_space.getUtility(bid=bid) - if candidate > mx_util: - mx_util = candidate - self._optimal_bid = bid - - except Exception as e: - print("error in settings:{}", e) - self.getReporter().log(logging.WARNING, "Error in {}".format(str(e))) + self._freq_map.clear() + + issues = self._domain.getIssues() + for issue in issues: + p = Pair() + + vs = self._domain.getValues(issue) + if isinstance(vs.get(0), DiscreteValue.DiscreteValue): + p.value_type = 0 + elif isinstance(vs.get(0), NumberValue.NumberValue): + p.value_type = 1 + for v in vs: + vstr = self.value_to_str(v, p) + p.vlist[vstr] = 0 + self._freq_map[issue] = p + + self._utility_space = self._profile_interface.getProfile() + self._all_bid_list: AllBidsList = AllBidsList(domain=self._domain) + r = self._max_bid_space_iteration > self._all_bid_list.size() + if r is True: + mx_util = 0 + bid_space_size = self._all_bid_list.size() + for i in range(bid_space_size): + bid = self._all_bid_list.get(i) + candidate = self._utility_space.getUtility(bid=bid) + if candidate > mx_util: + mx_util = candidate + self._optimal_bid = bid + else: + mx_util = 0 + bid_space_size = self._all_bid_list.size() + for attempt in range(self._max_bid_space_iteration): + i = random.randint(0, bid_space_size) + bid = self._all_bid_list.get(i) + candidate = self._utility_space.getUtility(bid=bid) + if candidate > mx_util: + mx_util = candidate + self._optimal_bid = bid + + except Exception as e: + print("error in settings:{}", e) + self.getReporter().log(logging.WARNING, "Error in {}".format(str(e))) elif isinstance(info, ActionDone): + self.getReporter().log(logging.WARNING, "ActionDone") # TODO: initalizie with negotiaiondata action: Action = cast(ActionDone, info).getAction() if self._me is not None and self._me != action.getActor(): - if self._opponent_name is None: - full_opponent_name = action.getActor().getName() - agent_index = full_opponent_name.rindex("_") - if agent_index != -1: - # which means index found - self._opponent_name = full_opponent_name[:agent_index] - self._negotiation_data.set_opponent_name(self._opponent_name) - self.op_threshold = self._persistent_data.get_smooth_threshold_over_time(self._opponent_name - ) - if self.op_threshold is not None: - for i in range(1, self.t_split): - self.op_threshold[i] = self.op_threshold[i] if self.op_threshold[i] > 0 else \ - self.op_threshold[i - 1] - self.alpha = self._persistent_data.get_opponent_alpha(self._opponent_name) - self.alpha = self.alpha if self.alpha > 0.0 else self.default_alpha + opponent_name = self.parse_opponent_name(full_opponent_name=action.getActor().getName()) + if self._opponent_name is None and opponent_name is not None: + self.initialize_storage(opponent_name) + # which means index found + self._opponent_name = opponent_name + self._negotiation_data.set_opponent_name(self._opponent_name) + + self.op_threshold = self._persistent_data.get_smooth_threshold_over_time(self._opponent_name + ) + if self.op_threshold is not None: + for i in range(1, self.t_split): + self.op_threshold[i] = self.op_threshold[i] if self.op_threshold[i] > 0 else \ + self.op_threshold[i - 1] + self.alpha = self._persistent_data.get_opponent_alpha(self._opponent_name) + self.alpha = self.alpha if self.alpha > 0.0 else self.default_alpha self.process_action(action) elif isinstance(info, YourTurn): # This is a super party + self.getReporter().log(logging.WARNING, "YourTurn") if isinstance(self._progress, ProgressRounds): self._progress = self._progress.advance() + self.getReporter().log(logging.WARNING, + "is NULL:{}:{}".format(self._persistent_data is None, self._opponent_name)) + + # self.initialize_storage(self._opponent_name) action = self._my_turn() val(self.getConnection()).send(action) elif isinstance(info, Finished): + self.getReporter().log(logging.WARNING, "Finished") self.terminate() + # self.getReporter().log(logging.WARNING, "Finished " + str(info)) # TODO:: handle NEGOTIATIONDATA finished_info = cast(Finished, info) agreements: Agreements = finished_info.getAgreements() self.process_agreements(agreements) - if self._data_paths is not None and len(self._data_paths) != 0 and self._negotiation_data is not None: - with open(self._data_paths[0]) as pers_file: - json.dump(self._negotiation_data, pers_file) - + self.learn() + print("datapath len:{}".format(len(self._negotiation_data_paths))) + if self._negotiation_data_paths is not None and len( + self._negotiation_data_paths) > 0 and self._negotiation_data is not None: + for negotiation_path in self._negotiation_data_paths: + try: + with open(negotiation_path, "wb") as negotiation_file: + pickle.dump(self._negotiation_data, negotiation_file) + + except Exception as e: + self.getReporter().log(logging.WARNING, "Error in {}".format(str(e))) self.terminate() else: self.getReporter().log( @@ -338,7 +366,7 @@ def is_good(self, bid): 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.alpha) - 1) if self._util_threshold < self._min_utility: self._util_threshold = self._min_utility @@ -390,6 +418,9 @@ def _find_bid(self): def _my_turn(self): # save average of the last avgSplit offers (only when frequency table is stabilized) + if self._opponent_name is None: + return Offer(self._me, self._optimal_bid) + if self.is_near_negotiation_end(): index = int( (self.t_split - 1) / (1 - self.t_phase) * (self._progress.get(get_ms_current_time()) - self.t_phase)) @@ -404,18 +435,22 @@ def _my_turn(self): def learn(self): self.getReporter().log(logging.INFO, "party is learning") - for path in self._data_paths: + # probably have to shift to self._negotiation_data_paths + for path in self._negotiation_data_paths: try: - with open(path) as f: - nego_data = json.load(f) - self._persistent_data.update(nego_data) + with open(path, "rb") as f: + nego_data = pickle.load(f) + self._persistent_data.update(nego_data) except: - raise Exception(f"Negotiation data path {0} does not exist".format(path)) + print("a") + # raise Exception(f"Negotiation data path {path} does not exist") try: - with open(self._persistent_path) as pers_file: - json.dump(self._persistent_data, pers_file) - except: - raise Exception(f"Failed to write persistent data to path: {0}".format(self._persistent_path)) + with open(self._persistent_path, "wb") as pers_file: + pickle.dump(self._persistent_data, pers_file) + # json.dump(self._persistent_data, pers_file) + except Exception as e: + print("error in persistent path dump:{}", str(e)) + # raise Exception(f"Failed to write persistent data to path: {0}".format(self._persistent_path)) def process_agreements(self, agreements: Agreements): # Check if we reached an agreement (walking away or passing the deadline diff --git a/agents/super_agent/utils/negotiation_data.py b/agents/super_agent/utils/negotiation_data.py index 6def42b..a824270 100644 --- a/agents/super_agent/utils/negotiation_data.py +++ b/agents/super_agent/utils/negotiation_data.py @@ -4,13 +4,16 @@ class NegotiationData: tSplit: int = 40 - def __init__(self): - self._max_received_util: float = 0.0 - self._agreement_util: float = 0.0 - self._opponent_name: str = '' - - self._opponent_util: float = 0.0 - self._opponent_util_by_time: List[float] = [0.0] * NegotiationData.tSplit + def __init__(self, max_received_util=0.0, agreement_util=0.0, opponent_name='', opponent_util=0.0, + opponent_util_by_time=None): + self._max_received_util: float = max_received_util + self._agreement_util: float = agreement_util + self._opponent_name: str = opponent_name + self._opponent_util: float = opponent_util + if opponent_util_by_time is None: + self._opponent_util_by_time: List[float] = [0.0] * NegotiationData.tSplit + else: + self._opponent_util_by_time: List[float] = opponent_util_by_time def add_agreement_util(self, agreement_util: float): self._agreement_util = agreement_util From dc620a2e5229f2eb8522a4cb0457c04bcd68f0ad Mon Sep 17 00:00:00 2001 From: Ben Nageris Date: Sat, 4 Jun 2022 17:56:54 +0300 Subject: [PATCH 6/9] no social --- agents/super_agent/super_agent.py | 61 +++++++++++++++++++------------ 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/agents/super_agent/super_agent.py b/agents/super_agent/super_agent.py index 6f75326..41763f5 100644 --- a/agents/super_agent/super_agent.py +++ b/agents/super_agent/super_agent.py @@ -91,6 +91,7 @@ def __init__(self): self.op_sum = [0.0] * self.t_split self.op_threshold = [0.0] * self.t_split self.t_phase = 0.5 + self.t_social_welfare = 0.995 self._max_bid_space_iteration = 50000 self._optimal_bid: Bid = None @@ -141,7 +142,7 @@ def initialize_storage(self, opponent_name): def notifyChange(self, info: Inform): # self.getReporter().log(logging.INFO, "received info:" + str(info)) if isinstance(info, Settings): - self.getReporter().log(logging.WARNING, "SETTINGS") + # self.getReporter().log(logging.WARNING, "SETTINGS") settings: Settings = cast(Settings, info) self._settings = settings self._me: PartyId = settings.getID() @@ -206,7 +207,7 @@ def notifyChange(self, info: Inform): self.getReporter().log(logging.WARNING, "Error in {}".format(str(e))) elif isinstance(info, ActionDone): - self.getReporter().log(logging.WARNING, "ActionDone") + # self.getReporter().log(logging.WARNING, "ActionDone") # TODO: initalizie with negotiaiondata action: Action = cast(ActionDone, info).getAction() if self._me is not None and self._me != action.getActor(): @@ -229,18 +230,15 @@ def notifyChange(self, info: Inform): elif isinstance(info, YourTurn): # This is a super party - self.getReporter().log(logging.WARNING, "YourTurn") + # self.getReporter().log(logging.WARNING, "YourTurn") if isinstance(self._progress, ProgressRounds): self._progress = self._progress.advance() - self.getReporter().log(logging.WARNING, - "is NULL:{}:{}".format(self._persistent_data is None, self._opponent_name)) - # self.initialize_storage(self._opponent_name) action = self._my_turn() val(self.getConnection()).send(action) elif isinstance(info, Finished): - self.getReporter().log(logging.WARNING, "Finished") + # self.getReporter().log(logging.WARNING, "Finished") self.terminate() # self.getReporter().log(logging.WARNING, "Finished " + str(info)) # TODO:: handle NEGOTIATIONDATA @@ -347,15 +345,21 @@ def is_op_good(self, bid: Bid): # index = (int)((t_split - 1) / (1 - t_phase) * (progress.get(System.currentTimeMillis()) - t_phase)); def is_near_negotiation_end(self): - # self.getReporter().log(logging.WARNING, - # "is nego near end:{} :{}".format(self._progress.get(get_ms_current_time()), - # self.t_phase)) return self._progress.get(time() * 1000) > self.t_phase + def is_social_welfare_time(self): + return self._progress.get(time() * 1000) > self.t_social_welfare + def calc_utility(self, bid): # get utility from utility space return self._utility_space.getUtility(bid) + def calc_social_welfare(self, bid: Bid): + return 0.6 * self.calc_utility(bid) + math.fabs(1 - 0.6) * self.calc_op_value(bid) + + def cmp_social_welfare(self, first_bid, second_bid): + return self.calc_social_welfare(first_bid) >= self.calc_social_welfare(second_bid) + def is_good(self, bid): if bid is None: return False @@ -372,6 +376,16 @@ def is_good(self, bid): return float(self.calc_utility(bid)) >= self._util_threshold + def on_negotiation_social_welfare(self): + bid: Bid = None + for attempt in range(5000): + if self.is_good(bid): + break + idx = random.randint(0, self._all_bid_list.size()) + bid = self._all_bid_list.get(idx) + if not self.is_good(bid): + bid = self._optimal_bid + return bid def on_negotiation_near_end(self): bid: Bid = None for attempt in range(1000): @@ -408,6 +422,8 @@ 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: @@ -441,29 +457,28 @@ def learn(self): with open(path, "rb") as f: nego_data = pickle.load(f) self._persistent_data.update(nego_data) - except: - print("a") - # raise Exception(f"Negotiation data path {path} does not exist") + except Exception as e: + print("error in learn function - persistent data update, error:{}", str(e)) + try: with open(self._persistent_path, "wb") as pers_file: pickle.dump(self._persistent_data, pers_file) - # json.dump(self._persistent_data, pers_file) except Exception as e: print("error in persistent path dump:{}", str(e)) - # raise Exception(f"Failed to write persistent data to path: {0}".format(self._persistent_path)) def process_agreements(self, agreements: Agreements): # Check if we reached an agreement (walking away or passing the deadline # results in no agreement) + self.getReporter().log(logging.INFO, "Length of agreements: {} :{}".format(len(agreements.getMap().items()),agreements.getMap())) if len(agreements.getMap().items()) > 0: # Get the bid that is agreed upon and add it's value to our negotiation data - agreement: Bid = agreements.getMap().values().__iter__().__next__() - self._negotiation_data.add_agreement_util(float(self.calc_utility(agreement))) - self._negotiation_data.set_opponent_util(self.calc_op_value(agreement)) - - self.getReporter().log(logging.INFO, "MY OWN THRESHOLD: {}".format(self._util_threshold)) - self.getReporter().log(logging.INFO, "MY OWN UTIL:{}".format(self._utility_space.getUtility(agreement))) - self.getReporter().log(logging.INFO, "EXP OPPONENT UTIL:".format(self.calc_op_value(agreement))) + for agreement in agreements.getMap().values(): + # agreement: Bid = agreements.getMap().values().__iter__().__next__() + self._negotiation_data.add_agreement_util(float(self.calc_utility(agreement))) + self._negotiation_data.set_opponent_util(self.calc_op_value(agreement)) + self.getReporter().log(logging.INFO, "MY OWN THRESHOLD: {}".format(self._util_threshold)) + self.getReporter().log(logging.INFO, "MY OWN UTIL:{}".format(self.calc_utility(agreement))) + self.getReporter().log(logging.INFO, "EXP OPPONENT UTIL:{}".format(self.calc_op_value(agreement))) else: if self._best_offer_bid is not None: self._negotiation_data.add_agreement_util(float(self.calc_utility(self._best_offer_bid))) @@ -476,4 +491,4 @@ def process_agreements(self, agreements: Agreements): try: self._negotiation_data.update_opponent_offers(self.op_sum, self.op_counter) except Exception as e: - self.getReporter().log(logging.INFO, "Error in process_agreements") + self.getReporter().log(logging.INFO, "Error in process_agreements,{}".format(str(e))) From 0526865480f1d1ab5b198bc10614cb9e467a85e8 Mon Sep 17 00:00:00 2001 From: Ben Nageris Date: Sun, 5 Jun 2022 02:11:35 +0300 Subject: [PATCH 7/9] added sorted bif list and useage in on_negotation functions instead of randomize bids --- agents/super_agent/super_agent.py | 119 +++++++++++++----------------- 1 file changed, 52 insertions(+), 67 deletions(-) diff --git a/agents/super_agent/super_agent.py b/agents/super_agent/super_agent.py index 41763f5..e0cd2ab 100644 --- a/agents/super_agent/super_agent.py +++ b/agents/super_agent/super_agent.py @@ -91,11 +91,13 @@ def __init__(self): self.op_sum = [0.0] * self.t_split self.op_threshold = [0.0] * self.t_split self.t_phase = 0.5 - self.t_social_welfare = 0.995 + self.t_social_welfare = 0.997 self._max_bid_space_iteration = 50000 self._optimal_bid: Bid = None self._all_bid_list: AllBidsList = None + self._sorted_bid_list: List = None + self._len_sorted_bid_list: int = 0 self._storage_dir: str = None def create_empty_negotiation_data(self, opponent_name): @@ -122,9 +124,7 @@ def initialize_persistent_data(self, opponent_name): self._persistent_data: PersistentData = pickle.load(persistent_file) self._avg_utility = self._persistent_data.get_avg_utility() self._std_utility = self._persistent_data.get_std_utility() - print("avg: {} std: {}".format(self._avg_utility, self._std_utility * self._std_utility)) else: - # print("empty PersistentData") self._persistent_data: PersistentData = PersistentData() @classmethod @@ -135,8 +135,12 @@ def parse_opponent_name(cls, full_opponent_name): return None def initialize_storage(self, opponent_name): - self.initialize_persistent_data(opponent_name=opponent_name) - self.initialize_negotiation_data(opponent_name=opponent_name) + if self._storage_dir is not None: + self.initialize_persistent_data(opponent_name=opponent_name) + self.initialize_negotiation_data(opponent_name=opponent_name) + else: + self.create_empty_negotiation_data(opponent_name=opponent_name) + self._persistent_data: PersistentData = PersistentData() # Override def notifyChange(self, info: Inform): @@ -168,7 +172,6 @@ def notifyChange(self, info: Inform): issues = self._domain.getIssues() for issue in issues: p = Pair() - vs = self._domain.getValues(issue) if isinstance(vs.get(0), DiscreteValue.DiscreteValue): p.value_type = 0 @@ -181,26 +184,11 @@ def notifyChange(self, info: Inform): self._utility_space = self._profile_interface.getProfile() self._all_bid_list: AllBidsList = AllBidsList(domain=self._domain) - r = self._max_bid_space_iteration > self._all_bid_list.size() - if r is True: - mx_util = 0 - bid_space_size = self._all_bid_list.size() - for i in range(bid_space_size): - bid = self._all_bid_list.get(i) - candidate = self._utility_space.getUtility(bid=bid) - if candidate > mx_util: - mx_util = candidate - self._optimal_bid = bid - else: - mx_util = 0 - bid_space_size = self._all_bid_list.size() - for attempt in range(self._max_bid_space_iteration): - i = random.randint(0, bid_space_size) - bid = self._all_bid_list.get(i) - candidate = self._utility_space.getUtility(bid=bid) - if candidate > mx_util: - mx_util = candidate - self._optimal_bid = bid + self._sorted_bid_list = sorted(AllBidsList(domain=self._domain), + key=self._utility_space.getUtility, reverse=True) + self._len_sorted_bid_list = len(self._sorted_bid_list) + # after sort of bid list the optimal bid is in the first element + self._optimal_bid = self._sorted_bid_list[0] except Exception as e: print("error in settings:{}", e) @@ -238,22 +226,17 @@ def notifyChange(self, info: Inform): val(self.getConnection()).send(action) elif isinstance(info, Finished): - # self.getReporter().log(logging.WARNING, "Finished") - self.terminate() - # self.getReporter().log(logging.WARNING, "Finished " + str(info)) # TODO:: handle NEGOTIATIONDATA finished_info = cast(Finished, info) agreements: Agreements = finished_info.getAgreements() self.process_agreements(agreements) self.learn() - print("datapath len:{}".format(len(self._negotiation_data_paths))) if self._negotiation_data_paths is not None and len( self._negotiation_data_paths) > 0 and self._negotiation_data is not None: for negotiation_path in self._negotiation_data_paths: try: with open(negotiation_path, "wb") as negotiation_file: pickle.dump(self._negotiation_data, negotiation_file) - except Exception as e: self.getReporter().log(logging.WARNING, "Error in {}".format(str(e))) self.terminate() @@ -355,7 +338,7 @@ def calc_utility(self, bid): return self._utility_space.getUtility(bid) def calc_social_welfare(self, bid: Bid): - return 0.6 * self.calc_utility(bid) + math.fabs(1 - 0.6) * self.calc_op_value(bid) + return 0.8 * float(self.calc_utility(bid)) + math.fabs(1 - 0.8) * float(self.calc_op_value(bid)) def cmp_social_welfare(self, first_bid, second_bid): return self.calc_social_welfare(first_bid) >= self.calc_social_welfare(second_bid) @@ -373,43 +356,45 @@ def is_good(self, bid): self.alpha) - 1) if self._util_threshold < self._min_utility: self._util_threshold = self._min_utility - return float(self.calc_utility(bid)) >= self._util_threshold - def on_negotiation_social_welfare(self): - bid: Bid = None - for attempt in range(5000): - if self.is_good(bid): - break - idx = random.randint(0, self._all_bid_list.size()) - bid = self._all_bid_list.get(idx) - if not self.is_good(bid): - bid = self._optimal_bid - return bid + 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): - bid: Bid = None - for attempt in range(1000): - if self.is_good(bid): - break - idx = random.randint(0, self._all_bid_list.size()) - bid = self._all_bid_list.get(idx) - if not self.is_good(bid): - bid = self._optimal_bid - return bid + 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): + return self._best_offer_bid + return self._sorted_bid_list[idx] def on_negotiation_continues(self): bid: Bid = None - for attempt in range(1000): - if self._optimal_bid is None: - self.getReporter().log(logging.INFO, "optimal bid is none") - if bid == self._optimal_bid or self.is_good(bid) or self.is_op_good(bid): + + slice_idx = self.first_is_good_idx() + end_slice = int(min(slice_idx + 0.005 * self._len_sorted_bid_list - 1, self._len_sorted_bid_list - 1)) + for i in range(end_slice, 0, -1): + tmp_bid = self._sorted_bid_list[i] + if tmp_bid == self._optimal_bid or self.is_good(tmp_bid) or self.is_op_good(tmp_bid): + bid = tmp_bid break - idx = random.randint(0, self._all_bid_list.size()) - bid = self._all_bid_list.get(idx) if self._progress.get(get_ms_current_time()) > 0.99 and self.is_good(self._best_offer_bid): bid = self._best_offer_bid if not self.is_good(bid): - bid = self._optimal_bid + idx = random.randint(0, slice_idx) + bid = self._sorted_bid_list[idx] return bid def cmp_utility(self, first_bid, second_bid): @@ -469,16 +454,16 @@ def learn(self): def process_agreements(self, agreements: Agreements): # Check if we reached an agreement (walking away or passing the deadline # results in no agreement) - self.getReporter().log(logging.INFO, "Length of agreements: {} :{}".format(len(agreements.getMap().items()),agreements.getMap())) + self.getReporter().log(logging.INFO, "Length of agreements: {} :{}".format(len(agreements.getMap().items()), + agreements.getMap())) if len(agreements.getMap().items()) > 0: # Get the bid that is agreed upon and add it's value to our negotiation data - for agreement in agreements.getMap().values(): - # agreement: Bid = agreements.getMap().values().__iter__().__next__() - self._negotiation_data.add_agreement_util(float(self.calc_utility(agreement))) - self._negotiation_data.set_opponent_util(self.calc_op_value(agreement)) - self.getReporter().log(logging.INFO, "MY OWN THRESHOLD: {}".format(self._util_threshold)) - self.getReporter().log(logging.INFO, "MY OWN UTIL:{}".format(self.calc_utility(agreement))) - self.getReporter().log(logging.INFO, "EXP OPPONENT UTIL:{}".format(self.calc_op_value(agreement))) + agreement: Bid = agreements.getMap().values().__iter__().__next__() + self._negotiation_data.add_agreement_util(float(self.calc_utility(agreement))) + self._negotiation_data.set_opponent_util(self.calc_op_value(agreement)) + self.getReporter().log(logging.INFO, "MY OWN THRESHOLD: {}".format(self._util_threshold)) + self.getReporter().log(logging.INFO, "MY OWN UTIL:{}".format(self.calc_utility(agreement))) + self.getReporter().log(logging.INFO, "EXP OPPONENT UTIL:{}".format(self.calc_op_value(agreement))) else: if self._best_offer_bid is not None: self._negotiation_data.add_agreement_util(float(self.calc_utility(self._best_offer_bid))) From 12ab82c63d4bd1f73f73563c43254558968c7ca7 Mon Sep 17 00:00:00 2001 From: Ben Nageris Date: Sun, 5 Jun 2022 09:11:51 +0300 Subject: [PATCH 8/9] removed unused imports --- agents/super_agent/super_agent.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/agents/super_agent/super_agent.py b/agents/super_agent/super_agent.py index e0cd2ab..84751d6 100644 --- a/agents/super_agent/super_agent.py +++ b/agents/super_agent/super_agent.py @@ -1,26 +1,16 @@ -import json import logging import math import os.path import random -import sys -# import json import pickle -from pathlib import Path -import uuid -from typing import Dict, Any from time import time from typing import cast from collections import defaultdict from typing import List -from geniusweb.actions.ActionWithBid import ActionWithBid from geniusweb.profileconnection.ProfileInterface import ProfileInterface from geniusweb.actions.Accept import Accept from geniusweb.actions.Action import Action from geniusweb.actions.Offer import Offer -from geniusweb.actions.LearningDone import LearningDone -from geniusweb.actions.FileLocation import FileLocation -from geniusweb.issuevalue.Domain import Domain from geniusweb.actions.PartyId import PartyId from geniusweb.inform.ActionDone import ActionDone from geniusweb.inform.Finished import Finished @@ -35,10 +25,8 @@ from geniusweb.issuevalue.Value import Value from geniusweb.issuevalue import DiscreteValue from geniusweb.issuevalue import NumberValue -from geniusweb.profile.utilityspace.LinearAdditive import LinearAdditive from geniusweb.inform.Agreements import Agreements from geniusweb.references.Parameters import Parameters -from geniusweb.profile.utilityspace.UtilitySpace import UtilitySpace from geniusweb.profileconnection.ProfileConnectionFactory import ( ProfileConnectionFactory, ) From 832abed87da6b1dc8f694410be28eb8febfda5a5 Mon Sep 17 00:00:00 2001 From: yokkon <0506422606e@gmail.com> Date: Sun, 5 Jun 2022 21:39:09 +0300 Subject: [PATCH 9/9] Finished 5 different threshold patterns --- agents/super_agent/super_agent.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/agents/super_agent/super_agent.py b/agents/super_agent/super_agent.py index 17ac7c6..22feda7 100644 --- a/agents/super_agent/super_agent.py +++ b/agents/super_agent/super_agent.py @@ -62,7 +62,7 @@ def __init__(self): self._profile_interface: ProfileInterface = None self._progress = None self._util_threshold_calculator = None - self.pick_acceptence_pattern(random.randint(0, 2)) + self.pick_acceptence_pattern(random.randint(0, 4)) self._protocol = None self._parameters: Parameters = None self._utility_space = None @@ -344,7 +344,7 @@ def is_good(self, bid): 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)'} + 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 - ( @@ -378,6 +378,22 @@ def pick_acceptence_pattern(self, pattern): (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 on_negotiation_near_end(self): bid: Bid = None for attempt in range(1000):