Пример #1
0
 def __init__(self):
     self.schedule = RandomActivation(self)
     self.__messages_service = MessageService(self.schedule)
     for i in range(2):
         a = TestAgent(i, self, "Agent" + str(i))
         self.schedule.add(a)
     self.running = True
class ArgumentModel(Model):
    """ ArgumentModel which inherit from Model.
    """
    def __init__(self):
        self.schedule = RandomActivation(self)
        self.__messages_service = MessageService(self.schedule)

        # To be completed

        self.list_items = []

        a = ArgumentAgent(next(), self, "alice")
        a.generate_preferences()
        self.schedule.add(a)

        b = ArgumentAgent(next(), self, "bob")
        b.generate_preferences()
        self.schedule.add(b)

        self.running = True

    def step(self):
        self.__messages_service.dispatch_messages()
        self.schedule.step()

    def get_list_items(self):
        return self.list_items
Пример #3
0
    def __init__(self, nb_items):
        self.schedule = RandomActivation(self)
        self.__messages_service = MessageService(self.schedule)
        self.next_id = 0
        self.step_index = 0
        criterions = [
            CriterionName.ENVIRONMENT_IMPACT, CriterionName.NOISE,
            CriterionName.CONSUMPTION, CriterionName.DURABILITY,
            CriterionName.PRODUCTION_COST
        ]
        self.random.shuffle(criterions)
        self.agent1 = ArgumentAgent(self.get_next_id(), self, "agent1",
                                    criterions)
        self.random.shuffle(criterions)
        self.agent2 = ArgumentAgent(self.get_next_id(), self, "agent2",
                                    criterions)

        items = [
            Item("Item{}".format(self.get_next_id()), "Some random item")
            for _ in range(nb_items)
        ]

        for item in items:
            self.agent1.generate_random_preferences(item)
            self.agent2.generate_random_preferences(item)

        self.schedule.add(self.agent1)
        self.schedule.add(self.agent2)
        self.running = True

        self.agent1.propose_preferred_item("agent2")
Пример #4
0
 def __init__(self):
     self.schedule = RandomActivation(self)
     self.__messages_service = MessageService(self.schedule)
     Item1 = Item('Item1', description='first item')
     Item2 = Item('Item2', description='second item')
     self.list_items = [Item1, Item2]
     for i in range(2):
         a = ArgumentAgent(i, self, "Agent" + str(i), self.list_items)
         self.schedule.add(a)
     self.running = True
Пример #5
0
    def __init__(self):
        self.schedule = RandomActivation(self)
        self.__messages_service = MessageService(self.schedule)

        # To be completed
        # list_items = [...]
        #
        # a = ArgumentAgent(id, "agent_name")
        # a.generate_preferences(preferences)
        # self.schedule.add(a)
        # ...

        self.running = True
Пример #6
0
class TestModel(Model):
    """ TestModel which inherit from Model to test CommunicatingAgent and MessageService.
    """
    def __init__(self):
        self.schedule = RandomActivation(self)
        self.__messages_service = MessageService(self.schedule)
        for i in range(2):
            a = TestAgent(i, self, "Agent" + str(i))
            self.schedule.add(a)
        self.running = True

    def step(self):
        self.__messages_service.dispatch_messages()
        self.schedule.step()
Пример #7
0
 def __init__(self, unique_id, model, name):
     """ Create a new communicating agent.
     """
     super().__init__(unique_id, model)
     self.__name = name
     self.__mailbox = Mailbox()
     self.__messages_service = MessageService.get_instance()
    def __init__(self):
        self.schedule = RandomActivation(self)
        self.__messages_service = MessageService(self.schedule)

        # To be completed

        self.list_items = []

        a = ArgumentAgent(next(), self, "alice")
        a.generate_preferences()
        self.schedule.add(a)

        b = ArgumentAgent(next(), self, "bob")
        b.generate_preferences()
        self.schedule.add(b)

        self.running = True
Пример #9
0
class ArgumentModel(Model):
    """ ArgumentModel which inherit from Model.
    """
    def __init__(self):
        self.schedule = RandomActivation(self)
        self.__messages_service = MessageService(self.schedule)
        Item1 = Item('Item1', description='first item')
        Item2 = Item('Item2', description='second item')
        self.list_items = [Item1, Item2]
        for i in range(2):
            a = ArgumentAgent(i, self, "Agent" + str(i), self.list_items)
            self.schedule.add(a)
        self.running = True

    def step(self):
        self.__messages_service.dispatch_messages()
        self.schedule.step()
Пример #10
0
class ArgumentModel(Model):
    """ ArgumentModel which inherit from Model.
    """
    def __init__(self):
        self.schedule = RandomActivation(self)
        self.__messages_service = MessageService(self.schedule)

        # To be completed
        # list_items = [...]
        #
        # a = ArgumentAgent(id, "agent_name")
        # a.generate_preferences(preferences)
        # self.schedule.add(a)
        # ...

        self.running = True

    def step(self):
        self.__messages_service.dispatch_messages()
        self.schedule.step()
Пример #11
0
    assert(agent0.get_name() == "Agent0")
    assert(agent1.get_name() == "Agent1")
    print("*     get_name() => OK")

    agent0.send_message(Message("Agent0", "Agent1", MessagePerformative.COMMIT, "Bonjour"))
    agent1.send_message(Message("Agent1", "Agent0", MessagePerformative.COMMIT, "Bonjour"))
    agent0.send_message(Message("Agent0", "Agent1", MessagePerformative.COMMIT, "Comment ça va ?"))

    assert(len(agent0.get_new_messages()) == 1)
    assert(len(agent1.get_new_messages()) == 2)
    assert(len(agent0.get_messages()) == 1)
    assert(len(agent1.get_messages()) == 2)
    print("*     send_message() & dispatch_message (instant delivery) => OK")

    MessageService.get_instance().set_instant_delivery(False)

    agent0.send_message(Message("Agent0", "Agent1", MessagePerformative.COMMIT, "Bonjour"))
    agent1.send_message(Message("Agent1", "Agent0", MessagePerformative.COMMIT, "Bonjour"))
    agent0.send_message(Message("Agent0", "Agent1", MessagePerformative.COMMIT, "Comment ça va ?"))

    assert(len(agent0.get_messages()) == 1)
    assert(len(agent1.get_messages()) == 2)

    communicating_model.step()

    assert(len(agent0.get_new_messages()) == 1)
    assert(len(agent1.get_new_messages()) == 2)
    assert(len(agent0.get_messages()) == 2)
    assert(len(agent1.get_messages()) == 4)
    print("*     send_message() & dispatch_messages => OK")
Пример #12
0
class ArgumentModel(Model):
    """ ArgumentModel which inherit from Model.
    """
    def __init__(self, nb_items):
        self.schedule = RandomActivation(self)
        self.__messages_service = MessageService(self.schedule)
        self.next_id = 0
        self.step_index = 0
        criterions = [
            CriterionName.ENVIRONMENT_IMPACT, CriterionName.NOISE,
            CriterionName.CONSUMPTION, CriterionName.DURABILITY,
            CriterionName.PRODUCTION_COST
        ]
        self.random.shuffle(criterions)
        self.agent1 = ArgumentAgent(self.get_next_id(), self, "agent1",
                                    criterions)
        self.random.shuffle(criterions)
        self.agent2 = ArgumentAgent(self.get_next_id(), self, "agent2",
                                    criterions)

        items = [
            Item("Item{}".format(self.get_next_id()), "Some random item")
            for _ in range(nb_items)
        ]

        for item in items:
            self.agent1.generate_random_preferences(item)
            self.agent2.generate_random_preferences(item)

        self.schedule.add(self.agent1)
        self.schedule.add(self.agent2)
        self.running = True

        self.agent1.propose_preferred_item("agent2")

    def step(self):
        self.step_index += 1
        self.__messages_service.dispatch_messages()
        self.schedule.step()

    def get_next_id(self):
        self.next_id += 1
        return self.next_id

    def run_n_steps(self, n):
        for _ in range(n):
            self.step()

    def run(self):
        while not self.agent1.vote_to_halt or not self.agent2.vote_to_halt:
            self.step()

    def show_stats(self):
        print()
        print("Number of steps to converge: {0} for {1} items".format(
            self.step_index, len(self.agent1.items)))
        print()
        for agent in [self.agent1, self.agent2]:
            print("Stats for: ", agent.get_name())
            print("Victories: ", agent.victory_count)
            print("Acceptation rate: ",
                  agent.accepted_propositions / agent.propositions)
            mean_scores_ratio = np.mean([
                item.get_score(agent.preference)
                for item in agent.committed_items
            ]) / np.mean(
                [item.get_score(agent.preference) for item in agent.items])
            print("Committed items mean score ratio: ", mean_scores_ratio)
            print()