Beispiel #1
0
 def action(self):
     # Setting a filter
     f = Filter()
     f.set_performative(ACLMessage.INFORM)  # Accept only INFORM messages
     message = self.read()
     if f.filter(message):  # Filtering the message
         display(self.agent, 'I received this list: \n%s' % message.content)
Beispiel #2
0
 def action(self):
     self.lock()
     display(self.agent, 'Now, I will count from 21 to 30 slowly:')
     for num in range(21, 31):
         display(self.agent, num)
         self.wait(1)
     self.unlock()
Beispiel #3
0
 def action(self):
     message = self.read()
     if not message.ontology in ['fruits', 'foods', 'office']:
         reply = message.create_reply()
         reply.set_content('Unknown list')
         reply.set_performative(ACLMessage.INFORM)
         self.agent.send(reply)
         display(self.agent, 'Unknown requisition')
Beispiel #4
0
 def action(self):
     if self.agent.has_messages():
         # Receives (reads) the message from queue
         message = self.agent.read()
         # Shows the message content
         display(
             self.agent,
             'I received a message with the content: %s.' % message.content)
Beispiel #5
0
 def action(self):
     self.lock()  # Here starts the critical section (holds the lock)
     display(self.agent, 'Now, I will count from 1 to 10 slowly:')
     for num in range(1, 11):
         display(self.agent, num)
         self.wait(
             1)  # I put this so that we can see the behaviours blocking
     self.unlock()  # Here ends the critical section (releases the lock)
Beispiel #6
0
 def action(self):
     message = ACLMessage(ACLMessage.REQUEST)
     message.add_receiver(AID('supermarket'))
     message.set_ontology(
         self.agent.session)  # Defines the tipe of list required
     message.set_content('Please, give me this list')
     self.agent.send(message)
     display(self.agent,
             'I requested for %s products.' % self.agent.session)
Beispiel #7
0
 def action(self):
     # Create a message with INFORM performative
     message = ACLMessage(ACLMessage.INFORM)
     # Adds the address (AID) of the message recipient
     message.add_receiver(self.agent.receiver)
     # Adds some content
     message.set_content('Hello! :)')
     # Send the message to receiver
     self.agent.send(message)
     display(self.agent, 'I sent a message to receiver.')
Beispiel #8
0
 def action(self):
     # Setting a filter
     f = Filter()
     # The object 'f' is the 'model' of message you want to receive
     f.set_ontology(self.agent.section
                    )  # The filter only accept agent's section messages
     if self.agent.has_messages():
         message = self.agent.read(f)
         if message != None:  # Filtering the message
             display(self.agent,
                     'I received this list: \n%s' % message.content)
Beispiel #9
0
    def action(self):
        if self.agent.has_messages():
            message = self.agent.read()

            # Filtering the received message manually
            if not message.ontology in ['fruits', 'foods', 'office']:
                reply = message.create_reply()
                reply.set_content('Unknown list')
                reply.set_performative(ACLMessage.INFORM)
                self.send(reply)
                display(self.agent, 'Unknown requisition')
Beispiel #10
0
 def action(self):
     f = Filter()
     f.set_performative(ACLMessage.REQUEST)
     f.set_ontology('foods')
     message = self.read()
     if f.filter(message):  # If the message satisfies the filter
         reply = message.create_reply()
         reply.set_content('meat\nchicken\ncookies\nice cream\nbread')
         reply.set_performative(ACLMessage.INFORM)
         self.agent.send(reply)
         display(self.agent,
                 'Food list sent to %s.' % message.sender.getLocalName())
Beispiel #11
0
 def action(self):
     f = Filter()
     f.set_performative(ACLMessage.REQUEST)
     f.set_ontology('office')
     message = self.read()
     if f.filter(message):
         reply = message.create_reply()
         reply.set_content('pen\nclips\nscissors\npaper\npencil')
         reply.set_performative(ACLMessage.INFORM)
         self.agent.send(reply)
         display(
             self.agent, 'Office material list sent to %s.' %
             message.sender.getLocalName())
Beispiel #12
0
    def action(self):
        # Setting a filter
        f = Filter()
        f.set_performative(ACLMessage.REQUEST)  # Accept only REQUEST messages
        f.set_ontology('fruits')

        # Reveiving a message and filtering it
        message = self.read()
        if f.filter(message):  # If the message satisfies the filter
            reply = message.create_reply()
            reply.set_content(
                'apple\nbanana\ncocoa\ncoconuts\ngrape\norange\nstrawberry')
            reply.set_performative(ACLMessage.INFORM)
            self.agent.send(reply)
            display(self.agent,
                    'Fruit list sent to %s.' % message.sender.getLocalName())
Beispiel #13
0
	def action(self):
		message = self.read()
		# Deserializing the information
		contact = pickle.loads(message.content)
		# Filtering the message in a non-elegant way (use for one field only)
		if message.performative == ACLMessage.INFORM:
			form = "Contact info: \nName: {name}\nPhone: {phone}\nE-mail: {email}"
			display(self.agent, form.format(
				name=contact['name'],
				phone=contact['phone'],
				email=contact['email'])
			)
		elif message.performative == ACLMessage.FAILURE:
			display(self.agent, '{id}: {desc}'.format(
				id=contact['error'],
				desc=contact['description'])
			)
Beispiel #14
0
    def action(self):
        # Setting the filter
        f = Filter()
        f.set_performative(ACLMessage.REQUEST)
        f.set_ontology('foods')

        # Filtering the received message based on 'f' filter
        if self.agent.has_messages(
        ):  # If the message satisfies the filter 'f'
            message = self.agent.read(f)
            if message != None:
                reply = message.create_reply()  # Creates a reply to the sender
                reply = message.create_reply()
                reply.set_content('meat\nchicken\ncookies\nice cream\nbread')
                reply.set_performative(ACLMessage.INFORM)
                self.send(reply)
                display(self.agent,
                        'Food list sent to %s.' % message.sender.getName())
Beispiel #15
0
    def action(self):
        # Setting the filter
        f = Filter()
        f.set_performative(ACLMessage.REQUEST)
        f.set_ontology('office')

        # Filtering the received message based on 'f' filter
        if self.agent.has_messages(
        ):  # If the message satisfies the filter 'f'
            message = self.agent.read(f)
            if message != None:
                reply = message.create_reply()  # Creates a reply to the sender
                reply = message.create_reply()
                reply.set_content('pen\nclips\nscissors\npaper\npencil')
                reply.set_performative(ACLMessage.INFORM)
                self.send(reply)
                display(
                    self.agent, 'Office material list sent to %s.' %
                    message.sender.getName())
Beispiel #16
0
 def action(self):
     message = self.read()
     # Deserializing the received information
     contact = pickle.loads(message.content)
     # Filtering the message
     f = Filter()
     f.set_performative(ACLMessage.INFORM)
     if f.filter(message):
         template = 'Contact info: \nName: {name}\nPhone: {phone}\nE-mail: {email}'
         # Showing the deserialized data
         display(
             self.agent,
             template.format(name=contact['name'],
                             phone=contact['phone'],
                             email=contact['email']))
     elif message.performative == ACLMessage.FAILURE:
         # Showing the failure information
         display(
             self.agent, '{id}: {desc}'.format(id=contact['error'],
                                               desc=contact['description']))
Beispiel #17
0
    def action(self):
        # Setting the filter
        f = Filter()
        # The object 'f' is the 'model' of message you want to receive
        f.set_performative(ACLMessage.REQUEST)  # Only accept REQUEST messages
        f.set_ontology(
            'fruits')  # Only accept messagens with 'fruits' in ontology field

        # Filtering the received message based on 'f' filter
        if self.agent.has_messages(
        ):  # If the message satisfies the filter 'f'
            message = self.agent.read(f)
            if message != None:
                reply = message.create_reply()  # Creates a reply to the sender
                reply.set_content(
                    'apple\nbanana\ncocoa\ncoconuts\ngrape\norange\nstrawberry'
                )
                reply.set_performative(ACLMessage.INFORM)
                self.send(reply)  # Sends the reply to the sender
                display(self.agent,
                        'Fruit list sent to %s.' % message.sender.getName())
Beispiel #18
0
 def action(self):
     for num in range(21, 31):
         display(self.agent, num)
Beispiel #19
0
 def action(self):
     message = ACLMessage(ACLMessage.REQUEST)
     message.add_receiver(self.agent.contact_book)
     message.set_content(self.agent.name)
     self.send(message)
     display(self.agent, "I requested for %s's contact." % self.agent.name)
Beispiel #20
0
 def action(self):
     message = self.read()
     display(self.agent, 'Running my behaviour...')
Beispiel #21
0
 def action(self):
     self.lock()
     # Here the agent will hold the lock only by 1 print, and
     # release it right away
     display(self.agent, '"BOLACHA" is the correct name.')
     self.unlock()
Beispiel #22
0
 def action(self):
     self.lock()  # Starts the critical section
     for _ in range(5):  # The agent will hold the lock by 5 prints
         display(self.agent, 'The correct name is "BISCOITO".')
         self.wait(0.5)
     self.unlock()  # Ends the critical section
Beispiel #23
0
 def action(self):
     message = ACLMessage(ACLMessage.INFORM)
     message.add_receiver(AID('receiver'))
     message.set_content('Hello! :)')
     self.agent.send(message)
     display(self.agent, 'I sent a message to receiver.')
Beispiel #24
0
 def action(self):
     message = self.read()
     display(self.agent,
             'I received a message with the content: %s.' % message.content)
Beispiel #25
0
	def action(self):
		display(self.agent, 'Counting #%d' % self.counter)
		self.counter += 1
Beispiel #26
0
	def on_end(self):
		display(self.agent, 'Counting finished.')