def cal_score(self): distance = self.__how_far_are_agents( ) #which will be greater than or equal to zero. if distance: negotiations = SYSTEM.get_total_negotiation( self.agent1.agent_id, self.agent2.agent_id) part_a = (negotiations[1] - negotiations[2]) / float( negotiations[0]) part_b = SYSTEM.get_fraction_change_in_price(self.entity.name) part_b *= -1 if self.type_of_action == 'BUY' else part_b part_c = 0 entity_global_avg_price = SYSTEM.get_entity_global_average_price( self.entity.name) if self.type_of_action == 'BUY': buying_amount = self.agent1.get_entity_buying_amount( self.entity.name) if buying_amount != None and entity_global_avg_price != None and buying_amount != 0: part_c = (buying_amount - entity_global_avg_price) / float(buying_amount) else: selling_amount = self.agent1.get_entity_selling_amount( self.entity.name) if selling_amount != None and entity_global_avg_price != None and selling_amount != 0: part_c = (entity_global_avg_price - selling_amount) / float(selling_amount) self.score = (self.part_0 + part_a + part_b + part_c) / float(distance) self.part_a = part_a self.part_b = part_b self.part_c = part_c self.md = float(distance)
def decline(self): from main import SYSTEM self.other_agent.state = RandomWalkState(this_agent=self.other_agent) self.this_agent.state = RandomWalkState(this_agent=self.this_agent) # print("Trade cancelled between agent {0} and agent {1} after {2} turn{3}.".format( # self.this_agent.name, # self.other_agent.name, # self.duration, # ('' if self.duration == 1 else 's'))) SYSTEM.update_negotiation_happened(self.this_agent.agent_id,self.other_agent.agent_id,False) #This means negative negotiation happend
def create_selling_arguments_for_agent(self): selling_arguments = [] all_other_agents = SYSTEM.get_all_agents_in_list( except_agents=[self.asking_agent.name]) all_entities = SYSTEM.get_all_entities() for agent in all_other_agents: for entity in all_entities: selling_arguments.append( ArgumentSet('SELL', self.asking_agent, agent, entity)) return selling_arguments
def accept(self): from main import SYSTEM transaction_money = self.price_each * self.quantity self.this_agent.money -= transaction_money self.this_agent.entities_info[self.fruit]['quantity'] += self.quantity self.other_agent.money+=transaction_money self.other_agent.entities_info[self.fruit]['quantity'] -= self.quantity self.other_agent.state = RandomWalkState(this_agent=self.other_agent) self.this_agent.state = RandomWalkState(this_agent=self.this_agent) SYSTEM.update_negotiation_happened(self.this_agent.agent_id, self.other_agent.agent_id, True) # This means positive negotiation happend SYSTEM.update_entity_global_average_price(self.fruit,self.price_each,self.quantity)
def make_csv(self, all_agents, sort_by): from main import SYSTEM df = pd.DataFrame(columns=[ 'elasticity', 'patience', 'money', 'Total Negotiations', 'Total Positive', 'Total Negative', 'Entities Value Start', 'Entities Value End', 'Total Final Value', 'Total Starting Value', 'Earnings' ]) for agent in enumerate(all_agents): negotiation_param = SYSTEM.get_negotiations_parameter_of_agent( agent[1].agent_id) entities_value_in_start = agent[1].cal_entities_value_in_start() entities_of_agent = agent[1].entities_info.items() total_quantity_price = 0 for entity_name, _ in entities_of_agent: entity_info = agent[1].entities_info[entity_name] if entity_info['isInterested']: gap = SYSTEM.get_entity_global_average_price(entity_name) if gap is None: gap = (entity_info['min_selling_price'] + entity_info['max_buying_price']) / 2 total_quantity_price += gap * entity_info['quantity'] val_start = constants.MONEY + entities_value_in_start val_end = agent[1].money + total_quantity_price df.loc[agent[0]] = [ agent[1].elasticity, agent[1].patience, agent[1].money, negotiation_param[0], negotiation_param[1], negotiation_param[2], entities_value_in_start, total_quantity_price, val_end, val_start, val_end - val_start ] df = df.sort_values(sort_by) print(df) df.to_csv('results/' + str(datetime.datetime.now()) + ".csv")