Example #1
0
    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)
Example #2
0
    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")